KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > taskmgmt > def > TaskDbTest


1 package org.jbpm.taskmgmt.def;
2
3 import org.jbpm.db.AbstractDbTestCase;
4 import org.jbpm.graph.def.Event;
5 import org.jbpm.graph.def.ExceptionHandler;
6 import org.jbpm.graph.def.ProcessDefinition;
7 import org.jbpm.graph.node.TaskNode;
8
9 public class TaskDbTest extends AbstractDbTestCase {
10
11   public void testTaskName() {
12     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
13       "<process-definition>" +
14       " <task name='wash car' />" +
15       "</process-definition>"
16     );
17     
18     processDefinition = saveAndReload(processDefinition);
19     TaskMgmtDefinition taskMgmtDefinition = processDefinition.getTaskMgmtDefinition();
20     Task task = taskMgmtDefinition.getTask("wash car");
21     assertNotNull(task);
22     assertEquals("wash car", task.getName());
23   }
24   
25   public void testTaskDescription() {
26     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
27       "<process-definition>" +
28       " <task name='wash car' description='wash the car till the paint is all gone' />" +
29       "</process-definition>"
30     );
31     
32     processDefinition = saveAndReload(processDefinition);
33     Task task = processDefinition.getTaskMgmtDefinition().getTask("wash car");
34
35     assertEquals("wash the car till the paint is all gone", task.getDescription());
36   }
37
38   public void testTaskBlocking() {
39     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
40       "<process-definition>" +
41       " <task name='wash car' blocking='true' />" +
42       "</process-definition>"
43     );
44     
45     processDefinition = saveAndReload(processDefinition);
46     Task task = processDefinition.getTaskMgmtDefinition().getTask("wash car");
47
48     assertTrue(task.isBlocking());
49   }
50
51   public void testTaskNode() {
52     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
53       "<process-definition>" +
54       " <task-node name='saturday afternoon'>" +
55       " <task name='wash car' />" +
56       " </task-node>" +
57       "</process-definition>"
58     );
59     
60     processDefinition = saveAndReload(processDefinition);
61     TaskNode taskNode = (TaskNode) processDefinition.getNode("saturday afternoon");
62     Task task = taskNode.getTask("wash car");
63
64     assertNotNull(task.getTaskNode());
65     assertSame(taskNode, task.getTaskNode());
66   }
67
68   public void testTaskMgmtDefinition() {
69     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
70       "<process-definition>" +
71       " <task-node name='saturday afternoon'>" +
72       " <task name='wash car' />" +
73       " </task-node>" +
74       "</process-definition>"
75     );
76     
77     processDefinition = saveAndReload(processDefinition);
78     TaskNode taskNode = (TaskNode) processDefinition.getNode("saturday afternoon");
79     Task task = taskNode.getTask("wash car");
80
81     assertNotNull(task.getTaskMgmtDefinition());
82     assertSame(processDefinition.getTaskMgmtDefinition(), task.getTaskMgmtDefinition());
83   }
84
85   public void testTaskSwimlane() {
86     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
87       "<process-definition>" +
88       " <swimlane name='butler' />" +
89       " <task-node name='saturday afternoon'>" +
90       " <task name='wash car' swimlane='butler' />" +
91       " </task-node>" +
92       "</process-definition>"
93     );
94     
95     processDefinition = saveAndReload(processDefinition);
96     TaskMgmtDefinition taskMgmtDefinition = processDefinition.getTaskMgmtDefinition();
97     Swimlane butler = taskMgmtDefinition.getSwimlane("butler");
98     TaskNode taskNode = (TaskNode) processDefinition.getNode("saturday afternoon");
99     Task task = taskNode.getTask("wash car");
100
101     assertNotNull(task.getSwimlane());
102     assertSame(butler, task.getSwimlane());
103   }
104
105   public void testTaskAssignmentDelegation() {
106     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
107       "<process-definition>" +
108       " <task-node name='saturday afternoon'>" +
109       " <task name='wash car'>" +
110       " <assignment class='the-wash-car-assignment-handler-class-name' />" +
111       " </task>" +
112       " </task-node>" +
113       "</process-definition>"
114     );
115     
116     processDefinition = saveAndReload(processDefinition);
117     TaskNode taskNode = (TaskNode) processDefinition.getNode("saturday afternoon");
118     Task task = taskNode.getTask("wash car");
119
120     assertNotNull(task.getAssignmentDelegation());
121     assertEquals("the-wash-car-assignment-handler-class-name", task.getAssignmentDelegation().getClassName());
122   }
123
124   public void testTaskEvent() {
125     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
126       "<process-definition>" +
127       " <task name='wash car'>" +
128       " <event type='task-create' />" +
129       " </task>" +
130       "</process-definition>"
131     );
132     
133     processDefinition = saveAndReload(processDefinition);
134     Task task = processDefinition.getTaskMgmtDefinition().getTask("wash car");
135     Event event = task.getEvent("task-create");
136     assertNotNull(event);
137     assertSame(task, event.getGraphElement());
138   }
139
140   public void testTaskExceptionHandler() {
141     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
142       "<process-definition>" +
143       " <task name='wash car'>" +
144       " <exception-handler exception-class='TooIntelligentException' />" +
145       " </task>" +
146       "</process-definition>"
147     );
148     
149     processDefinition = saveAndReload(processDefinition);
150     Task task = processDefinition.getTaskMgmtDefinition().getTask("wash car");
151     ExceptionHandler exceptionHandler = (ExceptionHandler) task.getExceptionHandlers().get(0);
152     assertNotNull(exceptionHandler);
153     assertEquals("TooIntelligentException",exceptionHandler.getExceptionClassName());
154     assertSame(task, exceptionHandler.getGraphElement());
155   }
156 }
157
Popular Tags