Author: rahul
Date: Mon Jan 26 22:04:49 2009
New Revision: 737887

URL: http://svn.apache.org/viewvc?rev=737887&view=rev
Log:
Add a test case for parsing custom actions with body text.

Added:
    
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/custom-action-body-test-1.xml
   (with props)
Modified:
    
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/SCXMLReaderTest.java

Modified: 
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/SCXMLReaderTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/SCXMLReaderTest.java?rev=737887&r1=737886&r2=737887&view=diff
==============================================================================
--- 
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/SCXMLReaderTest.java
 (original)
+++ 
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/SCXMLReaderTest.java
 Mon Jan 26 22:04:49 2009
@@ -18,6 +18,8 @@
 
 import java.io.IOException;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 import javax.xml.stream.XMLStreamException;
@@ -27,13 +29,23 @@
 import junit.framework.TestSuite;
 import junit.textui.TestRunner;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.scxml.ErrorReporter;
+import org.apache.commons.scxml.EventDispatcher;
+import org.apache.commons.scxml.SCInstance;
+import org.apache.commons.scxml.SCXMLExpressionException;
 import org.apache.commons.scxml.SCXMLTestHelper;
+import org.apache.commons.scxml.TriggerEvent;
 import org.apache.commons.scxml.model.Action;
+import org.apache.commons.scxml.model.CustomAction;
+import org.apache.commons.scxml.model.ExternalContent;
 import org.apache.commons.scxml.model.Final;
+import org.apache.commons.scxml.model.ModelException;
 import org.apache.commons.scxml.model.SCXML;
 import org.apache.commons.scxml.model.Send;
 import org.apache.commons.scxml.model.State;
 import org.apache.commons.scxml.model.Transition;
+import org.w3c.dom.Node;
 /**
  * Unit tests {...@link org.apache.commons.scxml.io.SCXMLReader}.
  */
@@ -54,7 +66,7 @@
 
     // Test data
     private URL microwave01, microwave02, transitions01, prefix01, send01,
-        microwave03, microwave04, scxmlinitialattr;
+        microwave03, microwave04, scxmlinitialattr, action01;
     private SCXML scxml;
     private String scxmlAsString;
 
@@ -79,6 +91,8 @@
             getResource("org/apache/commons/scxml/prefix-01.xml");
         scxmlinitialattr = this.getClass().getClassLoader().
             getResource("org/apache/commons/scxml/io/scxml-initial-attr.xml");
+        action01 = this.getClass().getClassLoader().
+            
getResource("org/apache/commons/scxml/io/custom-action-body-test-1.xml");
     }
 
     /**
@@ -86,7 +100,7 @@
      */
     @Override
     public void tearDown() {
-        microwave01 = microwave02 = microwave03 = microwave04 = transitions01 
= prefix01 = send01 = null;
+        microwave01 = microwave02 = microwave03 = microwave04 = transitions01 
= prefix01 = send01 = action01 = null;
         scxml = null;
         scxmlAsString = null;
     }
@@ -168,6 +182,21 @@
         assertEquals("foo", foo.getId());
     }
 
+    public void testSCXMLParserCustomActionWithBodyTextSample() throws 
Exception {
+        List<CustomAction> cas = new ArrayList<CustomAction>();
+        CustomAction ca = new CustomAction("http://my.custom-actions.domain";,
+            "action", MyAction.class);
+        cas.add(ca);
+        scxml = SCXMLTestHelper.parse(action01, cas);
+        State state = (State) scxml.getInitialTarget();
+        assertEquals("actions", state.getId());
+        List<Action> actions = state.getOnEntry().getActions();
+        assertEquals(1, actions.size());
+        MyAction my = (MyAction) actions.get(0);
+        assertNotNull(my);
+        assertTrue(my.getExternalNodes().size() > 0);
+    }
+
     private String serialize(final SCXML scxml) throws IOException, 
XMLStreamException {
         scxmlAsString = SCXMLWriter.write(scxml);
         assertNotNull(scxmlAsString);
@@ -178,5 +207,26 @@
         TestRunner.run(suite());
     }
 
+
+    public static class MyAction extends Action implements ExternalContent {
+        private static final long serialVersionUID = 1L;
+
+        private List<Node> nodes = new ArrayList<Node>();
+
+        @Override
+        public void execute(EventDispatcher evtDispatcher,
+                ErrorReporter errRep, SCInstance scInstance, Log appLog,
+                Collection<TriggerEvent> derivedEvents)
+        throws ModelException, SCXMLExpressionException {
+            // Not relevant to test
+        }
+
+        @Override
+        public List<Node> getExternalNodes() {
+            return nodes;
+        }
+
+    }
+
 }
 

Added: 
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/custom-action-body-test-1.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/custom-action-body-test-1.xml?rev=737887&view=auto
==============================================================================
--- 
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/custom-action-body-test-1.xml
 (added)
+++ 
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/custom-action-body-test-1.xml
 Mon Jan 26 22:04:49 2009
@@ -0,0 +1,34 @@
+<?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 SCXMLReaderTest.java in io package -->
+<scxml xmlns="http://www.w3.org/2005/07/scxml";
+       xmlns:my="http://my.custom-actions.domain";
+       version="1.0"
+       initial="actions">
+
+    <final id="actions">
+        <onentry>
+            <my:action>
+                ABCD
+                EFGH
+                IJKL
+            </my:action>
+        </onentry>
+    </final>
+
+</scxml>

Propchange: 
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/custom-action-body-test-1.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/custom-action-body-test-1.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL


Reply via email to