@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());
}