/** Creates and initialises an SCXML data model in the context. */ @Before public void setUp() throws Exception { fsm = SCXMLTestHelper.getExecutor(SCXMLReader.read(new StringReader(SCRIPT))); evaluator = fsm.getEvaluator(); context = fsm.getGlobalContext(); context.set(Context.NAMESPACES_KEY, null); }
// Hello World example using custom <my:hello> action that generates an // event which has the payload examined with JEXL expressions @Test public void testCustomActionEventPayloadHelloWorldJexl() throws Exception { // (1) Form a list of custom actions defined in the SCXML // document (and any included documents via "src" attributes) CustomAction ca = new CustomAction("http://my.custom-actions.domain/CUSTOM", "hello", Hello.class); List<CustomAction> customActions = new ArrayList<CustomAction>(); customActions.add(ca); // (2) Parse the document SCXML scxml = SCXMLTestHelper.parse( "org/apache/commons/scxml2/custom-hello-world-04-jexl.xml", customActions); // (3) Get a SCXMLExecutor SCXMLExecutor exec = SCXMLTestHelper.getExecutor(scxml); exec.go(); // (4) Single, final state Assert.assertEquals( "Invalid intermediate state", "custom1", (exec.getStatus().getStates().iterator().next()).getId()); // (5) Verify datamodel variable is correct Assert.assertEquals( "Missing helloName1 in root context", "custom04a", exec.getGlobalContext().get("helloName1")); // The custom action defined by Hello.class should be called // to execute() exactly once at this point (by onentry in init state). Assert.assertEquals(1, Hello.callbacks); // (6) Check use of payload in non-initial state SCXMLTestHelper.fireEvent(exec, "custom.next"); // (7) Verify correct end state Assert.assertEquals( "Missing helloName1 in root context", "custom04b", exec.getGlobalContext().get("helloName1")); Assert.assertEquals( "Invalid final state", "end", (exec.getStatus().getStates().iterator().next()).getId()); Assert.assertTrue(exec.getStatus().isFinal()); // The custom action defined by Hello.class should be called // to execute() exactly two times at this point (by onentry in custom2 state). Assert.assertEquals(2, Hello.callbacks); }