Author: rahul
Date: Wed Jul 30 20:53:51 2008
New Revision: 681271

URL: http://svn.apache.org/viewvc?rev=681271&view=rev
Log:
Porting r681270 from trunk.
Stop rendering non-standard parentid attribute during serialization.
Also correct namespace for <var> and <exit>.
New tests provided by Ingmar Kliche <ingmar dot kliche at googlemail dot com>
SCXML-79

Modified:
    
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLSerializer.java
    
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/SCXMLSerializerTest.java

Modified: 
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLSerializer.java
URL: 
http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLSerializer.java?rev=681271&r1=681270&r2=681271&view=diff
==============================================================================
--- 
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLSerializer.java
 (original)
+++ 
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLSerializer.java
 Wed Jul 30 20:53:51 2008
@@ -555,13 +555,6 @@
         if (id != null) {
             b.append(" id=\"").append(id).append("\"");
         }
-        TransitionTarget pt = t.getParent();
-        if (pt != null) {
-            String pid = pt.getId();
-            if (pid != null) {
-                b.append(" parentid=\"").append(pid).append("\"");
-            }
-        }
     }
 
     /**

Modified: 
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/SCXMLSerializerTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/SCXMLSerializerTest.java?rev=681271&r1=681270&r2=681271&view=diff
==============================================================================
--- 
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/SCXMLSerializerTest.java
 (original)
+++ 
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/SCXMLSerializerTest.java
 Wed Jul 30 20:53:51 2008
@@ -33,6 +33,7 @@
 import org.apache.commons.scxml.model.Log;
 import org.apache.commons.scxml.model.OnEntry;
 import org.apache.commons.scxml.model.OnExit;
+import org.apache.commons.scxml.model.Parallel;
 import org.apache.commons.scxml.model.SCXML;
 import org.apache.commons.scxml.model.Send;
 import org.apache.commons.scxml.model.State;
@@ -62,8 +63,8 @@
         scxml.addChild(new State());
         
         String assertValue = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
-            + "<scxml xmlns=\"http://www.w3.org/2005/07/scxml\"; 
version=\"version1\" "
-            + "initial=\"off\">\n <state>\n </state>\n</scxml>\n";
+            + "<scxml xmlns=\"http://www.w3.org/2005/07/scxml\"; 
xmlns:cs=\"http://commons.apache.org/scxml\"; "
+            + "version=\"version1\" initial=\"off\">\n <state>\n 
</state>\n</scxml>\n";
         
         assertEquals(assertValue, SCXMLSerializer.serialize(scxml));
     }
@@ -111,7 +112,7 @@
         List<Action> values = new ArrayList<Action>();
         values.add(var);
         
-        String actualValue = " <var name=\"newName\" 
expr=\"newExpression\"/>\n";
+        String actualValue = " <cs:var name=\"newName\" 
expr=\"newExpression\"/>\n";
         
         StringBuffer returnValue = new StringBuffer();
         boolean returnBoolean = SCXMLSerializer.serializeActions(returnValue, 
values, " ");
@@ -177,7 +178,7 @@
         List<Action> values = new ArrayList<Action>();
         values.add(exit);
         
-        String actualValue = " <exit expr=\"newExpression\" 
namelist=\"names\"/>\n";
+        String actualValue = " <cs:exit expr=\"newExpression\" 
namelist=\"names\"/>\n";
         
         StringBuffer returnValue = new StringBuffer();
         boolean returnBoolean = SCXMLSerializer.serializeActions(returnValue, 
values, " ");
@@ -303,4 +304,71 @@
         assertEquals(actualValue, returnValue.toString());
     }
 
+    public void testSerializeSCXMLState() {
+        SCXML scxml = new SCXML();
+        scxml.setVersion("1.0");
+        scxml.setInitial("S1");
+
+        State s1 = new State();
+        s1.setId("S1");
+
+        scxml.addChild(s1);
+
+        String assertValue = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+            + "<scxml xmlns=\"http://www.w3.org/2005/07/scxml\"; 
xmlns:cs=\"http://commons.apache.org/scxml\"; "
+            + "version=\"1.0\" initial=\"S1\">\n <state id=\"S1\">\n 
</state>\n</scxml>\n";
+
+        assertEquals(assertValue, SCXMLSerializer.serialize(scxml));
+    }
+
+    public void testSerializeParallel() {
+
+        SCXML scxml = new SCXML();
+        scxml.setVersion("1.0");
+        scxml.setInitial("par");
+
+        Parallel par = new Parallel();
+        par.setId("par");
+
+        State s1 = new State();
+        s1.setId("S1");
+
+        State s11 = new State();
+        s11.setId("S11");
+
+        s1.addChild((TransitionTarget)s11);
+
+        State s2 = new State();
+        s2.setId("S2");
+
+        State s21 = new State();
+        s21.setId("S21");
+
+        s2.addChild((TransitionTarget)s21);
+
+        par.addChild((TransitionTarget)s1);
+        par.addChild((TransitionTarget)s2);
+
+        scxml.addChild(par);
+
+        String assertValue = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+            + "<scxml xmlns=\"http://www.w3.org/2005/07/scxml\"; 
xmlns:cs=\"http://commons.apache.org/scxml\"; "
+            + "version=\"1.0\" initial=\"par\">\n"
+            + " <parallel id=\"par\">\n"
+            + "  <state id=\"S1\">\n"
+            + "   <state id=\"S11\">\n"
+            + "   </state>\n"
+            + "  </state>\n"
+            + "  <state id=\"S2\">\n"
+            + "   <state id=\"S21\">\n"
+            + "   </state>\n"
+            + "  </state>\n"
+            + " </parallel>\n"
+            + "</scxml>\n";
+
+        String s = SCXMLSerializer.serialize(scxml);
+
+        assertEquals(assertValue, s);
+     }
+
 }


Reply via email to