Author: ate
Date: Fri Jan 17 15:26:38 2014
New Revision: 1559147

URL: http://svn.apache.org/r1559147
Log:
SCXML-186: Groovy Expression evaluator support
- complete (albeit simple) test of the whole of this feature, using:
  - an initial script to define dynamic classes and functions
  - leveraging the initial script as base class and thereby providing its 
custom functions to child element script or condition evaluation
  - test and validate everything above is serializable

Added:
    
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/env/groovy/SerializableInitialBaseScriptTest.java
   (with props)
    
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/env/groovy/serializable-initial-base-script.xml
   (with props)

Added: 
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/env/groovy/SerializableInitialBaseScriptTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/env/groovy/SerializableInitialBaseScriptTest.java?rev=1559147&view=auto
==============================================================================
--- 
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/env/groovy/SerializableInitialBaseScriptTest.java
 (added)
+++ 
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/env/groovy/SerializableInitialBaseScriptTest.java
 Fri Jan 17 15:26:38 2014
@@ -0,0 +1,72 @@
+/*
+ * 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.env.groovy;
+
+import java.net.URL;
+import java.util.Set;
+
+import org.apache.commons.scxml2.SCXMLExecutor;
+import org.apache.commons.scxml2.SCXMLTestHelper;
+import org.apache.commons.scxml2.model.TransitionTarget;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Unit tests {@link org.apache.commons.scxml2.SCXMLExecutor}.
+ * Testing Groovy initial base script usage and validating serializable
+ */
+public class SerializableInitialBaseScriptTest {
+
+    // Test data
+    private URL scxml;
+    private SCXMLExecutor exec;
+
+    /**
+     * Set up instance variables required by this test case.
+     */
+    @Before
+    public void setUp() {
+        scxml = this.getClass().getClassLoader().
+            
getResource("org/apache/commons/scxml2/env/groovy/serializable-initial-base-script.xml");
+    }
+
+    /**
+     * Tear down instance variables required by this test case.
+     */
+    @After
+    public void tearDown() {
+        scxml = null;
+    }
+
+    /**
+     * Testing Groovy initial base script usage and validating serializable
+     */
+    @Test
+    public void testSerializableInitialBaseScriptSample() throws Exception {
+       exec = SCXMLTestHelper.getExecutor(scxml, new GroovyContext(), new 
GroovyEvaluator(true));
+        Assert.assertNotNull(exec);
+        Set<TransitionTarget> currentStates = 
exec.getCurrentStatus().getStates();
+        Assert.assertEquals(1, currentStates.size());
+        Assert.assertEquals("state1", currentStates.iterator().next().getId());
+        exec = SCXMLTestHelper.testExecutorSerializability(exec);
+        currentStates = SCXMLTestHelper.fireEvent(exec, "foo.bar.baz");
+        Assert.assertEquals(1, currentStates.size());
+        Assert.assertEquals("state4", currentStates.iterator().next().getId());
+    }
+}

Propchange: 
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/env/groovy/SerializableInitialBaseScriptTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/env/groovy/SerializableInitialBaseScriptTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/env/groovy/serializable-initial-base-script.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/env/groovy/serializable-initial-base-script.xml?rev=1559147&view=auto
==============================================================================
--- 
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/env/groovy/serializable-initial-base-script.xml
 (added)
+++ 
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/env/groovy/serializable-initial-base-script.xml
 Fri Jan 17 15:26:38 2014
@@ -0,0 +1,54 @@
+<?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.
+-->
+<!--
+ This document uses Groovy as the expressions language.
+-->
+<scxml xmlns="http://www.w3.org/2005/07/scxml";
+       xmlns:cs="http://commons.apache.org/scxml";
+       version="1.0"
+       initial="state1">
+  <script>
+    class Target implements Serializable {
+    private static final long serialVersionUID = 1L;
+    int val;
+    }
+    def targets(val) {
+    return target.val eq val;
+    }
+    target = new Target(val: 5)
+  </script>
+  <state id="state1">
+    <onentry>
+      <!-- More appropriate to use the script below to change target value 
instead of (mis)using an
+           expression with a modifying side-effect, but the var assignment 
would work also.
+      <cs:var name="target" expr="target.val=4;return target" />
+      -->
+      <script>
+        target.val = 4;
+      </script>
+    </onentry>
+    <!-- We'll trigger 'foo.bar.baz' event,
+         and therefore, must end up in state4 -->
+    <transition event="*" cond="targets(2)" target="state2"/>
+    <transition event="foo.*" cond="targets(3)" target="state3"/>
+    <transition event="foo.bar.*" cond="targets(4)" target="state4"/>
+  </state>
+  <state id="state2" final="true"/>
+  <state id="state3" final="true"/>
+  <state id="state4" final="true"/>
+</scxml>

Propchange: 
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/env/groovy/serializable-initial-base-script.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/env/groovy/serializable-initial-base-script.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: 
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/env/groovy/serializable-initial-base-script.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to