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.model;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import junit.framework.Test;
22  import junit.framework.TestCase;
23  import junit.framework.TestSuite;
24  
25  public class StateTest extends TestCase {
26  
27      public StateTest(String testName) {
28          super(testName);
29      }
30  
31      public static Test suite() {
32          return new TestSuite(StateTest.class);
33      }
34  
35      public static void main(String args[]) {
36          String[] testCaseName = { StateTest.class.getName()};
37          junit.textui.TestRunner.main(testCaseName);
38      }
39      
40      private State state;
41      
42      public void setUp() {
43          state = new State();
44      }
45      
46      public void testGetTransitionsListNull() {
47          assertNull(state.getTransitionsList("event"));
48      }
49      
50      public void testGetTransitionsList() {
51          List values = new ArrayList();
52          
53          state.getTransitions().put("event", values);
54          
55          assertNotNull(state.getTransitionsList("event"));
56      }
57      
58      public void testAddTransitionDoesNotContainKey() {
59          Transition transition = new Transition();
60          transition.setEvent("event");
61          
62          state.addTransition(transition);
63          
64          List events = (List)state.getTransitions().get("event");
65          
66          assertEquals(1, events.size());
67          assertEquals("event", ((Transition)events.get(0)).getEvent());
68      }
69      
70      public void testAddTransitionContainKey() {
71          Transition transition1 = new Transition();
72          transition1.setEvent("event");
73  
74          Transition transition2 = new Transition();
75          transition2.setEvent("event");
76  
77          state.addTransition(transition1);
78          state.addTransition(transition2);
79          
80          List events = (List)state.getTransitions().get("event");
81          
82          assertEquals(2, events.size());
83      }
84      
85      public void testGetTransitionList() {
86          Transition transition1 = new Transition();
87          transition1.setEvent("event");
88  
89          Transition transition2 = new Transition();
90          transition2.setEvent("event");
91  
92          state.addTransition(transition1);
93          state.addTransition(transition2);
94          
95          List events = state.getTransitionsList();
96          
97          assertEquals(2, events.size());
98      }
99      
100     public void testHasHistoryEmpty() {
101         assertFalse(state.hasHistory());
102     }
103 
104     public void testHasHistory() {
105         History history = new History();
106         
107         state.addHistory(history);
108         
109         assertTrue(state.hasHistory());
110     }
111     
112     public void testIsSimple() {
113         assertTrue(state.isSimple());
114     }
115     
116     public void testIsSimpleParallel() {
117         Parallel parallel = new Parallel();
118         
119         state.setParallel(parallel);
120         
121         assertFalse(state.isSimple());
122     }
123     
124     public void testIsSimpleHasChildren() {
125         State state1 = new State();
126         
127         state.addChild(state1);
128         
129         assertFalse(state.isSimple());
130     }
131     
132     public void testIsCompositeFalse() {
133         assertFalse(state.isComposite());
134     }
135     
136     public void testIsCompositeParallel() {
137         Parallel parallel = new Parallel();
138         
139         state.setParallel(parallel);
140         
141         assertTrue(state.isComposite());
142     }
143     
144     public void testIsCompositeHasChildren() {
145         State state1 = new State();
146         
147         state.addChild(state1);
148         
149         assertTrue(state.isComposite());
150     }
151     
152     public void testIsRegion() {
153         state.setParent(new Parallel());
154         
155         assertTrue(state.isRegion());
156     }
157     
158     public void testIsRegionNotParallel() {
159         state.setParent(new State());
160         
161         assertFalse(state.isRegion());
162     }
163     
164     public void testIsOrthogonal() {
165         Parallel parallel = new Parallel();
166         
167         state.setParallel(parallel);
168         
169         assertTrue(state.isOrthogonal());
170     }
171     
172     public void testIsOrthogonalFalse() {
173         assertFalse(state.isOrthogonal());
174     }
175 
176 }