KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > jpdl > xml > TaskNodeXmlTest


1 package org.jbpm.jpdl.xml;
2
3 import junit.framework.TestCase;
4
5 import org.jbpm.graph.def.Event;
6 import org.jbpm.graph.def.ProcessDefinition;
7 import org.jbpm.graph.node.TaskNode;
8 import org.jbpm.scheduler.def.CancelTimerAction;
9 import org.jbpm.scheduler.def.CreateTimerAction;
10 import org.jbpm.taskmgmt.def.Swimlane;
11 import org.jbpm.taskmgmt.def.Task;
12 import org.jbpm.taskmgmt.def.TaskMgmtDefinition;
13
14 public class TaskNodeXmlTest extends TestCase {
15   
16   public void testTaskNodeName() {
17     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
18       "<process-definition>" +
19       " <task-node name='t'>" +
20       " </task-node>" +
21       "</process-definition>"
22     );
23     TaskNode taskNode = (TaskNode) processDefinition.getNode("t");
24     assertNotNull(taskNode);
25     assertEquals("t", taskNode.getName());
26   }
27   
28   public void testTaskNodeTasks() {
29     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
30       "<process-definition>" +
31       " <task-node name='t'>" +
32       " <task name='one' />" +
33       " <task name='two' />" +
34       " <task name='three' />" +
35       " </task-node>" +
36       "</process-definition>");
37     TaskNode taskNode = (TaskNode) processDefinition.getNode("t");
38     assertNotNull(taskNode);
39     assertEquals(3, taskNode.getTasks().size());
40   }
41
42   public void testTaskNodeDefaultSignal() {
43     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
44       "<process-definition>" +
45       " <task-node name='t' />" +
46       "</process-definition>"
47     );
48     TaskNode taskNode = (TaskNode) processDefinition.getNode("t");
49     assertEquals(TaskNode.SIGNAL_LAST, taskNode.getSignal());
50   }
51
52   public void testTaskNodeSignalFirst() {
53     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
54       "<process-definition>" +
55       " <task-node name='t' signal='first' />" +
56       "</process-definition>"
57     );
58     TaskNode taskNode = (TaskNode) processDefinition.getNode("t");
59     assertEquals(TaskNode.SIGNAL_FIRST, taskNode.getSignal());
60   }
61
62   public void testTaskNodeDefaultCreate() {
63     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
64       "<process-definition>" +
65       " <task-node name='t' />" +
66       "</process-definition>"
67     );
68     TaskNode taskNode = (TaskNode) processDefinition.getNode("t");
69     assertTrue(taskNode.getCreateTasks());
70   }
71
72   public void testTaskNodeNoCreate() {
73     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
74       "<process-definition>" +
75       " <task-node name='t' create-tasks='false'/>" +
76       "</process-definition>"
77     );
78     TaskNode taskNode = (TaskNode) processDefinition.getNode("t");
79     assertFalse(taskNode.getCreateTasks());
80   }
81
82   public void testSwimlane() {
83     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
84       "<process-definition>" +
85       " <swimlane name='initiator'>" +
86       " <assignment class='assignment-specified-just-to-prevent-a-warning'/>" +
87       " </swimlane>" +
88       "</process-definition>"
89     );
90     TaskMgmtDefinition taskMgmtDefinition = processDefinition.getTaskMgmtDefinition();
91     Swimlane initiatorSwimlane = taskMgmtDefinition.getSwimlane("initiator");
92     assertNotNull(initiatorSwimlane);
93     assertEquals("initiator", initiatorSwimlane.getName());
94   }
95
96   public void testTaskSwimlane() {
97     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
98       "<process-definition>" +
99       " <swimlane name='initiator'>" +
100       " <assignment class='assignment-specified-just-to-prevent-a-warning'/>" +
101       " </swimlane>" +
102       " <task name='grow old' swimlane='initiator' />" +
103       "</process-definition>"
104     );
105     Task growOld = processDefinition.getTaskMgmtDefinition().getTask("grow old");
106     assertNotNull(growOld);
107     assertNotNull(growOld.getSwimlane());
108     assertEquals("initiator", growOld.getSwimlane().getName());
109   }
110
111   
112   public void testTaskCreationEvent() {
113     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
114       "<process-definition>" +
115       " <task-node name='a'>" +
116       " <task name='clean ceiling'>" +
117       " <event type='task-create'>" +
118       " <action class='org.jbpm.taskmgmt.exe.TaskEventTest$PlusPlus' />" +
119       " </event>" +
120       " </task>" +
121       " </task-node>" +
122       "</process-definition>"
123     );
124     TaskNode taskNode = (TaskNode) processDefinition.getNode("a");
125     Task task = taskNode.getTask("clean ceiling");
126     assertNotNull( task.getEvent(Event.EVENTTYPE_TASK_CREATE) );
127   }
128
129   public void testTaskStartEvent() {
130     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
131       "<process-definition>" +
132       " <task-node name='a'>" +
133       " <task name='clean ceiling'>" +
134       " <event type='task-start'>" +
135       " <action class='org.jbpm.taskmgmt.exe.TaskEventTest$PlusPlus' />" +
136       " </event>" +
137       " </task>" +
138       " </task-node>" +
139       "</process-definition>"
140     );
141     TaskNode taskNode = (TaskNode) processDefinition.getNode("a");
142     Task task = taskNode.getTask("clean ceiling");
143     assertNotNull( task.getEvent(Event.EVENTTYPE_TASK_START) );
144   }
145
146   public void testTaskAssignEvent() {
147     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
148       "<process-definition>" +
149       " <task-node name='a'>" +
150       " <task name='clean ceiling'>" +
151       " <event type='task-assign'>" +
152       " <action class='org.jbpm.taskmgmt.exe.TaskEventTest$PlusPlus' />" +
153       " </event>" +
154       " </task>" +
155       " </task-node>" +
156       "</process-definition>"
157     );
158     TaskNode taskNode = (TaskNode) processDefinition.getNode("a");
159     Task task = taskNode.getTask("clean ceiling");
160     assertNotNull( task.getEvent(Event.EVENTTYPE_TASK_ASSIGN) );
161   }
162
163   public void testTaskEndEvent() {
164     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
165       "<process-definition>" +
166       " <task-node name='a'>" +
167       " <task name='clean ceiling'>" +
168       " <event type='task-end'>" +
169       " <action class='org.jbpm.taskmgmt.exe.TaskEventTest$PlusPlus' />" +
170       " </event>" +
171       " </task>" +
172       " </task-node>" +
173       "</process-definition>"
174     );
175     TaskNode taskNode = (TaskNode) processDefinition.getNode("a");
176     Task task = taskNode.getTask("clean ceiling");
177     assertNotNull( task.getEvent(Event.EVENTTYPE_TASK_END) );
178   }
179
180   public void testTaskTimer() {
181     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
182       "<process-definition>" +
183       " <task-node name='a'>" +
184       " <task name='clean ceiling'>" +
185       " <timer duedate='2 business minutes'>" +
186       " <action class='org.jbpm.taskmgmt.exe.TaskEventTest$PlusPlus' />" +
187       " </timer>" +
188       " </task>" +
189       " </task-node>" +
190       "</process-definition>"
191     );
192     TaskNode taskNode = (TaskNode) processDefinition.getNode("a");
193     Task task = taskNode.getTask("clean ceiling");
194     Event event = task.getEvent(Event.EVENTTYPE_TASK_CREATE);
195     assertNotNull(event);
196     CreateTimerAction createTimerAction = (CreateTimerAction) event.getActions().get(0);
197     assertNotNull(createTimerAction);
198     assertEquals("2 business minutes", createTimerAction.getDueDate());
199
200     // test default cancel event
201
event = task.getEvent(Event.EVENTTYPE_TASK_END);
202     assertNotNull(event);
203     CancelTimerAction cancelTimerAction = (CancelTimerAction) event.getActions().get(0);
204     assertNotNull(cancelTimerAction);
205   }
206
207   public void testTaskTimerCancelEvents() {
208     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
209       "<process-definition>" +
210       " <task-node name='a'>" +
211       " <task name='clean ceiling'>" +
212       " <timer duedate='2 business minutes' cancel-event='task-start, task-assign, task-end'>" +
213       " <action class='org.jbpm.taskmgmt.exe.TaskEventTest$PlusPlus' />" +
214       " </timer>" +
215       " </task>" +
216       " </task-node>" +
217       "</process-definition>"
218     );
219     TaskNode taskNode = (TaskNode) processDefinition.getNode("a");
220     Task task = taskNode.getTask("clean ceiling");
221     Event event = task.getEvent(Event.EVENTTYPE_TASK_CREATE);
222     assertNotNull(event);
223     assertSame(CreateTimerAction.class, event.getActions().get(0).getClass());
224
225     event = task.getEvent(Event.EVENTTYPE_TASK_START);
226     assertNotNull(event);
227     assertSame(CancelTimerAction.class, event.getActions().get(0).getClass());
228
229     event = task.getEvent(Event.EVENTTYPE_TASK_ASSIGN);
230     assertNotNull(event);
231     assertSame(CancelTimerAction.class, event.getActions().get(0).getClass());
232
233     event = task.getEvent(Event.EVENTTYPE_TASK_END);
234     assertNotNull(event);
235     assertSame(CancelTimerAction.class, event.getActions().get(0).getClass());
236   }
237
238 }
239
Popular Tags