Search in sources :

Example 51 with Execution

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

Example 52 with Execution

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());
}
Also used : Task(org.activiti.engine.task.Task) Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance)

Example 53 with Execution

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

Example 54 with Execution

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());
}
Also used : Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 55 with Execution

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

Aggregations

Execution (org.activiti.engine.runtime.Execution)131 Deployment (org.activiti.engine.test.Deployment)105 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)75 Task (org.activiti.engine.task.Task)33 HashMap (java.util.HashMap)30 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 DelegateExecution (org.activiti.engine.delegate.DelegateExecution)12 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)12 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)10 ExecutionQuery (org.activiti.engine.runtime.ExecutionQuery)10 HttpPut (org.apache.http.client.methods.HttpPut)10 StringEntity (org.apache.http.entity.StringEntity)9 ArrayList (java.util.ArrayList)8 ActivitiException (org.activiti.engine.ActivitiException)8 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 Date (java.util.Date)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)5 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)5