KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.jpdl.patterns;
2
3 import junit.framework.TestCase;
4
5 import org.jbpm.graph.def.ActionHandler;
6 import org.jbpm.graph.def.ProcessDefinition;
7 import org.jbpm.graph.exe.ExecutionContext;
8 import org.jbpm.graph.exe.ProcessInstance;
9 import org.jbpm.graph.exe.Token;
10 import org.jbpm.taskmgmt.def.Task;
11 import org.jbpm.taskmgmt.def.TaskMgmtDefinition;
12 import org.jbpm.taskmgmt.exe.TaskMgmtInstance;
13
14 /**
15  * http://is.tm.tue.nl/research/patterns/download/swf/pat_12.swf
16  * actually this is a combination of unsynchronized tasks and
17  * runtime calculation of the tasks.
18  */

19 public class Wfp13MiWithoutSynchronizationTest extends TestCase {
20
21   private ProcessDefinition pd = null;
22   private ProcessInstance pi = null;
23
24   private static int scenario = 0;
25
26   public static class CreateTasks implements ActionHandler {
27     private static final long serialVersionUID = 1L;
28     public void execute(ExecutionContext executionContext) throws Exception JavaDoc {
29       // this piece of code is executed at runtime
30
TaskMgmtDefinition taskMgmtDefinition = (TaskMgmtDefinition) executionContext.getDefinition(TaskMgmtDefinition.class);
31       Task task = taskMgmtDefinition.getTask("undress");
32       
33       TaskMgmtInstance tmi = executionContext.getTaskMgmtInstance();
34       for (int i = 1; i<scenario; i++) {
35         tmi.createTaskInstance(task, executionContext.getToken());
36       }
37     }
38   }
39
40   public void setUp() {
41     pd = ProcessDefinition.parseXmlString(
42       "<process-definition>" +
43       " <start-state name='a'>" +
44       " <transition to='b' />" +
45       " </start-state>" +
46       " <node name='b'>" +
47       " <event type='node-enter'>" +
48       " <action class='org.jbpm.jpdl.patterns.Wfp13MiWithoutSynchronizationTest$CreateTasks'/>" +
49       " </event>" +
50       " <transition to='c' />" +
51       " </node>" +
52       " <state name='c' />" +
53       " <task name='undress' />" +
54       "</process-definition>"
55     );
56     
57     pi = new ProcessInstance(pd);
58   }
59   
60   public void testSituation1() {
61     scenario = 1;
62     pi.signal();
63     assertNbrOfTasks(0);
64   }
65
66   public void testSituation2() {
67     scenario = 2;
68     pi.signal();
69     assertNbrOfTasks(1);
70   }
71
72   public void testSituation3() {
73     scenario = 3;
74     pi.signal();
75     assertNbrOfTasks(2);
76   }
77
78   public void testSituation4() {
79     scenario = 4;
80     pi.signal();
81     assertNbrOfTasks(3);
82   }
83
84   private void assertNbrOfTasks(int nbrOfTasks) {
85     TaskMgmtInstance taskMgmtInstance = (TaskMgmtInstance) pi.getInstance(TaskMgmtInstance.class);
86     Token token = pi.getRootToken();
87     
88     assertEquals( nbrOfTasks, taskMgmtInstance.getUnfinishedTasks( token ).size() );
89     assertSame( pd.getNode("c"), token.getNode() );
90   }
91 }
92
Popular Tags