KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.taskmgmt.def;
2
3 import org.jbpm.db.AbstractDbTestCase;
4 import org.jbpm.graph.def.ProcessDefinition;
5 import org.jbpm.graph.node.TaskNode;
6 import org.jbpm.instantiation.Delegation;
7
8 public class SwimlaneDbTest extends AbstractDbTestCase {
9
10   ProcessDefinition processDefinition = null;
11   TaskMgmtDefinition taskMgmtDefinition = null;
12   Swimlane buyer = null;
13   Task laundry = null;
14   Task dishes = null;
15   
16   public void setUp() {
17     super.setUp();
18     
19     processDefinition = new ProcessDefinition();
20     taskMgmtDefinition = new TaskMgmtDefinition();
21     processDefinition.addDefinition(taskMgmtDefinition);
22     buyer = new Swimlane("buyer");
23     laundry = new Task("laundry");
24     dishes = new Task("dishes");
25   }
26   
27   public void testSwimlaneAddTask() {
28     buyer.addTask(laundry);
29     buyer.addTask(dishes);
30     
31     processDefinition = saveAndReload(processDefinition);
32     taskMgmtDefinition = processDefinition.getTaskMgmtDefinition();
33     
34     assertEquals(2,buyer.getTasks().size());
35     assertTrue(buyer.getTasks().contains(laundry));
36     assertTrue(buyer.getTasks().contains(dishes));
37   }
38
39   public void testSwimlaneAddTaskInverseReference() {
40     buyer.addTask(laundry);
41     buyer.addTask(dishes);
42     
43     processDefinition = saveAndReload(processDefinition);
44     taskMgmtDefinition = processDefinition.getTaskMgmtDefinition();
45     
46     assertSame(buyer, laundry.getSwimlane());
47     assertSame(buyer, dishes.getSwimlane());
48   }
49   
50   public void testTriangularRelation() {
51     buyer.addTask(laundry);
52     taskMgmtDefinition.addTask(laundry);
53     taskMgmtDefinition.addSwimlane(buyer);
54     
55     processDefinition = saveAndReload(processDefinition);
56     taskMgmtDefinition = processDefinition.getTaskMgmtDefinition();
57
58     laundry = taskMgmtDefinition.getTask("laundry");
59     assertEquals(1,taskMgmtDefinition.getTasks().size());
60     assertEquals(1,buyer.getTasks().size());
61     assertEquals("laundry", laundry.getName());
62     assertSame(laundry, taskMgmtDefinition.getSwimlane("buyer").getTasks().iterator().next());
63     assertSame(taskMgmtDefinition, laundry.getTaskMgmtDefinition());
64     assertSame(taskMgmtDefinition.getSwimlane("buyer"), laundry.getSwimlane());
65   }
66   
67   public void testSwimlaneAssignment() {
68     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
69         "<process-definition>" +
70         " <swimlane name='boss'>" +
71         " <assignment class='org.jbpm.TheOneAndOnly' />" +
72         " </swimlane>" +
73         "</process-definition>"
74       );
75     
76     processDefinition = saveAndReload(processDefinition);
77     taskMgmtDefinition = processDefinition.getTaskMgmtDefinition();
78     Swimlane boss = taskMgmtDefinition.getSwimlane("boss");
79     assertNotNull(boss);
80     Delegation bossAssignmentDelegation = boss.getAssignmentDelegation();
81     assertNotNull(bossAssignmentDelegation);
82     String JavaDoc assignmentHandlerClassName = bossAssignmentDelegation.getClassName();
83     assertNotNull(assignmentHandlerClassName);
84     assertEquals("org.jbpm.TheOneAndOnly", assignmentHandlerClassName);
85   }
86
87   public void testSwimlaneTaskMgmtTest() {
88     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
89         "<process-definition>" +
90         " <swimlane name='boss'>" +
91         " <assignment class='org.jbpm.TheOneAndOnly' />" +
92         " </swimlane>" +
93         "</process-definition>"
94       );
95     
96     processDefinition = saveAndReload(processDefinition);
97     taskMgmtDefinition = processDefinition.getTaskMgmtDefinition();
98     Swimlane boss = taskMgmtDefinition.getSwimlane("boss");
99     assertNotNull(boss);
100     assertSame(taskMgmtDefinition, boss.getTaskMgmtDefinition());
101   }
102
103   public void testTaskToSwimlane() {
104     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
105         "<process-definition>" +
106         " <swimlane name='boss'>" +
107         " <assignment class='org.jbpm.TheOneAndOnly' />" +
108         " </swimlane>" +
109         " <task-node name='work'>" +
110         " <task name='manage' swimlane='boss' />" +
111         " </task-node>" +
112         "</process-definition>"
113       );
114     
115     processDefinition = saveAndReload(processDefinition);
116     taskMgmtDefinition = processDefinition.getTaskMgmtDefinition();
117     
118     TaskNode work = (TaskNode) processDefinition.getNode("work");
119     Task manage = work.getTask("manage");
120     assertNotNull(manage);
121     assertSame(taskMgmtDefinition.getTask("manage"), manage);
122     
123     assertNotNull(manage.getSwimlane());
124     assertSame(taskMgmtDefinition.getSwimlane("boss"), manage.getSwimlane());
125   }
126 }
127
Popular Tags