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