1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.scxml.invoke;
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.env.SimpleDispatcher;
29 import org.apache.commons.scxml.env.SimpleErrorHandler;
30 import org.apache.commons.scxml.env.SimpleErrorReporter;
31 import org.apache.commons.scxml.env.jexl.JexlContext;
32 import org.apache.commons.scxml.env.jexl.JexlEvaluator;
33 import org.apache.commons.scxml.io.SCXMLDigester;
34 import org.apache.commons.scxml.model.SCXML;
35 import org.apache.commons.scxml.model.State;
36
37 /***
38 * Unit tests {@link org.apache.commons.scxml.SCXMLExecutor}.
39 * Testing <invoke>
40 */
41 public class InvokeTest extends TestCase {
42 /***
43 * Construct a new instance of SCXMLExecutorTest with
44 * the specified name
45 */
46 public InvokeTest(String name) {
47 super(name);
48 }
49
50 public static Test suite() {
51 TestSuite suite = new TestSuite(InvokeTest.class);
52 suite.setName("SCXML Executor Tests, wildcard event match");
53 return suite;
54 }
55
56
57 private URL invoke01;
58 private SCXMLExecutor exec;
59
60 /***
61 * Set up instance variables required by this test case.
62 */
63 public void setUp() {
64 invoke01 = this.getClass().getClassLoader().
65 getResource("org/apache/commons/scxml/invoke/invoker-01.xml");
66 }
67
68 /***
69 * Tear down instance variables required by this test case.
70 */
71 public void tearDown() {
72 invoke01 = null;
73 }
74
75 /***
76 * Test the SCXML documents, usage of <invoke>
77 */
78 public void testInvoke01Sample() {
79 try {
80 SCXML scxml = SCXMLDigester.digest(invoke01,
81 new SimpleErrorHandler());
82 exec = new SCXMLExecutor(new JexlEvaluator(), new SimpleDispatcher(),
83 new SimpleErrorReporter());
84 assertNotNull(exec);
85 exec.setRootContext(new JexlContext());
86 exec.setStateMachine(scxml);
87 exec.registerInvokerClass("scxml", SimpleSCXMLInvoker.class);
88 exec.go();
89 Set currentStates = exec.getCurrentStatus().getStates();
90 assertEquals(1, currentStates.size());
91 assertEquals("invoker", ((State)currentStates.iterator().
92 next()).getId());
93 } catch (Exception e) {
94 e.printStackTrace();
95 fail(e.getMessage());
96 }
97 }
98
99 public static void main(String args[]) {
100 TestRunner.run(suite());
101 }
102 }
103