001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.commons.scxml.invoke;
018:
019: import java.net.URL;
020: import java.util.Set;
021:
022: import junit.framework.Test;
023: import junit.framework.TestCase;
024: import junit.framework.TestSuite;
025: import junit.textui.TestRunner;
026:
027: import org.apache.commons.scxml.SCXMLExecutor;
028: import org.apache.commons.scxml.env.SimpleDispatcher;
029: import org.apache.commons.scxml.env.SimpleErrorHandler;
030: import org.apache.commons.scxml.env.SimpleErrorReporter;
031: import org.apache.commons.scxml.env.jexl.JexlContext;
032: import org.apache.commons.scxml.env.jexl.JexlEvaluator;
033: import org.apache.commons.scxml.io.SCXMLDigester;
034: import org.apache.commons.scxml.model.SCXML;
035: import org.apache.commons.scxml.model.State;
036:
037: /**
038: * Unit tests {@link org.apache.commons.scxml.SCXMLExecutor}.
039: * Testing <invoke>
040: */
041: public class InvokeTest extends TestCase {
042: /**
043: * Construct a new instance of SCXMLExecutorTest with
044: * the specified name
045: */
046: public InvokeTest(String name) {
047: super (name);
048: }
049:
050: public static Test suite() {
051: TestSuite suite = new TestSuite(InvokeTest.class);
052: suite.setName("SCXML Executor Tests, wildcard event match");
053: return suite;
054: }
055:
056: // Test data
057: private URL invoke01;
058: private SCXMLExecutor exec;
059:
060: /**
061: * Set up instance variables required by this test case.
062: */
063: public void setUp() {
064: invoke01 = this .getClass().getClassLoader().getResource(
065: "org/apache/commons/scxml/invoke/invoker-01.xml");
066: }
067:
068: /**
069: * Tear down instance variables required by this test case.
070: */
071: public void tearDown() {
072: invoke01 = null;
073: }
074:
075: /**
076: * Test the SCXML documents, usage of <invoke>
077: */
078: public void testInvoke01Sample() {
079: try {
080: SCXML scxml = SCXMLDigester.digest(invoke01,
081: new SimpleErrorHandler());
082: exec = new SCXMLExecutor(new JexlEvaluator(),
083: new SimpleDispatcher(), new SimpleErrorReporter());
084: assertNotNull(exec);
085: exec.setRootContext(new JexlContext());
086: exec.setStateMachine(scxml);
087: exec
088: .registerInvokerClass("scxml",
089: SimpleSCXMLInvoker.class);
090: exec.go();
091: Set currentStates = exec.getCurrentStatus().getStates();
092: assertEquals(1, currentStates.size());
093: assertEquals("invoker", ((State) currentStates.iterator()
094: .next()).getId());
095: } catch (Exception e) {
096: e.printStackTrace();
097: fail(e.getMessage());
098: }
099: }
100:
101: public static void main(String args[]) {
102: TestRunner.run(suite());
103: }
104: }
|