1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 * Unit tests {@link org.apache.commons.scxml.SCXMLDigester}
33 * Test white box nature of <state> element "src" attribute.
34 */
35 public class StateSrcTest extends TestCase {
36 /***
37 * Construct a new instance of SCXMLDigesterTest with
38 * the specified name
39 */
40 public StateSrcTest(String name) {
41 super(name);
42 }
43
44 public static Test suite() {
45 TestSuite suite = new TestSuite(StateSrcTest.class);
46 suite.setName("SCXML Digester Tests");
47 return suite;
48 }
49
50
51 private URL src01;
52 private SCXML scxml;
53 private SCXMLExecutor exec;
54
55 /***
56 * Set up instance variables required by this test case.
57 */
58 public void setUp() {
59 src01 = this.getClass().getClassLoader().
60 getResource("org/apache/commons/scxml/io/src-test-1.xml");
61 }
62
63 /***
64 * Tear down instance variables required by this test case.
65 */
66 public void tearDown() {
67 src01 = null;
68 scxml = null;
69 exec = null;
70 }
71
72 /***
73 * Test the implementation
74 */
75 public void testRecursiveSrcInclude() {
76 scxml = SCXMLTestHelper.digest(src01);
77 assertNotNull(scxml);
78 exec = SCXMLTestHelper.getExecutor(scxml);
79 assertNotNull(exec);
80 Set states = exec.getCurrentStatus().getStates();
81 assertEquals(1, states.size());
82 assertEquals("srctest3", ((State) states.iterator().next()).getId());
83 states = SCXMLTestHelper.fireEvent(exec, "src.test");
84 assertEquals(1, states.size());
85 assertEquals("srctest1end", ((State) states.iterator().next()).getId());
86 assertTrue(exec.getCurrentStatus().isFinal());
87 }
88
89 public static void main(String args[]) {
90 TestRunner.run(suite());
91 }
92 }
93