01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.scxml.io;
18:
19: import java.net.URL;
20: import java.util.Set;
21:
22: import junit.framework.Test;
23: import junit.framework.TestCase;
24: import junit.framework.TestSuite;
25: import junit.textui.TestRunner;
26:
27: import org.apache.commons.scxml.SCXMLExecutor;
28: import org.apache.commons.scxml.SCXMLTestHelper;
29: import org.apache.commons.scxml.model.SCXML;
30: import org.apache.commons.scxml.model.State;
31:
32: /**
33: * Unit tests {@link org.apache.commons.scxml.SCXMLDigester}
34: * Test white box nature of <state> element "src" attribute.
35: */
36: public class StateSrcTest extends TestCase {
37: /**
38: * Construct a new instance of SCXMLDigesterTest with
39: * the specified name
40: */
41: public StateSrcTest(String name) {
42: super (name);
43: }
44:
45: public static Test suite() {
46: TestSuite suite = new TestSuite(StateSrcTest.class);
47: suite.setName("SCXML Digester Tests");
48: return suite;
49: }
50:
51: // Test data
52: private URL src01;
53: private SCXML scxml;
54: private SCXMLExecutor exec;
55:
56: /**
57: * Set up instance variables required by this test case.
58: */
59: public void setUp() {
60: src01 = this .getClass().getClassLoader().getResource(
61: "org/apache/commons/scxml/io/src-test-1.xml");
62: }
63:
64: /**
65: * Tear down instance variables required by this test case.
66: */
67: public void tearDown() {
68: src01 = null;
69: scxml = null;
70: exec = null;
71: }
72:
73: /**
74: * Test the implementation
75: */
76: public void testRecursiveSrcInclude() {
77: scxml = SCXMLTestHelper.digest(src01);
78: assertNotNull(scxml);
79: exec = SCXMLTestHelper.getExecutor(scxml);
80: assertNotNull(exec);
81: Set states = exec.getCurrentStatus().getStates();
82: assertEquals(1, states.size());
83: assertEquals("srctest3", ((State) states.iterator().next())
84: .getId());
85: states = SCXMLTestHelper.fireEvent(exec, "src.test");
86: assertEquals(1, states.size());
87: assertEquals("srctest1end", ((State) states.iterator().next())
88: .getId());
89: assertTrue(exec.getCurrentStatus().isFinal());
90: }
91:
92: public static void main(String args[]) {
93: TestRunner.run(suite());
94: }
95: }
|