Search in sources :

Example 6 with RecorderExecutionListener

use of org.camunda.bpm.engine.test.bpmn.executionlistener.RecorderExecutionListener in project camunda-bpm-platform by camunda.

the class ProcessInstanceModificationTest method testSkipListenerInvocation.

@Deployment(resources = SUBPROCESS_LISTENER_PROCESS)
public void testSkipListenerInvocation() {
    RecorderExecutionListener.clear();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("subprocess", Collections.<String, Object>singletonMap("listener", new RecorderExecutionListener()));
    String processInstanceId = processInstance.getId();
    assertTrue(RecorderExecutionListener.getRecordedEvents().isEmpty());
    // when I start an activity with "skip listeners" setting
    runtimeService.createProcessInstanceModification(processInstanceId).startBeforeActivity("innerTask").execute(true, false);
    // then no listeners are invoked
    assertTrue(RecorderExecutionListener.getRecordedEvents().isEmpty());
    // when I cancel an activity with "skip listeners" setting
    ActivityInstance activityInstanceTree = runtimeService.getActivityInstance(processInstanceId);
    runtimeService.createProcessInstanceModification(processInstance.getId()).cancelActivityInstance(getChildInstanceForActivity(activityInstanceTree, "innerTask").getId()).execute(true, false);
    // then no listeners are invoked
    assertTrue(RecorderExecutionListener.getRecordedEvents().isEmpty());
    // when I cancel an activity that ends the process instance
    runtimeService.createProcessInstanceModification(processInstance.getId()).cancelActivityInstance(getChildInstanceForActivity(activityInstanceTree, "outerTask").getId()).execute(true, false);
    // then no listeners are invoked
    assertTrue(RecorderExecutionListener.getRecordedEvents().isEmpty());
}
Also used : ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) RecorderExecutionListener(org.camunda.bpm.engine.test.bpmn.executionlistener.RecorderExecutionListener) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 7 with RecorderExecutionListener

use of org.camunda.bpm.engine.test.bpmn.executionlistener.RecorderExecutionListener in project camunda-bpm-platform by camunda.

the class ProcessInstanceModificationTest method testActivityExecutionListenerInvocation.

@Deployment(resources = SUBPROCESS_LISTENER_PROCESS)
public void testActivityExecutionListenerInvocation() {
    RecorderExecutionListener.clear();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("subprocess", Collections.<String, Object>singletonMap("listener", new RecorderExecutionListener()));
    String processInstanceId = processInstance.getId();
    assertTrue(RecorderExecutionListener.getRecordedEvents().isEmpty());
    runtimeService.createProcessInstanceModification(processInstance.getId()).startBeforeActivity("innerTask").execute();
    // assert activity instance tree
    ActivityInstance activityInstanceTree = runtimeService.getActivityInstance(processInstanceId);
    assertNotNull(activityInstanceTree);
    assertEquals(processInstanceId, activityInstanceTree.getProcessInstanceId());
    assertThat(activityInstanceTree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("outerTask").beginScope("subProcess").activity("innerTask").done());
    // assert listener invocations
    List<RecordedEvent> recordedEvents = RecorderExecutionListener.getRecordedEvents();
    assertEquals(2, recordedEvents.size());
    ActivityInstance subprocessInstance = getChildInstanceForActivity(activityInstanceTree, "subProcess");
    ActivityInstance innerTaskInstance = getChildInstanceForActivity(subprocessInstance, "innerTask");
    RecordedEvent firstEvent = recordedEvents.get(0);
    RecordedEvent secondEvent = recordedEvents.get(1);
    assertEquals("subProcess", firstEvent.getActivityId());
    assertEquals(subprocessInstance.getId(), firstEvent.getActivityInstanceId());
    assertEquals(ExecutionListener.EVENTNAME_START, secondEvent.getEventName());
    assertEquals("innerTask", secondEvent.getActivityId());
    assertEquals(innerTaskInstance.getId(), secondEvent.getActivityInstanceId());
    assertEquals(ExecutionListener.EVENTNAME_START, secondEvent.getEventName());
    RecorderExecutionListener.clear();
    runtimeService.createProcessInstanceModification(processInstance.getId()).cancelActivityInstance(innerTaskInstance.getId()).execute();
    assertEquals(2, RecorderExecutionListener.getRecordedEvents().size());
}
Also used : ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) RecorderExecutionListener(org.camunda.bpm.engine.test.bpmn.executionlistener.RecorderExecutionListener) RecordedEvent(org.camunda.bpm.engine.test.bpmn.executionlistener.RecorderExecutionListener.RecordedEvent) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 8 with RecorderExecutionListener

use of org.camunda.bpm.engine.test.bpmn.executionlistener.RecorderExecutionListener in project camunda-bpm-platform by camunda.

the class ProcessInstanceModificationTest method testStartTransitionListenerInvocation.

@Deployment(resources = TRANSITION_LISTENER_PROCESS)
public void testStartTransitionListenerInvocation() {
    RecorderExecutionListener.clear();
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("transitionListenerProcess", Variables.createVariables().putValue("listener", new RecorderExecutionListener()));
    runtimeService.createProcessInstanceModification(instance.getId()).startTransition("flow2").execute();
    // transition listener should have been invoked
    List<RecordedEvent> events = RecorderExecutionListener.getRecordedEvents();
    assertEquals(1, events.size());
    RecordedEvent event = events.get(0);
    assertEquals("flow2", event.getTransitionId());
    RecorderExecutionListener.clear();
    ActivityInstance updatedTree = runtimeService.getActivityInstance(instance.getId());
    assertNotNull(updatedTree);
    assertEquals(instance.getId(), updatedTree.getProcessInstanceId());
    assertThat(updatedTree).hasStructure(describeActivityInstanceTree(instance.getProcessDefinitionId()).activity("task1").activity("task2").done());
    ExecutionTree executionTree = ExecutionTree.forExecution(instance.getId(), processEngine);
    assertThat(executionTree).matches(describeExecutionTree(null).scope().child("task1").concurrent().noScope().up().child("task2").concurrent().noScope().done());
    completeTasksInOrder("task1", "task2", "task2");
    assertProcessEnded(instance.getId());
}
Also used : ExecutionAssert.describeExecutionTree(org.camunda.bpm.engine.test.util.ExecutionAssert.describeExecutionTree) ExecutionTree(org.camunda.bpm.engine.test.util.ExecutionTree) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) RecorderExecutionListener(org.camunda.bpm.engine.test.bpmn.executionlistener.RecorderExecutionListener) RecordedEvent(org.camunda.bpm.engine.test.bpmn.executionlistener.RecorderExecutionListener.RecordedEvent) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 9 with RecorderExecutionListener

use of org.camunda.bpm.engine.test.bpmn.executionlistener.RecorderExecutionListener in project camunda-bpm-platform by camunda.

the class ProcessInstanceModificationTest method testStartAfterActivityListenerInvocation.

@Deployment(resources = TRANSITION_LISTENER_PROCESS)
public void testStartAfterActivityListenerInvocation() {
    RecorderExecutionListener.clear();
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("transitionListenerProcess", Variables.createVariables().putValue("listener", new RecorderExecutionListener()));
    runtimeService.createProcessInstanceModification(instance.getId()).startTransition("flow2").execute();
    // transition listener should have been invoked
    List<RecordedEvent> events = RecorderExecutionListener.getRecordedEvents();
    assertEquals(1, events.size());
    RecordedEvent event = events.get(0);
    assertEquals("flow2", event.getTransitionId());
    RecorderExecutionListener.clear();
    ActivityInstance updatedTree = runtimeService.getActivityInstance(instance.getId());
    assertNotNull(updatedTree);
    assertEquals(instance.getId(), updatedTree.getProcessInstanceId());
    assertThat(updatedTree).hasStructure(describeActivityInstanceTree(instance.getProcessDefinitionId()).activity("task1").activity("task2").done());
    ExecutionTree executionTree = ExecutionTree.forExecution(instance.getId(), processEngine);
    assertThat(executionTree).matches(describeExecutionTree(null).scope().child("task1").concurrent().noScope().up().child("task2").concurrent().noScope().done());
    completeTasksInOrder("task1", "task2", "task2");
    assertProcessEnded(instance.getId());
}
Also used : ExecutionAssert.describeExecutionTree(org.camunda.bpm.engine.test.util.ExecutionAssert.describeExecutionTree) ExecutionTree(org.camunda.bpm.engine.test.util.ExecutionTree) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) RecorderExecutionListener(org.camunda.bpm.engine.test.bpmn.executionlistener.RecorderExecutionListener) RecordedEvent(org.camunda.bpm.engine.test.bpmn.executionlistener.RecorderExecutionListener.RecordedEvent) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 10 with RecorderExecutionListener

use of org.camunda.bpm.engine.test.bpmn.executionlistener.RecorderExecutionListener in project camunda-bpm-platform by camunda.

the class ProcessInstanceModificationAsyncTest method testCancelAsyncAfterTransitionInstanceInvokesParentListeners.

@Deployment
public void testCancelAsyncAfterTransitionInstanceInvokesParentListeners() {
    RecorderExecutionListener.clear();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("nestedOneTaskProcess", Variables.createVariables().putValue("listener", new RecorderExecutionListener()));
    String processInstanceId = processInstance.getId();
    ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId());
    runtimeService.createProcessInstanceModification(processInstanceId).cancelTransitionInstance(getChildTransitionInstanceForTargetActivity(tree, "subProcessEnd").getId()).execute();
    assertEquals(1, RecorderExecutionListener.getRecordedEvents().size());
    RecordedEvent event = RecorderExecutionListener.getRecordedEvents().get(0);
    assertEquals("subProcess", event.getActivityId());
    RecorderExecutionListener.clear();
}
Also used : ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) RecorderExecutionListener(org.camunda.bpm.engine.test.bpmn.executionlistener.RecorderExecutionListener) RecordedEvent(org.camunda.bpm.engine.test.bpmn.executionlistener.RecorderExecutionListener.RecordedEvent) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)10 Deployment (org.camunda.bpm.engine.test.Deployment)10 RecorderExecutionListener (org.camunda.bpm.engine.test.bpmn.executionlistener.RecorderExecutionListener)10 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)7 RecordedEvent (org.camunda.bpm.engine.test.bpmn.executionlistener.RecorderExecutionListener.RecordedEvent)6 ExecutionAssert.describeExecutionTree (org.camunda.bpm.engine.test.util.ExecutionAssert.describeExecutionTree)2 ExecutionTree (org.camunda.bpm.engine.test.util.ExecutionTree)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2