1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.scxml.env;
18  
19  import org.apache.commons.scxml.model.State;
20  import org.apache.commons.scxml.model.Transition;
21  import org.apache.commons.scxml.model.TransitionTarget;
22  
23  import junit.framework.Test;
24  import junit.framework.TestCase;
25  import junit.framework.TestSuite;
26  
27  public class LogUtilsTest extends TestCase {
28  
29      public LogUtilsTest(String testName) {
30          super(testName);
31      }
32  
33      public static Test suite() {
34          return new TestSuite(LogUtilsTest.class);
35      }
36  
37      public static void main(String args[]) {
38          String[] testCaseName = {LogUtilsTest.class.getName()};
39          junit.textui.TestRunner.main(testCaseName);
40      }
41      
42      public void testGetTTPathParentNull() {
43          TransitionTarget target = new State();
44          target.setId("ID");
45          
46          assertEquals("/ID", LogUtils.getTTPath(target));
47      }
48      
49      public void testGetTTPathParent() {
50          TransitionTarget target = new State();
51          target.setId("ID");
52  
53          TransitionTarget parent1 = new State();
54          parent1.setId("parent1");
55  
56          TransitionTarget parent2 = new State();
57          parent2.setId("parent2");
58  
59          parent1.setParent(parent2);
60          target.setParent(parent1);
61          
62          assertEquals("/parent2/parent1/ID", LogUtils.getTTPath(target));
63      }
64      
65      public void testTransToString() {
66          TransitionTarget targetTo = new State();
67          targetTo.setId("TO");
68  
69          TransitionTarget targetFrom = new State();
70          targetFrom.setId("FROM");
71          
72          Transition transition = new Transition();
73          transition.setCond("condition");
74          transition.setEvent("event happened");
75          
76          assertEquals( "transition (event = event happened, cond = condition, from = /FROM, to = /TO)", 
77                                          LogUtils.transToString(targetFrom, targetTo, transition));
78      }
79  
80  }