KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > db > TaskMgmtSessionDbTest


1 package org.jbpm.db;
2
3 import java.util.*;
4
5 import org.jbpm.graph.def.*;
6 import org.jbpm.graph.exe.*;
7 import org.jbpm.taskmgmt.def.*;
8 import org.jbpm.taskmgmt.exe.*;
9
10 public class TaskMgmtSessionDbTest extends AbstractDbTestCase {
11
12   ProcessDefinition processDefinition = null;
13   TaskMgmtDefinition taskMgmtDefinition = null;
14   Task laundry = null;
15   Task dishes = null;
16
17   ProcessInstance processInstance = null;
18   TaskMgmtInstance taskMgmtInstance = null;
19
20   public void setUp() {
21     super.setUp();
22     
23     processDefinition = new ProcessDefinition();
24     taskMgmtDefinition = new TaskMgmtDefinition();
25     processDefinition.addDefinition(taskMgmtDefinition);
26     laundry = new Task("laundry");
27     taskMgmtDefinition.addTask(laundry);
28     dishes = new Task("dishes");
29     taskMgmtDefinition.addTask(dishes);
30     
31     graphSession.saveProcessDefinition(processDefinition);
32     
33     processInstance = new ProcessInstance(processDefinition);
34     processInstance = saveAndReload(processInstance);
35     
36     processDefinition = processInstance.getProcessDefinition();
37     taskMgmtDefinition = processDefinition.getTaskMgmtDefinition();
38     laundry = taskMgmtDefinition.getTask("laundry");
39     dishes = taskMgmtDefinition.getTask("dishes");
40     taskMgmtInstance = processInstance.getTaskMgmtInstance();
41   }
42
43   public void testFindTaskInstancesByActorId() {
44     taskMgmtInstance.addTaskInstance(new TaskInstance("laundry", "me"));
45     taskMgmtInstance.addTaskInstance(new TaskInstance("dishes", "me"));
46     taskMgmtInstance.addTaskInstance(new TaskInstance("vacation", "the other guy"));
47     
48     processInstance = saveAndReload(processInstance);
49     
50     List taskInstances = taskMgmtSession.findTaskInstances("me");
51     assertEquals(2, taskInstances.size());
52     TaskInstance taskInstanceOne = (TaskInstance)taskInstances.get(0);
53     TaskInstance taskInstanceTwo = (TaskInstance)taskInstances.get(1);
54     assertEquals("me", taskInstanceOne.getActorId());
55     assertEquals("me", taskInstanceTwo.getActorId());
56     assertNotSame(taskInstanceOne, taskInstanceTwo);
57   }
58
59   public void testFindTaskInstancesByActorIds() {
60     taskMgmtInstance.addTaskInstance(new TaskInstance("laundry", "me"));
61     taskMgmtInstance.addTaskInstance(new TaskInstance("dishes", "me"));
62     taskMgmtInstance.addTaskInstance(new TaskInstance("write software", "me"));
63     taskMgmtInstance.addTaskInstance(new TaskInstance("vacation", "the other guy"));
64     taskMgmtInstance.addTaskInstance(new TaskInstance("try", "a nobody"));
65     taskMgmtInstance.addTaskInstance(new TaskInstance("pretend", "a nobody"));
66     
67     processInstance = saveAndReload(processInstance);
68     
69     List taskInstances = taskMgmtSession.findTaskInstances(new String JavaDoc[]{"me", "the other guy"});
70     assertEquals(4, taskInstances.size());
71   }
72
73   public void testLoadTaskInstance() {
74     TaskInstance taskInstance = new TaskInstance("laundry", "me");
75     taskMgmtInstance.addTaskInstance(taskInstance);
76     
77     processInstance = saveAndReload(processInstance);
78     
79     taskInstance = taskMgmtSession.loadTaskInstance(taskInstance.getId());
80     assertNotNull(taskInstance);
81   }
82 }
83
Popular Tags