Search in sources :

Example 1 with ActivitiActivityCancelledEventImpl

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

the class ProcessInstanceEventsTest method testProcessInstanceTerminatedEvents_terminateInParentProcess.

@Deployment(resources = { "org/activiti/engine/test/bpmn/event/end/TerminateEndEventTest.testTerminateInParentProcess.bpmn", "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testProcessInstanceTerminatedEvents_terminateInParentProcess() throws Exception {
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("terminateParentProcess");
    // should terminate the called process and continue the parent
    Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).taskDefinitionKey("preTerminateEnd").singleResult();
    taskService.complete(task.getId());
    assertProcessEnded(pi.getId());
    List<ActivitiEvent> processTerminatedEvents = listener.filterEvents(ActivitiEventType.PROCESS_CANCELLED);
    assertEquals("There should be exactly one ActivitiEventType.PROCESS_TERMINATED event after the task complete.", 1, processTerminatedEvents.size());
    ActivitiProcessCancelledEventImpl processCancelledEvent = (ActivitiProcessCancelledEventImpl) processTerminatedEvents.get(0);
    assertThat(processCancelledEvent.getProcessInstanceId(), is(pi.getProcessInstanceId()));
    assertThat(processCancelledEvent.getProcessDefinitionId(), containsString("terminateParentProcess"));
    List<ActivitiEvent> activityTerminatedEvents = listener.filterEvents(ActivitiEventType.ACTIVITY_CANCELLED);
    assertThat("3 activities must be cancelled.", activityTerminatedEvents.size(), is(3));
    ActivitiActivityCancelledEventImpl activityEvent = (ActivitiActivityCancelledEventImpl) activityTerminatedEvents.get(0);
    assertThat("The user task must be terminated in the called sub process.", activityEvent.getActivityId(), is("theTask"));
    assertThat("The cause must be terminate end event", ((ActivityImpl) activityEvent.getCause()).getId(), is("EndEvent_3"));
    activityEvent = (ActivitiActivityCancelledEventImpl) activityTerminatedEvents.get(1);
    assertThat("The call activity must be terminated", activityEvent.getActivityId(), is("CallActivity_1"));
    assertThat("The cause must be terminate end event", ((ActivityImpl) activityEvent.getCause()).getId(), is("EndEvent_3"));
    activityEvent = (ActivitiActivityCancelledEventImpl) activityTerminatedEvents.get(2);
    assertThat("The gateway must be terminated", activityEvent.getActivityId(), is("ParallelGateway_1"));
    assertThat("The cause must be terminate end event", ((ActivityImpl) activityEvent.getCause()).getId(), is("EndEvent_3"));
}
Also used : Task(org.activiti.engine.task.Task) ActivitiActivityCancelledEventImpl(org.activiti.engine.delegate.event.impl.ActivitiActivityCancelledEventImpl) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiEvent(org.activiti.engine.delegate.event.ActivitiEvent) ActivitiProcessCancelledEventImpl(org.activiti.engine.delegate.event.impl.ActivitiProcessCancelledEventImpl) Deployment(org.activiti.engine.test.Deployment)

Example 2 with ActivitiActivityCancelledEventImpl

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

the class ProcessInstanceEventsTest method testProcessInstanceTerminatedEvents.

@Deployment(resources = "org/activiti/engine/test/bpmn/event/end/TerminateEndEventTest.testProcessTerminate.bpmn")
public void testProcessInstanceTerminatedEvents() throws Exception {
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("terminateEndEventExample");
    long executionEntities = runtimeService.createExecutionQuery().processInstanceId(pi.getId()).count();
    assertEquals(3, executionEntities);
    Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).taskDefinitionKey("preTerminateTask").singleResult();
    taskService.complete(task.getId());
    List<ActivitiEvent> processTerminatedEvents = listener.filterEvents(ActivitiEventType.PROCESS_CANCELLED);
    assertEquals("There should be exactly one ActivitiEventType.PROCESS_CANCELLED event after the task complete.", 1, processTerminatedEvents.size());
    ActivitiProcessCancelledEventImpl activitiEvent = (ActivitiProcessCancelledEventImpl) processTerminatedEvents.get(0);
    assertThat(activitiEvent.getProcessInstanceId(), is(pi.getProcessInstanceId()));
    assertThat(((ActivityImpl) activitiEvent.getCause()).getId(), is("EndEvent_2"));
    List<ActivitiEvent> activityTerminatedEvents = listener.filterEvents(ActivitiEventType.ACTIVITY_CANCELLED);
    assertThat("There should be exactly two ActivitiEventType.ACTIVITY_CANCELLED event after the task complete.", activityTerminatedEvents.size(), is(2));
    ActivitiActivityCancelledEventImpl activityEvent = (ActivitiActivityCancelledEventImpl) activityTerminatedEvents.get(0);
    assertThat("The user task must be terminated", activityEvent.getActivityId(), is("preNormalTerminateTask"));
    assertThat("The cause must be terminate end event", ((ActivityImpl) activityEvent.getCause()).getId(), is("EndEvent_2"));
    activityEvent = (ActivitiActivityCancelledEventImpl) activityTerminatedEvents.get(1);
    assertThat("The gateway must be terminated", activityEvent.getActivityId(), is("ParallelGateway_1"));
    assertThat("The cause must be terminate end event", ((ActivityImpl) activityEvent.getCause()).getId(), is("EndEvent_2"));
}
Also used : Task(org.activiti.engine.task.Task) ActivitiActivityCancelledEventImpl(org.activiti.engine.delegate.event.impl.ActivitiActivityCancelledEventImpl) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiEvent(org.activiti.engine.delegate.event.ActivitiEvent) ActivitiProcessCancelledEventImpl(org.activiti.engine.delegate.event.impl.ActivitiProcessCancelledEventImpl) Deployment(org.activiti.engine.test.Deployment)

Aggregations

ActivitiEvent (org.activiti.engine.delegate.event.ActivitiEvent)2 ActivitiActivityCancelledEventImpl (org.activiti.engine.delegate.event.impl.ActivitiActivityCancelledEventImpl)2 ActivitiProcessCancelledEventImpl (org.activiti.engine.delegate.event.impl.ActivitiProcessCancelledEventImpl)2 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)2 Task (org.activiti.engine.task.Task)2 Deployment (org.activiti.engine.test.Deployment)2