Search in sources :

Example 41 with Execution

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

the class CompetingJoinTest method testCompetingJoins.

@Deployment
public void testCompetingJoins() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("CompetingJoinsProcess");
    Execution execution1 = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).activityId("wait1").singleResult();
    Execution execution2 = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).activityId("wait2").singleResult();
    log.debug("test thread starts thread one");
    SignalThread threadOne = new SignalThread(execution1.getId());
    threadOne.startAndWaitUntilControlIsReturned();
    log.debug("test thread continues to start thread two");
    SignalThread threadTwo = new SignalThread(execution2.getId());
    threadTwo.startAndWaitUntilControlIsReturned();
    log.debug("test thread notifies thread 1");
    threadOne.proceedAndWaitTillDone();
    assertNull(threadOne.exception);
    log.debug("test thread notifies thread 2");
    threadTwo.proceedAndWaitTillDone();
    assertNotNull(threadTwo.exception);
    assertTextPresent("was updated by another transaction concurrently", threadTwo.exception.getMessage());
}
Also used : Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 42 with Execution

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

the class ExecutionQueryEscapeClauseTest method testQueryLikeByQueryVariableValue.

@Test
public void testQueryLikeByQueryVariableValue() {
    Execution execution = runtimeService.createExecutionQuery().variableValueLike("var1", "%\\%%").singleResult();
    assertNotNull(execution);
    assertEquals(processInstance1.getId(), execution.getId());
    execution = runtimeService.createExecutionQuery().variableValueLike("var1", "%\\_%").singleResult();
    assertNotNull(execution);
    assertEquals(processInstance2.getId(), execution.getId());
}
Also used : Execution(org.activiti.engine.runtime.Execution) Test(org.junit.Test)

Example 43 with Execution

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

the class ActivityEventsTest method testActivityMessageBoundaryEventsOnUserTask.

/**
   * Test events related to message events, called from the API.
   */
@Deployment
public void testActivityMessageBoundaryEventsOnUserTask() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("messageOnUserTaskProcess");
    assertNotNull(processInstance);
    Execution executionWithMessage = runtimeService.createExecutionQuery().activityId("cloudformtask1").singleResult();
    assertNotNull(executionWithMessage);
    runtimeService.messageEventReceived("message_1", executionWithMessage.getId());
    assertEquals(2, listener.getEventsReceived().size());
    // First, 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("boundaryMessageEventCatching", messageEvent.getActivityId());
    assertEquals(executionWithMessage.getId(), messageEvent.getExecutionId());
    assertEquals(executionWithMessage.getProcessInstanceId(), messageEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), messageEvent.getProcessDefinitionId());
    assertEquals("message_1", messageEvent.getMessageName());
    assertNull(messageEvent.getMessageData());
    // Next, an signal-event is expected, as a result of the message
    assertTrue(listener.getEventsReceived().get(1) instanceof ActivitiActivityCancelledEvent);
    ActivitiActivityCancelledEvent signalEvent = (ActivitiActivityCancelledEvent) listener.getEventsReceived().get(1);
    assertEquals(ActivitiEventType.ACTIVITY_CANCELLED, signalEvent.getType());
    assertEquals("cloudformtask1", signalEvent.getActivityId());
    assertEquals(executionWithMessage.getId(), signalEvent.getExecutionId());
    assertEquals(executionWithMessage.getProcessInstanceId(), signalEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), signalEvent.getProcessDefinitionId());
    assertNotNull(signalEvent.getCause());
    assertTrue(signalEvent.getCause() instanceof MessageEventSubscriptionEntity);
    MessageEventSubscriptionEntity cause = (MessageEventSubscriptionEntity) signalEvent.getCause();
    assertEquals("message_1", cause.getEventName());
    assertDatabaseEventPresent(ActivitiEventType.ACTIVITY_MESSAGE_RECEIVED);
}
Also used : Execution(org.activiti.engine.runtime.Execution) ActivitiActivityCancelledEvent(org.activiti.engine.delegate.event.ActivitiActivityCancelledEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiMessageEvent(org.activiti.engine.delegate.event.ActivitiMessageEvent) MessageEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity) Deployment(org.activiti.engine.test.Deployment)

Example 44 with Execution

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

the class ActivityEventsTest method testActivitySignalEventsWithinProcess.

/**
	 * Test to verify if signals coming from an intermediate throw-event trigger
	 * the right events to be dispatched.
	 */
@Deployment
public void testActivitySignalEventsWithinProcess() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("signalProcess");
    assertNotNull(processInstance);
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(task);
    Execution executionWithSignalEvent = runtimeService.createExecutionQuery().activityId("shipOrder").singleResult();
    taskService.complete(task.getId());
    assertEquals(1L, listener.getEventsReceived().size());
    assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiSignalEvent);
    ActivitiSignalEvent signalEvent = (ActivitiSignalEvent) listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ACTIVITY_SIGNALED, signalEvent.getType());
    assertEquals("shipOrder", signalEvent.getActivityId());
    assertEquals(executionWithSignalEvent.getId(), signalEvent.getExecutionId());
    assertEquals(executionWithSignalEvent.getProcessInstanceId(), signalEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), signalEvent.getProcessDefinitionId());
    assertEquals("alert", signalEvent.getSignalName());
    assertNull(signalEvent.getSignalData());
}
Also used : Task(org.activiti.engine.task.Task) Execution(org.activiti.engine.runtime.Execution) ActivitiSignalEvent(org.activiti.engine.delegate.event.ActivitiSignalEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 45 with Execution

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

the class ActivityEventsTest method testActivitySignalEvents.

/**
	 * Test events related to signalling
	 */
@Deployment
public void testActivitySignalEvents() throws Exception {
    // Two paths are active in the process, one receive-task and one
    // intermediate catching signal-event
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("signalProcess");
    assertNotNull(processInstance);
    // Check regular signal through API
    Execution executionWithSignal = runtimeService.createExecutionQuery().activityId("receivePayment").singleResult();
    assertNotNull(executionWithSignal);
    runtimeService.signal(executionWithSignal.getId());
    assertEquals(1, listener.getEventsReceived().size());
    assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiSignalEvent);
    ActivitiSignalEvent signalEvent = (ActivitiSignalEvent) listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ACTIVITY_SIGNALED, signalEvent.getType());
    assertEquals("receivePayment", signalEvent.getActivityId());
    assertEquals(executionWithSignal.getId(), signalEvent.getExecutionId());
    assertEquals(executionWithSignal.getProcessInstanceId(), signalEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), signalEvent.getProcessDefinitionId());
    assertNull(signalEvent.getSignalName());
    assertNull(signalEvent.getSignalData());
    listener.clearEventsReceived();
    // Check signal using event, and pass in additional payload
    Execution executionWithSignalEvent = runtimeService.createExecutionQuery().activityId("shipOrder").singleResult();
    runtimeService.signalEventReceived("alert", executionWithSignalEvent.getId(), Collections.singletonMap("test", (Object) "test"));
    assertEquals(1, listener.getEventsReceived().size());
    assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiSignalEvent);
    signalEvent = (ActivitiSignalEvent) listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ACTIVITY_SIGNALED, signalEvent.getType());
    assertEquals("shipOrder", signalEvent.getActivityId());
    assertEquals(executionWithSignalEvent.getId(), signalEvent.getExecutionId());
    assertEquals(executionWithSignalEvent.getProcessInstanceId(), signalEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), signalEvent.getProcessDefinitionId());
    assertEquals("alert", signalEvent.getSignalName());
    assertNotNull(signalEvent.getSignalData());
    listener.clearEventsReceived();
    assertDatabaseEventPresent(ActivitiEventType.ACTIVITY_SIGNALED);
}
Also used : Execution(org.activiti.engine.runtime.Execution) ActivitiSignalEvent(org.activiti.engine.delegate.event.ActivitiSignalEvent) 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