assertNotNull(task);
}
@Deployment
public void testThrowErrorWithErrorcode() throws Exception {
ErrorThrowingEventListener listener = null;
try {
listener = new ErrorThrowingEventListener();
listener.setErrorCode("123");
processEngineConfiguration.getEventDispatcher().addEventListener(listener, ActivitiEventType.TASK_ASSIGNED);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testError");
assertNotNull(processInstance);
// Fetch the task and assign it. Should cause error-event to be dispatched
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId())
.taskDefinitionKey("userTask")
.singleResult();
assertNotNull(task);
taskService.setAssignee(task.getId(), "kermit");
// Error-handling should have been called, and "escalate" task should be available instead of original one
task = taskService.createTaskQuery().processInstanceId(processInstance.getId())
.taskDefinitionKey("escalatedTask")
.singleResult();
assertNotNull(task);
// Try with a different error-code, resulting in a different task being created
listener.setErrorCode("456");
processInstance = runtimeService.startProcessInstanceByKey("testError");
assertNotNull(processInstance);
// Fetch the task and assign it. Should cause error-event to be dispatched