commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r600774 - in /commons/proper/scxml/trunk/src: main/java/org/apache/commons/scxml/ test/java/org/apache/commons/scxml/ test/java/org/apache/commons/scxml/model/
Date Tue, 04 Dec 2007 03:21:48 GMT
Author: rahul
Date: Mon Dec  3 19:21:47 2007
New Revision: 600774

URL: http://svn.apache.org/viewvc?rev=600774&view=rev
Log:
SCXML-54 Events from custom actions missing payload
Initial version of testcases thanks to Mike Tillberg <mtillberg at comcast dot net>

Added:
    commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/custom-hello-world-04-el.xml
  (with props)
    commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/custom-hello-world-04-jexl.xml
  (with props)
Modified:
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/SCXMLExecutor.java
    commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/CustomActionTest.java
    commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/Hello.java

Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/SCXMLExecutor.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/SCXMLExecutor.java?rev=600774&r1=600773&r2=600774&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/SCXMLExecutor.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/SCXMLExecutor.java Mon
Dec  3 19:21:47 2007
@@ -548,19 +548,21 @@
         Context rootCtx = scInstance.getRootContext();
         Object[] oldData = {rootCtx.get(EVENT_DATA),
             rootCtx.get(EVENT_DATA_MAP)};
-        Object eventData = null;
-        Map payloadMap = new HashMap();
         int len = evts.length;
-        for (int i = 0; i < len; i++) {
-            TriggerEvent te = evts[i];
-            payloadMap.put(te.getName(), te.getPayload());
+        if (len > 0) { // 0 has retry semantics (eg: see usage in reset())
+            Object eventData = null;
+            Map payloadMap = new HashMap();
+            for (int i = 0; i < len; i++) {
+                TriggerEvent te = evts[i];
+                payloadMap.put(te.getName(), te.getPayload());
+            }
+            if (len == 1) {
+                // we have only one event
+                eventData = evts[0].getPayload();
+            }
+            rootCtx.setLocal(EVENT_DATA, eventData);
+            rootCtx.setLocal(EVENT_DATA_MAP, payloadMap);
         }
-        if (len == 1) {
-            // we have only one event
-            eventData = evts[0].getPayload();
-        }
-        rootCtx.setLocal(EVENT_DATA, eventData);
-        rootCtx.setLocal(EVENT_DATA_MAP, payloadMap);
         return oldData;
     }
 

Added: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/custom-hello-world-04-el.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/custom-hello-world-04-el.xml?rev=600774&view=auto
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/custom-hello-world-04-el.xml
(added)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/custom-hello-world-04-el.xml
Mon Dec  3 19:21:47 2007
@@ -0,0 +1,43 @@
+<?xml version="1.0"?>
+<!--
+ * 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.
+-->
+<!-- Used for CustomActionTest.java in model package -->
+<scxml xmlns="http://www.w3.org/2005/07/scxml"
+       xmlns:my="http://my.custom-actions.domain/CUSTOM"
+       version="1.0" initialstate="init">
+    <datamodel>
+        <data name="helloName1" />
+    </datamodel>
+
+    <state id="init">        
+        <onentry>
+            <my:hello name="custom04" />
+        </onentry>
+
+        <transition event="helloevent" target="middle1">
+            <assign name="helloName1" expr="${_eventdatamap.helloevent}" />
+        </transition>
+    </state>
+
+    <state id="middle1">
+        <transition target="custom" cond="${helloName1 eq 'custom04'}" />
+    </state>
+
+    <state id="custom" final="true"/>
+
+</scxml>
+

Propchange: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/custom-hello-world-04-el.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/custom-hello-world-04-el.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/custom-hello-world-04-jexl.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/custom-hello-world-04-jexl.xml?rev=600774&view=auto
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/custom-hello-world-04-jexl.xml
(added)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/custom-hello-world-04-jexl.xml
Mon Dec  3 19:21:47 2007
@@ -0,0 +1,61 @@
+<?xml version="1.0"?>
+<!--
+ * 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.
+-->
+<!-- Used for CustomActionTest.java in model package -->
+<scxml xmlns="http://www.w3.org/2005/07/scxml"
+       xmlns:my="http://my.custom-actions.domain/CUSTOM"
+       version="1.0" initialstate="init">
+    <datamodel>
+        <data name="helloName1" />
+    </datamodel>
+
+    <state id="init">        
+        <onentry>
+            <my:hello name="custom04a" />
+        </onentry>
+
+        <transition event="helloevent" target="middle1">
+            <assign name="helloName1" expr="_eventdatamap['helloevent']" />
+        </transition>
+    </state>
+
+    <state id="middle1">
+        <transition target="custom1" cond="helloName1 eq 'custom04a'" />
+    </state>
+
+    <state id="custom1">
+        <transition event="custom.next" target="custom2"/>
+    </state>
+
+    <state id="custom2">        
+        <onentry>
+            <my:hello name="custom04b" />
+        </onentry>
+
+        <transition event="helloevent" target="custom3">
+            <assign name="helloName1" expr="_eventdatamap.helloevent" />
+        </transition>
+    </state>
+
+    <state id="custom3">
+        <transition target="end" cond="helloName1 eq 'custom04b'" />
+    </state>
+
+    <state id="end" final="true"/>
+
+</scxml>
+

Propchange: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/custom-hello-world-04-jexl.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/custom-hello-world-04-jexl.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/CustomActionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/CustomActionTest.java?rev=600774&r1=600773&r2=600774&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/CustomActionTest.java
(original)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/CustomActionTest.java
Mon Dec  3 19:21:47 2007
@@ -26,6 +26,7 @@
 
 import org.apache.commons.scxml.SCXMLExecutor;
 import org.apache.commons.scxml.SCXMLTestHelper;
+import org.apache.commons.scxml.env.jsp.ELEvaluator;
 
 public class CustomActionTest extends TestCase {
 
@@ -42,7 +43,7 @@
         junit.textui.TestRunner.main(testCaseName);
     }
 
-    private URL hello01, custom01, external01, override01;
+    private URL hello01, custom01, external01, override01, payload01, payload02;
     private SCXMLExecutor exec;
 
     /**
@@ -57,13 +58,17 @@
             getResource("org/apache/commons/scxml/external-hello-world.xml");
         override01 = this.getClass().getClassLoader().
             getResource("org/apache/commons/scxml/custom-hello-world-03.xml");
+        payload01 = this.getClass().getClassLoader().
+            getResource("org/apache/commons/scxml/custom-hello-world-04-jexl.xml");
+        payload02 = this.getClass().getClassLoader().
+            getResource("org/apache/commons/scxml/custom-hello-world-04-el.xml");
     }
 
     /**
      * Tear down instance variables required by this test case.
      */
     public void tearDown() {
-        hello01 = custom01 = external01 = null;
+        hello01 = custom01 = external01 = payload01 = payload02 = null;
         exec = null;
     }
 
@@ -210,6 +215,61 @@
     // to execute() exactly 5 times upto this point
     public void testCustomActionCallbacks() {
         assertEquals(5, Hello.callbacks);
+    }
+
+    // Hello World example using custom <my:hello> action that generates an
+    // event which has the payload examined with JEXL expressions
+    public void testCustomActionEventPayloadHelloWorldJexl() {
+        // (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 customActions = new ArrayList();
+        customActions.add(ca);
+        // (2) Parse the document with a custom digester.
+        SCXML scxml = SCXMLTestHelper.digest(payload01, customActions);
+        // (3) Get a SCXMLExecutor
+        exec = SCXMLTestHelper.getExecutor(scxml);
+        // (4) Single, final state
+        assertEquals("Invalid intermediate state",
+                     "custom1", ((State) exec.getCurrentStatus().getStates().
+                                iterator().next()).getId());
+        // (5) Verify datamodel variable is correct
+        assertEquals("Missing helloName1 in root context", "custom04a",
+                     (String) exec.getRootContext().get("helloName1"));
+        // (6) Check use of payload in non-initial state
+        SCXMLTestHelper.fireEvent(exec, "custom.next");
+        // (7) Verify correct end state
+        assertEquals("Missing helloName1 in root context", "custom04b",
+                (String) exec.getRootContext().get("helloName1"));
+        assertEquals("Invalid final state",
+                "end", ((State) exec.getCurrentStatus().getStates().
+                iterator().next()).getId());
+        assertTrue(exec.getCurrentStatus().isFinal());
+    }
+
+    // Hello World example using custom <my:hello> action that generates an
+    // event which has the payload examined with EL expressions
+    public void testCustomActionEventPayloadHelloWorldEL() {
+        // (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 customActions = new ArrayList();
+        customActions.add(ca);
+        // (2) Parse the document with a custom digester.
+        SCXML scxml = SCXMLTestHelper.digest(payload02, customActions);
+        // (3) Get a SCXMLExecutor
+        exec = SCXMLTestHelper.getExecutor(new ELEvaluator(), scxml);
+        // (4) Single, final state
+        assertEquals("Invalid final state",
+                     "custom", ((State) exec.getCurrentStatus().getStates().
+                                iterator().next()).getId());
+        // (5) Verify datamodel variable is correct
+        assertEquals("Missing helloName1 in root context", "custom04",
+                     (String) exec.getRootContext().get("helloName1"));
     }
 
 }

Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/Hello.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/Hello.java?rev=600774&r1=600773&r2=600774&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/Hello.java (original)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/Hello.java Mon
Dec  3 19:21:47 2007
@@ -23,7 +23,7 @@
 import org.apache.commons.scxml.EventDispatcher;
 import org.apache.commons.scxml.SCInstance;
 import org.apache.commons.scxml.SCXMLExpressionException;
-import org.apache.commons.scxml.model.Action;
+import org.apache.commons.scxml.TriggerEvent;
 
 /**
  * Our custom &quot;hello world&quot; action.
@@ -70,6 +70,10 @@
         if (appLog.isInfoEnabled()) {
             appLog.info("Hello " + name);
         }
+        // For derived events payload testing
+        TriggerEvent event =
+            new TriggerEvent("helloevent", TriggerEvent.SIGNAL_EVENT, name);
+        derivedEvents.add(event);
         callbacks++;
     }
 }



Mime
View raw message