1 package org.jbpm.taskmgmt.exe; 2 3 import junit.framework.TestCase; 4 5 import org.jbpm.graph.def.ActionHandler; 6 import org.jbpm.graph.def.ProcessDefinition; 7 import org.jbpm.graph.exe.ExecutionContext; 8 import org.jbpm.graph.exe.ProcessInstance; 9 import org.jbpm.graph.exe.Token; 10 11 public class TaskEventExecutionTest extends TestCase { 12 13 static int counter = 0; 14 15 public static class PlusPlus implements ActionHandler { 16 private static final long serialVersionUID = 1L; 17 public void execute(ExecutionContext executionContext) throws Exception { 18 counter++; 19 } 20 } 21 22 public void setUp() { 23 counter = 0; 24 } 25 26 public void testTaskCreationEvent() { 27 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 28 "<process-definition>" + 29 " <start-state>" + 30 " <transition to='a' />" + 31 " </start-state>" + 32 " <task-node name='a'>" + 33 " <task name='clean ceiling'>" + 34 " <event type='task-create'>" + 35 " <action class='org.jbpm.taskmgmt.exe.TaskEventExecutionTest$PlusPlus' />" + 36 " </event>" + 37 " </task>" + 38 " </task-node>" + 39 "</process-definition>" 40 ); 41 ProcessInstance processInstance = new ProcessInstance(processDefinition); 42 assertEquals(0, counter); 43 processInstance.signal(); 44 assertEquals(1, counter); 45 } 46 47 public void testTaskStartEvent() { 48 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 49 "<process-definition>" + 50 " <start-state>" + 51 " <transition to='a' />" + 52 " </start-state>" + 53 " <task-node name='a'>" + 54 " <task name='clean ceiling'>" + 55 " <event type='task-start'>" + 56 " <action class='org.jbpm.taskmgmt.exe.TaskEventExecutionTest$PlusPlus' />" + 57 " </event>" + 58 " </task>" + 59 " </task-node>" + 60 "</process-definition>" 61 ); 62 ProcessInstance processInstance = new ProcessInstance(processDefinition); 63 Token token = processInstance.getRootToken(); 64 assertEquals(0, counter); 65 processInstance.signal(); 66 assertEquals(0, counter); 67 68 TaskMgmtInstance tmi = processInstance.getTaskMgmtInstance(); 69 TaskInstance taskInstance = (TaskInstance) tmi.getUnfinishedTasks(token).iterator().next(); 70 taskInstance.start(); 71 assertEquals(1, counter); 72 } 73 74 public void testTaskAssignEvent() { 75 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 76 "<process-definition>" + 77 " <start-state>" + 78 " <transition to='a' />" + 79 " </start-state>" + 80 " <task-node name='a'>" + 81 " <task name='clean ceiling'>" + 82 " <event type='task-assign'>" + 83 " <action class='org.jbpm.taskmgmt.exe.TaskEventExecutionTest$PlusPlus' />" + 84 " </event>" + 85 " </task>" + 86 " </task-node>" + 87 "</process-definition>" 88 ); 89 ProcessInstance processInstance = new ProcessInstance(processDefinition); 90 Token token = processInstance.getRootToken(); 91 assertEquals(0, counter); 92 processInstance.signal(); 93 assertEquals(0, counter); 94 95 TaskMgmtInstance tmi = processInstance.getTaskMgmtInstance(); 96 TaskInstance taskInstance = (TaskInstance) tmi.getUnfinishedTasks(token).iterator().next(); 97 taskInstance.start(); 98 assertEquals(0, counter); 99 100 taskInstance.setActorId("john doe"); 101 assertEquals(1, counter); 102 } 103 104 public void testTaskEndEvent() { 105 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 106 "<process-definition>" + 107 " <start-state>" + 108 " <transition to='a' />" + 109 " </start-state>" + 110 " <task-node name='a'>" + 111 " <task name='clean ceiling'>" + 112 " <event type='task-end'>" + 113 " <action class='org.jbpm.taskmgmt.exe.TaskEventExecutionTest$PlusPlus' />" + 114 " </event>" + 115 " </task>" + 116 " <transition to='a' />" + 117 " </task-node>" + 118 "</process-definition>" 119 ); 120 ProcessInstance processInstance = new ProcessInstance(processDefinition); 121 Token token = processInstance.getRootToken(); 122 assertEquals(0, counter); 123 processInstance.signal(); 124 assertEquals(0, counter); 125 126 TaskMgmtInstance tmi = processInstance.getTaskMgmtInstance(); 127 TaskInstance taskInstance = (TaskInstance) tmi.getUnfinishedTasks(token).iterator().next(); 128 taskInstance.start(); 129 assertEquals(0, counter); 130 131 taskInstance.setActorId("john doe"); 132 assertEquals(0, counter); 133 134 taskInstance.end(); 135 assertEquals(1, counter); 136 } 137 } 138 | Popular Tags |