@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/receivetask/ReceiveTaskTest.multiParallelReceiveTaskCompensate.bpmn20.xml")
public void testSupportsMessageEventReceivedOnParallelMultiReceiveTaskWithCompensation() {
// given: a process instance waiting in two receive tasks
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess");
// expect: there are two message event subscriptions
List<EventSubscription> subscriptions = getEventSubscriptionList();
assertEquals(2, subscriptions.size());
// then: we can trigger the first event subscription
runtimeService.messageEventReceived(subscriptions.get(0).getEventName(), subscriptions.get(0).getExecutionId());
// expect: after completing the first receive task there is one event subscription for compensation
assertEquals(1, runtimeService.createEventSubscriptionQuery()
.eventType(CompensationEventHandler.EVENT_HANDLER_TYPE).count());
// then: we can trigger the second event subscription
runtimeService.messageEventReceived(subscriptions.get(1).getEventName(), subscriptions.get(1).getExecutionId());
// expect: there are two event subscriptions for compensation
assertEquals(2, runtimeService.createEventSubscriptionQuery()
.eventType(CompensationEventHandler.EVENT_HANDLER_TYPE).count());
// expect: one user task is created
Task task = taskService.createTaskQuery().singleResult();
taskService.complete(task.getId());
// expect: this ends the process instance
assertProcessEnded(processInstance.getId());
}