1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.scxml2.issues;
18
19 import java.util.ArrayList;
20 import java.util.LinkedList;
21 import java.util.List;
22 import java.util.Queue;
23
24 import org.apache.commons.scxml2.ActionExecutionContext;
25 import org.apache.commons.scxml2.SCXMLExecutor;
26 import org.apache.commons.scxml2.SCXMLExpressionException;
27 import org.apache.commons.scxml2.SCXMLTestHelper;
28 import org.apache.commons.scxml2.model.Action;
29 import org.apache.commons.scxml2.model.CustomAction;
30 import org.apache.commons.scxml2.model.ModelException;
31 import org.apache.commons.scxml2.model.SCXML;
32 import org.junit.After;
33 import org.junit.Assert;
34 import org.junit.Test;
35
36
37
38
39
40 public class Issue112Test {
41
42
43
44
45 @After
46 public void tearDown() {
47 Application.QUEUE.clear();
48 }
49
50
51
52 @Test
53 public void test01issue112() throws Exception {
54
55 CustomAction ca1 =
56 new CustomAction("http://my.custom-actions.domain/CUSTOM", "enqueue", Enqueue.class);
57 List<CustomAction> customActions = new ArrayList<CustomAction>();
58 customActions.add(ca1);
59
60 SCXML scxml = SCXMLTestHelper.parse("org/apache/commons/scxml2/issues/queue-01.xml", customActions);
61 SCXMLExecutor exec = SCXMLTestHelper.getExecutor(scxml);
62 exec.go();
63 Assert.assertEquals("init", exec.getStatus().getStates().
64 iterator().next().getId());
65
66
67 Application.QUEUE.add("next");
68
69
70
71 while (!Application.QUEUE.isEmpty()) {
72 try {
73 SCXMLTestHelper.fireEvent(exec, Application.QUEUE.remove());
74 } catch (Exception e) {
75 e.printStackTrace();
76 }
77 }
78
79 Assert.assertTrue(exec.getStatus().isFinal());
80 Assert.assertEquals("end", exec.getStatus().getStates().
81 iterator().next().getId());
82
83 }
84
85
86
87
88 public static class Enqueue extends Action {
89
90 private static final long serialVersionUID = 1L;
91 private String event;
92
93 public Enqueue() {
94 super();
95 }
96
97 public String getEvent() {
98 return event;
99 }
100
101 public void setEvent(String event) {
102 this.event = event;
103 }
104
105 @Override
106 public void execute(ActionExecutionContext exctx) throws ModelException, SCXMLExpressionException {
107
108 Application.QUEUE.add(event);
109
110 }
111
112 }
113
114
115 private static final class Application {
116 private static final Queue<String> QUEUE = new LinkedList<String>();
117 }
118
119 }
120