Search in sources :

Example 1 with ActivitiProcessStartedEvent

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

the class ProcessInstanceEventsTest method testSubProcessInstanceEvents.

/**
   * Test create, update and delete events of process instances.
   */
@Deployment(resources = { "org/activiti/engine/test/api/runtime/nestedSubProcess.bpmn20.xml", "org/activiti/engine/test/api/runtime/subProcess.bpmn20.xml" })
public void testSubProcessInstanceEvents() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("nestedSimpleSubProcess");
    assertNotNull(processInstance);
    // Check create-event one main process the second one Scope execution, and the third one subprocess
    assertEquals(8, 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(), ((ProcessInstance) event.getEntity()).getId());
    assertEquals(processInstance.getId(), event.getProcessInstanceId());
    assertEquals(processInstance.getId(), event.getExecutionId());
    assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
    assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
    assertEquals(processInstance.getId(), ((ProcessInstance) event.getEntity()).getId());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(2);
    assertEquals(ActivitiEventType.PROCESS_STARTED, event.getType());
    assertEquals(processInstance.getId(), ((ProcessInstance) event.getEntity()).getId());
    assertEquals(processInstance.getId(), event.getProcessInstanceId());
    assertEquals(processInstance.getId(), event.getExecutionId());
    assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
    assertTrue(event instanceof ActivitiProcessStartedEvent);
    assertNull(((ActivitiProcessStartedEvent) event).getNestedProcessDefinitionId());
    assertNull(((ActivitiProcessStartedEvent) event).getNestedProcessInstanceId());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(3);
    assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
    assertEquals(processInstance.getId(), ((ProcessInstance) event.getEntity()).getParentId());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(4);
    assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
    assertEquals(processInstance.getId(), ((ProcessInstance) event.getEntity()).getParentId());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(5);
    assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
    assertEquals("simpleSubProcess", ((ExecutionEntity) event.getEntity()).getProcessDefinition().getKey());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(6);
    assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
    assertEquals("simpleSubProcess", ((ExecutionEntity) event.getEntity()).getProcessDefinition().getKey());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(7);
    assertEquals(ActivitiEventType.PROCESS_STARTED, event.getType());
    assertEquals("simpleSubProcess", ((ExecutionEntity) event.getEntity()).getProcessDefinition().getKey());
    assertTrue(event instanceof ActivitiProcessStartedEvent);
    assertEquals(processInstance.getProcessDefinitionId(), ((ActivitiProcessStartedEvent) event).getNestedProcessDefinitionId());
    assertEquals(processInstance.getId(), ((ActivitiProcessStartedEvent) event).getNestedProcessInstanceId());
    listener.clearEventsReceived();
}
Also used : ActivitiProcessStartedEvent(org.activiti.engine.delegate.event.ActivitiProcessStartedEvent) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 2 with ActivitiProcessStartedEvent

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

the class ProcessInstanceEventsTest method testProcessInstanceEvents.

/**
	 * Test create, update and delete events of process instances.
	 */
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testProcessInstanceEvents() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    assertNotNull(processInstance);
    // Check create-event
    assertEquals(3, 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(), ((ProcessInstance) event.getEntity()).getId());
    assertEquals(processInstance.getId(), event.getProcessInstanceId());
    assertEquals(processInstance.getId(), event.getExecutionId());
    assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
    assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
    assertEquals(processInstance.getId(), ((ProcessInstance) event.getEntity()).getId());
    assertEquals(processInstance.getId(), event.getProcessInstanceId());
    assertEquals(processInstance.getId(), event.getExecutionId());
    assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(2);
    assertEquals(ActivitiEventType.PROCESS_STARTED, event.getType());
    assertEquals(processInstance.getId(), ((ProcessInstance) event.getEntity()).getId());
    assertEquals(processInstance.getId(), event.getProcessInstanceId());
    assertEquals(processInstance.getId(), event.getExecutionId());
    assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
    assertTrue(event instanceof ActivitiProcessStartedEvent);
    assertNull(((ActivitiProcessStartedEvent) event).getNestedProcessDefinitionId());
    assertNull(((ActivitiProcessStartedEvent) event).getNestedProcessInstanceId());
    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(), ((ProcessInstance) event.getEntity()).getId());
    assertEquals(ActivitiEventType.ENTITY_SUSPENDED, event.getType());
    assertEquals(processInstance.getId(), event.getProcessInstanceId());
    assertEquals(processInstance.getId(), event.getExecutionId());
    assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
    assertEquals(ActivitiEventType.ENTITY_ACTIVATED, event.getType());
    assertEquals(processInstance.getId(), ((ProcessInstance) event.getEntity()).getId());
    assertEquals(processInstance.getId(), event.getProcessInstanceId());
    assertEquals(processInstance.getId(), event.getExecutionId());
    assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
    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());
    assertEquals(processInstance.getId(), event.getProcessInstanceId());
    assertEquals(processInstance.getId(), event.getExecutionId());
    assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
    event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
    assertEquals(ActivitiEventType.ENTITY_ACTIVATED, event.getType());
    assertEquals(processInstance.getId(), ((ProcessInstance) event.getEntity()).getId());
    assertEquals(processInstance.getId(), event.getProcessInstanceId());
    assertEquals(processInstance.getId(), event.getExecutionId());
    assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
    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(), ((ProcessInstance) event.getEntity()).getId());
    assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
    assertEquals(processInstance.getId(), event.getProcessInstanceId());
    assertEquals(processInstance.getId(), event.getExecutionId());
    assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
    listener.clearEventsReceived();
    runtimeService.deleteProcessInstance(processInstance.getId(), "Testing events");
    List<ActivitiEvent> processCancelledEvents = listener.filterEvents(ActivitiEventType.PROCESS_CANCELLED);
    assertEquals(1, processCancelledEvents.size());
    ActivitiCancelledEvent cancelledEvent = (ActivitiCancelledEvent) processCancelledEvents.get(0);
    assertEquals(ActivitiEventType.PROCESS_CANCELLED, cancelledEvent.getType());
    assertEquals(processInstance.getId(), cancelledEvent.getProcessInstanceId());
    assertEquals(processInstance.getId(), cancelledEvent.getExecutionId());
    listener.clearEventsReceived();
}
Also used : ActivitiProcessStartedEvent(org.activiti.engine.delegate.event.ActivitiProcessStartedEvent) ActivitiCancelledEvent(org.activiti.engine.delegate.event.ActivitiCancelledEvent) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiEvent(org.activiti.engine.delegate.event.ActivitiEvent) Deployment(org.activiti.engine.test.Deployment)

Aggregations

ActivitiEntityEvent (org.activiti.engine.delegate.event.ActivitiEntityEvent)2 ActivitiProcessStartedEvent (org.activiti.engine.delegate.event.ActivitiProcessStartedEvent)2 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)2 Deployment (org.activiti.engine.test.Deployment)2 ActivitiCancelledEvent (org.activiti.engine.delegate.event.ActivitiCancelledEvent)1 ActivitiEvent (org.activiti.engine.delegate.event.ActivitiEvent)1 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)1