org.camunda.bpm.engine.task.Task

Here are the examples of the java api class org.camunda.bpm.engine.task.Task taken from open source projects.

1. FilterTaskQueryTest#createTasks()

View license
protected void createTasks() {
    Task task = taskService.newTask("task1");
    task.setName("Task 1");
    task.setOwner(testUser.getId());
    task.setDelegationState(DelegationState.PENDING);
    taskService.saveTask(task);
    taskService.addCandidateGroup(task.getId(), "accounting");
    task = taskService.newTask("task2");
    task.setName("Task 2");
    task.setOwner(testUser.getId());
    task.setDelegationState(DelegationState.RESOLVED);
    taskService.saveTask(task);
    taskService.setAssignee(task.getId(), "kermit");
    taskService.addCandidateGroup(task.getId(), "accounting");
    task = taskService.newTask("task3");
    task.setName("Task 3");
    task.setOwner(testUser.getId());
    task.setDelegationState(DelegationState.RESOLVED);
    taskService.saveTask(task);
}

2. MultiTenancyTaskServiceTest#testStandaloneTaskCannotSetDifferentTenantIdOnSubTask()

View license
public void testStandaloneTaskCannotSetDifferentTenantIdOnSubTask() {
    // given a persistent task with a tenant id
    Task task = taskService.newTask();
    task.setTenantId(tenant1);
    taskService.saveTask(task);
    // if
    // I create a subtask with a different tenant id
    Task subTask = taskService.newTask();
    subTask.setParentTaskId(task.getId());
    subTask.setTenantId(tenant2);
    // then an exception is thrown on save
    try {
        taskService.saveTask(subTask);
        fail("Exception expected.");
    } catch (ProcessEngineException e) {
        assertTextPresent("ENGINE-03073 Cannot set different tenantId on subtask than on parent Task", e.getMessage());
    }
    // Finally, delete task
    deleteTasks(task);
}

3. HistoricTaskInstanceUpdateTest#testHistoricTaskInstanceUpdate()

View license
@Deployment
public void testHistoricTaskInstanceUpdate() {
    runtimeService.startProcessInstanceByKey("HistoricTaskInstanceTest").getId();
    Task task = taskService.createTaskQuery().singleResult();
    // Update and save the task's fields before it is finished
    task.setPriority(12345);
    task.setDescription("Updated description");
    task.setName("Updated name");
    task.setAssignee("gonzo");
    taskService.saveTask(task);
    taskService.complete(task.getId());
    assertEquals(1, historyService.createHistoricTaskInstanceQuery().count());
    HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
    assertEquals("Updated name", historicTaskInstance.getName());
    assertEquals("Updated description", historicTaskInstance.getDescription());
    assertEquals("gonzo", historicTaskInstance.getAssignee());
    assertEquals("task", historicTaskInstance.getTaskDefinitionKey());
}

4. StandaloneTaskTest#testOptimisticLockingThrownOnMultipleUpdates()

View license
public void testOptimisticLockingThrownOnMultipleUpdates() {
    Task task = taskService.newTask();
    taskService.saveTask(task);
    String taskId = task.getId();
    // first modification
    Task task1 = taskService.createTaskQuery().taskId(taskId).singleResult();
    Task task2 = taskService.createTaskQuery().taskId(taskId).singleResult();
    task1.setDescription("first modification");
    taskService.saveTask(task1);
    // second modification on the initial instance
    task2.setDescription("second modification");
    try {
        taskService.saveTask(task2);
        fail("should get an exception here as the task was modified by someone else.");
    } catch (OptimisticLockingException expected) {
    }
    taskService.deleteTask(taskId, true);
}

5. TaskQueryTest#testQueryByParentTaskId()

View license
public void testQueryByParentTaskId() {
    String parentTaskId = "parentTask";
    Task parent = taskService.newTask(parentTaskId);
    taskService.saveTask(parent);
    Task sub1 = taskService.newTask("subTask1");
    sub1.setParentTaskId(parentTaskId);
    taskService.saveTask(sub1);
    Task sub2 = taskService.newTask("subTask2");
    sub2.setParentTaskId(parentTaskId);
    taskService.saveTask(sub2);
    TaskQuery query = taskService.createTaskQuery().taskParentTaskId(parentTaskId);
    verifyQueryResults(query, 2);
    taskService.deleteTask(parentTaskId, true);
}

6. TaskServiceTest#testSetDelegationState()

View license
/**
   * @see http://jira.codehaus.org/browse/ACT-1059
   */
public void testSetDelegationState() {
    Task task = taskService.newTask();
    task.setOwner("wuzh");
    task.delegate("other");
    taskService.saveTask(task);
    String taskId = task.getId();
    task = taskService.createTaskQuery().taskId(taskId).singleResult();
    assertEquals("wuzh", task.getOwner());
    assertEquals("other", task.getAssignee());
    assertEquals(DelegationState.PENDING, task.getDelegationState());
    task.setDelegationState(DelegationState.RESOLVED);
    taskService.saveTask(task);
    task = taskService.createTaskQuery().taskId(taskId).singleResult();
    assertEquals("wuzh", task.getOwner());
    assertEquals("other", task.getAssignee());
    assertEquals(DelegationState.RESOLVED, task.getDelegationState());
    taskService.deleteTask(taskId, true);
}

7. SubprocessParallelThrowCompensationScenarioTest#testInitCompletion()

View license
@Test
@ScenarioUnderTest("init.1")
public void testInitCompletion() {
    // given
    Task beforeCompensationTask = rule.taskQuery().taskDefinitionKey("beforeCompensate").singleResult();
    Task concurrentTask = rule.taskQuery().taskDefinitionKey("concurrentTask").singleResult();
    // when compensation is thrown
    rule.getTaskService().complete(beforeCompensationTask.getId());
    // then there is an active compensation handler task
    Task compensationHandlerTask = rule.taskQuery().taskDefinitionKey("undoTask").singleResult();
    Assert.assertNotNull(compensationHandlerTask);
    // and it can be completed such that the process instance ends successfully
    rule.getTaskService().complete(compensationHandlerTask.getId());
    Task afterCompensateTask = rule.taskQuery().taskDefinitionKey("afterCompensate").singleResult();
    Assert.assertNotNull(afterCompensateTask);
    rule.getTaskService().complete(afterCompensateTask.getId());
    rule.getTaskService().complete(concurrentTask.getId());
    rule.assertScenarioEnded();
}

8. TaskAuthorizationTest#testStandaloneTaskGetSubTasksWithoutAuthorization()

View license
// get sub tasks ((standalone) task) ////////////////////////////////////
public void testStandaloneTaskGetSubTasksWithoutAuthorization() {
    // given
    String parentTaskId = "parentTaskId";
    createTask(parentTaskId);
    disableAuthorization();
    Task sub1 = taskService.newTask("sub1");
    sub1.setParentTaskId(parentTaskId);
    taskService.saveTask(sub1);
    Task sub2 = taskService.newTask("sub2");
    sub2.setParentTaskId(parentTaskId);
    taskService.saveTask(sub2);
    enableAuthorization();
    // when
    List<Task> subTasks = taskService.getSubTasks(parentTaskId);
    // then
    assertTrue(subTasks.isEmpty());
    deleteTask(parentTaskId, true);
}

9. TaskAuthorizationTest#testProcessTaskGetSubTasksWithoutAuthorization()

View license
// get sub tasks ((process) task) ////////////////////////////////////
public void testProcessTaskGetSubTasksWithoutAuthorization() {
    // given
    startProcessInstanceByKey(PROCESS_KEY);
    String parentTaskId = selectSingleTask().getId();
    disableAuthorization();
    Task sub1 = taskService.newTask("sub1");
    sub1.setParentTaskId(parentTaskId);
    taskService.saveTask(sub1);
    Task sub2 = taskService.newTask("sub2");
    sub2.setParentTaskId(parentTaskId);
    taskService.saveTask(sub2);
    enableAuthorization();
    // when
    List<Task> subTasks = taskService.getSubTasks(parentTaskId);
    // then
    assertTrue(subTasks.isEmpty());
}

10. TaskAuthorizationTest#testProcessTaskGetSubTasks()

View license
public void testProcessTaskGetSubTasks() {
    // given
    startProcessInstanceByKey(PROCESS_KEY);
    String parentTaskId = selectSingleTask().getId();
    disableAuthorization();
    Task sub1 = taskService.newTask("sub1");
    sub1.setParentTaskId(parentTaskId);
    taskService.saveTask(sub1);
    Task sub2 = taskService.newTask("sub2");
    sub2.setParentTaskId(parentTaskId);
    taskService.saveTask(sub2);
    enableAuthorization();
    createGrantAuthorization(TASK, ANY, userId, READ);
    // when
    List<Task> subTasks = taskService.getSubTasks(parentTaskId);
    // then
    assertFalse(subTasks.isEmpty());
    assertEquals(2, subTasks.size());
}

11. TaskAuthorizationTest#testCaseTaskGetSubTasksWithoutAuthorization()

View license
// get sub tasks ((case) task) ////////////////////////////////////
public void testCaseTaskGetSubTasksWithoutAuthorization() {
    // given
    createCaseInstanceByKey(CASE_KEY);
    String parentTaskId = selectSingleTask().getId();
    disableAuthorization();
    Task sub1 = taskService.newTask("sub1");
    sub1.setParentTaskId(parentTaskId);
    taskService.saveTask(sub1);
    Task sub2 = taskService.newTask("sub2");
    sub2.setParentTaskId(parentTaskId);
    taskService.saveTask(sub2);
    enableAuthorization();
    // when
    List<Task> subTasks = taskService.getSubTasks(parentTaskId);
    // then
    assertTrue(subTasks.isEmpty());
}

12. TaskAuthorizationTest#testCaseTaskGetSubTasks()

View license
public void testCaseTaskGetSubTasks() {
    // given
    createCaseInstanceByKey(CASE_KEY);
    String parentTaskId = selectSingleTask().getId();
    disableAuthorization();
    Task sub1 = taskService.newTask("sub1");
    sub1.setParentTaskId(parentTaskId);
    taskService.saveTask(sub1);
    Task sub2 = taskService.newTask("sub2");
    sub2.setParentTaskId(parentTaskId);
    taskService.saveTask(sub2);
    enableAuthorization();
    createGrantAuthorization(TASK, ANY, userId, READ);
    // when
    List<Task> subTasks = taskService.getSubTasks(parentTaskId);
    // then
    assertFalse(subTasks.isEmpty());
    assertEquals(2, subTasks.size());
}

13. MultiTenancyTaskServiceTest#testStandaloneTaskCannotSetDifferentTenantIdOnSubTaskWithNull()

View license
public void testStandaloneTaskCannotSetDifferentTenantIdOnSubTaskWithNull() {
    // given a persistent task without tenant id
    Task task = taskService.newTask();
    taskService.saveTask(task);
    // if
    // I create a subtask with a different tenant id
    Task subTask = taskService.newTask();
    subTask.setParentTaskId(task.getId());
    subTask.setTenantId(tenant1);
    // then an exception is thrown on save
    try {
        taskService.saveTask(subTask);
        fail("Exception expected.");
    } catch (ProcessEngineException e) {
        assertTextPresent("ENGINE-03073 Cannot set different tenantId on subtask than on parent Task", e.getMessage());
    }
    // Finally, delete task
    deleteTasks(task);
}

14. MultiTenancyTaskServiceTest#testStandaloneTaskPropagateTenantIdToSubTask()

View license
public void testStandaloneTaskPropagateTenantIdToSubTask() {
    // given a persistent task with a tenant id
    Task task = taskService.newTask();
    task.setTenantId(tenant1);
    taskService.saveTask(task);
    // if
    // I create a subtask without tenant id
    Task subTask = taskService.newTask();
    subTask.setParentTaskId(task.getId());
    taskService.saveTask(subTask);
    // then
    // the parent task's tenant id is propagated to the sub task
    subTask = taskService.createTaskQuery().taskId(subTask.getId()).singleResult();
    assertEquals(tenant1, subTask.getTenantId());
    // Finally, delete task
    deleteTasks(subTask, task);
}

15. SingleActivityCompensationScenarioTest#testInitCompletion()

View license
@Test
@ScenarioUnderTest("init.1")
public void testInitCompletion() {
    // when compensation is thrown
    Task beforeCompensationTask = rule.taskQuery().singleResult();
    rule.getTaskService().complete(beforeCompensationTask.getId());
    // then there is an active compensation handler task
    Task compensationHandlerTask = rule.taskQuery().singleResult();
    Assert.assertNotNull(compensationHandlerTask);
    Assert.assertEquals("undoTask", compensationHandlerTask.getTaskDefinitionKey());
    // and it can be completed such that the process instance ends successfully
    rule.getTaskService().complete(compensationHandlerTask.getId());
    Task afterCompensateTask = rule.taskQuery().singleResult();
    Assert.assertNotNull(afterCompensateTask);
    Assert.assertEquals("afterCompensate", afterCompensateTask.getTaskDefinitionKey());
    rule.getTaskService().complete(afterCompensateTask.getId());
    rule.assertScenarioEnded();
}

16. TaskServiceTest#testUserTaskOptimisticLocking()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testUserTaskOptimisticLocking() {
    runtimeService.startProcessInstanceByKey("oneTaskProcess");
    Task task1 = taskService.createTaskQuery().singleResult();
    Task task2 = taskService.createTaskQuery().singleResult();
    task1.setDescription("test description one");
    taskService.saveTask(task1);
    try {
        task2.setDescription("test description two");
        taskService.saveTask(task2);
        fail("Expecting exception");
    } catch (OptimisticLockingException e) {
    }
}

17. TaskServiceTest#testTaskCaseInstanceId()

View license
public void testTaskCaseInstanceId() {
    Task task = taskService.newTask();
    task.setCaseInstanceId("aCaseInstanceId");
    taskService.saveTask(task);
    // Fetch the task again and update
    task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
    assertEquals("aCaseInstanceId", task.getCaseInstanceId());
    task.setCaseInstanceId("anotherCaseInstanceId");
    taskService.saveTask(task);
    task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
    assertEquals("anotherCaseInstanceId", task.getCaseInstanceId());
    // Finally, delete task
    taskService.deleteTask(task.getId(), true);
}

18. CompensateEventTest#testCompensateActivityInConcurrentSubprocess()

View license
@Deployment
public void testCompensateActivityInConcurrentSubprocess() {
    // given
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("compensateProcess");
    Task scopeTask = taskService.createTaskQuery().taskDefinitionKey("scopeTask").singleResult();
    taskService.complete(scopeTask.getId());
    Task outerTask = taskService.createTaskQuery().taskDefinitionKey("outerTask").singleResult();
    taskService.complete(outerTask.getId());
    // process has not yet thrown compensation
    // when throw compensation
    runtimeService.signal(instance.getId());
    // then
    Task compensationTask = taskService.createTaskQuery().singleResult();
    assertNotNull(compensationTask);
    assertEquals("undoScopeTask", compensationTask.getTaskDefinitionKey());
    taskService.complete(compensationTask.getId());
    runtimeService.signal(instance.getId());
    assertProcessEnded(instance.getId());
}

19. TransactionSubProcessTest#testCompensateSubprocessNotTriggered()

View license
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/subprocess/transaction/TransactionSubProcessTest.testCompensateSubprocess.bpmn20.xml")
public void testCompensateSubprocessNotTriggered() {
    // given
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("txProcess");
    Task innerTask = taskService.createTaskQuery().singleResult();
    taskService.complete(innerTask.getId());
    // when the transaction is not cancelled
    runtimeService.setVariable(instance.getId(), "cancelTx", false);
    runtimeService.setVariable(instance.getId(), "compensate", false);
    Task beforeEndTask = taskService.createTaskQuery().singleResult();
    taskService.complete(beforeEndTask.getId());
    // then
    Task afterTxTask = taskService.createTaskQuery().singleResult();
    assertEquals("afterTx", afterTxTask.getTaskDefinitionKey());
    // and the process has ended
    taskService.complete(afterTxTask.getId());
    assertProcessEnded(instance.getId());
}

20. ProcessInstanceSuspensionTest#testSubTaskCreationFailAfterProcessInstanceSuspend()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testSubTaskCreationFailAfterProcessInstanceSuspend() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
    final Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    Task subTask = taskService.newTask("someTaskId");
    subTask.setParentTaskId(task.getId());
    try {
        taskService.saveTask(subTask);
        fail("Creating sub tasks for suspended task should not be possible");
    } catch (SuspendedEntityInteractionException e) {
    }
}

21. ProcessInstanceSuspensionTest#testSubTaskCreationFailAfterProcessInstanceSuspendByProcessDefinitionId()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testSubTaskCreationFailAfterProcessInstanceSuspendByProcessDefinitionId() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
    final Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    runtimeService.suspendProcessInstanceByProcessDefinitionId(processDefinition.getId());
    Task subTask = taskService.newTask("someTaskId");
    subTask.setParentTaskId(task.getId());
    try {
        taskService.saveTask(subTask);
        fail("Creating sub tasks for suspended task should not be possible");
    } catch (SuspendedEntityInteractionException e) {
    }
}

22. ProcessInstanceSuspensionTest#testSubTaskCreationFailAfterProcessInstanceSuspendByProcessDefinitionKey()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testSubTaskCreationFailAfterProcessInstanceSuspendByProcessDefinitionKey() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
    final Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    runtimeService.suspendProcessInstanceByProcessDefinitionKey(processDefinition.getKey());
    Task subTask = taskService.newTask("someTaskId");
    subTask.setParentTaskId(task.getId());
    try {
        taskService.saveTask(subTask);
        fail("Creating sub tasks for suspended task should not be possible");
    } catch (SuspendedEntityInteractionException e) {
    }
}

23. StandaloneTaskTest#testRevisionUpdatedOnSave()

View license
// See http://jira.codehaus.org/browse/ACT-1290
public void testRevisionUpdatedOnSave() {
    Task task = taskService.newTask();
    taskService.saveTask(task);
    assertEquals(1, ((TaskEntity) task).getRevision());
    task.setDescription("first modification");
    taskService.saveTask(task);
    assertEquals(2, ((TaskEntity) task).getRevision());
    task.setDescription("second modification");
    taskService.saveTask(task);
    assertEquals(3, ((TaskEntity) task).getRevision());
    taskService.deleteTask(task.getId(), true);
}

24. TaskServiceTest#testSaveTaskSetParentTaskId()

View license
public void testSaveTaskSetParentTaskId() {
    // given
    Task parent = taskService.newTask("parent");
    taskService.saveTask(parent);
    Task task = taskService.newTask("subTask");
    // when
    task.setParentTaskId("parent");
    // then
    taskService.saveTask(task);
    // update task
    task = taskService.createTaskQuery().taskId("subTask").singleResult();
    assertEquals(parent.getId(), task.getParentTaskId());
    taskService.deleteTask("parent", true);
    taskService.deleteTask("subTask", true);
}

25. TaskServiceTest#testTaskOwner()

View license
public void testTaskOwner() {
    Task task = taskService.newTask();
    task.setOwner("johndoe");
    taskService.saveTask(task);
    // Fetch the task again and update
    task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
    assertEquals("johndoe", task.getOwner());
    task.setOwner("joesmoe");
    taskService.saveTask(task);
    task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
    assertEquals("joesmoe", task.getOwner());
    // Finally, delete task
    taskService.deleteTask(task.getId(), true);
}

26. TaskServiceTest#testTaskAssignee()

View license
public void testTaskAssignee() {
    Task task = taskService.newTask();
    task.setAssignee("johndoe");
    taskService.saveTask(task);
    // Fetch the task again and update
    task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
    assertEquals("johndoe", task.getAssignee());
    task.setAssignee("joesmoe");
    taskService.saveTask(task);
    task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
    assertEquals("joesmoe", task.getAssignee());
    // Finally, delete task
    taskService.deleteTask(task.getId(), true);
}

27. InterruptingEventSubprocessCompensationScenarioTest#testInitCompletion()

View license
@Test
@ScenarioUnderTest("init.1")
public void testInitCompletion() {
    // when compensation is thrown
    Task beforeCompensationTask = rule.taskQuery().singleResult();
    rule.getTaskService().complete(beforeCompensationTask.getId());
    // then there is an active compensation handler task
    Task compensationHandlerTask = rule.taskQuery().singleResult();
    Assert.assertNotNull(compensationHandlerTask);
    Assert.assertEquals("undoTask", compensationHandlerTask.getTaskDefinitionKey());
    // and it can be completed such that the process instance ends successfully
    rule.getTaskService().complete(compensationHandlerTask.getId());
    Task afterCompensateTask = rule.taskQuery().singleResult();
    Assert.assertNotNull(afterCompensateTask);
    Assert.assertEquals("afterCompensate", afterCompensateTask.getTaskDefinitionKey());
    rule.getTaskService().complete(afterCompensateTask.getId());
    rule.assertScenarioEnded();
}

28. SingleActivityCompensationScenarioTest#testInitCompletion()

View license
@Test
@ScenarioUnderTest("init.1")
public void testInitCompletion() {
    // when compensation is thrown
    Task beforeCompensationTask = rule.taskQuery().singleResult();
    rule.getTaskService().complete(beforeCompensationTask.getId());
    // then there is an active compensation handler task
    Task compensationHandlerTask = rule.taskQuery().singleResult();
    Assert.assertNotNull(compensationHandlerTask);
    Assert.assertEquals("undoTask", compensationHandlerTask.getTaskDefinitionKey());
    // and it can be completed such that the process instance ends successfully
    rule.getTaskService().complete(compensationHandlerTask.getId());
    Task afterCompensateTask = rule.taskQuery().singleResult();
    Assert.assertNotNull(afterCompensateTask);
    Assert.assertEquals("afterCompensate", afterCompensateTask.getTaskDefinitionKey());
    rule.getTaskService().complete(afterCompensateTask.getId());
    rule.assertScenarioEnded();
}

29. SubprocessCompensationScenarioTest#testInitCompletion()

View license
@Test
@ScenarioUnderTest("init.1")
public void testInitCompletion() {
    // when compensation is thrown
    Task beforeCompensationTask = rule.taskQuery().singleResult();
    rule.getTaskService().complete(beforeCompensationTask.getId());
    // then there is an active compensation handler task
    Task compensationHandlerTask = rule.taskQuery().singleResult();
    Assert.assertNotNull(compensationHandlerTask);
    Assert.assertEquals("undoTask", compensationHandlerTask.getTaskDefinitionKey());
    // and it can be completed such that the process instance ends successfully
    rule.getTaskService().complete(compensationHandlerTask.getId());
    Task afterCompensateTask = rule.taskQuery().singleResult();
    Assert.assertNotNull(afterCompensateTask);
    Assert.assertEquals("afterCompensate", afterCompensateTask.getTaskDefinitionKey());
    rule.getTaskService().complete(afterCompensateTask.getId());
    rule.assertScenarioEnded();
}

30. SubprocessCompensationScenarioTest#testInitConcurrentTriggerCompensationCompletion()

View license
@Test
@ScenarioUnderTest("init.concurrent.triggerCompensation.1")
public void testInitConcurrentTriggerCompensationCompletion() {
    // given active compensation
    Task undoTask1 = rule.taskQuery().taskDefinitionKey("undoTask1").singleResult();
    Task undoTask2 = rule.taskQuery().taskDefinitionKey("undoTask2").singleResult();
    // then it is possible to complete compensation and the follow-up task
    rule.getTaskService().complete(undoTask1.getId());
    rule.getTaskService().complete(undoTask2.getId());
    Task afterCompensateTask = rule.taskQuery().singleResult();
    Assert.assertNotNull(afterCompensateTask);
    Assert.assertEquals("afterCompensate", afterCompensateTask.getTaskDefinitionKey());
    rule.getTaskService().complete(afterCompensateTask.getId());
    rule.assertScenarioEnded();
}

31. SubprocessParallelThrowCompensationScenarioTest#testInitTriggerCompensationCompletion()

View license
@Test
@ScenarioUnderTest("init.triggerCompensation.1")
public void testInitTriggerCompensationCompletion() {
    // given active compensation
    Task compensationHandlerTask = rule.taskQuery().taskDefinitionKey("undoTask").singleResult();
    Task concurrentTask = rule.taskQuery().taskDefinitionKey("concurrentTask").singleResult();
    // then it is possible to complete compensation and the follow-up task, as well as the concurrent task
    rule.getTaskService().complete(compensationHandlerTask.getId());
    Task afterCompensateTask = rule.taskQuery().taskDefinitionKey("afterCompensate").singleResult();
    Assert.assertNotNull(afterCompensateTask);
    rule.getTaskService().complete(afterCompensateTask.getId());
    rule.getTaskService().complete(concurrentTask.getId());
    rule.assertScenarioEnded();
}

32. TransactionCancelCompensationScenarioTest#testInitCompletion()

View license
@Test
@ScenarioUnderTest("init.1")
public void testInitCompletion() {
    // when compensation is thrown
    Task beforeCompensationTask = rule.taskQuery().singleResult();
    rule.getTaskService().complete(beforeCompensationTask.getId());
    // then there is an active compensation handler task
    Task compensationHandlerTask = rule.taskQuery().singleResult();
    Assert.assertNotNull(compensationHandlerTask);
    Assert.assertEquals("undoTask", compensationHandlerTask.getTaskDefinitionKey());
    // and it can be completed such that the process instance ends successfully
    rule.getTaskService().complete(compensationHandlerTask.getId());
    Task afterCompensateTask = rule.taskQuery().singleResult();
    Assert.assertNotNull(afterCompensateTask);
    Assert.assertEquals("afterCancel", afterCompensateTask.getTaskDefinitionKey());
    rule.getTaskService().complete(afterCompensateTask.getId());
    rule.assertScenarioEnded();
}

33. NestedNonInterruptingEventSubprocessNestedSubprocessTest#testInitCompletionCase1()

View license
@Test
@ScenarioUnderTest("init.1")
public void testInitCompletionCase1() {
    // given
    Task outerSubProcessTask = rule.taskQuery().taskDefinitionKey("outerSubProcessTask").singleResult();
    Task eventSubprocessTask = rule.taskQuery().taskDefinitionKey("eventSubProcessTask").singleResult();
    // when
    rule.getTaskService().complete(outerSubProcessTask.getId());
    rule.getTaskService().complete(eventSubprocessTask.getId());
    // then
    Task innerSubprocessTask = rule.taskQuery().singleResult();
    Assert.assertNotNull(innerSubprocessTask);
    rule.getTaskService().complete(innerSubprocessTask.getId());
    // and
    rule.assertScenarioEnded();
}

34. NestedNonInterruptingEventSubprocessNestedSubprocessTest#testInitCompletionCase2()

View license
@Test
@ScenarioUnderTest("init.2")
public void testInitCompletionCase2() {
    // given
    Task outerSubProcessTask = rule.taskQuery().taskDefinitionKey("outerSubProcessTask").singleResult();
    Task eventSubprocessTask = rule.taskQuery().taskDefinitionKey("eventSubProcessTask").singleResult();
    // when
    rule.getTaskService().complete(eventSubprocessTask.getId());
    rule.getTaskService().complete(outerSubProcessTask.getId());
    // then
    Task innerSubprocessTask = rule.taskQuery().singleResult();
    Assert.assertNotNull(innerSubprocessTask);
    rule.getTaskService().complete(innerSubprocessTask.getId());
    // and
    rule.assertScenarioEnded();
}

35. NestedNonInterruptingEventSubprocessNestedSubprocessTest#testInitThrowError()

View license
@Test
@ScenarioUnderTest("init.5")
public void testInitThrowError() {
    // given
    ProcessInstance instance = rule.processInstance();
    Task eventSubProcessTask = rule.taskQuery().taskDefinitionKey("eventSubProcessTask").singleResult();
    // when
    rule.getTaskService().complete(eventSubProcessTask.getId());
    // and
    rule.getRuntimeService().setVariable(instance.getId(), ThrowBpmnErrorDelegate.ERROR_INDICATOR_VARIABLE, true);
    Task innerSubProcessTask = rule.taskQuery().taskDefinitionKey("innerSubProcessTask").singleResult();
    Assert.assertNotNull(innerSubProcessTask);
    rule.getTaskService().complete(innerSubProcessTask.getId());
    // then
    Task afterErrorTask = rule.taskQuery().singleResult();
    Assert.assertNotNull(afterErrorTask);
    Assert.assertEquals("escalatedTask", afterErrorTask.getTaskDefinitionKey());
    // and
    rule.getTaskService().complete(afterErrorTask.getId());
    rule.assertScenarioEnded();
}

36. NestedParallelNonInterruptingEventSubprocessScenarioTest#testInitCompletionCase1()

View license
@Test
@ScenarioUnderTest("init.1")
public void testInitCompletionCase1() {
    // given
    Task innerTask = rule.taskQuery().taskDefinitionKey("innerTask").singleResult();
    Task eventSubprocessTask1 = rule.taskQuery().taskDefinitionKey("eventSubProcessTask1").singleResult();
    Task eventSubprocessTask2 = rule.taskQuery().taskDefinitionKey("eventSubProcessTask2").singleResult();
    // when
    rule.getTaskService().complete(innerTask.getId());
    rule.getTaskService().complete(eventSubprocessTask1.getId());
    rule.getTaskService().complete(eventSubprocessTask2.getId());
    // then
    rule.assertScenarioEnded();
}

37. NestedParallelNonInterruptingEventSubprocessScenarioTest#testInitCompletionCase2()

View license
@Test
@ScenarioUnderTest("init.2")
public void testInitCompletionCase2() {
    // given
    Task innerTask = rule.taskQuery().taskDefinitionKey("innerTask").singleResult();
    Task eventSubprocessTask1 = rule.taskQuery().taskDefinitionKey("eventSubProcessTask1").singleResult();
    Task eventSubprocessTask2 = rule.taskQuery().taskDefinitionKey("eventSubProcessTask2").singleResult();
    // when
    rule.getTaskService().complete(eventSubprocessTask1.getId());
    rule.getTaskService().complete(eventSubprocessTask2.getId());
    rule.getTaskService().complete(innerTask.getId());
    // then
    rule.assertScenarioEnded();
}

38. ParallelNestedNonInterruptingEventSubprocessScenarioTest#testInitCompletionCase1()

View license
@Test
@ScenarioUnderTest("init.1")
public void testInitCompletionCase1() {
    // given
    Task outerTask = rule.taskQuery().taskDefinitionKey("outerTask").singleResult();
    Task innerTask = rule.taskQuery().taskDefinitionKey("innerTask").singleResult();
    Task eventSubprocessTask = rule.taskQuery().taskDefinitionKey("eventSubProcessTask").singleResult();
    // when
    rule.getTaskService().complete(outerTask.getId());
    rule.getTaskService().complete(innerTask.getId());
    rule.getTaskService().complete(eventSubprocessTask.getId());
    // then
    rule.assertScenarioEnded();
}

39. ParallelNestedNonInterruptingEventSubprocessScenarioTest#testInitCompletionCase2()

View license
@Test
@ScenarioUnderTest("init.2")
public void testInitCompletionCase2() {
    // given
    Task outerTask = rule.taskQuery().taskDefinitionKey("outerTask").singleResult();
    Task innerTask = rule.taskQuery().taskDefinitionKey("innerTask").singleResult();
    Task eventSubprocessTask = rule.taskQuery().taskDefinitionKey("eventSubProcessTask").singleResult();
    // when
    rule.getTaskService().complete(eventSubprocessTask.getId());
    rule.getTaskService().complete(innerTask.getId());
    rule.getTaskService().complete(outerTask.getId());
    // then
    rule.assertScenarioEnded();
}

40. ParallelNestedNonInterruptingEventSubprocessScenarioTest#testInitThrowError()

View license
@ScenarioUnderTest("init.5")
public void testInitThrowError() {
    // given
    ProcessInstance instance = rule.processInstance();
    Task eventSubprocessTask = rule.taskQuery().taskDefinitionKey("eventSubProcessTask").singleResult();
    Task outerTask = rule.taskQuery().taskDefinitionKey("outerTask").singleResult();
    // when
    rule.getTaskService().complete(outerTask.getId());
    rule.getRuntimeService().setVariable(instance.getId(), ThrowBpmnErrorDelegate.ERROR_INDICATOR_VARIABLE, true);
    rule.getTaskService().complete(eventSubprocessTask.getId());
    // then
    Task escalatedTask = rule.taskQuery().singleResult();
    Assert.assertEquals("escalatedTask", escalatedTask.getTaskDefinitionKey());
    Assert.assertNotNull(escalatedTask);
    rule.getTaskService().complete(escalatedTask.getId());
    rule.assertScenarioEnded();
}

41. ParallelNestedNonInterruptingEventSubprocessScenarioTest#testInitInnerTaskThrowError()

View license
@Test
@ScenarioUnderTest("init.innerTask.5")
public void testInitInnerTaskThrowError() {
    // given
    ProcessInstance instance = rule.processInstance();
    Task eventSubprocessTask = rule.taskQuery().taskDefinitionKey("eventSubProcessTask").singleResult();
    Task outerTask = rule.taskQuery().taskDefinitionKey("outerTask").singleResult();
    // when
    rule.getTaskService().complete(outerTask.getId());
    rule.getRuntimeService().setVariable(instance.getId(), ThrowBpmnErrorDelegate.ERROR_INDICATOR_VARIABLE, true);
    rule.getTaskService().complete(eventSubprocessTask.getId());
    // then
    Task escalatedTask = rule.taskQuery().singleResult();
    Assert.assertEquals("escalatedTask", escalatedTask.getTaskDefinitionKey());
    Assert.assertNotNull(escalatedTask);
    rule.getTaskService().complete(escalatedTask.getId());
    // the instance is deadlocked since no token has arrived on the sequence flow leaving the outer subprocess
    Assert.assertEquals(1, rule.executionQuery().count());
    Assert.assertEquals(1, rule.executionQuery().activityId("join").count());
}

42. TwoLevelNestedNonInterruptingEventSubprocessScenarioTest#testInitLevel1CompletionCase3()

View license
@Test
@ScenarioUnderTest("initLevel1.3")
public void testInitLevel1CompletionCase3() {
    // given
    Task outerTask = rule.taskQuery().taskDefinitionKey("outerTask").singleResult();
    Task innerTask = rule.taskQuery().taskDefinitionKey("subProcessTask").singleResult();
    // when
    rule.messageCorrelation("InnerEventSubProcessMessage").correlate();
    // then
    Assert.assertEquals(3, rule.taskQuery().count());
    Task innerEventSubprocessTask = rule.taskQuery().taskDefinitionKey("innerEventSubProcessTask").singleResult();
    Assert.assertNotNull(innerEventSubprocessTask);
    // and
    rule.getTaskService().complete(innerTask.getId());
    rule.getTaskService().complete(innerEventSubprocessTask.getId());
    rule.getTaskService().complete(outerTask.getId());
    rule.assertScenarioEnded();
}

43. TwoLevelNestedNonInterruptingEventSubprocessScenarioTest#testInitLevel1InitLevel2CompletionCase1()

View license
@Test
@ScenarioUnderTest("initLevel1.initLevel2.1")
public void testInitLevel1InitLevel2CompletionCase1() {
    // given
    Task outerTask = rule.taskQuery().taskDefinitionKey("outerTask").singleResult();
    Task innerTask = rule.taskQuery().taskDefinitionKey("subProcessTask").singleResult();
    Task innerEventSubprocessTask = rule.taskQuery().taskDefinitionKey("innerEventSubProcessTask").singleResult();
    // when
    rule.getTaskService().complete(outerTask.getId());
    rule.getTaskService().complete(innerTask.getId());
    rule.getTaskService().complete(innerEventSubprocessTask.getId());
    // then
    rule.assertScenarioEnded();
}

44. TwoLevelNestedNonInterruptingEventSubprocessScenarioTest#testInitLevel1InitLevel2CompletionCase2()

View license
@Test
@ScenarioUnderTest("initLevel1.initLevel2.2")
public void testInitLevel1InitLevel2CompletionCase2() {
    // given
    Task outerTask = rule.taskQuery().taskDefinitionKey("outerTask").singleResult();
    Task innerTask = rule.taskQuery().taskDefinitionKey("subProcessTask").singleResult();
    Task innerEventSubprocessTask = rule.taskQuery().taskDefinitionKey("innerEventSubProcessTask").singleResult();
    // when
    rule.getTaskService().complete(innerEventSubprocessTask.getId());
    rule.getTaskService().complete(innerTask.getId());
    rule.getTaskService().complete(outerTask.getId());
    // then
    rule.assertScenarioEnded();
}

45. ParallelMultiInstanceScenarioTest#testInitNonInterruptingBoundaryEventThrowError()

View license
@Test
@ScenarioUnderTest("initNonInterruptingBoundaryEvent.6")
public void testInitNonInterruptingBoundaryEventThrowError() {
    // given
    ProcessInstance instance = rule.processInstance();
    Task miSubprocessTask = rule.taskQuery().taskDefinitionKey("subProcessTask").list().get(0);
    Task afterBoundaryTask = rule.taskQuery().taskDefinitionKey("afterBoundaryTask").singleResult();
    // when
    rule.getRuntimeService().setVariable(instance.getId(), ThrowBpmnErrorDelegate.ERROR_INDICATOR_VARIABLE, true);
    rule.getTaskService().complete(miSubprocessTask.getId());
    // then
    Assert.assertEquals(2, rule.taskQuery().count());
    Task escalatedTask = rule.taskQuery().taskDefinitionKey("escalatedTask").singleResult();
    Assert.assertNotNull(escalatedTask);
    // and
    rule.getTaskService().complete(escalatedTask.getId());
    rule.getTaskService().complete(afterBoundaryTask.getId());
    rule.assertScenarioEnded();
}

46. SequentialMultiInstanceScenarioTest#testInitNonInterruptingBoundaryEventThrowError()

View license
@Test
@ScenarioUnderTest("initNonInterruptingBoundaryEvent.6")
public void testInitNonInterruptingBoundaryEventThrowError() {
    // given
    ProcessInstance instance = rule.processInstance();
    Task miSubprocessTask = rule.taskQuery().taskDefinitionKey("subProcessTask").singleResult();
    Task afterBoundaryTask = rule.taskQuery().taskDefinitionKey("afterBoundaryTask").singleResult();
    // when
    rule.getRuntimeService().setVariable(instance.getId(), ThrowBpmnErrorDelegate.ERROR_INDICATOR_VARIABLE, true);
    rule.getTaskService().complete(miSubprocessTask.getId());
    // then
    Assert.assertEquals(2, rule.taskQuery().count());
    Task escalatedTask = rule.taskQuery().taskDefinitionKey("escalatedTask").singleResult();
    Assert.assertNotNull(escalatedTask);
    // and
    rule.getTaskService().complete(escalatedTask.getId());
    rule.getTaskService().complete(afterBoundaryTask.getId());
    rule.assertScenarioEnded();
}

47. NonInterruptingEventSubProcessCompensationSenarioTest#testInitThrowCompensateCompletionCase1()

View license
@Test
@ScenarioUnderTest("init.throwCompensate.1")
public void testInitThrowCompensateCompletionCase1() {
    // given
    Task outerTask = rule.taskQuery().taskDefinitionKey("outerTask").singleResult();
    Task undoTask = rule.taskQuery().taskDefinitionKey("undoTask").singleResult();
    // when
    rule.getTaskService().complete(undoTask.getId());
    // then it is possible to complete the process successfully
    Task afterCompensateTask = rule.taskQuery().taskDefinitionKey("afterCompensate").singleResult();
    Assert.assertNotNull(afterCompensateTask);
    Assert.assertEquals("afterCompensate", afterCompensateTask.getTaskDefinitionKey());
    rule.getTaskService().complete(afterCompensateTask.getId());
    rule.getTaskService().complete(outerTask.getId());
    rule.assertScenarioEnded();
}

48. NonInterruptingEventSubProcessCompensationSenarioTest#testInitThrowCompensateCompletionCase2()

View license
@Test
@ScenarioUnderTest("init.throwCompensate.2")
public void testInitThrowCompensateCompletionCase2() {
    // given
    Task outerTask = rule.taskQuery().taskDefinitionKey("outerTask").singleResult();
    Task undoTask = rule.taskQuery().taskDefinitionKey("undoTask").singleResult();
    // when
    rule.getTaskService().complete(outerTask.getId());
    rule.getTaskService().complete(undoTask.getId());
    // then it is possible to complete the process successfully
    Task afterCompensateTask = rule.taskQuery().taskDefinitionKey("afterCompensate").singleResult();
    Assert.assertNotNull(afterCompensateTask);
    Assert.assertEquals("afterCompensate", afterCompensateTask.getTaskDefinitionKey());
    rule.getTaskService().complete(afterCompensateTask.getId());
    rule.assertScenarioEnded();
}

49. NonInterruptingEventSubProcessCompensationSenarioTest#testInitThrowCompensateCompletion()

View license
@Test
@ScenarioUnderTest("init.throwCompensate.3")
public void testInitThrowCompensateCompletion() {
    // given
    Task outerTask = rule.taskQuery().taskDefinitionKey("outerTask").singleResult();
    Task undoTask = rule.taskQuery().taskDefinitionKey("undoTask").singleResult();
    // when
    rule.getTaskService().complete(undoTask.getId());
    // then it is possible to complete the process successfully
    rule.getTaskService().complete(outerTask.getId());
    Task afterCompensateTask = rule.taskQuery().taskDefinitionKey("afterCompensate").singleResult();
    Assert.assertNotNull(afterCompensateTask);
    Assert.assertEquals("afterCompensate", afterCompensateTask.getTaskDefinitionKey());
    rule.getTaskService().complete(afterCompensateTask.getId());
    rule.assertScenarioEnded();
}

50. MultiTenancyTaskServiceTest#testStandaloneTaskCannotChangeTenantId()

View license
public void testStandaloneTaskCannotChangeTenantId() {
    // given a persistent task with tenant id
    Task task = taskService.newTask();
    task.setTenantId(tenant1);
    taskService.saveTask(task);
    task = taskService.createTaskQuery().singleResult();
    // if
    // change the tenant id
    task.setTenantId(tenant2);
    // an exception is thrown on 'save'
    try {
        taskService.saveTask(task);
        fail("Expected an exception");
    } catch (ProcessEngineException e) {
        assertTextPresent("ENGINE-03072 Cannot change tenantId of Task", e.getMessage());
    }
    // Finally, delete task
    deleteTasks(task);
}

51. NestedNonInterruptingEventSubprocessScenarioTest#testInitCompletionCase1()

View license
@Test
@ScenarioUnderTest("init.1")
public void testInitCompletionCase1() {
    // given
    Task innerTask = rule.taskQuery().taskDefinitionKey("innerTask").singleResult();
    Task eventSubprocessTask = rule.taskQuery().taskDefinitionKey("eventSubProcessTask").singleResult();
    // when
    rule.getTaskService().complete(innerTask.getId());
    rule.getTaskService().complete(eventSubprocessTask.getId());
    // then
    rule.assertScenarioEnded();
}

52. InclusiveGatewayTest#testPartialMergingInclusiveGateway()

View license
@Deployment
public void testPartialMergingInclusiveGateway() {
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("partialInclusiveGwMerging", CollectionUtil.singletonMap("input", 2));
    Task partialTask = taskService.createTaskQuery().singleResult();
    assertEquals("partialTask", partialTask.getTaskDefinitionKey());
    taskService.complete(partialTask.getId());
    Task fullTask = taskService.createTaskQuery().singleResult();
    assertEquals("theTask", fullTask.getTaskDefinitionKey());
    runtimeService.deleteProcessInstance(pi.getId(), "testing deletion");
}

53. NestedNonInterruptingEventSubprocessScenarioTest#testInitCompletionCase2()

View license
@Test
@ScenarioUnderTest("init.2")
public void testInitCompletionCase2() {
    // given
    Task innerTask = rule.taskQuery().taskDefinitionKey("innerTask").singleResult();
    Task eventSubprocessTask = rule.taskQuery().taskDefinitionKey("eventSubProcessTask").singleResult();
    // when
    rule.getTaskService().complete(eventSubprocessTask.getId());
    rule.getTaskService().complete(innerTask.getId());
    // then
    rule.assertScenarioEnded();
}

54. NestedNonInterruptingEventSubprocessScenarioTest#testInitThrowError()

View license
@Test
@ScenarioUnderTest("init.5")
public void testInitThrowError() {
    // given
    ProcessInstance instance = rule.processInstance();
    Task eventSubprocessTask = rule.taskQuery().taskDefinitionKey("eventSubProcessTask").singleResult();
    // when
    rule.getRuntimeService().setVariable(instance.getId(), ThrowBpmnErrorDelegate.ERROR_INDICATOR_VARIABLE, true);
    rule.getTaskService().complete(eventSubprocessTask.getId());
    // then
    Task escalatedTask = rule.taskQuery().singleResult();
    Assert.assertEquals("escalatedTask", escalatedTask.getTaskDefinitionKey());
    Assert.assertNotNull(escalatedTask);
    rule.getTaskService().complete(escalatedTask.getId());
    rule.assertScenarioEnded();
}

55. NestedNonInterruptingEventSubprocessScenarioTest#testInitTask1ThrowError()

View license
@Test
@ScenarioUnderTest("init.innerTask.4")
public void testInitTask1ThrowError() {
    // given
    ProcessInstance instance = rule.processInstance();
    Task eventSubprocessTask = rule.taskQuery().singleResult();
    // when
    rule.getRuntimeService().setVariable(instance.getId(), ThrowBpmnErrorDelegate.ERROR_INDICATOR_VARIABLE, true);
    rule.getTaskService().complete(eventSubprocessTask.getId());
    // then
    Task escalatedTask = rule.taskQuery().singleResult();
    Assert.assertEquals("escalatedTask", escalatedTask.getTaskDefinitionKey());
    Assert.assertNotNull(escalatedTask);
    rule.getTaskService().complete(escalatedTask.getId());
    rule.assertScenarioEnded();
}

56. NestedParallelNonInterruptingEventSubprocessScenarioTest#testInitThrowError()

View license
@Test
@ScenarioUnderTest("init.5")
public void testInitThrowError() {
    // given
    ProcessInstance instance = rule.processInstance();
    Task eventSubprocessTask = rule.taskQuery().taskDefinitionKey("eventSubProcessTask1").singleResult();
    // when
    rule.getRuntimeService().setVariable(instance.getId(), ThrowBpmnErrorDelegate.ERROR_INDICATOR_VARIABLE, true);
    rule.getTaskService().complete(eventSubprocessTask.getId());
    // then
    Task escalatedTask = rule.taskQuery().singleResult();
    Assert.assertEquals("escalatedTask", escalatedTask.getTaskDefinitionKey());
    Assert.assertNotNull(escalatedTask);
    rule.getTaskService().complete(escalatedTask.getId());
    rule.assertScenarioEnded();
}

57. NestedParallelNonInterruptingEventSubprocessScenarioTest#testInitInnerTaskCompletion()

View license
@Test
@ScenarioUnderTest("init.innerTask.1")
public void testInitInnerTaskCompletion() {
    // given
    Task eventSubprocessTask1 = rule.taskQuery().taskDefinitionKey("eventSubProcessTask1").singleResult();
    Task eventSubprocessTask2 = rule.taskQuery().taskDefinitionKey("eventSubProcessTask2").singleResult();
    // when
    rule.getTaskService().complete(eventSubprocessTask1.getId());
    rule.getTaskService().complete(eventSubprocessTask2.getId());
    // then
    rule.assertScenarioEnded();
}

58. NestedParallelNonInterruptingEventSubprocessScenarioTest#testInitInnerTaskThrowError()

View license
@Test
@ScenarioUnderTest("init.innerTask.4")
public void testInitInnerTaskThrowError() {
    // given
    ProcessInstance instance = rule.processInstance();
    Task eventSubprocessTask = rule.taskQuery().taskDefinitionKey("eventSubProcessTask1").singleResult();
    // when
    rule.getRuntimeService().setVariable(instance.getId(), ThrowBpmnErrorDelegate.ERROR_INDICATOR_VARIABLE, true);
    rule.getTaskService().complete(eventSubprocessTask.getId());
    // then
    Task escalatedTask = rule.taskQuery().singleResult();
    Assert.assertEquals("escalatedTask", escalatedTask.getTaskDefinitionKey());
    Assert.assertNotNull(escalatedTask);
    rule.getTaskService().complete(escalatedTask.getId());
    rule.assertScenarioEnded();
}

59. NonInterruptingEventSubprocessScenarioTest#testInitCompletionCase1()

View license
@Test
@ScenarioUnderTest("init.1")
public void testInitCompletionCase1() {
    // given
    Task outerTask = rule.taskQuery().taskDefinitionKey("outerTask").singleResult();
    Task eventSubprocessTask = rule.taskQuery().taskDefinitionKey("eventSubProcessTask").singleResult();
    // when
    rule.getTaskService().complete(outerTask.getId());
    rule.getTaskService().complete(eventSubprocessTask.getId());
    // then
    rule.assertScenarioEnded();
}

60. NonInterruptingEventSubprocessScenarioTest#testInitCompletionCase2()

View license
@Test
@ScenarioUnderTest("init.2")
public void testInitCompletionCase2() {
    // given
    Task outerTask = rule.taskQuery().taskDefinitionKey("outerTask").singleResult();
    Task eventSubprocessTask = rule.taskQuery().taskDefinitionKey("eventSubProcessTask").singleResult();
    // when
    rule.getTaskService().complete(eventSubprocessTask.getId());
    rule.getTaskService().complete(outerTask.getId());
    // then
    rule.assertScenarioEnded();
}

61. ParallelNestedNonInterruptingEventSubprocessScenarioTest#testInitThrowUnhandledException()

View license
@Test
@ScenarioUnderTest("init.6")
public void testInitThrowUnhandledException() {
    // given
    ProcessInstance instance = rule.processInstance();
    Task eventSubprocessTask = rule.taskQuery().taskDefinitionKey("eventSubProcessTask").singleResult();
    Task outerTask = rule.taskQuery().taskDefinitionKey("outerTask").singleResult();
    // when
    rule.getTaskService().complete(outerTask.getId());
    rule.getRuntimeService().setVariable(instance.getId(), ThrowBpmnErrorDelegate.EXCEPTION_INDICATOR_VARIABLE, true);
    rule.getRuntimeService().setVariable(instance.getId(), ThrowBpmnErrorDelegate.EXCEPTION_MESSAGE_VARIABLE, "unhandledException");
    // then
    try {
        rule.getTaskService().complete(eventSubprocessTask.getId());
        Assert.fail("should throw a ThrowBpmnErrorDelegateException");
    } catch (ThrowBpmnErrorDelegateException e) {
        Assert.assertEquals("unhandledException", e.getMessage());
    }
}

62. ParallelNestedNonInterruptingEventSubprocessScenarioTest#testInitInnerTaskCompletion1()

View license
@Test
@ScenarioUnderTest("init.innerTask.1")
public void testInitInnerTaskCompletion1() {
    // given
    Task eventSubprocessTask = rule.taskQuery().taskDefinitionKey("eventSubProcessTask").singleResult();
    Task outerTask = rule.taskQuery().taskDefinitionKey("outerTask").singleResult();
    // when
    rule.getTaskService().complete(eventSubprocessTask.getId());
    rule.getTaskService().complete(outerTask.getId());
    // then
    rule.assertScenarioEnded();
}

63. ParallelNestedNonInterruptingEventSubprocessScenarioTest#testInitInnerTaskCompletion2()

View license
@Test
@ScenarioUnderTest("init.innerTask.2")
public void testInitInnerTaskCompletion2() {
    // given
    Task eventSubprocessTask = rule.taskQuery().taskDefinitionKey("eventSubProcessTask").singleResult();
    Task outerTask = rule.taskQuery().taskDefinitionKey("outerTask").singleResult();
    // when
    rule.getTaskService().complete(outerTask.getId());
    rule.getTaskService().complete(eventSubprocessTask.getId());
    // then
    rule.assertScenarioEnded();
}

64. ParallelNestedNonInterruptingEventSubprocessScenarioTest#testInitInnerTaskThrowUnhandledException()

View license
@Test
@ScenarioUnderTest("init.innerTask.6")
public void testInitInnerTaskThrowUnhandledException() {
    // given
    ProcessInstance instance = rule.processInstance();
    Task eventSubprocessTask = rule.taskQuery().taskDefinitionKey("eventSubProcessTask").singleResult();
    Task outerTask = rule.taskQuery().taskDefinitionKey("outerTask").singleResult();
    // when
    rule.getTaskService().complete(outerTask.getId());
    rule.getRuntimeService().setVariable(instance.getId(), ThrowBpmnErrorDelegate.EXCEPTION_INDICATOR_VARIABLE, true);
    rule.getRuntimeService().setVariable(instance.getId(), ThrowBpmnErrorDelegate.EXCEPTION_MESSAGE_VARIABLE, "unhandledException");
    // then
    try {
        rule.getTaskService().complete(eventSubprocessTask.getId());
        Assert.fail("should throw a ThrowBpmnErrorDelegateException");
    } catch (ThrowBpmnErrorDelegateException e) {
        Assert.assertEquals("unhandledException", e.getMessage());
    }
}

65. TwoLevelNestedNonInterruptingEventSubprocessScenarioTest#testInitLevel1CompletionCase1()

View license
@Test
@ScenarioUnderTest("initLevel1.1")
public void testInitLevel1CompletionCase1() {
    // given
    Task outerTask = rule.taskQuery().taskDefinitionKey("outerTask").singleResult();
    Task innerTask = rule.taskQuery().taskDefinitionKey("subProcessTask").singleResult();
    // when
    rule.getTaskService().complete(outerTask.getId());
    rule.getTaskService().complete(innerTask.getId());
    // then
    rule.assertScenarioEnded();
}

66. TwoLevelNestedNonInterruptingEventSubprocessScenarioTest#testInitLevel1CompletionCase2()

View license
@Test
@ScenarioUnderTest("initLevel1.2")
public void testInitLevel1CompletionCase2() {
    // given
    Task outerTask = rule.taskQuery().taskDefinitionKey("outerTask").singleResult();
    Task innerTask = rule.taskQuery().taskDefinitionKey("subProcessTask").singleResult();
    // when
    rule.getTaskService().complete(innerTask.getId());
    rule.getTaskService().complete(outerTask.getId());
    // then
    rule.assertScenarioEnded();
}

67. TwoLevelNestedNonInterruptingEventSubprocessScenarioTest#testInitLevel1ThrowError()

View license
@ScenarioUnderTest("initLevel1.6")
public void testInitLevel1ThrowError() {
    // given
    ProcessInstance instance = rule.processInstance();
    rule.messageCorrelation("InnerEventSubProcessMessage").correlate();
    Task innerEventSubprocessTask = rule.taskQuery().taskDefinitionKey("innerEventSubProcessTask").singleResult();
    // when
    rule.getRuntimeService().setVariable(instance.getId(), ThrowBpmnErrorDelegate.ERROR_INDICATOR_VARIABLE, true);
    rule.getTaskService().complete(innerEventSubprocessTask.getId());
    // then
    Task escalatedTask = rule.taskQuery().singleResult();
    Assert.assertEquals("escalatedTask", escalatedTask.getTaskDefinitionKey());
    Assert.assertNotNull(escalatedTask);
    rule.getTaskService().complete(escalatedTask.getId());
    rule.assertScenarioEnded();
}

68. TwoLevelNestedNonInterruptingEventSubprocessScenarioTest#testInitLevel1InitLevel2CompletionCase3()

View license
@Test
@ScenarioUnderTest("initLevel1.initLevel2.3")
public void testInitLevel1InitLevel2CompletionCase3() {
    // given
    Task outerTask = rule.taskQuery().taskDefinitionKey("outerTask").singleResult();
    Task innerTask = rule.taskQuery().taskDefinitionKey("subProcessTask").singleResult();
    // when (the inner subprocess is triggered another time)
    rule.messageCorrelation("InnerEventSubProcessMessage").correlate();
    // then
    Assert.assertEquals(4, rule.taskQuery().count());
    List<Task> innerEventSubprocessTasks = rule.taskQuery().taskDefinitionKey("innerEventSubProcessTask").list();
    Assert.assertEquals(2, innerEventSubprocessTasks.size());
    // and
    rule.getTaskService().complete(innerTask.getId());
    rule.getTaskService().complete(innerEventSubprocessTasks.get(0).getId());
    rule.getTaskService().complete(outerTask.getId());
    rule.getTaskService().complete(innerEventSubprocessTasks.get(1).getId());
    rule.assertScenarioEnded();
}

69. TwoLevelNestedNonInterruptingEventSubprocessScenarioTest#testInitLevel1InitLevel2ThrowError()

View license
@ScenarioUnderTest("initLevel1.initLevel2.6")
public void testInitLevel1InitLevel2ThrowError() {
    // given
    ProcessInstance instance = rule.processInstance();
    Task innerEventSubprocessTask = rule.taskQuery().taskDefinitionKey("innerEventSubProcessTask").singleResult();
    // when
    rule.getRuntimeService().setVariable(instance.getId(), ThrowBpmnErrorDelegate.ERROR_INDICATOR_VARIABLE, true);
    rule.getTaskService().complete(innerEventSubprocessTask.getId());
    // then
    Task escalatedTask = rule.taskQuery().singleResult();
    Assert.assertEquals("escalatedTask", escalatedTask.getTaskDefinitionKey());
    Assert.assertNotNull(escalatedTask);
    rule.getTaskService().complete(escalatedTask.getId());
    rule.assertScenarioEnded();
}

70. NestedSequentialMultiInstanceScenarioTest#testInitThrowError()

View license
@Test
@ScenarioUnderTest("init.4")
public void testInitThrowError() {
    // given
    ProcessInstance instance = rule.processInstance();
    Task innerMiSubProcessTask = rule.taskQuery().taskDefinitionKey("innerSubProcessTask").singleResult();
    // when
    rule.getRuntimeService().setVariable(instance.getId(), ThrowBpmnErrorDelegate.ERROR_INDICATOR_VARIABLE, true);
    rule.getTaskService().complete(innerMiSubProcessTask.getId());
    // then
    Task escalatedTask = rule.taskQuery().singleResult();
    Assert.assertEquals("escalatedTask", escalatedTask.getTaskDefinitionKey());
    Assert.assertNotNull(escalatedTask);
    rule.getTaskService().complete(escalatedTask.getId());
    rule.assertScenarioEnded();
}

71. ParallelMultiInstanceScenarioTest#testInitNonInterruptingBoundaryEventCompletionCase1()

View license
@Test
@ScenarioUnderTest("initNonInterruptingBoundaryEvent.1")
public void testInitNonInterruptingBoundaryEventCompletionCase1() {
    // given
    List<Task> subProcessTasks = rule.taskQuery().taskDefinitionKey("subProcessTask").list();
    Task afterBoundaryTask = rule.taskQuery().taskDefinitionKey("afterBoundaryTask").singleResult();
    // when all instances are completed
    for (Task subProcessTask : subProcessTasks) {
        rule.getTaskService().complete(subProcessTask.getId());
    }
    // and
    rule.getTaskService().complete(afterBoundaryTask.getId());
    // then
    rule.assertScenarioEnded();
}

72. ParallelMultiInstanceScenarioTest#testInitNonInterruptingBoundaryEventCompletionCase2()

View license
@Test
@ScenarioUnderTest("initNonInterruptingBoundaryEvent.2")
public void testInitNonInterruptingBoundaryEventCompletionCase2() {
    // given
    List<Task> subProcessTasks = rule.taskQuery().taskDefinitionKey("subProcessTask").list();
    Task afterBoundaryTask = rule.taskQuery().taskDefinitionKey("afterBoundaryTask").singleResult();
    // when
    rule.getTaskService().complete(afterBoundaryTask.getId());
    for (Task subProcessTask : subProcessTasks) {
        rule.getTaskService().complete(subProcessTask.getId());
    }
    // then
    rule.assertScenarioEnded();
}

73. SequentialMultiInstanceScenarioTest#testInitThrowError()

View license
@Test
@ScenarioUnderTest("init.4")
public void testInitThrowError() {
    // given
    ProcessInstance instance = rule.processInstance();
    Task miSubprocessTask = rule.taskQuery().taskDefinitionKey("subProcessTask").singleResult();
    // when
    rule.getRuntimeService().setVariable(instance.getId(), ThrowBpmnErrorDelegate.ERROR_INDICATOR_VARIABLE, true);
    rule.getTaskService().complete(miSubprocessTask.getId());
    // then
    Task escalatedTask = rule.taskQuery().singleResult();
    Assert.assertEquals("escalatedTask", escalatedTask.getTaskDefinitionKey());
    Assert.assertNotNull(escalatedTask);
    rule.getTaskService().complete(escalatedTask.getId());
    rule.assertScenarioEnded();
}

74. SequentialMultiInstanceScenarioTest#testInitNonInterruptingBoundaryEventCompletionCase1()

View license
@Test
@ScenarioUnderTest("initNonInterruptingBoundaryEvent.1")
public void testInitNonInterruptingBoundaryEventCompletionCase1() {
    // given
    Task subProcessTask = rule.taskQuery().taskDefinitionKey("subProcessTask").singleResult();
    Task afterBoundaryTask = rule.taskQuery().taskDefinitionKey("afterBoundaryTask").singleResult();
    // when the first instance and the other two instances are completed
    rule.getTaskService().complete(subProcessTask.getId());
    for (int i = 0; i < 2; i++) {
        subProcessTask = rule.taskQuery().taskDefinitionKey("subProcessTask").singleResult();
        Assert.assertNotNull(subProcessTask);
        rule.getTaskService().complete(subProcessTask.getId());
    }
    rule.getTaskService().complete(afterBoundaryTask.getId());
    // then
    rule.assertScenarioEnded();
}

75. SequentialMultiInstanceScenarioTest#testInitNonInterruptingBoundaryEventCompletionCase2()

View license
@Test
@ScenarioUnderTest("initNonInterruptingBoundaryEvent.2")
public void testInitNonInterruptingBoundaryEventCompletionCase2() {
    // given
    Task subProcessTask = rule.taskQuery().taskDefinitionKey("subProcessTask").singleResult();
    Task afterBoundaryTask = rule.taskQuery().taskDefinitionKey("afterBoundaryTask").singleResult();
    // when the first instance and the other two instances are completed
    rule.getTaskService().complete(afterBoundaryTask.getId());
    rule.getTaskService().complete(subProcessTask.getId());
    for (int i = 0; i < 2; i++) {
        subProcessTask = rule.taskQuery().taskDefinitionKey("subProcessTask").singleResult();
        Assert.assertNotNull(subProcessTask);
        rule.getTaskService().complete(subProcessTask.getId());
    }
    // then
    rule.assertScenarioEnded();
}

76. SequentialMultiInstanceScenarioTest#testInitNonInterruptingBoundaryEventCompletionCase3()

View license
@Test
@ScenarioUnderTest("initNonInterruptingBoundaryEvent.3")
public void testInitNonInterruptingBoundaryEventCompletionCase3() {
    // given
    Task subProcessTask = rule.taskQuery().taskDefinitionKey("subProcessTask").singleResult();
    Task afterBoundaryTask = rule.taskQuery().taskDefinitionKey("afterBoundaryTask").singleResult();
    // when the first instance and the other two instances are completed
    rule.getTaskService().complete(subProcessTask.getId());
    rule.getTaskService().complete(afterBoundaryTask.getId());
    for (int i = 0; i < 2; i++) {
        subProcessTask = rule.taskQuery().taskDefinitionKey("subProcessTask").singleResult();
        Assert.assertNotNull(subProcessTask);
        rule.getTaskService().complete(subProcessTask.getId());
    }
    // then
    rule.assertScenarioEnded();
}

77. InterruptingEventSubProcessCompensationSenarioTest#testInitThrowCompensateCompletion()

View license
@Test
@ScenarioUnderTest("init.throwCompensate.1")
public void testInitThrowCompensateCompletion() {
    // given
    Task undoTask = rule.taskQuery().singleResult();
    // when
    rule.getTaskService().complete(undoTask.getId());
    // then it is possible to complete the process successfully
    Task afterCompensateTask = rule.taskQuery().singleResult();
    Assert.assertNotNull(afterCompensateTask);
    Assert.assertEquals("afterCompensate", afterCompensateTask.getTaskDefinitionKey());
    rule.getTaskService().complete(afterCompensateTask.getId());
    rule.assertScenarioEnded();
}

78. SequenceFlowTest#testTakeAllOutgoingFlowsFromScopeTask()

View license
@Deployment
public void testTakeAllOutgoingFlowsFromScopeTask() {
    // given
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("testProcess");
    // when
    Task task = taskService.createTaskQuery().singleResult();
    taskService.complete(task.getId());
    // then
    assertEquals(2, taskService.createTaskQuery().count());
    assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("task2").count());
    assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("task3").count());
    for (Task followUpTask : taskService.createTaskQuery().list()) {
        taskService.complete(followUpTask.getId());
    }
    assertProcessEnded(instance.getId());
}

79. TaskServiceTest#testSaveTaskWithNonExistingParentTask()

View license
public void testSaveTaskWithNonExistingParentTask() {
    // given
    Task task = taskService.newTask();
    // when
    task.setParentTaskId("non-existing");
    // then
    try {
        taskService.saveTask(task);
        fail("It should not be possible to save a task with a non existing parent task.");
    } catch (NotValidException e) {
    }
}

80. TaskQueryTest#testFollowUpDateCombinations()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml" })
public void testFollowUpDateCombinations() throws ParseException {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    // Set follow-up date on task
    Date dueDate = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("01/02/2003 01:12:13");
    task.setFollowUpDate(dueDate);
    taskService.saveTask(task);
    Date oneHourAgo = new Date(dueDate.getTime() - 60 * 60 * 1000);
    Date oneHourLater = new Date(dueDate.getTime() + 60 * 60 * 1000);
    assertEquals(1, taskService.createTaskQuery().followUpAfter(oneHourAgo).followUpDate(dueDate).followUpBefore(oneHourLater).count());
    assertEquals(0, taskService.createTaskQuery().followUpAfter(oneHourLater).followUpDate(dueDate).followUpBefore(oneHourAgo).count());
    assertEquals(0, taskService.createTaskQuery().followUpAfter(oneHourLater).followUpDate(dueDate).count());
    assertEquals(0, taskService.createTaskQuery().followUpDate(dueDate).followUpBefore(oneHourAgo).count());
}

81. TaskQueryTest#testTaskDueDateCombinations()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml" })
public void testTaskDueDateCombinations() throws ParseException {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    // Set due-date on task
    Date dueDate = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("01/02/2003 01:12:13");
    task.setDueDate(dueDate);
    taskService.saveTask(task);
    Date oneHourAgo = new Date(dueDate.getTime() - 60 * 60 * 1000);
    Date oneHourLater = new Date(dueDate.getTime() + 60 * 60 * 1000);
    assertEquals(1, taskService.createTaskQuery().dueAfter(oneHourAgo).dueDate(dueDate).dueBefore(oneHourLater).count());
    assertEquals(0, taskService.createTaskQuery().dueAfter(oneHourLater).dueDate(dueDate).dueBefore(oneHourAgo).count());
    assertEquals(0, taskService.createTaskQuery().dueAfter(oneHourLater).dueDate(dueDate).count());
    assertEquals(0, taskService.createTaskQuery().dueDate(dueDate).dueBefore(oneHourAgo).count());
}

82. TaskQueryTest#testTaskDueDate()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml" })
public void testTaskDueDate() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    // Set due-date on task
    Date dueDate = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("01/02/2003 01:12:13");
    task.setDueDate(dueDate);
    taskService.saveTask(task);
    assertEquals(1, taskService.createTaskQuery().dueDate(dueDate).count());
    Calendar otherDate = Calendar.getInstance();
    otherDate.add(Calendar.YEAR, 1);
    assertEquals(0, taskService.createTaskQuery().dueDate(otherDate.getTime()).count());
    Calendar priorDate = Calendar.getInstance();
    priorDate.setTime(dueDate);
    priorDate.roll(Calendar.YEAR, -1);
    assertEquals(1, taskService.createTaskQuery().dueAfter(priorDate.getTime()).count());
    assertEquals(1, taskService.createTaskQuery().dueBefore(otherDate.getTime()).count());
}

83. TaskIdentityLinksTest#testDeleteOwner()

View license
public void testDeleteOwner() {
    Task task = taskService.newTask();
    task.setOwner("nonExistingUser");
    taskService.saveTask(task);
    taskService.deleteUserIdentityLink(task.getId(), "nonExistingUser", IdentityLinkType.OWNER);
    task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
    assertNull(task.getOwner());
    assertEquals(0, taskService.getIdentityLinksForTask(task.getId()).size());
    // cleanup
    taskService.deleteTask(task.getId(), true);
}

84. TaskIdentityLinksTest#testDeleteAssignee()

View license
public void testDeleteAssignee() {
    Task task = taskService.newTask();
    task.setAssignee("nonExistingUser");
    taskService.saveTask(task);
    taskService.deleteUserIdentityLink(task.getId(), "nonExistingUser", IdentityLinkType.ASSIGNEE);
    task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
    assertNull(task.getAssignee());
    assertEquals(0, taskService.getIdentityLinksForTask(task.getId()).size());
    // cleanup
    taskService.deleteTask(task.getId(), true);
}

85. TaskIdentityLinksTest#testOwnerLink()

View license
public void testOwnerLink() {
    Task task = taskService.newTask("task");
    task.setOwner("owner");
    taskService.saveTask(task);
    List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(task.getId());
    assertNotNull(identityLinks);
    assertEquals(1, identityLinks.size());
    IdentityLink identityLink = identityLinks.get(0);
    assertEquals(IdentityLinkType.OWNER, identityLink.getType());
    assertEquals("owner", identityLink.getUserId());
    assertEquals("task", identityLink.getTaskId());
    taskService.deleteTask(task.getId(), true);
}

86. TaskIdentityLinksTest#testAssigneeLink()

View license
public void testAssigneeLink() {
    Task task = taskService.newTask("task");
    task.setAssignee("assignee");
    taskService.saveTask(task);
    List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(task.getId());
    assertNotNull(identityLinks);
    assertEquals(1, identityLinks.size());
    IdentityLink identityLink = identityLinks.get(0);
    assertEquals(IdentityLinkType.ASSIGNEE, identityLink.getType());
    assertEquals("assignee", identityLink.getUserId());
    assertEquals("task", identityLink.getTaskId());
    taskService.deleteTask(task.getId(), true);
}

87. RuntimeServiceTest#testDeleteProcessInstanceWithActiveCompensation()

View license
@Deployment
public void testDeleteProcessInstanceWithActiveCompensation() {
    // given
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("compensationProcess");
    Task innerTask = taskService.createTaskQuery().singleResult();
    taskService.complete(innerTask.getId());
    Task afterSubProcessTask = taskService.createTaskQuery().singleResult();
    assertEquals("taskAfterSubprocess", afterSubProcessTask.getTaskDefinitionKey());
    taskService.complete(afterSubProcessTask.getId());
    // when
    // there are two compensation tasks
    assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("outerAfterBoundaryTask").count());
    assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("innerAfterBoundaryTask").count());
    // when the process instance is deleted
    runtimeService.deleteProcessInstance(instance.getId(), "");
    // then
    assertProcessEnded(instance.getId());
}

88. ProcessInstanceSuspensionTest#testTaskSuspendedAfterProcessInstanceSuspensionByProcessDefinitionKey()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testTaskSuspendedAfterProcessInstanceSuspensionByProcessDefinitionKey() {
    // Start Process Instance
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    runtimeService.startProcessInstanceByKey(processDefinition.getKey());
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    // Suspense process instance
    runtimeService.suspendProcessInstanceByProcessDefinitionKey(processDefinition.getKey());
    // Assert that the task is now also suspended
    List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
    for (Task task : tasks) {
        assertTrue(task.isSuspended());
    }
    // Activate process instance again
    runtimeService.activateProcessInstanceByProcessDefinitionKey(processDefinition.getKey());
    tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
    for (Task task : tasks) {
        assertFalse(task.isSuspended());
    }
}

89. ProcessInstanceSuspensionTest#testTaskSuspendedAfterProcessInstanceSuspensionByProcessDefinitionId()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testTaskSuspendedAfterProcessInstanceSuspensionByProcessDefinitionId() {
    // Start Process Instance
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    runtimeService.startProcessInstanceByKey(processDefinition.getKey());
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    // Suspense process instance
    runtimeService.suspendProcessInstanceByProcessDefinitionId(processDefinition.getId());
    // Assert that the task is now also suspended
    List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
    for (Task task : tasks) {
        assertTrue(task.isSuspended());
    }
    // Activate process instance again
    runtimeService.activateProcessInstanceByProcessDefinitionId(processDefinition.getId());
    tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
    for (Task task : tasks) {
        assertFalse(task.isSuspended());
    }
}

90. ProcessInstanceSuspensionTest#testTaskSuspendedAfterProcessInstanceSuspension()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testTaskSuspendedAfterProcessInstanceSuspension() {
    // Start Process Instance
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    runtimeService.startProcessInstanceByKey(processDefinition.getKey());
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    // Suspense process instance
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    // Assert that the task is now also suspended
    List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
    for (Task task : tasks) {
        assertTrue(task.isSuspended());
    }
    // Activate process instance again
    runtimeService.activateProcessInstanceById(processInstance.getId());
    tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
    for (Task task : tasks) {
        assertFalse(task.isSuspended());
    }
}

91. EscalationEventTest#testPropagateOutputVariablesTwoTimes()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/event/escalation/EscalationEventTest.throwEscalationEvent.bpmn20.xml", "org/camunda/bpm/engine/test/bpmn/event/escalation/EscalationEventTest.testPropagateOutputVariablesWhileCatchEscalationOnCallActivity.bpmn20.xml" })
public void testPropagateOutputVariablesTwoTimes() {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("input", 42);
    String processInstanceId = runtimeService.startProcessInstanceByKey("catchEscalationProcess", variables).getId();
    // when throw an escalation event on called process
    Task taskInSuperProcess = taskService.createTaskQuery().taskDefinitionKey("taskAfterCatchedEscalation").singleResult();
    assertNotNull(taskInSuperProcess);
    // (1) the variables has been passed for the first time (from sub process to super process)
    assertEquals(42, runtimeService.getVariable(processInstanceId, "output"));
    // change variable "input" in sub process
    Task taskInSubProcess = taskService.createTaskQuery().taskDefinitionKey("task").singleResult();
    runtimeService.setVariable(taskInSubProcess.getProcessInstanceId(), "input", 999);
    taskService.complete(taskInSubProcess.getId());
    // (2) the variables has been passed for the second time (from sub process to super process)
    assertEquals(999, runtimeService.getVariable(processInstanceId, "output"));
}

92. InterruptingEventSubProcessNestedCompensationSenarioTest#testInitThrowCompensateCompletionCase1()

View license
@Test
@ScenarioUnderTest("init.throwCompensate.1")
public void testInitThrowCompensateCompletionCase1() {
    // given
    Task undoTask = rule.taskQuery().singleResult();
    // when
    rule.getTaskService().complete(undoTask.getId());
    // then it is possible to complete the process successfully
    // by completing the sub process regularly
    Task afterCompensateTask = rule.taskQuery().singleResult();
    Assert.assertNotNull(afterCompensateTask);
    Assert.assertEquals("afterCompensate", afterCompensateTask.getTaskDefinitionKey());
    rule.getTaskService().complete(afterCompensateTask.getId());
    rule.assertScenarioEnded();
}

93. InterruptingEventSubProcessNestedCompensationSenarioTest#testInitThrowCompensateCompletionCase2()

View license
/**
   * Fails because wrongly destroy the sub process scope execution when completing the
   * compensation throw event. See CAM-4914
   */
@Ignore
@Test
@ScenarioUnderTest("init.throwCompensate.2")
public void testInitThrowCompensateCompletionCase2() {
    // given
    Task undoTask = rule.taskQuery().singleResult();
    // when
    rule.getTaskService().complete(undoTask.getId());
    // then it is possible to complete the process successfully
    // by triggering the message boundary event
    rule.messageCorrelation("BoundaryEventMessage").correlate();
    Task afterBoundaryTask = rule.taskQuery().singleResult();
    Assert.assertNotNull(afterBoundaryTask);
    Assert.assertEquals("afterBoundaryTask", afterBoundaryTask.getTaskDefinitionKey());
    rule.getTaskService().complete(afterBoundaryTask.getId());
    rule.assertScenarioEnded();
}

94. ParallelMultiInstanceCompensationScenarioTest#testSingleActivityHandlerMultiInstancePartialDeletion()

View license
@Test
@ScenarioUnderTest("singleActivityHandler.multiInstancePartial.2")
public void testSingleActivityHandlerMultiInstancePartialDeletion() {
    // when throwing compensation
    Task lastMiTask = rule.taskQuery().singleResult();
    rule.getTaskService().complete(lastMiTask.getId());
    Task beforeCompensateTask = rule.taskQuery().singleResult();
    rule.getTaskService().complete(beforeCompensateTask.getId());
    // then it is possible to delete the process instance
    rule.getRuntimeService().deleteProcessInstance(rule.processInstance().getId(), null);
    // and the process is ended
    rule.assertScenarioEnded();
}

95. ParallelMultiInstanceCompensationScenarioTest#testDefaultHandlerMultiInstancePartialDeletion()

View license
@Test
@ScenarioUnderTest("defaultHandler.multiInstancePartial.2")
public void testDefaultHandlerMultiInstancePartialDeletion() {
    // when throwing compensation
    Task lastMiTask = rule.taskQuery().singleResult();
    rule.getTaskService().complete(lastMiTask.getId());
    Task beforeCompensateTask = rule.taskQuery().singleResult();
    rule.getTaskService().complete(beforeCompensateTask.getId());
    // then it is possible to delete the process instance
    rule.getRuntimeService().deleteProcessInstance(rule.processInstance().getId(), null);
    // and the process is ended
    rule.assertScenarioEnded();
}

96. ParallelMultiInstanceCompensationScenarioTest#testSubProcessHandlerMultiInstancePartialDeletion()

View license
@Test
@ScenarioUnderTest("subProcessHandler.multiInstancePartial.2")
public void testSubProcessHandlerMultiInstancePartialDeletion() {
    // when throwing compensation
    Task lastMiTask = rule.taskQuery().singleResult();
    rule.getTaskService().complete(lastMiTask.getId());
    Task beforeCompensateTask = rule.taskQuery().singleResult();
    rule.getTaskService().complete(beforeCompensateTask.getId());
    // then it is possible to delete the process instance
    rule.getRuntimeService().deleteProcessInstance(rule.processInstance().getId(), null);
    // and the process is ended
    rule.assertScenarioEnded();
}

97. SequentialMultiInstanceCompensationScenarioTest#testSingleActivityHandlerMultiInstancePartialDeletion()

View license
@Test
@ScenarioUnderTest("singleActivityHandler.multiInstancePartial.2")
public void testSingleActivityHandlerMultiInstancePartialDeletion() {
    // when throwing compensation
    Task lastMiTask = rule.taskQuery().singleResult();
    rule.getTaskService().complete(lastMiTask.getId());
    Task beforeCompensateTask = rule.taskQuery().singleResult();
    rule.getTaskService().complete(beforeCompensateTask.getId());
    // then it is possible to delete the process instance
    rule.getRuntimeService().deleteProcessInstance(rule.processInstance().getId(), null);
    // and the process is ended
    rule.assertScenarioEnded();
}

98. InclusiveGatewayTest#testDefaultSequenceFlow()

View license
@Deployment
public void testDefaultSequenceFlow() {
    // Input == 1 -> default is not selected, other 2 tasks are selected
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("inclusiveGwDefaultSequenceFlow", CollectionUtil.singletonMap("input", 1));
    List<Task> tasks = taskService.createTaskQuery().processInstanceId(pi.getId()).list();
    assertEquals(2, tasks.size());
    Map<String, String> expectedNames = new HashMap<String, String>();
    expectedNames.put("Input is one", "Input is one");
    expectedNames.put("Input is three or one", "Input is three or one");
    for (Task t : tasks) {
        expectedNames.remove(t.getName());
    }
    assertEquals(0, expectedNames.size());
    runtimeService.deleteProcessInstance(pi.getId(), null);
    // Input == 3 -> default is not selected, "one or three" is selected
    pi = runtimeService.startProcessInstanceByKey("inclusiveGwDefaultSequenceFlow", CollectionUtil.singletonMap("input", 3));
    Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    assertEquals("Input is three or one", task.getName());
    // Default input
    pi = runtimeService.startProcessInstanceByKey("inclusiveGwDefaultSequenceFlow", CollectionUtil.singletonMap("input", 5));
    task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    assertEquals("Default input", task.getName());
}

99. SequenceFlowTest#testTakeAllOutgoingFlowsFromNonScopeTask()

View license
@Deployment
public void testTakeAllOutgoingFlowsFromNonScopeTask() {
    // given
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("testProcess");
    // when
    Task task = taskService.createTaskQuery().singleResult();
    taskService.complete(task.getId());
    // then
    assertEquals(2, taskService.createTaskQuery().count());
    assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("task2").count());
    assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("task3").count());
    for (Task followUpTask : taskService.createTaskQuery().list()) {
        taskService.complete(followUpTask.getId());
    }
    assertProcessEnded(instance.getId());
}

100. InclusiveGatewayTest#testNoIdOnSequenceFlow()

View license
@Deployment
public void testNoIdOnSequenceFlow() {
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("inclusiveNoIdOnSequenceFlow", CollectionUtil.singletonMap("input", 3));
    Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    assertEquals("Input is more than one", task.getName());
    // Both should be enabled on 1
    pi = runtimeService.startProcessInstanceByKey("inclusiveNoIdOnSequenceFlow", CollectionUtil.singletonMap("input", 1));
    List<Task> tasks = taskService.createTaskQuery().processInstanceId(pi.getId()).list();
    assertEquals(2, tasks.size());
    Map<String, String> expectedNames = new HashMap<String, String>();
    expectedNames.put("Input is one", "Input is one");
    expectedNames.put("Input is more than one", "Input is more than one");
    for (Task t : tasks) {
        expectedNames.remove(t.getName());
    }
    assertEquals(0, expectedNames.size());
}