use of org.activiti.engine.impl.bpmn.helper.ErrorThrowingEventListener in project Activiti by Activiti.
the class ErrorThrowingEventListenerTest method testThrowError.
@Deployment
public void testThrowError() throws Exception {
ErrorThrowingEventListener listener = null;
try {
listener = new ErrorThrowingEventListener();
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);
} finally {
processEngineConfiguration.getEventDispatcher().removeEventListener(listener);
}
}
use of org.activiti.engine.impl.bpmn.helper.ErrorThrowingEventListener in project Activiti by Activiti.
the class DefaultListenerFactory method createEventThrowingEventListener.
@Override
public ActivitiEventListener createEventThrowingEventListener(EventListener eventListener) {
BaseDelegateEventListener result = null;
if (ImplementationType.IMPLEMENTATION_TYPE_THROW_SIGNAL_EVENT.equals(eventListener.getImplementationType())) {
result = new SignalThrowingEventListener();
((SignalThrowingEventListener) result).setSignalName(eventListener.getImplementation());
((SignalThrowingEventListener) result).setProcessInstanceScope(true);
} else if (ImplementationType.IMPLEMENTATION_TYPE_THROW_GLOBAL_SIGNAL_EVENT.equals(eventListener.getImplementationType())) {
result = new SignalThrowingEventListener();
((SignalThrowingEventListener) result).setSignalName(eventListener.getImplementation());
((SignalThrowingEventListener) result).setProcessInstanceScope(false);
} else if (ImplementationType.IMPLEMENTATION_TYPE_THROW_MESSAGE_EVENT.equals(eventListener.getImplementationType())) {
result = new MessageThrowingEventListener();
((MessageThrowingEventListener) result).setMessageName(eventListener.getImplementation());
} else if (ImplementationType.IMPLEMENTATION_TYPE_THROW_ERROR_EVENT.equals(eventListener.getImplementationType())) {
result = new ErrorThrowingEventListener();
((ErrorThrowingEventListener) result).setErrorCode(eventListener.getImplementation());
}
if (result == null) {
throw new ActivitiIllegalArgumentException("Cannot create an event-throwing event-listener, unknown implementation type: " + eventListener.getImplementationType());
}
result.setEntityClass(getEntityType(eventListener.getEntityType()));
return result;
}
use of org.activiti.engine.impl.bpmn.helper.ErrorThrowingEventListener in project Activiti by Activiti.
the class ErrorThrowingEventListenerTest method testThrowErrorWithErrorcode.
@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
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskDefinitionKey("userTask").singleResult();
assertNotNull(task);
taskService.setAssignee(task.getId(), "kermit");
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskDefinitionKey("escalatedTask2").singleResult();
assertNotNull(task);
} finally {
processEngineConfiguration.getEventDispatcher().removeEventListener(listener);
}
}
Aggregations