[jbpm-commits] JBoss JBPM SVN: r2153 - in jbpm3/trunk/modules/core/src/test/java/org/jbpm: graph/exe and 6 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Sep 9 10:41:32 EDT 2008
Author: thomas.diesler at jboss.com
Date: 2008-09-09 10:41:32 -0400 (Tue, 09 Sep 2008)
New Revision: 2153
Modified:
jbpm3/trunk/modules/core/src/test/java/org/jbpm/context/exe/TokenVariableMapDbTest.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/graph/exe/ActionExceptionsTest.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/graph/exe/BusinessKeyDbTest.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/graph/exe/ExceptionHandlingTest.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/job/executor/JobExecutorDbTest.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/el/DecisionExpressionTest.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ResourceAction.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/xml/SchemaTest.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/msg/command/AsyncExecutionDbTest.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/optimisticlocking/LockingTest.java
Log:
Remove unwanted test output
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/context/exe/TokenVariableMapDbTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/context/exe/TokenVariableMapDbTest.java 2008-09-09 14:21:41 UTC (rev 2152)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/context/exe/TokenVariableMapDbTest.java 2008-09-09 14:41:32 UTC (rev 2153)
@@ -21,33 +21,37 @@
*/
package org.jbpm.context.exe;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Map;
-import org.jbpm.context.def.*;
-import org.jbpm.context.exe.variableinstance.*;
-import org.jbpm.db.*;
-import org.jbpm.graph.def.*;
-import org.jbpm.graph.exe.*;
+import org.jbpm.context.def.ContextDefinition;
+import org.jbpm.context.exe.variableinstance.StringInstance;
+import org.jbpm.db.AbstractDbTestCase;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.graph.exe.Token;
-public class TokenVariableMapDbTest extends AbstractDbTestCase {
-
+public class TokenVariableMapDbTest extends AbstractDbTestCase
+{
+
ProcessDefinition processDefinition;
ProcessInstance processInstance;
Token token;
ContextInstance contextInstance;
Map tokenVariableMaps;
TokenVariableMap tokenVariableMap;
-
- public void setUp() throws Exception {
+
+ public void setUp() throws Exception
+ {
super.setUp();
-
+
processDefinition = new ProcessDefinition();
processDefinition.addDefinition(new ContextDefinition());
graphSession.saveProcessDefinition(processDefinition);
-
+
processInstance = new ProcessInstance(processDefinition);
token = processInstance.getRootToken();
-
+
contextInstance = processInstance.getContextInstance();
tokenVariableMaps = new HashMap();
tokenVariableMap = contextInstance.getOrCreateTokenVariableMap(token);
@@ -55,32 +59,35 @@
contextInstance.tokenVariableMaps = tokenVariableMaps;
}
- public void testTokenVariableMapContextInstance() {
+ public void testTokenVariableMapContextInstance()
+ {
processInstance = saveAndReload(processInstance);
token = processInstance.getRootToken();
contextInstance = processInstance.getContextInstance();
tokenVariableMaps = contextInstance.tokenVariableMaps;
- tokenVariableMap = (TokenVariableMap) tokenVariableMaps.get(token);
-
+ tokenVariableMap = (TokenVariableMap)tokenVariableMaps.get(token);
+
assertSame(contextInstance, tokenVariableMap.getContextInstance());
}
- public void testTokenVariableMapToken() {
+ public void testTokenVariableMapToken()
+ {
processInstance = saveAndReload(processInstance);
token = processInstance.getRootToken();
contextInstance = processInstance.getContextInstance();
tokenVariableMaps = contextInstance.tokenVariableMaps;
- tokenVariableMap = (TokenVariableMap) tokenVariableMaps.get(token);
-
+ tokenVariableMap = (TokenVariableMap)tokenVariableMaps.get(token);
+
assertSame(token, tokenVariableMap.getToken());
}
- public void testTokenVariableMapVariableInstances() {
- StringInstance stringVariable = (StringInstance) VariableInstance.create(token, "one", "hello");
+ public void testTokenVariableMapVariableInstances()
+ {
+ StringInstance stringVariable = (StringInstance)VariableInstance.create(token, "one", "hello");
tokenVariableMap.addVariableInstance(stringVariable);
- stringVariable = (StringInstance) VariableInstance.create(token, "two", "world");
+ stringVariable = (StringInstance)VariableInstance.create(token, "two", "world");
tokenVariableMap.addVariableInstance(stringVariable);
processInstance = saveAndReload(processInstance);
@@ -88,12 +95,12 @@
token = processInstance.getRootToken();
contextInstance = processInstance.getContextInstance();
tokenVariableMaps = contextInstance.tokenVariableMaps;
- tokenVariableMap = (TokenVariableMap) tokenVariableMaps.get(processInstance.getRootToken());
-
- System.out.println(tokenVariableMap.getVariable("one"));
- System.out.println(tokenVariableMap.getVariable("two"));
-
- assertEquals("hello", ((StringInstance)tokenVariableMap.variableInstances.get("one")).getValue() );
- assertEquals("world", ((StringInstance)tokenVariableMap.variableInstances.get("two")).getValue() );
+ tokenVariableMap = (TokenVariableMap)tokenVariableMaps.get(processInstance.getRootToken());
+
+ // System.out.println(tokenVariableMap.getVariable("one"));
+ // System.out.println(tokenVariableMap.getVariable("two"));
+
+ assertEquals("hello", ((StringInstance)tokenVariableMap.variableInstances.get("one")).getValue());
+ assertEquals("world", ((StringInstance)tokenVariableMap.variableInstances.get("two")).getValue());
}
}
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/graph/exe/ActionExceptionsTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/graph/exe/ActionExceptionsTest.java 2008-09-09 14:21:41 UTC (rev 2152)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/graph/exe/ActionExceptionsTest.java 2008-09-09 14:41:32 UTC (rev 2153)
@@ -26,66 +26,53 @@
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.def.ProcessDefinition;
-public class ActionExceptionsTest extends TestCase {
+public class ActionExceptionsTest extends TestCase
+{
- public static class FailingAction implements ActionHandler {
+ public static class FailingAction implements ActionHandler
+ {
private static final long serialVersionUID = 1L;
- public void execute(ExecutionContext context) {
+
+ public void execute(ExecutionContext context)
+ {
throw new IllegalArgumentException();
}
}
- public void testFailingReferenced() throws Exception {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state name='start'>" +
- " <transition to='state'/>" +
- " </start-state>" +
- " <state name='state'>" +
- " <transition to='end'>" +
- " <action ref-name='failing'/>" +
- " </transition>"+
- " </state>" +
- " <end-state name='end'/>" +
- " <action name='failing' class='org.jbpm.graph.exe.ActionExceptionsTest$FailingAction'/>"+
- "</process-definition>");
+ public void testFailingReferenced() throws Exception
+ {
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>" + " <start-state name='start'>" + " <transition to='state'/>"
+ + " </start-state>" + " <state name='state'>" + " <transition to='end'>" + " <action ref-name='failing'/>" + " </transition>" + " </state>"
+ + " <end-state name='end'/>" + " <action name='failing' class='org.jbpm.graph.exe.ActionExceptionsTest$FailingAction'/>" + "</process-definition>");
ProcessInstance pi = new ProcessInstance(processDefinition);
pi.signal();
- try {
+ try
+ {
pi.signal();
- } catch (RuntimeException e) {
- e.printStackTrace();
- // ObjectAssert.assertInstanceOf(IllegalArgumentException.class,
- // e.getCause());
+ }
+ catch (RuntimeException e)
+ {
assertTrue(e.getCause() instanceof IllegalArgumentException);
return;
}
fail("should have throws IllegalArgumentException");
}
- public void testFailingNotReferenced() throws Exception {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state name='start'>" +
- " <transition to='state'/>" +
- " </start-state>" +
- " <state name='state'>" +
- " <transition to='end'>" +
- " <action class='org.jbpm.graph.exe.ActionExceptionsTest$FailingAction'/>" +
- " </transition>" +
- " </state>" +
- " <end-state name='end'/>" +
- "</process-definition>");
+ public void testFailingNotReferenced() throws Exception
+ {
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>" + " <start-state name='start'>" + " <transition to='state'/>"
+ + " </start-state>" + " <state name='state'>" + " <transition to='end'>" + " <action class='org.jbpm.graph.exe.ActionExceptionsTest$FailingAction'/>"
+ + " </transition>" + " </state>" + " <end-state name='end'/>" + "</process-definition>");
ProcessInstance pi = new ProcessInstance(processDefinition);
pi.signal();
- try {
+ try
+ {
pi.signal();
- } catch (RuntimeException e) {
- e.printStackTrace();
- // ObjectAssert.assertInstanceOf(IllegalArgumentException.class,
- // e.getCause());
+ }
+ catch (RuntimeException e)
+ {
assertTrue(e.getCause() instanceof IllegalArgumentException);
return;
}
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/graph/exe/BusinessKeyDbTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/graph/exe/BusinessKeyDbTest.java 2008-09-09 14:21:41 UTC (rev 2152)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/graph/exe/BusinessKeyDbTest.java 2008-09-09 14:41:32 UTC (rev 2153)
@@ -3,19 +3,21 @@
import org.jbpm.db.AbstractDbTestCase;
import org.jbpm.graph.def.ProcessDefinition;
-public class BusinessKeyDbTest extends AbstractDbTestCase {
+public class BusinessKeyDbTest extends AbstractDbTestCase
+{
- public void testSimpleBusinessKey() {
+ public void testSimpleBusinessKey()
+ {
ProcessDefinition processDefinition = new ProcessDefinition("businesskeytest");
jbpmContext.deployProcessDefinition(processDefinition);
-
+
newTransaction();
-
+
ProcessInstance processInstance = jbpmContext.newProcessInstanceForUpdate("businesskeytest");
processInstance.setKey("businesskey1");
newTransaction();
-
+
processInstance = jbpmContext.newProcessInstanceForUpdate("businesskeytest");
processInstance.setKey("businesskey2");
@@ -26,41 +28,16 @@
assertEquals("businesskey1", processInstance.getKey());
}
-/*
-
- problematic unique key constraint. see also http://jira.jboss.com/jira/browse/JBPM-913
-
- public void testDuplicateBusinessKey() {
- ProcessDefinition processDefinition = new ProcessDefinition("businesskeytest");
- jbpmContext.deployProcessDefinition(processDefinition);
-
- newTransaction();
-
- jbpmContext.newProcessInstanceForUpdate("businesskeytest").setKey("duplicatekey");
- jbpmContext.newProcessInstanceForUpdate("businesskeytest").setKey("duplicatekey");
-
- try {
- jbpmContext.close();
- fail("expected exception");
- } catch (JbpmException e) {
- e.printStackTrace();
- } catch (Throwable t) {
- t.printStackTrace();
- }
-
- beginSessionTransaction();
- jbpmContext.getSession();
- }
-*/
- public void testDuplicateBusinessKeyInDifferentProcesses() {
+ public void testDuplicateBusinessKeyInDifferentProcesses()
+ {
ProcessDefinition processDefinition = new ProcessDefinition("businesskeytest1");
jbpmContext.deployProcessDefinition(processDefinition);
-
+
processDefinition = new ProcessDefinition("businesskeytest2");
jbpmContext.deployProcessDefinition(processDefinition);
-
+
newTransaction();
-
+
jbpmContext.newProcessInstanceForUpdate("businesskeytest1").setKey("duplicatekey");
jbpmContext.newProcessInstanceForUpdate("businesskeytest2").setKey("duplicatekey");
}
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/graph/exe/ExceptionHandlingTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/graph/exe/ExceptionHandlingTest.java 2008-09-09 14:21:41 UTC (rev 2152)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/graph/exe/ExceptionHandlingTest.java 2008-09-09 14:41:32 UTC (rev 2153)
@@ -30,230 +30,198 @@
import org.jbpm.graph.def.DelegationException;
import org.jbpm.graph.def.ProcessDefinition;
-public class ExceptionHandlingTest extends TestCase {
-
+public class ExceptionHandlingTest extends TestCase
+{
+
static List executedActions = null;
-
- public void setUp() {
+
+ public void setUp()
+ {
executedActions = new ArrayList();
}
-
- public static class BatterException extends Exception {
+
+ public static class BatterException extends Exception
+ {
private static final long serialVersionUID = 1L;
}
- public static class Batter implements ActionHandler {
+ public static class Batter implements ActionHandler
+ {
private static final long serialVersionUID = 1L;
- public void execute(ExecutionContext executionContext) throws Exception {
+
+ public void execute(ExecutionContext executionContext) throws Exception
+ {
throw new BatterException();
}
}
-
- public static class Pitcher implements ActionHandler {
+
+ public static class Pitcher implements ActionHandler
+ {
private static final long serialVersionUID = 1L;
Throwable exception = null;
- public void execute(ExecutionContext executionContext) throws DelegationException {
+
+ public void execute(ExecutionContext executionContext) throws DelegationException
+ {
this.exception = executionContext.getException();
executedActions.add(this);
}
}
- public void testUncaughtException() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='play ball' />" +
- " </start-state>" +
- " <state name='play ball'>" +
- " <event type='node-enter'>" +
- " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Batter' />" +
- " </event>" +
- " </state>" +
- "</process-definition>");
-
- try {
+ public void testUncaughtException()
+ {
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>" + " <start-state>" + " <transition to='play ball' />"
+ + " </start-state>" + " <state name='play ball'>" + " <event type='node-enter'>"
+ + " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Batter' />" + " </event>" + " </state>" + "</process-definition>");
+
+ try
+ {
new ProcessInstance(processDefinition).signal();
fail("expected exception");
- } catch (DelegationException e) {
- // OK
- e.printStackTrace();
+ }
+ catch (DelegationException e)
+ {
assertSame(BatterException.class, e.getCause().getClass());
}
}
- public static class RuntimeBatter implements ActionHandler {
+ public static class RuntimeBatter implements ActionHandler
+ {
private static final long serialVersionUID = 1L;
- public void execute(ExecutionContext executionContext) throws Exception {
+
+ public void execute(ExecutionContext executionContext) throws Exception
+ {
throw new RuntimeException("here i come");
}
}
-
- public void testUncaughtRuntimeException() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='play ball' />" +
- " </start-state>" +
- " <state name='play ball'>" +
- " <event type='node-enter'>" +
- " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$RuntimeBatter' />" +
- " </event>" +
- " </state>" +
- "</process-definition>");
-
- try {
+
+ public void testUncaughtRuntimeException()
+ {
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>" + " <start-state>" + " <transition to='play ball' />"
+ + " </start-state>" + " <state name='play ball'>" + " <event type='node-enter'>"
+ + " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$RuntimeBatter' />" + " </event>" + " </state>" + "</process-definition>");
+
+ try
+ {
new ProcessInstance(processDefinition).signal();
fail("expected exception");
- } catch (DelegationException e) {
- // OK
- e.printStackTrace();
+ }
+ catch (DelegationException e)
+ {
assertSame(RuntimeException.class, e.getCause().getClass());
}
}
- public static class ErrorBatter implements ActionHandler {
+ public static class ErrorBatter implements ActionHandler
+ {
private static final long serialVersionUID = 1L;
- public void execute(ExecutionContext executionContext) throws Exception {
+
+ public void execute(ExecutionContext executionContext) throws Exception
+ {
throw new Error("jvm trouble coming your way");
}
}
-
- public void testUncaughtError() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='play ball' />" +
- " </start-state>" +
- " <state name='play ball'>" +
- " <event type='node-enter'>" +
- " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$ErrorBatter' />" +
- " </event>" +
- " </state>" +
- "</process-definition>");
-
- try {
+
+ public void testUncaughtError()
+ {
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>" + " <start-state>" + " <transition to='play ball' />"
+ + " </start-state>" + " <state name='play ball'>" + " <event type='node-enter'>"
+ + " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$ErrorBatter' />" + " </event>" + " </state>" + "</process-definition>");
+
+ try
+ {
new ProcessInstance(processDefinition).signal();
fail("expected exception");
- } catch (DelegationException e) {
+ }
+ catch (DelegationException e)
+ {
fail("i don't want a delegation exception. jBPM should not handle Error's since that might lead to JVM halts");
- } catch (Error e) {
+ }
+ catch (Error e)
+ {
// OK
}
}
- public void testSimpleCatchAll() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='play ball' />" +
- " </start-state>" +
- " <state name='play ball'>" +
- " <event type='node-enter'>" +
- " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Batter' />" +
- " </event>" +
- " <exception-handler>" +
- " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Pitcher'/>" +
- " </exception-handler>" +
- " </state>" +
- "</process-definition>");
+ public void testSimpleCatchAll()
+ {
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>" + " <start-state>" + " <transition to='play ball' />"
+ + " </start-state>" + " <state name='play ball'>" + " <event type='node-enter'>"
+ + " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Batter' />" + " </event>" + " <exception-handler>"
+ + " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Pitcher'/>" + " </exception-handler>" + " </state>" + "</process-definition>");
new ProcessInstance(processDefinition).signal();
assertEquals(1, executedActions.size());
- Pitcher executedPitcher = (Pitcher) executedActions.get(0);
+ Pitcher executedPitcher = (Pitcher)executedActions.get(0);
assertSame(BatterException.class, executedPitcher.exception.getClass());
}
- public void testCatchOnlyTheSpecifiedException() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='play ball' />" +
- " </start-state>" +
- " <state name='play ball'>" +
- " <event type='node-enter'>" +
- " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Batter' />" +
- " </event>" +
- " <exception-handler exception-class='org.jbpm.graph.exe.ExceptionHandlingTest$BatterException'>" +
- " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Pitcher'/>" +
- " </exception-handler>" +
- " </state>" +
- "</process-definition>");
+ public void testCatchOnlyTheSpecifiedException()
+ {
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>" + " <start-state>" + " <transition to='play ball' />"
+ + " </start-state>" + " <state name='play ball'>" + " <event type='node-enter'>"
+ + " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Batter' />" + " </event>"
+ + " <exception-handler exception-class='org.jbpm.graph.exe.ExceptionHandlingTest$BatterException'>"
+ + " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Pitcher'/>" + " </exception-handler>" + " </state>" + "</process-definition>");
new ProcessInstance(processDefinition).signal();
}
- public void testDontCatchTheNonSpecifiedException() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='play ball' />" +
- " </start-state>" +
- " <state name='play ball'>" +
- " <event type='node-enter'>" +
- " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Batter' />" +
- " </event>" +
- " <exception-handler exception-class='java.lang.RuntimeException'>" +
- " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Pitcher'/>" +
- " </exception-handler>" +
- " </state>" +
- "</process-definition>");
+ public void testDontCatchTheNonSpecifiedException()
+ {
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>" + " <start-state>" + " <transition to='play ball' />"
+ + " </start-state>" + " <state name='play ball'>" + " <event type='node-enter'>"
+ + " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Batter' />" + " </event>"
+ + " <exception-handler exception-class='java.lang.RuntimeException'>" + " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Pitcher'/>"
+ + " </exception-handler>" + " </state>" + "</process-definition>");
- try {
+ try
+ {
new ProcessInstance(processDefinition).signal();
- } catch (DelegationException e) {
+ }
+ catch (DelegationException e)
+ {
assertSame(BatterException.class, e.getCause().getClass());
}
}
- public static class SecondExceptionHandler implements ActionHandler {
+ public static class SecondExceptionHandler implements ActionHandler
+ {
private static final long serialVersionUID = 1L;
- public void execute(ExecutionContext executionContext) throws DelegationException {
+
+ public void execute(ExecutionContext executionContext) throws DelegationException
+ {
executedActions.add(this);
}
}
- public void testCatchWithTheSecondSpecifiedExceptionHandler() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='play ball' />" +
- " </start-state>" +
- " <state name='play ball'>" +
- " <event type='node-enter'>" +
- " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Batter' />" +
- " </event>" +
- // the first exception-handler will not catch the BatterException
- " <exception-handler exception-class='java.lang.RuntimeException'>" +
- " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Pitcher'/>" +
- " </exception-handler>" +
- // but the second exception-handler will catch all
- " <exception-handler>" +
- " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$SecondExceptionHandler'/>" +
- " </exception-handler>" +
- " </state>" +
- "</process-definition>");
+ public void testCatchWithTheSecondSpecifiedExceptionHandler()
+ {
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>" + " <start-state>" + " <transition to='play ball' />"
+ + " </start-state>" + " <state name='play ball'>" + " <event type='node-enter'>"
+ + " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Batter' />"
+ + " </event>"
+ +
+ // the first exception-handler will not catch the BatterException
+ " <exception-handler exception-class='java.lang.RuntimeException'>" + " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Pitcher'/>"
+ + " </exception-handler>"
+ +
+ // but the second exception-handler will catch all
+ " <exception-handler>" + " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$SecondExceptionHandler'/>" + " </exception-handler>"
+ + " </state>" + "</process-definition>");
new ProcessInstance(processDefinition).signal();
assertEquals(1, executedActions.size());
assertSame(SecondExceptionHandler.class, executedActions.get(0).getClass());
}
- public void testTwoActionsInOneExceptionHandler() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='play ball' />" +
- " </start-state>" +
- " <state name='play ball'>" +
- " <event type='node-enter'>" +
- " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Batter' />" +
- " </event>" +
- " <exception-handler>" +
- " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Pitcher'/>" +
- " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$SecondExceptionHandler'/>" +
- " </exception-handler>" +
- " </state>" +
- "</process-definition>");
+ public void testTwoActionsInOneExceptionHandler()
+ {
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>" + " <start-state>" + " <transition to='play ball' />"
+ + " </start-state>" + " <state name='play ball'>" + " <event type='node-enter'>"
+ + " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Batter' />" + " </event>" + " <exception-handler>"
+ + " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Pitcher'/>"
+ + " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$SecondExceptionHandler'/>" + " </exception-handler>" + " </state>"
+ + "</process-definition>");
new ProcessInstance(processDefinition).signal();
assertEquals(2, executedActions.size());
@@ -261,43 +229,23 @@
assertSame(SecondExceptionHandler.class, executedActions.get(1).getClass());
}
- public void testProcessDefinitionExceptionHandling() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='play ball' />" +
- " </start-state>" +
- " <state name='play ball'>" +
- " <event type='node-enter'>" +
- " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Batter' />" +
- " </event>" +
- " </state>" +
- " <exception-handler>" +
- " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Pitcher'/>" +
- " </exception-handler>" +
- "</process-definition>");
+ public void testProcessDefinitionExceptionHandling()
+ {
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>" + " <start-state>" + " <transition to='play ball' />"
+ + " </start-state>" + " <state name='play ball'>" + " <event type='node-enter'>"
+ + " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Batter' />" + " </event>" + " </state>" + " <exception-handler>"
+ + " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Pitcher'/>" + " </exception-handler>" + "</process-definition>");
new ProcessInstance(processDefinition).signal();
assertEquals(1, executedActions.size());
}
- public void testSuperStateExceptionHandling() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='superstate/play ball' />" +
- " </start-state>" +
- " <super-state name='superstate'>" +
- " <state name='play ball'>" +
- " <event type='node-enter'>" +
- " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Batter' />" +
- " </event>" +
- " </state>" +
- " <exception-handler>" +
- " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Pitcher'/>" +
- " </exception-handler>" +
- " </super-state>" +
- "</process-definition>");
+ public void testSuperStateExceptionHandling()
+ {
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>" + " <start-state>" + " <transition to='superstate/play ball' />"
+ + " </start-state>" + " <super-state name='superstate'>" + " <state name='play ball'>" + " <event type='node-enter'>"
+ + " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Batter' />" + " </event>" + " </state>" + " <exception-handler>"
+ + " <action class='org.jbpm.graph.exe.ExceptionHandlingTest$Pitcher'/>" + " </exception-handler>" + " </super-state>" + "</process-definition>");
new ProcessInstance(processDefinition).signal();
assertEquals(1, executedActions.size());
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/job/executor/JobExecutorDbTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/job/executor/JobExecutorDbTest.java 2008-09-09 14:21:41 UTC (rev 2152)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/job/executor/JobExecutorDbTest.java 2008-09-09 14:41:32 UTC (rev 2153)
@@ -19,42 +19,50 @@
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.exe.ProcessInstance;
-public class JobExecutorDbTest extends TestCase {
+public class JobExecutorDbTest extends TestCase
+{
static int nbrOfConcurrentProcessExecutions = 20;
static int maxWaitTime = 60000;
static Set collectedResults = Collections.synchronizedSet(new TreeSet());
-
- protected static JbpmConfiguration jbpmConfiguration =
- JbpmConfiguration.getInstance("org/jbpm/jbpm.test.cfg.xml");
-
- static {
+
+ protected static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance("org/jbpm/jbpm.test.cfg.xml");
+
+ static
+ {
jbpmConfiguration.getJobExecutor().nbrOfThreads = 5;
}
protected JobExecutor jobExecutor;
- public static class AutomaticActivity implements ActionHandler {
+ public static class AutomaticActivity implements ActionHandler
+ {
private static final long serialVersionUID = 1L;
- public void execute(ExecutionContext executionContext) throws Exception {
+
+ public void execute(ExecutionContext executionContext) throws Exception
+ {
long id = executionContext.getProcessInstance().getId();
String nodeName = executionContext.getNode().getName();
- collectedResults.add(id+nodeName);
+ collectedResults.add(id + nodeName);
executionContext.leaveNode();
}
}
- public static class AsyncAction implements ActionHandler {
+ public static class AsyncAction implements ActionHandler
+ {
private static final long serialVersionUID = 1L;
- public void execute(ExecutionContext executionContext) throws Exception {
+
+ public void execute(ExecutionContext executionContext) throws Exception
+ {
long id = executionContext.getProcessInstance().getId();
Action action = executionContext.getAction();
String actionName = action.getName();
- collectedResults.add(id+actionName);
+ collectedResults.add(id + actionName);
}
}
- public void testJobExecutor() {
+ public void testJobExecutor()
+ {
jbpmConfiguration.createSchema();
deployProcess();
launchProcesses();
@@ -63,161 +71,209 @@
jbpmConfiguration.createSchema();
}
- public void deployProcess() {
+ public void deployProcess()
+ {
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
- try {
+ try
+ {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition name='bulk messages'>" +
- " <start-state>" +
- " <transition to='a' />" +
- " </start-state>" +
- " <node name='a' async='true'>" +
- " <action class='"+AutomaticActivity.class.getName()+"' />" +
- " <transition to='b' />" +
- " </node>" +
- " <node name='b' async='true'>" +
- " <event type='node-enter'>" +
- " <action name='X' async='true' class='"+AsyncAction.class.getName()+"' />" +
- " </event>" +
- " <action class='"+AutomaticActivity.class.getName()+"' />" +
- " <transition to='c' />" +
- " </node>" +
- " <node name='c' async='true'>" +
- " <action class='"+AutomaticActivity.class.getName()+"' />" +
- " <transition to='d'>" +
- " <action name='Y' async='true' class='"+AsyncAction.class.getName()+"' />" +
- " </transition>" +
- " </node>" +
- " <node name='d' async='true'>" +
- " <action class='"+AutomaticActivity.class.getName()+"' />" +
- " <transition to='e' />" +
- " <event type='node-leave'>" +
- " <action name='Z' async='true' class='"+AsyncAction.class.getName()+"' />" +
- " </event>" +
- " </node>" +
- " <node name='e' async='true'>" +
- " <action class='"+AutomaticActivity.class.getName()+"' />" +
- " <transition to='end' />" +
- " </node>" +
- " <end-state name='end'/>" +
- "</process-definition>"
- );
-
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition name='bulk messages'>" + " <start-state>"
+ + " <transition to='a' />" + " </start-state>" + " <node name='a' async='true'>" + " <action class='"
+ + AutomaticActivity.class.getName()
+ + "' />"
+ + " <transition to='b' />"
+ + " </node>"
+ + " <node name='b' async='true'>"
+ + " <event type='node-enter'>"
+ + " <action name='X' async='true' class='"
+ + AsyncAction.class.getName()
+ + "' />"
+ + " </event>"
+ + " <action class='"
+ + AutomaticActivity.class.getName()
+ + "' />"
+ + " <transition to='c' />"
+ + " </node>"
+ + " <node name='c' async='true'>"
+ + " <action class='"
+ + AutomaticActivity.class.getName()
+ + "' />"
+ + " <transition to='d'>"
+ + " <action name='Y' async='true' class='"
+ + AsyncAction.class.getName()
+ + "' />"
+ + " </transition>"
+ + " </node>"
+ + " <node name='d' async='true'>"
+ + " <action class='"
+ + AutomaticActivity.class.getName()
+ + "' />"
+ + " <transition to='e' />"
+ + " <event type='node-leave'>"
+ + " <action name='Z' async='true' class='"
+ + AsyncAction.class.getName()
+ + "' />"
+ + " </event>"
+ + " </node>"
+ + " <node name='e' async='true'>"
+ + " <action class='"
+ + AutomaticActivity.class.getName()
+ + "' />"
+ + " <transition to='end' />" + " </node>" + " <end-state name='end'/>" + "</process-definition>");
+
jbpmContext.deployProcessDefinition(processDefinition);
- } finally {
+ }
+ finally
+ {
jbpmContext.close();
}
}
- public void launchProcesses() {
- for (int i=0; i<nbrOfConcurrentProcessExecutions; i++) {
+ public void launchProcesses()
+ {
+ for (int i = 0; i < nbrOfConcurrentProcessExecutions; i++)
+ {
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
- try {
+ try
+ {
ProcessInstance processInstance = jbpmContext.newProcessInstanceForUpdate("bulk messages");
processInstance.signal();
- } finally {
+ }
+ finally
+ {
jbpmContext.close();
}
}
}
- public Set createExpectedResults() {
+ public Set createExpectedResults()
+ {
Set expectedResults = new TreeSet();
- for (int i=1; i<nbrOfConcurrentProcessExecutions+1; i++) {
- expectedResults.add(i+"a");
- expectedResults.add(i+"b");
- expectedResults.add(i+"c");
- expectedResults.add(i+"d");
- expectedResults.add(i+"e");
- expectedResults.add(i+"X");
- expectedResults.add(i+"Y");
- expectedResults.add(i+"Z");
+ for (int i = 1; i < nbrOfConcurrentProcessExecutions + 1; i++)
+ {
+ expectedResults.add(i + "a");
+ expectedResults.add(i + "b");
+ expectedResults.add(i + "c");
+ expectedResults.add(i + "d");
+ expectedResults.add(i + "e");
+ expectedResults.add(i + "X");
+ expectedResults.add(i + "Y");
+ expectedResults.add(i + "Z");
}
return expectedResults;
}
- protected void startJobExecutor() {
+ protected void startJobExecutor()
+ {
jobExecutor = jbpmConfiguration.getJobExecutor();
jobExecutor.start();
}
-
- private void processAllJobs(final long maxWait) {
+
+ private void processAllJobs(final long maxWait)
+ {
boolean jobsAvailable = true;
// install a timer that will interrupt if it takes too long
// if that happens, it will lead to an interrupted exception and the test will fail
- TimerTask interruptTask = new TimerTask() {
+ TimerTask interruptTask = new TimerTask()
+ {
Thread testThread = Thread.currentThread();
- public void run() {
- log.debug("test "+getName()+" took too long. going to interrupt...");
+
+ public void run()
+ {
+ log.debug("test " + getName() + " took too long. going to interrupt...");
testThread.interrupt();
}
};
Timer timer = new Timer();
timer.schedule(interruptTask, maxWait);
-
- try {
- while (jobsAvailable) {
+
+ try
+ {
+ while (jobsAvailable)
+ {
log.debug("going to sleep for 200 millis, waiting for the job executor to process more jobs");
Thread.sleep(200);
jobsAvailable = areJobsAvailable();
}
jobExecutor.stopAndJoin();
-
- } catch (InterruptedException e) {
- fail("test execution exceeded treshold of "+maxWait+" milliseconds");
- } finally {
+
+ }
+ catch (InterruptedException e)
+ {
+ fail("test execution exceeded treshold of " + maxWait + " milliseconds");
+ }
+ finally
+ {
timer.cancel();
}
}
- private int getNbrOfJobsAvailable() {
+ private int getNbrOfJobsAvailable()
+ {
int nbrOfJobsAvailable = 0;
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
- try {
+ try
+ {
Session session = jbpmContext.getSession();
- Number jobs = (Number) session.createQuery("select count(*) from org.jbpm.job.Job").uniqueResult();
- log.debug("there are '"+jobs+"' jobs currently in the job table");
- if (jobs!=null) {
+ Number jobs = (Number)session.createQuery("select count(*) from org.jbpm.job.Job").uniqueResult();
+ log.debug("there are '" + jobs + "' jobs currently in the job table");
+ if (jobs != null)
+ {
nbrOfJobsAvailable = jobs.intValue();
}
- } finally {
+ }
+ finally
+ {
jbpmContext.close();
}
return nbrOfJobsAvailable;
}
- protected boolean areJobsAvailable() {
- return (getNbrOfJobsAvailable()>0);
+ protected boolean areJobsAvailable()
+ {
+ return (getNbrOfJobsAvailable() > 0);
}
-
- protected void processJobs(long maxWait) {
- try {
+
+ protected void processJobs(long maxWait)
+ {
+ try
+ {
Thread.sleep(300);
- } catch (InterruptedException e) {
- e.printStackTrace();
}
+ catch (InterruptedException e)
+ {
+ // ignore
+ }
startJobExecutor();
- try {
+ try
+ {
processAllJobs(maxWait);
- } catch (Exception e) {
- e.printStackTrace();
+ }
+ catch (Exception e)
+ {
throw new RuntimeException(e);
- } finally {
+ }
+ finally
+ {
stopJobExecutor();
}
}
-
- protected void stopJobExecutor() {
- if (jobExecutor!=null) {
- try {
+
+ protected void stopJobExecutor()
+ {
+ if (jobExecutor != null)
+ {
+ try
+ {
jobExecutor.stopAndJoin();
- } catch (InterruptedException e) {
- throw new RuntimeException("waiting for job executor to stop and join got interrupted", e);
}
+ catch (InterruptedException e)
+ {
+ throw new RuntimeException("waiting for job executor to stop and join got interrupted", e);
+ }
}
}
-
+
private static Log log = LogFactory.getLog(JobExecutorDbTest.class);
}
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/el/DecisionExpressionTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/el/DecisionExpressionTest.java 2008-09-09 14:21:41 UTC (rev 2152)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/el/DecisionExpressionTest.java 2008-09-09 14:41:32 UTC (rev 2153)
@@ -6,44 +6,45 @@
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
-public class DecisionExpressionTest extends TestCase {
-
- public static class Customer {
+public class DecisionExpressionTest extends TestCase
+{
+
+ public static class Customer
+ {
String priority;
int number;
- public Customer(String priority) {
+
+ public Customer(String priority)
+ {
this.priority = priority;
}
- public Customer(int number) {
+
+ public Customer(int number)
+ {
this.number = number;
}
- public String getPriority() {
+
+ public String getPriority()
+ {
return priority;
}
- public int getNumber() {
+
+ public int getNumber()
+ {
return number;
}
}
-
- public ProcessDefinition createCustomerPriorityProcess() {
- return ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='d'/>" +
- " </start-state>" +
- " <decision name='d' expression='#{customer.priority}'>" +
- " <transition name='LOW' to='l' />" +
- " <transition name='MEDIUM' to='m' />" +
- " <transition name='HIGH' to='h' />" +
- " </decision>" +
- " <state name='l' />" +
- " <state name='m' />" +
- " <state name='h' />" +
- "</process-definition>"
- );
+
+ public ProcessDefinition createCustomerPriorityProcess()
+ {
+ return ProcessDefinition.parseXmlString("<process-definition>" + " <start-state>" + " <transition to='d'/>" + " </start-state>"
+ + " <decision name='d' expression='#{customer.priority}'>" + " <transition name='LOW' to='l' />" + " <transition name='MEDIUM' to='m' />"
+ + " <transition name='HIGH' to='h' />" + " </decision>" + " <state name='l' />" + " <state name='m' />" + " <state name='h' />"
+ + "</process-definition>");
}
- public void testCustomerPriorityLow() {
+ public void testCustomerPriorityLow()
+ {
ProcessDefinition processDefinition = createCustomerPriorityProcess();
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.getContextInstance().setVariable("customer", new Customer("LOW"));
@@ -51,7 +52,8 @@
assertEquals("l", processInstance.getRootToken().getNode().getName());
}
- public void testCustomerPriorityMedium() {
+ public void testCustomerPriorityMedium()
+ {
ProcessDefinition processDefinition = createCustomerPriorityProcess();
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.getContextInstance().setVariable("customer", new Customer("MEDIUM"));
@@ -59,50 +61,48 @@
assertEquals("m", processInstance.getRootToken().getNode().getName());
}
- public void testCustomerPriorityUndefined() {
+ public void testCustomerPriorityUndefined()
+ {
ProcessDefinition processDefinition = createCustomerPriorityProcess();
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.getContextInstance().setVariable("customer", new Customer("UNDEFINED"));
- try {
+ try
+ {
processInstance.signal();
fail("expected exception");
- } catch (JbpmException e) {
- e.printStackTrace();
- assertTrue(e.getMessage().indexOf("non existing transition")!=-1);
- // OK
}
+ catch (JbpmException e)
+ {
+ assertTrue(e.getMessage().indexOf("non existing transition") != -1);
+ }
}
- public void testCustomerPriorityNull() {
+ public void testCustomerPriorityNull()
+ {
ProcessDefinition processDefinition = createCustomerPriorityProcess();
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.getContextInstance().setVariable("customer", new Customer(null));
- try {
+ try
+ {
processInstance.signal();
fail("expected exception");
- } catch (JbpmException e) {
+ }
+ catch (JbpmException e)
+ {
// OK
}
}
-
- public ProcessDefinition createBooleanExpressionProcess() {
- return ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='d'/>" +
- " </start-state>" +
- " <decision name='d' expression='#{customer.number > 5}'>" +
- " <transition name='true' to='high-numbered-customer' />" +
- " <transition name='false' to='low-numbered-customer' />" +
- " </decision>" +
- " <state name='high-numbered-customer' />" +
- " <state name='low-numbered-customer' />" +
- "</process-definition>"
- );
+ public ProcessDefinition createBooleanExpressionProcess()
+ {
+ return ProcessDefinition.parseXmlString("<process-definition>" + " <start-state>" + " <transition to='d'/>" + " </start-state>"
+ + " <decision name='d' expression='#{customer.number > 5}'>" + " <transition name='true' to='high-numbered-customer' />"
+ + " <transition name='false' to='low-numbered-customer' />" + " </decision>" + " <state name='high-numbered-customer' />"
+ + " <state name='low-numbered-customer' />" + "</process-definition>");
}
- public void testBooleanExpressionTrue() {
+ public void testBooleanExpressionTrue()
+ {
ProcessDefinition processDefinition = createBooleanExpressionProcess();
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.getContextInstance().setVariable("customer", new Customer(9));
@@ -110,7 +110,8 @@
assertEquals("high-numbered-customer", processInstance.getRootToken().getNode().getName());
}
- public void testBooleanExpressionFalse() {
+ public void testBooleanExpressionFalse()
+ {
ProcessDefinition processDefinition = createBooleanExpressionProcess();
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.getContextInstance().setVariable("customer", new Customer(3));
@@ -118,29 +119,17 @@
assertEquals("low-numbered-customer", processInstance.getRootToken().getNode().getName());
}
- public ProcessDefinition createConditionProcess() {
- return ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='d'/>" +
- " </start-state>" +
- " <decision name='d'>" +
- " <transition to='low-numbered-customer' />" +
- " <transition to='high-numbered-customer'>" +
- " <condition expression='#{customer.number > 5}' />" +
- " </transition>" +
- " <transition to='medium-numbered-customer'>" +
- " <condition expression='#{customer.number == 5}' />" +
- " </transition>" +
- " </decision>" +
- " <state name='high-numbered-customer' />" +
- " <state name='medium-numbered-customer' />" +
- " <state name='low-numbered-customer' />" +
- "</process-definition>"
- );
+ public ProcessDefinition createConditionProcess()
+ {
+ return ProcessDefinition.parseXmlString("<process-definition>" + " <start-state>" + " <transition to='d'/>" + " </start-state>" + " <decision name='d'>"
+ + " <transition to='low-numbered-customer' />" + " <transition to='high-numbered-customer'>" + " <condition expression='#{customer.number > 5}' />"
+ + " </transition>" + " <transition to='medium-numbered-customer'>" + " <condition expression='#{customer.number == 5}' />" + " </transition>"
+ + " </decision>" + " <state name='high-numbered-customer' />" + " <state name='medium-numbered-customer' />" + " <state name='low-numbered-customer' />"
+ + "</process-definition>");
}
- public void testConditionHigh() {
+ public void testConditionHigh()
+ {
ProcessDefinition processDefinition = createConditionProcess();
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.getContextInstance().setVariable("customer", new Customer(9));
@@ -148,7 +137,8 @@
assertEquals("high-numbered-customer", processInstance.getRootToken().getNode().getName());
}
- public void testConditionMedium() {
+ public void testConditionMedium()
+ {
ProcessDefinition processDefinition = createConditionProcess();
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.getContextInstance().setVariable("customer", new Customer(5));
@@ -156,7 +146,8 @@
assertEquals("medium-numbered-customer", processInstance.getRootToken().getNode().getName());
}
- public void testConditionLow() {
+ public void testConditionLow()
+ {
ProcessDefinition processDefinition = createConditionProcess();
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.getContextInstance().setVariable("customer", new Customer(3));
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ResourceAction.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ResourceAction.java 2008-09-09 14:21:41 UTC (rev 2152)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ResourceAction.java 2008-09-09 14:41:32 UTC (rev 2153)
@@ -8,61 +8,89 @@
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;
-public class ResourceAction implements ActionHandler {
+public class ResourceAction implements ActionHandler
+{
private static final long serialVersionUID = 1L;
- public void execute(ExecutionContext executionContext) throws Exception {
- try {
- // class resources
-
- URL resource = getClass().getResource("classresource.txt");
- InputStream stream = resource.openStream();
- ProcessArchiveDeploymentDbTest.classResourceUrl = read(stream);
+ public void execute(ExecutionContext executionContext) throws Exception
+ {
+ // class resources
- stream = getClass().getResourceAsStream("classresource.txt");
- ProcessArchiveDeploymentDbTest.classResourceStream = read(stream);
+ URL resource = getClass().getResource("classresource.txt");
+ InputStream stream = resource.openStream();
+ ProcessArchiveDeploymentDbTest.classResourceUrl = read(stream);
- resource = ResourceAction.class.getClassLoader().getResource("org/jbpm/jpdl/par/classresource.txt");
- stream = resource.openStream();
- ProcessArchiveDeploymentDbTest.classLoaderResourceUrl = read(stream);
+ stream = getClass().getResourceAsStream("classresource.txt");
+ ProcessArchiveDeploymentDbTest.classResourceStream = read(stream);
- stream = ResourceAction.class.getClassLoader().getResourceAsStream("org/jbpm/jpdl/par/classresource.txt");
- ProcessArchiveDeploymentDbTest.classLoaderResourceStream = read(stream);
-
- // archive resources
+ resource = ResourceAction.class.getClassLoader().getResource("org/jbpm/jpdl/par/classresource.txt");
+ stream = resource.openStream();
+ ProcessArchiveDeploymentDbTest.classLoaderResourceUrl = read(stream);
- resource = getClass().getResource("//archiveresource.txt");
- stream = resource.openStream();
- ProcessArchiveDeploymentDbTest.archiveResourceUrl = read(stream);
+ stream = ResourceAction.class.getClassLoader().getResourceAsStream("org/jbpm/jpdl/par/classresource.txt");
+ ProcessArchiveDeploymentDbTest.classLoaderResourceStream = read(stream);
- stream = getClass().getResourceAsStream("//archiveresource.txt");
- ProcessArchiveDeploymentDbTest.archiveResourceStream = read(stream);
+ // archive resources
- resource = ResourceAction.class.getClassLoader().getResource("//archiveresource.txt");
- stream = resource.openStream();
- ProcessArchiveDeploymentDbTest.archiveClassLoaderResourceUrl = read(stream);
+ resource = getClass().getResource("//archiveresource.txt");
+ stream = resource.openStream();
+ ProcessArchiveDeploymentDbTest.archiveResourceUrl = read(stream);
- stream = ResourceAction.class.getClassLoader().getResourceAsStream("//archiveresource.txt");
- ProcessArchiveDeploymentDbTest.archiveClassLoaderResourceStream = read(stream);
-
- // unexisting resources
-
+ stream = getClass().getResourceAsStream("//archiveresource.txt");
+ ProcessArchiveDeploymentDbTest.archiveResourceStream = read(stream);
+
+ resource = ResourceAction.class.getClassLoader().getResource("//archiveresource.txt");
+ stream = resource.openStream();
+ ProcessArchiveDeploymentDbTest.archiveClassLoaderResourceUrl = read(stream);
+
+ stream = ResourceAction.class.getClassLoader().getResourceAsStream("//archiveresource.txt");
+ ProcessArchiveDeploymentDbTest.archiveClassLoaderResourceStream = read(stream);
+
+ // unexisting resources
+ try
+ {
ProcessArchiveDeploymentDbTest.unexistingClassResourceStream = getClass().getResourceAsStream("unexistingresource.txt");
+ }
+ catch (RuntimeException e)
+ {
+ // ignore
+ }
+
+ try
+ {
ProcessArchiveDeploymentDbTest.unexistingClassLoaderResourceStream = ResourceAction.class.getClassLoader().getResourceAsStream("org/jbpm/jpdl/par/unexistingresource.txt");
+ }
+ catch (RuntimeException e)
+ {
+ // ignore
+ }
+
+ try
+ {
ProcessArchiveDeploymentDbTest.unexistingArchiveResourceStream = getClass().getResourceAsStream("//unexistingarchiveresource.txt");
+ }
+ catch (RuntimeException e)
+ {
+ // ignore
+ }
+ try
+ {
ProcessArchiveDeploymentDbTest.unexistingArchiveLoaderResourceStream = ResourceAction.class.getClassLoader().getResourceAsStream("//unexistingarchiveresource.txt");
-
- } catch (RuntimeException e) {
- e.printStackTrace();
}
+ catch (RuntimeException e)
+ {
+ // ignore
+ }
}
- private String read(InputStream resourceAsStream) throws Exception {
+ private String read(InputStream resourceAsStream) throws Exception
+ {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(resourceAsStream));
StringBuffer buffer = new StringBuffer();
String l;
- while ((l = bufferedReader.readLine()) != null) {
+ while ((l = bufferedReader.readLine()) != null)
+ {
buffer.append(l);
}
return buffer.toString();
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/xml/SchemaTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/xml/SchemaTest.java 2008-09-09 14:21:41 UTC (rev 2152)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/xml/SchemaTest.java 2008-09-09 14:41:32 UTC (rev 2153)
@@ -22,271 +22,188 @@
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
-public class SchemaTest extends TestCase {
-
+public class SchemaTest extends TestCase
+{
+
private static Log log = LogFactory.getLog(SchemaTest.class);
-
- public static class TestEntityResolver implements EntityResolver {
+
+ public static class TestEntityResolver implements EntityResolver
+ {
Map schemas;
- public TestEntityResolver(Map schemas) {
+
+ public TestEntityResolver(Map schemas)
+ {
this.schemas = schemas;
}
- public InputSource resolveEntity(String publicId, String systemId) {
- String schemaXmlString = (String) schemas.get(systemId);
- if (schemaXmlString==null) {
+
+ public InputSource resolveEntity(String publicId, String systemId)
+ {
+ String schemaXmlString = (String)schemas.get(systemId);
+ if (schemaXmlString == null)
+ {
return null;
}
return new InputSource(new StringReader(schemaXmlString));
}
}
- public static class TestErrorHandler implements ErrorHandler {
+ public static class TestErrorHandler implements ErrorHandler
+ {
List errors = new ArrayList();
- public void error(SAXParseException exception) throws SAXException {
- errors.add("["+exception.getLineNumber()+"] "+exception.getMessage());
+
+ public void error(SAXParseException exception) throws SAXException
+ {
+ errors.add("[" + exception.getLineNumber() + "] " + exception.getMessage());
}
- public void fatalError(SAXParseException exception) throws SAXException {
+
+ public void fatalError(SAXParseException exception) throws SAXException
+ {
error(exception);
}
- public void warning(SAXParseException exception) throws SAXException {
+
+ public void warning(SAXParseException exception) throws SAXException
+ {
error(exception);
}
}
-
+
DocumentBuilderFactory dbf;
DocumentBuilder db;
Map schemas;
TestEntityResolver testEntityResolver;
-
- protected void setUp() throws Exception {
+
+ protected void setUp() throws Exception
+ {
dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(true);
dbf.setNamespaceAware(true);
- dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
- "http://www.w3.org/2001/XMLSchema");
+ dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
schemas = new HashMap();
testEntityResolver = new TestEntityResolver(schemas);
}
- public void addSchema(String schemaXmlString) {
- String systemId = "urn:schema"+schemas.size();
+ public void addSchema(String schemaXmlString)
+ {
+ String systemId = "urn:schema" + schemas.size();
schemas.put(systemId, schemaXmlString);
-
+
String[] schemaSources = new String[schemas.size()];
- for (int i=0; i<schemas.size(); i++) {
- schemaSources[i] = "urn:schema"+i;
+ for (int i = 0; i < schemas.size(); i++)
+ {
+ schemaSources[i] = "urn:schema" + i;
}
-
- dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource",
- schemaSources);
+
+ dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", schemaSources);
}
-
- public Document assertValidXml(String documentXmlString) {
- try {
+
+ public Document assertValidXml(String documentXmlString)
+ {
+ try
+ {
db = dbf.newDocumentBuilder();
db.setEntityResolver(testEntityResolver);
TestErrorHandler errorHandler = new TestErrorHandler();
db.setErrorHandler(errorHandler);
Document document = db.parse(new InputSource(new StringReader(documentXmlString)));
- if (! errorHandler.errors.isEmpty()) {
+ if (!errorHandler.errors.isEmpty())
+ {
StringBuffer buffer = new StringBuffer();
buffer.append("parsing problems: \n");
Iterator iter = errorHandler.errors.iterator();
- while (iter.hasNext()) {
+ while (iter.hasNext())
+ {
buffer.append("ERR: ");
buffer.append(iter.next());
}
throw new XmlException(buffer.toString());
}
-
+
return document;
- } catch (XmlException e) {
+ }
+ catch (XmlException e)
+ {
throw e;
- } catch (Exception e) {
- e.printStackTrace();
+ }
+ catch (Exception e)
+ {
throw new XmlException("couldn't parse", e);
}
}
- protected void tearDown() throws Exception {
+ protected void tearDown() throws Exception
+ {
super.tearDown();
}
- public static void printDocument(Document document) {
+ public static void printDocument(Document document)
+ {
log.debug(XmlUtil.toString(document.getDocumentElement()));
}
-
- public static class XmlException extends RuntimeException {
+
+ public static class XmlException extends RuntimeException
+ {
private static final long serialVersionUID = 1L;
- public XmlException(String message) {
+
+ public XmlException(String message)
+ {
super(message);
}
- public XmlException(String message, Throwable cause) {
+
+ public XmlException(String message, Throwable cause)
+ {
super(message, cause);
}
}
/*
+ *
+ * public void testSchemaChoices() { addSchema( "<xs:schema targetNamespace='urn:jbpm.org:test' \n" + " xmlns='urn:jbpm.org:test' \n" +
+ * " xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" + " elementFormDefault='qualified'>\n" + " <xs:element name='root'>\n" +
+ * " <xs:complexType>\n" + " <xs:choice minOccurs='0' maxOccurs='3'>\n" + " <xs:element name='hello' />\n" + " <xs:element name='world' />\n" +
+ * " </xs:choice>\n" + " </xs:complexType>\n" + " </xs:element>\n" + "</xs:schema>" );
+ *
+ * assertValidXml( "<?xml version='1.0'?>\n" + "<root xmlns='urn:jbpm.org:test'>\n" + " <hello />\n" + "</root>" );
+ *
+ * assertValidXml( "<?xml version='1.0'?>\n" + "<root xmlns='urn:jbpm.org:test'>\n" + " <hello />\n" + " <world />\n" + " <hello />\n" + "</root>" );
+ *
+ * try { assertValidXml( "<?xml version='1.0'?>\n" + "<root xmlns='urn:jbpm.org:test'>\n" + " <hello />\n" + " <world />\n" + " <hello />\n" + " <hello />\n" +
+ * "</root>" ); fail("expected exception"); } catch (XmlException e) { // OK } }
+ *
+ * public void testSchemaSequenceOfChoice() { addSchema( "<xs:schema targetNamespace='urn:jbpm.org:test' \n" + " xmlns='urn:jbpm.org:test' \n" +
+ * " xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" + " elementFormDefault='qualified'>\n" + " <xs:element name='root'>\n" +
+ * " <xs:complexType>\n" + " <xs:sequence maxOccurs='3'>\n" + " <xs:choice>\n" + " <xs:element name='hello' />\n" +
+ * " <xs:element name='world' />\n" + " </xs:choice>\n" + " </xs:sequence>\n" + " </xs:complexType>\n" + " </xs:element>\n" + "</xs:schema>"
+ * );
+ *
+ * assertValidXml( "<?xml version='1.0'?>\n" + "<root xmlns='urn:jbpm.org:test'>\n" + " <hello />\n" + "</root>" );
+ *
+ * assertValidXml( "<?xml version='1.0'?>\n" + "<root xmlns='urn:jbpm.org:test'>\n" + " <hello />\n" + " <world />\n" + " <hello />\n" + "</root>" );
+ *
+ * assertValidXml( "<?xml version='1.0'?>\n" + "<root xmlns='urn:jbpm.org:test'>\n" + " <hello />\n" + " <world />\n" + " <hello />\n" + "</root>" );
+ *
+ * try { assertValidXml( "<?xml version='1.0'?>\n" + "<root xmlns='urn:jbpm.org:test'>\n" + " <hello />\n" + " <world />\n" + " <hello />\n" + " <hello />\n" +
+ * "</root>" ); fail("expected exception"); } catch (XmlException e) { // OK } }
+ */
- public void testSchemaChoices() {
- addSchema(
- "<xs:schema targetNamespace='urn:jbpm.org:test' \n" +
- " xmlns='urn:jbpm.org:test' \n" +
- " xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" +
- " elementFormDefault='qualified'>\n" +
- " <xs:element name='root'>\n" +
- " <xs:complexType>\n" +
- " <xs:choice minOccurs='0' maxOccurs='3'>\n" +
- " <xs:element name='hello' />\n" +
- " <xs:element name='world' />\n" +
- " </xs:choice>\n" +
- " </xs:complexType>\n" +
- " </xs:element>\n" +
- "</xs:schema>"
- );
+ public void testMultiSchemas()
+ {
+ addSchema("<xs:schema targetNamespace='urn:jbpm.org:default' \n" + " xmlns='urn:jbpm.org:default' \n"
+ + " xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" + " elementFormDefault='qualified'>\n" + " <xs:element name='root'>\n"
+ + " <xs:complexType>\n" + " <xs:choice minOccurs='0' maxOccurs='3'>\n" + " <xs:element name='hello' />\n"
+ + " <xs:element name='world' />\n" + " <xs:any processContents='lax' minOccurs='0' maxOccurs='unbounded'/>\n"
+ + " <xs:any namespace='##other' processContents='lax' minOccurs='0' maxOccurs='unbounded'/>\n" + " </xs:choice>\n" + " </xs:complexType>\n"
+ + " </xs:element>\n" + " <xs:element name='tuut' />\n" + "</xs:schema>");
- assertValidXml(
- "<?xml version='1.0'?>\n" +
- "<root xmlns='urn:jbpm.org:test'>\n" +
- " <hello />\n" +
- "</root>"
- );
+ addSchema("<xs:schema targetNamespace='urn:jbpm.org:other' \n" + " xmlns='urn:jbpm.org:other' \n"
+ + " xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" + " elementFormDefault='qualified'>\n" + " <xs:element name='tree'>\n"
+ + " <xs:complexType>\n" + " <xs:choice minOccurs='0' maxOccurs='3'>\n" + " <xs:element name='tree' />\n"
+ + " <xs:element name='leaf' />\n" + " </xs:choice>\n" + " </xs:complexType>\n" + " </xs:element>\n" + " <xs:element name='leaf' />\n"
+ + "</xs:schema>");
- assertValidXml(
- "<?xml version='1.0'?>\n" +
- "<root xmlns='urn:jbpm.org:test'>\n" +
- " <hello />\n" +
- " <world />\n" +
- " <hello />\n" +
- "</root>"
- );
-
- try {
- assertValidXml(
- "<?xml version='1.0'?>\n" +
- "<root xmlns='urn:jbpm.org:test'>\n" +
- " <hello />\n" +
- " <world />\n" +
- " <hello />\n" +
- " <hello />\n" +
- "</root>"
- );
- fail("expected exception");
- } catch (XmlException e) {
- // OK
- }
+ assertValidXml("<?xml version='1.0'?>\n" + "<root xmlns='urn:jbpm.org:default'" + " xmlns:other='urn:jbpm.org:other'>\n" + " <hello />\n" + " <hello />\n"
+ + " <tuut />" + " <other:tree />" + "</root>");
}
- public void testSchemaSequenceOfChoice() {
- addSchema(
- "<xs:schema targetNamespace='urn:jbpm.org:test' \n" +
- " xmlns='urn:jbpm.org:test' \n" +
- " xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" +
- " elementFormDefault='qualified'>\n" +
- " <xs:element name='root'>\n" +
- " <xs:complexType>\n" +
- " <xs:sequence maxOccurs='3'>\n" +
- " <xs:choice>\n" +
- " <xs:element name='hello' />\n" +
- " <xs:element name='world' />\n" +
- " </xs:choice>\n" +
- " </xs:sequence>\n" +
- " </xs:complexType>\n" +
- " </xs:element>\n" +
- "</xs:schema>"
- );
-
- assertValidXml(
- "<?xml version='1.0'?>\n" +
- "<root xmlns='urn:jbpm.org:test'>\n" +
- " <hello />\n" +
- "</root>"
- );
-
- assertValidXml(
- "<?xml version='1.0'?>\n" +
- "<root xmlns='urn:jbpm.org:test'>\n" +
- " <hello />\n" +
- " <world />\n" +
- " <hello />\n" +
- "</root>"
- );
-
- assertValidXml(
- "<?xml version='1.0'?>\n" +
- "<root xmlns='urn:jbpm.org:test'>\n" +
- " <hello />\n" +
- " <world />\n" +
- " <hello />\n" +
- "</root>"
- );
-
- try {
- assertValidXml(
- "<?xml version='1.0'?>\n" +
- "<root xmlns='urn:jbpm.org:test'>\n" +
- " <hello />\n" +
- " <world />\n" +
- " <hello />\n" +
- " <hello />\n" +
- "</root>"
- );
- fail("expected exception");
- } catch (XmlException e) {
- // OK
- }
- }
-*/
-
- public void testMultiSchemas() {
- addSchema(
- "<xs:schema targetNamespace='urn:jbpm.org:default' \n" +
- " xmlns='urn:jbpm.org:default' \n" +
- " xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" +
- " elementFormDefault='qualified'>\n" +
- " <xs:element name='root'>\n" +
- " <xs:complexType>\n" +
- " <xs:choice minOccurs='0' maxOccurs='3'>\n" +
- " <xs:element name='hello' />\n" +
- " <xs:element name='world' />\n" +
- " <xs:any processContents='lax' minOccurs='0' maxOccurs='unbounded'/>\n" +
- " <xs:any namespace='##other' processContents='lax' minOccurs='0' maxOccurs='unbounded'/>\n" +
- " </xs:choice>\n" +
- " </xs:complexType>\n" +
- " </xs:element>\n" +
- " <xs:element name='tuut' />\n" +
- "</xs:schema>"
- );
-
- addSchema(
- "<xs:schema targetNamespace='urn:jbpm.org:other' \n" +
- " xmlns='urn:jbpm.org:other' \n" +
- " xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" +
- " elementFormDefault='qualified'>\n" +
- " <xs:element name='tree'>\n" +
- " <xs:complexType>\n" +
- " <xs:choice minOccurs='0' maxOccurs='3'>\n" +
- " <xs:element name='tree' />\n" +
- " <xs:element name='leaf' />\n" +
- " </xs:choice>\n" +
- " </xs:complexType>\n" +
- " </xs:element>\n" +
- " <xs:element name='leaf' />\n" +
- "</xs:schema>"
- );
-
- assertValidXml(
- "<?xml version='1.0'?>\n" +
- "<root xmlns='urn:jbpm.org:default'" +
- " xmlns:other='urn:jbpm.org:other'>\n" +
- " <hello />\n" +
- " <hello />\n" +
- " <tuut />" +
- " <other:tree />" +
- "</root>"
- );
- }
-
}
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/msg/command/AsyncExecutionDbTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/msg/command/AsyncExecutionDbTest.java 2008-09-09 14:21:41 UTC (rev 2152)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/msg/command/AsyncExecutionDbTest.java 2008-09-09 14:41:32 UTC (rev 2153)
@@ -33,42 +33,32 @@
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.exe.ProcessInstance;
-public class AsyncExecutionDbTest extends AbstractDbTestCase {
-
+public class AsyncExecutionDbTest extends AbstractDbTestCase
+{
+
static List recordedNodes = new ArrayList();
-
- public static class RecordNode implements ActionHandler {
+
+ public static class RecordNode implements ActionHandler
+ {
private static final long serialVersionUID = 1L;
- public void execute(ExecutionContext executionContext) throws Exception {
+
+ public void execute(ExecutionContext executionContext) throws Exception
+ {
Node node = executionContext.getNode();
recordedNodes.add(node.getName());
node.leave(executionContext);
}
}
-
- public void testAsyncExecution() throws Exception {
- try {
-
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='one' />" +
- " </start-state>" +
- " <node async='true' name='one'>" +
- " <action class='org.jbpm.msg.command.AsyncExecutionDbTest$RecordNode' />" +
- " <transition to='two' />" +
- " </node>" +
- " <node async='exclusive' name='two'>" +
- " <action class='org.jbpm.msg.command.AsyncExecutionDbTest$RecordNode' />" +
- " <transition to='three' />" +
- " </node>" +
- " <node async='true' name='three'>" +
- " <action class='org.jbpm.msg.command.AsyncExecutionDbTest$RecordNode' />" +
- " <transition to='end' />" +
- " </node>" +
- " <end-state name='end' />" +
- "</process-definition>"
- );
+
+ public void testAsyncExecution() throws Exception
+ {
+
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>" + " <start-state>" + " <transition to='one' />"
+ + " </start-state>" + " <node async='true' name='one'>" + " <action class='org.jbpm.msg.command.AsyncExecutionDbTest$RecordNode' />"
+ + " <transition to='two' />" + " </node>" + " <node async='exclusive' name='two'>"
+ + " <action class='org.jbpm.msg.command.AsyncExecutionDbTest$RecordNode' />" + " <transition to='three' />" + " </node>"
+ + " <node async='true' name='three'>" + " <action class='org.jbpm.msg.command.AsyncExecutionDbTest$RecordNode' />" + " <transition to='end' />"
+ + " </node>" + " <end-state name='end' />" + "</process-definition>");
processDefinition = saveAndReload(processDefinition);
ProcessInstance processInstance = new ProcessInstance(processDefinition);
@@ -77,73 +67,79 @@
assertEquals(processDefinition.getNode("one"), processInstance.getRootToken().getNode());
assertEquals(1, getNbrOfJobsAvailable());
-
+
processJobs(5000);
-
+
assertEquals(0, getNbrOfJobsAvailable());
-
+
List expectedNodes = new ArrayList();
expectedNodes.add("one");
expectedNodes.add("two");
expectedNodes.add("three");
-
+
assertEquals(expectedNodes, recordedNodes);
processDefinition = graphSession.loadProcessDefinition(processDefinition.getId());
processInstance = graphSession.loadProcessInstance(processInstance.getId());
assertTrue(processInstance.hasEnded());
assertEquals(processDefinition.getNode("end"), processInstance.getRootToken().getNode());
-
- } catch (Exception e) {
- e.printStackTrace();
- }
}
static Set recordedActionNumbers = new HashSet();
-
- public static class RecordAction implements ActionHandler {
+
+ public static class RecordAction implements ActionHandler
+ {
private static final long serialVersionUID = 1L;
String nbr;
- public void execute(ExecutionContext executionContext) throws Exception {
+
+ public void execute(ExecutionContext executionContext) throws Exception
+ {
recordedActionNumbers.add(nbr);
}
}
-
- public void testAsyncAction() throws Exception {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <event type='process-start'>" +
- " <action async='true' class='"+RecordAction.class.getName()+"'>" +
- " <nbr>1</nbr>" +
- " </action>" +
- " <action async='exclusive' class='"+RecordAction.class.getName()+"'>" +
- " <nbr>2</nbr>" +
- " </action>" +
- " </event>" +
- " <start-state>" +
- " <transition to='one'>" +
- " <action async='true' class='"+RecordAction.class.getName()+"'>" +
- " <nbr>3</nbr>" +
- " </action>" +
- " <action async='exclusive' class='"+RecordAction.class.getName()+"'>" +
- " <nbr>4</nbr>" +
- " </action>" +
- " </transition>" +
- " </start-state>" +
- " <node name='one'>" +
- " <event type='node-enter'>" +
- " <action async='true' class='"+RecordAction.class.getName()+"'>" +
- " <nbr>5</nbr>" +
- " </action>" +
- " <action async='exclusive' class='"+RecordAction.class.getName()+"'>" +
- " <nbr>6</nbr>" +
- " </action>" +
- " </event>" +
- " <transition to='end' />" +
- " </node>" +
- " <end-state name='end' />" +
- "</process-definition>"
- );
+
+ public void testAsyncAction() throws Exception
+ {
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>" + " <event type='process-start'>"
+ + " <action async='true' class='"
+ + RecordAction.class.getName()
+ + "'>"
+ + " <nbr>1</nbr>"
+ + " </action>"
+ + " <action async='exclusive' class='"
+ + RecordAction.class.getName()
+ + "'>"
+ + " <nbr>2</nbr>"
+ + " </action>"
+ + " </event>"
+ + " <start-state>"
+ + " <transition to='one'>"
+ + " <action async='true' class='"
+ + RecordAction.class.getName()
+ + "'>"
+ + " <nbr>3</nbr>"
+ + " </action>"
+ + " <action async='exclusive' class='"
+ + RecordAction.class.getName()
+ + "'>"
+ + " <nbr>4</nbr>"
+ + " </action>"
+ + " </transition>"
+ + " </start-state>"
+ + " <node name='one'>"
+ + " <event type='node-enter'>"
+ + " <action async='true' class='"
+ + RecordAction.class.getName()
+ + "'>"
+ + " <nbr>5</nbr>"
+ + " </action>"
+ + " <action async='exclusive' class='"
+ + RecordAction.class.getName()
+ + "'>"
+ + " <nbr>6</nbr>"
+ + " </action>"
+ + " </event>"
+ + " <transition to='end' />" + " </node>" + " <end-state name='end' />" + "</process-definition>");
processDefinition = saveAndReload(processDefinition);
ProcessInstance processInstance = new ProcessInstance(processDefinition);
@@ -152,9 +148,9 @@
assertEquals(processDefinition.getNode("end"), processInstance.getRootToken().getNode());
assertEquals(6, getNbrOfJobsAvailable());
assertEquals(0, recordedActionNumbers.size());
-
+
processJobs(5000);
-
+
assertEquals(0, getNbrOfJobsAvailable());
HashSet expected = new HashSet();
@@ -164,7 +160,7 @@
expected.add("4");
expected.add("5");
expected.add("6");
-
+
assertEquals(expected, recordedActionNumbers);
}
}
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/optimisticlocking/LockingTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/optimisticlocking/LockingTest.java 2008-09-09 14:21:41 UTC (rev 2152)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/optimisticlocking/LockingTest.java 2008-09-09 14:41:32 UTC (rev 2153)
@@ -16,62 +16,65 @@
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.persistence.db.DbPersistenceServiceFactory;
-public class LockingTest extends TestCase {
+public class LockingTest extends TestCase
+{
static JbpmConfiguration jbpmConfiguration = AbstractDbTestCase.getDbTestJbpmConfiguration();
-
+
static int nbrOfThreads = 5;
static int nbrOfIterations = 20;
- private void deployProcess() {
+ private void deployProcess()
+ {
// the process will be executed in 2 separete transactions:
- // Transaction 1 will create the process instance and position
+ // Transaction 1 will create the process instance and position
// the root token in the start state
// Transaction 2 will signal the process instance while it is in the
// start state, and that signal will bring the process to it's end state.
-
+
// It's the second transaction for which we'll set up multiple competing threads
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition name='lockprocess'>" +
- " <start-state name='start'>" +
- " <transition to='end'/>" +
- " </start-state>" +
- " <end-state name='end' />" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition name='lockprocess'>" + " <start-state name='start'>"
+ + " <transition to='end'/>" + " </start-state>" + " <end-state name='end' />" + "</process-definition>");
// deploy the process
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
- try {
+ try
+ {
jbpmContext.deployProcessDefinition(processDefinition);
- } finally {
+ }
+ finally
+ {
jbpmContext.close();
}
}
- public void testLocking() {
+ public void testLocking()
+ {
createSchema();
deployProcess();
-
- for(int i=0; i<nbrOfIterations; i++) {
+
+ for (int i = 0; i < nbrOfIterations; i++)
+ {
long processInstanceId = launchProcessInstance();
-
- // create a bunch of threads that will all wait on the
+
+ // create a bunch of threads that will all wait on the
// semaphore before they will try to signal the same process instance
Object semaphore = new Object();
List threads = startThreads(semaphore, processInstanceId);
-
+
// release all the threads
- synchronized(semaphore) {
+ synchronized (semaphore)
+ {
semaphore.notifyAll();
}
-
+
// wait for all threads to finish
joinAllThreads(threads);
-
+
// check that only 1 of those threads committed
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
- try {
+ try
+ {
Session session = jbpmContext.getSession();
Query query = session.createQuery("select c from org.jbpm.graph.exe.Comment as c");
List results = query.list();
@@ -80,109 +83,143 @@
// delete the comment
session.delete(results.get(0));
-
- } finally {
+
+ }
+ finally
+ {
jbpmContext.close();
}
// check that the process instance has ended
jbpmContext = jbpmConfiguration.createJbpmContext();
- try {
+ try
+ {
ProcessInstance processInstance = jbpmContext.loadProcessInstance(processInstanceId);
assertTrue(processInstance.hasEnded());
-
- } finally {
+
+ }
+ finally
+ {
jbpmContext.close();
}
}
}
-
- private long launchProcessInstance() {
+
+ private long launchProcessInstance()
+ {
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
- try {
+ try
+ {
return jbpmContext.newProcessInstance("lockprocess").getId();
- } finally {
+ }
+ finally
+ {
jbpmContext.close();
}
}
-
- private List startThreads(Object semaphore, long processInstanceId) {
+
+ private List startThreads(Object semaphore, long processInstanceId)
+ {
List threads = new ArrayList();
- for (int i=0; i<nbrOfThreads; i++) {
+ for (int i = 0; i < nbrOfThreads; i++)
+ {
Thread thread = new LockThread(semaphore, processInstanceId);
thread.start();
threads.add(thread);
}
-
- try {
+
+ try
+ {
// giving the threads the opportunity to start and arrive in the wait
Thread.sleep(200);
- } catch (InterruptedException e) {
- e.printStackTrace();
}
+ catch (InterruptedException e)
+ {
+ // ignore
+ }
return threads;
}
-
- public static class LockThread extends Thread {
+
+ public static class LockThread extends Thread
+ {
Object semaphore;
long processInstanceId;
- public LockThread(Object semaphore, long processInstanceId) {
+
+ public LockThread(Object semaphore, long processInstanceId)
+ {
this.semaphore = semaphore;
this.processInstanceId = processInstanceId;
}
- public void run() {
- try {
- // first wait until the all threads are released at once in the
+
+ public void run()
+ {
+ try
+ {
+ // first wait until the all threads are released at once in the
// method testLocking
- synchronized(semaphore) {
+ synchronized (semaphore)
+ {
semaphore.wait();
}
-
+
// after a thread is released (=notified), it will try to load the process instance,
// signal it and then commit the transaction
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
- try {
+ try
+ {
ProcessInstance processInstance = jbpmContext.loadProcessInstance(processInstanceId);
processInstance.signal();
jbpmContext.save(processInstance);
-
+
// add a comment in the same transaction so that we can see which thread won
- Comment comment = new Comment(getName()+" committed");
+ Comment comment = new Comment(getName() + " committed");
jbpmContext.getSession().save(comment);
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
jbpmContext.setRollbackOnly();
- } finally {
+ }
+ finally
+ {
jbpmContext.close();
}
-
- } catch (InterruptedException e) {
- e.printStackTrace();
+
+ }
+ catch (InterruptedException e)
+ {
fail("semaphore waiting got interrupted");
- } catch (Throwable t) {
- t.printStackTrace();
}
+ catch (Throwable t)
+ {
+ // ignore
+ }
}
}
- private void joinAllThreads(List threads) {
+ private void joinAllThreads(List threads)
+ {
Iterator iter = threads.iterator();
- while (iter.hasNext()) {
- Thread thread = (Thread) iter.next();
- try {
+ while (iter.hasNext())
+ {
+ Thread thread = (Thread)iter.next();
+ try
+ {
thread.join();
- } catch (InterruptedException e) {
- e.printStackTrace();
+ }
+ catch (InterruptedException e)
+ {
fail("join interrupted");
}
}
}
- private void createSchema() {
+ private void createSchema()
+ {
// create the jbpm schema
- DbPersistenceServiceFactory persistenceServiceFactory = (DbPersistenceServiceFactory) jbpmConfiguration.getServiceFactory("persistence");
+ DbPersistenceServiceFactory persistenceServiceFactory = (DbPersistenceServiceFactory)jbpmConfiguration.getServiceFactory("persistence");
persistenceServiceFactory.createSchema();
}
-
+
}
More information about the jbpm-commits
mailing list