1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.scxml;
17
18 import java.net.URL;
19 import java.util.Set;
20
21 import junit.framework.Test;
22 import junit.framework.TestCase;
23 import junit.framework.TestSuite;
24 import junit.textui.TestRunner;
25
26 import org.apache.commons.scxml.model.State;
27 /***
28 * Unit tests {@link org.apache.commons.scxml.SCXMLExecutor}.
29 * Testing wildcard event matching (*)
30 */
31 public class WildcardTest extends TestCase {
32 /***
33 * Construct a new instance of SCXMLExecutorTest with
34 * the specified name
35 */
36 public WildcardTest(String name) {
37 super(name);
38 }
39
40 public static Test suite() {
41 TestSuite suite = new TestSuite(WildcardTest.class);
42 suite.setName("SCXML Executor Tests, wildcard event match");
43 return suite;
44 }
45
46
47 private URL wildcard01;
48 private SCXMLExecutor exec;
49
50 /***
51 * Set up instance variables required by this test case.
52 */
53 public void setUp() {
54 wildcard01 = this.getClass().getClassLoader().
55 getResource("org/apache/commons/scxml/env/jexl/wildcard-01.xml");
56 }
57
58 /***
59 * Tear down instance variables required by this test case.
60 */
61 public void tearDown() {
62 wildcard01 = null;
63 }
64
65 /***
66 * Test the SCXML documents, usage of "_eventdata"
67 */
68 public void testWildcard01Sample() {
69 exec = SCXMLTestHelper.getExecutor(wildcard01);
70 assertNotNull(exec);
71 try {
72 Set currentStates = exec.getCurrentStatus().getStates();
73 assertEquals(1, currentStates.size());
74 assertEquals("state1", ((State)currentStates.iterator().
75 next()).getId());
76 currentStates = SCXMLTestHelper.fireEvent(exec, "*");
77 assertEquals(1, currentStates.size());
78 assertEquals("state4", ((State)currentStates.iterator().
79 next()).getId());
80 } catch (Exception e) {
81 fail(e.getMessage());
82 }
83 }
84
85 public static void main(String args[]) {
86 TestRunner.run(suite());
87 }
88 }