1 package org.jbpm.taskmgmt.def; 2 3 import java.util.List ; 4 5 import org.jbpm.context.def.VariableAccess; 6 import org.jbpm.db.AbstractDbTestCase; 7 import org.jbpm.graph.def.ProcessDefinition; 8 import org.jbpm.graph.node.TaskNode; 9 import org.jbpm.instantiation.Delegation; 10 11 public class TaskControllerDbTest extends AbstractDbTestCase { 12 13 public void testTaskControllerWithVariableAccesses() { 14 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 15 "<process-definition>" + 16 " <task-node name='t'>" + 17 " <task name='clean ceiling'>" + 18 " <controller>" + 19 " <variable name='a' access='read,write' mapped-name='x' />" + 20 " <variable name='b' access='read,write' mapped-name='y' />" + 21 " <variable name='c' access='read,write' />" + 22 " </controller>" + 23 " </task>" + 24 " </task-node>" + 25 "</process-definition>" 26 ); 27 28 processDefinition = saveAndReload(processDefinition); 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 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 61 processDefinition = saveAndReload(processDefinition); 62 63 TaskNode taskNode = (TaskNode) processDefinition.getNode("t"); 64 Task task = taskNode.getTask("clean ceiling"); 65 TaskController taskController = task.getTaskController(); 66 assertTrue( (taskController.getVariableAccesses()==null) 67 || (taskController.getVariableAccesses().isEmpty()) ); 68 Delegation taskControllerDelegation = taskController.getTaskControllerDelegation(); 69 assertNotNull(taskControllerDelegation); 70 assertEquals("my-own-task-controller-handler-class", taskControllerDelegation.getClassName()); 71 } 72 73 public void testStartTaskController() { 74 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 75 "<process-definition>" + 76 " <start-state name='t'>" + 77 " <task name='task to start this process'>" + 78 " <controller />" + 79 " </task>" + 80 " </start-state>" + 81 "</process-definition>" 82 ); 83 84 processDefinition = saveAndReload(processDefinition); 85 86 Task task = processDefinition.getTaskMgmtDefinition().getStartTask(); 87 assertNotNull(task.getTaskController()); 88 } 89 } 90 | Popular Tags |