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 junit.framework.Test;
020: import junit.framework.TestCase;
021: import junit.framework.TestSuite;
022:
023: public class PathTest extends TestCase {
024:
025: public PathTest(String testName) {
026: super (testName);
027: }
028:
029: public static Test suite() {
030: return new TestSuite(PathTest.class);
031: }
032:
033: public static void main(String args[]) {
034: String[] testCaseName = { PathTest.class.getName() };
035: junit.textui.TestRunner.main(testCaseName);
036: }
037:
038: public void testConstructorNull() {
039: Path path = new Path(null, null);
040:
041: assertNull(path.getScope());
042: }
043:
044: public void testConstructorNullState() {
045: Path path = new Path(new State(), null);
046:
047: assertTrue(path.getScope() instanceof State);
048: }
049:
050: public void testConstructorStates() {
051: TransitionTarget source = new State();
052: source.setId("1");
053:
054: TransitionTarget target = new State();
055: target.setId("2");
056:
057: Path path = new Path(source, target);
058:
059: assertNull(path.getScope());
060: assertEquals(1, path.getUpwardSegment().size());
061: assertEquals("1", ((State) path.getUpwardSegment().get(0))
062: .getId());
063:
064: assertEquals(1, path.getDownwardSegment().size());
065: assertEquals("2", ((State) path.getDownwardSegment().get(0))
066: .getId());
067:
068: assertFalse(path.isCrossRegion());
069: }
070:
071: public void testConstructorSourceCrossRegion() {
072: Parallel region = new Parallel();
073:
074: TransitionTarget source = new State();
075: source.setId("1");
076: source.setParent(region);
077:
078: TransitionTarget target = new State();
079: target.setId("2");
080:
081: Path path = new Path(source, target);
082:
083: assertTrue(path.isCrossRegion());
084: }
085:
086: public void testConstructorTargetCrossRegion() {
087: Parallel region = new Parallel();
088:
089: TransitionTarget source = new State();
090: source.setId("1");
091:
092: TransitionTarget target = new State();
093: target.setId("2");
094: target.setParent(region);
095:
096: Path path = new Path(source, target);
097:
098: assertTrue(path.isCrossRegion());
099: }
100:
101: public void testConstructorParentTarget() {
102: TransitionTarget source = new State();
103: source.setId("1");
104:
105: TransitionTarget target = new State();
106: target.setId("2");
107:
108: source.setParent(target);
109:
110: Path path = new Path(source, target);
111:
112: assertNull(path.getScope());
113: }
114:
115: public void testConstructorParentSource() {
116: TransitionTarget source = new State();
117: source.setId("1");
118:
119: TransitionTarget target = new State();
120: target.setId("2");
121:
122: target.setParent(source);
123:
124: Path path = new Path(source, target);
125:
126: assertNull(path.getScope());
127: }
128:
129: public void testConstructorParent() {
130: TransitionTarget source = new State();
131: source.setId("1");
132:
133: TransitionTarget target = new State();
134: target.setId("2");
135:
136: State parent = new State();
137: parent.setId("parentid");
138:
139: target.setParent(parent);
140: source.setParent(parent);
141:
142: Path path = new Path(source, target);
143:
144: assertEquals("parentid", path.getScope().getId());
145: }
146:
147: public void testConstructorParentParallel() {
148: TransitionTarget source = new State();
149: source.setId("1");
150:
151: TransitionTarget target = new State();
152: target.setId("2");
153:
154: Parallel parent = new Parallel();
155: parent.setId("parentid");
156:
157: target.setParent(parent);
158: source.setParent(parent);
159:
160: Path path = new Path(source, target);
161:
162: assertNull(path.getScope());
163: }
164:
165: public void testConstructorParentParallelParent() {
166: TransitionTarget source = new State();
167: source.setId("1");
168:
169: TransitionTarget target = new State();
170: target.setId("2");
171:
172: Parallel parent = new Parallel();
173: parent.setId("parentid");
174:
175: State parentOfParent = new State();
176: parentOfParent.setId("superParent");
177:
178: parent.setParent(parentOfParent);
179:
180: target.setParent(parent);
181: source.setParent(parent);
182:
183: Path path = new Path(source, target);
184:
185: assertEquals("superParent", path.getScope().getId());
186: }
187:
188: public void testGetRegionsExitedNull() {
189: Path path = new Path(new State(), null);
190:
191: assertEquals(0, path.getRegionsExited().size());
192: }
193:
194: public void testGetRegionsExitedNotRegion() {
195: TransitionTarget source = new State();
196: source.setId("1");
197:
198: TransitionTarget target = new State();
199: target.setId("2");
200:
201: Path path = new Path(source, target);
202:
203: assertEquals(0, path.getRegionsExited().size());
204: }
205:
206: public void testGetRegionsExitedParallel() {
207: TransitionTarget source = new Parallel();
208: source.setId("1");
209:
210: TransitionTarget target = new Parallel();
211: target.setId("2");
212:
213: Path path = new Path(source, target);
214:
215: assertEquals(0, path.getRegionsExited().size());
216: }
217:
218: public void testGetRegionsExited() {
219: Parallel region = new Parallel();
220:
221: TransitionTarget source = new State();
222: source.setId("1");
223: source.setParent(region);
224:
225: TransitionTarget target = new State();
226: target.setId("2");
227:
228: Path path = new Path(source, target);
229:
230: assertEquals(1, path.getRegionsExited().size());
231: assertEquals("1", ((State) path.getRegionsExited().get(0))
232: .getId());
233: }
234:
235: public void testGetRegionsEnteredNull() {
236: Path path = new Path(new State(), null);
237:
238: assertEquals(0, path.getRegionsEntered().size());
239: }
240:
241: public void testGetRegionsEnteredNotRegion() {
242: TransitionTarget source = new State();
243: source.setId("1");
244:
245: TransitionTarget target = new State();
246: target.setId("2");
247:
248: Path path = new Path(source, target);
249:
250: assertEquals(0, path.getRegionsEntered().size());
251: }
252:
253: public void testGetRegionsEnteredParallel() {
254: TransitionTarget source = new Parallel();
255: source.setId("1");
256:
257: TransitionTarget target = new Parallel();
258: target.setId("2");
259:
260: Path path = new Path(source, target);
261:
262: assertEquals(0, path.getRegionsEntered().size());
263: }
264:
265: public void testGetRegionsEntered() {
266: Parallel region = new Parallel();
267:
268: TransitionTarget source = new State();
269: source.setId("1");
270:
271: TransitionTarget target = new State();
272: target.setId("2");
273: target.setParent(region);
274:
275: Path path = new Path(source, target);
276:
277: assertEquals(1, path.getRegionsEntered().size());
278: assertEquals("2", ((State) path.getRegionsEntered().get(0))
279: .getId());
280: }
281:
282: }
|