use of org.activiti.engine.delegate.event.ActivitiSignalEvent in project Activiti by Activiti.
the class ActivityEventsTest method testActivitySignalEventsWithinProcess.
/**
* Test to verify if signals coming from an intermediate throw-event trigger
* the right events to be dispatched.
*/
@Deployment
public void testActivitySignalEventsWithinProcess() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("signalProcess");
assertNotNull(processInstance);
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
Execution executionWithSignalEvent = runtimeService.createExecutionQuery().activityId("shipOrder").singleResult();
taskService.complete(task.getId());
assertEquals(1L, listener.getEventsReceived().size());
assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiSignalEvent);
ActivitiSignalEvent signalEvent = (ActivitiSignalEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ACTIVITY_SIGNALED, signalEvent.getType());
assertEquals("shipOrder", signalEvent.getActivityId());
assertEquals(executionWithSignalEvent.getId(), signalEvent.getExecutionId());
assertEquals(executionWithSignalEvent.getProcessInstanceId(), signalEvent.getProcessInstanceId());
assertEquals(processInstance.getProcessDefinitionId(), signalEvent.getProcessDefinitionId());
assertEquals("alert", signalEvent.getSignalName());
assertNull(signalEvent.getSignalData());
}
use of org.activiti.engine.delegate.event.ActivitiSignalEvent in project Activiti by Activiti.
the class ActivityEventsTest method testActivitySignalEvents.
/**
* Test events related to signalling
*/
@Deployment
public void testActivitySignalEvents() throws Exception {
// Two paths are active in the process, one receive-task and one
// intermediate catching signal-event
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("signalProcess");
assertNotNull(processInstance);
// Check regular signal through API
Execution executionWithSignal = runtimeService.createExecutionQuery().activityId("receivePayment").singleResult();
assertNotNull(executionWithSignal);
runtimeService.signal(executionWithSignal.getId());
assertEquals(1, listener.getEventsReceived().size());
assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiSignalEvent);
ActivitiSignalEvent signalEvent = (ActivitiSignalEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ACTIVITY_SIGNALED, signalEvent.getType());
assertEquals("receivePayment", signalEvent.getActivityId());
assertEquals(executionWithSignal.getId(), signalEvent.getExecutionId());
assertEquals(executionWithSignal.getProcessInstanceId(), signalEvent.getProcessInstanceId());
assertEquals(processInstance.getProcessDefinitionId(), signalEvent.getProcessDefinitionId());
assertNull(signalEvent.getSignalName());
assertNull(signalEvent.getSignalData());
listener.clearEventsReceived();
// Check signal using event, and pass in additional payload
Execution executionWithSignalEvent = runtimeService.createExecutionQuery().activityId("shipOrder").singleResult();
runtimeService.signalEventReceived("alert", executionWithSignalEvent.getId(), Collections.singletonMap("test", (Object) "test"));
assertEquals(1, listener.getEventsReceived().size());
assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiSignalEvent);
signalEvent = (ActivitiSignalEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ACTIVITY_SIGNALED, signalEvent.getType());
assertEquals("shipOrder", signalEvent.getActivityId());
assertEquals(executionWithSignalEvent.getId(), signalEvent.getExecutionId());
assertEquals(executionWithSignalEvent.getProcessInstanceId(), signalEvent.getProcessInstanceId());
assertEquals(processInstance.getProcessDefinitionId(), signalEvent.getProcessDefinitionId());
assertEquals("alert", signalEvent.getSignalName());
assertNotNull(signalEvent.getSignalData());
listener.clearEventsReceived();
assertDatabaseEventPresent(ActivitiEventType.ACTIVITY_SIGNALED);
}
use of org.activiti.engine.delegate.event.ActivitiSignalEvent in project Activiti by Activiti.
the class ActivitySignaledEventHandler method generateEventLogEntry.
@Override
public EventLogEntryEntity generateEventLogEntry(CommandContext commandContext) {
ActivitiSignalEvent signalEvent = (ActivitiSignalEvent) event;
Map<String, Object> data = new HashMap<String, Object>();
putInMapIfNotNull(data, Fields.ACTIVITY_ID, signalEvent.getActivityId());
putInMapIfNotNull(data, Fields.ACTIVITY_NAME, signalEvent.getActivityName());
putInMapIfNotNull(data, Fields.PROCESS_DEFINITION_ID, signalEvent.getProcessDefinitionId());
putInMapIfNotNull(data, Fields.PROCESS_INSTANCE_ID, signalEvent.getProcessInstanceId());
putInMapIfNotNull(data, Fields.EXECUTION_ID, signalEvent.getExecutionId());
putInMapIfNotNull(data, Fields.ACTIVITY_TYPE, signalEvent.getActivityType());
putInMapIfNotNull(data, Fields.BEHAVIOR_CLASS, signalEvent.getBehaviorClass());
putInMapIfNotNull(data, Fields.SIGNAL_NAME, signalEvent.getSignalName());
putInMapIfNotNull(data, Fields.SIGNAL_DATA, signalEvent.getSignalData());
return createEventLogEntry(signalEvent.getProcessDefinitionId(), signalEvent.getProcessInstanceId(), signalEvent.getExecutionId(), null, data);
}
use of org.activiti.engine.delegate.event.ActivitiSignalEvent in project Activiti by Activiti.
the class ActivityEventsTest method testActivityMessageEvents.
/**
* Test events related to message events, called from the API.
*/
@Deployment
public void testActivityMessageEvents() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("messageProcess");
assertNotNull(processInstance);
Execution executionWithMessage = runtimeService.createExecutionQuery().activityId("shipOrder").singleResult();
assertNotNull(executionWithMessage);
runtimeService.messageEventReceived("messageName", executionWithMessage.getId());
assertEquals(2, listener.getEventsReceived().size());
// First, a message-event is expected
assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiMessageEvent);
ActivitiMessageEvent messageEvent = (ActivitiMessageEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ACTIVITY_MESSAGE_RECEIVED, messageEvent.getType());
assertEquals("shipOrder", messageEvent.getActivityId());
assertEquals(executionWithMessage.getId(), messageEvent.getExecutionId());
assertEquals(executionWithMessage.getProcessInstanceId(), messageEvent.getProcessInstanceId());
assertEquals(processInstance.getProcessDefinitionId(), messageEvent.getProcessDefinitionId());
assertEquals("messageName", messageEvent.getMessageName());
assertNull(messageEvent.getMessageData());
// Next, an signal-event is expected, as a result of the message
assertTrue(listener.getEventsReceived().get(1) instanceof ActivitiSignalEvent);
ActivitiSignalEvent signalEvent = (ActivitiSignalEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ACTIVITY_SIGNALED, signalEvent.getType());
assertEquals("shipOrder", signalEvent.getActivityId());
assertEquals(executionWithMessage.getId(), signalEvent.getExecutionId());
assertEquals(executionWithMessage.getProcessInstanceId(), signalEvent.getProcessInstanceId());
assertEquals(processInstance.getProcessDefinitionId(), signalEvent.getProcessDefinitionId());
assertEquals("messageName", signalEvent.getSignalName());
assertNull(signalEvent.getSignalData());
assertDatabaseEventPresent(ActivitiEventType.ACTIVITY_MESSAGE_RECEIVED);
}
use of org.activiti.engine.delegate.event.ActivitiSignalEvent in project Activiti by Activiti.
the class ActivityEventsTest method testActivityCompensationEvents.
/**
* Test events related to compensation events.
*/
@Deployment
public void testActivityCompensationEvents() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("compensationProcess");
assertNotNull(processInstance);
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
// Complete task, next a compensation event will be thrown
taskService.complete(task.getId());
assertEquals(2, listener.getEventsReceived().size());
// A compensate-event is expected
assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiActivityEvent);
ActivitiActivityEvent activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ACTIVITY_COMPENSATE, activityEvent.getType());
assertEquals("compensate", activityEvent.getActivityId());
// A new execution is created for the compensation-event, this should be visible in the event
assertFalse(processInstance.getId().equals(activityEvent.getExecutionId()));
assertEquals(processInstance.getProcessInstanceId(), activityEvent.getProcessInstanceId());
assertEquals(processInstance.getProcessDefinitionId(), activityEvent.getProcessDefinitionId());
// Also, a signal-event is received, representing the boundary-event being executed.
assertTrue(listener.getEventsReceived().get(1) instanceof ActivitiSignalEvent);
ActivitiSignalEvent signalEvent = (ActivitiSignalEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ACTIVITY_SIGNALED, signalEvent.getType());
assertEquals("throwCompensation", signalEvent.getActivityId());
assertEquals(processInstance.getId(), signalEvent.getExecutionId());
assertEquals(processInstance.getProcessInstanceId(), signalEvent.getProcessInstanceId());
assertEquals(processInstance.getProcessDefinitionId(), signalEvent.getProcessDefinitionId());
assertEquals("compensationDone", signalEvent.getSignalName());
assertNull(signalEvent.getSignalData());
// Check if the process is still alive
processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(processInstance);
assertDatabaseEventPresent(ActivitiEventType.ACTIVITY_COMPENSATE);
}
Aggregations