use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class MessageIntermediateEventTest method testExpressionInSingleIntermediateMessageEvent.
@Deployment
@Test
public void testExpressionInSingleIntermediateMessageEvent() {
// given
HashMap<String, Object> variables = new HashMap<String, Object>();
variables.put("foo", "bar");
// when
ProcessInstance pi = runtimeService.startProcessInstanceByKey("process", variables);
List<String> activeActivityIds = runtimeService.getActiveActivityIds(pi.getId());
assertNotNull(activeActivityIds);
assertEquals(1, activeActivityIds.size());
assertTrue(activeActivityIds.contains("messageCatch"));
// then
String messageName = "newInvoiceMessage-bar";
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());
}
use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class MessageIntermediateEventTest method testConcurrentIntermediateMessageEvent.
@Deployment
@Test
public void testConcurrentIntermediateMessageEvent() {
ProcessInstance pi = runtimeService.startProcessInstanceByKey("process");
List<String> activeActivityIds = runtimeService.getActiveActivityIds(pi.getId());
assertNotNull(activeActivityIds);
assertEquals(2, activeActivityIds.size());
assertTrue(activeActivityIds.contains("messageCatch1"));
assertTrue(activeActivityIds.contains("messageCatch2"));
String messageName = "newInvoiceMessage";
List<Execution> executions = runtimeService.createExecutionQuery().messageEventSubscriptionName(messageName).list();
assertNotNull(executions);
assertEquals(2, executions.size());
runtimeService.messageEventReceived(messageName, executions.get(0).getId());
Task task = taskService.createTaskQuery().singleResult();
assertNull(task);
runtimeService.messageEventReceived(messageName, executions.get(1).getId());
task = taskService.createTaskQuery().singleResult();
assertNotNull(task);
taskService.complete(task.getId());
}
use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class MessageNonInterruptingBoundaryEventTest method testNonInterruptingEventInCombinationWithReceiveTaskInsideSubProcess.
@Deployment
public void testNonInterruptingEventInCombinationWithReceiveTaskInsideSubProcess() {
// given
ProcessInstance instance = runtimeService.startProcessInstanceByKey("process");
String processInstanceId = instance.getId();
// when (1)
runtimeService.correlateMessage("firstMessage");
// then (1)
ActivityInstance activityInstance = runtimeService.getActivityInstance(instance.getId());
assertThat(activityInstance).hasStructure(describeActivityInstanceTree(instance.getProcessDefinitionId()).beginScope("subProcess").activity("task1").beginScope("innerSubProcess").activity("receiveTask").done());
assertEquals(1, taskService.createTaskQuery().count());
Task task1 = taskService.createTaskQuery().taskDefinitionKey("task1").singleResult();
assertNotNull(task1);
Execution task1Execution = runtimeService.createExecutionQuery().activityId("task1").singleResult();
assertFalse(processInstanceId.equals(((ExecutionEntity) task1Execution).getParentId()));
// when (2)
runtimeService.correlateMessage("secondMessage");
// then (2)
assertEquals(2, taskService.createTaskQuery().count());
task1 = taskService.createTaskQuery().taskDefinitionKey("task1").singleResult();
assertNotNull(task1);
task1Execution = runtimeService.createExecutionQuery().activityId("task1").singleResult();
assertFalse(processInstanceId.equals(((ExecutionEntity) task1Execution).getParentId()));
Task task2 = taskService.createTaskQuery().taskDefinitionKey("task2").singleResult();
assertNotNull(task2);
Execution task2Execution = runtimeService.createExecutionQuery().activityId("task1").singleResult();
assertFalse(processInstanceId.equals(((ExecutionEntity) task2Execution).getParentId()));
assertTrue(((ExecutionEntity) task1Execution).getParentId().equals(((ExecutionEntity) task2Execution).getParentId()));
assertEquals(0, runtimeService.createEventSubscriptionQuery().count());
taskService.complete(task1.getId());
taskService.complete(task2.getId());
assertProcessEnded(processInstanceId);
}
use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class MessageNonInterruptingBoundaryEventTest method testNonInterruptingEventInCombinationWithReceiveTask.
@Deployment
public void testNonInterruptingEventInCombinationWithReceiveTask() {
// given
String processInstanceId = runtimeService.startProcessInstanceByKey("process").getId();
// when (1)
runtimeService.correlateMessage("firstMessage");
// then (1)
assertEquals(1, taskService.createTaskQuery().count());
Task task1 = taskService.createTaskQuery().taskDefinitionKey("task1").singleResult();
assertNotNull(task1);
Execution task1Execution = runtimeService.createExecutionQuery().activityId("task1").singleResult();
assertEquals(processInstanceId, ((ExecutionEntity) task1Execution).getParentId());
// when (2)
runtimeService.correlateMessage("secondMessage");
// then (2)
assertEquals(2, taskService.createTaskQuery().count());
task1 = taskService.createTaskQuery().taskDefinitionKey("task1").singleResult();
assertNotNull(task1);
task1Execution = runtimeService.createExecutionQuery().activityId("task1").singleResult();
assertEquals(processInstanceId, ((ExecutionEntity) task1Execution).getParentId());
Task task2 = taskService.createTaskQuery().taskDefinitionKey("task2").singleResult();
assertNotNull(task2);
Execution task2Execution = runtimeService.createExecutionQuery().activityId("task1").singleResult();
assertEquals(processInstanceId, ((ExecutionEntity) task2Execution).getParentId());
assertEquals(0, runtimeService.createEventSubscriptionQuery().count());
taskService.complete(task1.getId());
taskService.complete(task2.getId());
assertProcessEnded(processInstanceId);
}
use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class MessageNonInterruptingBoundaryEventTest method testSingleNonInterruptingBoundaryMessageEvent.
@Deployment
public void testSingleNonInterruptingBoundaryMessageEvent() {
runtimeService.startProcessInstanceByKey("process");
assertEquals(2, runtimeService.createExecutionQuery().count());
Task userTask = taskService.createTaskQuery().taskDefinitionKey("task").singleResult();
assertNotNull(userTask);
Execution execution = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName").singleResult();
assertNotNull(execution);
// 1. case: message received before completing the task
runtimeService.messageEventReceived("messageName", execution.getId());
// event subscription not removed
execution = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName").singleResult();
assertNotNull(execution);
assertEquals(2, taskService.createTaskQuery().count());
userTask = taskService.createTaskQuery().taskDefinitionKey("taskAfterMessage").singleResult();
assertNotNull(userTask);
assertEquals("taskAfterMessage", userTask.getTaskDefinitionKey());
taskService.complete(userTask.getId());
assertEquals(1, runtimeService.createProcessInstanceQuery().count());
// send a message a second time
runtimeService.messageEventReceived("messageName", execution.getId());
// event subscription not removed
execution = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName").singleResult();
assertNotNull(execution);
assertEquals(2, taskService.createTaskQuery().count());
userTask = taskService.createTaskQuery().taskDefinitionKey("taskAfterMessage").singleResult();
assertNotNull(userTask);
assertEquals("taskAfterMessage", userTask.getTaskDefinitionKey());
taskService.complete(userTask.getId());
assertEquals(1, runtimeService.createProcessInstanceQuery().count());
// now complete the user task with the message boundary event
userTask = taskService.createTaskQuery().taskDefinitionKey("task").singleResult();
assertNotNull(userTask);
taskService.complete(userTask.getId());
// event subscription removed
execution = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName").singleResult();
assertNull(execution);
userTask = taskService.createTaskQuery().taskDefinitionKey("taskAfterTask").singleResult();
assertNotNull(userTask);
taskService.complete(userTask.getId());
assertEquals(0, runtimeService.createProcessInstanceQuery().count());
// 2nd. case: complete the user task cancels the message subscription
runtimeService.startProcessInstanceByKey("process");
userTask = taskService.createTaskQuery().taskDefinitionKey("task").singleResult();
assertNotNull(userTask);
taskService.complete(userTask.getId());
execution = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName").singleResult();
assertNull(execution);
userTask = taskService.createTaskQuery().taskDefinitionKey("taskAfterTask").singleResult();
assertNotNull(userTask);
assertEquals("taskAfterTask", userTask.getTaskDefinitionKey());
taskService.complete(userTask.getId());
assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
Aggregations