@Deployment(resources = PARALLEL_GATEWAY_PROCESS) public void testCancellationThatEndsProcessInstance() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("parallelGateway"); ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId()); runtimeService.createProcessInstanceModification(processInstance.getId()) .cancelActivityInstance(getInstanceIdForActivity(tree, "task1")) .cancelActivityInstance(getInstanceIdForActivity(tree, "task2")) .execute(); assertProcessEnded(processInstance.getId()); }
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS) public void testCancelNonExistingTranisitionInstance() { // given ProcessInstance instance = runtimeService.startProcessInstanceByKey("exclusiveGateway"); // when - then throw exception try { runtimeService.createProcessInstanceModification(instance.getId()).cancelTransitionInstance("nonExistingActivityInstance").execute(); fail("should not succeed"); } catch (NotValidException e) { assertTextPresent("Cannot perform instruction: Cancel transition instance 'nonExistingActivityInstance'; " + "Transition instance 'nonExistingActivityInstance' does not exist", e.getMessage()); } }
public void execute(ProcessEngine engine, String scenarioName) { String processDefinitionId = engine.getRepositoryService().createProcessDefinitionQuery() .processDefinitionKey("oneTaskProcessInstanceModification_710") .singleResult() .getId(); String processInstanceId = engine.getRuntimeService() .startProcessInstanceById(processDefinitionId, "ProcessInstanceModificationScenario").getId(); engine.getRuntimeService().createModification(processDefinitionId) .processInstanceIds(processInstanceId) .startBeforeActivity("userTask2") .execute(); ActivityInstance tree = engine.getRuntimeService().getActivityInstance(processInstanceId); engine.getRuntimeService().createProcessInstanceModification(processInstanceId) .cancelActivityInstance(tree.getActivityInstances("userTask1")[0].getId()) .cancelTransitionInstance(tree.getTransitionInstances("userTask2")[0].getId()) .executeAsync(); } };
@Override public void applyTo(ProcessInstanceModificationBuilder builder, ProcessEngine engine, ObjectMapper mapper) { validateParameters(); if (activityId != null) { builder.cancelAllForActivity(activityId); } else if (activityInstanceId != null) { builder.cancelActivityInstance(activityInstanceId); } else if (transitionInstanceId != null) { builder.cancelTransitionInstance(transitionInstanceId); } }
@Deployment(resources = PROCESS_PATH) public void testModifyProcessInstance() { // given String id = runtimeService.startProcessInstanceByKey(PROCESS_KEY).getId(); // when runtimeService .createProcessInstanceModification(id) .cancelAllForActivity("theTask") .execute(); // then verifyNoUserOperationLogged(); }
@Deployment(resources = PARALLEL_GATEWAY_PROCESS) public void testCancellationThatEndsProcessInstance() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("parallelGateway"); ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId()); Batch modificationBatch = runtimeService.createProcessInstanceModification(processInstance.getId()) .cancelActivityInstance(getInstanceIdForActivity(tree, "task1")) .cancelActivityInstance(getInstanceIdForActivity(tree, "task2")) .executeAsync(); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); assertProcessEnded(processInstance.getId()); }
/** * CAM-4090 */ @Deployment(resources = NESTED_PARALLEL_ASYNC_BEFORE_SCOPE_TASK_PROCESS) public void testRepeatedStartAndCancellationForTransitionInstance() { // given there is one transition instance in a scope ProcessInstance instance = runtimeService.createProcessInstanceByKey("nestedConcurrentTasksProcess") .startBeforeActivity("innerTask1") .execute(); ActivityInstance tree = runtimeService.getActivityInstance(instance.getId()); TransitionInstance transitionInstance = tree.getTransitionInstances("innerTask1")[0]; // when I start an activity in the same scope // and cancel the first transition instance runtimeService.createProcessInstanceModification(instance.getId()) .startBeforeActivity("innerTask2") // expand tree .cancelAllForActivity("innerTask2") // compact tree .startBeforeActivity("innerTask2") // expand tree .cancelAllForActivity("innerTask2") // compact tree .startBeforeActivity("innerTask2") // expand tree .cancelAllForActivity("innerTask2") // compact tree .cancelTransitionInstance(transitionInstance.getId()) .execute(); // then the process has ended assertProcessEnded(instance.getId()); }
@Override public void applyTo(ProcessInstanceModificationBuilder builder, ProcessEngine engine, ObjectMapper mapper) { checkValidity(); ProcessInstanceModificationInstantiationBuilder activityBuilder = null; if (ancestorActivityInstanceId != null) { activityBuilder = builder.startTransition(transitionId, ancestorActivityInstanceId); } else { activityBuilder = builder.startTransition(transitionId); } applyVariables(activityBuilder, engine, mapper); }
@Deployment(resources = TASK_LISTENER_PROCESS) public void testSkipTaskListenerInvocation() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("taskListenerProcess", "brum", Collections.<String, Object> singletonMap("listener", new RecorderTaskListener())); String processInstanceId = processInstance.getId(); RecorderTaskListener.clear(); // when I start an activity with "skip listeners" setting Batch modificationBatch = runtimeService .createProcessInstanceModification(processInstanceId) .startBeforeActivity("task") .executeAsync(true, false); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); // then no listeners are invoked assertTrue(RecorderTaskListener.getRecordedEvents().isEmpty()); // when I cancel an activity with "skip listeners" setting ActivityInstance activityInstanceTree = runtimeService.getActivityInstance(processInstanceId); Batch batch = runtimeService .createProcessInstanceModification(processInstance.getId()) .cancelActivityInstance(getChildInstanceForActivity(activityInstanceTree, "task").getId()) .executeAsync(true, false); assertNotNull(batch); executeSeedAndBatchJobs(batch); // then no listeners are invoked assertTrue(RecorderTaskListener.getRecordedEvents().isEmpty()); }
@Deployment(resources = ONE_TASK_PROCESS) public void testProcessInstanceVariablesPreservedOnIntermediateCancellation() { ProcessInstance processInstance = runtimeService .startProcessInstanceByKey("oneTaskProcess", Variables.createVariables().putValue("var", "value")); // when I execute cancellation and then start, such that the intermediate state of the process instance // has no activities ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId()); runtimeService.createProcessInstanceModification(processInstance.getId()) .cancelActivityInstance(getInstanceIdForActivity(tree, "theTask")) .startBeforeActivity("theTask") .execute(); // then the process instance variables remain Object variable = runtimeService.getVariable(processInstance.getId(), "var"); assertNotNull(variable); assertEquals("value", variable); }
@Override public void applyTo(ProcessInstanceModificationBuilder builder, ProcessEngine engine, ObjectMapper mapper) { checkValidity(); ProcessInstanceModificationInstantiationBuilder activityBuilder = null; if (ancestorActivityInstanceId != null) { activityBuilder = builder.startBeforeActivity(activityId, ancestorActivityInstanceId); } else { activityBuilder = builder.startBeforeActivity(activityId); } applyVariables(activityBuilder, engine, mapper); }
@Deployment(resources = IO_MAPPING_PROCESS) public void testSkipIoMappings() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("ioMappingProcess"); // when I start task2 Batch modificationBatch = runtimeService .createProcessInstanceModification(processInstance.getId()) .startBeforeActivity("task2") .executeAsync(false, true); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); // then the input mapping should not have executed Execution task2Execution = runtimeService.createExecutionQuery().activityId("task2").singleResult(); assertNotNull(task2Execution); assertNull(runtimeService.getVariable(task2Execution.getId(), "inputMappingExecuted")); // when I cancel task2 Batch modificationBatch2 = runtimeService.createProcessInstanceModification(processInstance.getId()).cancelAllForActivity("task2").executeAsync(false, true); assertNotNull(modificationBatch2); executeSeedAndBatchJobs(modificationBatch2); // then the output mapping should not have executed assertNull(runtimeService.getVariable(processInstance.getId(), "outputMappingExecuted")); }
@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()); }
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS) public void testCancelNonExistingTranisitionInstance() { // given ProcessInstance instance = runtimeService.startProcessInstanceByKey("exclusiveGateway"); // when - then throw exception try { Batch modificationBatch = runtimeService .createProcessInstanceModification(instance.getId()) .cancelTransitionInstance("nonExistingActivityInstance") .executeAsync(); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); fail("should not succeed"); } catch (NotValidException e) { assertTextPresent("Cannot perform instruction: Cancel transition instance 'nonExistingActivityInstance'; " + "Transition instance 'nonExistingActivityInstance' does not exist", e.getMessage()); } }
@Override public void applyTo(ProcessInstanceModificationBuilder builder, ProcessEngine engine, ObjectMapper mapper) { checkValidity(); ProcessInstanceModificationInstantiationBuilder activityBuilder = null; if (ancestorActivityInstanceId != null) { activityBuilder = builder.startAfterActivity(activityId, ancestorActivityInstanceId); } else { activityBuilder = builder.startAfterActivity(activityId); } applyVariables(activityBuilder, engine, mapper); }
@Deployment(resources = { CALL_ACTIVITY_PARENT_PROCESS, CALL_ACTIVITY_CHILD_PROCESS }) public void testCancelCallActivityInstance() { // given ProcessInstance parentprocess = runtimeService.startProcessInstanceByKey("parentprocess"); ProcessInstance subProcess = runtimeService.createProcessInstanceQuery().processDefinitionKey("subprocess").singleResult(); ActivityInstance subProcessActivityInst = runtimeService.getActivityInstance(subProcess.getId()); // when Batch modificationBatch = runtimeService.createProcessInstanceModification(subProcess.getId()) .startBeforeActivity("childEnd", subProcess.getId()) .cancelActivityInstance(getInstanceIdForActivity(subProcessActivityInst, "innerTask")) .executeAsync(); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); // then assertProcessEnded(parentprocess.getId()); }
.cancelTransitionInstance(getChildTransitionInstanceForTargetActivity(tree, "theTask").getId()) .startBeforeActivity("theTask") .execute();
@Deployment(resources = TRANSACTION_WITH_COMPENSATION_PROCESS) public void testStartCompensationBoundary() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess"); try { runtimeService.createProcessInstanceModification(processInstance.getId()).startBeforeActivity("compensateBoundaryEvent").execute(); fail("should not succeed"); } catch (ProcessEngineException e) { assertTextPresent("compensation boundary event", e.getMessage()); } try { runtimeService.createProcessInstanceModification(processInstance.getId()).startAfterActivity("compensateBoundaryEvent").execute(); fail("should not succeed"); } catch (ProcessEngineException e) { assertTextPresent("no outgoing sequence flow", e.getMessage()); } }
/** * CAM-3718 */ @Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS) public void testEndProcessInstanceIntermediately() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exclusiveGateway"); String processInstanceId = processInstance.getId(); ActivityInstance tree = runtimeService.getActivityInstance(processInstanceId); runtimeService.createProcessInstanceModification(processInstance.getId()).cancelActivityInstance(getInstanceIdForActivity(tree, "task1")) .startAfterActivity("task1").startBeforeActivity("task1").execute(); ActivityInstance updatedTree = runtimeService.getActivityInstance(processInstanceId); assertThat(updatedTree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("task1").done()); ExecutionTree executionTree = ExecutionTree.forExecution(processInstanceId, processEngine); assertThat(executionTree).matches(describeExecutionTree("task1").scope().done()); assertEquals(1, taskService.createTaskQuery().count()); // complete the process completeTasksInOrder("task1"); assertProcessEnded(processInstanceId); }
@Deployment(resources = CANCEL_AND_RESTART) public void testProcessInstanceModificationInEventSubProcessCancellationAndRestart() { // given ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("ProcessWithEventSubProcess"); // assume Task task = taskService.createTaskQuery() .processInstanceId(processInstance.getId()) .taskDefinitionKey("UserTaskEventSubProcess") .singleResult(); assertNotNull(task); // when runtimeService.createProcessInstanceModification(processInstance.getId()) .cancelAllForActivity("UserTaskEventSubProcess") .startAfterActivity("UserTaskEventSubProcess") .execute(); assertNull(runtimeService.createProcessInstanceQuery().singleResult()); }