// Check create-event
assertEquals(2, listener.getEventsReceived().size());
assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiEntityEvent);
ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
assertEquals(processInstance.getId(), ((Execution) event.getEntity()).getId());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
assertEquals(processInstance.getId(), ((Execution) event.getEntity()).getId());
listener.clearEventsReceived();
// Check update event when suspended/activated
runtimeService.suspendProcessInstanceById(processInstance.getId());
runtimeService.activateProcessInstanceById(processInstance.getId());
assertEquals(2, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(processInstance.getId(), ((Execution) event.getEntity()).getId());
assertEquals(ActivitiEventType.ENTITY_SUSPENDED, event.getType());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_ACTIVATED, event.getType());
assertEquals(processInstance.getId(), ((Execution) event.getEntity()).getId());
listener.clearEventsReceived();
// Check update event when process-definition is supended (should cascade suspend/activate all process instances)
repositoryService.suspendProcessDefinitionById(processInstance.getProcessDefinitionId(), true, null);
repositoryService.activateProcessDefinitionById(processInstance.getProcessDefinitionId(), true, null);
assertEquals(2, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(processInstance.getId(), ((ProcessInstance) event.getEntity()).getId());
assertEquals(ActivitiEventType.ENTITY_SUSPENDED, event.getType());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_ACTIVATED, event.getType());
assertEquals(processInstance.getId(), ((Execution) event.getEntity()).getId());
listener.clearEventsReceived();
// Check update-event when business-key is updated
runtimeService.updateBusinessKey(processInstance.getId(), "thekey");
assertEquals(1, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(processInstance.getId(), ((Execution) event.getEntity()).getId());
assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
listener.clearEventsReceived();
runtimeService.deleteProcessInstance(processInstance.getId(), "Testing events");
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
assertEquals(processInstance.getId(), ((Execution) event.getEntity()).getId());
listener.clearEventsReceived();
}