Search in sources :

Example 1 with ActivitiActivityEvent

use of org.activiti.engine.delegate.event.ActivitiActivityEvent 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);
}
Also used : Task(org.activiti.engine.task.Task) ActivitiActivityEvent(org.activiti.engine.delegate.event.ActivitiActivityEvent) ActivitiSignalEvent(org.activiti.engine.delegate.event.ActivitiSignalEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 2 with ActivitiActivityEvent

use of org.activiti.engine.delegate.event.ActivitiActivityEvent in project Activiti by Activiti.

the class ActivityEventsTest method testActivityEvents.

/**
	 * Test starting and completed events for activity. Since these events are dispatched in the core
	 * of the PVM, not all individual activity-type is tested. Rather, we test the main types (tasks, gateways, events,
	 * subprocesses). 
	 */
@Deployment
public void testActivityEvents() throws Exception {
    // We're interested in the raw events, alter the listener to keep those as well
    listener.setIgnoreRawActivityEvents(false);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("activityProcess");
    assertNotNull(processInstance);
    assertEquals(3, listener.getEventsReceived().size());
    // Start-event activity started
    ActivitiActivityEvent activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ACTIVITY_STARTED, activityEvent.getType());
    assertEquals("theStart", activityEvent.getActivityId());
    assertEquals(processInstance.getId(), activityEvent.getExecutionId());
    assertEquals(processInstance.getProcessInstanceId(), activityEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), activityEvent.getProcessDefinitionId());
    // Start-event finished
    activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(1);
    assertEquals(ActivitiEventType.ACTIVITY_COMPLETED, activityEvent.getType());
    assertEquals("theStart", activityEvent.getActivityId());
    assertEquals(processInstance.getId(), activityEvent.getExecutionId());
    assertEquals(processInstance.getProcessInstanceId(), activityEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), activityEvent.getProcessDefinitionId());
    // Usertask started
    activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(2);
    assertEquals(ActivitiEventType.ACTIVITY_STARTED, activityEvent.getType());
    assertEquals("shipOrder", activityEvent.getActivityId());
    assertEquals(processInstance.getId(), activityEvent.getExecutionId());
    assertEquals(processInstance.getProcessInstanceId(), activityEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), activityEvent.getProcessDefinitionId());
    // Complete usertask
    listener.clearEventsReceived();
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(task);
    taskService.complete(task.getId());
    // Subprocess execution is created
    Execution execution = runtimeService.createExecutionQuery().parentId(processInstance.getId()).singleResult();
    assertNotNull(execution);
    assertEquals(5, listener.getEventsReceived().size());
    activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ACTIVITY_COMPLETED, activityEvent.getType());
    assertEquals("shipOrder", activityEvent.getActivityId());
    assertEquals(processInstance.getId(), activityEvent.getExecutionId());
    assertEquals(processInstance.getProcessInstanceId(), activityEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), activityEvent.getProcessDefinitionId());
    activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(1);
    assertEquals(ActivitiEventType.ACTIVITY_STARTED, activityEvent.getType());
    assertEquals("subProcess", activityEvent.getActivityId());
    assertEquals(execution.getId(), activityEvent.getExecutionId());
    assertEquals(processInstance.getProcessInstanceId(), activityEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), activityEvent.getProcessDefinitionId());
    activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(2);
    assertEquals(ActivitiEventType.ACTIVITY_STARTED, activityEvent.getType());
    assertEquals("subProcessStart", activityEvent.getActivityId());
    assertEquals(execution.getId(), activityEvent.getExecutionId());
    assertEquals(processInstance.getProcessInstanceId(), activityEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), activityEvent.getProcessDefinitionId());
    activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(3);
    assertEquals(ActivitiEventType.ACTIVITY_COMPLETED, activityEvent.getType());
    assertEquals("subProcessStart", activityEvent.getActivityId());
    assertEquals(execution.getId(), activityEvent.getExecutionId());
    assertEquals(processInstance.getProcessInstanceId(), activityEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), activityEvent.getProcessDefinitionId());
    activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(4);
    assertEquals(ActivitiEventType.ACTIVITY_STARTED, activityEvent.getType());
    assertEquals("subTask", activityEvent.getActivityId());
    assertEquals(execution.getId(), activityEvent.getExecutionId());
    assertEquals(processInstance.getProcessInstanceId(), activityEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), activityEvent.getProcessDefinitionId());
    listener.clearEventsReceived();
    // Check gateway and intermediate throw event
    Task subTask = taskService.createTaskQuery().executionId(execution.getId()).singleResult();
    assertNotNull(subTask);
    taskService.complete(subTask.getId());
    assertEquals(10, listener.getEventsReceived().size());
    activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ACTIVITY_COMPLETED, activityEvent.getType());
    assertEquals("subTask", activityEvent.getActivityId());
    activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(1);
    assertEquals(ActivitiEventType.ACTIVITY_STARTED, activityEvent.getType());
    assertEquals("gateway", activityEvent.getActivityId());
    activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(2);
    assertEquals(ActivitiEventType.ACTIVITY_COMPLETED, activityEvent.getType());
    assertEquals("gateway", activityEvent.getActivityId());
    activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(3);
    assertEquals(ActivitiEventType.ACTIVITY_STARTED, activityEvent.getType());
    assertEquals("throwMessageEvent", activityEvent.getActivityId());
    activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(4);
    assertEquals(ActivitiEventType.ACTIVITY_COMPLETED, activityEvent.getType());
    assertEquals("throwMessageEvent", activityEvent.getActivityId());
    activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(5);
    assertEquals(ActivitiEventType.ACTIVITY_STARTED, activityEvent.getType());
    assertEquals("endSubProcess", activityEvent.getActivityId());
    activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(6);
    assertEquals(ActivitiEventType.ACTIVITY_COMPLETED, activityEvent.getType());
    assertEquals("endSubProcess", activityEvent.getActivityId());
    activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(7);
    assertEquals(ActivitiEventType.ACTIVITY_COMPLETED, activityEvent.getType());
    assertEquals("subProcess", activityEvent.getActivityId());
    activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(8);
    assertEquals(ActivitiEventType.ACTIVITY_STARTED, activityEvent.getType());
    assertEquals("theEnd", activityEvent.getActivityId());
    activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(9);
    assertEquals(ActivitiEventType.ACTIVITY_COMPLETED, activityEvent.getType());
    assertEquals("theEnd", activityEvent.getActivityId());
}
Also used : Task(org.activiti.engine.task.Task) Execution(org.activiti.engine.runtime.Execution) ActivitiActivityEvent(org.activiti.engine.delegate.event.ActivitiActivityEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 3 with ActivitiActivityEvent

use of org.activiti.engine.delegate.event.ActivitiActivityEvent in project Activiti by Activiti.

the class ActivityCompensatedEventHandler method generateEventLogEntry.

@Override
public EventLogEntryEntity generateEventLogEntry(CommandContext commandContext) {
    ActivitiActivityEvent activityEvent = (ActivitiActivityEvent) event;
    Map<String, Object> data = new HashMap<String, Object>();
    putInMapIfNotNull(data, Fields.ACTIVITY_ID, activityEvent.getActivityId());
    putInMapIfNotNull(data, Fields.ACTIVITY_NAME, activityEvent.getActivityName());
    putInMapIfNotNull(data, Fields.PROCESS_DEFINITION_ID, activityEvent.getProcessDefinitionId());
    putInMapIfNotNull(data, Fields.PROCESS_INSTANCE_ID, activityEvent.getProcessInstanceId());
    putInMapIfNotNull(data, Fields.EXECUTION_ID, activityEvent.getExecutionId());
    putInMapIfNotNull(data, Fields.ACTIVITY_TYPE, activityEvent.getActivityType());
    putInMapIfNotNull(data, Fields.BEHAVIOR_CLASS, activityEvent.getBehaviorClass());
    return createEventLogEntry(activityEvent.getProcessDefinitionId(), activityEvent.getProcessInstanceId(), activityEvent.getExecutionId(), null, data);
}
Also used : ActivitiActivityEvent(org.activiti.engine.delegate.event.ActivitiActivityEvent) HashMap(java.util.HashMap)

Example 4 with ActivitiActivityEvent

use of org.activiti.engine.delegate.event.ActivitiActivityEvent in project Activiti by Activiti.

the class ActivityCompletedEventHandler method generateEventLogEntry.

@Override
public EventLogEntryEntity generateEventLogEntry(CommandContext commandContext) {
    ActivitiActivityEvent activityEvent = (ActivitiActivityEvent) event;
    Map<String, Object> data = new HashMap<String, Object>();
    putInMapIfNotNull(data, Fields.ACTIVITY_ID, activityEvent.getActivityId());
    putInMapIfNotNull(data, Fields.ACTIVITY_NAME, activityEvent.getActivityName());
    putInMapIfNotNull(data, Fields.PROCESS_DEFINITION_ID, activityEvent.getProcessDefinitionId());
    putInMapIfNotNull(data, Fields.PROCESS_INSTANCE_ID, activityEvent.getProcessInstanceId());
    putInMapIfNotNull(data, Fields.EXECUTION_ID, activityEvent.getExecutionId());
    putInMapIfNotNull(data, Fields.ACTIVITY_TYPE, activityEvent.getActivityType());
    putInMapIfNotNull(data, Fields.BEHAVIOR_CLASS, activityEvent.getBehaviorClass());
    return createEventLogEntry(activityEvent.getProcessDefinitionId(), activityEvent.getProcessInstanceId(), activityEvent.getExecutionId(), null, data);
}
Also used : ActivitiActivityEvent(org.activiti.engine.delegate.event.ActivitiActivityEvent) HashMap(java.util.HashMap)

Example 5 with ActivitiActivityEvent

use of org.activiti.engine.delegate.event.ActivitiActivityEvent in project Activiti by Activiti.

the class ActivityErrorReceivedEventHandler method generateEventLogEntry.

@Override
public EventLogEntryEntity generateEventLogEntry(CommandContext commandContext) {
    ActivitiActivityEvent activityEvent = (ActivitiActivityEvent) event;
    Map<String, Object> data = new HashMap<String, Object>();
    putInMapIfNotNull(data, Fields.ACTIVITY_ID, activityEvent.getActivityId());
    putInMapIfNotNull(data, Fields.ACTIVITY_NAME, activityEvent.getActivityName());
    putInMapIfNotNull(data, Fields.PROCESS_DEFINITION_ID, activityEvent.getProcessDefinitionId());
    putInMapIfNotNull(data, Fields.PROCESS_INSTANCE_ID, activityEvent.getProcessInstanceId());
    putInMapIfNotNull(data, Fields.EXECUTION_ID, activityEvent.getExecutionId());
    putInMapIfNotNull(data, Fields.ACTIVITY_TYPE, activityEvent.getActivityType());
    putInMapIfNotNull(data, Fields.BEHAVIOR_CLASS, activityEvent.getBehaviorClass());
    return createEventLogEntry(activityEvent.getProcessDefinitionId(), activityEvent.getProcessInstanceId(), activityEvent.getExecutionId(), null, data);
}
Also used : ActivitiActivityEvent(org.activiti.engine.delegate.event.ActivitiActivityEvent) HashMap(java.util.HashMap)

Aggregations

ActivitiActivityEvent (org.activiti.engine.delegate.event.ActivitiActivityEvent)6 HashMap (java.util.HashMap)4 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)2 Task (org.activiti.engine.task.Task)2 Deployment (org.activiti.engine.test.Deployment)2 ActivitiSignalEvent (org.activiti.engine.delegate.event.ActivitiSignalEvent)1 Execution (org.activiti.engine.runtime.Execution)1