KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.jpdl.xml;
2
3 import java.util.List JavaDoc;
4
5 import junit.framework.TestCase;
6
7 import org.jbpm.context.def.VariableAccess;
8 import org.jbpm.graph.def.ProcessDefinition;
9 import org.jbpm.graph.node.TaskNode;
10 import org.jbpm.instantiation.Delegation;
11 import org.jbpm.taskmgmt.def.Task;
12 import org.jbpm.taskmgmt.def.TaskController;
13
14 public class TaskControllerXmlTest extends TestCase {
15
16   public void testTaskControllerWithVariableAccesses() {
17     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
18       "<process-definition>" +
19       " <task-node name='t'>" +
20       " <task name='clean ceiling'>" +
21       " <controller>" +
22       " <variable name='a' access='read,write' mapped-name='x' />" +
23       " <variable name='b' access='read,write' mapped-name='y' />" +
24       " <variable name='c' access='read,write' />" +
25       " </controller>" +
26       " </task>" +
27       " </task-node>" +
28       "</process-definition>"
29     );
30     TaskNode taskNode = (TaskNode) processDefinition.getNode("t");
31     Task task = taskNode.getTask("clean ceiling");
32     TaskController taskController = task.getTaskController();
33     assertNotNull(taskController);
34     assertNull(taskController.getTaskControllerDelegation());
35     List JavaDoc variableAccesses = taskController.getVariableAccesses();
36     assertNotNull(variableAccesses);
37     assertEquals(3, variableAccesses.size());
38     VariableAccess variableAccess = (VariableAccess) variableAccesses.get(0);
39     assertNotNull(variableAccesses);
40     assertEquals("a", variableAccess.getVariableName());
41     assertEquals("read,write", variableAccess.getAccess());
42     assertEquals("x", variableAccess.getMappedName());
43     variableAccess = (VariableAccess) variableAccesses.get(2);
44     assertNotNull(variableAccesses);
45     assertEquals("c", variableAccess.getMappedName());
46   }
47   
48   public void testTaskControllerWithDelegation() {
49     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
50       "<process-definition>" +
51       " <task-node name='t'>" +
52       " <task name='clean ceiling'>" +
53       " <controller class='my-own-task-controller-handler-class'>" +
54       " --here comes the configuration of the task controller handler--" +
55       " </controller>" +
56       " </task>" +
57       " </task-node>" +
58       "</process-definition>"
59     );
60     TaskNode taskNode = (TaskNode) processDefinition.getNode("t");
61     Task task = taskNode.getTask("clean ceiling");
62     TaskController taskController = task.getTaskController();
63     assertNull(taskController.getVariableAccesses());
64     Delegation taskControllerDelegation = taskController.getTaskControllerDelegation();
65     assertNotNull(taskControllerDelegation);
66     assertEquals("my-own-task-controller-handler-class", taskControllerDelegation.getClassName());
67   }
68   
69   public void testStartTaskController() {
70     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
71       "<process-definition>" +
72       " <start-state name='t'>" +
73       " <task name='task to start this process'>" +
74       " <controller />" +
75       " </task>" +
76       " </start-state>" +
77       "</process-definition>"
78     );
79     Task task = processDefinition.getTaskMgmtDefinition().getStartTask();
80     assertNotNull(task.getTaskController());
81   }
82   
83 }
84
Popular Tags