assertEquals(3, runtimeService.createExecutionQuery().count());
Task userTask = taskService.createTaskQuery().singleResult();
assertNotNull(userTask);
Execution execution1 = runtimeService.createExecutionQuery()
.messageEventSubscriptionName("messageName")
.singleResult();
assertNotNull(execution1);
Execution execution2 = runtimeService.createExecutionQuery()
.messageEventSubscriptionName("messageName2")
.singleResult();
assertNotNull(execution2);
assertNotSame(execution1.getId(), execution2.getId());
/////////////////////////////////////////////////////////////
// first case: we complete the inner usertask.
taskService.complete(userTask.getId());
userTask = taskService.createTaskQuery().singleResult();
assertNotNull(userTask);
assertEquals("taskAfterTask", userTask.getTaskDefinitionKey());
// the inner subscription is cancelled
Execution execution = runtimeService.createExecutionQuery()
.messageEventSubscriptionName("messageName")
.singleResult();
assertNull(execution);
// the outer subscription still exists
execution = runtimeService.createExecutionQuery()
.messageEventSubscriptionName("messageName2")
.singleResult();
assertNotNull(execution);
// now complete the second usertask
taskService.complete(userTask.getId());
// now the outer event subscription is cancelled as well
execution = runtimeService.createExecutionQuery()
.messageEventSubscriptionName("messageName2")
.singleResult();
assertNull(execution);
userTask = taskService.createTaskQuery().singleResult();
assertNotNull(userTask);
assertEquals("taskAfterSubprocess", userTask.getTaskDefinitionKey());
// now complete the outer usertask
taskService.complete(userTask.getId());
/////////////////////////////////////////////////////////////
// second case: we signal the inner message event
runtimeService.startProcessInstanceByKey("process");
execution = runtimeService.createExecutionQuery()
.messageEventSubscriptionName("messageName")
.singleResult();
runtimeService.messageEventReceived("messageName", execution.getId());
userTask = taskService.createTaskQuery().singleResult();
assertNotNull(userTask);
assertEquals("taskAfterMessage", userTask.getTaskDefinitionKey());
// the inner subscription is removed
execution = runtimeService.createExecutionQuery()
.messageEventSubscriptionName("messageName")
.singleResult();
assertNull(execution);
// the outer subscription still exists
execution = runtimeService.createExecutionQuery()
.messageEventSubscriptionName("messageName2")
.singleResult();
assertNotNull(execution);
// now complete the second usertask
taskService.complete(userTask.getId());
// now the outer event subscription is cancelled as well
execution = runtimeService.createExecutionQuery()
.messageEventSubscriptionName("messageName2")
.singleResult();
assertNull(execution);
userTask = taskService.createTaskQuery().singleResult();
assertNotNull(userTask);
assertEquals("taskAfterSubprocess", userTask.getTaskDefinitionKey());
// now complete the outer usertask
taskService.complete(userTask.getId());
/////////////////////////////////////////////////////////////
// third case: we signal the outer message event
runtimeService.startProcessInstanceByKey("process");
execution = runtimeService.createExecutionQuery()
.messageEventSubscriptionName("messageName2")
.singleResult();
runtimeService.messageEventReceived("messageName2", execution.getId());
userTask = taskService.createTaskQuery().singleResult();
assertNotNull(userTask);
assertEquals("taskAfterOuterMessageBoundary", userTask.getTaskDefinitionKey());