@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); }
@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); }
@Override public Void call() throws Exception { runtimeService.createProcessInstanceModification(processInstance.getProcessInstanceId()).startTransition("flow2") .execute(); return null; }
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS) public void testStartTransitionInvalidTransitionId() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exclusiveGateway"); String processInstanceId = processInstance.getId(); try { runtimeService.createProcessInstanceModification(processInstanceId).startTransition("invalidFlowId").execute(); 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()); } }
@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); }
runtimeService.createProcessInstanceModification(processInstance.getId()).startTransition("flow5", "noValidActivityInstanceId").execute(); fail(); } catch (NotValidException e) { runtimeService.createProcessInstanceModification(processInstance.getId()).startTransition("flow5", null).execute(); fail(); } catch (NotValidException e) { runtimeService.createProcessInstanceModification(processInstance.getId()).startTransition("flow5", subProcessTaskId).execute(); fail("should not succeed because subProcessTask is a child of subProcess"); } catch (NotValidException e) {
@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 = TRANSITION_LISTENER_PROCESS) public void testStartAfterActivityListenerInvocation() { RecorderExecutionListener.clear(); ProcessInstance instance = runtimeService.startProcessInstanceByKey("transitionListenerProcess", Variables.createVariables().putValue("listener", new RecorderExecutionListener())); runtimeService.createProcessInstanceModification(instance.getId()).startTransition("flow2").execute(); // 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 testStartTransitionListenerInvocation() { RecorderExecutionListener.clear(); ProcessInstance instance = runtimeService.startProcessInstanceByKey("transitionListenerProcess", Variables.createVariables().putValue("listener", new RecorderExecutionListener())); runtimeService.createProcessInstanceModification(instance.getId()).startTransition("flow2").execute(); // 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 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 testStartTransition() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exclusiveGateway"); String processInstanceId = processInstance.getId(); runtimeService.createProcessInstanceModification(processInstance.getId()).startTransition("flow4").execute(); 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 testStartTransitionCase2() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exclusiveGateway"); String processInstanceId = processInstance.getId(); runtimeService.createProcessInstanceModification(processInstance.getId()).startTransition("flow2").execute(); 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); runtimeService.createProcessInstanceModification(processInstance.getId()).startTransition("flow4", tree.getId()).execute(); 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 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 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); }
runtimeService.createProcessInstanceModification(processInstance.getId()).startTransition("flow5").execute(); runtimeService.createProcessInstanceModification(processInstanceId).startTransition("flow5", randomSubProcessInstance.getId()).execute();
.startTransition("flow2") .setVariable("procInstVar", "procInstValue") .setVariableLocal("localVar", "localValue")
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS) public void testStartTransitionInvalidTransitionId() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exclusiveGateway"); String processInstanceId = processInstance.getId(); try { runtimeService.createProcessInstanceModification(processInstanceId).startTransition("invalidFlowId").execute(); 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 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()); } }