[jbpm-commits] JBoss JBPM SVN: r4141 - in jbpm4/branches/tbaeyens/modules/test-db/src/test/java: org and 9 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Mar 4 14:24:26 EST 2009


Author: tom.baeyens at jboss.com
Date: 2009-03-04 14:24:25 -0500 (Wed, 04 Mar 2009)
New Revision: 4141

Added:
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/activities/
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/activities/ExclusiveTest.java
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/activities/StateTest.java
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/cfg/
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/cfg/ConfigurationTest.java
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/execution/
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/execution/FindExecutionTest.java
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/execution/SignalExecutionTest.java
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/execution/StartExecutionTest.java
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/history/
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/history/AvgDurationTest.java
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/history/ChoiceDistributionTest.java
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/history/EndProcessInstanceTest.java
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/history/ProcessInstanceHistoryTest.java
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/mgmt/
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/process/
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/process/ProcessAttachmentsTest.java
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/process/ProcessDefinitionQueryTest.java
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/process/ProcessServiceTest.java
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/SubTaskTest.java
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/TaskCommentsTest.java
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/TaskCreateUpdateDeleteTest.java
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/TaskListTest.java
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/TaskParticipationsTest.java
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryTest.java
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/variables/
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/variables/BasicVariablesTest.java
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/variables/VariableBasicTypesTest.java
Log:
updates :-)

Added: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/activities/ExclusiveTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/activities/ExclusiveTest.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/activities/ExclusiveTest.java	2009-03-04 19:24:25 UTC (rev 4141)
@@ -0,0 +1,96 @@
+/*
+ * 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.test.activities;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jbpm.Execution;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ExclusiveTest extends JbpmTestCase {
+
+  public void testExclusiveExpression() {
+    deployJpdlXmlString(
+      "<process name='Poolcar'>" +
+      "  <start>" +
+      "    <transition to='How far?' />" +
+      "  </start>" +
+      "  <exclusive name='How far?' expr='#{distance}'>" +
+      "    <transition name='far'    to='Big car' />" +
+      "    <transition name='nearby' to='Small car' />" +
+      "  </exclusive>" +
+      "  <state name='Big car' />" +
+      "  <state name='Small car' />" +
+      "</process>"
+    );
+
+    Map<String, Object> variables = new HashMap<String, Object>();
+    variables.put("distance", "far");
+    Execution execution = executionService.startProcessInstanceByKey("Poolcar", variables);
+    assertEquals("Big car", execution.getActivityName());
+
+    variables.put("distance", "nearby");
+    execution = executionService.startProcessInstanceByKey("Poolcar", variables);
+    assertEquals("Small car", execution.getActivityName());
+  }
+
+  public void testExclusiveWithConditions() {
+    deployJpdlXmlString(
+      "<process name='Poolcar'>" +
+      "  <start>" +
+      "    <transition to='How far?' />" +
+      "  </start>" +
+      "  <exclusive name='How far?'>" +
+      "    <transition to='Big car'>" +
+      "      <condition expr='#{distance &gt; 10}' />" +
+      "    </transition>" +
+      "    <transition to='Small car'>" +
+      "      <condition expr='#{distance &gt;= 3}' />" +
+      "    </transition>" +
+      "    <transition to='No car' />" +
+      "  </exclusive>" +
+      "  <state name='Big car' />" +
+      "  <state name='Small car' />" +
+      "  <state name='No car' />" +
+      "</process>"
+    );
+
+    Map<String, Object> variables = new HashMap<String, Object>();
+    variables.put("distance", new Integer(69));
+    Execution execution = executionService.startProcessInstanceByKey("Poolcar", variables);
+    assertEquals("Big car", execution.getActivityName());
+
+    variables.put("distance", new Integer(6));
+    execution = executionService.startProcessInstanceByKey("Poolcar", variables);
+    assertEquals("Small car", execution.getActivityName());
+
+    variables.put("distance", new Integer(2));
+    execution = executionService.startProcessInstanceByKey("Poolcar", variables);
+    assertEquals("No car", execution.getActivityName());
+  }
+
+}

Added: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/activities/StateTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/activities/StateTest.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/activities/StateTest.java	2009-03-04 19:24:25 UTC (rev 4141)
@@ -0,0 +1,153 @@
+/*
+ * 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.test.activities;
+
+import org.jbpm.Execution;
+import org.jbpm.JbpmException;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ * @author Tom Baeyens
+ */
+public class StateTest extends JbpmTestCase {
+
+  public void testWaitStatesSequence() {
+    deployJpdlXmlString(
+      "<process name='ThreeStates'>" +
+      "  <start name='a'>" +
+      "    <transition to='b' />" +
+      "  </start>" +
+      "  <state name='b'>" +
+      "    <transition to='c' />" +
+      "  </state>" +
+      "  <state name='c'>" +
+      "    <transition to='d' />" +
+      "  </state>" +
+      "  <end name='d' />" +
+      "</process>"
+    );
+    
+    Execution execution = executionService.startProcessInstanceById("ThreeStates:1");
+    assertEquals("b", execution.getActivityName());
+
+    String executionId = execution.getId();
+    execution = executionService.signalExecutionById(executionId);
+    assertEquals("c", execution.getActivityName());
+
+    execution = executionService.signalExecutionById(executionId);
+    assertEquals("d", execution.getActivityName());
+    assertTrue(execution.isEnded());
+  }
+
+  public void testExternalDecision() {
+    deployJpdlXmlString(
+      "<process name='p'>" +
+      "  <start>" +
+      "    <transition to='ed' />" +
+      "  </start>" +
+      "  <state name='ed'>" +
+      "    <transition name='left'   to='b' />" +
+      "    <transition name='middle' to='c' />" +
+      "    <transition name='right'  to='d' />" +
+      "  </state>" +
+      "  <state name='b' />" +
+      "  <state name='c' />" +
+      "  <state name='d' />" +
+      "</process>"
+    );
+
+    Execution execution = executionService.startProcessInstanceByKey("p", "one");
+    assertEquals("ed", execution.getActivityName());
+    execution = executionService.signalExecutionById("p/one", "left");
+    assertEquals("b", execution.getActivityName());
+
+    executionService.startProcessInstanceById("p:1", "two");
+    execution = executionService.signalExecutionById("p/two", "middle");
+    assertEquals("c", execution.getActivityName());
+
+    executionService.startProcessInstanceById("p:1", "three");
+    execution = executionService.signalExecutionById("p/three", "right");
+    assertEquals("d", execution.getActivityName());
+  }
+
+  public void testDefaultSignalWithNamedTransitions() {
+    deployJpdlXmlString(
+      "<process name='p'>" +
+      "  <start>" +
+      "    <transition to='a' />" +
+      "  </start>" +
+      "  <state name='a'>" +
+      "    <transition name='left'   to='b' />" +
+      "    <transition name='middle' to='c' />" +
+      "    <transition name='right'  to='d' />" +
+      "  </state>" +
+      "  <state name='b' />" +
+      "  <state name='c' />" +
+      "  <state name='d' />" +
+      "</process>"
+    );
+
+    executionService.startProcessInstanceByKey("p", "one");
+    try {
+      executionService.signalExecutionById("p/one", "left");
+    } catch (JbpmException e) {
+      assertTextPresent("no matching transition or event for default signal in state(a)", e.getMessage());
+    }
+  }
+
+  public void testNamedSignalWithoutMatchingTransition() {
+    deployJpdlXmlString(
+      "<process name='p'>" +
+      "  <start>" +
+      "    <transition to='a' />" +
+      "  </start>" +
+      "  <state name='a'>" +
+      "    <transition name='left'   to='b' />" +
+      "    <transition name='middle' to='c' />" +
+      "    <transition name='right'  to='d' />" +
+      "  </state>" +
+      "  <state name='b' />" +
+      "  <state name='c' />" +
+      "  <state name='d' />" +
+      "</process>"
+    );
+
+    executionService.startProcessInstanceByKey("p", "one");
+    Execution execution = executionService.signalExecutionById("p/one", "up");
+    assertEquals("a", execution.getActivityName());
+  }
+
+  public void testDefaultSignalWithoutTransitions() {
+    deployJpdlXmlString(
+      "<process name='p'>" +
+      "  <start>" +
+      "    <transition to='a' />" +
+      "  </start>" +
+      "  <state name='a' />" +
+      "</process>"
+    );
+
+    executionService.startProcessInstanceByKey("p", "one");
+    Execution execution = executionService.signalExecutionById("p/one");
+    assertEquals("a", execution.getActivityName());
+  }
+}

Added: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/cfg/ConfigurationTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/cfg/ConfigurationTest.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/cfg/ConfigurationTest.java	2009-03-04 19:24:25 UTC (rev 4141)
@@ -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.test.cfg;
+
+import org.jbpm.Configuration;
+import org.jbpm.ProcessEngine;
+import org.jbpm.test.BaseJbpmTestCase;
+
+/**
+ * @author Tom Baeyens
+ */
+public class ConfigurationTest extends BaseJbpmTestCase {
+
+  public void testDefaultConfiguration() {
+    ProcessEngine processEngine = new Configuration()
+        .buildProcessEngine();
+    assertNotNull(processEngine);
+  }
+
+  public void testMinimalConfiguration() {
+    ProcessEngine processEngine = new Configuration()
+        .setXmlString("<jbpm-configuration />")
+        .buildProcessEngine();
+    assertNotNull(processEngine);
+  }
+
+  public void testConfigurationServices() {
+    ProcessEngine processEngine = new Configuration()
+        .setXmlString(
+            "<jbpm-configuration>" +
+            "  <process-engine-context>" +
+            "    <process-service />" +
+            "    <execution-service />" +
+            "    <management-service />" +
+            "  </process-engine-context>" +
+            "</jbpm-configuration>"
+        )
+        .buildProcessEngine();
+    assertNotNull(processEngine);
+    assertNotNull(processEngine.getProcessService());
+    assertNotNull(processEngine.getExecutionService());
+    assertNotNull(processEngine.getManagementService());
+  }
+}

Added: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/execution/FindExecutionTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/execution/FindExecutionTest.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/execution/FindExecutionTest.java	2009-03-04 19:24:25 UTC (rev 4141)
@@ -0,0 +1,50 @@
+/*
+ * 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.test.execution;
+
+import org.jbpm.Execution;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ * @author Tom Baeyens
+ */
+public class FindExecutionTest extends JbpmTestCase {
+
+  public void testFindExecutionById() {
+    deployJpdlXmlString(
+      "<process name='p'>" +
+      "  <start>" +
+      "    <transition to='a' />" +
+      "  </start>" +
+      "  <state name='a' />" +
+      "</process>"
+    );
+
+    Execution execution = executionService.startProcessInstanceByKey("p");
+
+    // take the id and see if the execution service can still find it back
+    execution = executionService.findExecution(execution.getId());
+    assertNotNull(execution);
+    assertEquals("a", execution.getActivityName());
+  }
+
+}

Added: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/execution/SignalExecutionTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/execution/SignalExecutionTest.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/execution/SignalExecutionTest.java	2009-03-04 19:24:25 UTC (rev 4141)
@@ -0,0 +1,254 @@
+/*
+ * 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.test.execution;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.jbpm.Execution;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class SignalExecutionTest extends JbpmTestCase {
+  
+  public void testSignalExecutionByKey() {
+    deployJpdlXmlString(
+      "<process name='Insurance claim' key='ICL'>" +
+      "  <start>" +
+      "    <transition to='a' />" +
+      "  </start>" +
+      "  <state name='a'>" +
+      "    <transition to='b' />" +
+      "  </state>" +
+      "  <state name='b'>" +
+      "    <transition to='c' />" +
+      "  </state>" +
+      "  <state name='c' />" +
+      "</process>"
+    );
+
+    Execution execution = executionService.startProcessInstanceByKey("ICL", "82436");
+    
+    assertEquals("a", execution.getActivityName());
+    
+    execution = executionService.signalExecutionByKey("ICL", "82436");
+
+    assertEquals("b", execution.getActivityName());
+
+    execution = executionService.signalExecutionByKey("ICL", "82436");
+
+    assertEquals("c", execution.getActivityName());
+  }
+
+  public void testSignalExecutionById() {
+    deployJpdlXmlString(
+      "<process name='Insurance claim' key='ICL'>" +
+      "  <start>" +
+      "    <transition to='a' />" +
+      "  </start>" +
+      "  <state name='a'>" +
+      "    <transition to='b' />" +
+      "  </state>" +
+      "  <state name='b'>" +
+      "    <transition to='c' />" +
+      "  </state>" +
+      "  <state name='c' />" +
+      "</process>"
+    );
+
+    Execution execution = executionService.startProcessInstanceByKey("ICL", "82436");
+    
+    assertEquals("a", execution.getActivityName());
+    
+    execution = executionService.signalExecutionById("ICL/82436");
+
+    assertEquals("b", execution.getActivityName());
+
+    execution = executionService.signalExecutionById("ICL/82436");
+
+    assertEquals("c", execution.getActivityName());
+  }
+
+  public void testSignalExecutionWithVariables() {
+    deployJpdlXmlString(
+      "<process name='Insurance claim' key='ICL'>" +
+      "  <start>" +
+      "    <transition to='a' />" +
+      "  </start>" +
+      "  <state name='a'>" +
+      "    <transition to='b' />" +
+      "  </state>" +
+      "  <state name='b' />" +
+      "</process>"
+    );
+
+    Execution execution = executionService.startProcessInstanceByKey("ICL", "82436");
+
+    Map<String,Object> variables = new HashMap<String,Object>();
+    variables.put("customer", "John Doe");
+    variables.put("type", "Accident");
+    variables.put("amount", new Float(763.74));
+
+    execution = executionService.signalExecutionById("ICL/82436", variables);
+
+    assertNotNull(execution);
+    String executionId = execution.getId();
+    assertEquals("b", execution.getActivityName());
+    
+    Map<String,Object> expectedVariables = new HashMap<String, Object>(variables); 
+    Set<String> expectedVariableNames = new HashSet<String>(expectedVariables.keySet());
+    Set<String> variableNames = new HashSet<String>(executionService.getVariableNames(executionId));
+    assertEquals(expectedVariableNames, variableNames);
+    
+    variables = executionService.getVariables(executionId, variableNames);
+    assertEquals(expectedVariables, variables);
+  }
+
+  
+  public void testDefaultSignalWithoutTransitions() {
+    deployJpdlXmlString(
+      "<process name='p'>" +
+      "  <start>" +
+      "    <transition to='a' />" +
+      "  </start>" +
+      "  <state name='a' />" +
+      "</process>"
+    );
+
+    Execution execution = executionService.startProcessInstanceByKey("p");
+    execution = executionService.signalExecutionById(execution.getId());
+    assertEquals("a", execution.getActivityName());
+  }
+
+  /*
+
+  public void testSetVariable()
+  {
+    Execution execution = startExecution();
+
+    String executionId = execution.getId();
+    // set variable a to value text
+    executionService.setVariable(executionId, "a", "text");
+    // check if we can read that value back
+    assertEquals("text", executionService.getVariable(executionId, "a"));
+
+    // overwrite the value of variable a with another text
+    executionService.setVariable(executionId, "a", "another text");
+    // see if we can read another text back from the variable
+    assertEquals("another text", executionService.getVariable(executionId, "a"));
+  }
+
+  public void testSetVariables()
+  {
+    Execution execution = startExecution();
+
+    Map<String, Object> variables = new HashMap<String, Object>();
+    variables.put("a", new Integer(1));
+    variables.put("b", "text");
+
+    // set variables in bulk by providing a map
+    executionService.setVariables(execution.getId(), variables);
+
+    Map<String, Object> expected = new HashMap<String, Object>(variables);
+
+    Set<String> variableNames = new HashSet<String>();
+    variableNames.add("a");
+    variableNames.add("b");
+
+    // read the variables back and compare
+    assertEquals(expected, executionService.getVariables(execution.getId(), variableNames));
+
+    // now set variables b and c with a map
+    variables = new HashMap<String, Object>();
+    variables.put("b", new Integer(99));
+    variables.put("c", "another text");
+
+    // this should leave a untouched, overwrite b and create c
+    executionService.setVariables(execution.getId(), variables);
+
+    // update the expected map
+    expected.put("b", new Integer(99));
+    expected.put("c", "another text");
+
+    // add c to the variable names that should be collected
+    variableNames.add("c");
+
+    // read the variables back and compare
+    assertEquals(expected, executionService.getVariables(execution.getId(), variableNames));
+  }
+
+  // helper methods ///////////////////////////////////////////////////////////
+
+  /**
+   * deploys 3 versions of process with name 'nuclear fusion', 2 versions of the processes 'ultimate seduction' and
+   * 'publish book'
+  void deployMultipleVersionsOfProcesses()
+  {
+    ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
+
+    ProcessDefinition processDefinition = ProcessFactory.build("nuclear fusion").key("NFU").activity("initial").initial().behaviour(
+        WaitState.class).done();
+    DeploymentImpl deploymentImpl = new DeploymentImpl(processDefinition);
+    processService.deploy(deploymentImpl);
+
+    processDefinition = ProcessFactory.build("ultimate seduction").key("USD").activity("initial").initial().behaviour(WaitState.class).done();
+    deploymentImpl = new DeploymentImpl(processDefinition);
+    processService.deploy(deploymentImpl);
+
+    processDefinition = ProcessFactory.build("ultimate seduction").key("USD").activity("initial").initial().behaviour(WaitState.class).done();
+    deploymentImpl = new DeploymentImpl(processDefinition);
+    processService.deploy(deploymentImpl);
+
+    processDefinition = ProcessFactory.build("nuclear fusion").key("NFU").activity("initial").initial().behaviour(WaitState.class).done();
+    deploymentImpl = new DeploymentImpl(processDefinition);
+    processService.deploy(deploymentImpl);
+
+    processDefinition = ProcessFactory.build("publish book").key("PBO").activity("initial").initial().behaviour(WaitState.class).done();
+    deploymentImpl = new DeploymentImpl(processDefinition);
+    processService.deploy(deploymentImpl);
+
+    processDefinition = ProcessFactory.build("nuclear fusion").key("NFU").activity("initial").initial().behaviour(WaitState.class).done();
+    deploymentImpl = new DeploymentImpl(processDefinition);
+    processService.deploy(deploymentImpl);
+  }
+
+  Execution startExecution()
+  {
+    ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
+
+    ProcessDefinition processDefinition = ProcessFactory.build("nuclear fusion").activity("initial").initial().behaviour(WaitState.class)
+        .done();
+    DeploymentImpl deploymentImpl = new DeploymentImpl(processDefinition);
+    processService.deploy(deploymentImpl);
+
+    ExecutionService executionService = getEnvironmentFactory().get(ExecutionService.class);
+
+    return executionService.startExecutionByName("nuclear fusion");
+  }
+
+   */
+}

Added: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/execution/StartExecutionTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/execution/StartExecutionTest.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/execution/StartExecutionTest.java	2009-03-04 19:24:25 UTC (rev 4141)
@@ -0,0 +1,219 @@
+/*
+ * 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.test.execution;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.jbpm.Execution;
+import org.jbpm.ProcessDefinition;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class StartExecutionTest extends JbpmTestCase {
+
+  public void testStartNewExecutionByKey() {
+    deployJpdlXmlString(
+      "<process name='Insurance claim' key='ICL'>" +
+      "  <start>" +
+      "    <transition to='a' />" +
+      "  </start>" +
+      "  <state name='a' />" +
+      "</process>"
+    );
+
+    Execution execution = executionService.startProcessInstanceByKey("ICL");
+
+    assertNotNull(execution);
+    assertEquals("a", execution.getActivityName());
+  }
+
+  public void testStartNewExecutionInLatestProcessDefinition() {
+    deployJpdlXmlString(
+      "<process name='Insurance claim' key='ICL'>" +
+      "  <start>" +
+      "    <transition to='a' />" +
+      "  </start>" +
+      "  <state name='a' />" +
+      "</process>"
+    );
+
+    Execution execution = executionService.startProcessInstanceByKey("ICL");
+
+    assertNotNull(execution);
+    assertEquals("a", execution.getActivityName());
+
+    deployJpdlXmlString(
+      "<process name='Insurance claim' key='ICL'>" +
+      "  <start>" +
+      "    <transition to='b' />" +
+      "  </start>" +
+      "  <state name='b' />" +
+      "</process>"
+    );
+
+    execution = executionService.startProcessInstanceByKey("ICL");
+
+    assertNotNull(execution);
+    assertEquals("b", execution.getActivityName());
+  }
+  
+  public void testStartExecutionInLatestByNameWithVariables() {
+    deployJpdlXmlString(
+      "<process name='Insurance claim' key='ICL'>" +
+      "  <start>" +
+      "    <transition to='a' />" +
+      "  </start>" +
+      "  <state name='a' />" +
+      "</process>"
+    );
+
+    deployJpdlXmlString(
+      "<process name='Insurance claim' key='ICL'>" +
+      "  <start>" +
+      "    <transition to='b' />" +
+      "  </start>" +
+      "  <state name='b' />" +
+      "</process>"
+    );
+
+    // create variables that are fed into the process before it starts executing
+    Map<String, Object> variables = new HashMap<String, Object>();
+    variables.put("a", new Integer(1));
+    variables.put("b", "text");
+
+    // feed the variables in
+    Execution execution = executionService.startProcessInstanceByKey("ICL", variables);
+    String executionId = execution.getId();
+    assertEquals("b", execution.getActivityName());
+
+    // verify that the variables are actually set
+    assertEquals(new Integer(1), executionService.getVariable(executionId, "a"));
+    assertEquals("text", executionService.getVariable(executionId, "b"));
+
+    // in the generated id, we can see if the right process definition version was taken
+    assertTrue(execution.getId().startsWith("ICL/"));
+  }
+
+  public void testStartNewProcessInstanceWithAKey() {
+    deployJpdlXmlString(
+      "<process name='Insurance claim' key='ICL'>" +
+      "  <start>" +
+      "    <transition to='a' />" +
+      "  </start>" +
+      "  <state name='a' />" +
+      "</process>"
+    );
+
+    Execution execution = executionService.startProcessInstanceByKey("ICL", "one");
+
+    assertNotNull(execution);
+    assertEquals("ICL/one", execution.getId());
+  }
+
+  public void testStartNewProcessInstanceWithVariables() {
+    deployJpdlXmlString(
+      "<process name='Insurance claim' key='ICL'>" +
+      "  <start>" +
+      "    <transition to='a' />" +
+      "  </start>" +
+      "  <state name='a' />" +
+      "</process>"
+    );
+    
+    Map<String,Object> variables = new HashMap<String,Object>();
+    variables.put("customer", "John Doe");
+    variables.put("type", "Accident");
+    variables.put("amount", new Float(763.74));
+
+    Execution execution = executionService.startProcessInstanceByKey("ICL", variables);
+    
+    String executionId = execution.getId();
+
+    assertNotNull(execution);
+    
+    Map<String,Object> expectedVariables = new HashMap<String, Object>(variables); 
+    Set<String> expectedVariableNames = new HashSet<String>(expectedVariables.keySet());
+    Set<String> variableNames = new HashSet<String>(executionService.getVariableNames(executionId));
+    assertEquals(expectedVariableNames, variableNames);
+    
+    variables = executionService.getVariables(executionId, variableNames);
+    assertEquals(expectedVariables, variables);
+  }
+
+  public void testStartExecutionById() {
+    deployJpdlXmlString(
+      "<process name='Insurance claim' key='ICL'>" +
+      "  <start>" +
+      "    <transition to='a' />" +
+      "  </start>" +
+      "  <state name='a' />" +
+      "</process>"
+    );
+    
+    ProcessDefinition processDefinition = processService.findProcessDefinitionsByKey("ICL").get(0);
+    
+    // start an execution for the process with the given id
+    Execution execution = executionService.startProcessInstanceById("ICL:1");
+    assertNotNull(execution);
+
+    // checking the state
+    assertEquals("a", execution.getActivityName());
+
+    // checking the generated id
+    assertNull(execution.getName());
+    assertNull(execution.getKey());
+    // if there is no user defined name or key specified in the execution,
+    // the default id generator will create a unique id like this: processDefinitionId/execution.dbid
+    assertTrue(execution.getId().startsWith("ICL/"));
+    // the last part of the execution key should be the dbid.
+    Long.parseLong(execution.getId().substring(4));
+  }
+
+  public void testStartExecutionByIdWithVariables() {
+    deployJpdlXmlString(
+      "<process name='Insurance claim' key='ICL'>" +
+      "  <start>" +
+      "    <transition to='a' />" +
+      "  </start>" +
+      "  <state name='a' />" +
+      "</process>"
+    );
+
+    // create the map with variables
+    Map<String, Object> variables = new HashMap<String, Object>();
+    variables.put("a", new Integer(1));
+    variables.put("b", "text");
+
+    // provide the variables in the start execution method
+    Execution execution = executionService.startProcessInstanceById("ICL:1", variables);
+    String executionId = execution.getId();
+
+    assertEquals(new Integer(1), executionService.getVariable(executionId, "a"));
+    assertEquals("text", executionService.getVariable(executionId, "b"));
+  }
+}

Added: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/history/AvgDurationTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/history/AvgDurationTest.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/history/AvgDurationTest.java	2009-03-04 19:24:25 UTC (rev 4141)
@@ -0,0 +1,83 @@
+/*
+ * 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.test.history;
+
+import java.util.Map;
+
+import org.jbpm.Execution;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class AvgDurationTest extends JbpmTestCase {
+
+  public void testAvgDuration() throws Exception {
+    deployJpdlXmlString(
+      "<process name='Insurance claim' key='ICL'>" +
+      "  <start>" +
+      "    <transition to='one' />" +
+      "  </start>" +
+      "  <state name='one'>" +
+      "    <transition to='two' />" +
+      "  </state>" +
+      "  <state name='two'>" +
+      "    <transition to='three' />" +
+      "  </state>" +
+      "  <state name='three'>" +
+      "    <transition to='end' />" +
+      "  </state>" +
+      "  <end name='end' />" +
+      "</process>"
+    );
+
+    executeProcess();
+    executeProcess();
+    executeProcess();
+
+    Map<String, Long> avgDurations = historyService.avgDurationPerActivity("ICL:1");
+
+
+    Long avgDurationOne = avgDurations.get("one");
+    assertNotNull(avgDurationOne);
+    assertTrue("expected avg duration bigger then 40, but was"+avgDurationOne, avgDurationOne>40);
+    Long avgDurationTwo = avgDurations.get("two");
+    assertNotNull(avgDurationTwo);
+    assertTrue("expected avg duration bigger then 10, but was"+avgDurationTwo, avgDurationTwo>10);
+    Long avgDurationThree = avgDurations.get("three");
+    assertNotNull(avgDurationThree);
+    assertTrue("expected avg duration bigger then 0, but was"+avgDurationThree, avgDurationThree>=0);
+
+    assertEquals(3, avgDurations.size());
+  }
+
+  protected void executeProcess() throws InterruptedException {
+    Execution execution = executionService.startProcessInstanceByKey("ICL");
+    Thread.sleep(50);
+    executionService.signalExecutionById(execution.getId());
+    Thread.sleep(20);
+    executionService.signalExecutionById(execution.getId());
+    executionService.signalExecutionById(execution.getId());
+  }
+
+}

Added: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/history/ChoiceDistributionTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/history/ChoiceDistributionTest.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/history/ChoiceDistributionTest.java	2009-03-04 19:24:25 UTC (rev 4141)
@@ -0,0 +1,75 @@
+/*
+ * 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.test.history;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jbpm.Execution;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ChoiceDistributionTest extends JbpmTestCase {
+
+  public void testExclusiveExpression() {
+    deployJpdlXmlString(
+      "<process name='Transport Selection' key='TRS'>" +
+      "  <start>" +
+      "    <transition to='How far?' />" +
+      "  </start>" +
+      "  <exclusive name='How far?' expr='#{distance}'>" +
+      "    <transition name='far'           to='Big car' />" +
+      "    <transition name='nearby'        to='Small car' />" +
+      "    <transition name='other country' to='Airoplane' />" +
+      "  </exclusive>" +
+      "  <state name='Big car' />" +
+      "  <state name='Small car' />" +
+      "  <state name='Airoplane' />" +
+      "</process>"
+    );
+
+    Map<String, Object> variables = new HashMap<String, Object>();
+    variables.put("distance", "far");
+    executionService.startProcessInstanceByKey("TRS", variables);
+
+    variables.put("distance", "nearby");
+    executionService.startProcessInstanceByKey("TRS", variables);
+    executionService.startProcessInstanceByKey("TRS", variables);
+    executionService.startProcessInstanceByKey("TRS", variables);
+
+    variables.put("distance", "other country");
+    executionService.startProcessInstanceByKey("TRS", variables);
+    executionService.startProcessInstanceByKey("TRS", variables);
+
+    Map<String, Integer> choiceDistribution = historyService.choiceDistribution("TRS:1", "How far?");
+    
+    assertEquals(1, (int)choiceDistribution.get("far"));
+    assertEquals(3, (int)choiceDistribution.get("nearby"));
+    assertEquals(2, (int)choiceDistribution.get("other country"));
+      
+  }
+
+
+}

Added: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/history/EndProcessInstanceTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/history/EndProcessInstanceTest.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/history/EndProcessInstanceTest.java	2009-03-04 19:24:25 UTC (rev 4141)
@@ -0,0 +1,65 @@
+/*
+ * 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.test.history;
+
+import java.util.List;
+
+import org.jbpm.Execution;
+import org.jbpm.history.HistoryProcessInstance;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class EndProcessInstanceTest extends JbpmTestCase {
+
+  public void testCancelProcessInstance() {
+    deployJpdlXmlString(
+      "<process name='Insurance claim' key='ICL'>" +
+      "  <start>" +
+      "    <transition to='wait' />" +
+      "  </start>" +
+      "  <state name='wait'>" +
+      "    <transition to='end' />" +
+      "  </state>" +
+      "  <end name='end' />" +
+      "</process>"
+    );
+
+    Execution execution = executionService.startProcessInstanceByKey("ICL");
+    String processInstanceId = execution.getId();
+    executionService.endProcessInstance(processInstanceId, Execution.STATE_CANCELLED);
+
+    List<Execution> executions = executionService.createExecutionQuery()
+        .processInstanceId(processInstanceId)
+        .execute();
+    assertEquals(0, executions.size());
+
+    HistoryProcessInstance historyProcessInstance = historyService.createHistoryProcessInstanceQuery()
+      .processInstanceId(processInstanceId)
+      .executeUniqueResult();
+
+    assertNotNull(historyProcessInstance.getEndTime());
+    assertEquals(Execution.STATE_CANCELLED, historyProcessInstance.getState());
+  }
+}

Added: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/history/ProcessInstanceHistoryTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/history/ProcessInstanceHistoryTest.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/history/ProcessInstanceHistoryTest.java	2009-03-04 19:24:25 UTC (rev 4141)
@@ -0,0 +1,75 @@
+/*
+ * 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.test.history;
+
+import java.util.List;
+
+import org.jbpm.Execution;
+import org.jbpm.history.HistoryProcessInstance;
+import org.jbpm.history.HistoryProcessInstanceQuery;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ProcessInstanceHistoryTest extends JbpmTestCase {
+
+  public void testProcessInstanceHistory() {
+    deployJpdlXmlString(
+      "<process name='Insurance claim' key='ICL'>" +
+      "  <start>" +
+      "    <transition to='end' />" +
+      "  </start>" +
+      "  <end name='end' />" +
+      "</process>"
+    );
+
+    executionService.startProcessInstanceByKey("ICL");
+    executionService.startProcessInstanceByKey("ICL");
+    executionService.startProcessInstanceByKey("ICL");
+    
+    List<HistoryProcessInstance> historyProcessInstances = historyService
+      .createHistoryProcessInstanceQuery()
+      .processDefinitionId("ICL:1")
+      .orderAsc(HistoryProcessInstanceQuery.PROPERTY_STARTTIME)
+      .execute();
+
+    assertEquals(3, historyProcessInstances.size());
+    
+    for (HistoryProcessInstance historyProcessInstance: historyProcessInstances) {
+      assertTrue(historyProcessInstance.getProcessInstanceId().startsWith("ICL"));
+      assertEquals(HistoryProcessInstance.STATE_ENDED, historyProcessInstance.getState());
+      assertNotNull(historyProcessInstance.getStartTime());
+      assertNotNull(historyProcessInstance.getEndTime());
+    }
+    
+    // also check that the ended process instances have been removed from the 
+    // runtime database
+    List<Execution> executions = executionService
+      .createExecutionQuery()
+      .processDefinitionId("ICL:1")
+      .execute();
+
+    assertEquals(0, executions.size());
+  }
+}

Added: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/process/ProcessAttachmentsTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/process/ProcessAttachmentsTest.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/process/ProcessAttachmentsTest.java	2009-03-04 19:24:25 UTC (rev 4141)
@@ -0,0 +1,68 @@
+/*
+ * 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.test.process;
+
+import java.io.ByteArrayInputStream;
+import java.util.Arrays;
+import java.util.List;
+
+import org.jbpm.ProcessDefinition;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ProcessAttachmentsTest extends JbpmTestCase {
+
+  public void testProcessWithNameOnly() {
+    byte[] lotOfBytes = generateString("a lot of bytes ", 5000).getBytes();
+    byte[] otherBytes = generateString("other bytes ", 5000).getBytes();
+    
+    List<ProcessDefinition> deployedProcessDefinitions = 
+    processService.createDeployment()
+      .addString("xmlstring.jpdl.xml", 
+                 "<process name='Insurance claim'>" +
+                 "  <start />" +
+                 "</process>")
+      .addInputStream("a lot of attachment", new ByteArrayInputStream(lotOfBytes))
+      .addInputStream("other attachment", new ByteArrayInputStream(otherBytes))
+      .deploy()
+      .getProcessDefinitions();
+    ProcessDefinition processDefinition = registerDeployedProcessDefinitions(deployedProcessDefinitions);
+
+    byte[] retrievedLotOfBytes = processService.getAttachment(processDefinition.getId(), "a lot of attachment");
+    assertTrue(Arrays.equals(lotOfBytes, retrievedLotOfBytes));
+    
+    byte[] retrievedOtherBytes = processService.getAttachment(processDefinition.getId(), "other attachment");
+    assertTrue(Arrays.equals(otherBytes, retrievedOtherBytes));
+  }
+
+  protected String generateString(String base, int multiplier) {
+    StringBuffer buffer = new StringBuffer();
+    for (int i=0; i<multiplier; i++) {
+      buffer.append(base);
+    }
+    String string = buffer.toString();
+    return string;
+  }
+}

Added: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/process/ProcessDefinitionQueryTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/process/ProcessDefinitionQueryTest.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/process/ProcessDefinitionQueryTest.java	2009-03-04 19:24:25 UTC (rev 4141)
@@ -0,0 +1,139 @@
+/*
+ * 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.test.process;
+
+import java.util.List;
+
+import org.jbpm.ProcessDefinition;
+import org.jbpm.ProcessDefinitionQuery;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ProcessDefinitionQueryTest extends JbpmTestCase {
+
+  public void testQueryProcessDefinitionsEmpty() {
+    List<ProcessDefinition> processDefinitions = processService
+      .createProcessDefinitionQuery()
+      .execute();
+    
+    assertEquals(0, processDefinitions.size());
+  }
+
+  public void testQueryProcessDefinitionsNameLike() {
+    deployJpdlXmlString(
+      "<process name='make print'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    deployJpdlXmlString(
+      "<process name='use phone'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    deployJpdlXmlString(
+      "<process name='make friends'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    deployJpdlXmlString(
+      "<process name='clean whiteboard'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    deployJpdlXmlString(
+      "<process name='fix coffeemaker'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    List<ProcessDefinition> processDefinitions = processService.createProcessDefinitionQuery()
+      .nameLike("%make%")
+      .orderAsc(ProcessDefinitionQuery.PROPERTY_NAME)
+      .execute();
+
+    assertEquals("fix coffeemaker", processDefinitions.get(0).getName());
+    assertEquals("make friends",    processDefinitions.get(1).getName());
+    assertEquals("make print",      processDefinitions.get(2).getName());
+  }
+
+  public void testQueryProcessDefinitionsKeyLike() {
+    deployJpdlXmlString(
+      "<process name='make print'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    deployJpdlXmlString(
+      "<process name='use phone'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    deployJpdlXmlString(
+      "<process name='make friends'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    deployJpdlXmlString(
+      "<process name='make friends'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    deployJpdlXmlString(
+      "<process name='make friends'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    deployJpdlXmlString(
+      "<process name='clean whiteboard'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    deployJpdlXmlString(
+      "<process name='fix coffeemaker'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    List<ProcessDefinition> processDefinitions = processService.createProcessDefinitionQuery()
+      .keyLike("make%")
+      .orderAsc(ProcessDefinitionQuery.PROPERTY_NAME)
+      .orderDesc(ProcessDefinitionQuery.PROPERTY_VERSION)
+      .execute();
+
+    assertEquals("make_friends:3", processDefinitions.get(0).getId());
+    assertEquals("make_friends:2", processDefinitions.get(1).getId());
+    assertEquals("make_friends:1", processDefinitions.get(2).getId());
+    assertEquals("make_print:1",   processDefinitions.get(3).getId());
+  }
+}

Added: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/process/ProcessServiceTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/process/ProcessServiceTest.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/process/ProcessServiceTest.java	2009-03-04 19:24:25 UTC (rev 4141)
@@ -0,0 +1,356 @@
+/*
+ * 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.test.process;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jbpm.Execution;
+import org.jbpm.JbpmException;
+import org.jbpm.ProcessDefinition;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ProcessServiceTest extends JbpmTestCase {
+
+  public void testProcessWithNameOnly() {
+    ProcessDefinition processDefinition = deployJpdlXmlString(
+      "<process name='Insurance claim'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    assertNotNull(processDefinition);
+    assertEquals("Insurance claim", processDefinition.getName());
+    assertEquals("Insurance_claim", processDefinition.getKey());
+    assertEquals(1, processDefinition.getVersion());
+    assertEquals("Insurance_claim:1", processDefinition.getId());
+  }
+
+  public void testProcessWithNameAndKey() {
+    deployJpdlXmlString(
+      "<process name='Insurance claim' key='ICL'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    ProcessDefinition processDefinition = processService.findLatestProcessDefinitionByKey("ICL");
+
+    assertNotNull(processDefinition);
+    assertEquals("Insurance claim", processDefinition.getName());
+    assertEquals("ICL", processDefinition.getKey());
+    assertEquals(1, processDefinition.getVersion());
+    assertEquals("ICL:1", processDefinition.getId());
+  }
+
+  // interface methods ////////////////////////////////////////////////////////
+
+  public void testFindProcessDefinitionKeys() {
+    deployMultipleVersionsOfProcesses();
+
+    List<String> processKeys = processService.findProcessDefinitionKeys();
+
+    List<String> expected = new ArrayList<String>();
+    expected.add("nuclear_fusion");
+    expected.add("publish_book");
+    expected.add("ultimate_seduction");
+
+    assertEquals(expected, processKeys);
+  }
+
+
+  public void testFindProcessByKey() {
+    deployJpdlXmlString(
+      "<process name='Name with spaces'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    ProcessDefinition processDefinition = processService.findLatestProcessDefinitionByKey("Name_with_spaces");
+    assertNotNull(processDefinition);
+    assertEquals("Name with spaces", processDefinition.getName());
+    assertEquals("Name_with_spaces", processDefinition.getKey());
+    assertEquals(1, processDefinition.getVersion());
+    assertEquals("Name_with_spaces:1", processDefinition.getId());
+  }
+
+  public void testFindProcessDefinitions() {
+    deployMultipleVersionsOfProcesses();
+
+    List<ProcessDefinition> processDefinitions = processService.findProcessDefinitionsByKey("nuclear_fusion");
+    assertNotNull(processDefinitions);
+
+    assertEquals("expected 3 but was " + processDefinitions.size() + ": " + processDefinitions, 3, processDefinitions.size());
+    assertEquals("nuclear fusion", processDefinitions.get(0).getName());
+    assertEquals(3, processDefinitions.get(0).getVersion());
+
+    assertEquals("nuclear fusion", processDefinitions.get(1).getName());
+    assertEquals(2, processDefinitions.get(1).getVersion());
+
+    assertEquals("nuclear fusion", processDefinitions.get(2).getName());
+    assertEquals(1, processDefinitions.get(2).getVersion());
+  }
+
+  public void testFindLatestProcessDefinition() {
+    deployMultipleVersionsOfProcesses();
+
+    ProcessDefinition retrieved = processService.findLatestProcessDefinitionByKey("nuclear_fusion");
+    assertNotNull(retrieved);
+
+    assertEquals(3, retrieved.getVersion());
+    assertEquals("nuclear fusion", retrieved.getName());
+    assertEquals("nuclear_fusion", retrieved.getKey());
+  }
+
+  public void testFindProcessDefinitionById() {
+    deployJpdlXmlString(
+      "<process name='given' version='33'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    // load it
+    ProcessDefinition processDefinition = processService.findProcessDefinitionById("given:33");
+    assertNotNull(processDefinition);
+    assertEquals("given", processDefinition.getName());
+    assertEquals(33, processDefinition.getVersion());
+  }
+
+  public void testDeleteProcessDefinition() {
+    processService.createDeployment()
+        .addString("xmlstring.jpdl.xml", 
+            "<process name='deleteme' version='33'>" +
+            "  <start />" +
+            "</process>")
+        .deploy();
+
+    // delete it
+    processService.deleteProcessDefinition("deleteme:33");
+
+    // check if the db is empty
+    assertEquals(0, processService.createProcessDefinitionQuery().execute().size());
+  }
+
+  public void testDeleteProcessDefinitionAndInstances() {
+    processService.createDeployment()
+        .addString("xmlstring.jpdl.xml", 
+          "<process name='deleteme' version='33'>" +
+          "  <start>" +
+          "    <transition to='w' />" +
+          "  </start>" +
+          "  <state name='w' />" +
+          "</process>")
+        .deploy();
+    
+    executionService.startProcessInstanceByKey("deleteme");
+    executionService.startProcessInstanceByKey("deleteme");
+    executionService.startProcessInstanceByKey("deleteme");
+    executionService.startProcessInstanceByKey("deleteme");
+    
+    // delete it all
+    processService.deleteProcessDefinitionCascade("deleteme:33");
+
+    // check if the db is empty
+    assertEquals(0, processService.createProcessDefinitionQuery().execute().size());
+    assertEquals(0, executionService.createExecutionQuery().execute().size());
+  }
+  
+  public void testDeleteProcessDefinitionButNotInstances() {
+    deployJpdlXmlString(
+      "<process name='deleteme' version='33'>" +
+      "  <start>" +
+      "    <transition to='w' />" +
+      "  </start>" +
+      "  <state name='w' />" +
+      "</process>"
+    );
+    
+    executionService.startProcessInstanceByKey("deleteme");
+    executionService.startProcessInstanceByKey("deleteme");
+    executionService.startProcessInstanceByKey("deleteme");
+    executionService.startProcessInstanceByKey("deleteme");
+    
+    // delete it all
+    try {
+      processService.deleteProcessDefinition("deleteme:33");
+      fail("expected exception");
+    } catch (JbpmException e) {
+      assertTextPresent("still 4 process instances for process definition deleteme:33", e.getMessage());
+    }
+  }
+  
+  // various other aspects ////////////////////////////////////////////////////
+  
+  public void testAutomaticVersioning() {
+    deployJpdlXmlString(
+      "<process name='versionme'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    // look it up again
+    List<ProcessDefinition> processDefinitions = processService.findProcessDefinitionsByKey("versionme");
+    assertNotNull(processDefinitions);
+    // verify that there is only one
+    assertEquals(processDefinitions.toString(), 1, processDefinitions.size());
+    ProcessDefinition processDefinition = processDefinitions.get(0);
+    // and check that automatically assigned version starts with 1
+    assertEquals(1, processDefinition.getVersion());
+
+    deployJpdlXmlString(
+      "<process name='versionme'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    // look them up again
+    processDefinitions = processService.findProcessDefinitionsByKey("versionme");
+    // verify that there is only one
+    assertEquals(processDefinitions.toString(), 2, processDefinitions.size());
+    // and check that automatically assigned version starts with 1
+    assertEquals(2, processDefinitions.get(0).getVersion());
+    assertEquals(1, processDefinitions.get(1).getVersion());
+  }
+
+  public void testUserProvidedVersion() {
+    deployJpdlXmlString(
+      "<process name='takethis' version='234'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    // load it
+    List<ProcessDefinition> processDefinitions = processService.findProcessDefinitionsByKey("takethis");
+    assertNotNull(processDefinitions);
+    assertEquals(processDefinitions.toString(), 1, processDefinitions.size());
+    ProcessDefinition processDefinition = processDefinitions.get(0);
+    // verify that the user specified version was used
+    // (and not overwritten by an automatically assigned versioning)
+    assertEquals(234, processDefinition.getVersion());
+  }
+
+  public void testDuplicateUserProvidedVersion()  {
+    deployJpdlXmlString(
+      "<process name='takethis' version='234'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    try {
+      deployJpdlXmlString(
+        "<process name='takethis' version='234'>" +
+        "  <start />" +
+        "</process>"
+      );
+      fail("expected exception");
+    } catch (JbpmException e) {
+      assertTextPresent("process 'takethis:234' already exists", e.getMessage());
+    }
+  }
+
+  /**
+   * deploys 3 versions of process with name 'nuclear fusion', 2 versions of the processes 'ultimate seduction' and
+   * 'publish book'
+   */
+  void deployMultipleVersionsOfProcesses() {
+    deployJpdlXmlString(
+      "<process name='nuclear fusion'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    deployJpdlXmlString(
+      "<process name='ultimate seduction'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    deployJpdlXmlString(
+      "<process name='ultimate seduction'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    deployJpdlXmlString(
+      "<process name='ultimate seduction'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    deployJpdlXmlString(
+      "<process name='ultimate seduction'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    deployJpdlXmlString(
+      "<process name='publish book'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    deployJpdlXmlString(
+      "<process name='nuclear fusion'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    deployJpdlXmlString(
+      "<process name='nuclear fusion'>" +
+      "  <start />" +
+      "</process>"
+    );
+  }
+
+  public void testMinimalProcess() {
+    deployJpdlXmlString(
+      "<process name='minimal'>" +
+      "  <start>" +
+      "    <transition to='end' />" +
+      "  </start>" +
+      "  <end name='end' />" +
+      "</process>"
+    );
+    
+    Execution execution = executionService.startProcessInstanceByKey("minimal");
+    
+    assertEquals("end", execution.getActivityName());
+    assertTrue(execution.isEnded());
+    assertFalse(execution.isActive());
+  }
+
+  public void testMostMinimalProcess() {
+    deployJpdlXmlString(
+      "<process name='minimal'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    Execution execution = executionService.startProcessInstanceByKey("minimal");
+    
+    assertTrue(execution.isEnded());
+    assertFalse(execution.isActive());
+  }
+}

Added: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/SubTaskTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/SubTaskTest.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/SubTaskTest.java	2009-03-04 19:24:25 UTC (rev 4141)
@@ -0,0 +1,167 @@
+/*
+ * 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.test.task;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.jbpm.task.Task;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class SubTaskTest extends JbpmTestCase {
+
+  public void testTaskParticipants() {
+    
+    // create top level task
+    // * clean da house
+    
+    Task task = taskService.newTask();
+    task.setName("clean da house");
+    saveAndRegisterTask(task);
+    long taskDbid = task.getDbid();
+    
+    // create 3 sub tasks: 
+    // * clean da house
+    //   * dishes
+    //   * laundry
+    //   * sweep floor
+    
+    Task subTask = taskService.newTask(taskDbid);
+    subTask.setName("dishes");
+    taskService.saveTask(subTask);
+    long dishesTaskDbid = subTask.getDbid();
+    
+    subTask = taskService.newTask(taskDbid);
+    subTask.setName("laundry");
+    taskService.saveTask(subTask);
+    long laundryTaskDbid = subTask.getDbid();
+    
+    subTask = taskService.newTask(taskDbid);
+    subTask.setName("sweep floor");
+    taskService.saveTask(subTask);
+    long sweepFloorTaskDbid = subTask.getDbid();
+    
+    // verify 3 sub tasks of clean da house
+    
+    List<Task> subTasks = taskService.getSubTasks(taskDbid);
+    Set<String> subTaskNames = getTaskNames(subTasks);
+    
+    Set<String> expectedTaskNames = new HashSet<String>();
+    expectedTaskNames.add("dishes");
+    expectedTaskNames.add("laundry");
+    expectedTaskNames.add("sweep floor");
+    
+    assertEquals(expectedTaskNames, subTaskNames);
+
+    // add 3 sub tasks for sweep floor: 
+    // * clean da house
+    //   * dishes
+    //   * laundry
+    //   * sweep floor
+    //     * find broom
+    //     * find water
+    //     * scrub
+
+    // now second level subtasks under sweep floor
+    subTask = taskService.newTask(sweepFloorTaskDbid);
+    subTask.setName("find broom");
+    taskService.saveTask(subTask);
+
+    subTask = taskService.newTask(sweepFloorTaskDbid);
+    subTask.setName("find water");
+    taskService.saveTask(subTask);
+
+    subTask = taskService.newTask(sweepFloorTaskDbid);
+    subTask.setName("scrub");
+    taskService.saveTask(subTask);
+
+    // verify all the sub tasks of 'clean da house' and 'sweep floor'
+    
+    subTaskNames = getTaskNames(taskService.getSubTasks(taskDbid));
+    
+    expectedTaskNames = new HashSet<String>();
+    expectedTaskNames.add("dishes");
+    expectedTaskNames.add("laundry");
+    expectedTaskNames.add("sweep floor");
+    
+    assertEquals(expectedTaskNames, subTaskNames);
+    
+    subTaskNames = getTaskNames(taskService.getSubTasks(sweepFloorTaskDbid));
+    
+    expectedTaskNames = new HashSet<String>();
+    expectedTaskNames.add("find broom");
+    expectedTaskNames.add("find water");
+    expectedTaskNames.add("scrub");
+    
+    assertEquals(expectedTaskNames, subTaskNames);
+    
+    // delete task dishes
+    taskService.deleteTask(dishesTaskDbid);
+
+    // verify all the sub tasks of 'clean da house' and 'sweep floor'
+    
+    subTaskNames = getTaskNames(taskService.getSubTasks(taskDbid));
+    
+    expectedTaskNames = new HashSet<String>();
+    expectedTaskNames.add("laundry");
+    expectedTaskNames.add("sweep floor");
+    
+    assertEquals(expectedTaskNames, subTaskNames);
+    
+    subTaskNames = getTaskNames(taskService.getSubTasks(sweepFloorTaskDbid));
+    
+    expectedTaskNames = new HashSet<String>();
+    expectedTaskNames.add("find broom");
+    expectedTaskNames.add("find water");
+    expectedTaskNames.add("scrub");
+    
+    assertEquals(expectedTaskNames, subTaskNames);
+
+    // delete laundry and delete sweep floor
+    // NOTE: deleting sweep floor should recursively delete the subtasks
+    taskService.deleteTask(laundryTaskDbid);
+    taskService.deleteTask(sweepFloorTaskDbid);
+
+    subTaskNames = getTaskNames(taskService.getSubTasks(taskDbid));
+
+    expectedTaskNames = new HashSet<String>();
+    assertEquals(expectedTaskNames, subTaskNames);
+    
+    subTaskNames = getTaskNames(taskService.getSubTasks(sweepFloorTaskDbid));
+    
+    expectedTaskNames = new HashSet<String>();
+    assertEquals(expectedTaskNames, subTaskNames);
+  }
+
+  private Set<String> getTaskNames(List<Task> tasks) {
+    Set<String> taskNames = new HashSet<String>();
+    for (Task task: tasks) {
+      taskNames.add(task.getName());
+    }
+    return taskNames;
+  }
+}

Added: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/TaskCommentsTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/TaskCommentsTest.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/TaskCommentsTest.java	2009-03-04 19:24:25 UTC (rev 4141)
@@ -0,0 +1,73 @@
+/*
+ * 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.test.task;
+
+import java.util.List;
+
+import org.jbpm.model.Comment;
+import org.jbpm.task.Task;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class TaskCommentsTest extends JbpmTestCase {
+  
+  public void testComments() {
+    Task task = taskService.newTask();
+    task.setName("clean da house");
+    taskService.saveTask(task);
+    long taskDbid = task.getDbid();
+
+    // what a party yesterday
+    //   - what! you had a party while i was out ?!
+    //      - euh yes.  it was a great party :-)
+    // i'll clean up the mess
+    Comment comment = taskService.addTaskComment(taskDbid, "what a party yesterday");
+    long whatAPartyDbid = comment.getDbid();
+    comment = taskService.addReplyComment(whatAPartyDbid, "what! you had a party while i was out ?!");
+    long youHadAPartyDbid = comment.getDbid();
+    taskService.addReplyComment(youHadAPartyDbid, "euh yes.  it was a great party :-)");
+
+    taskService.addTaskComment(taskDbid, "i'll clean up the mess");
+    
+    List<Comment> taskComments = taskService.getTaskComments(taskDbid);
+    assertEquals("what a party yesterday", taskComments.get(0).getMessage());
+    assertEquals("i'll clean up the mess", taskComments.get(1).getMessage());
+    
+    taskComments = taskComments.get(0).getComments();
+    assertEquals("what! you had a party while i was out ?!", taskComments.get(0).getMessage());
+    
+    taskComments = taskComments.get(0).getComments();
+    assertEquals("euh yes.  it was a great party :-)", taskComments.get(0).getMessage());
+    
+    taskService.deleteComment(whatAPartyDbid);
+
+    taskComments = taskService.getTaskComments(taskDbid);
+    assertEquals("i'll clean up the mess", taskComments.get(0).getMessage());
+    
+    // the following should delete the remaining comment.  if not, this 
+    // will show up as a fixme.
+    taskService.deleteTask(taskDbid);
+  }
+}

Added: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/TaskCreateUpdateDeleteTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/TaskCreateUpdateDeleteTest.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/TaskCreateUpdateDeleteTest.java	2009-03-04 19:24:25 UTC (rev 4141)
@@ -0,0 +1,73 @@
+/*
+ * 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.test.task;
+
+import java.util.Date;
+import java.text.DateFormat;
+
+import org.jbpm.task.Task;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ * @author Alejandro Guizar
+ */
+public class TaskCreateUpdateDeleteTest extends JbpmTestCase {
+
+  public void testNewTask() {
+    // creation of a new non-persisted task
+    Task task = taskService.newTask();
+    task = taskService.getTask(task.getDbid());
+    assertNull(task);
+  }
+
+  public void testSaveTask() {
+    Task task = taskService.newTask();
+    saveAndRegisterTask(task);
+    long taskDbid = task.getDbid();
+    // task was made persistent
+    task = taskService.getTask(taskDbid); 
+    assertNotNull("expected non-null task", task);
+    // make some change
+    Date dueDate = new Date();
+    task.setDueDate(dueDate);
+    taskService.saveTask(task);
+    // verify change is applied
+    task = taskService.getTask(taskDbid);
+    
+    // task.getDueDate() return an java.sql.Timestamp
+    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
+    assertEquals(df.format(dueDate), df.format(task.getDueDate()));
+  }
+
+  public void testDeleteTask() {
+    Task task = taskService.newTask();
+    taskService.saveTask(task);
+    long taskDbid = task.getDbid();
+    
+    // task was made persistent
+    assertNotNull("expected non-null task", taskService.getTask(taskDbid));
+    // delete task and verify it does not exist
+    taskService.deleteTask(taskDbid);
+    task = taskService.getTask(taskDbid);
+    assertNull("expected null, but was " + task, task);
+  }
+}

Added: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/TaskListTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/TaskListTest.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/TaskListTest.java	2009-03-04 19:24:25 UTC (rev 4141)
@@ -0,0 +1,115 @@
+/*
+ * 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.test.task;
+
+import java.util.List;
+
+import org.jbpm.task.Task;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class TaskListTest extends JbpmTestCase {
+
+  public void testPersonalTaskList() {
+    Task task = taskService.newTask();
+    task.setName("do laundry");
+    task.setAssignee("johndoe");
+    saveAndRegisterTask(task);
+
+    task = taskService.newTask();
+    task.setName("get good idea");
+    task.setAssignee("joesmoe");
+    saveAndRegisterTask(task);
+
+    task = taskService.newTask();
+    task.setName("find venture capital");
+    task.setAssignee("joesmoe");
+    saveAndRegisterTask(task);
+    
+    task = taskService.newTask();
+    task.setName("start new business");
+    task.setAssignee("joesmoe");
+    saveAndRegisterTask(task);
+
+    List<Task> taskList = taskService.getPersonalTaskList("johndoe", 0, 10);
+    assertNotNull(taskList);
+    
+    assertEquals("do laundry", taskList.get(0).getName());
+    assertEquals(1, taskList.size());
+
+    taskList = taskService.getPersonalTaskList("joesmoe", 0, 10);
+    assertNotNull(taskList);
+    
+    assertContainsTask(taskList, "get good idea");
+    assertContainsTask(taskList, "start new business");
+    assertContainsTask(taskList, "find venture capital");
+
+    assertEquals(3, taskList.size());
+  }
+
+  public void testPersonalTaskListDefaultSortOrder() {
+    Task task = taskService.newTask();
+    task.setName("get good idea");
+    task.setAssignee("joesmoe");
+    task.setPriority(3);
+    saveAndRegisterTask(task);
+
+    task = taskService.newTask();
+    task.setName("find venture capital");
+    task.setAssignee("joesmoe");
+    task.setPriority(2);
+    saveAndRegisterTask(task);
+    
+    task = taskService.newTask();
+    task.setName("start new business");
+    task.setAssignee("joesmoe");
+    task.setPriority(1);
+    saveAndRegisterTask(task);
+
+    task = taskService.newTask();
+    task.setName("take a day off");
+    task.setAssignee("joesmoe");
+    task.setPriority(-5);
+    saveAndRegisterTask(task);
+
+    task = taskService.newTask();
+    task.setName("make profit");
+    task.setAssignee("joesmoe");
+    task.setPriority(10);
+    saveAndRegisterTask(task);
+
+    List<Task> taskList = taskService.getPersonalTaskList("joesmoe", 0, 10);
+    assertNotNull(taskList);
+    
+    // default sort order is based on the priority
+    assertEquals("make profit",          taskList.get(0).getName());
+    assertEquals("get good idea",        taskList.get(1).getName());
+    assertEquals("find venture capital", taskList.get(2).getName());
+    assertEquals("start new business",   taskList.get(3).getName());
+    assertEquals("take a day off",       taskList.get(4).getName());
+
+    assertEquals(5, taskList.size());
+  }
+}

Added: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/TaskParticipationsTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/TaskParticipationsTest.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/TaskParticipationsTest.java	2009-03-04 19:24:25 UTC (rev 4141)
@@ -0,0 +1,104 @@
+/*
+ * 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.test.task;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.jbpm.task.GroupRef;
+import org.jbpm.task.IdentityRef;
+import org.jbpm.task.Participant;
+import org.jbpm.task.Task;
+import org.jbpm.task.UserRef;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class TaskParticipationsTest extends JbpmTestCase {
+
+  public void testTaskParticipants() {
+    Task task = taskService.newTask();
+    task.setName("do laundry");
+    saveAndRegisterTask(task);
+    
+    long taskDbid = task.getDbid();
+
+    taskService.addTaskParticipant(taskDbid, new UserRef("johndoe"), Participant.CANDIDATE);
+    taskService.addTaskParticipant(taskDbid, new UserRef("joesmoe"), Participant.CANDIDATE);
+    taskService.addTaskParticipant(taskDbid, new UserRef("joesmoe"), Participant.OWNER);
+    taskService.addTaskParticipant(taskDbid, new GroupRef("losers"), Participant.CANDIDATE);
+    taskService.addTaskParticipant(taskDbid, new GroupRef("dummies"), Participant.CANDIDATE);
+    
+    List<Participant> taskParticipants = taskService.getTaskParticipants(taskDbid);
+
+    Set<IdentityRef> candidateIdentityRefs = getIdentityRefs(taskParticipants, Participant.CANDIDATE);
+
+    Set<IdentityRef> expectedIdentityRefs = new HashSet<IdentityRef>();
+    expectedIdentityRefs.add(new UserRef("johndoe"));
+    expectedIdentityRefs.add(new UserRef("joesmoe"));
+    expectedIdentityRefs.add(new GroupRef("losers"));
+    expectedIdentityRefs.add(new GroupRef("dummies"));
+
+    assertEquals(expectedIdentityRefs, candidateIdentityRefs);
+    
+    candidateIdentityRefs = getIdentityRefs(taskParticipants, Participant.OWNER);
+
+    expectedIdentityRefs = new HashSet<IdentityRef>();
+    expectedIdentityRefs.add(new UserRef("joesmoe"));
+
+    assertEquals(expectedIdentityRefs, candidateIdentityRefs);
+    
+    taskService.removeTaskParticipant(taskDbid, new UserRef("joesmoe"), Participant.OWNER);
+    taskService.removeTaskParticipant(taskDbid, new GroupRef("losers"), Participant.CANDIDATE);
+
+    
+    taskParticipants = taskService.getTaskParticipants(taskDbid);
+
+    candidateIdentityRefs = getIdentityRefs(taskParticipants, Participant.CANDIDATE);
+
+    expectedIdentityRefs = new HashSet<IdentityRef>();
+    expectedIdentityRefs.add(new UserRef("johndoe"));
+    expectedIdentityRefs.add(new UserRef("joesmoe"));
+    expectedIdentityRefs.add(new GroupRef("dummies"));
+
+    assertEquals(expectedIdentityRefs, candidateIdentityRefs);
+    
+    candidateIdentityRefs = getIdentityRefs(taskParticipants, Participant.OWNER);
+
+    expectedIdentityRefs = new HashSet<IdentityRef>();
+
+    assertEquals(expectedIdentityRefs, candidateIdentityRefs);
+  }
+
+  public Set<IdentityRef> getIdentityRefs(List<Participant> taskParticipants, String participation) {
+    Set<IdentityRef> identityRefs = new HashSet<IdentityRef>();
+    for (Participant participant: taskParticipants) {
+      if (participation.equals(participant.getParticipation())) {
+        identityRefs.add(participant.getIdentityRef());
+      }
+    }
+    return identityRefs;
+  }
+}

Added: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryTest.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryTest.java	2009-03-04 19:24:25 UTC (rev 4141)
@@ -0,0 +1,111 @@
+/*
+ * 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.test.task;
+
+import java.util.List;
+
+import org.jbpm.TaskQuery;
+import org.jbpm.task.Task;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class TaskQueryTest extends JbpmTestCase {
+
+  public void testSimplestTaskQuery() {
+    Task task = taskService.newTask();
+    task.setName("do laundry");
+    task.setAssignee("johndoe");
+    task.setPriority(3);
+    saveAndRegisterTask(task);
+
+    task = taskService.newTask();
+    task.setName("change dyper");
+    task.setAssignee("johndoe");
+    task.setPriority(1);
+    saveAndRegisterTask(task);
+
+    task = taskService.newTask();
+    task.setName("start new business");
+    task.setAssignee("joesmoe");
+    task.setPriority(4);
+    saveAndRegisterTask(task);
+
+    task = taskService.newTask();
+    task.setName("find venture capital");
+    task.setPriority(4);
+    saveAndRegisterTask(task);
+
+    List<Task> taskList = taskService
+      .createTaskQuery()
+      .execute();
+    assertNotNull(taskList);
+    
+    assertContainsTask(taskList, "do laundry");
+    assertContainsTask(taskList, "change dyper");
+    assertContainsTask(taskList, "start new business");
+    assertContainsTask(taskList, "find venture capital");
+
+    assertEquals(4, taskList.size());
+  }
+
+  public void testSimplestTaskQuerySortBy() {
+    Task task = taskService.newTask();
+    task.setName("do laundry");
+    task.setAssignee("johndoe");
+    task.setPriority(3);
+    saveAndRegisterTask(task);
+
+    task = taskService.newTask();
+    task.setName("change dyper");
+    task.setAssignee("johndoe");
+    task.setPriority(1);
+    saveAndRegisterTask(task);
+
+    task = taskService.newTask();
+    task.setName("start new business");
+    task.setAssignee("joesmoe");
+    task.setPriority(4);
+    saveAndRegisterTask(task);
+
+    task = taskService.newTask();
+    task.setName("find venture capital");
+    task.setPriority(7);
+    saveAndRegisterTask(task);
+
+    List<Task> taskList = taskService
+      .createTaskQuery()
+      .orderAsc(TaskQuery.PROPERTY_NAME)
+      .execute();
+    assertNotNull(taskList);
+    
+    assertEquals("change dyper",         taskList.get(0).getName());
+    assertEquals("do laundry",           taskList.get(1).getName());
+    assertEquals("find venture capital", taskList.get(2).getName());
+    assertEquals("start new business",   taskList.get(3).getName());
+
+    assertEquals(4, taskList.size());
+  }
+
+}

Added: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/variables/BasicVariablesTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/variables/BasicVariablesTest.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/variables/BasicVariablesTest.java	2009-03-04 19:24:25 UTC (rev 4141)
@@ -0,0 +1,116 @@
+/*
+ * 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.test.variables;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class BasicVariablesTest extends JbpmTestCase {
+
+  public void testStartProcessInstanceWithoutVariables() {
+    deployJpdlXmlString(
+      "<process name='var'>" +
+      "  <start name='a'>" +
+      "    <transition to='b' />" +
+      "  </start>" +
+      "  <state name='b'/>" +
+      "</process>"
+    );
+    
+    executionService.startProcessInstanceByKey("var", "one");
+    Set<String> variableNames = executionService.getVariableNames("var/one");
+    assertNotNull(variableNames);
+    assertEquals(0, variableNames.size());
+  }
+
+  public void testStartProcessInstanceWithThreeVariables() {
+    deployJpdlXmlString(
+      "<process name='var'>" +
+      "  <start name='a'>" +
+      "    <transition to='b' />" +
+      "  </start>" +
+      "  <state name='b'/>" +
+      "</process>"
+    );
+    
+    Map<String, Object> variables = new HashMap<String, Object>();
+    variables.put("customer", "John Doe");
+    variables.put("type", "Accident");
+    variables.put("amount", new Float(763.74));
+
+    Set<String> expectedVariableNames = new HashSet<String>(variables.keySet());
+    Map<String, Object> expectedVariables = new HashMap<String, Object>(variables);
+
+    executionService.startProcessInstanceByKey("var", variables, "one");
+    
+    Set<String> variableNames = executionService.getVariableNames("var/one");
+    assertNotNull(variableNames);
+    
+    assertEquals(expectedVariableNames, variableNames);
+
+    variables = executionService.getVariables("var/one", variableNames);
+
+    assertEquals(expectedVariables, variables);
+  }
+
+  public void testSetAndUpdateVariable() {
+    deployJpdlXmlString(
+      "<process name='var'>" +
+      "  <start name='a'>" +
+      "    <transition to='b' />" +
+      "  </start>" +
+      "  <state name='b'/>" +
+      "</process>"
+    );
+    
+    executionService.startProcessInstanceByKey("var", "one");
+    executionService.setVariable("var/one", "msg", "hello");
+    assertEquals("hello", executionService.getVariable("var/one", "msg"));
+    executionService.setVariable("var/one", "msg", "world");
+    assertEquals("world", executionService.getVariable("var/one", "msg"));
+  }
+
+  public void testUpdateVariableToDifferentType() {
+    deployJpdlXmlString(
+      "<process name='var'>" +
+      "  <start name='a'>" +
+      "    <transition to='b' />" +
+      "  </start>" +
+      "  <state name='b'/>" +
+      "</process>"
+    );
+    
+    executionService.startProcessInstanceByKey("var", "one");
+    executionService.setVariable("var/one", "msg", "hello");
+    assertEquals("hello", executionService.getVariable("var/one", "msg"));
+    executionService.setVariable("var/one", "msg", new Integer(5));
+    assertEquals(new Integer(5), executionService.getVariable("var/one", "msg"));
+  }
+}

Added: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/variables/VariableBasicTypesTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/variables/VariableBasicTypesTest.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/variables/VariableBasicTypesTest.java	2009-03-04 19:24:25 UTC (rev 4141)
@@ -0,0 +1,138 @@
+/*
+ * 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.test.variables;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class VariableBasicTypesTest extends JbpmTestCase {
+
+  public void checkVariableValue(Object variableValue) {
+    deployJpdlXmlString(
+      "<process name='var'>" +
+      "  <start name='a'>" +
+      "    <transition to='b' />" +
+      "  </start>" +
+      "  <state name='b'/>" +
+      "</process>"
+    );
+    
+    executionService.startProcessInstanceByKey("var", "one");
+    executionService.setVariable("var/one", "msg", variableValue);
+    assertEquals(variableValue, executionService.getVariable("var/one", "msg"));
+  }
+
+  public void testVariableTypeString() {
+    checkVariableValue("hello");
+  }
+
+  public void testVariableTypeCharacter() {
+    checkVariableValue(new Character('x'));
+  }
+
+  public void testVariableTypeBoolean() {
+    checkVariableValue(Boolean.TRUE);
+  }
+
+  public void testVariableTypeByte() {
+    checkVariableValue(new Byte((byte)5));
+  }
+
+  public void testVariableTypeShort() {
+    checkVariableValue(new Short((short)5));
+  }
+
+  public void testVariableTypeInteger() {
+    checkVariableValue(new Integer(5));
+  }
+
+  public void testVariableTypeLong() {
+    checkVariableValue(new Long(5));
+  }
+
+  public void testVariableTypeFloat() {
+    checkVariableValue(new Float(5.7));
+  }
+
+  public void testVariableTypeDouble() {
+    checkVariableValue(new Double(5.7));
+  }
+
+  public void testVariableTypeDate() {
+    checkVariableValue(new Date());
+  }
+  
+  public static class SerializeMe implements Serializable {
+    private static final long serialVersionUID = 1L;
+    String text;
+    public SerializeMe(String text) {
+      this.text = text;
+    }
+    public int hashCode() {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + ((text == null) ? 0 : text.hashCode());
+      return result;
+    }
+    public boolean equals(Object obj) {
+      if (this == obj)
+        return true;
+      if (obj == null)
+        return false;
+      if (getClass() != obj.getClass())
+        return false;
+      SerializeMe other = (SerializeMe) obj;
+      if (text == null) {
+        if (other.text != null)
+          return false;
+      } else if (!text.equals(other.text))
+        return false;
+      return true;
+    }
+  }
+  
+  public void testVariableTypeSerializable() {
+    SerializeMe originalValue = new SerializeMe(generateString("a lot of text ", 500));
+    checkVariableValue(originalValue);
+    
+    // now check if an update still works ok
+    // updating a serialized object might fail when the blob is cached by hibernate
+    SerializeMe newValue = new SerializeMe(generateString("another text ", 500));
+    executionService.setVariable("var/one", "msg", newValue);
+    assertEquals(newValue, executionService.getVariable("var/one", "msg"));
+  }
+  
+  protected String generateString(String base, int multiplier) {
+    StringBuffer buffer = new StringBuffer();
+    for (int i=0; i<multiplier; i++) {
+      buffer.append(base);
+    }
+    String string = buffer.toString();
+    return string;
+  }
+}




More information about the jbpm-commits mailing list