1 package org.jbpm.taskmgmt.exe; 2 3 import java.util.Iterator ; 4 5 import junit.framework.TestCase; 6 7 import org.jbpm.graph.def.ActionHandler; 8 import org.jbpm.graph.def.ProcessDefinition; 9 import org.jbpm.graph.exe.ExecutionContext; 10 import org.jbpm.graph.exe.ProcessInstance; 11 import org.jbpm.graph.exe.Token; 12 import org.jbpm.graph.node.TaskNode; 13 import org.jbpm.taskmgmt.def.Task; 14 15 public class RuntimeTaskCreationTest extends TestCase { 16 17 public static class CreateTasks implements ActionHandler { 18 private static final long serialVersionUID = 1L; 19 public void execute(ExecutionContext executionContext) throws Exception { 20 Token token = executionContext.getToken(); 21 TaskMgmtInstance tmi = executionContext.getTaskMgmtInstance(); 22 23 TaskNode taskNode = (TaskNode) executionContext.getNode(); 24 Task changeNappy = taskNode.getTask("change nappy"); 25 26 tmi.createTaskInstance(changeNappy, token); 28 tmi.createTaskInstance(changeNappy, token); 29 } 30 } 31 32 public void testRuntimeTaskCreation() { 33 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 34 "<process-definition>" + 35 " <start-state>" + 36 " <transition to='a' />" + 37 " </start-state>" + 38 " <task-node name='a' create-tasks='false'>" + 39 " <event type='node-enter'>" + 40 " <action class='org.jbpm.taskmgmt.exe.RuntimeTaskCreationTest$CreateTasks' />" + 41 " </event>" + 42 " <task name='change nappy' />'" + 43 " <task name='make bottle' />'" + 44 " <task name='do dishes' />'" + 45 " <transition to='b' />" + 46 " </task-node>" + 47 " <state name='b' />" + 48 "</process-definition>" 49 ); 50 51 ProcessInstance processInstance = new ProcessInstance(processDefinition); 52 processInstance.signal(); 53 54 TaskMgmtInstance tmi = (TaskMgmtInstance) processInstance.getInstance(TaskMgmtInstance.class); 55 assertNotNull(tmi); 56 assertEquals(2, tmi.getTaskInstances().size()); 57 Iterator iter = tmi.getTaskInstances().iterator(); 58 while (iter.hasNext()) { 59 TaskInstance taskInstance = (TaskInstance) iter.next(); 60 assertEquals("change nappy", taskInstance.getName()); 61 } 62 } 63 } 64 | Popular Tags |