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