use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class MessageBoundaryEventTest method testBoundaryMessageEventOnSubprocessAndInsideSubprocess.
@Deployment
public void testBoundaryMessageEventOnSubprocessAndInsideSubprocess() {
// this time the boundary events are placed on a user task that is contained inside a sub process
// and on the subprocess itself
runtimeService.startProcessInstanceByKey("process");
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 removes
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());
// the inner subscription is removed
execution = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName").singleResult();
assertNull(execution);
// the outer subscription is removed
execution = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName2").singleResult();
assertNull(execution);
// now complete the second usertask
taskService.complete(userTask.getId());
// and we are done
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class MessageEventSubprocessTest method testInterruptingUnderProcessDefinition.
private void testInterruptingUnderProcessDefinition(int expectedNumberOfEventSubscriptions) {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");
// the process instance must have a message event subscription:
Execution execution = runtimeService.createExecutionQuery().executionId(processInstance.getId()).messageEventSubscriptionName("newMessage").singleResult();
assertNotNull(execution);
assertEquals(expectedNumberOfEventSubscriptions, createEventSubscriptionQuery().count());
assertEquals(1, runtimeService.createExecutionQuery().count());
// if we trigger the usertask, the process terminates and the event subscription is removed:
Task task = taskService.createTaskQuery().singleResult();
assertEquals("task", task.getTaskDefinitionKey());
taskService.complete(task.getId());
assertProcessEnded(processInstance.getId());
assertEquals(0, createEventSubscriptionQuery().count());
assertEquals(0, runtimeService.createExecutionQuery().count());
// now we start a new instance but this time we trigger the event subprocess:
processInstance = runtimeService.startProcessInstanceByKey("process");
runtimeService.messageEventReceived("newMessage", processInstance.getId());
task = taskService.createTaskQuery().singleResult();
assertEquals("eventSubProcessTask", task.getTaskDefinitionKey());
taskService.complete(task.getId());
assertProcessEnded(processInstance.getId());
assertEquals(0, createEventSubscriptionQuery().count());
assertEquals(0, runtimeService.createExecutionQuery().count());
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class MessageEventSubprocessTest method FAILING_testNonInterruptingUnderProcessDefinition.
@Deployment
public void FAILING_testNonInterruptingUnderProcessDefinition() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");
// the process instance must have a message event subscription:
Execution execution = runtimeService.createExecutionQuery().executionId(processInstance.getId()).messageEventSubscriptionName("newMessage").singleResult();
assertNotNull(execution);
assertEquals(1, createEventSubscriptionQuery().count());
assertEquals(1, runtimeService.createExecutionQuery().count());
// if we trigger the usertask, the process terminates and the event subscription is removed:
Task task = taskService.createTaskQuery().singleResult();
assertEquals("task", task.getTaskDefinitionKey());
taskService.complete(task.getId());
assertEquals(0, createEventSubscriptionQuery().count());
assertEquals(0, runtimeService.createExecutionQuery().count());
// ###################### now we start a new instance but this time we trigger the event subprocess:
processInstance = runtimeService.startProcessInstanceByKey("process");
runtimeService.messageEventReceived("newMessage", processInstance.getId());
assertEquals(2, taskService.createTaskQuery().count());
// now let's first complete the task in the main flow:
task = taskService.createTaskQuery().taskDefinitionKey("task").singleResult();
taskService.complete(task.getId());
// we still have 2 executions:
assertEquals(2, runtimeService.createExecutionQuery().count());
// now let's complete the task in the event subprocess
task = taskService.createTaskQuery().taskDefinitionKey("eventSubProcessTask").singleResult();
taskService.complete(task.getId());
// done!
assertEquals(0, runtimeService.createExecutionQuery().count());
// #################### again, the other way around:
processInstance = runtimeService.startProcessInstanceByKey("process");
runtimeService.messageEventReceived("newMessage", processInstance.getId());
assertEquals(2, taskService.createTaskQuery().count());
task = taskService.createTaskQuery().taskDefinitionKey("eventSubProcessTask").singleResult();
taskService.complete(task.getId());
// we still have 1 execution:
assertEquals(2, runtimeService.createExecutionQuery().count());
task = taskService.createTaskQuery().taskDefinitionKey("task").singleResult();
taskService.complete(task.getId());
// done!
assertEquals(0, runtimeService.createExecutionQuery().count());
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class MessageIntermediateEventTest method testAsyncTriggeredMessageEvent.
@Deployment
public void testAsyncTriggeredMessageEvent() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");
assertNotNull(processInstance);
Execution execution = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).messageEventSubscriptionName("newMessage").singleResult();
assertNotNull(execution);
assertEquals(1, createEventSubscriptionQuery().count());
assertEquals(2, runtimeService.createExecutionQuery().count());
runtimeService.messageEventReceivedAsync("newMessage", execution.getId());
assertEquals(1, managementService.createJobQuery().messages().count());
waitForJobExecutorToProcessAllJobs(8000L, 200L);
assertEquals(0, createEventSubscriptionQuery().count());
assertEquals(0, runtimeService.createProcessInstanceQuery().count());
assertEquals(0, managementService.createJobQuery().count());
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class MessageIntermediateEventTest method testSingleIntermediateMessageEvent.
@Deployment
public void testSingleIntermediateMessageEvent() {
ProcessInstance pi = runtimeService.startProcessInstanceByKey("process");
List<String> activeActivityIds = runtimeService.getActiveActivityIds(pi.getId());
assertNotNull(activeActivityIds);
assertEquals(1, activeActivityIds.size());
assertTrue(activeActivityIds.contains("messageCatch"));
String messageName = "newInvoiceMessage";
Execution execution = runtimeService.createExecutionQuery().messageEventSubscriptionName(messageName).singleResult();
assertNotNull(execution);
runtimeService.messageEventReceived(messageName, execution.getId());
Task task = taskService.createTaskQuery().singleResult();
assertNotNull(task);
taskService.complete(task.getId());
}
Aggregations