Search in sources :

Example 96 with Execution

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());
}
Also used : Task(org.camunda.bpm.engine.task.Task) Execution(org.camunda.bpm.engine.runtime.Execution) HashMap(java.util.HashMap) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 97 with Execution

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());
}
Also used : Task(org.camunda.bpm.engine.task.Task) Execution(org.camunda.bpm.engine.runtime.Execution) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 98 with Execution

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);
}
Also used : Task(org.camunda.bpm.engine.task.Task) Execution(org.camunda.bpm.engine.runtime.Execution) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 99 with Execution

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);
}
Also used : Task(org.camunda.bpm.engine.task.Task) Execution(org.camunda.bpm.engine.runtime.Execution) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 100 with Execution

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());
}
Also used : Task(org.camunda.bpm.engine.task.Task) Execution(org.camunda.bpm.engine.runtime.Execution) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

Execution (org.camunda.bpm.engine.runtime.Execution)279 Deployment (org.camunda.bpm.engine.test.Deployment)188 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)143 Task (org.camunda.bpm.engine.task.Task)99 Test (org.junit.Test)95 HashMap (java.util.HashMap)45 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)33 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)23 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)22 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)20 ThrowErrorDelegate.leaveExecution (org.camunda.bpm.engine.test.bpmn.event.error.ThrowErrorDelegate.leaveExecution)18 ExecutionQuery (org.camunda.bpm.engine.runtime.ExecutionQuery)17 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)15 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)14 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)14 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)14 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)14 DelegateExecution (org.camunda.bpm.engine.delegate.DelegateExecution)13 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)12 ArrayList (java.util.ArrayList)11