You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by at...@apache.org on 2014/01/27 21:30:26 UTC
svn commit: r1561832 - in /commons/proper/scxml/trunk/src:
main/java/org/apache/commons/scxml2/io/SCXMLWriter.java
test/java/org/apache/commons/scxml2/io/SCXMLReaderTest.java
Author: ate
Date: Mon Jan 27 20:30:25 2014
New Revision: 1561832
URL: http://svn.apache.org/r1561832
Log:
SCXML-187: add SCXML initial script support to SCXMLWriter as well and adding test case to validate
Modified:
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLWriter.java
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/io/SCXMLReaderTest.java
Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLWriter.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLWriter.java?rev=1561832&r1=1561831&r2=1561832&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLWriter.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLWriter.java Mon Jan 27 20:30:25 2014
@@ -445,6 +445,11 @@ public class SCXMLWriter {
// Marker to indicate generated document
writer.writeComment(XMLNS_COMMONS_SCXML);
+ // Write initial script if defined
+ if (scxml.getInitialScript() != null) {
+ writeExecutableContent(writer, scxml.getInitialScript().getParent().getActions());
+ }
+
// Children
writeDatamodel(writer, scxml.getDatamodel());
for (TransitionTarget tt : scxml.getChildren().values()) {
Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/io/SCXMLReaderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/io/SCXMLReaderTest.java?rev=1561832&r1=1561831&r2=1561832&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/io/SCXMLReaderTest.java (original)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml2/io/SCXMLReaderTest.java Mon Jan 27 20:30:25 2014
@@ -17,6 +17,7 @@
package org.apache.commons.scxml2.io;
import java.io.IOException;
+import java.io.StringReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
@@ -66,7 +67,7 @@ public class SCXMLReaderTest {
// Test data
private URL microwave01, microwave02, transitions01, prefix01, send01,
microwave03, microwave04, scxmlinitialattr, action01,
- scxmlWithInvalidElems;
+ scxmlWithInvalidElems, groovyClosure;
private SCXML scxml;
private String scxmlAsString;
@@ -112,6 +113,8 @@ public class SCXMLReaderTest {
getResource("org/apache/commons/scxml2/io/custom-action-body-test-1.xml");
scxmlWithInvalidElems = this.getClass().getClassLoader().
getResource("org/apache/commons/scxml2/io/scxml-with-invalid-elems.xml");
+ groovyClosure = this.getClass().getClassLoader().
+ getResource("org/apache/commons/scxml2/env/groovy/groovy-closure.xml");
scxmlReaderLog = LogFactory.getLog(SCXMLReader.class);
clearRecordedLogMessages();
@@ -123,7 +126,7 @@ public class SCXMLReaderTest {
@After
public void after() {
microwave01 = microwave02 = microwave03 = microwave04 = transitions01 = prefix01 = send01 = action01 =
- scxmlinitialattr = scxmlWithInvalidElems = null;
+ scxmlinitialattr = scxmlWithInvalidElems = groovyClosure = null;
scxml = null;
scxmlAsString = null;
}
@@ -310,6 +313,18 @@ public class SCXMLReaderTest {
assertNotContainsRecordedLogMessage("Ignoring unknown or invalid element <onbeforeexit> in namespace \"http://www.w3.org/2005/07/scxml\" as child of <final>");
}
+ @Test
+ public void testSCXMLReaderGroovyClosure() throws Exception {
+ scxml = SCXMLTestHelper.parse(groovyClosure);
+ Assert.assertNotNull(scxml);
+ Assert.assertNotNull(scxml.getInitialScript());
+ scxmlAsString = serialize(scxml);
+ Assert.assertNotNull(scxmlAsString);
+ scxml = SCXMLTestHelper.parse(new StringReader(scxmlAsString), null);
+ Assert.assertNotNull(scxml);
+ Assert.assertNotNull(scxml.getInitialScript());
+ }
+
private String serialize(final SCXML scxml) throws IOException, XMLStreamException {
scxmlAsString = SCXMLWriter.write(scxml);
Assert.assertNotNull(scxmlAsString);