[jbpm-commits] JBoss JBPM SVN: r6400 - in jbpm4/trunk/modules: jpdl/src/main/java/org/jbpm/jpdl/internal/activity and 4 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Jun 10 12:11:58 EDT 2010


Author: alex.guizar at jboss.com
Date: 2010-06-10 12:11:57 -0400 (Thu, 10 Jun 2010)
New Revision: 6400

Modified:
   jbpm4/trunk/modules/api/src/main/resources/jpdl-4.4.xsd
   jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachActivity.java
   jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachBinding.java
   jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForkActivity.java
   jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/ForkTest.java
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/assign/AssignTest.java
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/foreach/ForEachTest.java
Log:
JBPM-2414: enable and fix 4.4 schema
allow multiple outgoing transitions from foreach (e.g. timers)
end execution trunk if no execution branch meets the condition

Modified: jbpm4/trunk/modules/api/src/main/resources/jpdl-4.4.xsd
===================================================================
--- jbpm4/trunk/modules/api/src/main/resources/jpdl-4.4.xsd	2010-06-10 12:36:42 UTC (rev 6399)
+++ jbpm4/trunk/modules/api/src/main/resources/jpdl-4.4.xsd	2010-06-10 16:11:57 UTC (rev 6400)
@@ -8,15 +8,15 @@
         
   <annotation>
     <documentation>Schema for jPDL 4 process descriptions; 
-    element process is the top level element.
+    the top level element is process.
     </documentation>
   </annotation>
 
   <!-- ### PROCESS DEFINITION ############################################# -->
 
   <element name="process">
-    <annotation><documentation>A jPDL process definition description; This 
-    is the top level element in a jPDL process file.</documentation></annotation>
+    <annotation><documentation>jPDL process definition.
+    This is the top level element in a jPDL process file.</documentation></annotation>
     <complexType>
       <sequence minOccurs="0" maxOccurs="unbounded">
         <element name="description" minOccurs="0" type="string" />
@@ -29,24 +29,25 @@
       <attribute name="name" use="required" type="string">
         <annotation>
           <documentation>
-            The process name. Multiple processes can be deployed with the same name, as long as they have a different
-            version.
+            The process name. Multiple processes can be deployed with the same name,
+            as long as they have a different version.
           </documentation>
         </annotation>
       </attribute>
       <attribute name="key" type="string">
         <annotation>
           <documentation>
-            The key can be used to provide a short acronym that will replace the name as the basis for the generated
-            process definition id
+            The key can be used to provide a short acronym that replaces the name as
+            the basis for the generated process definition id.
           </documentation>
         </annotation>
       </attribute>
       <attribute name="version" type="int">
         <annotation>
           <documentation>
-            Indicates the sequence number of this version for all processes with the same name. By specifying a version
-            automatic deployment can figure out if this process is already deployed or not.
+            Indicates the version number of this process definition among its homonyms.
+            By specifying a version, automatic deployment can tell whether this process
+            is already deployed.
           </documentation>
         </annotation>
       </attribute>
@@ -218,7 +219,7 @@
         </complexType>
       </element>
 
-      <!-- ~~~ FORK ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
+      <!-- ~~~ FOREACH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
       <element name="foreach">
         <annotation><documentation>Spawns concurrent paths of execution
           over each element of a collection.
@@ -230,7 +231,7 @@
             <element ref="tns:transition" minOccurs="0" maxOccurs="unbounded" />
           </sequence>
           <attributeGroup ref="tns:activityAttributes" />
-          <attribute name="var" type="string" default="var"/>
+          <attribute name="var" type="string" use="required"/>
           <attribute name="in" type="string" use="required"/>
         </complexType>
       </element>
@@ -409,24 +410,23 @@
             <extension base="tns:wireObjectType">
               <sequence>
                 <element ref="tns:on" minOccurs="0" maxOccurs="unbounded"/>
-                <element ref="tns:transition" minOccurs="0" maxOccurs="unbounded" >
+                <element name="transition" minOccurs="0" maxOccurs="unbounded">
                   <complexType>
-		                <complexContent>
-		                  <extension base="tns:transitionType">
-		                    <sequence>
-		                      <element ref="tns:timer" minOccurs="0" />
-		                    </sequence>
-		                  </extension>
-		                </complexContent>
-		              </complexType>
+                    <complexContent>
+                      <extension base="tns:transitionType">
+                        <sequence>
+                          <element ref="tns:timer" minOccurs="0" />
+                        </sequence>
+                      </extension>
+                    </complexContent>
+                  </complexType>
                 </element>
               </sequence>
               <attributeGroup ref="tns:activityAttributes" />
             </extension>
           </complexContent>
         </complexType>
-      </element>   
-      
+      </element>
 
       <!-- ~~~ TASK ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
       <element name="task">

Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachActivity.java	2010-06-10 12:36:42 UTC (rev 6399)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachActivity.java	2010-06-10 16:11:57 UTC (rev 6400)
@@ -70,8 +70,7 @@
       execution.end();
     }
     else {
-      // TODO is any other state possible?
-      concurrentRoot = execution;
+      throw new AssertionError(execution.getState());
     }
 
     // evaluate transition condition and create concurrent executions
@@ -80,39 +79,44 @@
     int index = 1;
     
     //execution context needs to be temporarily replaced to give access to child execution variables
-    ExecutionContext originalExecutionContext = null;
-    ExecutionContext concurrentExecutionContext = null;
+    ExecutionContext originalContext = null;
     EnvironmentImpl environment = EnvironmentImpl.getCurrent();
-    if (environment!=null) {
-      originalExecutionContext = (ExecutionContext) environment.removeContext(Context.CONTEXTNAME_EXECUTION);
+    if (environment != null) {
+      originalContext = (ExecutionContext) environment.removeContext(Context.CONTEXTNAME_EXECUTION);
     }
-    
-    for (Object value : collection) {
-      ExecutionImpl concurrentExecution = concurrentRoot.createExecution(Integer
-        .toString(index++));
-      concurrentExecution.setActivity(activity);
-      concurrentExecution.setState(Execution.STATE_ACTIVE_CONCURRENT);
-      concurrentExecution.createVariable(variable, value);
 
-      // repla!
 ce in the current environment execution context for expression evaluation purpose
-      concurrentExecutionContext = new ExecutionContext(concurrentExecution);
-      environment.setContext(concurrentExecutionContext);
-
-      Condition condition = transition.getCondition();
-      if (condition == null || condition.evaluate(concurrentExecution)) {
-        concurrentExecutions.add(concurrentExecution);
+    try {
+      for (Object value : collection) {
+        ExecutionImpl concurrentExecution = concurrentRoot.createExecution(Integer
+          .toString(index++));
+        concurrentExecution.setActivity(activity);
+        concurrentExecution.setState(Execution.STATE_ACTIVE_CONCURRENT);
+        concurrentExecution.createVariable(variable, value);
+  
+        // replace the current execution context for expression evaluation purposes
+        if (environment != null) {
+          environment.setContext(new ExecutionContext(concurrentExecution));
+        }
+  
+    !
     Condition condition = transition.getCondition();
+        !
 if (cond
ition == null || condition.evaluate(concurrentExecution)) {
+          concurrentExecutions.add(concurrentExecution);
+        }
+        else {
+          concurrentExecution.end();
+        }
       }
-      else {
-        concurrentExecution.end();
+    }
+    finally {
+      // reset original execution context after creating concurrent executions
+      if (environment != null) {
+        environment.setContext(originalContext);
       }
     }
-    // after all concurrent execution were processed reset original execution context
-    environment.setContext(originalExecutionContext);
 
-    // if no concurrent executions should be launched
     if (concurrentExecutions.isEmpty()) {
-      // throw exceptions to be consistent with decision activity
-      throw new JbpmException("no outgoing transition condition evaluated to true for " + activity);
+      // if no outgoing transitions should be forked, end this execution
+      execution.end();
     }
     else {
      !
  for (ExecutionImpl concurrentExecution : concurrentExecutions) {
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachBinding.java	2010-06-10 12:36:42 UTC (rev 6399)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachBinding.java	2010-06-10 16:11:57 UTC (rev 6400)
@@ -21,7 +21,7 @@
  */
 package org.jbpm.jpdl.internal.activity;
 
-import java.util.List;
+import org.w3c.dom.Element;
 
 import org.jbpm.jpdl.internal.xml.JpdlParser;
 import org.jbpm.pvm.internal.el.Expression;
@@ -32,7 +32,6 @@
 import org.jbpm.pvm.internal.wire.usercode.UserCodeCondition;
 import org.jbpm.pvm.internal.wire.usercode.UserCodeReference;
 import org.jbpm.pvm.internal.xml.Parse;
-import org.w3c.dom.Element;
 
 /**
  * @author Alejandro Guizar
@@ -58,50 +57,43 @@
     }
 
     if (element.hasAttribute(COLLECTION)) {
-      Expression collection = Expression
-        .create(element.getAttribute(COLLECTION), Expression.LANGUAGE_UEL_VALUE);
+      Expression collection = Expression.create(element.getAttribute(COLLECTION), Expression.LANGUAGE_UEL_VALUE);
       activity.setCollection(collection);
     }
     else {
       parse.addProblem(COLLECTION + " attribute missing", element);
     }
-   
+
     // process transition elements
-    List<Element> transitionElements = XmlUtil.elements(element, "transition");
-    
-    if (transitionElements.size() != 1) {
-      parse.addProblem("foreach activity can/must have one outgoing transition, found "+ transitionElements.size() + " transitions ", element);
-    } else {
-    
+    Element transitionElement = XmlUtil.element(element, "transition");
+
+    if (transitionElement == null) {
+      parse.addProblem("outgoing transition expected", element);
+    }
+    else {
       ActivityImpl a!
 ctivityFromStack = parse.contextStackFind(ActivityImpl.class);
       TransitionImpl transition = activityFromStack.getDefaultOutgoingTransition();
-  
-      // get first transition
-      Element transitionElement = transitionElements.get(0);
-  
+
       Element conditionElement = XmlUtil.element(transitionElement, "condition");
       if (conditionElement != null) {
-  
         if (conditionElement.hasAttribute("expr")) {
-          ExpressionCondition expressionCondition = new ExpressionCondition();
-          expressionCondition.setExpression(conditionElement.getAttribute("expr"));
-          expressionCondition.setLanguage(XmlUtil.attribute(conditionElement, "lang"));
-          transition.setCondition(expressionCondition);
-  
-        } else {
-          Element conditionHandlerElement = XmlUtil.element(conditionElement, "handler");
-          if (conditionHandlerElement != null) {
-            UserCodeCondition userCodeCondition = new UserCodeCondition();
-  
-  !
           UserCodeReference conditionReference = parser.parseU!
 serCodeR
eference(conditionHandlerElement, parse);
-            userCodeCondition.setConditionReference(conditionReference);
-  
-            transition.setCondition(userCodeCondition);
+          ExpressionCondition condition = new ExpressionCondition();
+          condition.setExpression(conditionElement.getAttribute("expr"));
+          condition.setLanguage(XmlUtil.attribute(conditionElement, "lang"));
+          transition.setCondition(condition);
+        }
+        else {
+          Element handlerElement = XmlUtil.element(conditionElement, "handler");
+          if (handlerElement != null) {
+            UserCodeReference conditionReference = parser.parseUserCodeReference(handlerElement, parse);
+            UserCodeCondition condition = new UserCodeCondition();
+            condition.setConditionReference(conditionReference);
+            transition.setCondition(condition);
           }
         }
       }
     }
-    
+
     return activity;
   }
 
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForkActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForkActivity.java	2010-06-10 12:36:42 UTC (rev 6399)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForkActivity.java	2010-06-10 16:11:57 UTC (rev 6400)
@@ -35,7 +35,6 @@
 import org.jbpm.pvm.internal.model.ExecutionImpl;
 import org.jbpm.pvm.internal.model.TransitionImpl;
 
-
 /**
  * @author Tom Baeyens
  */
@@ -50,40 +49,39 @@
   public void execute(ExecutionImpl execution) {
     Activity activity = execution.getActivity();
 
-    // evaluate the conditions and find the transitions that should be forked
+    // evaluate the conditions and select the forking transitions
     List<Transition> forkingTransitions = new ArrayList<Transition>();
     for (Transition transition: activity.getOutgoingTransitions()) {
       Condition condition = ((TransitionImpl) transition).getCondition();
-      if  ( (condition==null)
-            || (condition.evaluate(execution))
-          ) {
+      if (condition==null || condition.evaluate(execution)) {
         forkingTransitions.add(transition);
       }
     }
 
-    // if no outgoing transitions should be forked, 
-    if (forkingTransitions.size()==0) {
-      // end this execution
+    switch (forkingTransitions.size()) {
+    case 0:
+      // if no outgoing transitions should be forked, end this execution
       execution.end();
-
-    // if there is exactly 1 transition to be taken, just use the incoming execution
-    } else if (forkingTransitions.size()==1) {
+      break;
+    case 1:
+      // if there is exactly one transition to be taken, just use the incoming execution
       execution.take(forkingTransitions.get(0));
-      
-    // if there are more transitions
-    } else {
+      break;
+    default:
+      // if there are more transitions, perform full fork
       ExecutionImpl concurrentRoot;
       if (Execution.STATE_ACTIVE_ROOT.equals(execution.getState())) {
         concurrentRoot = execution;
         execution.setState(Execution.STATE_INACTIVE_CONCURRENT_ROOT);
         execution.setActivity(null);
-      } else if (Execution.STATE_ACTIVE_CONCURRENT.equals(execution.getState())) {
+      }
+      else if (Execution.STATE_ACTIVE_CONCURRENT.equals(execution.getState())) {
         concurrentRoot = execution.getParent();
         execution.end();
-      } else {
-        // TODO is any other state possible?
-        concurrentRoot = execution;
       }
+      else {
+        throw new AssertionError(execution.getState());
+      }
 
       Map<Transition, ExecutionImpl> concurrentExecutions = new HashMap<Transition, ExecutionImpl>();
       for (Transition transition : forkingTransitions) {
@@ -93,13 +91,9 @@
         concurrentExecutions.put(transition, concurrentExecution);
       }
 
-      
       for (Entry<Transition, ExecutionImpl> entry : concurrentExecutions.entrySet()) {
         entry.getValue().take(entry.getKey());
-
-        if (concurrentRoot.isEnded()) {
-          break;
-        }
+        if (concurrentRoot.isEnded()) break;
       }
     }
   }

Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java	2010-06-10 12:36:42 UTC (rev 6399)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java	2010-06-10 16:11:57 UTC (rev 6400)
@@ -25,6 +25,7 @@
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Date;
 import java.util.Enumeration;
 import java.util.List;
@@ -84,26 +85,23 @@
   public static final String NAMESPACE_JPDL_40 = "http://jbpm.org/4.0/jpdl";
   public static final String NAMESPACE_JPDL_42 = "http://jbpm.org/4.2/jpdl";
   public static final String NAMESPACE_JPDL_43 = "http://jbpm.org/4.3/jpdl";
+  public static final String NAMESPACE_JPDL_44 = "http://jbpm.org/jpdl/4.4";
 
-  public static final String CURRENT_VERSION_JBPM = "4.3";
-  public static final String CURRENT_VERSION_NAMESPACE = "http://jbpm.org/"+CURRENT_VERSION_JBPM+"/jpdl";
+  public static final String CURRENT_VERSION_JBPM = "4.4";
+  public static final String CURRENT_VERSION_NAMESPACE = "http://jbpm.org/jpdl/"+CURRENT_VERSION_JBPM;
   public static final String CURRENT_VERSION_PROCESS_LANGUAGE_ID = "jpdl-"+CURRENT_VERSION_JBPM;
   
-  public static final List<String> SCHEMA_RESOURCES = new ArrayList<String>();
-  static {
-    SCHEMA_RESOURCES.add("jpdl-4.0.xsd");
-    SCHEMA_RESOURCES.add("jpdl-4.2.xsd");
-    SCHEMA_RESOURCES.add("jpdl-4.3.xsd");
-  }
+  private static final List<String> SCHEMA_RESOURCES = Arrays.asList("jpdl-4.0.xsd",
+    "jpdl-4.2.xsd", "jpdl-4.3.xsd", "jpdl-4.4.xsd");
 
   // array elements are mutable, even when final
   // never make a static array public
-  static final String[] DEFAULT_BINDING_RESOURCES = {
+  private static final String[] DEFAULT_BINDING_RESOURCES = {
     "jbpm.jpdl.bindings.xml",
     "jbpm.user.bindings.xml"
   }; 
 
-  static JpdlBindingsParser jpdlBindingsParser = new JpdlBindingsParser();
+  private static JpdlBindingsParser jpdlBindingsParser = new JpdlBindingsParser();
 
   public static final String CATEGORY_ACTIVITY = "activity";
   public static final String CATEGORY_EVENT_LISTENER = "eventlistener";

Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/ForkTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/ForkTest.java	2010-06-10 12:36:42 UTC (rev 6399)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/ForkTest.java	2010-06-10 16:11:57 UTC (rev 6400)
@@ -24,11 +24,9 @@
  */
 package org.jbpm.test.activities;
 
-import org.jbpm.api.history.HistoryProcessInstance;
 import org.jbpm.api.task.Task;
 import org.jbpm.test.JbpmTestCase;
 
-
 /**
  * @author Joram Barrez
  */

Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/assign/AssignTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/assign/AssignTest.java	2010-06-10 12:36:42 UTC (rev 6399)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/assign/AssignTest.java	2010-06-10 16:11:57 UTC (rev 6400)
@@ -33,7 +33,7 @@
 public class AssignTest extends JbpmTestCase {
 
   public void testFromExprToVar() {
-    deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/4.4/jpdl'>"
+    deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/jpdl/4.4'>"
       + "  <start>"
       + "    <transition to='resolve' />"
       + "  </start>"
@@ -52,7 +52,7 @@
   }
 
   public void testFromMethodExprToVar() {
-    deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/4.4/jpdl'>"
+    deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/jpdl/4.4'>"
       + "  <start>"
       + "    <transition to='resolve' />"
       + "  </start>"
@@ -71,7 +71,7 @@
   }
 
   public void testFromMethodParamExprToVar() {
-    deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/4.4/jpdl'>"
+    deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/jpdl/4.4'>"
       + "  <start>"
       + "    <transition to='resolve' />"
       + "  </start>"
@@ -90,7 +90,7 @@
   }
 
   public void testFromDescToExpr() {
-    deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/4.4/jpdl'>"
+    deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/jpdl/4.4'>"
       + "  <start>"
       + "    <transition to='resolve' />"
       + "  </start>"
@@ -111,7 +111,7 @@
   }
 
   public void testFromVarToVar() {
-    deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/4.4/jpdl'>"
+    deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/jpdl/4.4'>"
       + "  <start>"
       + "    <transition to='resolve' />"
       + "  </start>"

Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/foreach/ForEachTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/foreach/ForEachTest.java	2010-06-10 12:36:42 UTC (rev 6399)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/foreach/ForEachTest.java	2010-06-10 16:11:57 UTC (rev 6400)
@@ -24,6 +24,7 @@
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Date;
+import java.util.List;
 import java.util.Map;
 
 import org.jbpm.api.Execution;
@@ -37,7 +38,7 @@
  * @author Maciej Swiderski
  */
 public class ForEachTest extends JbpmTestCase {
-  
+
   public void testForEachLiteral() {
     deployJpdlXmlString(""
       + "<process name='ForEachLiteral' xmlns='http://jbpm.org/jpdl/4.4'>"
@@ -235,6 +236,7 @@
     }
     catch (JbpmException e) {
       // expected result
+      e.printStackTrace();
     }
   }
 
@@ -250,7 +252,7 @@
       + "   <task name='task1' g='90,177,73,44' assignee='#{assign}'>"
       + "      <transition name='to state' to='join2' g='-43,-18'/>"
       + "   </task>"
-      + "   <join name='join2' g='192,511,57,44' multiplicity='#{actors.size() - 1}'>"
+      + "   <join name='join2' g='192,511,57,44' multiplicity='#{actors.size()-1}'>"
       + "      <transition name='to end1' to='end1' g='-42,-18'/>"
       + "   </join>"
       + "   <end g='193,606,38,33' name='end1'/>"
@@ -272,17 +274,17 @@
     assertEquals(ProcessInstance.STATE_ENDED, history.getState());
     assertEquals("end1", history.getEndActivityName());
   }
-  
-  public void testForEachLiteralWithTransitionExpr() {
+
+  public void testForEachConditionMet() {
     deployJpdlXmlString(""
-      + "<process name='ForEachCondition' xmlns='http://jbpm.org/jpdl/4.4'>"
+      + "<process name='ForEachConditionMet' xmlns='http://jbpm.org/jpdl/4.4'>"
       + "   <start g='179,17,32,29' name='start1'>"
       + "      <transition g='-43,-18' name='to foreach1' to='foreach1'/>"
       + "   </start>"
       + "   <foreach g='185,95,49,50' name='foreach1' var='assign' in='alex, mike, peter'>"
       + "      <transition name='left' to='task1' g='-44,-18'>"
-      + "           <condition expr='#{assign==&quot;alex&quot; or assign==&quot;mike&quot;}' /> "
-      + "      </transition>" 
+      + "         <condition expr='#{assign != &quot;peter&quot;}' /> "
+      + "      </transition>"
       + "   </foreac!
 h>"
       + "   <task name='task1' g='90,177,73,44' assignee='#{assign}'>"
       + "      <transition name='to state' to='Big car' g='-43,-18'/>"
@@ -296,7 +298,7 @@
       + "   <end g='193,606,38,33' name='end1'/>"
       + "</process>");
 
-    ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForEachCondition");
+    ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForEachConditionMet");
 
     Task taskAlex = taskService.createTaskQuery().assignee("alex").uniqueResult();
     assertEquals("task1", taskAlex.getActivityName());
@@ -320,37 +322,41 @@
     assertEquals(ProcessInstance.STATE_ENDED, history.getState());
     assertEquals("end1", history.getEndActivityName());
   }
-  
-  public void testForEachTooManyTransitions() {
-    try {
-      deployJpdlXmlString(""
-        + "<process name='ForEachTooManyTransitions' xmlns='http://jbpm.org/jpdl/4.4'>"
-        + "   <start g='179,17,32,29' name='start1'>"
-        + "      <transition g='-43,-18' name='to foreach1' to='foreach1'/>"
-        + "   </start>"
-        + "   <foreach g='185,95,49,50' name='foreach1' in='#{actors}' var='assign'>"
-        + "      <transition name='left' to='task1' g='-44,-18'/>"
-        + "      <transition name='right' to='task1' g='-44,-18'/>"
-        + "   </foreach>"
-        + "   <task name='task1' g='90,177,73,44' assignee='#{assign}'>"
-        + "      <transition name='to state' to='Big car' g='-43,-18'/>"
-        + "   </task>"
-        + "   <state name='Big car' > "
-        + "   <transition name='to join2' to='join2' !
 g='-43,-18'/>"
-        + "   </state> "
-        + "   <join name='join2' g='192,511,57,44'>"
-        + "      <transition name='to end1' to='end1' g='-42,-18'/>"
-        + "   </join>"
-        + "   <end g='193,606,38,33' name='end1'/>"
-        + "</process>");
 
-      fail("expected foreach with too many transitions");
-    }
-    catch (JbpmException e) {
-      // expected result
-    }
+  public void testForEachConditionNotMet() {
+    deployJpdlXmlString(""
+      + "<process name='ForEachConditionNotMet' xmlns='http://jbpm.org/jpdl/4.4'>"
+      + "   <start g='179,17,32,29' name='start1'>"
+      + "      <transition g='-43,-18' name='to foreach1' to='foreach1'/>"
+      + "   </start>"
+      + "   <foreach g='185,95,49,50' name='foreach1' var='assign' in='alex, mike'>"
+      + "      <transition name='left' to='task1' g='-44,-18'>"
+      + "         <condition expr='#{assign==&quot;peter&quot;}' /> "
+      + "      </transition>"
+      + "   </foreach>"
!
 +      + "   <task name='task1' g='90,177,73,44' assignee='#{a!
 ssign}'>
"
+      + "      <transition name='to state' to='Big car' g='-43,-18'/>"
+      + "   </task>"
+      + "   <state name='Big car' > "
+      + "      <transition name='to join2' to='join2' g='-43,-18'/>"
+      + "   </state> "
+      + "   <join name='join2' g='192,511,57,44'>"
+      + "      <transition name='to end1' to='end1' g='-42,-18'/>"
+      + "   </join>"
+      + "   <end g='193,606,38,33' name='end1'/>"
+      + "</process>");
+
+    ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForEachConditionNotMet");
+
+    List<Task> tasks = taskService.createTaskQuery().list();
+    assertEquals(0, tasks.size());
+
+    HistoryProcessInstance history = historyService.createHistoryProcessInstanceQuery()
+      .processInstanceId(processInstance.getId())
+      .uniqueResult();
+    assertEquals(ProcessInstance.STATE_ENDED, history.getState());
   }
-  
+
   public void testForEachNoTransitions() {
     try {
       deployJpdlXmlString(""
@@!
  -358,7 +364,7 @@
         + "   <start g='179,17,32,29' name='start1'>"
         + "      <transition g='-43,-18' name='to foreach1' to='foreach1'/>"
         + "   </start>"
-        + "   <foreach g='185,95,49,50' name='foreach1' in='#{actors}' var='assign' >"
+        + "   <foreach g='185,95,49,50' name='foreach1' var='assign' in='#{actors}'>"
         + "   </foreach>"
         + "   <task name='task1' g='90,177,73,44' assignee='#{assign}'>"
         + "      <transition name='to state' to='Big car' g='-43,-18'/>"
@@ -372,44 +378,10 @@
         + "   <end g='193,606,38,33' name='end1'/>"
         + "</process>");
 
-      fail("expected foreach with too many transitions");
+      fail("expected deployment failure");
     }
     catch (JbpmException e) {
       // expected result
     }
   }
-  
-  public void testForEachConditionTransitionsEvaluatedToFalse() {
-    try {
-      deployJpdlXmlString(""
-        + "<process name='ForEachConditionFalse' xmlns='http://jbpm.org/jpdl/4.4'>"
-        + "   <start g='179,17,32,29' name='start1'>"
-        + "      <transition g='-43,-18' name='to foreach1' to='foreach1'/>"
-        + "   </start>"
-        + "   <foreach g='185,95,49,50' name='foreach1' in='#{actors}' var='assign' >"
-        + "      <transition name='left' to='task1' g='-44,-18'>"
-        + "           <condition expr='#{assign==&quot;peter&quot;}' /> "
-        + "      </transition>" 
-        + "   </foreach>"
-        + "   <task name='task1' g='90,177,73,44' assignee='#{assign}'>"
-        !
 + "      <transition name='to state' to='Big car' g='-43,-18'/>"
-        + "   </task>"
-        + "   <state name='Big car' > "
-        + "   <transition name='to join2' to='join2' g='-43,-18'/>"
-        + "   </state> "
-        + "   <join name='join2' g='192,511,57,44'>"
-        + "      <transition name='to end1' to='end1' g='-42,-18'/>"
-        + "   </join>"
-        + "   <end g='193,606,38,33' name='end1'/>"
-        + "</process>");
-
-      Map<String, ?> variables = Collections.singletonMap("actors", Arrays.asList("alex", "mike"));
-      ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForEachConditionFalse", variables);
-
-      fail("expected foreach all conditions evaluated to false");
-    }
-    catch (JbpmException e) {
-      // expected result
-    }
-  }
 }


More information about the jbpm-commits mailing list