org.camunda.bpm.engine.runtime.EventSubscription

Here are the examples of the java api class org.camunda.bpm.engine.runtime.EventSubscription taken from open source projects.

1. MessageBoundaryEventTest#testBoundaryMessageEventConcurrent()

Project: camunda-bpm-platform
File: MessageBoundaryEventTest.java
/**
   * Triggering one boundary event should not remove the event subscription
   * of a boundary event for a concurrent task
   */
@Deployment
public void testBoundaryMessageEventConcurrent() {
    runtimeService.startProcessInstanceByKey("boundaryEvent");
    EventSubscription eventSubscriptionTask1 = runtimeService.createEventSubscriptionQuery().activityId("messageBoundary1").singleResult();
    assertNotNull(eventSubscriptionTask1);
    EventSubscription eventSubscriptionTask2 = runtimeService.createEventSubscriptionQuery().activityId("messageBoundary2").singleResult();
    assertNotNull(eventSubscriptionTask2);
    // when I trigger the boundary event for task1
    runtimeService.correlateMessage("task1Message");
    // then the event subscription for task2 still exists
    assertEquals(1, runtimeService.createEventSubscriptionQuery().count());
    assertNotNull(runtimeService.createEventSubscriptionQuery().activityId("messageBoundary2").singleResult());
}

2. ProcessInstanceModificationCancellationTest#testProcessInstanceEventSubscriptionsPreservedOnIntermediateCancellation()

Project: camunda-bpm-platform
File: ProcessInstanceModificationCancellationTest.java
@Deployment(resources = INTERRUPTING_EVENT_SUBPROCESS)
public void testProcessInstanceEventSubscriptionsPreservedOnIntermediateCancellation() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");
    // event subscription for the event subprocess
    EventSubscription subscription = runtimeService.createEventSubscriptionQuery().singleResult();
    assertNotNull(subscription);
    assertEquals(processInstance.getId(), subscription.getProcessInstanceId());
    // when I execute cancellation and then start, such that the intermediate state of the process instance
    // has no activities
    ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId());
    runtimeService.createProcessInstanceModification(processInstance.getId()).cancelActivityInstance(getInstanceIdForActivity(tree, "task1")).startBeforeActivity("task1").execute();
    // then the message event subscription remains (i.e. it is not deleted and later re-created)
    EventSubscription updatedSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
    assertNotNull(updatedSubscription);
    assertEquals(subscription.getId(), updatedSubscription.getId());
    assertEquals(subscription.getProcessInstanceId(), updatedSubscription.getProcessInstanceId());
}

3. MigrationReceiveTaskTest#testMigrateEventSubscriptionProperties()

Project: camunda-bpm-platform
File: MigrationReceiveTaskTest.java
@Test
public void testMigrateEventSubscriptionProperties() {
    // given
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(MessageReceiveModels.ONE_RECEIVE_TASK_PROCESS);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(MessageReceiveModels.ONE_RECEIVE_TASK_PROCESS);
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("receiveTask", "receiveTask").build();
    // when
    testHelper.createProcessInstanceAndMigrate(migrationPlan);
    // then
    EventSubscription eventSubscriptionBefore = testHelper.snapshotBeforeMigration.getEventSubscriptions().get(0);
    List<EventSubscription> eventSubscriptionsAfter = testHelper.snapshotAfterMigration.getEventSubscriptions();
    Assert.assertEquals(1, eventSubscriptionsAfter.size());
    EventSubscription eventSubscriptionAfter = eventSubscriptionsAfter.get(0);
    Assert.assertEquals(eventSubscriptionBefore.getCreated(), eventSubscriptionAfter.getCreated());
    Assert.assertEquals(eventSubscriptionBefore.getExecutionId(), eventSubscriptionAfter.getExecutionId());
    Assert.assertEquals(eventSubscriptionBefore.getProcessInstanceId(), eventSubscriptionAfter.getProcessInstanceId());
}

4. EventSubscriptionQueryTest#testMultipleEventSubscriptions()

Project: camunda-bpm-platform
File: EventSubscriptionQueryTest.java
@Deployment
public void testMultipleEventSubscriptions() {
    String message = "cancelation-requested";
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess");
    assertTrue(areJobsAvailable());
    long eventSubscriptionCount = runtimeService.createEventSubscriptionQuery().count();
    assertEquals(2, eventSubscriptionCount);
    EventSubscription messageEvent = runtimeService.createEventSubscriptionQuery().eventType("message").singleResult();
    assertEquals(message, messageEvent.getEventName());
    EventSubscription compensationEvent = runtimeService.createEventSubscriptionQuery().eventType("compensate").singleResult();
    assertNull(compensationEvent.getEventName());
    runtimeService.createMessageCorrelation(message).processInstanceId(processInstance.getId()).correlate();
    assertProcessEnded(processInstance.getId());
}

5. InvocationContextTest#testInvokeProcessApplicationWithContextOnMessageReceived()

Project: camunda-bpm-platform
File: InvocationContextTest.java
@Test
@OperateOnDeployment("app")
public void testInvokeProcessApplicationWithContextOnMessageReceived() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("messageProcess");
    ProcessApplicationWithInvocationContext.clearInvocationContext();
    EventSubscription messageSubscription = runtimeService.createEventSubscriptionQuery().eventType("message").processInstanceId(processInstance.getId()).singleResult();
    assertThat(messageSubscription, is(notNullValue()));
    runtimeService.messageEventReceived(messageSubscription.getEventName(), messageSubscription.getExecutionId());
    InvocationContext invocationContext = ProcessApplicationWithInvocationContext.getInvocationContext();
    assertThat(invocationContext, is(notNullValue()));
    assertThat(invocationContext.getExecution(), is(notNullValue()));
    assertThat(invocationContext.getExecution().getId(), is(messageSubscription.getExecutionId()));
}

6. MockProvider#createMockEventSubscription()

Project: camunda-bpm-platform
File: MockProvider.java
public static EventSubscription createMockEventSubscription() {
    EventSubscription mock = mock(EventSubscription.class);
    when(mock.getId()).thenReturn(EXAMPLE_EVENT_SUBSCRIPTION_ID);
    when(mock.getEventType()).thenReturn(EXAMPLE_EVENT_SUBSCRIPTION_TYPE);
    when(mock.getEventName()).thenReturn(EXAMPLE_EVENT_SUBSCRIPTION_NAME);
    when(mock.getExecutionId()).thenReturn(EXAMPLE_EXECUTION_ID);
    when(mock.getProcessInstanceId()).thenReturn(EXAMPLE_PROCESS_INSTANCE_ID);
    when(mock.getActivityId()).thenReturn(EXAMPLE_ACTIVITY_ID);
    when(mock.getCreated()).thenReturn(DateTimeUtil.parseDate(EXAMPLE_EVENT_SUBSCRIPTION_CREATION_DATE));
    when(mock.getTenantId()).thenReturn(EXAMPLE_TENANT_ID);
    return mock;
}

7. MessageEventSubscriptionResource#getEventSubscription()

Project: camunda-bpm-platform
File: MessageEventSubscriptionResource.java
@Override
public EventSubscriptionDto getEventSubscription() {
    RuntimeService runtimeService = engine.getRuntimeService();
    EventSubscription eventSubscription = runtimeService.createEventSubscriptionQuery().executionId(executionId).eventName(messageName).eventType(MESSAGE_EVENT_TYPE).singleResult();
    if (eventSubscription == null) {
        String errorMessage = String.format("Message event subscription for execution %s named %s does not exist", executionId, messageName);
        throw new InvalidRequestException(Status.NOT_FOUND, errorMessage);
    }
    return EventSubscriptionDto.fromEventSubscription(eventSubscription);
}

8. ReceiveTaskTest#testSupportsMessageEventReceivedOnSubProcessReceiveTask()

Project: camunda-bpm-platform
File: ReceiveTaskTest.java
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/receivetask/ReceiveTaskTest.subProcessReceiveTask.bpmn20.xml")
public void testSupportsMessageEventReceivedOnSubProcessReceiveTask() {
    // given: a process instance waiting in the sub-process receive task
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess");
    // expect: there is a message event subscription for the task
    List<EventSubscription> subscriptionList = getEventSubscriptionList();
    assertEquals(1, subscriptionList.size());
    EventSubscription subscription = subscriptionList.get(0);
    // then: we can trigger the event subscription
    runtimeService.messageEventReceived(subscription.getEventName(), subscription.getExecutionId());
    // expect: subscription is removed
    assertEquals(0, getEventSubscriptionList().size());
    // expect: this ends the process instance
    assertProcessEnded(processInstance.getId());
}

9. ReceiveTaskTest#testSupportsMessageEventReceivedOnParallelMultiInstanceWithBoundaryEventReceived()

Project: camunda-bpm-platform
File: ReceiveTaskTest.java
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/receivetask/ReceiveTaskTest.multiParallelReceiveTaskBoundary.bpmn20.xml")
public void testSupportsMessageEventReceivedOnParallelMultiInstanceWithBoundaryEventReceived() {
    // given: a process instance waiting in two receive tasks
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess");
    // expect: there are three message event subscriptions
    assertEquals(3, getEventSubscriptionList().size());
    // expect: there is one message event subscription for the boundary event
    List<EventSubscription> subscriptions = getEventSubscriptionList("cancel");
    assertEquals(1, subscriptions.size());
    EventSubscription subscription = subscriptions.get(0);
    // then: we can trigger the boundary subscription to cancel both tasks
    runtimeService.messageEventReceived(subscription.getEventName(), subscription.getExecutionId());
    // expect: all subscriptions are removed (receive task subscriptions too)
    assertEquals(0, getEventSubscriptionList().size());
    // expect: this ends the process instance
    assertProcessEnded(processInstance.getId());
}

10. ReceiveTaskTest#testSupportsCorrelateMessageOnSingleReceiveTask()

Project: camunda-bpm-platform
File: ReceiveTaskTest.java
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/receivetask/ReceiveTaskTest.singleReceiveTask.bpmn20.xml")
public void testSupportsCorrelateMessageOnSingleReceiveTask() {
    // given: a process instance waiting in the receive task
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess");
    // expect: there is a message event subscription for the task
    List<EventSubscription> subscriptionList = getEventSubscriptionList();
    assertEquals(1, subscriptionList.size());
    EventSubscription subscription = subscriptionList.get(0);
    // then: we can correlate the event subscription
    runtimeService.correlateMessage(subscription.getEventName());
    // expect: subscription is removed
    assertEquals(0, getEventSubscriptionList().size());
    // expect: this ends the process instance
    assertProcessEnded(processInstance.getId());
}

11. ReceiveTaskTest#testSupportsMessageEventReceivedOnSingleReceiveTask()

Project: camunda-bpm-platform
File: ReceiveTaskTest.java
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/receivetask/ReceiveTaskTest.singleReceiveTask.bpmn20.xml")
public void testSupportsMessageEventReceivedOnSingleReceiveTask() {
    // given: a process instance waiting in the receive task
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess");
    // expect: there is a message event subscription for the task
    List<EventSubscription> subscriptionList = getEventSubscriptionList();
    assertEquals(1, subscriptionList.size());
    EventSubscription subscription = subscriptionList.get(0);
    // then: we can trigger the event subscription
    runtimeService.messageEventReceived(subscription.getEventName(), subscription.getExecutionId());
    // expect: subscription is removed
    assertEquals(0, getEventSubscriptionList().size());
    // expect: this ends the process instance
    assertProcessEnded(processInstance.getId());
}

12. SignalEventReceivedBuilderTest#testSendSignalWithExecutionId()

Project: camunda-bpm-platform
File: SignalEventReceivedBuilderTest.java
public void testSendSignalWithExecutionId() {
    deployment(signalCatchProcess("signalCatch"), signalCatchProcess("signalCatch2"));
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("signalCatch");
    runtimeService.startProcessInstanceByKey("signalCatch2");
    EventSubscription eventSubscription = runtimeService.createEventSubscriptionQuery().processInstanceId(processInstance.getId()).singleResult();
    String executionId = eventSubscription.getExecutionId();
    runtimeService.createSignalEvent("signal").executionId(executionId).send();
    assertThat(taskService.createTaskQuery().count(), is(1L));
}

13. SignalEventDeploymentTest#testCreateEventSubscriptionOnDeployment()

Project: camunda-bpm-platform
File: SignalEventDeploymentTest.java
public void testCreateEventSubscriptionOnDeployment() {
    deploymentId = repositoryService.createDeployment().addClasspathResource(SIGNAL_START_EVENT_PROCESS).deploy().getId();
    EventSubscription eventSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
    assertNotNull(eventSubscription);
    assertEquals("signal", eventSubscription.getEventType());
    assertEquals("alert", eventSubscription.getEventName());
    assertEquals("start", eventSubscription.getActivityId());
}

14. BoundaryErrorEventTest#testCatchErrorOnSubprocessThrownByNestedEventSubprocess()

Project: camunda-bpm-platform
File: BoundaryErrorEventTest.java
@Deployment
public void testCatchErrorOnSubprocessThrownByNestedEventSubprocess() {
    runtimeService.startProcessInstanceByKey("testProcess");
    // trigger outer event subprocess
    EventSubscription messageSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
    runtimeService.messageEventReceived("outerMessage", messageSubscription.getExecutionId());
    // trigger inner event subprocess
    messageSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
    runtimeService.messageEventReceived("innerMessage", messageSubscription.getExecutionId());
    // should successfully have reached the task following the boundary event
    Execution taskExecution = runtimeService.createExecutionQuery().activityId("afterBoundaryTask").singleResult();
    assertNotNull(taskExecution);
    Task task = taskService.createTaskQuery().executionId(taskExecution.getId()).singleResult();
    assertNotNull(task);
}

15. BoundaryErrorEventTest#testCatchErrorOnSubprocessThrownByInterruptingEventSubprocess()

Project: camunda-bpm-platform
File: BoundaryErrorEventTest.java
@Deployment
public void testCatchErrorOnSubprocessThrownByInterruptingEventSubprocess() {
    runtimeService.startProcessInstanceByKey("testProcess");
    EventSubscription messageSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
    runtimeService.messageEventReceived("message", messageSubscription.getExecutionId());
    // should successfully have reached the task following the boundary event
    Execution taskExecution = runtimeService.createExecutionQuery().activityId("afterBoundaryTask").singleResult();
    assertNotNull(taskExecution);
    Task task = taskService.createTaskQuery().executionId(taskExecution.getId()).singleResult();
    assertNotNull(task);
}

16. BoundaryErrorEventTest#testCatchErrorOnSubprocessThrownByNonInterruptingEventSubprocess()

Project: camunda-bpm-platform
File: BoundaryErrorEventTest.java
@Deployment
public void testCatchErrorOnSubprocessThrownByNonInterruptingEventSubprocess() {
    runtimeService.startProcessInstanceByKey("testProcess");
    EventSubscription messageSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
    runtimeService.messageEventReceived("message", messageSubscription.getExecutionId());
    // should successfully have reached the task following the boundary event
    Execution taskExecution = runtimeService.createExecutionQuery().activityId("afterBoundaryTask").singleResult();
    assertNotNull(taskExecution);
    Task task = taskService.createTaskQuery().executionId(taskExecution.getId()).singleResult();
    assertNotNull(task);
}

17. ProcessInstanceSuspensionTest#testMessageEventReceiveFailAfterSuspendByProcessDefinitionKey()

Project: camunda-bpm-platform
File: ProcessInstanceSuspensionTest.java
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/ProcessInstanceSuspensionTest.testMessageEventReceiveFailAfterSuspend.bpmn20.xml" })
public void testMessageEventReceiveFailAfterSuspendByProcessDefinitionKey() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    runtimeService.startProcessInstanceById(processDefinition.getId());
    runtimeService.suspendProcessInstanceByProcessDefinitionKey(processDefinition.getKey());
    EventSubscription subscription = runtimeService.createEventSubscriptionQuery().singleResult();
    try {
        runtimeService.messageEventReceived("someMessage", subscription.getExecutionId());
        fail();
    } catch (SuspendedEntityInteractionException e) {
        assertTextPresent("is suspended", e.getMessage());
    }
    try {
        runtimeService.messageEventReceived("someMessage", subscription.getExecutionId(), new HashMap<String, Object>());
        fail();
    } catch (SuspendedEntityInteractionException e) {
        assertTextPresent("is suspended", e.getMessage());
    }
}

18. ProcessInstanceSuspensionTest#testMessageEventReceiveFailAfterSuspendByProcessDefinitionId()

Project: camunda-bpm-platform
File: ProcessInstanceSuspensionTest.java
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/ProcessInstanceSuspensionTest.testMessageEventReceiveFailAfterSuspend.bpmn20.xml" })
public void testMessageEventReceiveFailAfterSuspendByProcessDefinitionId() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    runtimeService.startProcessInstanceById(processDefinition.getId());
    runtimeService.suspendProcessInstanceByProcessDefinitionId(processDefinition.getId());
    EventSubscription subscription = runtimeService.createEventSubscriptionQuery().singleResult();
    try {
        runtimeService.messageEventReceived("someMessage", subscription.getExecutionId());
        fail();
    } catch (SuspendedEntityInteractionException e) {
        assertTextPresent("is suspended", e.getMessage());
    }
    try {
        runtimeService.messageEventReceived("someMessage", subscription.getExecutionId(), new HashMap<String, Object>());
        fail();
    } catch (SuspendedEntityInteractionException e) {
        assertTextPresent("is suspended", e.getMessage());
    }
}

19. ProcessInstanceSuspensionTest#testMessageEventReceiveFailAfterSuspend()

Project: camunda-bpm-platform
File: ProcessInstanceSuspensionTest.java
@Deployment
public void testMessageEventReceiveFailAfterSuspend() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    EventSubscription subscription = runtimeService.createEventSubscriptionQuery().singleResult();
    try {
        runtimeService.messageEventReceived("someMessage", subscription.getExecutionId());
        fail();
    } catch (SuspendedEntityInteractionException e) {
        assertTextPresent("is suspended", e.getMessage());
    }
    try {
        runtimeService.messageEventReceived("someMessage", subscription.getExecutionId(), new HashMap<String, Object>());
        fail();
    } catch (SuspendedEntityInteractionException e) {
        assertTextPresent("is suspended", e.getMessage());
    }
}

20. ProcessInstanceSnapshot#getEventSubscriptionsForActivityIdAndEventName()

Project: camunda-bpm-platform
File: ProcessInstanceSnapshot.java
public List<EventSubscription> getEventSubscriptionsForActivityIdAndEventName(String activityId, String eventName) {
    List<EventSubscription> collectedEventsubscriptions = new ArrayList<EventSubscription>();
    for (EventSubscription eventSubscription : getEventSubscriptions()) {
        if (activityId.equals(eventSubscription.getActivityId())) {
            if ((eventName == null && eventSubscription.getEventName() == null) || eventName != null && eventName.equals(eventSubscription.getEventName())) {
                collectedEventsubscriptions.add(eventSubscription);
            }
        }
    }
    return collectedEventsubscriptions;
}

21. EventSubscriptionQueryTest#testQueryByEventSubscriptionId()

Project: camunda-bpm-platform
File: EventSubscriptionQueryTest.java
public void testQueryByEventSubscriptionId() {
    createExampleEventSubscriptions();
    List<EventSubscription> list = runtimeService.createEventSubscriptionQuery().eventName("messageName2").list();
    assertEquals(1, list.size());
    EventSubscription eventSubscription = list.get(0);
    EventSubscriptionQuery query = runtimeService.createEventSubscriptionQuery().eventSubscriptionId(eventSubscription.getId());
    assertEquals(1, query.count());
    assertEquals(1, query.list().size());
    assertNotNull(query.singleResult());
    try {
        runtimeService.createEventSubscriptionQuery().eventSubscriptionId(null).list();
        fail("Expected ProcessEngineException");
    } catch (ProcessEngineException e) {
    }
    cleanDb();
}

22. MultiTenancyExecutionPropagationTest#testPropagateTenantIdToCompensationEventSubscription()

Project: camunda-bpm-platform
File: MultiTenancyExecutionPropagationTest.java
public void testPropagateTenantIdToCompensationEventSubscription() {
    deploymentForTenant(TENANT_ID, "org/camunda/bpm/engine/test/api/multitenancy/compensationBoundaryEvent.bpmn");
    startProcessInstance(PROCESS_DEFINITION_KEY);
    // the event subscription is created after execute the activity with the attached compensation boundary event
    EventSubscription eventSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
    assertThat(eventSubscription, is(notNullValue()));
    // inherit the tenant id from process instance
    assertThat(eventSubscription.getTenantId(), is(TENANT_ID));
}

23. MultiTenancyExecutionPropagationTest#testPropagateTenantIdToIntermediateSignalEventSubscription()

Project: camunda-bpm-platform
File: MultiTenancyExecutionPropagationTest.java
public void testPropagateTenantIdToIntermediateSignalEventSubscription() {
    deploymentForTenant(TENANT_ID, Bpmn.createExecutableProcess(PROCESS_DEFINITION_KEY).startEvent().intermediateCatchEvent().signal("start").endEvent().done());
    startProcessInstance(PROCESS_DEFINITION_KEY);
    EventSubscription eventSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
    assertThat(eventSubscription, is(notNullValue()));
    // inherit the tenant id from process instance
    assertThat(eventSubscription.getTenantId(), is(TENANT_ID));
}

24. MultiTenancyExecutionPropagationTest#testPropagateTenantIdToIntermediateMessageEventSubscription()

Project: camunda-bpm-platform
File: MultiTenancyExecutionPropagationTest.java
public void testPropagateTenantIdToIntermediateMessageEventSubscription() {
    deploymentForTenant(TENANT_ID, Bpmn.createExecutableProcess(PROCESS_DEFINITION_KEY).startEvent().intermediateCatchEvent().message("start").endEvent().done());
    startProcessInstance(PROCESS_DEFINITION_KEY);
    EventSubscription eventSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
    assertThat(eventSubscription, is(notNullValue()));
    // inherit the tenant id from process instance
    assertThat(eventSubscription.getTenantId(), is(TENANT_ID));
}

25. MultiTenancyExecutionPropagationTest#testPropagateTenantIdToStartSignalEventSubscription()

Project: camunda-bpm-platform
File: MultiTenancyExecutionPropagationTest.java
public void testPropagateTenantIdToStartSignalEventSubscription() {
    deploymentForTenant(TENANT_ID, Bpmn.createExecutableProcess(PROCESS_DEFINITION_KEY).startEvent().signal("start").endEvent().done());
    // the event subscription of the signal start event is created on deployment
    EventSubscription eventSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
    assertThat(eventSubscription, is(notNullValue()));
    // inherit the tenant id from process definition
    assertThat(eventSubscription.getTenantId(), is(TENANT_ID));
}

26. MultiTenancyExecutionPropagationTest#testPropagateTenantIdToStartMessageEventSubscription()

Project: camunda-bpm-platform
File: MultiTenancyExecutionPropagationTest.java
public void testPropagateTenantIdToStartMessageEventSubscription() {
    deploymentForTenant(TENANT_ID, Bpmn.createExecutableProcess(PROCESS_DEFINITION_KEY).startEvent().message("start").endEvent().done());
    // the event subscription of the message start is created on deployment
    EventSubscription eventSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
    assertThat(eventSubscription, is(notNullValue()));
    // inherit the tenant id from process definition
    assertThat(eventSubscription.getTenantId(), is(TENANT_ID));
}

27. EventSubscriptionAuthorizationTest#testQueryWithReadPermissionOnProcessInstance()

Project: camunda-bpm-platform
File: EventSubscriptionAuthorizationTest.java
public void testQueryWithReadPermissionOnProcessInstance() {
    // given
    startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
    startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
    String processInstanceId = startProcessInstanceByKey(ONE_TASK_PROCESS_KEY).getId();
    startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
    startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
    startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
    startProcessInstanceByKey(SIGNAL_BOUNDARY_PROCESS_KEY);
    createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, READ);
    // when
    EventSubscriptionQuery query = runtimeService.createEventSubscriptionQuery();
    // then
    verifyQueryResults(query, 1);
    EventSubscription eventSubscription = query.singleResult();
    assertNotNull(eventSubscription);
    assertEquals(processInstanceId, eventSubscription.getProcessInstanceId());
}

28. EventSubscriptionAuthorizationTest#testSimpleQueryWithReadInstancesPermissionOnAnyProcessDefinition()

Project: camunda-bpm-platform
File: EventSubscriptionAuthorizationTest.java
public void testSimpleQueryWithReadInstancesPermissionOnAnyProcessDefinition() {
    // given
    String processInstanceId = startProcessInstanceByKey(ONE_TASK_PROCESS_KEY).getId();
    createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, READ_INSTANCE);
    // when
    EventSubscriptionQuery query = runtimeService.createEventSubscriptionQuery();
    // then
    verifyQueryResults(query, 1);
    EventSubscription eventSubscription = query.singleResult();
    assertNotNull(eventSubscription);
    assertEquals(processInstanceId, eventSubscription.getProcessInstanceId());
}

29. EventSubscriptionAuthorizationTest#testSimpleQueryWithReadInstancesPermissionOnOneTaskProcess()

Project: camunda-bpm-platform
File: EventSubscriptionAuthorizationTest.java
public void testSimpleQueryWithReadInstancesPermissionOnOneTaskProcess() {
    // given
    String processInstanceId = startProcessInstanceByKey(ONE_TASK_PROCESS_KEY).getId();
    createGrantAuthorization(PROCESS_DEFINITION, ONE_TASK_PROCESS_KEY, userId, READ_INSTANCE);
    // when
    EventSubscriptionQuery query = runtimeService.createEventSubscriptionQuery();
    // then
    verifyQueryResults(query, 1);
    EventSubscription eventSubscription = query.singleResult();
    assertNotNull(eventSubscription);
    assertEquals(processInstanceId, eventSubscription.getProcessInstanceId());
}

30. EventSubscriptionAuthorizationTest#testSimpleQueryWithReadPermissionOnAnyProcessInstance()

Project: camunda-bpm-platform
File: EventSubscriptionAuthorizationTest.java
public void testSimpleQueryWithReadPermissionOnAnyProcessInstance() {
    // given
    String processInstanceId = startProcessInstanceByKey(ONE_TASK_PROCESS_KEY).getId();
    createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, READ);
    // when
    EventSubscriptionQuery query = runtimeService.createEventSubscriptionQuery();
    // then
    verifyQueryResults(query, 1);
    EventSubscription eventSubscription = query.singleResult();
    assertNotNull(eventSubscription);
    assertEquals(processInstanceId, eventSubscription.getProcessInstanceId());
}

31. EventSubscriptionAuthorizationTest#testSimpleQueryWithReadPermissionOnProcessInstance()

Project: camunda-bpm-platform
File: EventSubscriptionAuthorizationTest.java
public void testSimpleQueryWithReadPermissionOnProcessInstance() {
    // given
    String processInstanceId = startProcessInstanceByKey(ONE_TASK_PROCESS_KEY).getId();
    createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, READ);
    // when
    EventSubscriptionQuery query = runtimeService.createEventSubscriptionQuery();
    // then
    verifyQueryResults(query, 1);
    EventSubscription eventSubscription = query.singleResult();
    assertNotNull(eventSubscription);
    assertEquals(processInstanceId, eventSubscription.getProcessInstanceId());
}

32. ProcessInstanceModificationEventTest#testStartBeforeMessageStartEvent()

Project: camunda-bpm-platform
File: ProcessInstanceModificationEventTest.java
@Deployment(resources = MESSAGE_START_EVENT_PROCESS)
public void testStartBeforeMessageStartEvent() {
    runtimeService.correlateMessage("startMessage");
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertNotNull(processInstance);
    EventSubscription startEventSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
    assertNotNull(startEventSubscription);
    String processInstanceId = processInstance.getId();
    // when I start before the message start event
    runtimeService.createProcessInstanceModification(processInstanceId).startBeforeActivity("theStart").execute();
    // then there are two instances of "task"
    ActivityInstance updatedTree = runtimeService.getActivityInstance(processInstanceId);
    assertNotNull(updatedTree);
    assertEquals(processInstanceId, updatedTree.getProcessInstanceId());
    assertThat(updatedTree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("task").activity("task").done());
    ExecutionTree executionTree = ExecutionTree.forExecution(processInstanceId, processEngine);
    assertThat(executionTree).matches(describeExecutionTree(null).scope().child("task").concurrent().noScope().up().child("task").concurrent().noScope().done());
    // and there is only the message start event subscription
    EventSubscription subscription = runtimeService.createEventSubscriptionQuery().singleResult();
    assertNotNull(subscription);
    assertEquals(startEventSubscription.getId(), subscription.getId());
    completeTasksInOrder("task", "task");
    assertProcessEnded(processInstanceId);
}

33. MigrationTestRule#assertEventSubscriptionCreated()

Project: camunda-bpm-platform
File: MigrationTestRule.java
public void assertEventSubscriptionCreated(String activityId, String eventName) {
    EventSubscription eventSubscriptionAfter = snapshotAfterMigration.getEventSubscriptionForActivityIdAndEventName(activityId, eventName);
    assertNotNull("Expected an event subscription for activity '" + activityId + "' after the migration", eventSubscriptionAfter);
    for (EventSubscription eventSubscription : snapshotBeforeMigration.getEventSubscriptions()) {
        if (eventSubscriptionAfter.getId().equals(eventSubscription.getId())) {
            fail("Expected event subscription '" + eventSubscriptionAfter.getId() + "' to be created after migration");
        }
    }
}

34. MigrationTestRule#assertEventSubscriptionRemoved()

Project: camunda-bpm-platform
File: MigrationTestRule.java
public void assertEventSubscriptionRemoved(String activityId, String eventName) {
    EventSubscription eventSubscriptionBefore = snapshotBeforeMigration.getEventSubscriptionForActivityIdAndEventName(activityId, eventName);
    assertNotNull("Expected an event subscription for activity '" + activityId + "' before the migration", eventSubscriptionBefore);
    for (EventSubscription eventSubscription : snapshotAfterMigration.getEventSubscriptions()) {
        if (eventSubscriptionBefore.getId().equals(eventSubscription.getId())) {
            fail("Expected event subscription '" + eventSubscriptionBefore.getId() + "' to be removed after migration");
        }
    }
}

35. EventSubscriptionQueryTest#testQueryByExecutionId()

Project: camunda-bpm-platform
File: EventSubscriptionQueryTest.java
@Deployment
public void testQueryByExecutionId() {
    // starting two instances:
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("catchSignal");
    runtimeService.startProcessInstanceByKey("catchSignal");
    // test query by process instance id
    EventSubscription subscription = runtimeService.createEventSubscriptionQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(subscription);
    Execution executionWaitingForSignal = runtimeService.createExecutionQuery().activityId("signalEvent").processInstanceId(processInstance.getId()).singleResult();
    // test query by execution id
    EventSubscription signalSubscription = runtimeService.createEventSubscriptionQuery().executionId(executionWaitingForSignal.getId()).singleResult();
    assertNotNull(signalSubscription);
    assertEquals(signalSubscription, subscription);
    try {
        runtimeService.createEventSubscriptionQuery().executionId(null).list();
        fail("Expected ProcessEngineException");
    } catch (ProcessEngineException e) {
    }
    cleanDb();
}

36. ExecutionRestServiceInteractionTest#mockEventSubscriptionQuery()

Project: camunda-bpm-platform
File: ExecutionRestServiceInteractionTest.java
private void mockEventSubscriptionQuery() {
    EventSubscription mockSubscription = MockProvider.createMockEventSubscription();
    EventSubscriptionQuery mockQuery = mock(EventSubscriptionQuery.class);
    when(runtimeServiceMock.createEventSubscriptionQuery()).thenReturn(mockQuery);
    when(mockQuery.executionId(eq(MockProvider.EXAMPLE_EXECUTION_ID))).thenReturn(mockQuery);
    when(mockQuery.eventType(eq(MockProvider.EXAMPLE_EVENT_SUBSCRIPTION_TYPE))).thenReturn(mockQuery);
    when(mockQuery.eventName(eq(MockProvider.EXAMPLE_EVENT_SUBSCRIPTION_NAME))).thenReturn(mockQuery);
    when(mockQuery.singleResult()).thenReturn(mockSubscription);
}

37. ReceiveTaskTest#testSupportsCorrelateMessageOnSequentialMultiReceiveTask()

Project: camunda-bpm-platform
File: ReceiveTaskTest.java
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/receivetask/ReceiveTaskTest.multiSequentialReceiveTask.bpmn20.xml")
public void testSupportsCorrelateMessageOnSequentialMultiReceiveTask() {
    // given: a process instance waiting in the first receive tasks
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess");
    // expect: there is a message event subscription for the first task
    List<EventSubscription> subscriptionList = getEventSubscriptionList();
    assertEquals(1, subscriptionList.size());
    EventSubscription subscription = subscriptionList.get(0);
    String firstSubscriptionId = subscription.getId();
    // then: we can trigger the event subscription
    runtimeService.correlateMessage(subscription.getEventName());
    // expect: there is a new subscription created for the second receive task instance
    subscriptionList = getEventSubscriptionList();
    assertEquals(1, subscriptionList.size());
    subscription = subscriptionList.get(0);
    assertFalse(firstSubscriptionId.equals(subscription.getId()));
    // then: we can trigger the second event subscription
    runtimeService.correlateMessage(subscription.getEventName());
    // expect: no event subscription left
    assertEquals(0, getEventSubscriptionList().size());
    // expect: one user task is created
    Task task = taskService.createTaskQuery().singleResult();
    taskService.complete(task.getId());
    // expect: this ends the process instance
    assertProcessEnded(processInstance.getId());
}

38. ReceiveTaskTest#testSupportsMessageEventReceivedOnSequentialMultiReceiveTask()

Project: camunda-bpm-platform
File: ReceiveTaskTest.java
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/receivetask/ReceiveTaskTest.multiSequentialReceiveTask.bpmn20.xml")
public void testSupportsMessageEventReceivedOnSequentialMultiReceiveTask() {
    // given: a process instance waiting in the first receive tasks
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess");
    // expect: there is a message event subscription for the first task
    List<EventSubscription> subscriptionList = getEventSubscriptionList();
    assertEquals(1, subscriptionList.size());
    EventSubscription subscription = subscriptionList.get(0);
    String firstSubscriptionId = subscription.getId();
    // then: we can trigger the event subscription
    runtimeService.messageEventReceived(subscription.getEventName(), subscription.getExecutionId());
    // expect: there is a new subscription created for the second receive task instance
    subscriptionList = getEventSubscriptionList();
    assertEquals(1, subscriptionList.size());
    subscription = subscriptionList.get(0);
    assertFalse(firstSubscriptionId.equals(subscription.getId()));
    // then: we can trigger the second event subscription
    runtimeService.messageEventReceived(subscription.getEventName(), subscription.getExecutionId());
    // expect: no event subscription left
    assertEquals(0, getEventSubscriptionList().size());
    // expect: one user task is created
    Task task = taskService.createTaskQuery().singleResult();
    taskService.complete(task.getId());
    // expect: this ends the process instance
    assertProcessEnded(processInstance.getId());
}

39. ReceiveTaskTest#testSupportsLegacySignalingOnSequentialMultiReceiveTask()

Project: camunda-bpm-platform
File: ReceiveTaskTest.java
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/receivetask/ReceiveTaskTest.multiSequentialReceiveTask.bpmn20.xml")
public void testSupportsLegacySignalingOnSequentialMultiReceiveTask() {
    // given: a process instance waiting in the first receive tasks
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess");
    // expect: there is a message event subscription for the first task
    List<EventSubscription> subscriptionList = getEventSubscriptionList();
    assertEquals(1, subscriptionList.size());
    EventSubscription subscription = subscriptionList.get(0);
    String firstSubscriptionId = subscription.getId();
    // then: we can signal the waiting receive task
    runtimeService.signal(getExecutionId(processInstance.getId(), "waitState"));
    // expect: there is a new subscription created for the second receive task instance
    subscriptionList = getEventSubscriptionList();
    assertEquals(1, subscriptionList.size());
    subscription = subscriptionList.get(0);
    assertFalse(firstSubscriptionId.equals(subscription.getId()));
    // then: we can signal the second waiting receive task
    runtimeService.signal(getExecutionId(processInstance.getId(), "waitState"));
    // expect: no event subscription left
    assertEquals(0, getEventSubscriptionList().size());
    // expect: one user task is created
    Task task = taskService.createTaskQuery().singleResult();
    taskService.complete(task.getId());
    // expect: this ends the process instance
    assertProcessEnded(processInstance.getId());
}

40. SignalEventDeploymentTest#testUpdateEventSubscriptionOnDeployment()

Project: camunda-bpm-platform
File: SignalEventDeploymentTest.java
public void testUpdateEventSubscriptionOnDeployment() {
    deploymentId = repositoryService.createDeployment().addClasspathResource(SIGNAL_START_EVENT_PROCESS).deploy().getId();
    EventSubscription eventSubscription = runtimeService.createEventSubscriptionQuery().eventType("signal").singleResult();
    assertNotNull(eventSubscription);
    assertEquals("alert", eventSubscription.getEventName());
    // deploy a new version of the process with different signal name
    String newDeploymentId = repositoryService.createDeployment().addClasspathResource(SIGNAL_START_EVENT_PROCESS_NEW_VERSION).deploy().getId();
    ProcessDefinition newProcessDefinition = repositoryService.createProcessDefinitionQuery().latestVersion().singleResult();
    assertEquals(2, newProcessDefinition.getVersion());
    List<EventSubscription> newEventSubscriptions = runtimeService.createEventSubscriptionQuery().eventType("signal").list();
    // only one event subscription for the new version of the process definition
    assertEquals(1, newEventSubscriptions.size());
    EventSubscriptionEntity newEventSubscription = (EventSubscriptionEntity) newEventSubscriptions.iterator().next();
    assertEquals(newProcessDefinition.getId(), newEventSubscription.getConfiguration());
    assertEquals("abort", newEventSubscription.getEventName());
    // clean db
    repositoryService.deleteDeployment(newDeploymentId);
}

41. MessageIntermediateEventTest#testSetSerializedVariableValues()

Project: camunda-bpm-platform
File: MessageIntermediateEventTest.java
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/event/message/MessageIntermediateEventTest.testSingleIntermediateMessageEvent.bpmn20.xml")
public void testSetSerializedVariableValues() throws IOException, ClassNotFoundException {
    // given
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");
    EventSubscription messageEventSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
    // when
    FailingJavaSerializable javaSerializable = new FailingJavaSerializable("foo");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new ObjectOutputStream(baos).writeObject(javaSerializable);
    String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), processEngine);
    // then it is not possible to deserialize the object
    try {
        new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())).readObject();
    } catch (RuntimeException e) {
        assertTextPresent("Exception while deserializing object.", e.getMessage());
    }
    // but it can be set as a variable when delivering a message:
    runtimeService.messageEventReceived("newInvoiceMessage", messageEventSubscription.getExecutionId(), Variables.createVariables().putValueTyped("var", Variables.serializedObjectValue(serializedObject).objectTypeName(FailingJavaSerializable.class.getName()).serializationDataFormat(SerializationDataFormats.JAVA).create()));
    // then
    ObjectValue variableTyped = runtimeService.getVariableTyped(processInstance.getId(), "var", false);
    assertNotNull(variableTyped);
    assertFalse(variableTyped.isDeserialized());
    assertEquals(serializedObject, variableTyped.getValueSerialized());
    assertEquals(FailingJavaSerializable.class.getName(), variableTyped.getObjectTypeName());
    assertEquals(SerializationDataFormats.JAVA.getName(), variableTyped.getSerializationDataFormat());
}

42. MessageEventSubprocessTest#testNonInterruptingInMultiParallelEmbeddedSubprocess()

Project: camunda-bpm-platform
File: MessageEventSubprocessTest.java
@Deployment
public void testNonInterruptingInMultiParallelEmbeddedSubprocess() {
    // #################### I. start process and only complete the tasks
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");
    // assert execution tree: scope (process) > scope (subprocess) > 2 x subprocess + usertask
    assertEquals(6, runtimeService.createExecutionQuery().count());
    // expect: two subscriptions, one for each instance
    assertEquals(2, runtimeService.createEventSubscriptionQuery().count());
    // expect: two subprocess instances, i.e. two tasks created
    List<Task> tasks = taskService.createTaskQuery().list();
    // then: complete both tasks
    for (Task task : tasks) {
        assertEquals("subUserTask", task.getTaskDefinitionKey());
        taskService.complete(task.getId());
    }
    // expect: the event subscriptions are removed
    assertEquals(0, runtimeService.createEventSubscriptionQuery().count());
    // then: complete the last task of the main process
    taskService.complete(taskService.createTaskQuery().singleResult().getId());
    assertProcessEnded(processInstance.getId());
    // #################### II. start process and correlate messages to trigger subprocesses instantiation
    processInstance = runtimeService.startProcessInstanceByKey("process");
    for (EventSubscription es : runtimeService.createEventSubscriptionQuery().list()) {
        // trigger
        runtimeService.messageEventReceived("message", es.getExecutionId());
    }
    // expect: both subscriptions are remaining and they can be re-triggered as long as the subprocesses are active
    assertEquals(2, runtimeService.createEventSubscriptionQuery().count());
    // expect: two additional task, one for each triggered process
    tasks = taskService.createTaskQuery().taskName("Message User Task").list();
    assertEquals(2, tasks.size());
    for (Task task : tasks) {
        // complete both tasks
        taskService.complete(task.getId());
    }
    // then: complete one subprocess
    taskService.complete(taskService.createTaskQuery().taskName("Sub User Task").list().get(0).getId());
    // expect: only the subscription of the second subprocess instance is left
    assertEquals(1, runtimeService.createEventSubscriptionQuery().count());
    // then: trigger the second subprocess again
    runtimeService.messageEventReceived("message", runtimeService.createEventSubscriptionQuery().singleResult().getExecutionId());
    // expect: one message subprocess task exist
    assertEquals(1, taskService.createTaskQuery().taskName("Message User Task").list().size());
    // then: complete all inner subprocess tasks
    tasks = taskService.createTaskQuery().list();
    for (Task task : tasks) {
        taskService.complete(task.getId());
    }
    // expect: no subscription is left
    assertEquals(0, runtimeService.createEventSubscriptionQuery().count());
    // then: complete the last task of the main process
    taskService.complete(taskService.createTaskQuery().singleResult().getId());
    assertProcessEnded(processInstance.getId());
}

43. CompensateEventTest#FAILING_testReceiveTaskCompensationHandler()

Project: camunda-bpm-platform
File: CompensateEventTest.java
/**
   * CAM-4387
   */
@Deployment
public void FAILING_testReceiveTaskCompensationHandler() {
    // given a process instance
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("receiveTaskCompensationHandler");
    // when triggering compensation
    Task beforeCompensationTask = taskService.createTaskQuery().singleResult();
    taskService.complete(beforeCompensationTask.getId());
    // then there is a message event subscription for the receive task compensation handler
    EventSubscription eventSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
    assertNotNull(eventSubscription);
    assertEquals(MessageEventHandler.EVENT_HANDLER_TYPE, eventSubscription.getEventType());
    // and triggering the message completes compensation
    runtimeService.correlateMessage("Message");
    Task afterCompensationTask = taskService.createTaskQuery().singleResult();
    assertNotNull(afterCompensationTask);
    assertEquals("beforeEnd", afterCompensationTask.getTaskDefinitionKey());
    taskService.complete(afterCompensationTask.getId());
    // and the process has successfully ended
    assertProcessEnded(processInstance.getId());
}

44. ProcessInstanceSuspensionTest#testSignalEventReceivedAfterProcessInstanceSuspendedByProcessDefinitionKey()

Project: camunda-bpm-platform
File: ProcessInstanceSuspensionTest.java
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/ProcessInstanceSuspensionTest.testSignalEventReceivedAfterProcessInstanceSuspended.bpmn20.xml" })
public void testSignalEventReceivedAfterProcessInstanceSuspendedByProcessDefinitionKey() {
    final String signal = "Some Signal";
    // Test if process instance can be completed using the signal
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("signalSuspendedProcessInstance");
    runtimeService.signalEventReceived(signal);
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
    // Now test when suspending the process instance: the process instance shouldn't be continued
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("signalSuspendedProcessInstance").singleResult();
    processInstance = runtimeService.startProcessInstanceByKey("signalSuspendedProcessInstance");
    runtimeService.suspendProcessInstanceByProcessDefinitionKey(processDefinition.getKey());
    runtimeService.signalEventReceived(signal);
    assertEquals(1, runtimeService.createProcessInstanceQuery().count());
    runtimeService.signalEventReceived(signal, new HashMap<String, Object>());
    assertEquals(1, runtimeService.createProcessInstanceQuery().count());
    EventSubscription subscription = runtimeService.createEventSubscriptionQuery().singleResult();
    try {
        runtimeService.signalEventReceived(signal, subscription.getExecutionId());
        fail();
    } catch (SuspendedEntityInteractionException e) {
        assertTextPresent("is suspended", e.getMessage());
    }
    try {
        runtimeService.signalEventReceived(signal, subscription.getExecutionId(), new HashMap<String, Object>());
        fail();
    } catch (SuspendedEntityInteractionException e) {
        assertTextPresent("is suspended", e.getMessage());
    }
    // Activate and try again
    runtimeService.activateProcessInstanceById(processInstance.getId());
    runtimeService.signalEventReceived(signal);
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}

45. ProcessInstanceSuspensionTest#testSignalEventReceivedAfterProcessInstanceSuspendedByProcessDefinitionId()

Project: camunda-bpm-platform
File: ProcessInstanceSuspensionTest.java
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/ProcessInstanceSuspensionTest.testSignalEventReceivedAfterProcessInstanceSuspended.bpmn20.xml" })
public void testSignalEventReceivedAfterProcessInstanceSuspendedByProcessDefinitionId() {
    final String signal = "Some Signal";
    // Test if process instance can be completed using the signal
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("signalSuspendedProcessInstance");
    runtimeService.signalEventReceived(signal);
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
    // Now test when suspending the process instance: the process instance shouldn't be continued
    processInstance = runtimeService.startProcessInstanceByKey("signalSuspendedProcessInstance");
    runtimeService.suspendProcessInstanceByProcessDefinitionId(processInstance.getProcessDefinitionId());
    runtimeService.signalEventReceived(signal);
    assertEquals(1, runtimeService.createProcessInstanceQuery().count());
    runtimeService.signalEventReceived(signal, new HashMap<String, Object>());
    assertEquals(1, runtimeService.createProcessInstanceQuery().count());
    EventSubscription subscription = runtimeService.createEventSubscriptionQuery().singleResult();
    try {
        runtimeService.signalEventReceived(signal, subscription.getExecutionId());
        fail();
    } catch (SuspendedEntityInteractionException e) {
        assertTextPresent("is suspended", e.getMessage());
    }
    try {
        runtimeService.signalEventReceived(signal, subscription.getExecutionId(), new HashMap<String, Object>());
        fail();
    } catch (SuspendedEntityInteractionException e) {
        assertTextPresent("is suspended", e.getMessage());
    }
    // Activate and try again
    runtimeService.activateProcessInstanceById(processInstance.getId());
    runtimeService.signalEventReceived(signal);
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}

46. ProcessInstanceSuspensionTest#testSignalEventReceivedAfterProcessInstanceSuspended()

Project: camunda-bpm-platform
File: ProcessInstanceSuspensionTest.java
@Deployment
public void testSignalEventReceivedAfterProcessInstanceSuspended() {
    final String signal = "Some Signal";
    // Test if process instance can be completed using the signal
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("signalSuspendedProcessInstance");
    runtimeService.signalEventReceived(signal);
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
    // Now test when suspending the process instance: the process instance shouldn't be continued
    processInstance = runtimeService.startProcessInstanceByKey("signalSuspendedProcessInstance");
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    runtimeService.signalEventReceived(signal);
    assertEquals(1, runtimeService.createProcessInstanceQuery().count());
    runtimeService.signalEventReceived(signal, new HashMap<String, Object>());
    assertEquals(1, runtimeService.createProcessInstanceQuery().count());
    EventSubscription subscription = runtimeService.createEventSubscriptionQuery().singleResult();
    try {
        runtimeService.signalEventReceived(signal, subscription.getExecutionId());
        fail();
    } catch (SuspendedEntityInteractionException e) {
        assertTextPresent("is suspended", e.getMessage());
    }
    try {
        runtimeService.signalEventReceived(signal, subscription.getExecutionId(), new HashMap<String, Object>());
        fail();
    } catch (SuspendedEntityInteractionException e) {
        assertTextPresent("is suspended", e.getMessage());
    }
    // Activate and try again
    runtimeService.activateProcessInstanceById(processInstance.getId());
    runtimeService.signalEventReceived(signal);
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}

47. ProcessInstanceSnapshot#getEventSubscriptionById()

Project: camunda-bpm-platform
File: ProcessInstanceSnapshot.java
public EventSubscription getEventSubscriptionById(String id) {
    for (EventSubscription subscription : eventSubscriptions) {
        if (subscription.getId().equals(id)) {
            return subscription;
        }
    }
    return null;
}

48. MigrationTestRule#assertEventSubscriptionMigrated()

Project: camunda-bpm-platform
File: MigrationTestRule.java
public void assertEventSubscriptionMigrated(String activityIdBefore, String eventNameBefore, String activityIdAfter, String eventNameAfter) {
    EventSubscription eventSubscriptionBefore = snapshotBeforeMigration.getEventSubscriptionForActivityIdAndEventName(activityIdBefore, eventNameBefore);
    assertNotNull("Expected that an event subscription for activity '" + activityIdBefore + "' exists before migration", eventSubscriptionBefore);
    assertEventSubscriptionMigrated(eventSubscriptionBefore, activityIdAfter, eventNameAfter);
}

49. MigrationTestRule#assertEventSubscriptionMigrated()

Project: camunda-bpm-platform
File: MigrationTestRule.java
public void assertEventSubscriptionMigrated(String activityIdBefore, String activityIdAfter, String eventName) {
    EventSubscription eventSubscriptionBefore = snapshotBeforeMigration.getEventSubscriptionForActivityIdAndEventName(activityIdBefore, eventName);
    assertNotNull("Expected that an event subscription for activity '" + activityIdBefore + "' exists before migration", eventSubscriptionBefore);
    assertEventSubscriptionMigrated(eventSubscriptionBefore, activityIdAfter, eventName);
}

50. MigrationTestRule#assertEventSubscriptionMigrated()

Project: camunda-bpm-platform
File: MigrationTestRule.java
protected void assertEventSubscriptionMigrated(EventSubscription eventSubscriptionBefore, String activityIdAfter, String eventName) {
    EventSubscription eventSubscriptionAfter = snapshotAfterMigration.getEventSubscriptionById(eventSubscriptionBefore.getId());
    assertNotNull("Expected that an event subscription with id '" + eventSubscriptionBefore.getId() + "' " + "exists after migration", eventSubscriptionAfter);
    assertEquals(eventSubscriptionBefore.getEventType(), eventSubscriptionAfter.getEventType());
    assertEquals(activityIdAfter, eventSubscriptionAfter.getActivityId());
    assertEquals(eventName, eventSubscriptionAfter.getEventName());
}

51. MigrationTestRule#assertEventSubscriptionsMigrated()

Project: camunda-bpm-platform
File: MigrationTestRule.java
public void assertEventSubscriptionsMigrated(String activityIdBefore, String activityIdAfter, String eventName) {
    List<EventSubscription> eventSubscriptionsBefore = snapshotBeforeMigration.getEventSubscriptionsForActivityIdAndEventName(activityIdAfter, eventName);
    for (EventSubscription eventSubscription : eventSubscriptionsBefore) {
        assertEventSubscriptionMigrated(eventSubscription, activityIdAfter, eventName);
    }
}

52. MigrationBoundaryEventsTest#testMigrateSignalBoundaryEventOnUserTaskAndSendOldSignalName()

Project: camunda-bpm-platform
File: MigrationBoundaryEventsTest.java
@Test
public void testMigrateSignalBoundaryEventOnUserTaskAndSendOldSignalName() {
    // given
    BpmnModelInstance sourceProcess = modify(ProcessModels.ONE_TASK_PROCESS).activityBuilder("userTask").boundaryEvent("boundary").signal(SIGNAL_NAME).userTask(AFTER_BOUNDARY_TASK).endEvent().done();
    BpmnModelInstance targetProcess = modify(ProcessModels.ONE_TASK_PROCESS).activityBuilder("userTask").boundaryEvent("boundary").signal("new" + SIGNAL_NAME).userTask(AFTER_BOUNDARY_TASK).endEvent().done();
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(sourceProcess);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(targetProcess);
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("userTask", "userTask").mapActivities("boundary", "boundary").build();
    // when
    testHelper.createProcessInstanceAndMigrate(migrationPlan);
    // then
    testHelper.assertEventSubscriptionMigrated("boundary", "boundary", SIGNAL_NAME);
    // and no event subscription for the new signal exists
    EventSubscription eventSubscription = rule.getRuntimeService().createEventSubscriptionQuery().eventName("new" + SIGNAL_NAME).singleResult();
    assertNull(eventSubscription);
    // and it is possible to correlate the signal by the old signal name and successfully complete the migrated instance
    testHelper.sendSignal(SIGNAL_NAME);
    testHelper.completeTask(AFTER_BOUNDARY_TASK);
    testHelper.assertProcessEnded(testHelper.snapshotBeforeMigration.getProcessInstanceId());
}

53. MigrationBoundaryEventsTest#testMigrateMessageBoundaryEventAndTriggerByOldMessageName()

Project: camunda-bpm-platform
File: MigrationBoundaryEventsTest.java
@Test
public void testMigrateMessageBoundaryEventAndTriggerByOldMessageName() {
    // given
    BpmnModelInstance sourceProcess = modify(ProcessModels.ONE_TASK_PROCESS).activityBuilder("userTask").boundaryEvent("boundary").message(MESSAGE_NAME).userTask(AFTER_BOUNDARY_TASK).endEvent().done();
    BpmnModelInstance targetProcess = modify(ProcessModels.ONE_TASK_PROCESS).activityBuilder("userTask").boundaryEvent("boundary").message("new" + MESSAGE_NAME).userTask(AFTER_BOUNDARY_TASK).endEvent().done();
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(sourceProcess);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(targetProcess);
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("userTask", "userTask").mapActivities("boundary", "boundary").build();
    // when
    testHelper.createProcessInstanceAndMigrate(migrationPlan);
    // then
    testHelper.assertEventSubscriptionMigrated("boundary", "boundary", MESSAGE_NAME);
    // and no event subscription for the new message name exists
    EventSubscription eventSubscription = rule.getRuntimeService().createEventSubscriptionQuery().eventName("new" + MESSAGE_NAME).singleResult();
    assertNull(eventSubscription);
    // and it is possible to correlate the message with the old message name and successfully complete the migrated instance
    testHelper.correlateMessage(MESSAGE_NAME);
    testHelper.completeTask(AFTER_BOUNDARY_TASK);
    testHelper.assertProcessEnded(testHelper.snapshotBeforeMigration.getProcessInstanceId());
}

54. BatchMigrationTest#testUpdateEventTrigger()

Project: camunda-bpm-platform
File: BatchMigrationTest.java
@Test
public void testUpdateEventTrigger() {
    // given
    String newMessageName = "newMessage";
    ProcessDefinition sourceProcessDefinition = migrationRule.deployAndGetDefinition(ProcessModels.ONE_RECEIVE_TASK_PROCESS);
    ProcessDefinition targetProcessDefinition = migrationRule.deployAndGetDefinition(modify(ProcessModels.ONE_RECEIVE_TASK_PROCESS).renameMessage("Message", newMessageName));
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceProcessDefinition.getId());
    MigrationPlan migrationPlan = runtimeService.createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapEqualActivities().updateEventTriggers().build();
    Batch batch = runtimeService.newMigration(migrationPlan).processInstanceIds(Collections.singletonList(processInstance.getId())).executeAsync();
    helper.executeSeedJob(batch);
    // when
    helper.executeMigrationJobs(batch);
    // then the message event subscription's event name was changed
    EventSubscription eventSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
    assertEquals(newMessageName, eventSubscription.getEventName());
}