[jbpm-commits] JBoss JBPM SVN: r6425 - jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task.

do-not-reply at jboss.org do-not-reply at jboss.org
Sat Jun 19 03:26:55 EDT 2010


Author: rebody
Date: 2010-06-19 03:26:54 -0400 (Sat, 19 Jun 2010)
New Revision: 6425

Modified:
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/AssignmentHandlerTest.java
Log:
JBPM-2758 don't re-build process engine in AutoAssignmentHandler. This could prevent the different session error.

Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/AssignmentHandlerTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/AssignmentHandlerTest.java	2010-06-18 01:27:36 UTC (rev 6424)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/AssignmentHandlerTest.java	2010-06-19 07:26:54 UTC (rev 6425)
@@ -1,10 +1,10 @@
 package org.jbpm.test.task;
- 
+
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
- 
+
 import org.jbpm.api.Configuration;
 import org.jbpm.api.ProcessEngine;
 import org.jbpm.api.ProcessInstance;
@@ -14,20 +14,21 @@
 import org.jbpm.api.task.AssignmentHandler;
 import org.jbpm.api.task.Participation;
 import org.jbpm.api.task.Task;
+import org.jbpm.pvm.internal.env.EnvironmentImpl;
 import org.jbpm.test.JbpmTestCase;
- 
+
 public class AssignmentHandlerTest extends JbpmTestCase {
- 
+
     /** Deployment id. */
     String deploymentId;
- 
+
     /**
      * Set up.
      * @throws Exception exception
      */
     protected void setUp() throws Exception {
         super.setUp();
- 
+
         // XML definition
         StringBuilder jpdl = new StringBuilder();
         jpdl.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
@@ -56,13 +57,13 @@
         jpdl.append("    <transition g=\"-44,-18\" name=\"to task3\" to=\"task3\"/>");
         jpdl.append("  </join>");
         jpdl.append("</process>");
- 
+
         // Deploys the process
-        deploymentId =
-                repositoryService.createDeployment().addResourceFromString("testProcess.jpdl.xml", jpdl.toString())
-                        .deploy();
+        deploymentId = repositoryService.createDeployment()
+                                        .addResourceFromString("testProcess.jpdl.xml", jpdl.toString())
+                                        .deploy();
     }
- 
+
     /**
      * Tear down.
      * @throws Exception exception
@@ -71,47 +72,47 @@
         repositoryService.deleteDeploymentCascade(deploymentId);
         super.tearDown();
     }
- 
+
     /**
      * Tests the process.
      */
     public void testProcess() {
- 
+
         // Starts a new process instance and gets the instance id
         ProcessInstance processInstance = executionService.startProcessInstanceByKey("testProcess");
         String pid = processInstance.getId();
- 
+
         // Gets the tasks auto-assigned for the first user and completes the task
-        List < Task > taskList = taskService.findPersonalTasks("firstUser");
+        List <Task> taskList = taskService.findPersonalTasks("firstUser");
         assertEquals(1, taskList.size());
         Task task = taskList.get(0);
         taskService.completeTask(task.getId());
- 
+
         // Gets the tasks auto-assigned for the second user and completes the task
         taskList = taskService.findPersonalTasks("secondUser");
         assertEquals(1, taskList.size());
         task = taskList.get(0);
         taskService.completeTask(task.getId());
- 
+
         // Gets the tasks auto-assigned for the second user and completes the task
         taskList = taskService.findPersonalTasks("thirdUser");
         assertEquals(1, taskList.size());
         task = taskList.get(0);
         taskService.completeTask(task.getId());
- 
+
         // Tries to load the instance and checks if it was finished
         processInstance = executionService.findProcessInstanceById(pid);
         assertNull(processInstance);
     }
- 
+
     /**
      * Auto assignment class.
      */
     public static class AutoAssignment implements AssignmentHandler {
- 
+
         /** Serial version ID. */
         private static final long serialVersionUID = 9063679883107908899L;
- 
+
         /**
          * Auto-claim the task to the default user.
          * @param assignable assignable object
@@ -119,38 +120,37 @@
          * @throws Exception exception
          */
         public void assign(Assignable assignable, OpenExecution execution) throws Exception {
- 
+
             // Default users (group --> user mapping)
-            Map < String, String > defaultUsers = new HashMap < String, String >();
+            Map <String, String> defaultUsers = new HashMap <String, String>();
             defaultUsers.put("firstGroup", "firstUser");
             defaultUsers.put("secondGroup", "secondUser");
             defaultUsers.put("thirdGroup", "thirdUser");
- 
+
             // Engine and task service
-            ProcessEngine processEngine = new Configuration().buildProcessEngine();
-            TaskService taskService = processEngine.getTaskService();
- 
+            TaskService taskService = EnvironmentImpl.getFromCurrent(TaskService.class);
+
             // Loads the active activities
-            Set < String > activities = execution.findActiveActivityNames();
- 
+            Set <String> activities = execution.findActiveActivityNames();
+
             // Iterates the activities
             for (String activity : activities) {
- 
+
                 // Loads the tasks according to the process instance and activity name
-                List < Task > tasks =
+                List <Task> tasks =
                         taskService.createTaskQuery().activityName(activity).processInstanceId(
                             execution.getProcessInstance().getId()).list();
- 
+
                 // Iterates the tasks
                 for (Task task : tasks) {
- 
+
                     // Compares the task name to the activity name
                     // If the task name matches the activity name, loads the candidate-group and assigns the default user
                     if (task.getName().equals(activity)) {
- 
+
                         // Loads the tasks candidate groups (in our process we have just one group)
-                        List < Participation > groups = taskService.getTaskParticipations(task.getId());
- 
+                        List <Participation> groups = taskService.getTaskParticipations(task.getId());
+
                         // If the groups collection is not empty, loads the default user and sets in the task
                         if (!groups.isEmpty()) {
                             assignable.setAssignee(defaultUsers.get(groups.get(0).getGroupId()));



More information about the jbpm-commits mailing list