Author: rahul
Date: Tue Mar 28 15:50:38 2006
New Revision: 389631

URL: http://svn.apache.org/viewcvs?rev=389631&view=rev
Log:
 * Unnamed events are not ignored, came out of test cases from Heiko Eichberger 
(Heiko dot Eichberger AT rsbick.rohde-schwarz DOT com).

 * Add slightly modified versions of Heiko's tests to the Commons SCXML test 
suite.

 * Add Heiko to the contributors section in POM.

Added:
    
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/WizardsTest.java
   (with props)
    
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wizard-01.xml
   (with props)
    
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wizard-02.xml
   (with props)
Modified:
    jakarta/commons/sandbox/scxml/trunk/project.xml
    
jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
    
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLTestSuite.java

Modified: jakarta/commons/sandbox/scxml/trunk/project.xml
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/project.xml?rev=389631&r1=389630&r2=389631&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/project.xml (original)
+++ jakarta/commons/sandbox/scxml/trunk/project.xml Tue Mar 28 15:50:38 2006
@@ -93,6 +93,9 @@
     <contributor>
       <name>Wendy Smoak</name>
     </contributor>
+    <contributor>
+      <name>Heiko Eichberger</name>
+    </contributor>
   </contributors>
   
   <dependencies>

Modified: 
jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java?rev=389631&r1=389630&r2=389631&view=diff
==============================================================================
--- 
jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
 (original)
+++ 
jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
 Tue Mar 28 15:50:38 2006
@@ -602,9 +602,11 @@
             Iterator i = eventOccurrences.iterator();
             while (i.hasNext()) {
                 String evt = (String) i.next();
-                if (evt == null || evt.equals(transEvent) //null for Standalone
-                    || evt.startsWith(transEventDot)) {
-                        return true;
+                if (evt == null) {
+                    continue; // Unnamed events
+                } else if (evt.equals(transEvent)
+                            || evt.startsWith(transEventDot)) {
+                    return true;
                 }
             }
             return false;

Modified: 
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLTestSuite.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLTestSuite.java?rev=389631&r1=389630&r2=389631&view=diff
==============================================================================
--- 
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLTestSuite.java
 (original)
+++ 
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLTestSuite.java
 Tue Mar 28 15:50:38 2006
@@ -52,6 +52,7 @@
         suite.addTest(SCXMLHelperTest.suite());
         suite.addTest(StatusTest.suite());
         suite.addTest(TriggerEventTest.suite());
+        suite.addTest(WizardsTest.suite());
         return suite;
     }
 }

Added: 
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/WizardsTest.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/WizardsTest.java?rev=389631&view=auto
==============================================================================
--- 
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/WizardsTest.java
 (added)
+++ 
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/WizardsTest.java
 Tue Mar 28 15:50:38 2006
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.scxml;
+
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.apache.commons.scxml.env.Tracer;
+import org.apache.commons.scxml.env.jexl.JexlContext;
+import org.apache.commons.scxml.env.jexl.JexlEvaluator;
+import org.apache.commons.scxml.model.SCXML;
+import org.apache.commons.scxml.model.State;
+/**
+ * Unit tests [EMAIL PROTECTED] org.apache.commons.scxml.SCXMLExecutor}.
+ */
+public class WizardsTest extends TestCase {
+    /**
+     * Construct a new instance of SCXMLExecutorTest with
+     * the specified name
+     */
+    public WizardsTest(String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite(WizardsTest.class);
+        suite.setName("SCXML Executor Tests, Wizard Style documents");
+        return suite;
+    }
+
+    // Test data
+    private URL wizard01, wizard02;
+    private SCXMLExecutor exec;
+
+    /**
+     * Set up instance variables required by this test case.
+     */
+    public void setUp() {
+        wizard01 = this.getClass().getClassLoader().
+            getResource("org/apache/commons/scxml/env/jexl/wizard-01.xml");
+        wizard02 = this.getClass().getClassLoader().
+            getResource("org/apache/commons/scxml/env/jexl/wizard-02.xml");
+    }
+
+    /**
+     * Tear down instance variables required by this test case.
+     */
+    public void tearDown() {
+        wizard01 = wizard02 = null;
+    }
+
+    /**
+     * Test the wizard style SCXML documents, and send usage
+     */
+    public void testWizard01Sample() {
+       exec = SCXMLTestHelper.getExecutor(wizard01);
+        assertNotNull(exec);
+        try {
+            Set currentStates = exec.getCurrentStatus().getStates();
+            assertEquals(1, currentStates.size());
+            assertEquals("state1", ((State)currentStates.iterator().
+                next()).getId());
+            currentStates = fireEvent("event2");
+            assertEquals(1, currentStates.size());
+            assertEquals("state2", ((State)currentStates.iterator().
+                next()).getId());
+            currentStates = fireEvent("event4");
+            assertEquals(1, currentStates.size());
+            assertEquals("state4", ((State)currentStates.iterator().
+                next()).getId());
+            currentStates = fireEvent("event3");
+            assertEquals(1, currentStates.size());
+            assertEquals("state3", ((State)currentStates.iterator().
+                next()).getId());
+            currentStates = fireEvent("event3"); // ensure we stay put
+            assertEquals(1, currentStates.size());
+            assertEquals("state3", ((State)currentStates.iterator().
+                next()).getId());
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+    }
+
+    public void testWizard02Sample() {
+        SCXML scxml = SCXMLTestHelper.digest(wizard02);
+        exec = SCXMLTestHelper.getExecutor(new JexlContext(),
+            new JexlEvaluator(), scxml, new TestEventDispatcher(),
+            new Tracer());
+        assertNotNull(exec);
+        try {
+            // If you change this, you must also change
+            // the TestEventDispatcher
+            Set currentStates = exec.getCurrentStatus().getStates();
+            assertEquals(1, currentStates.size());
+            assertEquals("state2", ((State)currentStates.iterator().
+                next()).getId());
+            currentStates = fireEvent("event4");
+            assertEquals(1, currentStates.size());
+            assertEquals("state4", ((State)currentStates.iterator().
+                next()).getId());
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+    }
+
+    class TestEventDispatcher implements EventDispatcher {
+        // If you change this, you must also change testWizard02Sample()
+        int callback = 0;
+        public void send(String sendId, String target, String targetType,
+                String event, Map params, Object hints, long delay,
+                List externalNodes) {
+            int i = ((Integer) params.get("aValue")).intValue();
+            switch (callback) {
+                case 0:
+                    assertTrue(i == 2); // state2
+                    callback++;
+                    break;
+                case 1:
+                    assertTrue(i == 4); // state4
+                    callback++;
+                    break;
+                default:
+                    fail("More than 2 TestEventDispatcher <send> callbacks");
+            }
+        }
+        public void cancel(String sendId) {
+            // should never be called
+            fail("<cancel> TestEventDispatcher callback unexpected");
+        }
+    }
+
+    private Set fireEvent(String name) {
+        TriggerEvent[] evts = {new TriggerEvent(name,
+                TriggerEvent.SIGNAL_EVENT, null)};
+        try {
+            exec.triggerEvents(evts);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        return exec.getCurrentStatus().getStates();
+    }
+
+    public static void main(String args[]) {
+        TestRunner.run(suite());
+    }
+}

Propchange: 
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/WizardsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/WizardsTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wizard-01.xml
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wizard-01.xml?rev=389631&view=auto
==============================================================================
--- 
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wizard-01.xml
 (added)
+++ 
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wizard-01.xml
 Tue Mar 28 15:50:38 2006
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   Copyright 2006 The Apache Software Foundation
+
+   Licensed 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";
+      version="1.0"
+      initialstate="state1">
+     <state id="state1">
+           <transition event="event2" target="state2"/>
+           <transition event="event3" target="state3"/>
+           <transition event="event4" target="state4"/>
+     </state>
+     <state id="state2">
+           <transition event="event1" target="state1"/>
+           <transition event="event3" target="state3"/>
+           <transition event="event4" target="state4"/>
+     </state>
+     <state id="state3">
+           <transition event="event1" target="state1"/>
+           <transition event="event2" target="state2"/>
+           <transition event="event4" target="state4"/>
+     </state>
+     <state id="state4">
+           <transition event="event1" target="state1"/>
+           <transition event="event2" target="state2"/>
+           <transition event="event3" target="state3"/>
+     </state>
+</scxml>

Propchange: 
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wizard-01.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wizard-01.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wizard-02.xml
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wizard-02.xml?rev=389631&view=auto
==============================================================================
--- 
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wizard-02.xml
 (added)
+++ 
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wizard-02.xml
 Tue Mar 28 15:50:38 2006
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   Copyright 2006 The Apache Software Foundation
+
+   Licensed 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";
+      version="1.0"
+      initialstate="state1">
+     <state id="state1">
+           <onentry>
+                 <!-- Send without a targettype causes the
+                      default to be chosen as "scxml".
+                      This will cause the first transition
+                      to state2 to be immediately followed. -->
+                 <send event="event2" />
+           </onentry>
+           <transition event="event2" target="state2"/>
+           <transition event="event3" target="state3"/>
+           <transition event="event4" target="state4"/>
+     </state>
+     <state id="state2">
+           <onentry>
+                 <var name="aValue" expr="2"/>
+                 <!-- Send with a non-empty (and not "scxml")
+                      targettype causes the callback on the
+                      EventDispatcher implementation. See
+                      testWizard02Sample() in WizardsTest
+                      (org.apache.commons.scxml test package) -->
+                 <send namelist="aValue" targettype="foo" />
+           </onentry>
+           <transition event="event1" target="state1"/>
+           <transition event="event3" target="state3"/>
+           <transition event="event4" target="state4"/>
+     </state>
+     <state id="state3">
+           <onentry>
+                 <var name="aValue" expr="3"/>
+                 <send namelist="aValue" targettype="foo" />
+           </onentry>
+           <transition event="event1" target="state1"/>
+           <transition event="event2" target="state2"/>
+           <transition event="event4" target="state4"/>
+     </state>
+     <state id="state4">
+           <onentry>
+                 <var name="aValue" expr="4"/>
+                 <send namelist="aValue" targettype="foo" />
+           </onentry>
+           <transition event="event1" target="state1"/>
+           <transition event="event2" target="state2"/>
+           <transition event="event3" target="state3"/>
+     </state>
+</scxml>

Propchange: 
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wizard-02.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
jakarta/commons/sandbox/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/wizard-02.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to