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: */
017: package org.apache.commons.scxml.model;
018:
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import junit.framework.Test;
023: import junit.framework.TestCase;
024: import junit.framework.TestSuite;
025:
026: public class StateTest extends TestCase {
027:
028: public StateTest(String testName) {
029: super (testName);
030: }
031:
032: public static Test suite() {
033: return new TestSuite(StateTest.class);
034: }
035:
036: public static void main(String args[]) {
037: String[] testCaseName = { StateTest.class.getName() };
038: junit.textui.TestRunner.main(testCaseName);
039: }
040:
041: private State state;
042:
043: public void setUp() {
044: state = new State();
045: }
046:
047: public void testGetTransitionsListNull() {
048: assertNull(state.getTransitionsList("event"));
049: }
050:
051: public void testGetTransitionsList() {
052: List values = new ArrayList();
053:
054: state.getTransitions().put("event", values);
055:
056: assertNotNull(state.getTransitionsList("event"));
057: }
058:
059: public void testAddTransitionDoesNotContainKey() {
060: Transition transition = new Transition();
061: transition.setEvent("event");
062:
063: state.addTransition(transition);
064:
065: List events = (List) state.getTransitions().get("event");
066:
067: assertEquals(1, events.size());
068: assertEquals("event", ((Transition) events.get(0)).getEvent());
069: }
070:
071: public void testAddTransitionContainKey() {
072: Transition transition1 = new Transition();
073: transition1.setEvent("event");
074:
075: Transition transition2 = new Transition();
076: transition2.setEvent("event");
077:
078: state.addTransition(transition1);
079: state.addTransition(transition2);
080:
081: List events = (List) state.getTransitions().get("event");
082:
083: assertEquals(2, events.size());
084: }
085:
086: public void testGetTransitionList() {
087: Transition transition1 = new Transition();
088: transition1.setEvent("event");
089:
090: Transition transition2 = new Transition();
091: transition2.setEvent("event");
092:
093: state.addTransition(transition1);
094: state.addTransition(transition2);
095:
096: List events = state.getTransitionsList();
097:
098: assertEquals(2, events.size());
099: }
100:
101: public void testHasHistoryEmpty() {
102: assertFalse(state.hasHistory());
103: }
104:
105: public void testHasHistory() {
106: History history = new History();
107:
108: state.addHistory(history);
109:
110: assertTrue(state.hasHistory());
111: }
112:
113: public void testIsSimple() {
114: assertTrue(state.isSimple());
115: }
116:
117: public void testIsSimpleParallel() {
118: Parallel parallel = new Parallel();
119:
120: state.setParallel(parallel);
121:
122: assertFalse(state.isSimple());
123: }
124:
125: public void testIsSimpleHasChildren() {
126: State state1 = new State();
127:
128: state.addChild(state1);
129:
130: assertFalse(state.isSimple());
131: }
132:
133: public void testIsCompositeFalse() {
134: assertFalse(state.isComposite());
135: }
136:
137: public void testIsCompositeParallel() {
138: Parallel parallel = new Parallel();
139:
140: state.setParallel(parallel);
141:
142: assertTrue(state.isComposite());
143: }
144:
145: public void testIsCompositeHasChildren() {
146: State state1 = new State();
147:
148: state.addChild(state1);
149:
150: assertTrue(state.isComposite());
151: }
152:
153: public void testIsRegion() {
154: state.setParent(new Parallel());
155:
156: assertTrue(state.isRegion());
157: }
158:
159: public void testIsRegionNotParallel() {
160: state.setParent(new State());
161:
162: assertFalse(state.isRegion());
163: }
164:
165: public void testIsOrthogonal() {
166: Parallel parallel = new Parallel();
167:
168: state.setParallel(parallel);
169:
170: assertTrue(state.isOrthogonal());
171: }
172:
173: public void testIsOrthogonalFalse() {
174: assertFalse(state.isOrthogonal());
175: }
176:
177: }
|