[jbpm-commits] JBoss JBPM SVN: r6395 - in jbpm4/trunk/modules: test-db/src/test/java/org/jbpm/test/activity and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Mon Jun 7 16:23:17 EDT 2010
Author: swiderski.maciej
Date: 2010-06-07 16:23:16 -0400 (Mon, 07 Jun 2010)
New Revision: 6395
Added:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/script/
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/script/ScriptTest.java
Modified:
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ScriptBinding.java
Log:
JBPM-2882: ensure that either expr attribute is given or text nested element for script activity
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ScriptBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ScriptBinding.java 2010-06-04 08:48:07 UTC (rev 6394)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ScriptBinding.java 2010-06-07 20:23:16 UTC (rev 6395)
@@ -49,11 +49,13 @@
ScriptManager scriptManager = EnvironmentImpl.getFromCurrent(ScriptManager.class);
language = scriptManager.getDefaultExpressionLanguage();
if (textElement!=null) {
- parse.addProblem("in <script ...> attribute expr can't be combined with a nexted text element", element);
+ parse.addProblem("in <script ...> attribute expr can't be combined with a nested text element", element);
}
- } else {
+ } else if(textElement != null) {
language = XmlUtil.attribute(element, "lang");
script = XmlUtil.getContentText(textElement);
+ } else {
+ parse.addProblem("<script...> element must have either expr attribute or nested text element", element);
}
String variableName = XmlUtil.attribute(element, "var");
Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/script/ScriptTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/script/ScriptTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/script/ScriptTest.java 2010-06-07 20:23:16 UTC (rev 6395)
@@ -0,0 +1,82 @@
+package org.jbpm.test.activity.script;
+
+import java.util.HashMap;
+
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.test.JbpmTestCase;
+
+
+public class ScriptTest extends JbpmTestCase {
+
+ public void testIncompleteScriptDefinition() {
+
+ try {
+ deployJpdlXmlString(
+ "<process name='ScriptProcess'> " +
+ " <start name='start'> " +
+ " <transition to='script'/> " +
+ " </start> " +
+ " <script name='script'> " +
+ " </script> " +
+ "</process>"
+ );
+
+ fail("Should fail sine script definition is incomplete");
+
+ } catch (Exception e) {
+ String expectedErrorMsg = "error: <script...> element must have either expr attribute or nested text element";
+
+ assertTrue(e.getMessage().trim().startsWith(expectedErrorMsg));
+ }
+ }
+
+ public void testScriptDefinitionWithExpr() {
+
+ deployJpdlXmlString(
+ "<process name='ScriptProcess'> " +
+ " <start name='start'> " +
+ " <transition to='script'/> " +
+ " </start> " +
+ " <script name='script' expr='Send packet to #{receiver}' var='result'> " +
+ " <transition to='wait' />" +
+ " </script> " +
+ " <state name='wait' />" +
+ "</process>"
+ );
+
+ HashMap<String, String> variables = new HashMap<String, String>();
+ variables.put("receiver", "johndoe");
+
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("ScriptProcess", variables);
+
+ String resultVariable = (String) executionService.getVariable(processInstance.getId(), "result");
+
+ assertEquals("Send packet to johndoe", resultVariable);
+ }
+
+ public void testScriptDefinitionWithTextElement() {
+
+
+ deployJpdlXmlString(
+ "<process name='ScriptProcess'> " +
+ " <start name='start'> " +
+ " <transition to='script'/> " +
+ " </start> " +
+ " <script name='script' var='result'> " +
+ " <text>Send packet to #{receiver}</text> " +
+ " <transition to='wait' />" +
+ " </script> " +
+ " <state name='wait' />" +
+ "</process>"
+ );
+
+ HashMap<String, String> variables = new HashMap<String, String>();
+ variables.put("receiver", "johndoe");
+
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("ScriptProcess", variables);
+
+ String resultVariable = (String) executionService.getVariable(processInstance.getId(), "result");
+
+ assertEquals("Send packet to johndoe", resultVariable);
+ }
+}
More information about the jbpm-commits
mailing list