1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.scxml2.env.javascript;
19
20 import java.util.ArrayList;
21 import java.util.List;
22 import java.util.Set;
23
24 import org.apache.commons.scxml2.SCXMLExecutor;
25 import org.apache.commons.scxml2.SCXMLExpressionException;
26 import org.apache.commons.scxml2.SCXMLTestHelper;
27 import org.apache.commons.scxml2.TriggerEvent;
28 import org.apache.commons.scxml2.model.Action;
29 import org.apache.commons.scxml2.ActionExecutionContext;
30 import org.apache.commons.scxml2.model.CustomAction;
31 import org.apache.commons.scxml2.model.EnterableState;
32 import org.apache.commons.scxml2.model.ModelException;
33 import org.apache.commons.scxml2.model.SCXML;
34
35 import org.junit.Assert;
36 import org.junit.Test;
37
38
39
40
41
42 public class JSExampleTest {
43
44
45 @Test
46 public void testExample01Sample() throws Exception {
47
48 List<CustomAction> actions = new ArrayList<CustomAction>();
49 actions.add(new CustomAction("http://my.custom-actions.domain", "eventdatamaptest", EventDataMapTest.class));
50
51 SCXML scxml = SCXMLTestHelper.parse("org/apache/commons/scxml2/env/javascript/example-01.xml", actions);
52 SCXMLExecutor exec = SCXMLTestHelper.getExecutor(scxml);
53 exec.go();
54 Set<EnterableState> currentStates = exec.getStatus().getStates();
55 Assert.assertEquals(1, currentStates.size());
56 Assert.assertEquals("end", currentStates.iterator().next().getId());
57 }
58
59
60
61 public static class EventDataMapTest extends Action {
62 private static final long serialVersionUID = 1L;
63
64 @Override
65 public void execute(ActionExecutionContext exctx) throws ModelException, SCXMLExpressionException {
66 exctx.getInternalIOProcessor().addEvent(new TriggerEvent("ok",TriggerEvent.SIGNAL_EVENT,"and its ok with me to"));
67 }
68 }
69
70 }
71