View Javadoc
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.scxml2.env;
18  
19  import org.apache.commons.scxml2.model.State;
20  import org.apache.commons.scxml2.model.Transition;
21  import org.junit.Assert;
22  import org.junit.Test;
23  
24  public class LogUtilsTest {
25  
26      @Test
27      public void testGetTTPathParentNull() {
28          State target = new State();
29          target.setId("ID");
30          
31          Assert.assertEquals("/ID", LogUtils.getTTPath(target));
32      }
33      
34      @Test
35      public void testGetTTPathParent() {
36          State target = new State();
37          target.setId("ID");
38  
39          State parent1 = new State();
40          parent1.setId("parent1");
41  
42          State parent2 = new State();
43          parent2.setId("parent2");
44  
45          parent1.setParent(parent2);
46          target.setParent(parent1);
47          
48          Assert.assertEquals("/parent2/parent1/ID", LogUtils.getTTPath(target));
49      }
50      
51      @Test
52      public void testTransToString() {
53          State targetTo = new State();
54          targetTo.setId("TO");
55  
56          State targetFrom = new State();
57          targetFrom.setId("FROM");
58          
59          Transition transition = new Transition();
60          transition.setCond("condition");
61          transition.setEvent("event happened");
62          
63          Assert.assertEquals( "(event = event happened, cond = condition, from = /FROM, to = /TO)",
64                                          LogUtils.transToString(targetFrom, targetTo, transition, transition.getEvent()));
65      }
66  
67  }