org.camunda.bpm.engine.runtime.processinstance

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

1. ProcessInstanceQueryTest#testQueryBySuperProcessInstanceIdNested()

View license
// Nested subprocess make the query complexer, hence this test
@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/superProcessWithNestedSubProcess.bpmn20.xml", "org/camunda/bpm/engine/test/api/runtime/nestedSubProcess.bpmn20.xml", "org/camunda/bpm/engine/test/api/runtime/subProcess.bpmn20.xml" })
public void testQueryBySuperProcessInstanceIdNested() {
    ProcessInstance superProcessInstance = runtimeService.startProcessInstanceByKey("nestedSubProcessQueryTest");
    ProcessInstance subProcessInstance = runtimeService.createProcessInstanceQuery().superProcessInstanceId(superProcessInstance.getId()).singleResult();
    assertNotNull(subProcessInstance);
    ProcessInstance nestedSubProcessInstance = runtimeService.createProcessInstanceQuery().superProcessInstanceId(subProcessInstance.getId()).singleResult();
    assertNotNull(nestedSubProcessInstance);
}

2. ProcessInstanceQueryTest#testQueryBySubProcessInstanceIdNested()

View license
//Nested subprocess make the query complexer, hence this test
@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/superProcessWithNestedSubProcess.bpmn20.xml", "org/camunda/bpm/engine/test/api/runtime/nestedSubProcess.bpmn20.xml", "org/camunda/bpm/engine/test/api/runtime/subProcess.bpmn20.xml" })
public void testQueryBySubProcessInstanceIdNested() {
    ProcessInstance superProcessInstance = runtimeService.startProcessInstanceByKey("nestedSubProcessQueryTest");
    ProcessInstance subProcessInstance = runtimeService.createProcessInstanceQuery().superProcessInstanceId(superProcessInstance.getId()).singleResult();
    assertEquals(superProcessInstance.getId(), runtimeService.createProcessInstanceQuery().subProcessInstanceId(subProcessInstance.getId()).singleResult().getId());
    ProcessInstance nestedSubProcessInstance = runtimeService.createProcessInstanceQuery().superProcessInstanceId(subProcessInstance.getId()).singleResult();
    assertEquals(subProcessInstance.getId(), runtimeService.createProcessInstanceQuery().subProcessInstanceId(nestedSubProcessInstance.getId()).singleResult().getId());
}

3. TaskQueryTest#testQueryResultOrderingByStringVariableWithMixedCase()

View license
@Deployment(resources = "org/camunda/bpm/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml")
public void testQueryResultOrderingByStringVariableWithMixedCase() {
    // given three tasks with String and Integer process instance variables
    ProcessInstance instance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", Collections.<String, Object>singletonMap("var", "a"));
    ProcessInstance instance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", Collections.<String, Object>singletonMap("var", "B"));
    ProcessInstance instance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", Collections.<String, Object>singletonMap("var", "c"));
    // when I make a task query with variable ordering by String values
    List<Task> tasks = taskService.createTaskQuery().processDefinitionKey("oneTaskProcess").orderByProcessVariable("var", ValueType.STRING).asc().list();
    // then the tasks are ordered correctly
    assertEquals(3, tasks.size());
    // first the numeric valued task (since it is treated like null-valued)
    assertEquals(instance1.getId(), tasks.get(0).getProcessInstanceId());
    // then the others in alphabetical order
    assertEquals(instance2.getId(), tasks.get(1).getProcessInstanceId());
    assertEquals(instance3.getId(), tasks.get(2).getProcessInstanceId());
}

4. MultiTenancyHistoricDetailFormPropertyQueryTest#setUp()

View license
@Override
protected void setUp() throws IOException {
    BpmnModelInstance oneTaskProcess = Bpmn.createExecutableProcess("testProcess").startEvent().userTask("userTask").camundaFormField().camundaId("myFormField").camundaType("string").camundaFormFieldDone().endEvent().done();
    deploymentForTenant(TENANT_ONE, oneTaskProcess);
    deploymentForTenant(TENANT_TWO, oneTaskProcess);
    ProcessInstance processInstanceOne = startProcessInstanceForTenant(TENANT_ONE);
    ProcessInstance processInstanceTwo = startProcessInstanceForTenant(TENANT_TWO);
    completeUserTask(processInstanceOne);
    completeUserTask(processInstanceTwo);
}

5. MultiTenancyHistoricDetailVariableUpdateQueryTest#setUp()

View license
@Override
protected void setUp() {
    BpmnModelInstance oneTaskProcess = Bpmn.createExecutableProcess("testProcess").startEvent().userTask().endEvent().done();
    deploymentForTenant(TENANT_ONE, oneTaskProcess);
    deploymentForTenant(TENANT_TWO, oneTaskProcess);
    ProcessInstance processInstanceOne = startProcessInstanceForTenant(TENANT_ONE, TENANT_ONE_VAR);
    ProcessInstance processInstanceTwo = startProcessInstanceForTenant(TENANT_TWO, TENANT_TWO_VAR);
    completeUserTask(processInstanceOne, TENANT_ONE_VAR + "_updated");
    completeUserTask(processInstanceTwo, TENANT_TWO_VAR + "_updated");
}

6. MultiTenancyHistoricTaskInstanceQueryTest#setUp()

View license
@Override
protected void setUp() {
    BpmnModelInstance oneTaskProcess = Bpmn.createExecutableProcess("testProcess").startEvent().userTask().endEvent().done();
    deploymentForTenant(TENANT_ONE, oneTaskProcess);
    deploymentForTenant(TENANT_TWO, oneTaskProcess);
    ProcessInstance processInstanceOne = startProcessInstanceForTenant(TENANT_ONE);
    ProcessInstance processInstanceTwo = startProcessInstanceForTenant(TENANT_TWO);
    completeUserTask(processInstanceOne);
    completeUserTask(processInstanceTwo);
}

7. TenantIdProviderTest#setsTenantId_SubProcessInstance()

View license
@Test
public void setsTenantId_SubProcessInstance() {
    String tenantId = TENANT_ID;
    SetValueOnSubProcessInstanceTenantIdProvider tenantIdProvider = new SetValueOnSubProcessInstanceTenantIdProvider(tenantId);
    TestTenantIdProvider.delegate = tenantIdProvider;
    testRule.deploy(Bpmn.createExecutableProcess(PROCESS_DEFINITION_KEY).startEvent().userTask().done(), Bpmn.createExecutableProcess("superProcess").startEvent().callActivity().calledElement(PROCESS_DEFINITION_KEY).done());
    // if a process instance is started
    engineRule.getRuntimeService().startProcessInstanceByKey("superProcess");
    // then the tenant id provider can set the tenant id to a value
    ProcessInstance subProcessInstance = engineRule.getRuntimeService().createProcessInstanceQuery().processDefinitionKey(PROCESS_DEFINITION_KEY).singleResult();
    assertThat(subProcessInstance.getTenantId(), is(tenantId));
    // and the super process instance is not assigned a tenant id
    ProcessInstance superProcessInstance = engineRule.getRuntimeService().createProcessInstanceQuery().processDefinitionKey("superProcess").singleResult();
    assertThat(superProcessInstance.getTenantId(), is(nullValue()));
}

8. ExecutionQueryTest#testClashingValues()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testClashingValues() throws Exception {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("var", 1234L);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    Map<String, Object> vars2 = new HashMap<String, Object>();
    vars2.put("var", 1234);
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars2);
    List<Execution> executions = runtimeService.createExecutionQuery().processDefinitionKey("oneTaskProcess").variableValueEquals("var", 1234L).list();
    assertEquals(1, executions.size());
    assertEquals(processInstance.getId(), executions.get(0).getProcessInstanceId());
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
}

9. ExecutionQueryTest#testQueryForExecutionsWithMessageEventSubscriptions()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml", "org/camunda/bpm/engine/test/api/runtime/oneMessageCatchProcess.bpmn20.xml" })
public void testQueryForExecutionsWithMessageEventSubscriptions() {
    runtimeService.startProcessInstanceByKey("oneTaskProcess");
    runtimeService.startProcessInstanceByKey("oneTaskProcess");
    ProcessInstance instance1 = runtimeService.startProcessInstanceByKey("oneMessageCatchProcess");
    ProcessInstance instance2 = runtimeService.startProcessInstanceByKey("oneMessageCatchProcess");
    List<Execution> executions = runtimeService.createExecutionQuery().messageEventSubscription().orderByProcessInstanceId().asc().list();
    assertEquals(2, executions.size());
    if (instance1.getId().compareTo(instance2.getId()) < 0) {
        assertEquals(instance1.getId(), executions.get(0).getProcessInstanceId());
        assertEquals(instance2.getId(), executions.get(1).getProcessInstanceId());
    } else {
        assertEquals(instance2.getId(), executions.get(0).getProcessInstanceId());
        assertEquals(instance1.getId(), executions.get(1).getProcessInstanceId());
    }
}

10. IncidentQueryTest#testQueryByCauseIncidentId()

View license
@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/IncidentQueryTest.testQueryByCauseIncidentId.bpmn" })
public void testQueryByCauseIncidentId() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("callFailingProcess");
    testHelper.executeAvailableJobs();
    ProcessInstance subProcessInstance = runtimeService.createProcessInstanceQuery().superProcessInstanceId(processInstance.getId()).singleResult();
    assertNotNull(subProcessInstance);
    Incident causeIncident = runtimeService.createIncidentQuery().processInstanceId(subProcessInstance.getId()).singleResult();
    assertNotNull(causeIncident);
    IncidentQuery query = runtimeService.createIncidentQuery().causeIncidentId(causeIncident.getId());
    assertEquals(2, query.count());
    List<Incident> incidents = query.list();
    assertFalse(incidents.isEmpty());
    assertEquals(2, incidents.size());
}

11. MessageCorrelationTest#testMessageCorrelateAllResultListWithResultTypeExecution()

View license
@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/MessageCorrelationTest.testCatchingMessageEventCorrelation.bpmn20.xml")
public void testMessageCorrelateAllResultListWithResultTypeExecution() {
    //given
    ProcessInstance procInstance1 = runtimeService.startProcessInstanceByKey("process");
    ProcessInstance procInstance2 = runtimeService.startProcessInstanceByKey("process");
    //when correlated all with result
    List<MessageCorrelationResult> resultList = runtimeService.createMessageCorrelation("newInvoiceMessage").correlateAllWithResult();
    assertEquals(2, resultList.size());
    //then result should contains executions on which messages was correlated
    for (MessageCorrelationResult result : resultList) {
        assertNotNull(result);
        assertEquals(MessageCorrelationResultType.Execution, result.getResultType());
        assertTrue(procInstance1.getId().equalsIgnoreCase(result.getExecution().getProcessInstanceId()) || procInstance2.getId().equalsIgnoreCase(result.getExecution().getProcessInstanceId()));
        ExecutionEntity entity = (ExecutionEntity) result.getExecution();
        assertEquals("messageCatch", entity.getActivityId());
    }
}

12. BatchMigrationTest#testMigrateWithVarargsArray()

View license
@Test
public void testMigrateWithVarargsArray() {
    ProcessDefinition sourceDefinition = migrationRule.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    ProcessDefinition targetDefinition = migrationRule.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    MigrationPlan migrationPlan = runtimeService.createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId()).mapEqualActivities().build();
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceById(sourceDefinition.getId());
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceById(sourceDefinition.getId());
    // when
    Batch batch = runtimeService.newMigration(migrationPlan).processInstanceIds(processInstance1.getId(), processInstance2.getId()).executeAsync();
    helper.executeSeedJob(batch);
    helper.executeMigrationJobs(batch);
    helper.executeMonitorJob(batch);
    // then
    Assert.assertEquals(2, runtimeService.createProcessInstanceQuery().processDefinitionId(targetDefinition.getId()).count());
}

13. MigrationProcessInstanceTest#testMigrateWithIdVarargsArray()

View license
@Test
public void testMigrateWithIdVarargsArray() {
    ProcessDefinition sourceDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    ProcessDefinition targetDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    MigrationPlan migrationPlan = runtimeService.createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId()).mapEqualActivities().build();
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceById(sourceDefinition.getId());
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceById(sourceDefinition.getId());
    // when
    runtimeService.newMigration(migrationPlan).processInstanceIds(processInstance1.getId(), processInstance2.getId()).execute();
    // then
    Assert.assertEquals(2, runtimeService.createProcessInstanceQuery().processDefinitionId(targetDefinition.getId()).count());
}

14. MigrationProcessInstanceTest#testProcessInstanceIdsAndQuery()

View license
@Test
public void testProcessInstanceIdsAndQuery() {
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    MigrationPlan migrationPlan = runtimeService.createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapEqualActivities().build();
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceById(sourceProcessDefinition.getId());
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceById(sourceProcessDefinition.getId());
    ProcessInstanceQuery sourceProcessInstanceQuery = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance2.getId());
    ProcessInstanceQuery targetProcessInstanceQuery = runtimeService.createProcessInstanceQuery().processDefinitionId(targetProcessDefinition.getId());
    assertEquals(0, targetProcessInstanceQuery.count());
    runtimeService.newMigration(migrationPlan).processInstanceIds(Collections.singletonList(processInstance1.getId())).processInstanceQuery(sourceProcessInstanceQuery).execute();
    assertEquals(2, targetProcessInstanceQuery.count());
}

15. MigrationProcessInstanceTest#testOverlappingProcessInstanceIdsAndQuery()

View license
@Test
public void testOverlappingProcessInstanceIdsAndQuery() {
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    MigrationPlan migrationPlan = runtimeService.createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapEqualActivities().build();
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceById(sourceProcessDefinition.getId());
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceById(sourceProcessDefinition.getId());
    ProcessInstanceQuery sourceProcessInstanceQuery = runtimeService.createProcessInstanceQuery().processDefinitionId(sourceProcessDefinition.getId());
    ProcessInstanceQuery targetProcessInstanceQuery = runtimeService.createProcessInstanceQuery().processDefinitionId(targetProcessDefinition.getId());
    assertEquals(0, targetProcessInstanceQuery.count());
    runtimeService.newMigration(migrationPlan).processInstanceIds(Arrays.asList(processInstance1.getId(), processInstance2.getId())).processInstanceQuery(sourceProcessInstanceQuery).execute();
    assertEquals(2, targetProcessInstanceQuery.count());
}

16. ProcessInstanceModificationTest#FAILING_testCancelCallActivityInstance()

View license
@Deployment(resources = { CALL_ACTIVITY_PARENT_PROCESS, CALL_ACTIVITY_CHILD_PROCESS })
public void FAILING_testCancelCallActivityInstance() {
    // given
    ProcessInstance parentprocess = runtimeService.startProcessInstanceByKey("parentprocess");
    ProcessInstance subProcess = runtimeService.createProcessInstanceQuery().processDefinitionKey("subprocess").singleResult();
    ActivityInstance subProcessActivityInst = runtimeService.getActivityInstance(subProcess.getId());
    // when
    runtimeService.createProcessInstanceModification(subProcess.getId()).startBeforeActivity("childEnd", subProcess.getId()).cancelActivityInstance(getInstanceIdForActivity(subProcessActivityInst, "innerTask")).execute();
    // then
    assertProcessEnded(parentprocess.getId());
}

17. ProcessInstanceQueryTest#testQueryBySuperProcessInstanceId()

View license
@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/superProcess.bpmn20.xml", "org/camunda/bpm/engine/test/api/runtime/subProcess.bpmn20.xml" })
public void testQueryBySuperProcessInstanceId() {
    ProcessInstance superProcessInstance = runtimeService.startProcessInstanceByKey("subProcessQueryTest");
    ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().superProcessInstanceId(superProcessInstance.getId());
    ProcessInstance subProcessInstance = query.singleResult();
    assertNotNull(subProcessInstance);
    assertEquals(1, query.list().size());
    assertEquals(1, query.count());
}

18. ProcessInstanceQueryTest#testClashingValues()

View license
@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testClashingValues() throws Exception {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("var", 1234L);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    Map<String, Object> vars2 = new HashMap<String, Object>();
    vars2.put("var", 1234);
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars2);
    List<ProcessInstance> foundInstances = runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").variableValueEquals("var", 1234L).list();
    assertEquals(1, foundInstances.size());
    assertEquals(processInstance.getId(), foundInstances.get(0).getId());
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
}

19. TaskQueryTest#testQueryByMultipleActivityInstanceIds()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml" })
public void testQueryByMultipleActivityInstanceIds() throws Exception {
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    String activityInstanceId1 = runtimeService.getActivityInstance(processInstance1.getId()).getChildActivityInstances()[0].getId();
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    String activityInstanceId2 = runtimeService.getActivityInstance(processInstance2.getId()).getChildActivityInstances()[0].getId();
    List<Task> result1 = taskService.createTaskQuery().activityInstanceIdIn(activityInstanceId1).list();
    assertEquals(1, result1.size());
    assertEquals(processInstance1.getId(), result1.get(0).getProcessInstanceId());
    List<Task> result2 = taskService.createTaskQuery().activityInstanceIdIn(activityInstanceId2).list();
    assertEquals(1, result2.size());
    assertEquals(processInstance2.getId(), result2.get(0).getProcessInstanceId());
    assertEquals(2, taskService.createTaskQuery().activityInstanceIdIn(activityInstanceId1, activityInstanceId2).list().size());
}

20. CallActivityDelegateMappingTest#testCallSubProcessWithDelegatedVariableMappingAndAsyncServiceTask()

View license
@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/callactivity/CallActivityDelegateMappingTest.testCallSubProcessWithDelegatedVariableMappingAndAsyncServiceTask.bpmn20.xml", "org/camunda/bpm/engine/test/bpmn/callactivity/simpleSubProcessWithAsyncService.bpmn20.xml" })
public void testCallSubProcessWithDelegatedVariableMappingAndAsyncServiceTask() {
    //given starting process instance with call activity which has asyn service task
    ProcessInstance superProcInst = engineRule.getRuntimeService().startProcessInstanceByKey("callSimpleSubProcess");
    ProcessInstance subProcInst = engineRule.getRuntimeService().createProcessInstanceQuery().processDefinitionKey("simpleSubProcessWithAsyncService").singleResult();
    //then delegation variable mapping class should also been resolved
    //input mapping should be executed
    Object inVar = engineRule.getRuntimeService().getVariable(subProcInst.getId(), "TestInputVar");
    assertEquals("inValue", inVar);
    //and after finish call activity the ouput mapping is executed
    testHelper.executeAvailableJobs();
    Object outputVar = engineRule.getRuntimeService().getVariable(superProcInst.getId(), "TestOutputVar");
    assertEquals("outValue", outputVar);
}

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

22. HistoricDecisionInstanceTest#testQueryByDecisionInstanceId()

View license
@Deployment(resources = { DECISION_PROCESS, DECISION_SINGLE_OUTPUT_DMN })
public void testQueryByDecisionInstanceId() {
    ProcessInstance pi1 = startProcessInstanceAndEvaluateDecision();
    ProcessInstance pi2 = startProcessInstanceAndEvaluateDecision();
    String decisionInstanceId1 = historyService.createHistoricDecisionInstanceQuery().processInstanceId(pi1.getId()).singleResult().getId();
    String decisionInstanceId2 = historyService.createHistoricDecisionInstanceQuery().processInstanceId(pi2.getId()).singleResult().getId();
    HistoricDecisionInstanceQuery query = historyService.createHistoricDecisionInstanceQuery();
    assertThat(query.decisionInstanceId(decisionInstanceId1).count(), is(1L));
    assertThat(query.decisionInstanceId(decisionInstanceId2).count(), is(1L));
    assertThat(query.decisionInstanceId("unknown").count(), is(0L));
}

23. HistoricDecisionInstanceTest#testQueryByDecisionInstanceIds()

View license
@Deployment(resources = { DECISION_PROCESS, DECISION_SINGLE_OUTPUT_DMN })
public void testQueryByDecisionInstanceIds() {
    ProcessInstance pi1 = startProcessInstanceAndEvaluateDecision();
    ProcessInstance pi2 = startProcessInstanceAndEvaluateDecision();
    String decisionInstanceId1 = historyService.createHistoricDecisionInstanceQuery().processInstanceId(pi1.getId()).singleResult().getId();
    String decisionInstanceId2 = historyService.createHistoricDecisionInstanceQuery().processInstanceId(pi2.getId()).singleResult().getId();
    HistoricDecisionInstanceQuery query = historyService.createHistoricDecisionInstanceQuery();
    assertThat(query.decisionInstanceIdIn(decisionInstanceId1).count(), is(1L));
    assertThat(query.decisionInstanceIdIn(decisionInstanceId2).count(), is(1L));
    assertThat(query.decisionInstanceIdIn(decisionInstanceId1, decisionInstanceId2).count(), is(2L));
}

24. HistoricTaskInstanceTest#testHistoricTaskInstanceQueryByActivityInstanceIds()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/history/HistoricTaskInstanceTest.testHistoricTaskInstance.bpmn20.xml" })
public void testHistoricTaskInstanceQueryByActivityInstanceIds() throws Exception {
    ProcessInstance pi1 = runtimeService.startProcessInstanceByKey("HistoricTaskInstanceTest");
    ProcessInstance pi2 = runtimeService.startProcessInstanceByKey("HistoricTaskInstanceTest");
    String activityInstanceId1 = historyService.createHistoricActivityInstanceQuery().processInstanceId(pi1.getId()).activityId("task").singleResult().getId();
    String activityInstanceId2 = historyService.createHistoricActivityInstanceQuery().processInstanceId(pi2.getId()).activityId("task").singleResult().getId();
    HistoricTaskInstanceQuery query = historyService.createHistoricTaskInstanceQuery().activityInstanceIdIn(activityInstanceId1, activityInstanceId2);
    assertEquals(2, query.count());
    assertEquals(2, query.list().size());
}

25. HistoricVariableInstanceTest#testOrderProcessWithCallActivity()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/history/orderProcess.bpmn20.xml", "org/camunda/bpm/engine/test/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();
    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());
}

26. HistoricVariableInstanceTest#testHistoricVariableInstanceQueryByInvalidProcessIdIn()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/history/HistoricVariableInstanceTest.testParallel.bpmn20.xml" })
public void testHistoricVariableInstanceQueryByInvalidProcessIdIn() {
    // given
    Map<String, Object> vars = new HashMap<String, Object>();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc", vars);
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("myProc", vars);
    // check existing variables for task ID
    try {
        historyService.createHistoricVariableInstanceQuery().processInstanceIdIn(processInstance.getProcessInstanceId(), null);
        fail("Search by process instance ID was finished");
    } catch (ProcessEngineException e) {
    }
}

27. HistoricVariableInstanceTest#testHistoricVariableInstanceQueryByExecutionIds()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testHistoricVariableInstanceQueryByExecutionIds() {
    // given
    Map<String, Object> variables1 = new HashMap<String, Object>();
    variables1.put("stringVar", "test");
    variables1.put("myVar", "test123");
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables1);
    HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery().executionIdIn(processInstance1.getId());
    assertEquals(2, query.count());
    List<HistoricVariableInstance> variableInstances = query.list();
    assertEquals(2, variableInstances.size());
    for (HistoricVariableInstance variableInstance : variableInstances) {
        assertEquals(processInstance1.getId(), variableInstance.getExecutionId());
    }
    Map<String, Object> variables2 = new HashMap<String, Object>();
    variables2.put("myVar", "test123");
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables2);
    query = historyService.createHistoricVariableInstanceQuery().executionIdIn(processInstance1.getId(), processInstance2.getId());
    assertEquals(3, query.list().size());
    assertEquals(3, query.count());
}

28. HistoricVariableInstanceTest#testQueryByActivityInstanceIdIn()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testQueryByActivityInstanceIdIn() {
    // given
    Map<String, Object> variables1 = new HashMap<String, Object>();
    variables1.put("stringVar", "test");
    variables1.put("myVar", "test123");
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables1);
    HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();
    query.activityInstanceIdIn(processInstance1.getId());
    assertEquals(2, query.list().size());
    assertEquals(2, query.count());
    Map<String, Object> variables2 = new HashMap<String, Object>();
    variables2.put("myVar", "test123");
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables2);
    query.activityInstanceIdIn(processInstance1.getId(), processInstance2.getId());
    assertEquals(3, query.list().size());
    assertEquals(3, query.count());
}

29. SignalEventTest#testSignalCatchBoundaryWithVariables()

View license
@Test
@Deployment(resources = { "org/camunda/bpm/engine/cdi/test/bpmn/SignalEventTests.catchAlertSignalBoundaryWithReceiveTask.bpmn20.xml", "org/camunda/bpm/engine/cdi/test/bpmn/SignalEventTests.throwAlertSignalWithDelegate.bpmn20.xml" })
public void testSignalCatchBoundaryWithVariables() {
    HashMap<String, Object> variables1 = new HashMap<String, Object>();
    variables1.put("processName", "catchSignal");
    ProcessInstance piCatchSignal = runtimeService.startProcessInstanceByKey("catchSignal", variables1);
    HashMap<String, Object> variables2 = new HashMap<String, Object>();
    variables2.put("processName", "throwSignal");
    variables2.put("signalProcessInstanceId", piCatchSignal.getProcessInstanceId());
    ProcessInstance piThrowSignal = runtimeService.startProcessInstanceByKey("throwSignal", variables2);
    assertEquals(1, runtimeService.createExecutionQuery().processInstanceId(piCatchSignal.getProcessInstanceId()).activityId("receiveTask").count());
    assertEquals(1, runtimeService.createExecutionQuery().processInstanceId(piThrowSignal.getProcessInstanceId()).activityId("receiveTask").count());
    assertEquals("catchSignal-visited (was catchSignal)", runtimeService.getVariable(piCatchSignal.getId(), "processName"));
    assertEquals("throwSignal-visited (was throwSignal)", runtimeService.getVariable(piThrowSignal.getId(), "processName"));
    // clean up
    runtimeService.signal(piCatchSignal.getId());
    runtimeService.signal(piThrowSignal.getId());
}

30. CallActivityContextSwitchTest#testMainSyncCalledSync()

View license
@Test
@OperateOnDeployment("mainDeployment")
public void testMainSyncCalledSync() {
    Map<String, Object> processVariables = new HashMap<String, Object>();
    processVariables.put("calledElement", "calledProcessSync");
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("mainProcessSync", processVariables);
    Assert.assertEquals(true, runtimeService.getVariable(pi.getId(), DelegateBefore.class.getName()));
    ProcessInstance calledPi = runtimeService.createProcessInstanceQuery().processDefinitionKey("calledProcessSync").singleResult();
    Assert.assertEquals(true, runtimeService.getVariable(calledPi.getId(), "calledDelegate"));
    taskService.complete(taskService.createTaskQuery().processInstanceId(calledPi.getId()).singleResult().getId());
    Assert.assertEquals(true, runtimeService.getVariable(pi.getId(), DelegateAfter.class.getName()));
    taskService.complete(taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult().getId());
    Assert.assertNull(runtimeService.createProcessInstanceQuery().processDefinitionId(pi.getId()).singleResult());
    Assert.assertNull(runtimeService.createProcessInstanceQuery().processDefinitionId(calledPi.getId()).singleResult());
}

31. AsyncIntermediateThrowSignalEventTest#testAsyncSignalEvent()

View license
@Test
public void testAsyncSignalEvent() throws InterruptedException {
    ProcessInstance piCatchSignal = runtimeService.startProcessInstanceByKey("catchSignal");
    ProcessInstance piThrowSignal = runtimeService.startProcessInstanceByKey("throwSignal");
    waitForJobExecutorToProcessAllJobs();
    assertEquals(1, runtimeService.createExecutionQuery().processInstanceId(piCatchSignal.getProcessInstanceId()).activityId("receiveTask").count());
    assertEquals(1, runtimeService.createExecutionQuery().processInstanceId(piThrowSignal.getProcessInstanceId()).activityId("receiveTask").count());
    // clean up
    runtimeService.signal(piCatchSignal.getId());
    runtimeService.signal(piThrowSignal.getId());
    assertEquals(0, runtimeService.createExecutionQuery().processInstanceId(piCatchSignal.getProcessInstanceId()).count());
    assertEquals(0, runtimeService.createExecutionQuery().processInstanceId(piThrowSignal.getProcessInstanceId()).count());
}

32. IndependentJobExecutionTest#testDeploymentAwareJobAcquisition()

View license
@OperateOnDeployment("pa1")
@Test
public void testDeploymentAwareJobAcquisition() {
    JobExecutor jobExecutor1 = engine1Configuration.getJobExecutor();
    ProcessInstance instance1 = engine1.getRuntimeService().startProcessInstanceByKey("archive1Process");
    ProcessInstance instance2 = processEngine.getRuntimeService().startProcessInstanceByKey("archive2Process");
    Job job1 = managementService.createJobQuery().processInstanceId(instance1.getId()).singleResult();
    Job job2 = managementService.createJobQuery().processInstanceId(instance2.getId()).singleResult();
    // the deployment aware configuration should only return the jobs of the registered deployments
    CommandExecutor commandExecutor = engine1Configuration.getCommandExecutorTxRequired();
    AcquiredJobs acquiredJobs = commandExecutor.execute(new AcquireJobsCmd(jobExecutor1));
    Assert.assertEquals(1, acquiredJobs.size());
    Assert.assertTrue(acquiredJobs.contains(job1.getId()));
    Assert.assertFalse(acquiredJobs.contains(job2.getId()));
}

33. IndependentJobExecutionTest#testDeploymentUnawareJobAcquisition()

View license
@OperateOnDeployment("pa1")
@Test
public void testDeploymentUnawareJobAcquisition() {
    JobExecutor defaultJobExecutor = processEngineConfiguration.getJobExecutor();
    ProcessInstance instance1 = engine1.getRuntimeService().startProcessInstanceByKey("archive1Process");
    ProcessInstance instance2 = processEngine.getRuntimeService().startProcessInstanceByKey("archive2Process");
    Job job1 = managementService.createJobQuery().processInstanceId(instance1.getId()).singleResult();
    Job job2 = managementService.createJobQuery().processInstanceId(instance2.getId()).singleResult();
    // the deployment unaware configuration should return both jobs
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    processEngineConfiguration.setJobExecutorDeploymentAware(false);
    try {
        AcquiredJobs acquiredJobs = commandExecutor.execute(new AcquireJobsCmd(defaultJobExecutor));
        Assert.assertEquals(2, acquiredJobs.size());
        Assert.assertTrue(acquiredJobs.contains(job1.getId()));
        Assert.assertTrue(acquiredJobs.contains(job2.getId()));
    } finally {
        processEngineConfiguration.setJobExecutorDeploymentAware(true);
    }
}

34. CmmnDisabledTest#testVariableInstanceQuery()

View license
public void testVariableInstanceQuery() {
    ProcessApplicationDeployment deployment = repositoryService.createDeployment(processApplication.getReference()).addClasspathResource("org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml").deploy();
    VariableMap variables = Variables.createVariables().putValue("my-variable", "a-value");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);
    // variable instance query
    List<VariableInstance> result = runtimeService.createVariableInstanceQuery().list();
    assertEquals(1, result.size());
    VariableInstance variableInstance = result.get(0);
    assertEquals("my-variable", variableInstance.getName());
    // get variable
    assertNotNull(runtimeService.getVariable(processInstance.getId(), "my-variable"));
    // get variable local
    assertNotNull(runtimeService.getVariableLocal(processInstance.getId(), "my-variable"));
    repositoryService.deleteDeployment(deployment.getId(), true);
}

35. ProcessApplicationElResolverTest#testCallActivityOutputExpression()

View license
/**
   * Tests that an expression for a call activity output parameter is resolved
   * in the context of the called process definition's application.
   */
public void testCallActivityOutputExpression() {
    // given an instance of the calling process that calls the called process
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("callingProcess");
    // when the called process is completed
    Task calledProcessTask = taskService.createTaskQuery().singleResult();
    taskService.complete(calledProcessTask.getId());
    // then the output mapping should have successfully resolved the expression
    String outVariable = (String) runtimeService.getVariable(instance.getId(), "outVar");
    assertEquals(CalledProcessApplication.STRING_VARIABLE_VALUE, outVariable);
}

36. BatchQueryAuthorizationTest#deployProcessesAndCreateMigrationPlan()

View license
@Before
public void deployProcessesAndCreateMigrationPlan() {
    ProcessDefinition sourceDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    ProcessDefinition targetDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    migrationPlan = engineRule.getRuntimeService().createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId()).mapEqualActivities().build();
    ProcessInstance pi = engineRule.getRuntimeService().startProcessInstanceById(sourceDefinition.getId());
    batch1 = engineRule.getRuntimeService().newMigration(migrationPlan).processInstanceIds(Arrays.asList(pi.getId())).executeAsync();
    batch2 = engineRule.getRuntimeService().newMigration(migrationPlan).processInstanceIds(Arrays.asList(pi.getId())).executeAsync();
}

37. BatchStatisticsQueryAuthorizationTest#deployProcessesAndCreateMigrationPlan()

View license
@Before
public void deployProcessesAndCreateMigrationPlan() {
    ProcessDefinition sourceDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    ProcessDefinition targetDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    migrationPlan = engineRule.getRuntimeService().createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId()).mapEqualActivities().build();
    ProcessInstance pi = engineRule.getRuntimeService().startProcessInstanceById(sourceDefinition.getId());
    batch1 = engineRule.getRuntimeService().newMigration(migrationPlan).processInstanceIds(Arrays.asList(pi.getId())).executeAsync();
    Job seedJob = engineRule.getManagementService().createJobQuery().singleResult();
    engineRule.getManagementService().executeJob(seedJob.getId());
    batch2 = engineRule.getRuntimeService().newMigration(migrationPlan).processInstanceIds(Arrays.asList(pi.getId())).executeAsync();
}

38. DeleteHistoricBatchAuthorizationTest#testDeleteBatch()

View license
@Test
public void testDeleteBatch() {
    // given
    ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceById(migrationPlan.getSourceProcessDefinitionId());
    batch = engineRule.getRuntimeService().newMigration(migrationPlan).processInstanceIds(Arrays.asList(processInstance.getId())).executeAsync();
    // when
    authRule.init(scenario).withUser("userId").bindResource("batchId", batch.getId()).start();
    engineRule.getHistoryService().deleteHistoricBatch(batch.getId());
    // then
    if (authRule.assertScenario(scenario)) {
        Assert.assertEquals(0, engineRule.getHistoryService().createHistoricBatchQuery().count());
    }
}

39. HistoricBatchQueryAuthorizationTest#deployProcessesAndCreateMigrationPlan()

View license
@Before
public void deployProcessesAndCreateMigrationPlan() {
    ProcessDefinition sourceDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    ProcessDefinition targetDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    migrationPlan = engineRule.getRuntimeService().createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId()).mapEqualActivities().build();
    ProcessInstance pi = engineRule.getRuntimeService().startProcessInstanceById(sourceDefinition.getId());
    batch1 = engineRule.getRuntimeService().newMigration(migrationPlan).processInstanceIds(Arrays.asList(pi.getId())).executeAsync();
    batch2 = engineRule.getRuntimeService().newMigration(migrationPlan).processInstanceIds(Arrays.asList(pi.getId())).executeAsync();
}

40. SetExternalTaskPriorityAuthorizationTest#testSetPriority()

View license
@Test
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testSetPriority() {
    // given
    ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceByKey("oneExternalTaskProcess");
    ExternalTask task = engineRule.getExternalTaskService().createExternalTaskQuery().singleResult();
    // when
    authRule.init(scenario).withUser("userId").bindResource("processInstanceId", processInstance.getId()).bindResource("processDefinitionKey", "oneExternalTaskProcess").start();
    engineRule.getExternalTaskService().setPriority(task.getId(), 5);
    // then
    if (authRule.assertScenario(scenario)) {
        task = engineRule.getExternalTaskService().createExternalTaskQuery().singleResult();
        Assert.assertEquals(5, task.getPriority());
    }
}

41. SetExternalTaskRetriesAuthorizationTest#testSetRetries()

View license
@Test
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testSetRetries() {
    // given
    ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceByKey("oneExternalTaskProcess");
    ExternalTask task = engineRule.getExternalTaskService().createExternalTaskQuery().singleResult();
    // when
    authRule.init(scenario).withUser("userId").bindResource("processInstanceId", processInstance.getId()).bindResource("processDefinitionKey", "oneExternalTaskProcess").start();
    engineRule.getExternalTaskService().setRetries(task.getId(), 5);
    // then
    if (authRule.assertScenario(scenario)) {
        task = engineRule.getExternalTaskService().createExternalTaskQuery().singleResult();
        Assert.assertEquals(5, (int) task.getRetries());
    }
}

42. FormAuthorizationTest#testSubmitStartForm()

View license
public void testSubmitStartForm() {
    // given
    String processDefinitionId = selectProcessDefinitionByKey(FORM_KEY_PROCESS_KEY).getId();
    createGrantAuthorization(PROCESS_DEFINITION, FORM_KEY_PROCESS_KEY, userId, CREATE_INSTANCE);
    createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, CREATE);
    // when
    ProcessInstance instance = formService.submitStartForm(processDefinitionId, null);
    // then
    assertNotNull(instance);
}

43. SetJobPriorityAuthorizationTest#testSetJobPriority()

View license
@Test
@Deployment(resources = "org/camunda/bpm/engine/test/api/authorization/oneIncidentProcess.bpmn20.xml")
public void testSetJobPriority() {
    // given
    ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceByKey("process");
    Job job = engineRule.getManagementService().createJobQuery().singleResult();
    // when
    authRule.init(scenario).withUser("userId").bindResource("processInstanceId", processInstance.getId()).bindResource("processDefinitionKey", "process").start();
    engineRule.getManagementService().setJobPriority(job.getId(), 42);
    // then
    if (authRule.assertScenario(scenario)) {
        Job updatedJob = engineRule.getManagementService().createJobQuery().singleResult();
        Assert.assertEquals(42, updatedJob.getPriority());
    }
}

44. ProcessDefinitionAuthorizationTest#testSuspendProcessDefinitionByIdIncludingInstancesWithUpdatePermissionOnAnyProcessInstance()

View license
public void testSuspendProcessDefinitionByIdIncludingInstancesWithUpdatePermissionOnAnyProcessInstance() {
    // given
    String processDefinitionId = selectProcessDefinitionByKey(ONE_TASK_PROCESS_KEY).getId();
    createGrantAuthorization(PROCESS_DEFINITION, ONE_TASK_PROCESS_KEY, userId, UPDATE);
    startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
    createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, UPDATE);
    // when
    repositoryService.suspendProcessDefinitionById(processDefinitionId, true, null);
    // then
    ProcessDefinition definition = selectProcessDefinitionByKey(ONE_TASK_PROCESS_KEY);
    assertTrue(definition.isSuspended());
    ProcessInstance instance = selectSingleProcessInstance();
    assertTrue(instance.isSuspended());
}

45. ProcessDefinitionAuthorizationTest#testSuspendProcessDefinitionByIdIncludingInstancesWithUpdateInstancePermissionOnProcessDefinition()

View license
public void testSuspendProcessDefinitionByIdIncludingInstancesWithUpdateInstancePermissionOnProcessDefinition() {
    // given
    String processDefinitionId = selectProcessDefinitionByKey(ONE_TASK_PROCESS_KEY).getId();
    createGrantAuthorization(PROCESS_DEFINITION, ONE_TASK_PROCESS_KEY, userId, UPDATE, UPDATE_INSTANCE);
    startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
    // when
    repositoryService.suspendProcessDefinitionById(processDefinitionId, true, null);
    // then
    ProcessDefinition definition = selectProcessDefinitionByKey(ONE_TASK_PROCESS_KEY);
    assertTrue(definition.isSuspended());
    ProcessInstance instance = selectSingleProcessInstance();
    assertTrue(instance.isSuspended());
}

46. ProcessDefinitionAuthorizationTest#testActivateProcessDefinitionByIdIncludingInstancesWithUpdatePermissionOnAnyProcessInstance()

View license
public void testActivateProcessDefinitionByIdIncludingInstancesWithUpdatePermissionOnAnyProcessInstance() {
    // given
    startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
    createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, UPDATE);
    String processDefinitionId = selectProcessDefinitionByKey(ONE_TASK_PROCESS_KEY).getId();
    suspendProcessDefinitionById(processDefinitionId);
    createGrantAuthorization(PROCESS_DEFINITION, ONE_TASK_PROCESS_KEY, userId, UPDATE);
    // when
    repositoryService.activateProcessDefinitionById(processDefinitionId, true, null);
    // then
    ProcessDefinition definition = selectProcessDefinitionByKey(ONE_TASK_PROCESS_KEY);
    assertFalse(definition.isSuspended());
    ProcessInstance instance = selectSingleProcessInstance();
    assertFalse(instance.isSuspended());
}

47. ProcessDefinitionAuthorizationTest#testActivateProcessDefinitionByIdIncludingInstancesWithUpdateInstancePermissionOnProcessDefinition()

View license
public void testActivateProcessDefinitionByIdIncludingInstancesWithUpdateInstancePermissionOnProcessDefinition() {
    // given
    startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
    String processDefinitionId = selectProcessDefinitionByKey(ONE_TASK_PROCESS_KEY).getId();
    suspendProcessDefinitionById(processDefinitionId);
    createGrantAuthorization(PROCESS_DEFINITION, ONE_TASK_PROCESS_KEY, userId, UPDATE, UPDATE_INSTANCE);
    // when
    repositoryService.activateProcessDefinitionById(processDefinitionId, true, null);
    // then
    ProcessDefinition definition = selectProcessDefinitionByKey(ONE_TASK_PROCESS_KEY);
    assertFalse(definition.isSuspended());
    ProcessInstance instance = selectSingleProcessInstance();
    assertFalse(instance.isSuspended());
}

48. ProcessDefinitionAuthorizationTest#testSuspendProcessDefinitionByKeyIncludingInstancesWithUpdatePermissionOnAnyProcessInstance()

View license
public void testSuspendProcessDefinitionByKeyIncludingInstancesWithUpdatePermissionOnAnyProcessInstance() {
    // given
    createGrantAuthorization(PROCESS_DEFINITION, ONE_TASK_PROCESS_KEY, userId, UPDATE);
    startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
    createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, UPDATE);
    // when
    repositoryService.suspendProcessDefinitionByKey(ONE_TASK_PROCESS_KEY, true, null);
    // then
    ProcessDefinition definition = selectProcessDefinitionByKey(ONE_TASK_PROCESS_KEY);
    assertTrue(definition.isSuspended());
    ProcessInstance instance = selectSingleProcessInstance();
    assertTrue(instance.isSuspended());
}

49. ProcessDefinitionAuthorizationTest#testSuspendProcessDefinitionByKeyIncludingInstancesWithUpdateInstancePermissionOnProcessDefinition()

View license
public void testSuspendProcessDefinitionByKeyIncludingInstancesWithUpdateInstancePermissionOnProcessDefinition() {
    // given
    createGrantAuthorization(PROCESS_DEFINITION, ONE_TASK_PROCESS_KEY, userId, UPDATE, UPDATE_INSTANCE);
    startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
    // when
    repositoryService.suspendProcessDefinitionByKey(ONE_TASK_PROCESS_KEY, true, null);
    // then
    ProcessDefinition definition = selectProcessDefinitionByKey(ONE_TASK_PROCESS_KEY);
    assertTrue(definition.isSuspended());
    ProcessInstance instance = selectSingleProcessInstance();
    assertTrue(instance.isSuspended());
}

50. ProcessDefinitionAuthorizationTest#testActivateProcessDefinitionByKeyIncludingInstancesWithUpdatePermissionOnAnyProcessInstance()

View license
public void testActivateProcessDefinitionByKeyIncludingInstancesWithUpdatePermissionOnAnyProcessInstance() {
    // given
    startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
    createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, UPDATE);
    suspendProcessDefinitionByKey(ONE_TASK_PROCESS_KEY);
    createGrantAuthorization(PROCESS_DEFINITION, ONE_TASK_PROCESS_KEY, userId, UPDATE);
    // when
    repositoryService.activateProcessDefinitionByKey(ONE_TASK_PROCESS_KEY, true, null);
    // then
    ProcessDefinition definition = selectProcessDefinitionByKey(ONE_TASK_PROCESS_KEY);
    assertFalse(definition.isSuspended());
    ProcessInstance instance = selectSingleProcessInstance();
    assertFalse(instance.isSuspended());
}

51. ProcessDefinitionAuthorizationTest#testActivateProcessDefinitionByKeyIncludingInstancesWithUpdateInstancePermissionOnProcessDefinition()

View license
public void testActivateProcessDefinitionByKeyIncludingInstancesWithUpdateInstancePermissionOnProcessDefinition() {
    // given
    startProcessInstanceByKey(ONE_TASK_PROCESS_KEY);
    suspendProcessDefinitionByKey(ONE_TASK_PROCESS_KEY);
    createGrantAuthorization(PROCESS_DEFINITION, ONE_TASK_PROCESS_KEY, userId, UPDATE, UPDATE_INSTANCE);
    // when
    repositoryService.activateProcessDefinitionByKey(ONE_TASK_PROCESS_KEY, true, null);
    // then
    ProcessDefinition definition = selectProcessDefinitionByKey(ONE_TASK_PROCESS_KEY);
    assertFalse(definition.isSuspended());
    ProcessInstance instance = selectSingleProcessInstance();
    assertFalse(instance.isSuspended());
}

52. ProcessInstanceAuthorizationTest#testSimpleQueryWithReadPermissionOnProcessInstance()

View license
public void testSimpleQueryWithReadPermissionOnProcessInstance() {
    // given
    String processInstanceId = startProcessInstanceByKey(PROCESS_KEY).getId();
    createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, READ);
    // when
    ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();
    // then
    verifyQueryResults(query, 1);
    ProcessInstance instance = query.singleResult();
    assertNotNull(instance);
    assertEquals(processInstanceId, instance.getId());
}

53. ProcessInstanceAuthorizationTest#testSimpleQueryWithReadPermissionOnAnyProcessInstance()

View license
public void testSimpleQueryWithReadPermissionOnAnyProcessInstance() {
    // given
    String processInstanceId = startProcessInstanceByKey(PROCESS_KEY).getId();
    createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, READ);
    // when
    ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();
    // then
    verifyQueryResults(query, 1);
    ProcessInstance instance = query.singleResult();
    assertNotNull(instance);
    assertEquals(processInstanceId, instance.getId());
}

54. ProcessInstanceAuthorizationTest#testSimpleQueryWithReadInstancesPermissionOnOneTaskProcess()

View license
public void testSimpleQueryWithReadInstancesPermissionOnOneTaskProcess() {
    // given
    String processInstanceId = startProcessInstanceByKey(PROCESS_KEY).getId();
    createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, READ_INSTANCE);
    // when
    ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();
    // then
    verifyQueryResults(query, 1);
    ProcessInstance instance = query.singleResult();
    assertNotNull(instance);
    assertEquals(processInstanceId, instance.getId());
}

55. ProcessInstanceAuthorizationTest#testSimpleQueryWithReadInstancesPermissionOnAnyProcessDefinition()

View license
public void testSimpleQueryWithReadInstancesPermissionOnAnyProcessDefinition() {
    // given
    String processInstanceId = startProcessInstanceByKey(PROCESS_KEY).getId();
    createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, READ_INSTANCE);
    // when
    ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();
    // then
    verifyQueryResults(query, 1);
    ProcessInstance instance = query.singleResult();
    assertNotNull(instance);
    assertEquals(processInstanceId, instance.getId());
}

56. ProcessInstanceAuthorizationTest#testQueryWithReadPermissionOnProcessInstance()

View license
public void testQueryWithReadPermissionOnProcessInstance() {
    // given
    startProcessInstanceByKey(PROCESS_KEY);
    startProcessInstanceByKey(PROCESS_KEY);
    String processInstanceId = startProcessInstanceByKey(PROCESS_KEY).getId();
    startProcessInstanceByKey(MESSAGE_START_PROCESS_KEY);
    startProcessInstanceByKey(MESSAGE_START_PROCESS_KEY);
    startProcessInstanceByKey(MESSAGE_START_PROCESS_KEY);
    startProcessInstanceByKey(MESSAGE_START_PROCESS_KEY);
    createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, READ);
    // when
    ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();
    // then
    verifyQueryResults(query, 1);
    ProcessInstance instance = query.singleResult();
    assertNotNull(instance);
    assertEquals(processInstanceId, instance.getId());
}

57. ProcessInstanceAuthorizationTest#testSuspendProcessInstanceByIdWithUpdatePermissionOnProcessInstance()

View license
public void testSuspendProcessInstanceByIdWithUpdatePermissionOnProcessInstance() {
    // given
    String processInstanceId = startProcessInstanceByKey(PROCESS_KEY).getId();
    createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, UPDATE);
    // when
    runtimeService.suspendProcessInstanceById(processInstanceId);
    // then
    ProcessInstance instance = selectSingleProcessInstance();
    assertTrue(instance.isSuspended());
}

58. ProcessInstanceAuthorizationTest#testSuspendProcessInstanceByIdWithUpdatePermissionOnAnyProcessInstance()

View license
public void testSuspendProcessInstanceByIdWithUpdatePermissionOnAnyProcessInstance() {
    // given
    String processInstanceId = startProcessInstanceByKey(PROCESS_KEY).getId();
    createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, UPDATE);
    // when
    runtimeService.suspendProcessInstanceById(processInstanceId);
    // then
    ProcessInstance instance = selectSingleProcessInstance();
    assertTrue(instance.isSuspended());
}

59. ProcessInstanceAuthorizationTest#testSuspendProcessInstanceByIdWithUpdateInstancesPermissionOnProcessDefinition()

View license
public void testSuspendProcessInstanceByIdWithUpdateInstancesPermissionOnProcessDefinition() {
    // given
    String processInstanceId = startProcessInstanceByKey(PROCESS_KEY).getId();
    createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, UPDATE_INSTANCE);
    // when
    runtimeService.suspendProcessInstanceById(processInstanceId);
    // then
    ProcessInstance instance = selectSingleProcessInstance();
    assertTrue(instance.isSuspended());
}

60. ProcessInstanceAuthorizationTest#testSuspendProcessInstanceById()

View license
public void testSuspendProcessInstanceById() {
    // given
    String processInstanceId = startProcessInstanceByKey(PROCESS_KEY).getId();
    createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, UPDATE);
    createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, UPDATE_INSTANCE);
    // when
    runtimeService.suspendProcessInstanceById(processInstanceId);
    // then
    ProcessInstance instance = selectSingleProcessInstance();
    assertTrue(instance.isSuspended());
}

61. ProcessInstanceAuthorizationTest#testActivateProcessInstanceByIdWithUpdatePermissionOnProcessInstance()

View license
public void testActivateProcessInstanceByIdWithUpdatePermissionOnProcessInstance() {
    // given
    String processInstanceId = startProcessInstanceByKey(PROCESS_KEY).getId();
    suspendProcessInstanceById(processInstanceId);
    createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, UPDATE);
    // when
    runtimeService.activateProcessInstanceById(processInstanceId);
    // then
    ProcessInstance instance = selectSingleProcessInstance();
    assertFalse(instance.isSuspended());
}

62. ProcessInstanceAuthorizationTest#testActivateProcessInstanceByIdWithUpdatePermissionOnAnyProcessInstance()

View license
public void testActivateProcessInstanceByIdWithUpdatePermissionOnAnyProcessInstance() {
    // given
    String processInstanceId = startProcessInstanceByKey(PROCESS_KEY).getId();
    suspendProcessInstanceById(processInstanceId);
    createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, UPDATE);
    // when
    runtimeService.activateProcessInstanceById(processInstanceId);
    // then
    ProcessInstance instance = selectSingleProcessInstance();
    assertFalse(instance.isSuspended());
}

63. ProcessInstanceAuthorizationTest#testActivateProcessInstanceByIdWithUpdateInstancesPermissionOnProcessDefinition()

View license
public void testActivateProcessInstanceByIdWithUpdateInstancesPermissionOnProcessDefinition() {
    // given
    String processInstanceId = startProcessInstanceByKey(PROCESS_KEY).getId();
    suspendProcessInstanceById(processInstanceId);
    createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, UPDATE_INSTANCE);
    // when
    runtimeService.activateProcessInstanceById(processInstanceId);
    // then
    ProcessInstance instance = selectSingleProcessInstance();
    assertFalse(instance.isSuspended());
}

64. ProcessInstanceAuthorizationTest#testActivateProcessInstanceById()

View license
public void testActivateProcessInstanceById() {
    // given
    String processInstanceId = startProcessInstanceByKey(PROCESS_KEY).getId();
    suspendProcessInstanceById(processInstanceId);
    createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, UPDATE);
    createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, UPDATE_INSTANCE);
    // when
    runtimeService.activateProcessInstanceById(processInstanceId);
    // then
    ProcessInstance instance = selectSingleProcessInstance();
    assertFalse(instance.isSuspended());
}

65. ProcessInstanceAuthorizationTest#testSuspendProcessInstanceByProcessDefinitionIdWithUpdatePermissionOnProcessInstance()

View license
public void testSuspendProcessInstanceByProcessDefinitionIdWithUpdatePermissionOnProcessInstance() {
    // given
    ProcessInstance instance = startProcessInstanceByKey(PROCESS_KEY);
    String processInstanceId = instance.getId();
    String processDefinitionId = instance.getProcessDefinitionId();
    createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, UPDATE);
    try {
        // when
        runtimeService.suspendProcessInstanceByProcessDefinitionId(processDefinitionId);
        fail("Exception expected: It should not be posssible to suspend a process instance.");
    } catch (AuthorizationException e) {
        String message = e.getMessage();
        assertTextPresent(userId, message);
        assertTextPresent(UPDATE_INSTANCE.getName(), message);
        assertTextPresent(PROCESS_KEY, message);
        assertTextPresent(PROCESS_DEFINITION.resourceName(), message);
    }
}

66. ProcessInstanceAuthorizationTest#testSuspendProcessInstanceByProcessDefinitionIdWithUpdatePermissionOnAnyProcessInstance()

View license
public void testSuspendProcessInstanceByProcessDefinitionIdWithUpdatePermissionOnAnyProcessInstance() {
    // given
    ProcessInstance instance = startProcessInstanceByKey(PROCESS_KEY);
    String processDefinitionId = instance.getProcessDefinitionId();
    createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, UPDATE);
    // when
    runtimeService.suspendProcessInstanceByProcessDefinitionId(processDefinitionId);
    // then
    instance = selectSingleProcessInstance();
    assertTrue(instance.isSuspended());
}

67. ProcessInstanceAuthorizationTest#testSuspendProcessInstanceByProcessDefinitionIdWithUpdateInstancesPermissionOnProcessDefinition()

View license
public void testSuspendProcessInstanceByProcessDefinitionIdWithUpdateInstancesPermissionOnProcessDefinition() {
    // given
    ProcessInstance instance = startProcessInstanceByKey(PROCESS_KEY);
    String processDefinitionId = instance.getProcessDefinitionId();
    createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, UPDATE_INSTANCE);
    // when
    runtimeService.suspendProcessInstanceByProcessDefinitionId(processDefinitionId);
    // then
    instance = selectSingleProcessInstance();
    assertTrue(instance.isSuspended());
}

68. ProcessInstanceAuthorizationTest#testSuspendProcessInstanceByProcessDefinitionId()

View license
public void testSuspendProcessInstanceByProcessDefinitionId() {
    // given
    ProcessInstance instance = startProcessInstanceByKey(PROCESS_KEY);
    String processInstanceId = instance.getId();
    String processDefinitionId = instance.getProcessDefinitionId();
    createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, UPDATE);
    createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, UPDATE_INSTANCE);
    // when
    runtimeService.suspendProcessInstanceByProcessDefinitionId(processDefinitionId);
    // then
    instance = selectSingleProcessInstance();
    assertTrue(instance.isSuspended());
}

69. ProcessInstanceAuthorizationTest#testActivateProcessInstanceByProcessDefinitionIdWithoutAuthorization()

View license
// activate process instance by process definition id /////////////////////////////
public void testActivateProcessInstanceByProcessDefinitionIdWithoutAuthorization() {
    // given
    ProcessInstance instance = startProcessInstanceByKey(PROCESS_KEY);
    String processInstanceId = instance.getId();
    String processDefinitionId = instance.getProcessDefinitionId();
    suspendProcessInstanceById(processInstanceId);
    try {
        // when
        runtimeService.activateProcessInstanceByProcessDefinitionId(processDefinitionId);
        fail("Exception expected: It should not be posssible to suspend a process instance.");
    } catch (AuthorizationException e) {
        String message = e.getMessage();
        assertTextPresent(userId, message);
        assertTextPresent(UPDATE_INSTANCE.getName(), message);
        assertTextPresent(PROCESS_KEY, message);
        assertTextPresent(PROCESS_DEFINITION.resourceName(), message);
    }
}

70. ProcessInstanceAuthorizationTest#testActivateProcessInstanceByProcessDefinitionIdWithUpdatePermissionOnProcessInstance()

View license
public void testActivateProcessInstanceByProcessDefinitionIdWithUpdatePermissionOnProcessInstance() {
    // given
    ProcessInstance instance = startProcessInstanceByKey(PROCESS_KEY);
    String processInstanceId = instance.getId();
    String processDefinitionId = instance.getProcessDefinitionId();
    suspendProcessInstanceById(processInstanceId);
    createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, UPDATE);
    try {
        // when
        runtimeService.activateProcessInstanceByProcessDefinitionId(processDefinitionId);
        fail("Exception expected: It should not be posssible to suspend a process instance.");
    } catch (AuthorizationException e) {
        String message = e.getMessage();
        assertTextPresent(userId, message);
        assertTextPresent(UPDATE_INSTANCE.getName(), message);
        assertTextPresent(PROCESS_KEY, message);
        assertTextPresent(PROCESS_DEFINITION.resourceName(), message);
    }
}

71. ProcessInstanceAuthorizationTest#testActivateProcessInstanceByProcessDefinitionIdWithUpdatePermissionOnAnyProcessInstance()

View license
public void testActivateProcessInstanceByProcessDefinitionIdWithUpdatePermissionOnAnyProcessInstance() {
    // given
    ProcessInstance instance = startProcessInstanceByKey(PROCESS_KEY);
    String processInstanceId = instance.getId();
    String processDefinitionId = instance.getProcessDefinitionId();
    suspendProcessInstanceById(processInstanceId);
    createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, UPDATE);
    // when
    runtimeService.activateProcessInstanceByProcessDefinitionId(processDefinitionId);
    // then
    instance = selectSingleProcessInstance();
    assertFalse(instance.isSuspended());
}

72. ProcessInstanceAuthorizationTest#testActivateProcessInstanceByProcessDefinitionIdWithUpdateInstancesPermissionOnProcessDefinition()

View license
public void testActivateProcessInstanceByProcessDefinitionIdWithUpdateInstancesPermissionOnProcessDefinition() {
    // given
    ProcessInstance instance = startProcessInstanceByKey(PROCESS_KEY);
    String processInstanceId = instance.getId();
    String processDefinitionId = instance.getProcessDefinitionId();
    suspendProcessInstanceById(processInstanceId);
    createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, UPDATE_INSTANCE);
    // when
    runtimeService.activateProcessInstanceByProcessDefinitionId(processDefinitionId);
    // then
    instance = selectSingleProcessInstance();
    assertFalse(instance.isSuspended());
}

73. ProcessInstanceAuthorizationTest#testActivateProcessInstanceByProcessDefinitionId()

View license
public void testActivateProcessInstanceByProcessDefinitionId() {
    // given
    ProcessInstance instance = startProcessInstanceByKey(PROCESS_KEY);
    String processInstanceId = instance.getId();
    String processDefinitionId = instance.getProcessDefinitionId();
    suspendProcessInstanceById(processInstanceId);
    createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, UPDATE);
    createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, UPDATE_INSTANCE);
    // when
    runtimeService.activateProcessInstanceByProcessDefinitionId(processDefinitionId);
    // then
    instance = selectSingleProcessInstance();
    assertFalse(instance.isSuspended());
}

74. ProcessInstanceAuthorizationTest#testSuspendProcessInstanceByProcessDefinitionKeyWithUpdatePermissionOnProcessInstance()

View license
public void testSuspendProcessInstanceByProcessDefinitionKeyWithUpdatePermissionOnProcessInstance() {
    // given
    ProcessInstance instance = startProcessInstanceByKey(PROCESS_KEY);
    String processInstanceId = instance.getId();
    createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, UPDATE);
    try {
        // when
        runtimeService.suspendProcessInstanceByProcessDefinitionKey(PROCESS_KEY);
        fail("Exception expected: It should not be posssible to suspend a process instance.");
    } catch (AuthorizationException e) {
        String message = e.getMessage();
        assertTextPresent(userId, message);
        assertTextPresent(UPDATE_INSTANCE.getName(), message);
        assertTextPresent(PROCESS_KEY, message);
        assertTextPresent(PROCESS_DEFINITION.resourceName(), message);
    }
}

75. ProcessInstanceAuthorizationTest#testSuspendProcessInstanceByProcessDefinitionKeyWithUpdatePermissionOnAnyProcessInstance()

View license
public void testSuspendProcessInstanceByProcessDefinitionKeyWithUpdatePermissionOnAnyProcessInstance() {
    // given
    startProcessInstanceByKey(PROCESS_KEY);
    createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, UPDATE);
    // when
    runtimeService.suspendProcessInstanceByProcessDefinitionKey(PROCESS_KEY);
    // then
    ProcessInstance instance = selectSingleProcessInstance();
    assertTrue(instance.isSuspended());
}

76. ProcessInstanceAuthorizationTest#testSuspendProcessInstanceByProcessDefinitionKeyWithUpdateInstancesPermissionOnProcessDefinition()

View license
public void testSuspendProcessInstanceByProcessDefinitionKeyWithUpdateInstancesPermissionOnProcessDefinition() {
    // given
    startProcessInstanceByKey(PROCESS_KEY);
    createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, UPDATE_INSTANCE);
    // when
    runtimeService.suspendProcessInstanceByProcessDefinitionKey(PROCESS_KEY);
    // then
    ProcessInstance instance = selectSingleProcessInstance();
    assertTrue(instance.isSuspended());
}

77. ProcessInstanceAuthorizationTest#testSuspendProcessInstanceByProcessDefinitionKey()

View license
public void testSuspendProcessInstanceByProcessDefinitionKey() {
    // given
    ProcessInstance instance = startProcessInstanceByKey(PROCESS_KEY);
    String processInstanceId = instance.getId();
    createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, UPDATE);
    createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, UPDATE_INSTANCE);
    // when
    runtimeService.suspendProcessInstanceByProcessDefinitionKey(PROCESS_KEY);
    // then
    instance = selectSingleProcessInstance();
    assertTrue(instance.isSuspended());
}

78. ProcessInstanceAuthorizationTest#testActivateProcessInstanceByProcessDefinitionKeyWithoutAuthorization()

View license
// activate process instance by process definition key /////////////////////////////
public void testActivateProcessInstanceByProcessDefinitionKeyWithoutAuthorization() {
    // given
    ProcessInstance instance = startProcessInstanceByKey(PROCESS_KEY);
    String processInstanceId = instance.getId();
    suspendProcessInstanceById(processInstanceId);
    try {
        // when
        runtimeService.activateProcessInstanceByProcessDefinitionKey(PROCESS_KEY);
        fail("Exception expected: It should not be posssible to suspend a process instance.");
    } catch (AuthorizationException e) {
        String message = e.getMessage();
        assertTextPresent(userId, message);
        assertTextPresent(UPDATE_INSTANCE.getName(), message);
        assertTextPresent(PROCESS_KEY, message);
        assertTextPresent(PROCESS_DEFINITION.resourceName(), message);
    }
}

79. ProcessInstanceAuthorizationTest#testActivateProcessInstanceByProcessDefinitionKeyWithUpdatePermissionOnProcessInstance()

View license
public void testActivateProcessInstanceByProcessDefinitionKeyWithUpdatePermissionOnProcessInstance() {
    // given
    ProcessInstance instance = startProcessInstanceByKey(PROCESS_KEY);
    String processInstanceId = instance.getId();
    suspendProcessInstanceById(processInstanceId);
    createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, UPDATE);
    try {
        // when
        runtimeService.activateProcessInstanceByProcessDefinitionKey(PROCESS_KEY);
        fail("Exception expected: It should not be posssible to suspend a process instance.");
    } catch (AuthorizationException e) {
        String message = e.getMessage();
        assertTextPresent(userId, message);
        assertTextPresent(UPDATE_INSTANCE.getName(), message);
        assertTextPresent(PROCESS_KEY, message);
        assertTextPresent(PROCESS_DEFINITION.resourceName(), message);
    }
}

80. ProcessInstanceAuthorizationTest#testActivateProcessInstanceByProcessDefinitionKeyWithUpdatePermissionOnAnyProcessInstance()

View license
public void testActivateProcessInstanceByProcessDefinitionKeyWithUpdatePermissionOnAnyProcessInstance() {
    // given
    ProcessInstance instance = startProcessInstanceByKey(PROCESS_KEY);
    String processInstanceId = instance.getId();
    suspendProcessInstanceById(processInstanceId);
    createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, UPDATE);
    // when
    runtimeService.activateProcessInstanceByProcessDefinitionKey(PROCESS_KEY);
    // then
    instance = selectSingleProcessInstance();
    assertFalse(instance.isSuspended());
}

81. ProcessInstanceAuthorizationTest#testActivateProcessInstanceByProcessDefinitionKeyWithUpdateInstancesPermissionOnProcessDefinition()

View license
public void testActivateProcessInstanceByProcessDefinitionKeyWithUpdateInstancesPermissionOnProcessDefinition() {
    // given
    ProcessInstance instance = startProcessInstanceByKey(PROCESS_KEY);
    String processInstanceId = instance.getId();
    suspendProcessInstanceById(processInstanceId);
    createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, UPDATE_INSTANCE);
    // when
    runtimeService.activateProcessInstanceByProcessDefinitionKey(PROCESS_KEY);
    // then
    instance = selectSingleProcessInstance();
    assertFalse(instance.isSuspended());
}

82. ProcessInstanceAuthorizationTest#testActivateProcessInstanceByProcessDefinitionKey()

View license
public void testActivateProcessInstanceByProcessDefinitionKey() {
    // given
    ProcessInstance instance = startProcessInstanceByKey(PROCESS_KEY);
    String processInstanceId = instance.getId();
    suspendProcessInstanceById(processInstanceId);
    createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, UPDATE);
    createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, UPDATE_INSTANCE);
    // when
    runtimeService.activateProcessInstanceByProcessDefinitionKey(PROCESS_KEY);
    // then
    instance = selectSingleProcessInstance();
    assertFalse(instance.isSuspended());
}

83. CaseServiceProcessTaskTest#testReenableAnEnabledProcessTask()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneProcessTaskCase.cmmn" })
public void testReenableAnEnabledProcessTask() {
    // given
    createCaseInstance(DEFINITION_KEY);
    String processTaskId = queryCaseExecutionByActivityId(PROCESS_TASK_KEY).getId();
    ProcessInstance processInstance = queryProcessInstance();
    assertNull(processInstance);
    try {
        // when
        caseService.withCaseExecution(processTaskId).reenable();
        fail("It should not be possible to re-enable an enabled process task.");
    } catch (NotAllowedException e) {
    }
}

84. CaseServiceProcessTaskTest#testReenableADisabledProcessTask()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneProcessTaskAndOneHumanTaskCase.cmmn", "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testReenableADisabledProcessTask() {
    // given
    createCaseInstance(DEFINITION_KEY);
    String processTaskId = queryCaseExecutionByActivityId(PROCESS_TASK_KEY).getId();
    ProcessInstance processInstance = queryProcessInstance();
    assertNull(processInstance);
    caseService.withCaseExecution(processTaskId).disable();
    // when
    caseService.withCaseExecution(processTaskId).reenable();
    // then
    CaseExecution processTask = queryCaseExecutionByActivityId(PROCESS_TASK_KEY);
    assertTrue(processTask.isEnabled());
}

85. CaseServiceProcessTaskTest#testReenableAnActiveProcessTask()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneProcessTaskCase.cmmn", "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testReenableAnActiveProcessTask() {
    // given
    createCaseInstance(DEFINITION_KEY);
    String processTaskId = queryCaseExecutionByActivityId(PROCESS_TASK_KEY).getId();
    ProcessInstance processInstance = queryProcessInstance();
    assertNull(processInstance);
    caseService.withCaseExecution(processTaskId).manualStart();
    try {
        // when
        caseService.withCaseExecution(processTaskId).reenable();
        fail("It should not be possible to re-enable an active process task.");
    } catch (NotAllowedException e) {
    }
}

86. CaseServiceProcessTaskTest#testDisableAnEnabledProcessTask()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneProcessTaskAndOneHumanTaskCase.cmmn" })
public void testDisableAnEnabledProcessTask() {
    // given
    createCaseInstance(DEFINITION_KEY);
    String processTaskId = queryCaseExecutionByActivityId(PROCESS_TASK_KEY).getId();
    ProcessInstance processInstance = queryProcessInstance();
    assertNull(processInstance);
    // when
    caseService.withCaseExecution(processTaskId).disable();
    // then
    CaseExecution processTask = queryCaseExecutionByActivityId(PROCESS_TASK_KEY);
    assertTrue(processTask.isDisabled());
}

87. ExternalTaskQueryTest#testSingleResult()

View license
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testSingleResult() {
    // given
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
    // when
    ExternalTask externalTask = externalTaskService.createExternalTaskQuery().singleResult();
    // then
    assertNotNull(externalTask.getId());
    assertEquals(processInstance.getId(), externalTask.getProcessInstanceId());
    assertEquals("externalTask", externalTask.getActivityId());
    assertNotNull(externalTask.getActivityInstanceId());
    assertNotNull(externalTask.getExecutionId());
    assertEquals(processInstance.getProcessDefinitionId(), externalTask.getProcessDefinitionId());
    assertEquals("oneExternalTaskProcess", externalTask.getProcessDefinitionKey());
    assertEquals(TOPIC_NAME, externalTask.getTopicName());
    assertNull(externalTask.getWorkerId());
    assertNull(externalTask.getLockExpirationTime());
    assertFalse(externalTask.isSuspended());
}

88. ExternalTaskQueryTest#testQueryByExecutionId()

View license
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testQueryByExecutionId() {
    // given
    List<ProcessInstance> processInstances = startInstancesByKey("oneExternalTaskProcess", 3);
    ProcessInstance firstInstance = processInstances.get(0);
    ActivityInstance externalTaskActivityInstance = runtimeService.getActivityInstance(firstInstance.getId()).getActivityInstances("externalTask")[0];
    String executionId = externalTaskActivityInstance.getExecutionIds()[0];
    // when
    ExternalTask externalTask = externalTaskService.createExternalTaskQuery().executionId(executionId).singleResult();
    // then
    assertNotNull(externalTask);
    assertEquals(executionId, externalTask.getExecutionId());
}

89. ExternalTaskQueryTest#testQueryById()

View license
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testQueryById() {
    // given
    List<ProcessInstance> processInstances = startInstancesByKey("oneExternalTaskProcess", 2);
    List<ExternalTask> tasks = externalTaskService.createExternalTaskQuery().list();
    ProcessInstance firstInstance = processInstances.get(0);
    ExternalTask firstTask = tasks.get(0);
    if (!firstTask.getProcessInstanceId().equals(firstInstance.getId())) {
        firstTask = tasks.get(1);
    }
    // when
    ExternalTask resultTask = externalTaskService.createExternalTaskQuery().externalTaskId(firstTask.getId()).singleResult();
    // then
    assertEquals(firstTask.getId(), resultTask.getId());
}

90. ExternalTaskServiceTest#testFetchSuspendedTask()

View license
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testFetchSuspendedTask() {
    // given
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
    // when suspending the process instance
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    // then the external task cannot be fetched
    List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(5, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
    assertEquals(0, externalTasks.size());
    // when activating the process instance
    runtimeService.activateProcessInstanceById(processInstance.getId());
    // then the task can be fetched
    externalTasks = externalTaskService.fetchAndLock(5, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
    assertEquals(1, externalTasks.size());
}

91. ExternalTaskServiceTest#testComplete()

View license
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/twoExternalTaskProcess.bpmn20.xml")
public void testComplete() {
    // given
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("twoExternalTaskProcess");
    // when
    List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
    externalTaskService.complete(externalTasks.get(0).getId(), WORKER_ID);
    // then
    externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
    assertEquals(0, externalTasks.size());
    ActivityInstance activityInstance = runtimeService.getActivityInstance(processInstance.getId());
    assertThat(activityInstance).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("afterExternalTask").done());
}

92. ExternalTaskServiceTest#testCompleteWithVariables()

View license
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/twoExternalTaskProcess.bpmn20.xml")
public void testCompleteWithVariables() {
    // given
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("twoExternalTaskProcess");
    // when
    List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
    externalTaskService.complete(externalTasks.get(0).getId(), WORKER_ID, Variables.createVariables().putValue("var", 42));
    // then
    ActivityInstance activityInstance = runtimeService.getActivityInstance(processInstance.getId());
    assertThat(activityInstance).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("afterExternalTask").done());
    assertEquals(42, runtimeService.getVariable(processInstance.getId(), "var"));
}

93. ExternalTaskServiceTest#testCompleteLockExpiredTask()

View license
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testCompleteLockExpiredTask() {
    // given
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
    // when
    List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
    // and the lock expires without the task being reclaimed
    ClockUtil.setCurrentTime(new DateTime(ClockUtil.getCurrentTime()).plus(LOCK_TIME * 2).toDate());
    // then the task can successfully be completed
    externalTaskService.complete(externalTasks.get(0).getId(), WORKER_ID);
    externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
    assertEquals(0, externalTasks.size());
    assertProcessEnded(processInstance.getId());
}

94. ExternalTaskServiceTest#testDeleteProcessInstance()

View license
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testDeleteProcessInstance() {
    // given
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
    // when
    runtimeService.deleteProcessInstance(processInstance.getId(), null);
    // then
    assertEquals(0, externalTaskService.fetchAndLock(5, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute().size());
    assertProcessEnded(processInstance.getId());
}

95. ExternalTaskServiceTest#testHandleFailureAndDeleteProcessInstance()

View license
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testHandleFailureAndDeleteProcessInstance() {
    // given a failed external task with incident
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
    List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(5, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
    LockedExternalTask task = tasks.get(0);
    externalTaskService.handleFailure(task.getId(), WORKER_ID, "someError", 0, LOCK_TIME);
    // when
    runtimeService.deleteProcessInstance(processInstance.getId(), null);
    // then
    assertProcessEnded(processInstance.getId());
}

96. ExternalTaskServiceTest#testHandleBpmnErrorWithoutDefinedBoundary()

View license
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testHandleBpmnErrorWithoutDefinedBoundary() {
    // given
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
    //when
    List<LockedExternalTask> externalTasks = helperHandleBpmnError(1, WORKER_ID, TOPIC_NAME, LOCK_TIME, "ERROR-OCCURED");
    //then
    assertEquals(0, externalTasks.size());
    assertEquals(0, externalTaskService.createExternalTaskQuery().count());
    Task afterBpmnError = taskService.createTaskQuery().singleResult();
    assertNull(afterBpmnError);
    assertProcessEnded(processInstance.getId());
}

97. ExternalTaskServiceTest#testHandleBpmnErrorSuspendedTask()

View license
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testHandleBpmnErrorSuspendedTask() {
    // given
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
    List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(5, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
    LockedExternalTask task = externalTasks.get(0);
    // when suspending the process instance
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    // then the external task cannot be completed
    try {
        externalTaskService.handleBpmnError(task.getId(), WORKER_ID, "ERROR-OCCURED");
        fail("expected exception");
    } catch (ProcessEngineException e) {
        assertTextPresent("ExternalTask with id '" + task.getId() + "' is suspended", e.getMessage());
    }
}

98. ExternalTaskSupportTest#testExternalTaskSupport()

View license
@Test
public void testExternalTaskSupport() {
    // given
    ProcessDefinition processDefinition = rule.getRepositoryService().createProcessDefinitionQuery().singleResult();
    // when
    ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(processDefinition.getId());
    // then
    List<LockedExternalTask> externalTasks = rule.getExternalTaskService().fetchAndLock(1, "aWorker").topic("externalTaskTopic", 5000L).execute();
    Assert.assertEquals(1, externalTasks.size());
    Assert.assertEquals(processInstance.getId(), externalTasks.get(0).getProcessInstanceId());
    // and it is possible to complete the external task successfully and end the process instance
    rule.getExternalTaskService().complete(externalTasks.get(0).getId(), "aWorker");
    Assert.assertEquals(0L, rule.getRuntimeService().createProcessInstanceQuery().count());
}

99. FilterTaskQueryTest#testInitializeFormKeysEnabled()

View license
@Deployment(resources = { "org/camunda/bpm/engine/test/api/task/oneTaskWithFormKeyProcess.bpmn20.xml" })
public void testInitializeFormKeysEnabled() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess");
    TaskQuery query = taskService.createTaskQuery().processInstanceId(processInstance.getId());
    saveQuery(query);
    Task task = (Task) filterService.list(filter.getId()).get(0);
    assertEquals("exampleFormKey", task.getFormKey());
    task = filterService.singleResult(filter.getId());
    assertEquals("exampleFormKey", task.getFormKey());
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");
}

100. FormDataTest#testMissingFormVariables()

View license
@Deployment
public void testMissingFormVariables() {
    // given process definition with defined form varaibles
    // when start process instance with no variables
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("date-form-property-test");
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    // then taskFormData contains form variables with null as values
    TaskFormData taskFormData = formService.getTaskFormData(task.getId());
    assertNotNull(taskFormData);
    assertEquals(5, taskFormData.getFormFields().size());
    for (FormField field : taskFormData.getFormFields()) {
        assertNotNull(field);
        assertNull(field.getValue().getValue());
    }
}