Author: woonsan
Date: Fri Feb 13 23:51:13 2015
New Revision: 1659719

URL: http://svn.apache.org/r1659719
Log:
SCXML-225: applying Franck Foutou's patch. Also added a unit test for this 
patch.

Added:
    
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/SendTest.java
    
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/send-test-01.xml
Modified:
    
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Send.java
    
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/SCXMLTestHelper.java

Modified: 
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Send.java
URL: 
http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Send.java?rev=1659719&r1=1659718&r2=1659719&view=diff
==============================================================================
--- 
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Send.java
 (original)
+++ 
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Send.java
 Fri Feb 13 23:51:13 2015
@@ -16,7 +16,7 @@
  */
 package org.apache.commons.scxml2.model;
 
-import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.Map;
 
 import org.apache.commons.logging.Log;
@@ -386,7 +386,7 @@ public class Send extends NamelistHolder
             typeValue = SCXMLIOProcessor.DEFAULT_EVENT_PROCESSOR;
         }
         Object payload = null;
-        Map<String, Object> payloadDataMap = new HashMap<String, Object>();
+        Map<String, Object> payloadDataMap = new LinkedHashMap<String, 
Object>();
         addNamelistDataToPayload(exctx, payloadDataMap);
         addParamsToPayload(exctx, payloadDataMap);
         if (!payloadDataMap.isEmpty()) {

Modified: 
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/SCXMLTestHelper.java
URL: 
http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/SCXMLTestHelper.java?rev=1659719&r1=1659718&r2=1659719&view=diff
==============================================================================
--- 
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/SCXMLTestHelper.java
 (original)
+++ 
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/SCXMLTestHelper.java
 Fri Feb 13 23:51:13 2015
@@ -103,11 +103,11 @@ public class SCXMLTestHelper {
         return getExecutor(parse(url), null);
     }
 
-    public static SCXMLExecutor getExecutor(String scxmlResource) throws 
Exception {
+    public static SCXMLExecutor getExecutor(final String scxmlResource) throws 
Exception {
         return getExecutor(parse(scxmlResource), null);
     }
 
-    public static SCXMLExecutor getExecutor(SCXML scxml) throws Exception {
+    public static SCXMLExecutor getExecutor(final SCXML scxml) throws 
Exception {
         return getExecutor(scxml, null);
     }
 
@@ -115,9 +115,13 @@ public class SCXMLTestHelper {
         return getExecutor(parse(url), evaluator);
     }
 
-    public static SCXMLExecutor getExecutor(SCXML scxml, Evaluator evaluator) 
throws Exception {
+    public static SCXMLExecutor getExecutor(final SCXML scxml, final Evaluator 
evaluator) throws Exception {
+        return getExecutor(scxml, evaluator, new SimpleDispatcher());
+    }
+
+    public static SCXMLExecutor getExecutor(final SCXML scxml, final Evaluator 
evaluator, final EventDispatcher eventDispatcher) throws Exception {
         Tracer trc = new Tracer();
-        SCXMLExecutor exec = new SCXMLExecutor(evaluator, new 
SimpleDispatcher(), trc);
+        SCXMLExecutor exec = new SCXMLExecutor(evaluator, eventDispatcher, 
trc);
         exec.setStateMachine(scxml);
         exec.addListener(scxml, trc);
         return exec;

Added: 
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/SendTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/SendTest.java?rev=1659719&view=auto
==============================================================================
--- 
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/SendTest.java
 (added)
+++ 
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/SendTest.java
 Fri Feb 13 23:51:13 2015
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.scxml2.model;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.scxml2.SCXMLExecutor;
+import org.apache.commons.scxml2.SCXMLIOProcessor;
+import org.apache.commons.scxml2.SCXMLTestHelper;
+import org.apache.commons.scxml2.TriggerEvent;
+import org.apache.commons.scxml2.env.SimpleDispatcher;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class SendTest {
+
+    @Test
+    public void testNamelistOrderPreserved() throws Exception {
+        final List<Object> payloads = new ArrayList<Object>();
+        final SCXML scxml = 
SCXMLTestHelper.parse("org/apache/commons/scxml2/model/send-test-01.xml");
+        final SCXMLExecutor exec = SCXMLTestHelper.getExecutor(scxml, null, 
new SimpleDispatcher() {
+            @Override
+            public void send(final Map<String, SCXMLIOProcessor> ioProcessors, 
final String id, final String target,
+                    final String type, final String event, final Object data, 
final Object hints, final long delay) {
+                payloads.add(data);
+                super.send(ioProcessors, id, target, type, event, data, hints, 
delay);
+            }
+        });
+        exec.go();
+        TriggerEvent te = new TriggerEvent("event.foo", 
TriggerEvent.SIGNAL_EVENT, new Integer(3));
+        SCXMLTestHelper.fireEvent(exec, te);
+
+        Assert.assertFalse("Payloads empty.", payloads.isEmpty());
+        Assert.assertTrue("Payload is not a map.", payloads.get(0) instanceof 
Map);
+        Map<String, Object> firstPayload = (Map<String, Object>) 
payloads.get(0);
+        Assert.assertEquals("Only two in the namelist data expected.", 2, 
firstPayload.size());
+
+        Assert.assertEquals("Unexpected value for 'one'.", 1.0, 
firstPayload.get("one"));
+        Assert.assertEquals("Unexpected value for 'two'.", 2.0, 
firstPayload.get("two"));
+
+        // Note: the standard allows specifying the value of the namelist 
attribute of the <send> element
+        // as space-separated list of values, which implies an ordered 
sequence of items.
+        final Iterator<String> it = firstPayload.keySet().iterator();
+        Assert.assertEquals("The first one in the namelist must be 'one'.", 
"one", it.next());
+        Assert.assertEquals("The first one in the namelist must be 'two'.", 
"two", it.next());
+    }
+}

Added: 
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/send-test-01.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/send-test-01.xml?rev=1659719&view=auto
==============================================================================
--- 
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/send-test-01.xml
 (added)
+++ 
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/model/send-test-01.xml
 Fri Feb 13 23:51:13 2015
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+<scxml xmlns="http://www.w3.org/2005/07/scxml";
+       xmlns:cs="http://commons.apache.org/scxml";
+       version="1.0"
+       datamodel="jexl"
+       initial="ten">
+
+    <datamodel>
+        <data id="rootdata">
+            <root xmlns="">
+                <one>1</one>
+                <two>2</two>
+            </root>
+        </data>
+    </datamodel>
+
+    <state id="ten">
+        <transition event="event.foo" target="twenty"/>
+    </state>
+
+    <state id="twenty">
+        <onentry>
+            <cs:var name="one" expr="Data('number($rootdata/root/one)')"/>
+            <cs:var name="two" expr="Data('number($rootdata/root/two)')"/>
+            <send event="event.bar" namelist="one two"/>
+        </onentry>
+        <transition event="event.bar"
+            cond="_event.data.one + _event.data.two eq 3"
+            target="thirty"/>
+    </state>
+
+    <final id="thirty"/>
+
+</scxml>


Reply via email to