Search in sources :

Example 56 with ProcessInstance

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

the class MultiInstanceTest method testParalellEmptyCollection.

@Deployment(resources = { "org/activiti/engine/test/bpmn/multiinstance/MultiInstanceTest.testParallelEmptyCollection.bpmn20.xml" })
public void testParalellEmptyCollection() throws Exception {
    Collection<String> collection = Collections.emptyList();
    Map<String, Object> variableMap = new HashMap<String, Object>();
    variableMap.put("collection", collection);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testParalellEmptyCollection", variableMap);
    assertNotNull(processInstance);
    Task task = taskService.createTaskQuery().singleResult();
    assertNull(task);
    assertProcessEnded(processInstance.getId());
}
Also used : Task(org.activiti.engine.task.Task) DelegateTask(org.activiti.engine.delegate.DelegateTask) HashMap(java.util.HashMap) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 57 with ProcessInstance

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

the class MultiInstanceTest method testSequentialSubprocessEmptyCollection.

@Deployment(resources = { "org/activiti/engine/test/bpmn/multiinstance/MultiInstanceTest.testSequentialSubprocessEmptyCollection.bpmn20.xml" })
public void testSequentialSubprocessEmptyCollection() {
    Collection<String> collection = Collections.emptyList();
    Map<String, Object> variableMap = new HashMap<String, Object>();
    variableMap.put("collection", collection);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testSequentialSubProcessEmptyCollection", variableMap);
    assertNotNull(processInstance);
    Task task = taskService.createTaskQuery().singleResult();
    assertNull(task);
    assertProcessEnded(processInstance.getId());
}
Also used : Task(org.activiti.engine.task.Task) DelegateTask(org.activiti.engine.delegate.DelegateTask) HashMap(java.util.HashMap) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 58 with ProcessInstance

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

the class SubProcessTest method IGNORE_testSimpleSubProcessWithConcurrentTimer.

/**
   * A test case that has a timer attached to the subprocess,
   * where 2 concurrent paths are defined when the timer fires.
   */
@Deployment
public void IGNORE_testSimpleSubProcessWithConcurrentTimer() {
    // After staring the process, the task in the subprocess should be active
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("simpleSubProcessWithConcurrentTimer");
    TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(pi.getId()).orderByTaskName().asc();
    Task subProcessTask = taskQuery.singleResult();
    assertEquals("Task in subprocess", subProcessTask.getName());
    // When the timer is fired (after 2 hours), two concurrent paths should be created
    Job job = managementService.createJobQuery().singleResult();
    managementService.executeJob(job.getId());
    List<Task> tasksAfterTimer = taskQuery.list();
    assertEquals(2, tasksAfterTimer.size());
    Task taskAfterTimer1 = tasksAfterTimer.get(0);
    Task taskAfterTimer2 = tasksAfterTimer.get(1);
    assertEquals("Task after timer 1", taskAfterTimer1.getName());
    assertEquals("Task after timer 2", taskAfterTimer2.getName());
    // Completing the two tasks should end the process instance
    taskService.complete(taskAfterTimer1.getId());
    taskService.complete(taskAfterTimer2.getId());
    assertProcessEnded(pi.getId());
}
Also used : Task(org.activiti.engine.task.Task) TaskQuery(org.activiti.engine.task.TaskQuery) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Job(org.activiti.engine.runtime.Job) Deployment(org.activiti.engine.test.Deployment)

Example 59 with ProcessInstance

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

the class TransactionSubProcessTest method testCancelEndConcurrent.

@Deployment
public void testCancelEndConcurrent() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("transactionProcess");
    // after the process is started, we have compensate event subscriptions:
    assertEquals(5, createEventSubscriptionQuery().eventType("compensate").activityId("undoBookHotel").count());
    assertEquals(1, createEventSubscriptionQuery().eventType("compensate").activityId("undoBookFlight").count());
    // the task is present:
    Task task = taskService.createTaskQuery().singleResult();
    assertNotNull(task);
    // making the tx fail:
    taskService.setVariable(task.getId(), "confirmed", false);
    taskService.complete(task.getId());
    // now the process instance execution is sitting in the 'afterCancellation' task 
    // -> has left the transaction using the cancel boundary event
    List<String> activeActivityIds = runtimeService.getActiveActivityIds(processInstance.getId());
    assertTrue(activeActivityIds.contains("afterCancellation"));
    // we have no more compensate event subscriptions
    assertEquals(0, createEventSubscriptionQuery().eventType("compensate").count());
    // assert that the compensation handlers have been invoked:
    assertEquals(5, runtimeService.getVariable(processInstance.getId(), "undoBookHotel"));
    assertEquals(1, runtimeService.getVariable(processInstance.getId(), "undoBookFlight"));
    // if we have history, we check that the invocation of the compensation handlers is recorded in history.
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("undoBookFlight").count());
        assertEquals(5, historyService.createHistoricActivityInstanceQuery().activityId("undoBookHotel").count());
    }
    // end the process instance
    runtimeService.signal(processInstance.getId());
    assertProcessEnded(processInstance.getId());
    assertEquals(0, runtimeService.createExecutionQuery().count());
}
Also used : Task(org.activiti.engine.task.Task) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 60 with ProcessInstance

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

the class TransactionSubProcessTest method testSimpleCaseTxSuccessful.

@Deployment(resources = { "org/activiti/engine/test/bpmn/subprocess/transaction/TransactionSubProcessTest.testSimpleCase.bpmn20.xml" })
public void testSimpleCaseTxSuccessful() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("transactionProcess");
    // after the process is started, we have compensate event subscriptions:
    assertEquals(5, createEventSubscriptionQuery().eventType("compensate").activityId("undoBookHotel").count());
    assertEquals(1, createEventSubscriptionQuery().eventType("compensate").activityId("undoBookFlight").count());
    // the task is present:
    Task task = taskService.createTaskQuery().singleResult();
    assertNotNull(task);
    // making the tx succeed:
    taskService.setVariable(task.getId(), "confirmed", true);
    taskService.complete(task.getId());
    // now the process instance execution is sitting in the 'afterSuccess' task 
    // -> has left the transaction using the "normal" sequence flow
    List<String> activeActivityIds = runtimeService.getActiveActivityIds(processInstance.getId());
    assertTrue(activeActivityIds.contains("afterSuccess"));
    // there is a compensate event subscription for the transaction under the process instance
    EventSubscriptionEntity eventSubscriptionEntity = createEventSubscriptionQuery().eventType("compensate").activityId("tx").executionId(processInstance.getId()).singleResult();
    // there is an event-scope execution associated with the event-subscription:
    assertNotNull(eventSubscriptionEntity.getConfiguration());
    Execution eventScopeExecution = runtimeService.createExecutionQuery().executionId(eventSubscriptionEntity.getConfiguration()).singleResult();
    assertNotNull(eventScopeExecution);
    // we still have compensate event subscriptions for the compensation handlers, only now they are part of the event scope
    assertEquals(5, createEventSubscriptionQuery().eventType("compensate").activityId("undoBookHotel").executionId(eventScopeExecution.getId()).count());
    assertEquals(1, createEventSubscriptionQuery().eventType("compensate").activityId("undoBookFlight").executionId(eventScopeExecution.getId()).count());
    assertEquals(1, createEventSubscriptionQuery().eventType("compensate").activityId("undoChargeCard").executionId(eventScopeExecution.getId()).count());
    // assert that the compensation handlers have not been invoked:
    assertNull(runtimeService.getVariable(processInstance.getId(), "undoBookHotel"));
    assertNull(runtimeService.getVariable(processInstance.getId(), "undoBookFlight"));
    assertNull(runtimeService.getVariable(processInstance.getId(), "undoChargeCard"));
    // end the process instance
    runtimeService.signal(processInstance.getId());
    assertProcessEnded(processInstance.getId());
    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) EventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity) Deployment(org.activiti.engine.test.Deployment)

Aggregations

ProcessInstance (org.activiti.engine.runtime.ProcessInstance)822 Deployment (org.activiti.engine.test.Deployment)708 Task (org.activiti.engine.task.Task)374 HashMap (java.util.HashMap)242 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)182 Execution (org.activiti.engine.runtime.Execution)76 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)64 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)57 Job (org.activiti.engine.runtime.Job)55 Date (java.util.Date)53 JsonNode (com.fasterxml.jackson.databind.JsonNode)49 Calendar (java.util.Calendar)48 ActivitiException (org.activiti.engine.ActivitiException)41 ArrayList (java.util.ArrayList)38 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)38 HttpGet (org.apache.http.client.methods.HttpGet)38 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)27 StringEntity (org.apache.http.entity.StringEntity)27 HttpPost (org.apache.http.client.methods.HttpPost)25 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)24