[jbpm-commits] JBoss JBPM SVN: r6240 - in jbpm3/branches/jbpm-3.2-soa/modules/core/src: main/java/org/jbpm/graph/def and 13 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Wed Mar 31 22:41:23 EDT 2010
Author: alex.guizar at jboss.com
Date: 2010-03-31 22:41:22 -0400 (Wed, 31 Mar 2010)
New Revision: 6240
Added:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm642/
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm642/JBPM642Test.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm642/
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm642/gpd.xml
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm642/processdefinition.xml
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/action/Script.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Node.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/exe/Token.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/Fork.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/InterleaveStart.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/Join.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/TaskNode.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/exe/MilestoneInstance.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/context/exe/VariableTypeTest.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/context/log/VariableLogTest.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/graph/action/ScriptTest.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp04ExclusiveChoiceTest.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp06MultiChoiceTest.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp07SynchronizingMergeTest.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp13MiWithoutSynchronizationTest.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp14MiWithAPrioriDesigntimeKnowledgeTest.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp15MiWithAPrioriRuntimeKnowledgeTest.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp16MiWithoutAPrioriRuntimeKnowledgeTest.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/logging/exe/CompositeLogTest.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/taskmgmt/exe/RuntimeTaskCreationTest.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/taskmgmt/exe/TaskExecutionTest.java
Log:
JBPM-642: lock parent token parked in fork node
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/action/Script.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/action/Script.java 2010-03-31 08:20:39 UTC (rev 6239)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/action/Script.java 2010-04-01 02:41:22 UTC (rev 6240)
@@ -21,6 +21,7 @@
*/
package org.jbpm.graph.action;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -55,7 +56,7 @@
expression = scriptElement.getText();
}
else {
- this.variableAccesses = new HashSet(jpdlReader.readVariableAccesses(scriptElement));
+ variableAccesses = new HashSet(jpdlReader.readVariableAccesses(scriptElement));
expression = scriptElement.element("expression").getText();
}
}
@@ -69,11 +70,11 @@
return "Script(" + expression + ')';
}
- public Map eval(Token token) throws Exception {
+ public Map eval(Token token) {
return eval(new ExecutionContext(token));
}
- public Map eval(ExecutionContext executionContext) throws Exception {
+ public Map eval(ExecutionContext executionContext) {
Map inputMap = createInputMap(executionContext);
Set outputNames = getOutputNames();
return eval(inputMap, outputNames);
@@ -92,7 +93,7 @@
// if no readable variableInstances are specified,
ContextInstance contextInstance = executionContext.getContextInstance();
if (!hasReadableVariable()) {
- // we copy all the variableInstances of the context into the interpreter
+ // put all variables into the input map
Map variables = contextInstance.getVariables(token);
if (variables != null) {
for (Iterator iter = variables.entrySet().iterator(); iter.hasNext();) {
@@ -104,7 +105,7 @@
}
}
else {
- // we only copy the specified variableInstances into the interpreter
+ // put only the specified variables into the input map
for (Iterator iter = variableAccesses.iterator(); iter.hasNext();) {
VariableAccess variableAccess = (VariableAccess) iter.next();
if (variableAccess.isReadable()) {
@@ -119,8 +120,7 @@
return inputMap;
}
- public Map eval(Map inputMap, Set outputNames) throws Exception {
- Map outputMap = new HashMap();
+ public Map eval(Map inputMap, Set outputNames) {
try {
// set input variables
log.debug("script input: " + inputMap);
@@ -132,12 +132,15 @@
// evaluate script
interpreter.eval(expression);
// get output variables
+ if (outputNames.isEmpty()) return Collections.EMPTY_MAP;
+ Map outputMap = new HashMap();
for (Iterator iter = outputNames.iterator(); iter.hasNext();) {
String outputName = (String) iter.next();
Object outputValue = interpreter.get(outputName);
outputMap.put(outputName, outputValue);
}
log.debug("script output: " + outputMap);
+ return outputMap;
}
catch (ParseException e) {
throw new DelegationException("failed to parse script", e);
@@ -148,8 +151,6 @@
catch (EvalError e) {
throw new DelegationException("script evaluation halted", e);
}
-
- return outputMap;
}
public void addVariableAccess(VariableAccess variableAccess) {
@@ -157,57 +158,40 @@
variableAccesses.add(variableAccess);
}
- Set getOutputNames() {
+ private Set getOutputNames() {
+ if (variableAccesses == null || variableAccesses.isEmpty()) return Collections.EMPTY_SET;
+
Set outputNames = new HashSet();
- if (variableAccesses != null) {
- Iterator iter = variableAccesses.iterator();
- while (iter.hasNext()) {
- VariableAccess variableAccess = (VariableAccess) iter.next();
- if (variableAccess.isWritable()) {
- outputNames.add(variableAccess.getMappedName());
- }
- }
+ for (Iterator iter = variableAccesses.iterator(); iter.hasNext();) {
+ VariableAccess variableAccess = (VariableAccess) iter.next();
+ if (variableAccess.isWritable()) outputNames.add(variableAccess.getMappedName());
}
return outputNames;
}
- boolean hasReadableVariable() {
- if (variableAccesses == null) return false;
- Iterator iter = variableAccesses.iterator();
- while (iter.hasNext()) {
- VariableAccess variableAccess = (VariableAccess) iter.next();
- if (variableAccess.isReadable()) {
- return true;
+ private boolean hasReadableVariable() {
+ if (variableAccesses != null) {
+ for (Iterator iter = variableAccesses.iterator(); iter.hasNext();) {
+ VariableAccess variableAccess = (VariableAccess) iter.next();
+ if (variableAccess.isReadable()) return true;
}
}
return false;
}
- void setVariables(Map outputMap, ExecutionContext executionContext) {
- if ((outputMap != null) && (!outputMap.isEmpty()) && (executionContext != null)) {
- Map variableNames = getVariableNames();
- ContextInstance contextInstance = executionContext.getContextInstance();
- Token token = executionContext.getToken();
+ private void setVariables(Map outputMap, ExecutionContext executionContext) {
+ if (variableAccesses == null) return;
- Iterator iter = outputMap.keySet().iterator();
- while (iter.hasNext()) {
- String mappedName = (String) iter.next();
- String variableName = (String) variableNames.get(mappedName);
- contextInstance.setVariable(variableName, outputMap.get(mappedName), token);
- }
- }
- }
+ ContextInstance contextInstance = executionContext.getContextInstance();
+ Token token = executionContext.getToken();
- Map getVariableNames() {
- Map variableNames = new HashMap();
- Iterator iter = variableAccesses.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = variableAccesses.iterator(); iter.hasNext();) {
VariableAccess variableAccess = (VariableAccess) iter.next();
if (variableAccess.isWritable()) {
- variableNames.put(variableAccess.getMappedName(), variableAccess.getVariableName());
+ Object value = outputMap.get(variableAccess.getMappedName());
+ contextInstance.setVariable(variableAccess.getVariableName(), value, token);
}
}
- return variableNames;
}
public String getExpression() {
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Node.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Node.java 2010-03-31 08:20:39 UTC (rev 6239)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Node.java 2010-04-01 02:41:22 UTC (rev 6240)
@@ -108,15 +108,14 @@
}
// event types //////////////////////////////////////////////////////////////
-
- private static final String[] EVENT_TYPES = {
- Event.EVENTTYPE_NODE_ENTER, Event.EVENTTYPE_NODE_LEAVE, Event.EVENTTYPE_BEFORE_SIGNAL,
- Event.EVENTTYPE_AFTER_SIGNAL
- };
+ private static final String[] EVENT_TYPES =
+ { Event.EVENTTYPE_NODE_ENTER, Event.EVENTTYPE_NODE_LEAVE, Event.EVENTTYPE_BEFORE_SIGNAL,
+ Event.EVENTTYPE_AFTER_SIGNAL };
+
/**
- * @deprecated arrays are mutable and thus vulnerable to external manipulation.
- * use {@link #getSupportedEventTypes()} instead
+ * @deprecated arrays are mutable and thus vulnerable to external
+ * manipulation. use {@link #getSupportedEventTypes()} instead
*/
public static final String[] supportedEventTypes = (String[]) EVENT_TYPES.clone();
@@ -274,21 +273,17 @@
* is the default leaving transition.
*/
public Transition getDefaultLeavingTransition() {
- Transition defaultTransition = null;
if (leavingTransitions != null) {
- // Select the first unconditional transition
+ // select the first unconditional transition
for (Iterator i = leavingTransitions.iterator(); i.hasNext();) {
- Transition auxTransition = (Transition) i.next();
- if (auxTransition.getCondition() == null) {
- defaultTransition = auxTransition;
- break;
- }
+ Transition transition = (Transition) i.next();
+ if (transition.getCondition() == null) return transition;
}
}
else if (superState != null) {
- defaultTransition = superState.getDefaultLeavingTransition();
+ return superState.getDefaultLeavingTransition();
}
- return defaultTransition;
+ return null;
}
/**
@@ -487,8 +482,8 @@
String oldName = this.name;
if (superState != null) {
if (superState.hasNode(name)) {
- throw new IllegalArgumentException("cannot rename " + this
- + " because " + superState + " already has a node named " + name);
+ throw new IllegalArgumentException("cannot rename " + this + " because " + superState
+ + " already has a node named " + name);
}
Map nodes = superState.getNodesMap();
nodes.remove(oldName);
@@ -496,8 +491,8 @@
}
else if (processDefinition != null) {
if (processDefinition.hasNode(name)) {
- throw new IllegalArgumentException("cannot rename " + this
- + " because " + processDefinition + " already has a node named " + name);
+ throw new IllegalArgumentException("cannot rename " + this + " because "
+ + processDefinition + " already has a node named " + name);
}
Map nodeMap = processDefinition.getNodesMap();
nodeMap.remove(oldName);
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/exe/Token.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/exe/Token.java 2010-03-31 08:20:39 UTC (rev 6239)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/exe/Token.java 2010-04-01 02:41:22 UTC (rev 6240)
@@ -128,8 +128,8 @@
}
/**
- * provides a signal to the token. this method activates this token and leaves
- * the current state over the default transition.
+ * sends a signal to this token. leaves the current {@link #getNode() node}
+ * over the default transition.
*/
public void signal() {
if (node == null) {
@@ -143,8 +143,8 @@
}
/**
- * Provides a signal to the token. This leave the current state over the given
- * transition name.
+ * sends a signal to this token. leaves the current {@link #getNode() node}
+ * over the transition with the given name.
*/
public void signal(String transitionName) {
if (node == null) {
@@ -152,28 +152,26 @@
}
Transition leavingTransition = node.getLeavingTransition(transitionName);
-
if (leavingTransition == null) {
- // Fall back to the name of the target node
- for (Iterator i = node.getLeavingTransitions().iterator(); i.hasNext();) {
- Transition auxTrans = (Transition) i.next();
- if (transitionName.equals(auxTrans.getTo().getName())) {
- leavingTransition = auxTrans;
+ // fall back to target node name
+ for (Iterator iter = node.getLeavingTransitions().iterator(); iter.hasNext();) {
+ Transition transition = (Transition) iter.next();
+ if (transitionName.equals(transition.getTo().getName())) {
+ leavingTransition = transition;
break;
}
}
+ if (leavingTransition == null) {
+ throw new JbpmException(node + " has no leaving transition named " + transitionName);
+ }
}
- if (leavingTransition == null) {
- throw new JbpmException(node + " has no leaving transition named " + transitionName);
- }
-
signal(leavingTransition, new ExecutionContext(this));
}
/**
- * provides a signal to the token. this leave the current state over the given
- * transition name.
+ * sends a signal to this token. leaves the current {@link #getNode() node}
+ * over the given transition.
*/
public void signal(Transition transition) {
signal(transition, new ExecutionContext(this));
@@ -214,7 +212,6 @@
// fire the event after-signal
signalNode.fireEvent(Event.EVENTTYPE_AFTER_SIGNAL, executionContext);
-
}
finally {
endCompositeLog();
@@ -235,7 +232,7 @@
/**
* adds available transitions of that node to the Set and after that calls
- * itself recursivly for the SuperSate of the Node if it has a super state
+ * itself recursively for the SuperSate of the Node if it has a super state
*/
private void addAvailableTransitionsOfNode(Node currentNode, Set availableTransitions) {
List leavingTransitions = currentNode.getLeavingTransitions();
@@ -244,8 +241,8 @@
Transition transition = (Transition) iter.next();
String conditionExpression = transition.getCondition();
if (conditionExpression != null) {
- Object result = JbpmExpressionEvaluator.evaluate(conditionExpression, new ExecutionContext(
- this));
+ Object result =
+ JbpmExpressionEvaluator.evaluate(conditionExpression, new ExecutionContext(this));
if ((result instanceof Boolean) && (((Boolean) result).booleanValue())) {
availableTransitions.add(transition);
}
@@ -262,7 +259,7 @@
/**
* ends this token and all of its children (if any). this is the last active
- * (=not-ended) child of a parent token, the parent token will be ended as
+ * (i.e. not-ended) child of a parent token, the parent token will be ended as
* well and that verification will continue to propagate.
*/
public void end() {
@@ -372,10 +369,10 @@
* convenience method for adding a process log.
*/
public void addLog(ProcessLog processLog) {
- LoggingInstance li = (LoggingInstance) processInstance.getInstance(LoggingInstance.class);
- if (li != null) {
+ LoggingInstance loggingInstance = processInstance.getLoggingInstance();
+ if (loggingInstance != null) {
processLog.setToken(this);
- li.addLog(processLog);
+ loggingInstance.addLog(processLog);
}
}
@@ -384,10 +381,10 @@
* logs, make sure you put the {@link #endCompositeLog()} in a finally block.
*/
public void startCompositeLog(CompositeLog compositeLog) {
- LoggingInstance li = (LoggingInstance) processInstance.getInstance(LoggingInstance.class);
- if (li != null) {
+ LoggingInstance loggingInstance = processInstance.getLoggingInstance();
+ if (loggingInstance != null) {
compositeLog.setToken(this);
- li.startCompositeLog(compositeLog);
+ loggingInstance.startCompositeLog(compositeLog);
}
}
@@ -396,10 +393,8 @@
* finally block.
*/
public void endCompositeLog() {
- LoggingInstance li = (LoggingInstance) processInstance.getInstance(LoggingInstance.class);
- if (li != null) {
- li.endCompositeLog();
- }
+ LoggingInstance loggingInstance = processInstance.getLoggingInstance();
+ if (loggingInstance != null) loggingInstance.endCompositeLog();
}
// various information extraction methods ///////////////////////////////////
@@ -615,8 +610,8 @@
public int hashCode() {
int result = 2080763213 + (name != null ? name.hashCode() : 0);
- result = 1076685199 * result
- + (parent != null ? parent.hashCode() : processInstance.hashCode());
+ result =
+ 1076685199 * result + (parent != null ? parent.hashCode() : processInstance.hashCode());
return result;
}
@@ -652,13 +647,8 @@
log.debug('\'' + lockOwnerId + "' locked " + this);
}
else if (!lock.equals(lockOwnerId)) {
- throw new JbpmException('\''
- + lockOwnerId
- + "' cannot lock "
- + this
- + " because '"
- + lock
- + "' already locked it");
+ throw new JbpmException('\'' + lockOwnerId + "' cannot lock " + this + " because '"
+ + lock + "' already locked it");
}
}
@@ -668,19 +658,14 @@
public void unlock(String lockOwnerId) {
if (lock != null) {
if (!lock.equals(lockOwnerId)) {
- throw new JbpmException('\''
- + lockOwnerId
- + "' cannot unlock "
- + this
- + " because '"
- + lock
- + "' locked it");
+ throw new JbpmException('\'' + lockOwnerId + "' cannot unlock " + this + " because '"
+ + lock + "' locked it");
}
lock = null;
log.debug('\'' + lockOwnerId + "' unlocked " + this);
}
else {
- log.warn(this + " was unlocked already");
+ log.warn(this + " was already unlocked");
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/Fork.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/Fork.java 2010-03-31 08:20:39 UTC (rev 6239)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/Fork.java 2010-04-01 02:41:22 UTC (rev 6240)
@@ -23,17 +23,18 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.dom4j.Element;
import org.jbpm.JbpmException;
import org.jbpm.graph.action.Script;
+import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.def.Node;
+import org.jbpm.graph.def.Transition;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.exe.Token;
import org.jbpm.jpdl.xml.JpdlXmlReader;
@@ -41,19 +42,20 @@
/**
* specifies configurable fork behaviour.
* <p>
- * if this fork behaviour is not sufficient for your needs, consider writing your own custom
- * TokenHandler.
- * </p>
- * <p>
- * this forkhandler can be configured in 3 ways :
+ * the fork can behave in two ways:
* <ul>
- * <li>without configuration : in that case the fork will launch one new sub-token over each of the
- * leaving tranisions of the fork node.</li>
- * <li>a script : can be used to calculate a collection of transition names at runtime. if a script
- * is configured, the script must have exactly one variable with 'write' access. that variable
- * should be assigned a java.util.Collection in the script expression.</li>
+ * <li>without configuration, the fork spawns one new child token over each
+ * leaving transition.</li>
+ * <li>with a script, the fork evaluates the script to obtain the names of
+ * leaving transitions to take. the script must have exactly one variable with
+ * 'write' access. the script has to assign a {@link Collection} of transition
+ * names ({@link String}) to that variable.</li>
* </ul>
* </p>
+ * <p>
+ * if these behaviors do not cover your needs, consider writing a custom
+ * {@link ActionHandler}.
+ * </p>
*/
public class Fork extends Node {
@@ -62,7 +64,7 @@
/**
* a script that calculates the transitionNames at runtime.
*/
- Script script = null;
+ Script script;
public Fork() {
}
@@ -76,110 +78,91 @@
}
public void read(Element forkElement, JpdlXmlReader jpdlReader) {
- Element scriptElement = forkElement.element("script");
- if (scriptElement != null) {
- log.warn("KNOWN LIMITATION: the script in a fork is not persisted. script in fork might be removed in later versions of jPDL");
- script = new Script();
- script.read(scriptElement, jpdlReader);
- }
+ // nothing to read
}
public void execute(ExecutionContext executionContext) {
- Token token = executionContext.getToken();
-
- // phase one: collect all the transitionNames
- Collection transitionNames = null;
- List forkedTokens = new ArrayList();
-
- // by default, the fork spawns a token for each leaving transition
+ // phase one: determine leaving transitions
+ Collection transitionNames;
if (script == null) {
- transitionNames = getLeavingTransitionsMap().keySet();
-
- }
- else { // a script is specified
- // if a script is specified, use that script to calculate the set
- // of leaving transitions to be used for forking tokens.
- Map outputMap = null;
- try {
- outputMap = script.eval(token);
+ // by default, take all leaving transitions
+ List transitions = getLeavingTransitions();
+ transitionNames = new ArrayList(transitions.size());
+ for (Iterator iter = transitions.iterator(); iter.hasNext();) {
+ Transition transition = (Transition) iter.next();
+ transitionNames.add(transition.getName());
}
- catch (Exception e) {
- this.raiseException(e, executionContext);
- }
- if (outputMap.size() == 1) {
- Object result = outputMap.values().iterator().next();
- if (result instanceof Collection) {
- transitionNames = (Collection) result;
- }
- }
- if (transitionNames == null) {
- throw new JbpmException("script for fork '"
- + name
- + "' should produce one collection (in one writable variable): "
- + transitionNames);
- }
}
+ else {
+ // script evaluation selects transitions to take
+ transitionNames = evaluateScript(executionContext);
+ }
- // TODO add some way of blocking the current token here and disable that blocking when the join reactivates this token
- // Then an exception can be thrown by in case someone tries to signal a token that is waiting in a fork.
- // Suspend and resume can NOT be used for this since that will also suspend any related timers, tasks and messages...
- // So a separate kind of blocking should be created for this.
- // @see also http://jira.jboss.com/jira/browse/JBPM-642
+ // lock the arriving token to prevent application code from signaling tokens
+ // parked in a fork
+ // the corresponding join node unlocks the token after joining
+ // https://jira.jboss.com/jira/browse/JBPM-642
+ Token token = executionContext.getToken();
+ token.lock(toString());
- // phase two: create forked tokens for the collected transition names
- Iterator iter = transitionNames.iterator();
- while (iter.hasNext()) {
+ // phase two: create child token for each selected transition
+ Map childTokens = new HashMap();
+ for (Iterator iter = transitionNames.iterator(); iter.hasNext();) {
String transitionName = (String) iter.next();
- forkedTokens.add(createForkedToken(token, transitionName));
+ Token childToken = createForkedToken(token, transitionName);
+ childTokens.put(transitionName, childToken);
}
- // phase three: launch child tokens from the fork over the given transitions
- iter = forkedTokens.iterator();
- while (iter.hasNext()) {
- ForkedToken forkedToken = (ForkedToken) iter.next();
- Token childToken = forkedToken.token;
- String leavingTransitionName = forkedToken.leavingTransitionName;
- ExecutionContext childExecutionContext = new ExecutionContext(childToken);
- if (leavingTransitionName != null) {
- leave(childExecutionContext, leavingTransitionName);
- }
- else {
- leave(childExecutionContext);
- }
+ // phase three: branch child tokens from the fork into the transitions
+ for (Iterator iter = childTokens.entrySet().iterator(); iter.hasNext();) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ String transitionName = (String) entry.getKey();
+ Token childToken = (Token) entry.getValue();
+ leave(new ExecutionContext(childToken), transitionName);
}
}
- protected ForkedToken createForkedToken(Token parent, String transitionName) {
- // instantiate the new token
- Token childToken = new Token(parent, getTokenName(parent, transitionName));
+ /** evaluates script and retrieves the names of leaving transitions. */
+ private Collection evaluateScript(ExecutionContext executionContext) {
+ Map outputMap = script.eval(executionContext);
+ if (outputMap.size() == 1) {
+ // interpret single output value as collection
+ Object result = outputMap.values().iterator().next();
+ if (result instanceof Collection) return (Collection) result;
+ }
+ throw new JbpmException("expected " + script
+ + " to write one collection variable, output was: " + outputMap);
+ }
- // create a forked token
- ForkedToken forkedToken = null;
- forkedToken = new ForkedToken(childToken, transitionName);
-
- return forkedToken;
+ protected Token createForkedToken(Token parent, String transitionName) {
+ // instantiate the child token
+ return new Token(parent, getTokenName(parent, transitionName));
}
protected String getTokenName(Token parent, String transitionName) {
- String tokenName = null;
if (transitionName != null) {
- if (!parent.hasChild(transitionName)) {
- tokenName = transitionName;
- }
- else {
- int i = 2;
- tokenName = transitionName + Integer.toString(i);
- while (parent.hasChild(tokenName)) {
- i++;
- tokenName = transitionName + Integer.toString(i);
- }
- }
+ // use transition name, if not taken already
+ if (!parent.hasChild(transitionName)) return transitionName;
+
+ // append numeric suffix to transition name
+ StringBuffer tokenText = new StringBuffer(transitionName);
+ String tokenName;
+
+ int baseLength = transitionName.length();
+ int suffix = 2;
+ do {
+ tokenText.append(suffix++);
+ tokenName = tokenText.toString();
+ tokenText.setLength(baseLength);
+ } while (parent.hasChild(tokenName));
+
+ return tokenName;
}
- else { // no transition name
- int size = (parent.getChildren() != null ? parent.getChildren().size() + 1 : 1);
- tokenName = Integer.toString(size);
+ // no transition name
+ else {
+ Map childTokens = parent.getChildren();
+ return childTokens != null ? Integer.toString(childTokens.size() + 1) : "1";
}
- return tokenName;
}
public Script getScript() {
@@ -189,17 +172,4 @@
public void setScript(Script script) {
this.script = script;
}
-
- static class ForkedToken {
-
- Token token = null;
- String leavingTransitionName = null;
-
- public ForkedToken(Token token, String leavingTransitionName) {
- this.token = token;
- this.leavingTransitionName = leavingTransitionName;
- }
- }
-
- private static Log log = LogFactory.getLog(Fork.class);
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/InterleaveStart.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/InterleaveStart.java 2010-03-31 08:20:39 UTC (rev 6239)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/InterleaveStart.java 2010-04-01 02:41:22 UTC (rev 6240)
@@ -114,18 +114,18 @@
}
protected void storeTransitionNames(Collection transitionNames, Token token) {
- ContextInstance ci = (ContextInstance) token.getProcessInstance().getInstance(ContextInstance.class);
+ ContextInstance ci = token.getProcessInstance().getContextInstance();
if (ci==null) throw new JbpmException("an interleave start node requires the availability of a context");
ci.setVariable(variableName,transitionNames, token);
}
public Collection retrieveTransitionNames(Token token) {
- ContextInstance ci = (ContextInstance) token.getProcessInstance().getInstance(ContextInstance.class);
+ ContextInstance ci = token.getProcessInstance().getContextInstance();
return (Collection) ci.getVariable(variableName, token);
}
public void removeTransitionNames(Token token) {
- ContextInstance ci = (ContextInstance) token.getProcessInstance().getInstance(ContextInstance.class);
+ ContextInstance ci = token.getProcessInstance().getContextInstance();
ci.setVariable(variableName,null, token);
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/Join.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/Join.java 2010-03-31 08:20:39 UTC (rev 6239)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/Join.java 2010-04-01 02:41:22 UTC (rev 6240)
@@ -23,6 +23,7 @@
import java.util.Collection;
import java.util.Iterator;
+import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -31,6 +32,7 @@
import org.hibernate.Session;
import org.jbpm.JbpmContext;
+import org.jbpm.JbpmException;
import org.jbpm.graph.action.Script;
import org.jbpm.graph.def.Node;
import org.jbpm.graph.exe.ExecutionContext;
@@ -49,17 +51,17 @@
/**
* specifies if this join is a discriminator. a descriminator reactivates the
- * parent when the first concurrent token enters the join.
+ * parent when the first child token enters the join.
*/
boolean isDiscriminator;
/**
- * a fixed set of concurrent tokens.
+ * a fixed set of child tokens.
*/
Collection tokenNames;
/**
- * a script that calculates concurrent tokens at runtime.
+ * a script that calculates child tokens at runtime.
*/
Script script;
@@ -112,8 +114,8 @@
Session session;
if (jbpmContext != null && (session = jbpmContext.getSession()) != null) {
// obtain update lock by default (LockMode.UPGRADE)
- LockMode lockMode = parentLockMode != null ? LockMode.parse(parentLockMode)
- : LockMode.UPGRADE;
+ LockMode lockMode =
+ parentLockMode != null ? LockMode.parse(parentLockMode) : LockMode.UPGRADE;
// load() hits the database as required, no need to flush() here
parentToken = (Token) session.load(Token.class, new Long(parentToken.getId()), lockMode);
log.debug(this + " acquires " + lockMode + " lock on " + parentToken);
@@ -128,68 +130,74 @@
// if a fixed set of tokenNames is specified at design time...
else if (tokenNames != null) {
// check reactivation on the basis of those tokenNames
- reactivateParent = !parentToken.hasActiveChildren()
- && mustParentBeReactivated(parentToken, tokenNames);
+ reactivateParent =
+ !parentToken.hasActiveChildren() && mustParentBeReactivated(parentToken, tokenNames);
}
// if a script is specified
else if (script != null) {
- // check if the script returns a collection or a boolean
- Object result = null;
- try {
- result = script.eval(arrivingToken);
- }
- catch (Exception e) {
- raiseException(e, executionContext);
- }
- // if the result is a collection
- if (result instanceof Collection) {
- // interpret as a collection of token names
- Collection tokenNames = (Collection) result;
- reactivateParent = !parentToken.hasActiveChildren()
- && mustParentBeReactivated(parentToken, tokenNames);
- }
- // if it is a boolean...
- else if (result instanceof Boolean) {
- // the boolean specifies if the parent needs to be reactivated
- reactivateParent = ((Boolean) result).booleanValue();
- }
- // any other object
- else {
- // non-null result means the parent needs to be reactivated
- reactivateParent = result != null;
- }
+ // script evaluation tells whether parent must be reactivated
+ reactivateParent = evaluateScript(executionContext);
}
// if a nOutOfM is specified
else if (nOutOfM != -1) {
int n = 0;
- // check how many tokens already arrived in the join
+ // check how many tokens arrived already
for (Iterator iter = parentToken.getChildren().values().iterator(); iter.hasNext();) {
- Token concurrentToken = (Token) iter.next();
- if (equals(concurrentToken.getNode())) n++;
+ Token childToken = (Token) iter.next();
+ if (equals(childToken.getNode())) n++;
}
reactivateParent = n >= nOutOfM;
}
// if no configuration is specified
else {
- // check all concurrent tokens and reactivate the parent
+ // check all child tokens and reactivate the parent
// when the last token arrives in the join
Collection tokenNames = parentToken.getChildren().keySet();
- reactivateParent = !parentToken.hasActiveChildren()
- && mustParentBeReactivated(parentToken, tokenNames);
+ reactivateParent =
+ !parentToken.hasActiveChildren() && mustParentBeReactivated(parentToken, tokenNames);
}
// if the parent token is to leave this node
if (reactivateParent) {
- // ensure concurrent tokens are unable to reactivate the parent
+ // make sibling tokens unable to reactivate the parent
for (Iterator iter = parentToken.getChildren().values().iterator(); iter.hasNext();) {
- Token concurrentToken = (Token) iter.next();
- concurrentToken.setAbleToReactivateParent(false);
+ Token childToken = (Token) iter.next();
+ childToken.setAbleToReactivateParent(false);
}
+ // unlock parent token
+ parentToken.unlock(parentToken.getNode().toString());
// leave the join node
leave(new ExecutionContext(parentToken));
}
}
+ private boolean evaluateScript(ExecutionContext executionContext) {
+ Map outputMap = script.eval(executionContext);
+ if (outputMap.size() == 1) {
+ // extract single output value
+ Object result = outputMap.values().iterator().next();
+
+ // if result is a collection
+ if (result instanceof Collection) {
+ Token parentToken = executionContext.getToken().getParent();
+ return !parentToken.hasActiveChildren()
+ && mustParentBeReactivated(parentToken, (Collection) result);
+ }
+ // if it is a boolean...
+ else if (result instanceof Boolean) {
+ // the boolean value tells whether the parent must be reactivated
+ return ((Boolean) result).booleanValue();
+ }
+ // any other object
+ else {
+ // non-null result means the parent must be reactivated
+ return result != null;
+ }
+ }
+ throw new JbpmException("expected " + script + " to write one variable, output was: "
+ + outputMap);
+ }
+
private boolean mustParentBeReactivated(Token parentToken, Collection childTokenNames) {
return mustParentBeReactivated(parentToken, childTokenNames.iterator());
}
@@ -200,7 +208,7 @@
Token childToken = parentToken.getChild(childTokenName);
if (childToken.isAbleToReactivateParent()) {
log.debug(parentToken + " does not leave " + this + " as " + childToken
- + " can still reactivate it");
+ + " is still active");
return false;
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/TaskNode.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/TaskNode.java 2010-03-31 08:20:39 UTC (rev 6239)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/TaskNode.java 2010-04-01 02:41:22 UTC (rev 6240)
@@ -126,10 +126,10 @@
}
}
- Set tasks;
- int signal = SIGNAL_LAST;
- boolean createTasks = true;
- boolean endTasks;
+ private Set tasks;
+ private int signal = SIGNAL_LAST;
+ private boolean createTasks = true;
+ private boolean endTasks;
public TaskNode() {
}
@@ -204,12 +204,10 @@
}
}
- boolean evaluateTaskCondition(String condition,
- ExecutionContext executionContext) {
+ private boolean evaluateTaskCondition(String condition, ExecutionContext executionContext) {
if (condition == null) return true;
- Object result = JbpmExpressionEvaluator.evaluate(condition,
- executionContext);
+ Object result = JbpmExpressionEvaluator.evaluate(condition, executionContext);
return Boolean.TRUE.equals(result);
}
@@ -242,17 +240,15 @@
return completionTriggersSignal;
}
- boolean isLastToComplete(TaskInstance taskInstance) {
+ private boolean isLastToComplete(TaskInstance taskInstance) {
Token token = taskInstance.getToken();
TaskMgmtInstance tmi = getTaskMgmtInstance(token);
boolean isLastToComplete = true;
- for (Iterator iter = tmi.getTaskInstances().iterator(); iter.hasNext()
- && isLastToComplete;) {
+ for (Iterator iter = tmi.getTaskInstances().iterator(); iter.hasNext() && isLastToComplete;) {
TaskInstance other = (TaskInstance) iter.next();
- if (token != null && token.equals(other.getToken())
- && !other.equals(taskInstance) && other.isSignalling()
- && !other.hasEnded()) {
+ if (token != null && token.equals(other.getToken()) && !other.equals(taskInstance)
+ && other.isSignalling() && !other.hasEnded()) {
isLastToComplete = false;
}
}
@@ -275,10 +271,8 @@
if (taskInstance.isBlocking()) {
taskInstance.setBlocking(false);
}
- // if this is a non-finished task and all those
- // tasks should be finished
- if (!taskInstance.hasEnded() && endTasks
- && tasks.contains(taskInstance.getTask())) {
+ // if this is a non-finished task and all tasks should be finished
+ if (!taskInstance.hasEnded() && endTasks && tasks.contains(taskInstance.getTask())) {
// end this task
taskInstance.end();
}
@@ -287,9 +281,8 @@
}
}
- TaskMgmtInstance getTaskMgmtInstance(Token token) {
- return (TaskMgmtInstance) token.getProcessInstance()
- .getInstance(TaskMgmtInstance.class);
+ private static TaskMgmtInstance getTaskMgmtInstance(Token token) {
+ return token.getProcessInstance().getTaskMgmtInstance();
}
// getters and setters
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/exe/MilestoneInstance.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/exe/MilestoneInstance.java 2010-03-31 08:20:39 UTC (rev 6239)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/exe/MilestoneInstance.java 2010-04-01 02:41:22 UTC (rev 6240)
@@ -21,48 +21,51 @@
*/
package org.jbpm.jpdl.exe;
-import java.io.*;
-import java.util.*;
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
-import org.jbpm.context.exe.*;
-import org.jbpm.graph.def.*;
-import org.jbpm.graph.exe.*;
+import org.jbpm.context.exe.ContextInstance;
+import org.jbpm.graph.def.Node;
+import org.jbpm.graph.exe.ExecutionContext;
+import org.jbpm.graph.exe.Token;
public class MilestoneInstance implements Serializable {
-
+
private static final long serialVersionUID = 1L;
-
- protected long id = 0;
- protected String name = null;
- protected boolean reached = false;
- protected Token token = null;
- protected Collection listeners = null;
-
+
+ protected long id;
+ protected String name;
+ protected boolean reached;
+ protected Token token;
+ protected Collection listeners;
+
public MilestoneInstance() {
}
public MilestoneInstance(String name) {
this.name = name;
}
-
+
public static MilestoneInstance getMilestoneInstance(String milestoneName, Token token) {
- ContextInstance ci = (ContextInstance) token.getProcessInstance().getInstance(ContextInstance.class);
- MilestoneInstance mi = (MilestoneInstance) ci.getVariable( milestoneName, token );
+ ContextInstance ci = token.getProcessInstance().getContextInstance();
+ MilestoneInstance mi = (MilestoneInstance) ci.getVariable(milestoneName, token);
if (mi == null) {
mi = new MilestoneInstance(milestoneName);
mi.setToken(token);
- ci.setVariable( milestoneName, mi );
+ ci.setVariable(milestoneName, mi);
}
return mi;
}
public void addListener(Token token) {
- if ( listeners == null ) listeners = new HashSet();
- listeners.add( token );
+ if (listeners == null) listeners = new HashSet();
+ listeners.add(token);
}
-
+
public void notifyListeners() {
- if ( listeners != null ) {
+ if (listeners != null) {
// for every token that was waiting for this milestone
Iterator iter = listeners.iterator();
while (iter.hasNext()) {
@@ -78,30 +81,39 @@
public long getId() {
return id;
}
+
public void setId(long id) {
this.id = id;
}
+
public Collection getListeners() {
return listeners;
}
+
public void setListeners(Collection listeners) {
this.listeners = listeners;
}
+
public String getName() {
return name;
}
+
public void setName(String name) {
this.name = name;
}
+
public boolean isReached() {
return reached;
}
+
public void setReached(boolean reached) {
this.reached = reached;
}
+
public Token getToken() {
return token;
}
+
public void setToken(Token token) {
this.token = token;
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/context/exe/VariableTypeTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/context/exe/VariableTypeTest.java 2010-03-31 08:20:39 UTC (rev 6239)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/context/exe/VariableTypeTest.java 2010-04-01 02:41:22 UTC (rev 6240)
@@ -41,7 +41,7 @@
processDefinition = new ProcessDefinition();
processDefinition.addDefinition(new ContextDefinition());
processInstance = new ProcessInstance( processDefinition );
- contextInstance = (ContextInstance) processInstance.getInstance(ContextInstance.class);
+ contextInstance = processInstance.getContextInstance();
}
public void testString() {
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/context/log/VariableLogTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/context/log/VariableLogTest.java 2010-03-31 08:20:39 UTC (rev 6239)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/context/log/VariableLogTest.java 2010-04-01 02:41:22 UTC (rev 6240)
@@ -47,8 +47,8 @@
processDefinition = new ProcessDefinition();
processDefinition.addDefinition(new ContextDefinition());
processInstance = new ProcessInstance( processDefinition );
- contextInstance = (ContextInstance) processInstance.getInstance(ContextInstance.class);
- loggingInstance = (LoggingInstance) processInstance.getInstance(LoggingInstance.class);
+ contextInstance = processInstance.getContextInstance();
+ loggingInstance = processInstance.getLoggingInstance();
}
public void testVariableCreateLogs() {
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/graph/action/ScriptTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/graph/action/ScriptTest.java 2010-03-31 08:20:39 UTC (rev 6239)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/graph/action/ScriptTest.java 2010-04-01 02:41:22 UTC (rev 6240)
@@ -61,7 +61,7 @@
processDefinition.addDefinition(new ContextDefinition());
ProcessInstance processInstance = new ProcessInstance(processDefinition);
- ContextInstance contextInstance = (ContextInstance) processInstance.getInstance(ContextInstance.class);
+ ContextInstance contextInstance = processInstance.getContextInstance();
contextInstance.setVariable("b", new Integer(3));
contextInstance.setVariable("c", new Integer(9));
processInstance.signal();
Added: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm642/JBPM642Test.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm642/JBPM642Test.java (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm642/JBPM642Test.java 2010-04-01 02:41:22 UTC (rev 6240)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.jbpm642;
+
+import org.jbpm.AbstractJbpmTestCase;
+import org.jbpm.JbpmException;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.graph.exe.Token;
+
+/**
+ * @author Alejandro Guizar
+ */
+public class JBPM642Test extends AbstractJbpmTestCase {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testSignalTokenInFork() {
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlResource("org/jbpm/jbpm642/processdefinition.xml");
+
+ ProcessInstance processInstance = new ProcessInstance(processDefinition);
+ processInstance.signal();
+
+ Token rootToken = processInstance.getRootToken();
+ assertEquals("fork", rootToken.getNode().getName());
+
+ try {
+ rootToken.signal();
+ fail("expected locked exception");
+ }
+ catch (JbpmException e) {
+ assert e.getMessage().indexOf("locked") != -1 : e;
+ }
+
+ rootToken.getChild("left").signal();
+ rootToken.getChild("2").signal();
+ assertEquals("middle", rootToken.getNode().getName());
+
+ rootToken.signal();
+ assert processInstance.hasEnded() : "expected " + processInstance + " to have ended";
+ }
+}
Property changes on: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm642/JBPM642Test.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp04ExclusiveChoiceTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp04ExclusiveChoiceTest.java 2010-03-31 08:20:39 UTC (rev 6239)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp04ExclusiveChoiceTest.java 2010-04-01 02:41:22 UTC (rev 6240)
@@ -23,7 +23,6 @@
import org.jbpm.AbstractJbpmTestCase;
import org.jbpm.context.def.ContextDefinition;
-import org.jbpm.context.exe.ContextInstance;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.graph.exe.Token;
@@ -31,48 +30,38 @@
/**
* http://is.tm.tue.nl/research/patterns/download/swf/pat_4.swf
*
- * <p>we make a distinction in the api between process and client based
- * decisions. the first tests show the situations as described in the
- * pattern. after that a demonstration of client based decision is
- * added.
- * </p>
+ * <p>
+ * we make a distinction in the api between process and client based decisions.
+ * the first tests show the situations as described in the pattern. after that a
+ * demonstration of client based decision is added.
+ * </p>
*
- * <p>process based
- * decisions makes use of a decision node. the node has a piece of
- * programming logic associated that calculates the leaving transition
- * name. the programming logic is executed within the calculation of
- * the next state of the process instance.
+ * <p>
+ * process based decisions makes use of a decision node. the node has a piece of
+ * programming logic associated that calculates the leaving transition name. the
+ * programming logic is executed within the calculation of the next state of the
+ * process instance.
* </p>
*
- * <p>client based decisions allow clients to select on of the multiple
- * transitions that leave the current state.
- * </p>
+ * <p>
+ * client based decisions allow clients to select on of the multiple transitions
+ * that leave the current state.
+ * </p>
*/
public class Wfp04ExclusiveChoiceTest extends AbstractJbpmTestCase {
-
- static ProcessDefinition exclusiveChoiceProcessDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state name='start'>" +
- " <transition to='a' />" +
- " </start-state>" +
- " <state name='a'>" +
- " <transition to='xor' />" +
- " </state>" +
- " <decision name='xor'>" +
- " <transition name='forget about it' to='d'/>" +
- " <transition name='urgent' to='b'>" +
- " <condition>#{scenario==1}</condition>" +
- " </transition>" +
- " <transition name='dont care' to='c'>" +
- " <condition>#{scenario==2}</condition>" +
- " </transition>" +
- " </decision>" +
- " <state name='b' />" +
- " <state name='c' />" +
- " <state name='d' />" +
- "</process-definition>" );
+
+ static ProcessDefinition exclusiveChoiceProcessDefinition =
+ ProcessDefinition.parseXmlString("<process-definition>" + " <start-state name='start'>"
+ + " <transition to='a' />" + " </start-state>" + " <state name='a'>"
+ + " <transition to='xor' />" + " </state>" + " <decision name='xor'>"
+ + " <transition name='forget about it' to='d'/>"
+ + " <transition name='urgent' to='b'>" + " <condition>#{scenario==1}</condition>"
+ + " </transition>" + " <transition name='dont care' to='c'>"
+ + " <condition>#{scenario==2}</condition>" + " </transition>" + " </decision>"
+ + " <state name='b' />" + " <state name='c' />" + " <state name='d' />"
+ + "</process-definition>");
static {
- exclusiveChoiceProcessDefinition.addDefinition( new ContextDefinition() );
+ exclusiveChoiceProcessDefinition.addDefinition(new ContextDefinition());
}
/**
@@ -81,17 +70,16 @@
public void testExclusiveChoiceSituation1() {
ProcessDefinition pd = exclusiveChoiceProcessDefinition;
- ProcessInstance pi = new ProcessInstance( pd );
- ContextInstance ci = (ContextInstance) pi.getInstance( ContextInstance.class );
+ ProcessInstance pi = new ProcessInstance(pd);
pi.signal();
+
Token root = pi.getRootToken();
+ assertSame(pd.getNode("a"), root.getNode());
- assertSame( pd.getNode("a"), root.getNode() );
-
- ci.setVariable( "scenario", new Integer(1) );
+ pi.getContextInstance().setVariable("scenario", new Integer(1));
root.signal();
-
- assertSame( pd.getNode("b"), root.getNode() );
+
+ assertSame(pd.getNode("b"), root.getNode());
}
/**
@@ -100,17 +88,16 @@
public void testExclusiveChoiceSituation2() {
ProcessDefinition pd = exclusiveChoiceProcessDefinition;
- ProcessInstance pi = new ProcessInstance( pd );
- ContextInstance ci = (ContextInstance) pi.getInstance( ContextInstance.class );
+ ProcessInstance pi = new ProcessInstance(pd);
pi.signal();
+
Token root = pi.getRootToken();
+ assertSame(pd.getNode("a"), root.getNode());
- assertSame( pd.getNode("a"), root.getNode() );
-
- ci.setVariable( "scenario", new Integer(2) );
+ pi.getContextInstance().setVariable("scenario", new Integer(2));
root.signal();
-
- assertSame( pd.getNode("c"), root.getNode() );
+
+ assertSame(pd.getNode("c"), root.getNode());
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp06MultiChoiceTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp06MultiChoiceTest.java 2010-03-31 08:20:39 UTC (rev 6239)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp06MultiChoiceTest.java 2010-04-01 02:41:22 UTC (rev 6240)
@@ -24,7 +24,6 @@
import org.jbpm.AbstractJbpmTestCase;
import org.jbpm.context.def.ContextDefinition;
import org.jbpm.context.def.VariableAccess;
-import org.jbpm.context.exe.ContextInstance;
import org.jbpm.graph.action.Script;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
@@ -35,90 +34,94 @@
* http://is.tm.tue.nl/research/patterns/download/swf/pat_6.swf
*/
public class Wfp06MultiChoiceTest extends AbstractJbpmTestCase {
-
+
private static ProcessDefinition multiChoiceProcessDefinition = createMultiChoiceProcessDefinition();
- public static ProcessDefinition createMultiChoiceProcessDefinition() {
- ProcessDefinition pd = new ProcessDefinition(
- new String[]{"start-state start",
- "state a",
- "fork multichoice",
- "state b",
- "state c",
- "join syncmerge",
- "end-state end"},
- new String[]{"start --> a",
- "a --> multichoice",
- "multichoice --to b--> b",
- "multichoice --to c--> c",
- "b --> syncmerge",
- "c --> syncmerge",
- "syncmerge --> end"});
-
+ static ProcessDefinition createMultiChoiceProcessDefinition() {
+ ProcessDefinition pd = new ProcessDefinition(new String[] {
+ "start-state start",
+ "state a",
+ "fork multichoice",
+ "state b",
+ "state c",
+ "join syncmerge",
+ "end-state end"
+ }, new String[] {
+ "start --> a",
+ "a --> multichoice",
+ "multichoice --to b--> b",
+ "multichoice --to c--> c",
+ "b --> syncmerge",
+ "c --> syncmerge",
+ "syncmerge --> end"
+ });
+
// create the script
Script script = new Script();
- script.addVariableAccess(new VariableAccess("transitionNames","write",null));
- script.setExpression(
- "transitionNames = new ArrayList();" +
- "if ( scenario == 1 ) {" +
- " transitionNames.add( \"to b\" );" +
- "} else if ( scenario == 2 ) {" +
- " transitionNames.add( \"to c\" );" +
- "} else if ( scenario >= 3 ) {" +
- " transitionNames.add( \"to b\" );" +
- " transitionNames.add( \"to c\" );" +
- "}" );
-
+ script.addVariableAccess(new VariableAccess("transitionNames", "write", null));
+ script.setExpression("transitionNames = new ArrayList();"
+ + "if ( scenario == 1 ) {"
+ + " transitionNames.add( \"to b\" );"
+ + "} else if ( scenario == 2 ) {"
+ + " transitionNames.add( \"to c\" );"
+ + "} else if ( scenario >= 3 ) {"
+ + " transitionNames.add( \"to b\" );"
+ + " transitionNames.add( \"to c\" );"
+ + "}");
+
// put the script in the multichoice handler
Fork fork = (Fork) pd.getNode("multichoice");
- fork.setScript( script );
-
- pd.addDefinition( new ContextDefinition() );
-
+ fork.setScript(script);
+
+ pd.addDefinition(new ContextDefinition());
return pd;
}
public void testMultiChoiceScenario1() {
ProcessDefinition pd = multiChoiceProcessDefinition;
Token root = executeScenario(pd, 1);
- Token tokenB = root.getChild("to b"); // the default token names are extracted from the leaving transitions
- Token tokenC = root.getChild("to c"); // the default token names are extracted from the leaving transitions
- assertNotNull( tokenB );
- assertNull( tokenC );
- assertEquals( 1, root.getChildren().size() );
- assertSame( pd.getNode("b"), tokenB.getNode() );
+ // the token names come from the leaving transitions
+ Token tokenB = root.getChild("to b");
+ Token tokenC = root.getChild("to c");
+ assertNotNull(tokenB);
+ assertNull(tokenC);
+ assertEquals(1, root.getChildren().size());
+ assertSame(pd.getNode("b"), tokenB.getNode());
}
public void testMultiChoiceScenario2() {
ProcessDefinition pd = multiChoiceProcessDefinition;
Token root = executeScenario(pd, 2);
- Token tokenB = root.getChild("to b"); // the default token names are extracted from the leaving transitions
- Token tokenC = root.getChild("to c"); // the default token names are extracted from the leaving transitions
- assertNull( tokenB );
- assertNotNull( tokenC );
- assertEquals( 1, root.getChildren().size() );
- assertSame( pd.getNode("c"), tokenC.getNode() );
+ // the token names come from the leaving transitions
+ Token tokenB = root.getChild("to b");
+ Token tokenC = root.getChild("to c");
+ assertNull(tokenB);
+ assertNotNull(tokenC);
+ assertEquals(1, root.getChildren().size());
+ assertSame(pd.getNode("c"), tokenC.getNode());
}
public void testMultiChoiceScenario3() {
ProcessDefinition pd = multiChoiceProcessDefinition;
Token root = executeScenario(pd, 3);
- Token tokenB = root.getChild("to b"); // the default token names are extracted from the leaving transitions
- Token tokenC = root.getChild("to c"); // the default token names are extracted from the leaving transitions
- assertNotNull( tokenB );
- assertNotNull( tokenC );
- assertEquals( 2, root.getChildren().size() );
- assertSame( pd.getNode("b"), tokenB.getNode() );
- assertSame( pd.getNode("c"), tokenC.getNode() );
+ // the token names come from the leaving transitions
+ Token tokenB = root.getChild("to b");
+ Token tokenC = root.getChild("to c");
+ assertNotNull(tokenB);
+ assertNotNull(tokenC);
+ assertEquals(2, root.getChildren().size());
+ assertSame(pd.getNode("b"), tokenB.getNode());
+ assertSame(pd.getNode("c"), tokenC.getNode());
}
- public static Token executeScenario(ProcessDefinition pd, int scenario) {
- ProcessInstance pi = new ProcessInstance( pd );
- ContextInstance ci = (ContextInstance) pi.getInstance( ContextInstance.class );
+ static Token executeScenario(ProcessDefinition pd, int scenario) {
+ ProcessInstance pi = new ProcessInstance(pd);
pi.signal();
+
Token root = pi.getRootToken();
- assertSame( pd.getNode("a"), root.getNode() );
- ci.setVariable( "scenario", new Integer(scenario) );
+ assertSame(pd.getNode("a"), root.getNode());
+ pi.getContextInstance().setVariable("scenario", new Integer(scenario));
+
root.signal();
return root;
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp07SynchronizingMergeTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp07SynchronizingMergeTest.java 2010-03-31 08:20:39 UTC (rev 6239)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp07SynchronizingMergeTest.java 2010-04-01 02:41:22 UTC (rev 6240)
@@ -37,58 +37,62 @@
public void testSynchronizingMergeScenario1() {
ProcessDefinition pd = synchronizingMergeProcessDefinition;
- Token root = Wfp06MultiChoiceTest.executeScenario(pd,1);
- Token tokenB = root.getChild("to b"); // the default token names are extracted from the leaving transitions
+ // the token names come from the leaving transitions
+ Token root = Wfp06MultiChoiceTest.executeScenario(pd, 1);
+ Token tokenB = root.getChild("to b");
tokenB.signal();
- assertSame( pd.getNode("end"), root.getNode() );
- assertSame( pd.getNode("syncmerge"), tokenB.getNode() );
+ assertSame(pd.getNode("end"), root.getNode());
+ assertSame(pd.getNode("syncmerge"), tokenB.getNode());
}
public void testSynchronizingMergeScenario2() {
ProcessDefinition pd = synchronizingMergeProcessDefinition;
- Token root = Wfp06MultiChoiceTest.executeScenario(pd,2);
- Token tokenC = root.getChild("to c"); // the default token names are extracted from the leaving transitions
+ // the token names come from the leaving transitions
+ Token root = Wfp06MultiChoiceTest.executeScenario(pd, 2);
+ Token tokenC = root.getChild("to c");
tokenC.signal();
- assertSame( pd.getNode("end"), root.getNode() );
- assertSame( pd.getNode("syncmerge"), tokenC.getNode() );
+ assertSame(pd.getNode("end"), root.getNode());
+ assertSame(pd.getNode("syncmerge"), tokenC.getNode());
}
public void testSynchronizingMergeScenario3() {
ProcessDefinition pd = synchronizingMergeProcessDefinition;
- Token root = Wfp06MultiChoiceTest.executeScenario(pd,3);
- Token tokenB = root.getChild("to b"); // the default token names are extracted from the leaving transitions
- Token tokenC = root.getChild("to c"); // the default token names are extracted from the leaving transitions
+ // the token names come from the leaving transitions
+ Token root = Wfp06MultiChoiceTest.executeScenario(pd, 3);
+ Token tokenB = root.getChild("to b");
+ Token tokenC = root.getChild("to c");
tokenB.signal();
- assertSame( pd.getNode("multichoice"), root.getNode() );
- assertSame( pd.getNode("syncmerge"), tokenB.getNode() );
- assertSame( pd.getNode("c"), tokenC.getNode() );
+ assertSame(pd.getNode("multichoice"), root.getNode());
+ assertSame(pd.getNode("syncmerge"), tokenB.getNode());
+ assertSame(pd.getNode("c"), tokenC.getNode());
tokenC.signal();
- assertSame( pd.getNode("end"), root.getNode() );
- assertSame( pd.getNode("syncmerge"), tokenB.getNode() );
- assertSame( pd.getNode("syncmerge"), tokenC.getNode() );
+ assertSame(pd.getNode("end"), root.getNode());
+ assertSame(pd.getNode("syncmerge"), tokenB.getNode());
+ assertSame(pd.getNode("syncmerge"), tokenC.getNode());
}
public void testSynchronizingMergeScenario4() {
ProcessDefinition pd = synchronizingMergeProcessDefinition;
- Token root = Wfp06MultiChoiceTest.executeScenario(pd,3);
- Token tokenB = root.getChild("to b"); // the default token names are extracted from the leaving transitions
- Token tokenC = root.getChild("to c"); // the default token names are extracted from the leaving transitions
+ // the token names come from the leaving transitions
+ Token root = Wfp06MultiChoiceTest.executeScenario(pd, 3);
+ Token tokenB = root.getChild("to b");
+ Token tokenC = root.getChild("to c");
tokenC.signal();
- assertSame( pd.getNode("multichoice"), root.getNode() );
- assertSame( pd.getNode("b"), tokenB.getNode() );
- assertSame( pd.getNode("syncmerge"), tokenC.getNode() );
+ assertSame(pd.getNode("multichoice"), root.getNode());
+ assertSame(pd.getNode("b"), tokenB.getNode());
+ assertSame(pd.getNode("syncmerge"), tokenC.getNode());
tokenB.signal();
- assertSame( pd.getNode("end"), root.getNode() );
- assertSame( pd.getNode("syncmerge"), tokenB.getNode() );
- assertSame( pd.getNode("syncmerge"), tokenC.getNode() );
+ assertSame(pd.getNode("end"), root.getNode());
+ assertSame(pd.getNode("syncmerge"), tokenB.getNode());
+ assertSame(pd.getNode("syncmerge"), tokenC.getNode());
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp13MiWithoutSynchronizationTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp13MiWithoutSynchronizationTest.java 2010-03-31 08:20:39 UTC (rev 6239)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp13MiWithoutSynchronizationTest.java 2010-04-01 02:41:22 UTC (rev 6240)
@@ -32,53 +32,51 @@
import org.jbpm.taskmgmt.exe.TaskMgmtInstance;
/**
- * http://is.tm.tue.nl/research/patterns/download/swf/pat_12.swf
- * actually this is a combination of unsynchronized tasks and
- * runtime calculation of the tasks.
+ * http://is.tm.tue.nl/research/patterns/download/swf/pat_12.swf actually this
+ * is a combination of unsynchronized tasks and runtime calculation of the
+ * tasks.
*/
public class Wfp13MiWithoutSynchronizationTest extends AbstractJbpmTestCase {
- private ProcessDefinition pd = null;
- private ProcessInstance pi = null;
+ private ProcessDefinition pd;
+ private ProcessInstance pi;
- static int scenario = 0;
+ static int scenario;
public static class CreateTasks implements ActionHandler {
private static final long serialVersionUID = 1L;
+
public void execute(ExecutionContext executionContext) throws Exception {
// this piece of code is executed at runtime
TaskMgmtDefinition taskMgmtDefinition = (TaskMgmtDefinition) executionContext.getDefinition(TaskMgmtDefinition.class);
Task task = taskMgmtDefinition.getTask("undress");
-
+
TaskMgmtInstance tmi = executionContext.getTaskMgmtInstance();
- for (int i = 1; i<scenario; i++) {
+ for (int i = 1; i < scenario; i++) {
tmi.createTaskInstance(task, executionContext.getToken());
}
}
}
- protected void setUp() throws Exception
- {
+ protected void setUp() throws Exception {
super.setUp();
- pd = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state name='a'>" +
- " <transition to='b' />" +
- " </start-state>" +
- " <node name='b'>" +
- " <event type='node-enter'>" +
- " <action class='org.jbpm.jpdl.patterns.Wfp13MiWithoutSynchronizationTest$CreateTasks'/>" +
- " </event>" +
- " <transition to='c' />" +
- " </node>" +
- " <state name='c' />" +
- " <task name='undress' />" +
- "</process-definition>"
- );
-
+ pd = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state name='a'>"
+ + " <transition to='b' />"
+ + " </start-state>"
+ + " <node name='b'>"
+ + " <event type='node-enter'>"
+ + " <action class='org.jbpm.jpdl.patterns.Wfp13MiWithoutSynchronizationTest$CreateTasks'/>"
+ + " </event>"
+ + " <transition to='c' />"
+ + " </node>"
+ + " <state name='c' />"
+ + " <task name='undress' />"
+ + "</process-definition>");
+
pi = new ProcessInstance(pd);
}
-
+
public void testSituation1() {
scenario = 1;
pi.signal();
@@ -104,10 +102,10 @@
}
private void assertNbrOfTasks(int nbrOfTasks) {
- TaskMgmtInstance taskMgmtInstance = (TaskMgmtInstance) pi.getInstance(TaskMgmtInstance.class);
+ TaskMgmtInstance taskMgmtInstance = pi.getTaskMgmtInstance();
Token token = pi.getRootToken();
-
- assertEquals( nbrOfTasks, taskMgmtInstance.getUnfinishedTasks( token ).size() );
- assertSame( pd.getNode("c"), token.getNode() );
+
+ assertEquals(nbrOfTasks, taskMgmtInstance.getUnfinishedTasks(token).size());
+ assertSame(pd.getNode("c"), token.getNode());
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp14MiWithAPrioriDesigntimeKnowledgeTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp14MiWithAPrioriDesigntimeKnowledgeTest.java 2010-03-31 08:20:39 UTC (rev 6239)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp14MiWithAPrioriDesigntimeKnowledgeTest.java 2010-04-01 02:41:22 UTC (rev 6240)
@@ -37,70 +37,69 @@
public class Wfp14MiWithAPrioriDesigntimeKnowledgeTest extends AbstractJbpmTestCase {
public void testSituation1() {
- ProcessDefinition pd = ProcessDefinition.parseXmlString(
- "<process-definition name='the life of a baby ?'>" +
- " <start-state name='a'>" +
- " <transition to='b' />" +
- " </start-state>" +
- " <state name='b'>" +
- " <transition to='t' />" +
- " </state>" +
- " <task-node name='t'>" +
- " <task name='eat' />" +
- " <task name='drink' />" +
- " <task name='sleep' />" +
- " <transition to='c' />" +
- " </task-node>" +
- " <state name='c' />" +
- "</process-definition>"
- );
+ ProcessDefinition pd = ProcessDefinition.parseXmlString("<process-definition name='the life of a baby'>"
+ + " <start-state name='a'>"
+ + " <transition to='b' />"
+ + " </start-state>"
+ + " <state name='b'>"
+ + " <transition to='t' />"
+ + " </state>"
+ + " <task-node name='t'>"
+ + " <task name='eat' />"
+ + " <task name='drink' />"
+ + " <task name='sleep' />"
+ + " <transition to='c' />"
+ + " </task-node>"
+ + " <state name='c' />"
+ + "</process-definition>");
- ProcessInstance pi = new ProcessInstance( pd );
- TaskMgmtInstance taskMgmtInstance = (TaskMgmtInstance) pi.getInstance(TaskMgmtInstance.class);
-
+ ProcessInstance pi = new ProcessInstance(pd);
+ TaskMgmtInstance taskMgmtInstance = pi.getTaskMgmtInstance();
+
pi.signal();
Token token = pi.getRootToken();
// after start, the token is waiting in state b
- assertSame( pd.getNode("b"), token.getNode() );
-
+ assertSame(pd.getNode("b"), token.getNode());
+
// and no tasks have been created yet
- assertEquals(0, taskMgmtInstance.getUnfinishedTasks(token).size() );
+ assertEquals(0, taskMgmtInstance.getUnfinishedTasks(token).size());
// now we signal the process to move on.
// execution will arrive at the task-node
- // the default behaviour of the task node is to create each task and wait till the last one finishes
+ // the default behaviour of the task node is to create each task and wait
+ // till the last one finishes
pi.signal();
// now, 3 tasks have been created...
- List tasks = new ArrayList( taskMgmtInstance.getUnfinishedTasks(token) );
+ List tasks = new ArrayList(taskMgmtInstance.getUnfinishedTasks(token));
assertEquals(3, tasks.size());
// ... and the process is in the task state
- assertSame( pd.getNode("t"), token.getNode() );
+ assertSame(pd.getNode("t"), token.getNode());
// now we finish the tasks one by one
// finish task 0
- ((TaskInstance)tasks.get(0)).end();
-
+ ((TaskInstance) tasks.get(0)).end();
+
// still 2 tasks remaining
- assertEquals(2, taskMgmtInstance.getUnfinishedTasks(token).size() );
+ assertEquals(2, taskMgmtInstance.getUnfinishedTasks(token).size());
// and the process is still in node t
- assertSame( pd.getNode("t"), token.getNode() );
-
+ assertSame(pd.getNode("t"), token.getNode());
+
// finish task 1
- ((TaskInstance)tasks.get(1)).end();
-
+ ((TaskInstance) tasks.get(1)).end();
+
// still 1 task remaining
- assertEquals(1, taskMgmtInstance.getUnfinishedTasks(token).size() );
+ assertEquals(1, taskMgmtInstance.getUnfinishedTasks(token).size());
// and the process is still in node t
- assertSame( pd.getNode("t"), token.getNode() );
-
+ assertSame(pd.getNode("t"), token.getNode());
+
// finish task 2
- ((TaskInstance)tasks.get(2)).end();
-
+ ((TaskInstance) tasks.get(2)).end();
+
// no more tasks remaining
- assertEquals(0, taskMgmtInstance.getUnfinishedTasks(token).size() );
+ assertEquals(0, taskMgmtInstance.getUnfinishedTasks(token).size());
// and the process has moved to node c
- assertEquals( pd.getNode("c"), token.getNode() );
+ assertEquals(pd.getNode("c"), token.getNode());
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp15MiWithAPrioriRuntimeKnowledgeTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp15MiWithAPrioriRuntimeKnowledgeTest.java 2010-03-31 08:20:39 UTC (rev 6239)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp15MiWithAPrioriRuntimeKnowledgeTest.java 2010-04-01 02:41:22 UTC (rev 6240)
@@ -39,117 +39,106 @@
public class Wfp15MiWithAPrioriRuntimeKnowledgeTest extends AbstractJbpmTestCase {
public static int scenario = -1;
-
+
public static class CreateTasks implements ActionHandler {
private static final long serialVersionUID = 1L;
+
public void execute(ExecutionContext executionContext) throws Exception {
TaskMgmtDefinition tmd = (TaskMgmtDefinition) executionContext.getDefinition(TaskMgmtDefinition.class);
Task task = tmd.getTask("watch movie amadeus");
-
- // create as many task instances as the scenario prescribes :
- // 0 tasks for scenario 1
- // 1 task for scenario 2
- // 2 tasks for scenario 3
- // 3 tasks for scenario 4
+
+ // create as many task instances as the scenario prescribes :
+ // 0 tasks for scenario 1
+ // 1 task for scenario 2
+ // 2 tasks for scenario 3
+ // 3 tasks for scenario 4
TaskMgmtInstance tmi = executionContext.getTaskMgmtInstance();
- for (int i = 1; i<scenario; i++) {
+ for (int i = 1; i < scenario; i++) {
tmi.createTaskInstance(task, executionContext.getToken());
}
}
}
- public static ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state name='a'>" +
- " <transition to='b' />" +
- " </start-state>" +
- " <state name='b'>" +
- " <transition to='t' />" +
- " </state>" +
- " <task-node name='t' create-tasks='false'>" +
- " <event type='node-enter'>" +
- " <action class='org.jbpm.jpdl.patterns.Wfp15MiWithAPrioriRuntimeKnowledgeTest$CreateTasks' />" +
- " </event>" +
- " <task name='watch movie amadeus' />" +
- " <transition to='c' />" +
- " </task-node>" +
- " <state name='c' />" +
- "</process-definition>"
- );
-
+ public static ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state name='a'>"
+ + " <transition to='b' />"
+ + " </start-state>"
+ + " <state name='b'>"
+ + " <transition to='t' />"
+ + " </state>"
+ + " <task-node name='t' create-tasks='false'>"
+ + " <event type='node-enter'>"
+ + " <action class='org.jbpm.jpdl.patterns.Wfp15MiWithAPrioriRuntimeKnowledgeTest$CreateTasks' />"
+ + " </event>"
+ + " <task name='watch movie amadeus' />"
+ + " <transition to='c' />"
+ + " </task-node>"
+ + " <state name='c' />"
+ + "</process-definition>");
+
public static Node t = processDefinition.getNode("t");
public static Node c = processDefinition.getNode("c");
public void testAprioriRuntimeKnowledgeScenario1() {
scenario = 1;
-
+
ProcessInstance processInstance = new ProcessInstance(processDefinition);
Token token = processInstance.getRootToken();
processInstance.signal();
processInstance.signal();
-
assertSame(c, token.getNode());
}
public void testAprioriRuntimeKnowledgeScenario2() {
scenario = 2;
-
+
ProcessInstance processInstance = new ProcessInstance(processDefinition);
Token token = processInstance.getRootToken();
processInstance.signal();
processInstance.signal();
-
assertSame(t, token.getNode());
-
- endOneTask(token);
+ endOneTask(token);
assertSame(c, token.getNode());
}
public void testAprioriRuntimeKnowledgeScenario3() {
scenario = 3;
-
+
ProcessInstance processInstance = new ProcessInstance(processDefinition);
Token token = processInstance.getRootToken();
processInstance.signal();
processInstance.signal();
-
assertSame(t, token.getNode());
-
- endOneTask(token);
- assertSame(t, token.getNode());
-
endOneTask(token);
+ assertSame(t, token.getNode());
+ endOneTask(token);
assertSame(c, token.getNode());
}
public void testAprioriRuntimeKnowledgeScenario4() {
scenario = 4;
-
+
ProcessInstance processInstance = new ProcessInstance(processDefinition);
Token token = processInstance.getRootToken();
processInstance.signal();
processInstance.signal();
-
assertSame(t, token.getNode());
-
- endOneTask(token);
- assertSame(t, token.getNode());
-
endOneTask(token);
-
assertSame(t, token.getNode());
-
+
endOneTask(token);
+ assertSame(t, token.getNode());
+ endOneTask(token);
assertSame(c, token.getNode());
}
public static void endOneTask(Token token) {
- TaskMgmtInstance tmi = (TaskMgmtInstance)token.getProcessInstance().getInstance(TaskMgmtInstance.class);
+ TaskMgmtInstance tmi = token.getProcessInstance().getTaskMgmtInstance();
TaskInstance taskInstance = (TaskInstance) tmi.getUnfinishedTasks(token).iterator().next();
taskInstance.end();
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp16MiWithoutAPrioriRuntimeKnowledgeTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp16MiWithoutAPrioriRuntimeKnowledgeTest.java 2010-03-31 08:20:39 UTC (rev 6239)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp16MiWithoutAPrioriRuntimeKnowledgeTest.java 2010-04-01 02:41:22 UTC (rev 6240)
@@ -37,161 +37,145 @@
* http://is.tm.tue.nl/research/patterns/download/swf/pat_15.swf
*/
public class Wfp16MiWithoutAPrioriRuntimeKnowledgeTest extends AbstractJbpmTestCase {
-
+
public static int scenario = -1;
-
+
public static class CreateTasks implements ActionHandler {
private static final long serialVersionUID = 1L;
+
public void execute(ExecutionContext executionContext) throws Exception {
TaskMgmtDefinition tmd = (TaskMgmtDefinition) executionContext.getDefinition(TaskMgmtDefinition.class);
Task task = tmd.getTask("watch movie amadeus");
-
- // create as many task instances as the scenario prescribes :
- // 0 tasks for scenario 1
- // 1 task for scenario 2
- // 2 tasks for scenario 3
- // 3 tasks for scenario 4
+
+ // create as many task instances as the scenario prescribes :
+ // 0 tasks for scenario 1
+ // 1 task for scenario 2
+ // 2 tasks for scenario 3
+ // 3 tasks for scenario 4
TaskMgmtInstance tmi = executionContext.getTaskMgmtInstance();
- for (int i = 1; i<scenario; i++) {
+ for (int i = 1; i < scenario; i++) {
tmi.createTaskInstance(task, executionContext.getToken());
}
}
}
- public static ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state name='a'>" +
- " <transition to='b' />" +
- " </start-state>" +
- " <state name='b'>" +
- " <transition to='t' />" +
- " </state>" +
- " <task-node name='t' create-tasks='false' signal='last-wait'>" +
- " <event type='node-enter'>" +
- " <action class='" + CreateTasks.class.getName() + "' />" +
- " </event>" +
- " <task name='watch movie amadeus' />" +
- " <transition to='c' />" +
- " </task-node>" +
- " <state name='c' />" +
- "</process-definition>"
- );
-
+ public static ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state name='a'>"
+ + " <transition to='b' />"
+ + " </start-state>"
+ + " <state name='b'>"
+ + " <transition to='t' />"
+ + " </state>"
+ + " <task-node name='t' create-tasks='false' signal='last-wait'>"
+ + " <event type='node-enter'>"
+ + " <action class='"
+ + CreateTasks.class.getName()
+ + "' />"
+ + " </event>"
+ + " <task name='watch movie amadeus' />"
+ + " <transition to='c' />"
+ + " </task-node>"
+ + " <state name='c' />"
+ + "</process-definition>");
+
public static Node t = processDefinition.getNode("t");
public static Node c = processDefinition.getNode("c");
public void testAprioriRuntimeKnowledgeScenario1() {
scenario = 1;
-
+
ProcessInstance processInstance = new ProcessInstance(processDefinition);
Token token = processInstance.getRootToken();
processInstance.signal();
processInstance.signal();
-
assertSame(t, token.getNode());
assertEquals(0, getNbrOfTasks(token));
-
- addOneTask(token);
+ addOneTask(token);
assertSame(t, token.getNode());
assertEquals(1, getNbrOfTasks(token));
-
- addOneTask(token);
+ addOneTask(token);
assertSame(t, token.getNode());
assertEquals(2, getNbrOfTasks(token));
-
- endOneTask(token);
+ endOneTask(token);
assertSame(t, token.getNode());
assertEquals(1, getNbrOfTasks(token));
-
- endOneTask(token);
+ endOneTask(token);
assertSame(c, token.getNode());
assertEquals(0, getNbrOfTasks(token));
}
public void testAprioriRuntimeKnowledgeScenario2() {
scenario = 2;
-
+
ProcessInstance processInstance = new ProcessInstance(processDefinition);
Token token = processInstance.getRootToken();
processInstance.signal();
processInstance.signal();
-
assertSame(t, token.getNode());
assertEquals(1, getNbrOfTasks(token));
-
- addOneTask(token);
+ addOneTask(token);
assertSame(t, token.getNode());
assertEquals(2, getNbrOfTasks(token));
-
- endOneTask(token);
+ endOneTask(token);
assertSame(t, token.getNode());
assertEquals(1, getNbrOfTasks(token));
-
- endOneTask(token);
+ endOneTask(token);
assertSame(c, token.getNode());
assertEquals(0, getNbrOfTasks(token));
}
public void testAprioriRuntimeKnowledgeScenario3() {
scenario = 3;
-
+
ProcessInstance processInstance = new ProcessInstance(processDefinition);
Token token = processInstance.getRootToken();
processInstance.signal();
processInstance.signal();
-
assertSame(t, token.getNode());
assertEquals(2, getNbrOfTasks(token));
-
- addOneTask(token);
+ addOneTask(token);
assertSame(t, token.getNode());
assertEquals(3, getNbrOfTasks(token));
-
+
endOneTask(token);
endOneTask(token);
-
assertSame(t, token.getNode());
assertEquals(1, getNbrOfTasks(token));
-
- endOneTask(token);
+ endOneTask(token);
assertSame(c, token.getNode());
assertEquals(0, getNbrOfTasks(token));
}
public void testAprioriRuntimeKnowledgeScenario4() {
scenario = 4;
-
+
ProcessInstance processInstance = new ProcessInstance(processDefinition);
Token token = processInstance.getRootToken();
processInstance.signal();
processInstance.signal();
-
assertSame(t, token.getNode());
assertEquals(3, getNbrOfTasks(token));
-
- addOneTask(token);
+ addOneTask(token);
assertSame(t, token.getNode());
assertEquals(4, getNbrOfTasks(token));
-
+
endOneTask(token);
endOneTask(token);
endOneTask(token);
-
assertSame(t, token.getNode());
assertEquals(1, getNbrOfTasks(token));
-
- endOneTask(token);
+ endOneTask(token);
assertSame(c, token.getNode());
assertEquals(0, getNbrOfTasks(token));
}
@@ -199,18 +183,18 @@
private void addOneTask(Token token) {
TaskMgmtDefinition tmd = (TaskMgmtDefinition) processDefinition.getDefinition(TaskMgmtDefinition.class);
Task task = tmd.getTask("watch movie amadeus");
-
+
TaskMgmtInstance tmi = token.getProcessInstance().getTaskMgmtInstance();
tmi.createTaskInstance(task, token);
}
private int getNbrOfTasks(Token token) {
- TaskMgmtInstance tmi = (TaskMgmtInstance) token.getProcessInstance().getInstance(TaskMgmtInstance.class);
+ TaskMgmtInstance tmi = token.getProcessInstance().getTaskMgmtInstance();
return tmi.getUnfinishedTasks(token).size();
}
public static void endOneTask(Token token) {
- TaskMgmtInstance tmi = (TaskMgmtInstance)token.getProcessInstance().getInstance(TaskMgmtInstance.class);
+ TaskMgmtInstance tmi = token.getProcessInstance().getTaskMgmtInstance();
TaskInstance taskInstance = (TaskInstance) tmi.getUnfinishedTasks(token).iterator().next();
taskInstance.end();
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/logging/exe/CompositeLogTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/logging/exe/CompositeLogTest.java 2010-03-31 08:20:39 UTC (rev 6239)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/logging/exe/CompositeLogTest.java 2010-04-01 02:41:22 UTC (rev 6240)
@@ -30,72 +30,72 @@
import org.jbpm.logging.log.ProcessLog;
public class CompositeLogTest extends AbstractJbpmTestCase {
-
+
public void testCompositeLogs() {
ProcessDefinition processDefinition = new ProcessDefinition();
ProcessInstance pi = new ProcessInstance(processDefinition);
Token root = pi.getRootToken();
- LoggingInstance li = (LoggingInstance) pi.getInstance(LoggingInstance.class);
-
+ LoggingInstance li = pi.getLoggingInstance();
+
ProcessLog one = new MessageLog(null);
li.addLog(one);
-
- assertNull( one.getParent() );
- assertSame( one, li.getLogs().get(1) );
- assertEquals( 2, li.getLogs().size() );
- assertEquals( 0, li.getCompositeLogStack().size() );
+ assertNull(one.getParent());
+ assertSame(one, li.getLogs().get(1));
+ assertEquals(2, li.getLogs().size());
+ assertEquals(0, li.getCompositeLogStack().size());
+
CompositeLog two = new CompositeLog();
two.setToken(root);
li.startCompositeLog(two);
- assertNull( two.getParent() );
- assertSame( two, li.getLogs().get(2) );
- assertEquals( 3, li.getLogs().size() );
- assertEquals( 1, li.getCompositeLogStack().size() );
+ assertNull(two.getParent());
+ assertSame(two, li.getLogs().get(2));
+ assertEquals(3, li.getLogs().size());
+ assertEquals(1, li.getCompositeLogStack().size());
ProcessLog three = new MessageLog(null);
li.addLog(three);
- assertSame( two, three.getParent() );
- assertSame( three, li.getLogs().get(3) );
- assertEquals( 4, li.getLogs().size() );
- assertEquals( 1, li.getCompositeLogStack().size() );
+ assertSame(two, three.getParent());
+ assertSame(three, li.getLogs().get(3));
+ assertEquals(4, li.getLogs().size());
+ assertEquals(1, li.getCompositeLogStack().size());
CompositeLog four = new CompositeLog();
four.setToken(root);
li.startCompositeLog(four);
- assertSame( two, four.getParent() );
- assertSame( four, li.getLogs().get(4) );
- assertEquals( 5, li.getLogs().size() );
- assertEquals( 2, li.getCompositeLogStack().size() );
+ assertSame(two, four.getParent());
+ assertSame(four, li.getLogs().get(4));
+ assertEquals(5, li.getLogs().size());
+ assertEquals(2, li.getCompositeLogStack().size());
ProcessLog five = new MessageLog(null);
li.addLog(five);
- assertSame( four, five.getParent() );
- assertSame( two, five.getParent().getParent() );
- assertNull( five.getParent().getParent().getParent() );
- assertSame( five, li.getLogs().get(5) );
- assertEquals( 6, li.getLogs().size() );
- assertEquals( 2, li.getCompositeLogStack().size() );
+ assertSame(four, five.getParent());
+ assertSame(two, five.getParent().getParent());
+ assertNull(five.getParent().getParent().getParent());
+ assertSame(five, li.getLogs().get(5));
+ assertEquals(6, li.getLogs().size());
+ assertEquals(2, li.getCompositeLogStack().size());
li.endCompositeLog();
- assertEquals( 1, li.getCompositeLogStack().size() );
+ assertEquals(1, li.getCompositeLogStack().size());
ProcessLog six = new MessageLog(null);
li.addLog(six);
- assertSame( two, six.getParent() );
- assertNull( six.getParent().getParent() );
- assertSame( six, li.getLogs().get(6) );
- assertEquals( 7, li.getLogs().size() );
- assertEquals( 1, li.getCompositeLogStack().size() );
+ assertSame(two, six.getParent());
+ assertNull(six.getParent().getParent());
+ assertSame(six, li.getLogs().get(6));
+ assertEquals(7, li.getLogs().size());
+ assertEquals(1, li.getCompositeLogStack().size());
li.endCompositeLog();
-
- assertEquals( 0, li.getCompositeLogStack().size() );
+
+ assertEquals(0, li.getCompositeLogStack().size());
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/taskmgmt/exe/RuntimeTaskCreationTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/taskmgmt/exe/RuntimeTaskCreationTest.java 2010-03-31 08:20:39 UTC (rev 6239)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/taskmgmt/exe/RuntimeTaskCreationTest.java 2010-04-01 02:41:22 UTC (rev 6240)
@@ -33,13 +33,14 @@
import org.jbpm.taskmgmt.def.Task;
public class RuntimeTaskCreationTest extends AbstractJbpmTestCase {
-
+
public static class CreateTasks implements ActionHandler {
private static final long serialVersionUID = 1L;
+
public void execute(ExecutionContext executionContext) throws Exception {
Token token = executionContext.getToken();
TaskMgmtInstance tmi = executionContext.getTaskMgmtInstance();
-
+
TaskNode taskNode = (TaskNode) executionContext.getNode();
Task changeNappy = taskNode.getTask("change nappy");
@@ -50,32 +51,29 @@
}
public void testRuntimeTaskCreation() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='a' />" +
- " </start-state>" +
- " <task-node name='a' create-tasks='false'>" +
- " <event type='node-enter'>" +
- " <action class='org.jbpm.taskmgmt.exe.RuntimeTaskCreationTest$CreateTasks' />" +
- " </event>" +
- " <task name='change nappy' />'" +
- " <task name='make bottle' />'" +
- " <task name='do dishes' />'" +
- " <transition to='b' />" +
- " </task-node>" +
- " <state name='b' />" +
- "</process-definition>"
- );
-
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <task-node name='a' create-tasks='false'>"
+ + " <event type='node-enter'>"
+ + " <action class='org.jbpm.taskmgmt.exe.RuntimeTaskCreationTest$CreateTasks' />"
+ + " </event>"
+ + " <task name='change nappy' />'"
+ + " <task name='make bottle' />'"
+ + " <task name='do dishes' />'"
+ + " <transition to='b' />"
+ + " </task-node>"
+ + " <state name='b' />"
+ + "</process-definition>");
+
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.signal();
- TaskMgmtInstance tmi = (TaskMgmtInstance) processInstance.getInstance(TaskMgmtInstance.class);
+ TaskMgmtInstance tmi = processInstance.getTaskMgmtInstance();
assertNotNull(tmi);
assertEquals(2, tmi.getTaskInstances().size());
- Iterator iter = tmi.getTaskInstances().iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = tmi.getTaskInstances().iterator(); iter.hasNext();) {
TaskInstance taskInstance = (TaskInstance) iter.next();
assertEquals("change nappy", taskInstance.getName());
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/taskmgmt/exe/TaskExecutionTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/taskmgmt/exe/TaskExecutionTest.java 2010-03-31 08:20:39 UTC (rev 6239)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/taskmgmt/exe/TaskExecutionTest.java 2010-04-01 02:41:22 UTC (rev 6240)
@@ -34,30 +34,27 @@
public class TaskExecutionTest extends AbstractJbpmTestCase {
public void testSignalLast() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='a' />" +
- " </start-state>" +
- " <task-node name='a'>" +
- " <task name='laundry' />" +
- " <task name='dishes' />" +
- " <task name='change nappy' />" +
- " <transition to='b' />" +
- " </task-node>" +
- " <state name='b' />" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <task-node name='a'>"
+ + " <task name='laundry' />"
+ + " <task name='dishes' />"
+ + " <task name='change nappy' />"
+ + " <transition to='b' />"
+ + " </task-node>"
+ + " <state name='b' />"
+ + "</process-definition>");
ProcessInstance processInstance = new ProcessInstance(processDefinition);
Token token = processInstance.getRootToken();
processInstance.signal();
- TaskMgmtInstance tmi = (TaskMgmtInstance) processInstance.getInstance(TaskMgmtInstance.class);
+ TaskMgmtInstance tmi = processInstance.getTaskMgmtInstance();
assertNotNull(tmi);
assertEquals(3, tmi.getTaskInstances().size());
-
- Iterator iter = tmi.getTaskInstances().iterator();
- while (iter.hasNext()) {
+
+ for (Iterator iter = tmi.getTaskInstances().iterator(); iter.hasNext();) {
// before every task is completed, check if the token is still in node a
assertSame(processDefinition.getNode("a"), token.getNode());
TaskInstance taskInstance = (TaskInstance) iter.next();
@@ -69,33 +66,30 @@
}
public void testSignalFirst() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='a' />" +
- " </start-state>" +
- " <task-node name='a' signal='first'>" +
- " <task name='laundry' />" +
- " <task name='dishes' />" +
- " <task name='change nappy' />" +
- " <transition to='b' />" +
- " </task-node>" +
- " <state name='b' />" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <task-node name='a' signal='first'>"
+ + " <task name='laundry' />"
+ + " <task name='dishes' />"
+ + " <task name='change nappy' />"
+ + " <transition to='b' />"
+ + " </task-node>"
+ + " <state name='b' />"
+ + "</process-definition>");
ProcessInstance processInstance = new ProcessInstance(processDefinition);
Token token = processInstance.getRootToken();
processInstance.signal();
- TaskMgmtInstance tmi = (TaskMgmtInstance) processInstance.getInstance(TaskMgmtInstance.class);
+ TaskMgmtInstance tmi = processInstance.getTaskMgmtInstance();
assertNotNull(tmi);
assertEquals(3, tmi.getTaskInstances().size());
-
+
// only before the first task, the token should be in a
assertSame(processDefinition.getNode("a"), token.getNode());
- Iterator iter = tmi.getTaskInstances().iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = tmi.getTaskInstances().iterator(); iter.hasNext();) {
// before every task is completed, check if the token is still in node a
TaskInstance taskInstance = (TaskInstance) iter.next();
taskInstance.end();
@@ -103,37 +97,33 @@
// after each task, check if the token has moved to b
assertSame(processDefinition.getNode("b"), token.getNode());
}
-
}
public void testSignalNever() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='a' />" +
- " </start-state>" +
- " <task-node name='a' signal='never'>" +
- " <task name='laundry' />" +
- " <task name='dishes' />" +
- " <task name='change nappy' />" +
- " <transition to='b' />" +
- " </task-node>" +
- " <state name='b' />" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <task-node name='a' signal='never'>"
+ + " <task name='laundry' />"
+ + " <task name='dishes' />"
+ + " <task name='change nappy' />"
+ + " <transition to='b' />"
+ + " </task-node>"
+ + " <state name='b' />"
+ + "</process-definition>");
ProcessInstance processInstance = new ProcessInstance(processDefinition);
Token token = processInstance.getRootToken();
processInstance.signal();
- TaskMgmtInstance tmi = (TaskMgmtInstance) processInstance.getInstance(TaskMgmtInstance.class);
+ TaskMgmtInstance tmi = processInstance.getTaskMgmtInstance();
assertNotNull(tmi);
assertEquals(3, tmi.getTaskInstances().size());
-
+
// only before the first task, the token should be in a
assertSame(processDefinition.getNode("a"), token.getNode());
- Iterator iter = tmi.getTaskInstances().iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = tmi.getTaskInstances().iterator(); iter.hasNext();) {
// before every task is completed, check if the token is still in node a
TaskInstance taskInstance = (TaskInstance) iter.next();
taskInstance.end();
@@ -141,40 +131,37 @@
// after each task, check if the token remains in a
assertSame(processDefinition.getNode("a"), token.getNode());
}
- // signal='never' is used when an external trigger should trigger execution, without
- // any relation to the tasks finishing
+ // signal='never' is used when an external trigger should trigger execution,
+ // without any relation to the tasks finishing
processInstance.signal();
assertSame(processDefinition.getNode("b"), token.getNode());
}
public void testSignalUnsynchronized() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='a' />" +
- " </start-state>" +
- " <task-node name='a' signal='unsynchronized'>" +
- " <task name='laundry' />" +
- " <task name='dishes' />" +
- " <task name='change nappy' />" +
- " <transition to='b' />" +
- " </task-node>" +
- " <state name='b' />" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <task-node name='a' signal='unsynchronized'>"
+ + " <task name='laundry' />"
+ + " <task name='dishes' />"
+ + " <task name='change nappy' />"
+ + " <transition to='b' />"
+ + " </task-node>"
+ + " <state name='b' />"
+ + "</process-definition>");
ProcessInstance processInstance = new ProcessInstance(processDefinition);
Token token = processInstance.getRootToken();
processInstance.signal();
- TaskMgmtInstance tmi = (TaskMgmtInstance) processInstance.getInstance(TaskMgmtInstance.class);
+ TaskMgmtInstance tmi = processInstance.getTaskMgmtInstance();
assertNotNull(tmi);
assertEquals(3, tmi.getTaskInstances().size());
-
- // unsyncronized means that after creation of the tasks, execution should just continue.
+
+ // unsynchronized means execution continues right after creating the tasks
assertSame(processDefinition.getNode("b"), token.getNode());
- Iterator iter = tmi.getTaskInstances().iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = tmi.getTaskInstances().iterator(); iter.hasNext();) {
// before every task is completed, check if the token is still in node a
TaskInstance taskInstance = (TaskInstance) iter.next();
taskInstance.end();
@@ -185,66 +172,61 @@
}
public void testCreateTasksDisabled() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='a' />" +
- " </start-state>" +
- " <task-node name='a' create-tasks='false'>" +
- " <task name='laundry' />" +
- " <task name='dishes' />" +
- " <task name='change nappy' />" +
- " <transition to='b' />" +
- " </task-node>" +
- " <state name='b' />" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <task-node name='a' create-tasks='false'>"
+ + " <task name='laundry' />"
+ + " <task name='dishes' />"
+ + " <task name='change nappy' />"
+ + " <transition to='b' />"
+ + " </task-node>"
+ + " <state name='b' />"
+ + "</process-definition>");
ProcessInstance processInstance = new ProcessInstance(processDefinition);
Token token = processInstance.getRootToken();
processInstance.signal();
- TaskMgmtInstance tmi = (TaskMgmtInstance) processInstance.getInstance(TaskMgmtInstance.class);
+ TaskMgmtInstance tmi = processInstance.getTaskMgmtInstance();
assertNotNull(tmi);
assertNull(tmi.getTaskInstances());
-
- // if no tasks are created and signal is last (default) then execution continues
+
+ // if signal is last (def) and no task is created, execution continues
assertSame(processDefinition.getNode("b"), token.getNode());
}
public void testNonBlockingTask() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='a' />" +
- " </start-state>" +
- " <task-node name='a'>" +
- " <task name='laundry' />" +
- " <transition to='b' />" +
- " </task-node>" +
- " <state name='b' />" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <task-node name='a'>"
+ + " <task name='laundry' />"
+ + " <transition to='b' />"
+ + " </task-node>"
+ + " <state name='b' />"
+ + "</process-definition>");
ProcessInstance processInstance = new ProcessInstance(processDefinition);
- Token token = processInstance.getRootToken();
processInstance.signal();
+ Token token = processInstance.getRootToken();
assertSame(processDefinition.getNode("a"), token.getNode());
+
processInstance.signal();
assertSame(processDefinition.getNode("b"), token.getNode());
}
public void testBlockingTask() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='a' />" +
- " </start-state>" +
- " <task-node name='a'>" +
- " <task name='laundry' blocking='true' />" +
- " <transition to='b' />" +
- " </task-node>" +
- " <state name='b' />" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <task-node name='a'>"
+ + " <task name='laundry' blocking='true' />"
+ + " <transition to='b' />"
+ + " </task-node>"
+ + " <state name='b' />"
+ + "</process-definition>");
ProcessInstance processInstance = new ProcessInstance(processDefinition);
Token token = processInstance.getRootToken();
processInstance.signal();
@@ -252,155 +234,143 @@
try {
processInstance.signal();
fail("expected exception");
- } catch (IllegalStateException e) {
+ }
+ catch (IllegalStateException e) {
// OK
}
}
public void testTransitionNameInTaskEnd() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='t' />" +
- " </start-state>" +
- " <task-node name='t'>" +
- " <task name='change nappy' />" +
- " <transition name='ok' to='a' />" +
- " <transition name='messed all over the floor' to='b' />" +
- " </task-node>" +
- " <state name='a' />" +
- " <state name='b' />" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='t' />"
+ + " </start-state>"
+ + " <task-node name='t'>"
+ + " <task name='change nappy' />"
+ + " <transition name='ok' to='a' />"
+ + " <transition name='messed all over the floor' to='b' />"
+ + " </task-node>"
+ + " <state name='a' />"
+ + " <state name='b' />"
+ + "</process-definition>");
ProcessInstance processInstance = new ProcessInstance(processDefinition);
Token token = processInstance.getRootToken();
processInstance.signal();
assertSame(processDefinition.getNode("t"), token.getNode());
- TaskMgmtInstance tmi = (TaskMgmtInstance) processInstance.getInstance(TaskMgmtInstance.class);
+ TaskMgmtInstance tmi = processInstance.getTaskMgmtInstance();
TaskInstance taskInstance = (TaskInstance) tmi.getUnfinishedTasks(token).iterator().next();
taskInstance.end("messed all over the floor");
-
assertSame(processDefinition.getNode("b"), token.getNode());
}
public void testTransitionInTaskEnd() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='t' />" +
- " </start-state>" +
- " <task-node name='t'>" +
- " <task name='change nappy' />" +
- " <transition name='ok' to='a' />" +
- " <transition name='messed all over the floor' to='b' />" +
- " </task-node>" +
- " <state name='a' />" +
- " <state name='b' />" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='t' />"
+ + " </start-state>"
+ + " <task-node name='t'>"
+ + " <task name='change nappy' />"
+ + " <transition name='ok' to='a' />"
+ + " <transition name='messed all over the floor' to='b' />"
+ + " </task-node>"
+ + " <state name='a' />"
+ + " <state name='b' />"
+ + "</process-definition>");
ProcessInstance processInstance = new ProcessInstance(processDefinition);
Token token = processInstance.getRootToken();
processInstance.signal();
assertSame(processDefinition.getNode("t"), token.getNode());
- TaskMgmtInstance tmi = (TaskMgmtInstance) processInstance.getInstance(TaskMgmtInstance.class);
+ TaskMgmtInstance tmi = processInstance.getTaskMgmtInstance();
TaskInstance taskInstance = (TaskInstance) tmi.getUnfinishedTasks(token).iterator().next();
-
- Transition messedTransition = processDefinition.getNode("t").getLeavingTransition("messed all over the floor");
+
+ Transition messedTransition = processDefinition.getNode("t")
+ .getLeavingTransition("messed all over the floor");
taskInstance.end(messedTransition);
-
assertSame(processDefinition.getNode("b"), token.getNode());
}
public void testTaskPriorityHighest() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='t' />" +
- " </start-state>" +
- " <task-node name='t'>" +
- " <task name='change nappy' priority='highest' />" +
- " </task-node>" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='t' />"
+ + " </start-state>"
+ + " <task-node name='t'>"
+ + " <task name='change nappy' priority='highest' />"
+ + " </task-node>"
+ + "</process-definition>");
ProcessInstance processInstance = new ProcessInstance(processDefinition);
Token token = processInstance.getRootToken();
processInstance.signal();
assertSame(processDefinition.getNode("t"), token.getNode());
- TaskMgmtInstance tmi = (TaskMgmtInstance) processInstance.getInstance(TaskMgmtInstance.class);
+ TaskMgmtInstance tmi = processInstance.getTaskMgmtInstance();
TaskInstance taskInstance = (TaskInstance) tmi.getUnfinishedTasks(token).iterator().next();
-
assertEquals(Task.PRIORITY_HIGHEST, taskInstance.getPriority());
}
public void testTaskPriorityOne() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='t' />" +
- " </start-state>" +
- " <task-node name='t'>" +
- " <task name='change nappy' priority='1' />" +
- " </task-node>" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='t' />"
+ + " </start-state>"
+ + " <task-node name='t'>"
+ + " <task name='change nappy' priority='1' />"
+ + " </task-node>"
+ + "</process-definition>");
ProcessInstance processInstance = new ProcessInstance(processDefinition);
Token token = processInstance.getRootToken();
processInstance.signal();
assertSame(processDefinition.getNode("t"), token.getNode());
- TaskMgmtInstance tmi = (TaskMgmtInstance) processInstance.getInstance(TaskMgmtInstance.class);
+ TaskMgmtInstance tmi = processInstance.getTaskMgmtInstance();
TaskInstance taskInstance = (TaskInstance) tmi.getUnfinishedTasks(token).iterator().next();
-
assertEquals(1, taskInstance.getPriority());
}
public void testTaskDescriptionEvaluation() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='a' />" +
- " </start-state>" +
- " <task-node name='a' >" +
- " <task name='laundry' description='the #{company} case'>" +
- " <controller>" +
- " <variable name='company' />" +
- " </controller>" +
- " </task>" +
- " <transition to='b' />" +
- " </task-node>" +
- " <state name='b' />" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <task-node name='a' >"
+ + " <task name='laundry' description='the #{company} case'>"
+ + " <controller>"
+ + " <variable name='company' />"
+ + " </controller>"
+ + " </task>"
+ + " <transition to='b' />"
+ + " </task-node>"
+ + " <state name='b' />"
+ + "</process-definition>");
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.getContextInstance().setVariable("company", "jboss");
processInstance.signal();
- TaskMgmtInstance tmi = (TaskMgmtInstance) processInstance.getInstance(TaskMgmtInstance.class);
+ TaskMgmtInstance tmi = processInstance.getTaskMgmtInstance();
TaskInstance taskInstance = (TaskInstance) tmi.getTaskInstances().iterator().next();
assertEquals("the jboss case", taskInstance.getDescription());
}
public void testTaskDescriptionExpression() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='a' />" +
- " </start-state>" +
- " <task-node name='a'>" +
- " <task name='clean ceiling' description='This task is about #{item}' />" +
- " </task-node>" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <task-node name='a'>"
+ + " <task name='clean ceiling' description='This task is about #{item}' />"
+ + " </task-node>"
+ + "</process-definition>");
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.getContextInstance().setVariable("item", "shoes");
processInstance.signal();
+
Token token = processInstance.getRootToken();
Collection taskInstances = processInstance.getTaskMgmtInstance().getUnfinishedTasks(token);
assertEquals(1, taskInstances.size());
+
TaskInstance taskInstance = (TaskInstance) taskInstances.iterator().next();
assertEquals("This task is about shoes", taskInstance.getDescription());
}
Added: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm642/gpd.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm642/gpd.xml (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm642/gpd.xml 2010-04-01 02:41:22 UTC (rev 6240)
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<root-container name="jbpm642" width="884" height="567">
+ <node name="start" x="72" y="24" width="121" height="37">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="fork" x="72" y="96" width="121" height="24">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="left" x="12" y="156" width="97" height="37">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="right" x="156" y="156" width="109" height="36">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="join" x="72" y="228" width="121" height="25">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="end" x="72" y="360" width="121" height="37"/>
+ <node name="middle" x="72" y="288" width="121" height="37">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <deployment serverName="" serverPort="" serverDeployer="">
+ <classesAndResources/>
+ <filesAndFolders>
+ <element value="/jbpm-jpdl/src/test/resources/org/jbpm/jbpm642/gpd.xml"/>
+ <element value="/jbpm-jpdl/src/test/resources/org/jbpm/jbpm642/processdefinition.xml"/>
+ </filesAndFolders>
+ </deployment>
+</root-container>
Property changes on: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm642/gpd.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm642/processdefinition.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm642/processdefinition.xml (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm642/processdefinition.xml 2010-04-01 02:41:22 UTC (rev 6240)
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<process-definition name="jbpm642" xmlns="urn:jbpm.org:jpdl-3.2">
+
+ <start-state name="start">
+ <transition to="fork" />
+ </start-state>
+
+ <fork name="fork">
+ <transition to="left" name="left" />
+ <transition to="right" />
+ </fork>
+
+ <state name="left">
+ <transition to="join" />
+ </state>
+
+ <state name="right">
+ <transition to="join" />
+ </state>
+
+ <join name="join" >
+ <transition to="middle"></transition>
+ </join>
+
+ <state name="middle">
+ <transition to="end"></transition>
+ </state>
+
+ <end-state name="end" />
+
+</process-definition>
\ No newline at end of file
Property changes on: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm642/processdefinition.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
More information about the jbpm-commits
mailing list