Search in sources :

Example 46 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class ActivityEventsTest method testActivitySignalBoundaryEventsOnSubProcess.

@Deployment
public void testActivitySignalBoundaryEventsOnSubProcess() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("signalOnSubProcess");
    assertNotNull(processInstance);
    Execution executionWithSignal = runtimeService.createExecutionQuery().activityId("userTaskInsideProcess").singleResult();
    assertNotNull(executionWithSignal);
    runtimeService.signalEventReceived("signalName");
    assertEquals(1, listener.getEventsReceived().size());
    // Next, an signal-event is expected, as a result of the message
    assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiActivityCancelledEvent);
    ActivitiActivityCancelledEvent signalEvent = (ActivitiActivityCancelledEvent) listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ACTIVITY_CANCELLED, signalEvent.getType());
    assertEquals("userTaskInsideProcess", signalEvent.getActivityId());
    assertEquals(executionWithSignal.getId(), signalEvent.getExecutionId());
    assertEquals(executionWithSignal.getProcessInstanceId(), signalEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), signalEvent.getProcessDefinitionId());
    assertNotNull(signalEvent.getCause());
    assertTrue(signalEvent.getCause() instanceof SignalEventSubscriptionEntity);
    SignalEventSubscriptionEntity cause = (SignalEventSubscriptionEntity) signalEvent.getCause();
    assertEquals("signalName", cause.getEventName());
}
Also used : Execution(org.activiti.engine.runtime.Execution) ActivitiActivityCancelledEvent(org.activiti.engine.delegate.event.ActivitiActivityCancelledEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity) Deployment(org.activiti.engine.test.Deployment)

Example 47 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class ActivityEventsTest method testActivityMessageEventsInEventSubprocess.

/**
	 * Test events related to message events, called from the API, targeting an event-subprocess.
	 */
@Deployment
public void testActivityMessageEventsInEventSubprocess() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("messageProcess");
    assertNotNull(processInstance);
    Execution executionWithMessage = runtimeService.createExecutionQuery().activityId("shipOrder").singleResult();
    assertNotNull(executionWithMessage);
    runtimeService.messageEventReceived("messageName", executionWithMessage.getId());
    // Only a message-event should be present, no signal-event, since the
    // event-subprocess is
    // not signaled, but executed instead
    assertEquals(1, listener.getEventsReceived().size());
    // A message-event is expected
    assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiMessageEvent);
    ActivitiMessageEvent messageEvent = (ActivitiMessageEvent) listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ACTIVITY_MESSAGE_RECEIVED, messageEvent.getType());
    assertEquals("catchMessage", messageEvent.getActivityId());
    assertEquals(executionWithMessage.getId(), messageEvent.getExecutionId());
    assertEquals(executionWithMessage.getProcessInstanceId(), messageEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), messageEvent.getProcessDefinitionId());
    assertEquals("messageName", messageEvent.getMessageName());
    assertNull(messageEvent.getMessageData());
}
Also used : Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiMessageEvent(org.activiti.engine.delegate.event.ActivitiMessageEvent) Deployment(org.activiti.engine.test.Deployment)

Example 48 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class MessageBoundaryEventTest method testDoubleBoundaryMessageEventMultiInstance.

@Deployment
public void testDoubleBoundaryMessageEventMultiInstance() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");
    // assume we have 7 executions
    // one process instance
    // one execution for scope created for boundary message event
    // five execution because we have loop cardinality 5
    assertEquals(7, runtimeService.createExecutionQuery().count());
    assertEquals(5, taskService.createTaskQuery().count());
    Execution execution1 = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName_1").singleResult();
    Execution execution2 = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName_2").singleResult();
    // both executions are the same
    assertEquals(execution1.getId(), execution2.getId());
    ///////////////////////////////////////////////////////////////////////////////////
    // 1. first message received cancels all tasks and the executions and both subscriptions
    runtimeService.messageEventReceived("messageName_1", execution1.getId());
    // this should then throw an exception because execution2 no longer exists
    try {
        runtimeService.messageEventReceived("messageName_2", execution2.getId());
        fail();
    } catch (Exception e) {
    // This is good
    }
    // only process instance left
    assertEquals(1, runtimeService.createExecutionQuery().count());
    Task userTask = taskService.createTaskQuery().singleResult();
    assertNotNull(userTask);
    assertEquals("taskAfterMessage_1", userTask.getTaskDefinitionKey());
    taskService.complete(userTask.getId());
    assertProcessEnded(processInstance.getId());
    ///////////////////////////////////////////////////////////////////////////////////
    // 2. complete the user task cancels the message subscriptions
    processInstance = runtimeService.startProcessInstanceByKey("process");
    // assume we have 7 executions
    // one process instance
    // one execution for scope created for boundary message event
    // five execution because we have loop cardinality 5
    assertEquals(7, runtimeService.createExecutionQuery().count());
    assertEquals(5, taskService.createTaskQuery().count());
    execution1 = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName_1").singleResult();
    execution2 = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName_2").singleResult();
    // both executions are the same
    assertEquals(execution1.getId(), execution2.getId());
    List<Task> userTasks = taskService.createTaskQuery().list();
    assertNotNull(userTasks);
    assertEquals(5, userTasks.size());
    // as long as tasks exists, the message subscriptions exist
    for (int i = 0; i < userTasks.size() - 1; i++) {
        Task task = userTasks.get(i);
        taskService.complete(task.getId());
        execution1 = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName_1").singleResult();
        assertNotNull(execution1);
        execution2 = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName_2").singleResult();
        assertNotNull(execution2);
    }
    // only one task left
    userTask = taskService.createTaskQuery().singleResult();
    assertNotNull(userTask);
    taskService.complete(userTask.getId());
    // after last task is completed, no message subscriptions left
    execution1 = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName_1").singleResult();
    assertNull(execution1);
    execution2 = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName_2").singleResult();
    assertNull(execution2);
    // complete last task to end process
    userTask = taskService.createTaskQuery().singleResult();
    assertNotNull(userTask);
    assertEquals("taskAfterTask", userTask.getTaskDefinitionKey());
    taskService.complete(userTask.getId());
    assertProcessEnded(processInstance.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)

Example 49 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class MessageBoundaryEventTest method testBoundaryMessageEventOnSubprocessAndInsideSubprocessMultiInstance.

@Deployment
public void testBoundaryMessageEventOnSubprocessAndInsideSubprocessMultiInstance() {
    // 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(17, runtimeService.createExecutionQuery().count());
    // 5 user tasks
    List<Task> userTasks = taskService.createTaskQuery().list();
    assertNotNull(userTasks);
    assertEquals(5, userTasks.size());
    // there are 5 event subscriptions to the event on the inner user task
    List<Execution> executions = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName").list();
    assertNotNull(executions);
    assertEquals(5, executions.size());
    // there is a single event subscription for the event on the subprocess
    executions = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName2").list();
    assertNotNull(executions);
    assertEquals(1, executions.size());
    // if we complete the outer message event, all inner executions are removed
    Execution outerScopeExecution = executions.get(0);
    runtimeService.messageEventReceived("messageName2", outerScopeExecution.getId());
    executions = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName").list();
    assertEquals(0, executions.size());
    Task userTask = taskService.createTaskQuery().singleResult();
    assertNotNull(userTask);
    assertEquals("taskAfterOuterMessageBoundary", userTask.getTaskDefinitionKey());
    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 50 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class MessageBoundaryEventTest method testBoundaryMessageEventOnSubprocess.

@Deployment
public void testBoundaryMessageEventOnSubprocess() {
    runtimeService.startProcessInstanceByKey("process");
    assertEquals(2, runtimeService.createExecutionQuery().count());
    Task userTask = taskService.createTaskQuery().singleResult();
    assertNotNull(userTask);
    // 1. case: message one received cancels the task
    Execution executionMessageOne = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName_one").singleResult();
    assertNotNull(executionMessageOne);
    runtimeService.messageEventReceived("messageName_one", executionMessageOne.getId());
    userTask = taskService.createTaskQuery().singleResult();
    assertNotNull(userTask);
    assertEquals("taskAfterMessage_one", userTask.getTaskDefinitionKey());
    taskService.complete(userTask.getId());
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
    // 2nd. case: message two received cancels the task
    runtimeService.startProcessInstanceByKey("process");
    Execution executionMessageTwo = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName_two").singleResult();
    assertNotNull(executionMessageTwo);
    runtimeService.messageEventReceived("messageName_two", executionMessageTwo.getId());
    userTask = taskService.createTaskQuery().singleResult();
    assertNotNull(userTask);
    assertEquals("taskAfterMessage_two", userTask.getTaskDefinitionKey());
    taskService.complete(userTask.getId());
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
    // 3rd. case: complete the user task cancels the message subscription
    runtimeService.startProcessInstanceByKey("process");
    userTask = taskService.createTaskQuery().singleResult();
    assertNotNull(userTask);
    taskService.complete(userTask.getId());
    executionMessageOne = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName_one").singleResult();
    assertNull(executionMessageOne);
    executionMessageTwo = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName_two").singleResult();
    assertNull(executionMessageTwo);
    userTask = taskService.createTaskQuery().singleResult();
    assertNotNull(userTask);
    assertEquals("taskAfterSubProcess", userTask.getTaskDefinitionKey());
    taskService.complete(userTask.getId());
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
Also used : Task(org.activiti.engine.task.Task) Execution(org.activiti.engine.runtime.Execution) 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