Author: jbeard
Date: Sat Jul 31 22:33:38 2010
New Revision: 981098

URL: http://svn.apache.org/viewvc?rev=981098&view=rev
Log:
Refined templates, added test.

Added:
    
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/send/
    
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/send/TestSend.xml
   (with props)
    
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/send/scripts/
    
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/send/scripts/unitTest.js
   (with props)
Modified:
    
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/genMessageTemplates.xsl
    
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/sendToMessageTemplate.xsl

Modified: 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/genMessageTemplates.xsl
URL: 
http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/genMessageTemplates.xsl?rev=981098&r1=981097&r2=981098&view=diff
==============================================================================
--- 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/genMessageTemplates.xsl
 (original)
+++ 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/genMessageTemplates.xsl
 Sat Jul 31 22:33:38 2010
@@ -22,64 +22,76 @@
        xmlns:c="http://commons.apache.org/scxml-js";
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
        version="1.0">
-    <xsl:output method="xml"/>
-    
-    <xsl:template match="c:messageTemplate">
-        <xsl:text>function(</xsl:text>
-        <xsl:for-each select=".//c:param">
-            <xsl:value-of select="@name"/>
-            <xsl:if test="not(position() = last())">
-                <xsl:text>,</xsl:text>
-            </xsl:if>
-        </xsl:for-each>
-        <xsl:text>){</xsl:text>
-        <xsl:text>return &apos;</xsl:text><xsl:apply-templates 
select="node()"/>
-        <xsl:text>&apos;</xsl:text>
-        <xsl:text>}</xsl:text>
-    </xsl:template>
-    
-    <!-- from: 
http://stackoverflow.com/questions/1162352/converting-xml-to-escaped-text-in-xslt
 -->
-    <xsl:template match="*" mode="escape">
-        <!-- Begin opening tag -->
-        <xsl:text>&lt;</xsl:text>
-        <xsl:value-of select="name()"/>
-        
-        <!-- Namespaces -->
-        <xsl:for-each select="namespace::*">
-            <xsl:text> xmlns</xsl:text>
-            <xsl:if test="name() != ''">
-                <xsl:text>:</xsl:text>
-                <xsl:value-of select="name()"/>
-            </xsl:if>
-            <xsl:text>='</xsl:text>
-            <xsl:call-template name="escape-xml">
-                <xsl:with-param name="text" select="."/>
-            </xsl:call-template>
-            <xsl:text>'</xsl:text>
-        </xsl:for-each>
-        
-        <!-- Attributes -->
-        <xsl:for-each select="@*">
-            <xsl:text> </xsl:text>
-            <xsl:value-of select="name()"/>
-            <xsl:text>='</xsl:text>
-            <xsl:call-template name="escape-xml">
-                <xsl:with-param name="text" select="."/>
-            </xsl:call-template>
-            <xsl:text>'</xsl:text>
-        </xsl:for-each>
-        
-        <!-- End opening tag -->
-        <xsl:text>&gt;</xsl:text>
-        
-        <!-- Content (child elements, text nodes, and PIs) -->
-        <xsl:apply-templates select="node()" mode="escape" />
-        
-        <!-- Closing tag -->
-        <xsl:text>&lt;/</xsl:text>
-        <xsl:value-of select="name()"/>
-        <xsl:text>&gt;</xsl:text>
-    </xsl:template>
-    
-    
+       <xsl:output method="text"/>
+
+       <xsl:template match="send">
+               <xsl:text>send(</xsl:text>
+                       <xsl:apply-templates select="c:messageTemplate"/>,
+                       <xsl:text>&apos;</xsl:text><xsl:value-of 
select="@target"/><xsl:text>&apos;</xsl:text>
+               <xsl:text>)</xsl:text>
+       </xsl:template>
+               
+       <xsl:template match="c:messageTemplate">
+               <xsl:text>return &apos;</xsl:text><xsl:apply-templates 
select="*"/> <xsl:text>&apos;</xsl:text>
+       </xsl:template>
+
+       <xsl:template match="c:name">
+               <xsl:text>&apos; + </xsl:text>
+                       <xsl:value-of select="@name"/>
+               <xsl:text> + apos;</xsl:text>
+       </xsl:template>
+
+       <xsl:template match="c:param">
+               <xsl:text>&apos; + </xsl:text>
+                       <xsl:value-of select="@name"/>
+                       <xsl:if test="@expr">
+                               || <xsl:value-of select="@expr"/>
+                       </xsl:if>
+               <xsl:text> + apos;</xsl:text>
+       </xsl:template>
+       
+       <!-- from: 
http://stackoverflow.com/questions/1162352/converting-xml-to-escaped-text-in-xslt
 -->
+       <xsl:template match="*" mode="escape">
+               <!-- Begin opening tag -->
+               <xsl:text>&lt;</xsl:text>
+               <xsl:value-of select="name()"/>
+               
+               <!-- Namespaces -->
+               <xsl:for-each select="namespace::*">
+                       <xsl:text> xmlns</xsl:text>
+                       <xsl:if test="name() != ''">
+                               <xsl:text>:</xsl:text>
+                               <xsl:value-of select="name()"/>
+                       </xsl:if>
+                       <xsl:text>='</xsl:text>
+                       <xsl:call-template name="escape-xml">
+                                       <xsl:with-param name="text" select="."/>
+                       </xsl:call-template>
+                       <xsl:text>'</xsl:text>
+               </xsl:for-each>
+               
+               <!-- Attributes -->
+               <xsl:for-each select="@*">
+                       <xsl:text> </xsl:text>
+                       <xsl:value-of select="name()"/>
+                       <xsl:text>='</xsl:text>
+                       <xsl:call-template name="escape-xml">
+                                       <xsl:with-param name="text" select="."/>
+                       </xsl:call-template>
+                       <xsl:text>'</xsl:text>
+               </xsl:for-each>
+               
+               <!-- End opening tag -->
+               <xsl:text>&gt;</xsl:text>
+               
+               <!-- Content (child elements, text nodes, and PIs) -->
+               <xsl:apply-templates select="node()" mode="escape" />
+               
+               <!-- Closing tag -->
+               <xsl:text>&lt;/</xsl:text>
+               <xsl:value-of select="name()"/>
+               <xsl:text>&gt;</xsl:text>
+       </xsl:template>
+               
+               
 </xsl:stylesheet>

Modified: 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/sendToMessageTemplate.xsl
URL: 
http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/sendToMessageTemplate.xsl?rev=981098&r1=981097&r2=981098&view=diff
==============================================================================
--- 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/sendToMessageTemplate.xsl
 (original)
+++ 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/src/xslt/ir-compiler/external_communications/sendToMessageTemplate.xsl
 Sat Jul 31 22:33:38 2010
@@ -91,11 +91,18 @@
                                                                
<xsl:apply-templates select="content"/>
                                                        </xsl:when>
                                                        <xsl:otherwise>
-                                                               <xsl:for-each 
select="c:namelist/c:name | param/@name">
+                                                               <xsl:for-each 
select="c:namelist/c:name">
                                                                        
<property name="{.}">
                                                                                
<c:param name="{.}"/>
                                                                        
</property>
-                                                               </xsl:for-each>
+                                                               </xsl:for-each> 
+                                                               <xsl:for-each 
select="param/@name">
+                                                                       
<property name="{.}">
+                                                                               
<c:name name="{.}"/>
+                                                                       
</property>
+                                                               </xsl:for-each> 
+
+
                                                        </xsl:otherwise>
                                                </xsl:choose>
                                        </payload>

Added: 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/send/TestSend.xml
URL: 
http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/send/TestSend.xml?rev=981098&view=auto
==============================================================================
--- 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/send/TestSend.xml
 (added)
+++ 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/send/TestSend.xml
 Sat Jul 31 22:33:38 2010
@@ -0,0 +1,101 @@
+<?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";
+       version="1.0"
+       profile="ecmascript">
+
+       <initial>
+               <transition target="a1"/>
+       </initial>
+
+       <datamodel>
+               <data id="foo" expr="'foo'"/>
+               <data id="bar" expr="1"/>
+               <data id="bat"/>
+       </datamodel>
+
+       <!-- given event foo.bar, foo should be selected, and we should end in 
state b1-->
+       <state id="a">
+               <transition id="b2" event="t1">
+                       <send target="http://www.google.com"/>
+               </transition>
+       </state>
+
+       <state id="b">
+               <transition id="c" event="t2">
+                       <send target="http://www.google.com"; namelist="foo 
bar"/>
+               </transition>
+       </state>
+
+       <state id="c">
+               <transition id="d" event="t3">
+                       <!-- namelist foo should take priority over param foo,
+                               default expression in bar should be ignored, as 
it's already defined in the data model,
+                               and bat is not defined, so should here use the 
value 'default3' --> 
+                       <send target="http://www.google.com"; namelist="foo">
+                               <param name="foo" expr="'default1'"/>
+                               <param name="bar" expr="'default2'"/>
+                               <param name="bat" expr="'default3'"/>
+                       </send>
+               </transition>
+       </state>
+       
+       <state id="d">
+               <transition id="e" event="t4">
+                       <!-- try with JSON data -->
+                       <send target="http://www.google.com";>
+                               <content><![CDATA[
+                                       {
+                                               foo : 'foo',    
+                                               bar : 1,
+                                               woot : true
+                                       }
+                               ]]></content>
+                       </send>
+               </transition>
+       </state>
+
+       <state id="e">
+               <transition id="f" event="t5">
+                       <!-- try it with some arbirary XML content, here a bit 
of XSL -->
+                       <send target="http://www.google.com";>
+                               <content>
+                                       <xsl:stylesheet 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
+                                               
xmlns:s="http://www.w3.org/2005/07/scxml";
+                                               
xmlns="http://www.w3.org/2005/07/scxml";
+                                               
xmlns:c="http://commons.apache.org/scxml-js";
+                                               
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+                                               version="1.0">
+                                               <xsl:output method="text"/>
+
+                                               <xsl:template match="send">
+                                                       
<xsl:text>send(</xsl:text>
+                                                               
<xsl:apply-templates select="c:messageTemplate"/>,
+                                                               
<xsl:text>&apos;</xsl:text><xsl:value-of 
select="@target"/><xsl:text>&apos;</xsl:text>
+                                                       <xsl:text>)</xsl:text>
+                                               </xsl:template>
+                                       </xsl:stylesheet>
+                               </content>
+                       </send>
+               </transition>
+       </state>
+
+       <state id="f">
+       </state>
+</scxml>

Propchange: 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/send/TestSend.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/send/scripts/unitTest.js
URL: 
http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/send/scripts/unitTest.js?rev=981098&view=auto
==============================================================================
--- 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/send/scripts/unitTest.js
 (added)
+++ 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/send/scripts/unitTest.js
 Sat Jul 31 22:33:38 2010
@@ -0,0 +1,102 @@
+/*
+ * 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.
+ */
+
+
+require.def( "test/send/scripts/unitTest",
+{
+
+       scxmlTest : "test/send/TestSend.xml",
+
+       register:function(scConstructor){
+
+               //TODO: can load this using RequireJS, so we don't need to use 
the dojo module system?
+               dojo.require("doh.runner");
+               var sc,mockComm;
+               doh.register("testExternalCommunicationsModule",[
+                               {
+                                       name:"testSend",
+                                       //timeout:5000,
+                                       setUp:function(){
+                                               //set up mock communications 
object
+                                               mockComm = {
+                                                       _lastUrl : "",
+                                                       _lastData : "",
+                                                       send : 
funciton(url,data){
+                                                               this._lastUrl = 
url;
+                                                               this._lastData 
= data;
+                                                               
console.log("data ", data);
+                                                       }
+                                               };
+                                               sc = new scConstructor(mockComm)
+                                               sc.initialize();
+                                       },
+                                       runTest:function(){
+                                               var $ = function(conf){return 
conf.map(function(s){return s.toString()})};
+
+                                               var conf;
+                                               var googleUrl = 
"http://www.google.com";;
+
+                                               conf = 
sc.getCurrentConfiguration();
+                                               console.log($(conf));
+                                               
doh.assertEqual(setwiseEqual(sc._states.a,conf[0]));
+
+                                               console.info("sending event t1")
+                                               sc.t1()
+                                               conf = 
sc.getCurrentConfiguration();
+                                               console.log($(conf));
+                                               
doh.assertEqual(setwiseEqual(sc._states.b,conf[0]));
+
+                                               
doh.assertEqual(googleUrl,mockComm._lastUrl);
+                                               
doh.assertEqual("",mockComm._lastData);
+
+
+                                               console.info("sending event t2")
+                                               sc.t2()
+                                               conf = 
sc.getCurrentConfiguration();
+                                               console.log($(conf));
+                                               
doh.assertEqual(setwiseEqual(sc._states.c,conf[0]));
+
+                                               //TODO: figure out best way to 
test the mock data coming in
+
+                                               console.info("sending event t3")
+                                               sc.t3()
+                                               conf = 
sc.getCurrentConfiguration();
+                                               console.log($(conf));
+                                               
doh.assertEqual(setwiseEqual(sc._states.d,conf[0]));
+
+                                               console.info("sending event t4")
+                                               sc.t4()
+                                               conf = 
sc.getCurrentConfiguration();
+                                               console.log($(conf));
+                                               
doh.assertEqual(setwiseEqual(sc._states.e,conf[0]));
+
+                                               console.info("sending event t5")
+                                               sc.t5()
+                                               conf = 
sc.getCurrentConfiguration();
+                                               console.log($(conf));
+                                               
doh.assertEqual(setwiseEqual(sc._states.f,conf[0]));
+
+                                       },
+                                       tearDown:function(){
+                                                sc.destroy();
+                                       }
+                               }
+               ]);
+       }
+})
+
+

Propchange: 
commons/sandbox/gsoc/2010/scxml-js/branches/SCXML-143_external-communications-module/test/send/scripts/unitTest.js
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to