KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > jpdl > patterns > Wfp14MiWithAPrioriDesigntimeKnowledgeTest


1 package org.jbpm.jpdl.patterns;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5
6 import junit.framework.TestCase;
7
8 import org.jbpm.graph.def.ProcessDefinition;
9 import org.jbpm.graph.exe.ProcessInstance;
10 import org.jbpm.graph.exe.Token;
11 import org.jbpm.taskmgmt.exe.TaskInstance;
12 import org.jbpm.taskmgmt.exe.TaskMgmtInstance;
13
14 /**
15  * http://is.tm.tue.nl/research/patterns/download/swf/pat_13.swf
16  */

17 public class Wfp14MiWithAPrioriDesigntimeKnowledgeTest extends TestCase {
18
19   public void testSituation1() {
20     ProcessDefinition pd = ProcessDefinition.parseXmlString(
21       "<process-definition name='the life of a baby ?'>" +
22       " <start-state name='a'>" +
23       " <transition to='b' />" +
24       " </start-state>" +
25       " <state name='b'>" +
26       " <transition to='t' />" +
27       " </state>" +
28       " <task-node name='t'>" +
29       " <task name='eat' />" +
30       " <task name='drink' />" +
31       " <task name='sleep' />" +
32       " <transition to='c' />" +
33       " </task-node>" +
34       " <state name='c' />" +
35       "</process-definition>"
36     );
37
38     ProcessInstance pi = new ProcessInstance( pd );
39     TaskMgmtInstance taskMgmtInstance = (TaskMgmtInstance) pi.getInstance(TaskMgmtInstance.class);
40     
41     pi.signal();
42     Token token = pi.getRootToken();
43
44     // after start, the token is waiting in state b
45
assertSame( pd.getNode("b"), token.getNode() );
46     
47     // and no tasks have been created yet
48
assertEquals(0, taskMgmtInstance.getUnfinishedTasks(token).size() );
49
50     // now we signal the process to move on.
51
// execution will arrive at the task-node
52
// the default behaviour of the task node is to create each task and wait till the last one finishes
53
pi.signal();
54
55     // now, 3 tasks have been created...
56
List JavaDoc tasks = new ArrayList JavaDoc( taskMgmtInstance.getUnfinishedTasks(token) );
57     assertEquals(3, tasks.size());
58     // ... and the process is in the task state
59
assertSame( pd.getNode("t"), token.getNode() );
60
61     // now we finish the tasks one by one
62
// finish task 0
63
((TaskInstance)tasks.get(0)).end();
64     
65     // still 2 tasks remaining
66
assertEquals(2, taskMgmtInstance.getUnfinishedTasks(token).size() );
67     // and the process is still in node t
68
assertSame( pd.getNode("t"), token.getNode() );
69     
70     // finish task 1
71
((TaskInstance)tasks.get(1)).end();
72     
73     // still 1 task remaining
74
assertEquals(1, taskMgmtInstance.getUnfinishedTasks(token).size() );
75     // and the process is still in node t
76
assertSame( pd.getNode("t"), token.getNode() );
77     
78     // finish task 2
79
((TaskInstance)tasks.get(2)).end();
80     
81     // no more tasks remaining
82
assertEquals(0, taskMgmtInstance.getUnfinishedTasks(token).size() );
83     // and the process has moved to node c
84
assertEquals( pd.getNode("c"), token.getNode() );
85   }
86 }
87
Popular Tags