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. 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);
}

4. 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);
}

5. 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());
}

6. 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);
}

7. 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());
}

8. 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());
}

9. 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());
}

10. 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());
}

11. 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);
}

12. 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);
}

13. 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);
}

14. 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();
}

15. 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);
}

16. 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) {
    }
}

17. 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) {
    }
}

18. 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) {
    }
}

19. 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);
}

20. 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);
}

21. 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);
}

22. 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);
}

23. 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) {
    }
}

24. 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);
}

25. 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());
}

26. 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());
}

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. 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();
}

51. ProcessApplicationElResolverTest#testCallActivityConditionalOutgoingFlow()

View license
/**
   * Tests that an expression on an outgoing flow leaving a call activity
   * is resolved in the context of the calling process definition's application.
   */
public void testCallActivityConditionalOutgoingFlow() {
    // given an instance of the calling process that calls the called process
    runtimeService.startProcessInstanceByKey("callingProcessConditionalFlow");
    // when the called process is completed
    Task calledProcessTask = taskService.createTaskQuery().singleResult();
    taskService.complete(calledProcessTask.getId());
    // then the conditional flow expression was resolved in the context of the calling process application, so
    // the following task has been reached successfully
    Task afterCallActivityTask = taskService.createTaskQuery().singleResult();
    assertNotNull(afterCallActivityTask);
    assertEquals("afterCallActivityTask", afterCallActivityTask.getTaskDefinitionKey());
}

52. HistoricIdentityLinkLogAuthorizationTest#testQueryForStandaloneTaskHistoricIdentityLinkWithoutAuthrorization()

View license
// historic identity link query (standalone task) - Authorization
public void testQueryForStandaloneTaskHistoricIdentityLinkWithoutAuthrorization() {
    // given
    disableAuthorization();
    Task taskAssignee = taskService.newTask("newTask");
    taskAssignee.setAssignee("aUserId");
    taskService.saveTask(taskAssignee);
    enableAuthorization();
    // when
    HistoricIdentityLinkLogQuery query = historyService.createHistoricIdentityLinkLogQuery();
    // then
    verifyQueryResults(query, 1);
    disableAuthorization();
    taskService.deleteTask("newTask", true);
    enableAuthorization();
}

53. TaskAuthorizationTest#testSaveStandaloneTaskUpdate()

View license
public void testSaveStandaloneTaskUpdate() {
    // given
    String taskId = "myTask";
    createTask(taskId);
    Task task = selectSingleTask();
    task.setAssignee("demo");
    createGrantAuthorization(TASK, taskId, userId, UPDATE);
    // when
    taskService.saveTask(task);
    // then
    task = selectSingleTask();
    assertNotNull(task);
    assertEquals("demo", task.getAssignee());
    deleteTask(taskId, true);
}

54. TaskAuthorizationTest#testSaveProcessTaskUpdateWithUpdatePermissionOnTask()

View license
public void testSaveProcessTaskUpdateWithUpdatePermissionOnTask() {
    // given
    startProcessInstanceByKey(PROCESS_KEY);
    Task task = selectSingleTask();
    task.setAssignee("demo");
    createGrantAuthorization(TASK, task.getId(), userId, UPDATE);
    // when
    taskService.saveTask(task);
    // then
    task = selectSingleTask();
    assertNotNull(task);
    assertEquals("demo", task.getAssignee());
}

55. TaskAuthorizationTest#testSaveProcessTaskUpdateWithTaskAssignPermissionOnTask()

View license
public void testSaveProcessTaskUpdateWithTaskAssignPermissionOnTask() {
    // given
    startProcessInstanceByKey(PROCESS_KEY);
    Task task = selectSingleTask();
    task.setAssignee("demo");
    createGrantAuthorization(TASK, task.getId(), userId, TASK_ASSIGN);
    // when
    taskService.saveTask(task);
    // then
    task = selectSingleTask();
    assertNotNull(task);
    assertEquals("demo", task.getAssignee());
}

56. TaskAuthorizationTest#testSaveProcessTaskUpdateWithUpdatePermissionOnAnyTask()

View license
public void testSaveProcessTaskUpdateWithUpdatePermissionOnAnyTask() {
    // given
    startProcessInstanceByKey(PROCESS_KEY);
    Task task = selectSingleTask();
    task.setAssignee("demo");
    createGrantAuthorization(TASK, ANY, userId, UPDATE);
    // when
    taskService.saveTask(task);
    // then
    task = selectSingleTask();
    assertNotNull(task);
    assertEquals("demo", task.getAssignee());
}

57. TaskAuthorizationTest#testSaveProcessTaskUpdateWithTaskAssignPermissionOnAnyTask()

View license
public void testSaveProcessTaskUpdateWithTaskAssignPermissionOnAnyTask() {
    // given
    startProcessInstanceByKey(PROCESS_KEY);
    Task task = selectSingleTask();
    task.setAssignee("demo");
    createGrantAuthorization(TASK, ANY, userId, TASK_ASSIGN);
    // when
    taskService.saveTask(task);
    // then
    task = selectSingleTask();
    assertNotNull(task);
    assertEquals("demo", task.getAssignee());
}

58. TaskAuthorizationTest#testSaveProcessTaskUpdateWithUpdateTasksPermissionOnProcessDefinition()

View license
public void testSaveProcessTaskUpdateWithUpdateTasksPermissionOnProcessDefinition() {
    // given
    startProcessInstanceByKey(PROCESS_KEY);
    Task task = selectSingleTask();
    task.setAssignee("demo");
    createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, UPDATE_TASK);
    // when
    taskService.saveTask(task);
    // then
    task = selectSingleTask();
    assertNotNull(task);
    assertEquals("demo", task.getAssignee());
}

59. TaskAuthorizationTest#testSaveProcessTaskUpdateWithTaskAssignPermissionOnProcessDefinition()

View license
public void testSaveProcessTaskUpdateWithTaskAssignPermissionOnProcessDefinition() {
    // given
    startProcessInstanceByKey(PROCESS_KEY);
    Task task = selectSingleTask();
    task.setAssignee("demo");
    createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, TASK_ASSIGN);
    // when
    taskService.saveTask(task);
    // then
    task = selectSingleTask();
    assertNotNull(task);
    assertEquals("demo", task.getAssignee());
}

60. TaskAuthorizationTest#testSaveCaseTaskUpdate()

View license
// save (case) task (update) //////////////////////////////////////////////////////////
public void testSaveCaseTaskUpdate() {
    // given
    createCaseInstanceByKey(CASE_KEY);
    Task task = selectSingleTask();
    task.setAssignee("demo");
    // when
    taskService.saveTask(task);
    // then
    task = selectSingleTask();
    assertNotNull(task);
    assertEquals("demo", task.getAssignee());
}

61. TaskAuthorizationTest#testStandaloneTaskSaveWithGenericResourceIdOwner()

View license
public void testStandaloneTaskSaveWithGenericResourceIdOwner() {
    createGrantAuthorization(TASK, ANY, userId, CREATE);
    Task task = taskService.newTask();
    task.setOwner("*");
    try {
        taskService.saveTask(task);
        fail("it should not be possible to save a task with the generic resource id *");
    } catch (ProcessEngineException e) {
        assertTextPresent("Cannot create default authorization for owner *: " + "id cannot be *. * is a reserved identifier", e.getMessage());
    }
}

62. TaskAuthorizationTest#testStandaloneTaskSaveWithGenericResourceIdAssignee()

View license
public void testStandaloneTaskSaveWithGenericResourceIdAssignee() {
    createGrantAuthorization(TASK, ANY, userId, CREATE);
    Task task = taskService.newTask();
    task.setAssignee("*");
    try {
        taskService.saveTask(task);
        fail("it should not be possible to save a task with the generic resource id *");
    } catch (ProcessEngineException e) {
        assertTextPresent("Cannot create default authorization for assignee *: " + "id cannot be *. * is a reserved identifier", e.getMessage());
    }
}

63. HistoryServiceTest#testOrderProcessWithCallActivity()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/api/history/orderProcess.bpmn20.xml", "org/camunda/bpm/engine/test/api/history/checkCreditProcess.bpmn20.xml" })
public void testOrderProcessWithCallActivity() {
    // After the process has started, the 'verify credit history' task should be
    // active
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("orderProcess");
    TaskQuery taskQuery = taskService.createTaskQuery();
    Task verifyCreditTask = taskQuery.singleResult();
    // Completing the task with approval, will end the subprocess and continue
    // the original process
    taskService.complete(verifyCreditTask.getId(), CollectionUtil.singletonMap("creditApproved", true));
    Task prepareAndShipTask = taskQuery.singleResult();
    assertEquals("Prepare and Ship", prepareAndShipTask.getName());
    // verify
    HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().superProcessInstanceId(pi.getId()).singleResult();
    assertNotNull(historicProcessInstance);
    assertTrue(historicProcessInstance.getProcessDefinitionId().contains("checkCreditProcess"));
}

64. MultiTenancyFilterServiceTest#createTaskForTenant()

View license
protected void createTaskForTenant(String tenantId) {
    Task newTask = taskService.newTask();
    newTask.setName("testTask");
    if (tenantId != null) {
        newTask.setTenantId(tenantId);
    }
    taskService.saveTask(newTask);
    taskIds.add(newTask.getId());
}

65. MultiTenancyTaskServiceTest#testStandaloneTaskCreateWithTenantId()

View license
public void testStandaloneTaskCreateWithTenantId() {
    // given a transient task with tenant id
    Task task = taskService.newTask();
    task.setTenantId(tenant1);
    // if
    // it is saved
    taskService.saveTask(task);
    // then
    // when I load it, the tenant id is preserved
    task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
    assertEquals(tenant1, task.getTenantId());
    // Finally, delete task
    deleteTasks(task);
}

66. MultiTenancyTaskServiceTest#testStandaloneTaskCannotChangeTenantIdIfNull()

View license
public void testStandaloneTaskCannotChangeTenantIdIfNull() {
    // given a persistent task without tenant id
    Task task = taskService.newTask();
    taskService.saveTask(task);
    task = taskService.createTaskQuery().singleResult();
    // if
    // change the tenant id
    task.setTenantId(tenant1);
    // 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);
}

67. MultiTenancyTaskServiceTest#testStandaloneTaskPropagatesTenantIdToVariableInstance()

View license
public void testStandaloneTaskPropagatesTenantIdToVariableInstance() {
    // given a task with tenant id
    Task task = taskService.newTask();
    task.setTenantId(tenant1);
    taskService.saveTask(task);
    // if we set a variable for the task
    taskService.setVariable(task.getId(), "var", "test");
    // then a variable instance with the same tenant id is created
    VariableInstance variableInstance = runtimeService.createVariableInstanceQuery().singleResult();
    assertThat(variableInstance, is(notNullValue()));
    assertThat(variableInstance.getTenantId(), is(tenant1));
    deleteTasks(task);
}

68. 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());
    }
}

69. 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());
    }
}

70. 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());
    }
}

71. 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());
}

72. 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);
}

73. 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);
}

74. 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);
}

75. 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);
}

76. 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());
}

77. 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());
}

78. 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());
}

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. TaskServiceTest#testResolveTaskWithParametersNullParameters()

View license
public void testResolveTaskWithParametersNullParameters() {
    Task task = taskService.newTask();
    task.setDelegationState(DelegationState.PENDING);
    taskService.saveTask(task);
    String taskId = task.getId();
    taskService.resolveTask(taskId, null);
    if (processEngineConfiguration.getHistoryLevel().getId() >= ProcessEngineConfigurationImpl.HISTORYLEVEL_AUDIT) {
        historyService.deleteHistoricTaskInstance(taskId);
    }
    // Fetch the task again
    task = taskService.createTaskQuery().taskId(taskId).singleResult();
    assertEquals(DelegationState.RESOLVED, task.getDelegationState());
    taskService.deleteTask(taskId, true);
}

81. TaskServiceTest#testResolveTaskWithParametersEmptyParameters()

View license
@SuppressWarnings("unchecked")
public void testResolveTaskWithParametersEmptyParameters() {
    Task task = taskService.newTask();
    task.setDelegationState(DelegationState.PENDING);
    taskService.saveTask(task);
    String taskId = task.getId();
    taskService.resolveTask(taskId, Collections.EMPTY_MAP);
    if (processEngineConfiguration.getHistoryLevel().getId() >= ProcessEngineConfigurationImpl.HISTORYLEVEL_AUDIT) {
        historyService.deleteHistoricTaskInstance(taskId);
    }
    // Fetch the task again
    task = taskService.createTaskQuery().taskId(taskId).singleResult();
    assertEquals(DelegationState.RESOLVED, task.getDelegationState());
    taskService.deleteTask(taskId, true);
}

82. TaskServiceTest#testResolveWithParametersTask()

View license
@Deployment(resources = TWO_TASKS_PROCESS)
public void testResolveWithParametersTask() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("twoTasksProcess");
    // Fetch first task
    Task task = taskService.createTaskQuery().singleResult();
    assertEquals("First task", task.getName());
    task.delegate("johndoe");
    // Resolve first task
    Map<String, Object> taskParams = new HashMap<String, Object>();
    taskParams.put("myParam", "myValue");
    taskService.resolveTask(task.getId(), taskParams);
    // Verify that task is resolved
    task = taskService.createTaskQuery().taskDelegationState(DelegationState.RESOLVED).singleResult();
    assertEquals("First task", task.getName());
    // Verify task parameters set on execution
    Map<String, Object> variables = runtimeService.getVariables(processInstance.getId());
    assertEquals(1, variables.size());
    assertEquals("myValue", variables.get("myParam"));
}

83. ExecutionVariablesTest#testTreeCompactionAndExpansionWithConcurrentLocalVariables()

View license
@Deployment(resources = "org/camunda/bpm/engine/test/api/variables/ExecutionVariablesTest.testTreeCompactionForkParallelGateway.bpmn20.xml")
public void testTreeCompactionAndExpansionWithConcurrentLocalVariables() {
    // given
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");
    Execution task1Execution = runtimeService.createExecutionQuery().activityId("task1").singleResult();
    Task task2 = taskService.createTaskQuery().taskDefinitionKey("task2").singleResult();
    runtimeService.setVariableLocal(task1Execution.getId(), "var", "value");
    // when compacting the tree
    taskService.complete(task2.getId());
    // and expanding again
    runtimeService.createProcessInstanceModification(processInstance.getId()).startBeforeActivity("task2").execute();
    // then the variable is again assigned to task1's concurrent execution
    Task task1 = taskService.createTaskQuery().taskDefinitionKey("task1").singleResult();
    VariableInstance variable = runtimeService.createVariableInstanceQuery().singleResult();
    assertEquals(task1.getExecutionId(), variable.getExecutionId());
}

84. CallActivityDelegateMappingTest#delegateVariableMappingThrowExceptionOutput()

View license
private void delegateVariableMappingThrowExceptionOutput() {
    //given
    engineRule.getRuntimeService().startProcessInstanceByKey("callSimpleSubProcess");
    TaskQuery taskQuery = engineRule.getTaskService().createTaskQuery();
    Task taskBeforeSubProcess = taskQuery.singleResult();
    assertEquals("Task before subprocess", taskBeforeSubProcess.getName());
    engineRule.getTaskService().complete(taskBeforeSubProcess.getId());
    Task taskInSubProcess = taskQuery.singleResult();
    //which throws an exception
    try {
        engineRule.getTaskService().complete(taskInSubProcess.getId());
        fail("Exeption expected!");
    } catch (//then
    ProcessEngineException //then
    pee) {
        Assert.assertTrue(pee.getMessage().equalsIgnoreCase("org.camunda.bpm.engine.ProcessEngineException: New process engine exception.") || pee.getMessage().contains("1234"));
    }
    //then process rollback to user task which is in sub process
    //not catched by boundary event
    taskInSubProcess = taskQuery.singleResult();
    assertEquals("Task in subprocess", taskInSubProcess.getName());
}

85. CallActivityTest#testTimerOnCallActivity()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/callactivity/CallActivity.testTimerOnCallActivity.bpmn20.xml", "org/camunda/bpm/engine/test/bpmn/callactivity/simpleSubProcess.bpmn20.xml" })
public void testTimerOnCallActivity() {
    // After process start, the task in the subprocess should be active
    runtimeService.startProcessInstanceByKey("timerOnCallActivity");
    TaskQuery taskQuery = taskService.createTaskQuery();
    Task taskInSubProcess = taskQuery.singleResult();
    assertEquals("Task in subprocess", taskInSubProcess.getName());
    Job timer = managementService.createJobQuery().singleResult();
    assertNotNull(timer);
    managementService.executeJob(timer.getId());
    Task escalatedTask = taskQuery.singleResult();
    assertEquals("Escalated Task", escalatedTask.getName());
    // Completing the task ends the complete process
    taskService.complete(escalatedTask.getId());
    assertEquals(0, runtimeService.createExecutionQuery().list().size());
}

86. CallActivityTest#testOrderProcessWithCallActivity()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/callactivity/orderProcess.bpmn20.xml", "org/camunda/bpm/engine/test/bpmn/callactivity/checkCreditProcess.bpmn20.xml" })
public void testOrderProcessWithCallActivity() {
    // After the process has started, the 'verify credit history' task should be active
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("orderProcess");
    TaskQuery taskQuery = taskService.createTaskQuery();
    Task verifyCreditTask = taskQuery.singleResult();
    assertEquals("Verify credit history", verifyCreditTask.getName());
    // Verify with Query API
    ProcessInstance subProcessInstance = runtimeService.createProcessInstanceQuery().superProcessInstanceId(pi.getId()).singleResult();
    assertNotNull(subProcessInstance);
    assertEquals(pi.getId(), runtimeService.createProcessInstanceQuery().subProcessInstanceId(subProcessInstance.getId()).singleResult().getId());
    // Completing the task with approval, will end the subprocess and continue the original process
    taskService.complete(verifyCreditTask.getId(), CollectionUtil.singletonMap("creditApproved", true));
    Task prepareAndShipTask = taskQuery.singleResult();
    assertEquals("Prepare and Ship", prepareAndShipTask.getName());
}

87. CompensateEventTest#testCompensateParallelSubprocessCompHandlerWaitstate()

View license
@Deployment
public void testCompensateParallelSubprocessCompHandlerWaitstate() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("compensateProcess");
    List<Task> compensationHandlerTasks = taskService.createTaskQuery().taskDefinitionKey("undoBookHotel").list();
    assertEquals(5, compensationHandlerTasks.size());
    ActivityInstance rootActivityInstance = runtimeService.getActivityInstance(processInstance.getId());
    List<ActivityInstance> compensationHandlerInstances = getInstancesForActivityId(rootActivityInstance, "undoBookHotel");
    assertEquals(5, compensationHandlerInstances.size());
    for (Task task : compensationHandlerTasks) {
        taskService.complete(task.getId());
    }
    Task singleResult = taskService.createTaskQuery().singleResult();
    taskService.complete(singleResult.getId());
    runtimeService.signal(processInstance.getId());
    assertProcessEnded(processInstance.getId());
}

88. CompensateEventTest#testCompensateActivityInSubprocess()

View license
@Deployment
public void testCompensateActivityInSubprocess() {
    // given
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("compensateProcess");
    Task scopeTask = taskService.createTaskQuery().singleResult();
    taskService.complete(scopeTask.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());
}

89. CompensateEventTest#FAILING_testSubprocessCompensationHandlerWithEventSubprocess()

View license
/**
   * CAM-4387
   */
@Deployment
public void FAILING_testSubprocessCompensationHandlerWithEventSubprocess() {
    // given a process instance in compensation
    runtimeService.startProcessInstanceByKey("subProcessCompensationHandlerWithEventSubprocess");
    Task beforeCompensationTask = taskService.createTaskQuery().singleResult();
    taskService.complete(beforeCompensationTask.getId());
    // when the event subprocess is triggered that is defined as part of the compensation handler
    runtimeService.correlateMessage("Message");
    // then activity instance tree is correct
    Task task = taskService.createTaskQuery().singleResult();
    assertNotNull(task);
    assertEquals("eventSubProcessTask", task.getTaskDefinitionKey());
}

90. TerminateEndEventTest#testTerminateInSubProcessConcurrentMultiInstance()

View license
@Deployment
public void testTerminateInSubProcessConcurrentMultiInstance() throws Exception {
    serviceTaskInvokedCount = 0;
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("terminateEndEventExample");
    long executionEntities = runtimeService.createExecutionQuery().count();
    assertEquals(12, executionEntities);
    Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).taskDefinitionKey("preNormalEnd").singleResult();
    taskService.complete(task.getId());
    long executionEntities2 = runtimeService.createExecutionQuery().count();
    assertEquals(10, executionEntities2);
    List<Task> tasks = taskService.createTaskQuery().list();
    for (Task t : tasks) {
        taskService.complete(t.getId());
    }
    assertProcessEnded(pi.getId());
}

91. EscalationEventSubprocessTest#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/EscalationEventSubprocessTest.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
    // (1) the variables has been passed for the first time (from sub process to super process)
    Task taskInSuperProcess = taskService.createTaskQuery().taskDefinitionKey("taskAfterCatchedEscalation").singleResult();
    assertNotNull(taskInSuperProcess);
    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. 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"));
}

93. MessageEventSubprocessTest#testNonInterruptingWithTerminatingEndEvent()

View license
@Deployment
public void testNonInterruptingWithTerminatingEndEvent() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");
    Task task = taskService.createTaskQuery().singleResult();
    assertThat(task.getName(), is("Inner User Task"));
    runtimeService.correlateMessage("message");
    Task eventSubprocessTask = taskService.createTaskQuery().taskName("Event User Task").singleResult();
    assertThat(eventSubprocessTask, is(notNullValue()));
    taskService.complete(eventSubprocessTask.getId());
    ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId());
    assertThat(tree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).beginScope("SubProcess_1").activity("UserTask_1").endScope().endScope().done());
}

94. BoundaryTimerNonInterruptingEventTest#testTimerOnConcurrentTasks()

View license
@Deployment
public void testTimerOnConcurrentTasks() {
    String procId = runtimeService.startProcessInstanceByKey("nonInterruptingOnConcurrentTasks").getId();
    assertEquals(2, taskService.createTaskQuery().count());
    Job timer = managementService.createJobQuery().singleResult();
    managementService.executeJob(timer.getId());
    assertEquals(3, taskService.createTaskQuery().count());
    // Complete task that was reached by non interrupting timer
    Task task = taskService.createTaskQuery().taskDefinitionKey("timerFiredTask").singleResult();
    taskService.complete(task.getId());
    assertEquals(2, taskService.createTaskQuery().count());
    // Complete other tasks
    for (Task t : taskService.createTaskQuery().list()) {
        taskService.complete(t.getId());
    }
    assertProcessEnded(procId);
}

95. 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");
}

96. 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());
}

97. 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());
}

98. 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());
}

99. 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());
}

100. SubProcessTest#testDoubleNestedSimpleSubProcess()

View license
/**
   * Test case where the simple sub process of previous test cases
   * is nested within two other sub processes
   */
@Deployment
public void testDoubleNestedSimpleSubProcess() {
    // After staring the process, the task in the inner subprocess must be active
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("nestedSimpleSubProcess");
    Task subProcessTask = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    assertEquals("Task in subprocess", subProcessTask.getName());
    // After completing the task in the subprocess,
    // both subprocesses are destroyed and the task after the subprocess should be active
    taskService.complete(subProcessTask.getId());
    Task taskAfterSubProcesses = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    assertEquals("Task after subprocesses", taskAfterSubProcesses.getName());
}