001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.scxml2.env;
018
019import org.apache.commons.scxml2.model.State;
020import org.apache.commons.scxml2.model.Transition;
021import org.junit.Assert;
022import org.junit.Test;
023
024public class LogUtilsTest {
025
026    @Test
027    public void testGetTTPathParentNull() {
028        State target = new State();
029        target.setId("ID");
030        
031        Assert.assertEquals("/ID", LogUtils.getTTPath(target));
032    }
033    
034    @Test
035    public void testGetTTPathParent() {
036        State target = new State();
037        target.setId("ID");
038
039        State parent1 = new State();
040        parent1.setId("parent1");
041
042        State parent2 = new State();
043        parent2.setId("parent2");
044
045        parent1.setParent(parent2);
046        target.setParent(parent1);
047        
048        Assert.assertEquals("/parent2/parent1/ID", LogUtils.getTTPath(target));
049    }
050    
051    @Test
052    public void testTransToString() {
053        State targetTo = new State();
054        targetTo.setId("TO");
055
056        State targetFrom = new State();
057        targetFrom.setId("FROM");
058        
059        Transition transition = new Transition();
060        transition.setCond("condition");
061        transition.setEvent("event happened");
062        
063        Assert.assertEquals( "(event = event happened, cond = condition, from = /FROM, to = /TO)",
064                                        LogUtils.transToString(targetFrom, targetTo, transition, transition.getEvent()));
065    }
066
067}