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