KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.db;
2
3 import org.jbpm.graph.def.ActionHandler;
4 import org.jbpm.graph.def.ProcessDefinition;
5 import org.jbpm.graph.exe.ExecutionContext;
6 import org.jbpm.graph.exe.ProcessInstance;
7
8 public class IdAssignmentDbTest extends AbstractDbTestCase {
9   
10   static int successfullInvocations = 0;
11   
12   public void setUp() {
13     super.setUp();
14     successfullInvocations = 0;
15   }
16   
17   public static class TaskInstanceIdVerifier implements ActionHandler {
18     private static final long serialVersionUID = 1L;
19     public void execute(ExecutionContext executionContext) throws Exception JavaDoc {
20       if (executionContext.getTaskInstance().getId()==0) {
21         throw new RuntimeException JavaDoc("task instance didn't have an id");
22       }
23       successfullInvocations++;
24     }
25   }
26
27   public void testTaskInstanceId() {
28     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
29       "<process-definition>" +
30       " <event type='task-create'>" +
31       " <action class='org.jbpm.db.IdAssignmentDbTest$TaskInstanceIdVerifier' />" +
32       " </event>" +
33       " <start-state>" +
34       " <transition to='distribute work' />" +
35       " </start-state>" +
36       " <task-node name='distribute work'>" +
37       " <task name='negotiate a rebate' />" +
38       " </task-node>" +
39       "</process-definition>"
40     );
41     
42     processDefinition = saveAndReload(processDefinition);
43     
44     ProcessInstance processInstance = new ProcessInstance(processDefinition);
45     processInstance.signal();
46     jbpmSession.getGraphSession().saveProcessInstance(processInstance);
47     
48     assertEquals(1, successfullInvocations);
49   }
50
51   public static class ProcessInstanceIdVerifier implements ActionHandler {
52     private static final long serialVersionUID = 1L;
53     public void execute(ExecutionContext executionContext) throws Exception JavaDoc {
54       if (executionContext.getProcessInstance().getId()==0) {
55         throw new RuntimeException JavaDoc("process instance didn't have an id");
56       }
57       successfullInvocations++;
58     }
59   }
60
61   public void testProcessInstanceId() {
62     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
63       "<process-definition>" +
64       " <event type='process-start'>" +
65       " <action class='org.jbpm.db.IdAssignmentDbTest$ProcessInstanceIdVerifier' />" +
66       " </event>" +
67       " <start-state>" +
68       " <transition to='a' />" +
69       " </start-state>" +
70       " <state name='a' />" +
71       "</process-definition>"
72     );
73     
74     processDefinition = saveAndReload(processDefinition);
75     
76     ProcessInstance processInstance = new ProcessInstance(processDefinition);
77     processInstance.signal();
78     jbpmSession.getGraphSession().saveProcessInstance(processInstance);
79     
80     assertEquals(1, successfullInvocations);
81   }
82
83   public static class TokenIdVerifier implements ActionHandler {
84     private static final long serialVersionUID = 1L;
85     public void execute(ExecutionContext executionContext) throws Exception JavaDoc {
86       if (executionContext.getToken().getId()==0) {
87         throw new RuntimeException JavaDoc("token '"+executionContext.getToken()+"' didn't have an id");
88       }
89       successfullInvocations++;
90     }
91   }
92
93   public void testTokenId() {
94     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
95       "<process-definition>" +
96       " <start-state>" +
97       " <transition to='f' />" +
98       " </start-state>" +
99       " <fork name='f'>" +
100       " <transition name='a' to='a' />" +
101       " <transition name='b' to='b' />" +
102       " <event type='node-leave'>" +
103       " <action class='org.jbpm.db.IdAssignmentDbTest$TokenIdVerifier' />" +
104       " </event>" +
105       " </fork>" +
106       " <state name='a' />" +
107       " <state name='b' />" +
108       "</process-definition>"
109     );
110     
111     processDefinition = saveAndReload(processDefinition);
112     
113     ProcessInstance processInstance = new ProcessInstance(processDefinition);
114     processInstance.signal();
115     jbpmSession.getGraphSession().saveProcessInstance(processInstance);
116     
117     assertEquals(2, successfullInvocations);
118   }
119 }
120
Popular Tags