public void testModifyNullProcessInstance() { try { Batch modificationBatch = runtimeService .createProcessInstanceModification(null) .startBeforeActivity("someActivity") .executeAsync(); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); fail("should not succeed"); } catch (NotValidException e) { assertTextPresent("processInstanceId is null", e.getMessage()); } }
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS) public void testStartAfterActivityAmbiguousTransitions() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exclusiveGateway"); String processInstanceId = processInstance.getId(); try { Batch modificationBatch = runtimeService .createProcessInstanceModification(processInstanceId) .startAfterActivity("fork") .executeAsync(); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); fail("should not suceed since 'fork' has more than one outgoing sequence flow"); } catch (ProcessEngineException e) { // happy path assertTextPresent("activity has more than one outgoing sequence flow", e.getMessage()); } }
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS) public void testStartAfterActivityNoOutgoingTransitions() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exclusiveGateway"); String processInstanceId = processInstance.getId(); try { Batch modificationBatch = runtimeService .createProcessInstanceModification(processInstanceId) .startAfterActivity("theEnd") .executeAsync(); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); fail("should not suceed since 'theEnd' has no outgoing sequence flow"); } catch (ProcessEngineException e) { // happy path assertTextPresent("activity has no outgoing sequence flow to take", e.getMessage()); } }
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS) public void testStartBeforeNonExistingActivity() { // given ProcessInstance instance = runtimeService.startProcessInstanceByKey("exclusiveGateway"); try { // when Batch modificationBatch = runtimeService.createProcessInstanceModification(instance.getId()).startBeforeActivity("someNonExistingActivity").executeAsync(); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); fail("should not succeed"); } catch (NotValidException e) { // then assertTextPresentIgnoreCase("element 'someNonExistingActivity' does not exist in process ", e.getMessage()); } }
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS) public void testStartTransitionInvalidTransitionId() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exclusiveGateway"); String processInstanceId = processInstance.getId(); try { Batch modificationBatch = runtimeService.createProcessInstanceModification(processInstanceId).startTransition("invalidFlowId").executeAsync(); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); fail("should not suceed"); } catch (ProcessEngineException e) { // happy path assertTextPresent("Cannot perform instruction: " + "Start transition 'invalidFlowId'; " + "Element 'invalidFlowId' does not exist in process '" + processInstance.getProcessDefinitionId() + "'", e.getMessage()); } }
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS) public void testStartAfterNonExistingActivity() { // given ProcessInstance instance = runtimeService.startProcessInstanceByKey("exclusiveGateway"); try { // when Batch modificationBatch = runtimeService .createProcessInstanceModification(instance.getId()) .startAfterActivity("someNonExistingActivity") .executeAsync(); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); fail("should not succeed"); } catch (NotValidException e) { // then assertTextPresentIgnoreCase("Cannot perform instruction: " + "Start after activity 'someNonExistingActivity'; " + "Activity 'someNonExistingActivity' does not exist: activity is null", e.getMessage()); } }
@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 = 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 = TRANSITION_LISTENER_PROCESS) public void testStartTransitionListenerInvocation() { RecorderExecutionListener.clear(); ProcessInstance instance = runtimeService.startProcessInstanceByKey("transitionListenerProcess", Variables.createVariables().putValue("listener", new RecorderExecutionListener())); Batch modificationBatch = runtimeService .createProcessInstanceModification(instance.getId()) .startTransition("flow2") .executeAsync(); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); // transition listener should have been invoked List<RecordedEvent> events = RecorderExecutionListener.getRecordedEvents(); assertEquals(1, events.size()); RecordedEvent event = events.get(0); assertEquals("flow2", event.getTransitionId()); RecorderExecutionListener.clear(); ActivityInstance updatedTree = runtimeService.getActivityInstance(instance.getId()); assertNotNull(updatedTree); assertEquals(instance.getId(), updatedTree.getProcessInstanceId()); assertThat(updatedTree).hasStructure(describeActivityInstanceTree(instance.getProcessDefinitionId()).activity("task1").activity("task2").done()); ExecutionTree executionTree = ExecutionTree.forExecution(instance.getId(), processEngine); assertThat(executionTree) .matches(describeExecutionTree(null).scope().child("task1").concurrent().noScope().up().child("task2").concurrent().noScope().done()); completeTasksInOrder("task1", "task2", "task2"); assertProcessEnded(instance.getId()); }
@Deployment(resources = TRANSITION_LISTENER_PROCESS) public void testStartAfterActivityListenerInvocation() { RecorderExecutionListener.clear(); ProcessInstance instance = runtimeService.startProcessInstanceByKey("transitionListenerProcess", Variables.createVariables().putValue("listener", new RecorderExecutionListener())); Batch modificationBatch = runtimeService .createProcessInstanceModification(instance.getId()) .startTransition("flow2") .executeAsync(); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); // transition listener should have been invoked List<RecordedEvent> events = RecorderExecutionListener.getRecordedEvents(); assertEquals(1, events.size()); RecordedEvent event = events.get(0); assertEquals("flow2", event.getTransitionId()); RecorderExecutionListener.clear(); ActivityInstance updatedTree = runtimeService.getActivityInstance(instance.getId()); assertNotNull(updatedTree); assertEquals(instance.getId(), updatedTree.getProcessInstanceId()); assertThat(updatedTree).hasStructure(describeActivityInstanceTree(instance.getProcessDefinitionId()).activity("task1").activity("task2").done()); ExecutionTree executionTree = ExecutionTree.forExecution(instance.getId(), processEngine); assertThat(executionTree) .matches(describeExecutionTree(null).scope().child("task1").concurrent().noScope().up().child("task2").concurrent().noScope().done()); completeTasksInOrder("task1", "task2", "task2"); assertProcessEnded(instance.getId()); }
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS) public void testCancellationAndStartBefore() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exclusiveGateway"); String processInstanceId = processInstance.getId(); ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId()); Batch modificationBatch = runtimeService.createProcessInstanceModification(processInstance.getId()) .cancelActivityInstance(getInstanceIdForActivity(tree, "task1")) .startBeforeActivity("task2") .executeAsync(); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); ActivityInstance activityInstanceTree = runtimeService.getActivityInstance(processInstanceId); assertNotNull(activityInstanceTree); assertEquals(processInstanceId, activityInstanceTree.getProcessInstanceId()); assertThat(activityInstanceTree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("task2").done()); ExecutionTree executionTree = ExecutionTree.forExecution(processInstanceId, processEngine); assertThat(executionTree).matches(describeExecutionTree("task2").scope().done()); completeTasksInOrder("task2"); assertProcessEnded(processInstanceId); }
/** * CAM-3718 */ @Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS) public void testEndProcessInstanceIntermediately() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exclusiveGateway"); String processInstanceId = processInstance.getId(); ActivityInstance tree = runtimeService.getActivityInstance(processInstanceId); Batch modificationBatch = runtimeService.createProcessInstanceModification(processInstance.getId()) .cancelActivityInstance(getInstanceIdForActivity(tree, "task1")) .startAfterActivity("task1") .startBeforeActivity("task1") .executeAsync(); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); 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); }
.createProcessInstanceModification(processInstance.getId()) .startAfterActivity("theTask") .executeAsync(); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); Batch modificationBatch2 = runtimeService.createProcessInstanceModification(processInstance.getId()).startAfterActivity("theStart").executeAsync(); assertNotNull(modificationBatch2); executeSeedAndBatchJobs(modificationBatch2);
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS) public void testStartBefore() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exclusiveGateway"); String processInstanceId = processInstance.getId(); Batch modificationBatch = runtimeService .createProcessInstanceModification(processInstance.getId()) .startBeforeActivity("task2") .executeAsync(); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); ActivityInstance updatedTree = runtimeService.getActivityInstance(processInstanceId); assertNotNull(updatedTree); assertEquals(processInstanceId, updatedTree.getProcessInstanceId()); assertThat(updatedTree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("task1").activity("task2").done()); ExecutionTree executionTree = ExecutionTree.forExecution(processInstanceId, processEngine); assertThat(executionTree) .matches(describeExecutionTree(null).scope().child("task1").concurrent().noScope().up().child("task2").concurrent().noScope().done()); assertEquals(2, taskService.createTaskQuery().count()); // complete the process completeTasksInOrder("task1", "task2"); assertProcessEnded(processInstanceId); }
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS) public void testStartAfter() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exclusiveGateway"); String processInstanceId = processInstance.getId(); Batch modificationBatch = runtimeService .createProcessInstanceModification(processInstance.getId()) .startAfterActivity("theStart") .executeAsync(); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); ActivityInstance updatedTree = runtimeService.getActivityInstance(processInstanceId); assertNotNull(updatedTree); assertEquals(processInstanceId, updatedTree.getProcessInstanceId()); assertThat(updatedTree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("task1").activity("task1").done()); ExecutionTree executionTree = ExecutionTree.forExecution(processInstanceId, processEngine); assertThat(executionTree) .matches(describeExecutionTree(null).scope().child("task1").concurrent().noScope().up().child("task1").concurrent().noScope().done()); assertEquals(2, taskService.createTaskQuery().count()); // complete the process completeTasksInOrder("task1", "task1"); assertProcessEnded(processInstanceId); }
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS) public void testStartTransition() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exclusiveGateway"); String processInstanceId = processInstance.getId(); Batch modificationBatch = runtimeService .createProcessInstanceModification(processInstance.getId()) .startTransition("flow4") .executeAsync(); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); ActivityInstance updatedTree = runtimeService.getActivityInstance(processInstanceId); assertNotNull(updatedTree); assertEquals(processInstanceId, updatedTree.getProcessInstanceId()); assertThat(updatedTree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("task1").activity("task2").done()); ExecutionTree executionTree = ExecutionTree.forExecution(processInstanceId, processEngine); assertThat(executionTree) .matches(describeExecutionTree(null).scope().child("task1").concurrent().noScope().up().child("task2").concurrent().noScope().done()); assertEquals(2, taskService.createTaskQuery().count()); // complete the process completeTasksInOrder("task1", "task2"); assertProcessEnded(processInstanceId); }
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS) public void testStartBeforeWithAncestorInstanceId() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exclusiveGateway"); String processInstanceId = processInstance.getId(); ActivityInstance tree = runtimeService.getActivityInstance(processInstanceId); Batch modificationBatch = runtimeService .createProcessInstanceModification(processInstance.getId()) .startBeforeActivity("task2", tree.getId()) .executeAsync(); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); ActivityInstance updatedTree = runtimeService.getActivityInstance(processInstanceId); assertNotNull(updatedTree); assertEquals(processInstanceId, updatedTree.getProcessInstanceId()); assertThat(updatedTree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("task1").activity("task2").done()); ExecutionTree executionTree = ExecutionTree.forExecution(processInstanceId, processEngine); assertThat(executionTree) .matches(describeExecutionTree(null).scope().child("task1").concurrent().noScope().up().child("task2").concurrent().noScope().done()); assertEquals(2, taskService.createTaskQuery().count()); // complete the process completeTasksInOrder("task1", "task2"); assertProcessEnded(processInstanceId); }
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS) public void testStartAfterWithAncestorInstanceId() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exclusiveGateway"); String processInstanceId = processInstance.getId(); ActivityInstance tree = runtimeService.getActivityInstance(processInstanceId); Batch modificationBatch = runtimeService .createProcessInstanceModification(processInstance.getId()) .startAfterActivity("theStart", tree.getId()) .executeAsync(); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); ActivityInstance updatedTree = runtimeService.getActivityInstance(processInstanceId); assertNotNull(updatedTree); assertEquals(processInstanceId, updatedTree.getProcessInstanceId()); assertThat(updatedTree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("task1").activity("task1").done()); ExecutionTree executionTree = ExecutionTree.forExecution(processInstanceId, processEngine); assertThat(executionTree) .matches(describeExecutionTree(null).scope().child("task1").concurrent().noScope().up().child("task1").concurrent().noScope().done()); assertEquals(2, taskService.createTaskQuery().count()); // complete the process completeTasksInOrder("task1", "task1"); assertProcessEnded(processInstanceId); }
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS) public void testStartTransitionWithAncestorInstanceId() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exclusiveGateway"); String processInstanceId = processInstance.getId(); ActivityInstance tree = runtimeService.getActivityInstance(processInstanceId); Batch modificationBatch = runtimeService .createProcessInstanceModification(processInstance.getId()) .startTransition("flow4", tree.getId()) .executeAsync(); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); ActivityInstance updatedTree = runtimeService.getActivityInstance(processInstanceId); assertNotNull(updatedTree); assertEquals(processInstanceId, updatedTree.getProcessInstanceId()); assertThat(updatedTree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("task1").activity("task2").done()); ExecutionTree executionTree = ExecutionTree.forExecution(processInstanceId, processEngine); assertThat(executionTree) .matches(describeExecutionTree(null).scope().child("task1").concurrent().noScope().up().child("task2").concurrent().noScope().done()); assertEquals(2, taskService.createTaskQuery().count()); // complete the process completeTasksInOrder("task1", "task2"); assertProcessEnded(processInstanceId); }
@Deployment(resources = ONE_SCOPE_TASK_PROCESS) public void testScopeTaskStartBefore() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); String processInstanceId = processInstance.getId(); Batch modificationBatch = runtimeService .createProcessInstanceModification(processInstance.getId()) .startBeforeActivity("theTask") .executeAsync(); assertNotNull(modificationBatch); executeSeedAndBatchJobs(modificationBatch); ActivityInstance updatedTree = runtimeService.getActivityInstance(processInstanceId); assertNotNull(updatedTree); assertEquals(processInstanceId, updatedTree.getProcessInstanceId()); assertThat(updatedTree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("theTask").activity("theTask").done()); ExecutionTree executionTree = ExecutionTree.forExecution(processInstanceId, processEngine); assertThat(executionTree).matches(describeExecutionTree(null).scope().child(null).concurrent().noScope().child("theTask").scope().up().up().child(null) .concurrent().noScope().child("theTask").scope().done()); assertEquals(2, taskService.createTaskQuery().count()); completeTasksInOrder("theTask", "theTask"); assertProcessEnded(processInstanceId); }