KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > taskmgmt > exe > TaskMgmtInstanceDbTest


1 package org.jbpm.taskmgmt.exe;
2
3 import org.jbpm.db.AbstractDbTestCase;
4 import org.jbpm.graph.def.ProcessDefinition;
5 import org.jbpm.graph.exe.ExecutionContext;
6 import org.jbpm.graph.exe.ProcessInstance;
7 import org.jbpm.taskmgmt.def.AssignmentHandler;
8 import org.jbpm.taskmgmt.def.Swimlane;
9 import org.jbpm.taskmgmt.def.Task;
10 import org.jbpm.taskmgmt.def.TaskMgmtDefinition;
11
12 public class TaskMgmtInstanceDbTest extends AbstractDbTestCase {
13
14   ProcessDefinition processDefinition = null;
15   TaskMgmtDefinition taskMgmtDefinition = null;
16   Swimlane buyer = null;
17   Swimlane seller = null;
18   Task laundry = null;
19   Task dishes = null;
20
21   ProcessInstance processInstance = null;
22   TaskMgmtInstance taskMgmtInstance = null;
23
24   public void setUp() {
25     super.setUp();
26     
27     processDefinition = new ProcessDefinition();
28     taskMgmtDefinition = new TaskMgmtDefinition();
29     processDefinition.addDefinition(taskMgmtDefinition);
30     buyer = new Swimlane("buyer");
31     taskMgmtDefinition.addSwimlane(buyer);
32     seller = new Swimlane("seller");
33     taskMgmtDefinition.addSwimlane(seller);
34     laundry = new Task("laundry");
35     taskMgmtDefinition.addTask(laundry);
36     dishes = new Task("dishes");
37     taskMgmtDefinition.addTask(dishes);
38     
39     graphSession.saveProcessDefinition(processDefinition);
40     
41     processInstance = new ProcessInstance(processDefinition);
42     processInstance = saveAndReload(processInstance);
43     
44     processDefinition = processInstance.getProcessDefinition();
45     taskMgmtDefinition = processDefinition.getTaskMgmtDefinition();
46     buyer = taskMgmtDefinition.getSwimlane("buyer");
47     seller = taskMgmtDefinition.getSwimlane("seller");
48     laundry = taskMgmtDefinition.getTask("laundry");
49     dishes = taskMgmtDefinition.getTask("dishes");
50     taskMgmtInstance = processInstance.getTaskMgmtInstance();
51   }
52
53   public void testTaskMgmtInstanceTaskInstances() {
54     taskMgmtInstance.createTaskInstance(laundry, processInstance.getRootToken());
55     taskMgmtInstance.createTaskInstance(dishes, processInstance.getRootToken());
56     
57     processInstance = saveAndReload(processInstance);
58     taskMgmtInstance = processInstance.getTaskMgmtInstance();
59     assertEquals(2, taskMgmtInstance.getTaskInstances().size());
60   }
61
62   public void testTaskMgmtInstanceSwimlaneInstances() {
63     SwimlaneInstance swimlaneInstance = new SwimlaneInstance(buyer);
64     swimlaneInstance.setActorId("john doe");
65     taskMgmtInstance.addSwimlaneInstance(swimlaneInstance);
66
67     swimlaneInstance = new SwimlaneInstance(seller);
68     swimlaneInstance.setActorId("john smoe");
69     taskMgmtInstance.addSwimlaneInstance(swimlaneInstance);
70     
71     processInstance = saveAndReload(processInstance);
72     
73     taskMgmtInstance = processInstance.getTaskMgmtInstance();
74     assertEquals(2, taskMgmtInstance.getSwimlaneInstances().size());
75   }
76
77   
78   public static class MultipleAssignmentHandler implements AssignmentHandler {
79     private static final long serialVersionUID = 1L;
80     public void assign(Assignable assignable, ExecutionContext executionContext) throws Exception JavaDoc {
81       assignable.setPooledActors(new String JavaDoc[]{"me", "you", "them"});
82     }
83   }
84
85 }
86
Popular Tags