@Before public void setUpRuntimeData() { runtimeServiceMock = mock(RuntimeService.class); when(processEngine.getRuntimeService()).thenReturn(runtimeServiceMock); historyServiceMock = mock(HistoryService.class); when(processEngine.getHistoryService()).thenReturn(historyServiceMock); builderMock = mock(RestartProcessInstanceBuilder.class); when(builderMock.startAfterActivity(anyString())).thenReturn(builderMock); when(builderMock.startBeforeActivity(anyString())).thenReturn(builderMock); when(builderMock.startTransition(anyString())).thenReturn(builderMock); when(builderMock.processInstanceIds(anyListOf(String.class))).thenReturn(builderMock); when(builderMock.historicProcessInstanceQuery(any(HistoricProcessInstanceQuery.class))).thenReturn(builderMock); when(builderMock.skipCustomListeners()).thenReturn(builderMock); when(builderMock.skipIoMappings()).thenReturn(builderMock); when(builderMock.initialSetOfVariables()).thenReturn(builderMock); when(builderMock.withoutBusinessKey()).thenReturn(builderMock); Batch batchMock = createMockBatch(); when(builderMock.executeAsync()).thenReturn(batchMock); when(runtimeServiceMock.restartProcessInstances(anyString())).thenReturn(builderMock); }
@Test public void testRestartProcessInstanceWithoutBusinessKey() { Map<String, Object> json = new HashMap<String, Object>(); List<Map<String, Object>> instructions = new ArrayList<Map<String, Object>>(); json.put("processInstanceIds", Arrays.asList("processInstance1", "processInstance2")); instructions.add(ModificationInstructionBuilder.startBefore().activityId("activityId").getJson()); json.put("instructions", instructions); json.put("withoutBusinessKey", true); given() .pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID) .contentType(ContentType.JSON) .body(json) .then() .expect() .statusCode(Status.NO_CONTENT.getStatusCode()) .when() .post(RESTART_PROCESS_INSTANCE_URL); verify(builderMock).processInstanceIds(Arrays.asList("processInstance1", "processInstance2")); verify(builderMock).withoutBusinessKey(); verify(builderMock).startBeforeActivity("activityId"); verify(builderMock).execute(); }
public void execute(ProcessEngine engine, String scenarioName) { List<String> processInstanceIds = new ArrayList<>(); String processDefinitionId = null; for (int i = 0; i < 10; i++) { ProcessInstance processInstance = engine.getRuntimeService() .startProcessInstanceByKey("oneTaskProcessRestart_710", "RestartProcessInstanceBatchScenario"); processDefinitionId = processInstance.getProcessDefinitionId(); processInstanceIds.add(processInstance.getId()); String taskId = engine.getTaskService().createTaskQuery() .processDefinitionKey("oneTaskProcessRestart_710") .processInstanceBusinessKey("RestartProcessInstanceBatchScenario") .singleResult() .getId(); engine.getTaskService().complete(taskId); } engine.getRuntimeService().restartProcessInstances(processDefinitionId) .startBeforeActivity("theTask") .processInstanceIds(processInstanceIds) .skipCustomListeners() .skipIoMappings() .withoutBusinessKey() .executeAsync(); } };
private RestartProcessInstanceBuilder createRestartProcessInstanceBuilder(RestartProcessInstanceDto restartProcessInstanceDto) { RuntimeService runtimeService = engine.getRuntimeService(); RestartProcessInstanceBuilder builder = runtimeService .restartProcessInstances(processDefinitionId); if (restartProcessInstanceDto.getProcessInstanceIds() != null) { builder.processInstanceIds(restartProcessInstanceDto.getProcessInstanceIds()); } if (restartProcessInstanceDto.getHistoricProcessInstanceQuery() != null) { builder.historicProcessInstanceQuery(restartProcessInstanceDto.getHistoricProcessInstanceQuery().toQuery(engine)); } if (restartProcessInstanceDto.isInitialVariables()) { builder.initialSetOfVariables(); } if (restartProcessInstanceDto.isWithoutBusinessKey()) { builder.withoutBusinessKey(); } if (restartProcessInstanceDto.isSkipCustomListeners()) { builder.skipCustomListeners(); } if (restartProcessInstanceDto.isSkipIoMappings()) { builder.skipIoMappings(); } restartProcessInstanceDto.applyTo(builder, engine, objectMapper); return builder; }
private RestartProcessInstanceBuilder createRestartProcessInstanceBuilder(RestartProcessInstanceDto restartProcessInstanceDto) { RuntimeService runtimeService = engine.getRuntimeService(); RestartProcessInstanceBuilder builder = runtimeService .restartProcessInstances(processDefinitionId); if (restartProcessInstanceDto.getProcessInstanceIds() != null) { builder.processInstanceIds(restartProcessInstanceDto.getProcessInstanceIds()); } if (restartProcessInstanceDto.getHistoricProcessInstanceQuery() != null) { builder.historicProcessInstanceQuery(restartProcessInstanceDto.getHistoricProcessInstanceQuery().toQuery(engine)); } if (restartProcessInstanceDto.isInitialVariables()) { builder.initialSetOfVariables(); } if (restartProcessInstanceDto.isWithoutBusinessKey()) { builder.withoutBusinessKey(); } if (restartProcessInstanceDto.isSkipCustomListeners()) { builder.skipCustomListeners(); } if (restartProcessInstanceDto.isSkipIoMappings()) { builder.skipIoMappings(); } restartProcessInstanceDto.applyTo(builder, engine, objectMapper); return builder; }
@Test public void shouldRestartProcessInstanceWithoutBusinessKey() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process", "businessKey1", (String) null); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process", "businessKey2", (String) null); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); // when Batch batch = runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity("userTask1") .processInstanceIds(processInstance1.getId(), processInstance2.getId()) .withoutBusinessKey() .executeAsync(); helper.completeBatch(batch); // then List<ProcessInstance> restartedProcessInstances = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition.getId()).active().list(); ProcessInstance restartedProcessInstance1 = restartedProcessInstances.get(0); ProcessInstance restartedProcessInstance2 = restartedProcessInstances.get(1); assertNull(restartedProcessInstance1.getBusinessKey()); assertNull(restartedProcessInstance2.getBusinessKey()); }
@Test public void shouldRestartProcessInstanceWithoutBusinessKey() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process", "businessKey", (String) null); runtimeService.deleteProcessInstance(processInstance.getId(), "test"); // when runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity("userTask1") .processInstanceIds(processInstance.getId()) .withoutBusinessKey() .execute(); // then ProcessInstance restartedProcessInstance = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition.getId()).active().singleResult(); assertNull(restartedProcessInstance.getBusinessKey()); }
private RestartProcessInstanceBuilder createRestartProcessInstanceBuilder(RestartProcessInstanceDto restartProcessInstanceDto) { RuntimeService runtimeService = engine.getRuntimeService(); RestartProcessInstanceBuilder builder = runtimeService .restartProcessInstances(processDefinitionId); if (restartProcessInstanceDto.getProcessInstanceIds() != null) { builder.processInstanceIds(restartProcessInstanceDto.getProcessInstanceIds()); } if (restartProcessInstanceDto.getHistoricProcessInstanceQuery() != null) { builder.historicProcessInstanceQuery(restartProcessInstanceDto.getHistoricProcessInstanceQuery().toQuery(engine)); } if (restartProcessInstanceDto.isInitialVariables()) { builder.initialSetOfVariables(); } if (restartProcessInstanceDto.isWithoutBusinessKey()) { builder.withoutBusinessKey(); } if (restartProcessInstanceDto.isSkipCustomListeners()) { builder.skipCustomListeners(); } if (restartProcessInstanceDto.isSkipIoMappings()) { builder.skipIoMappings(); } restartProcessInstanceDto.applyTo(builder, engine, objectMapper); return builder; }
@Test public void shouldRestartProcessInstanceWithoutBusinessKey() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process", "businessKey1", (String) null); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process", "businessKey2", (String) null); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); // when Batch batch = runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity("userTask1") .processInstanceIds(processInstance1.getId(), processInstance2.getId()) .withoutBusinessKey() .executeAsync(); helper.completeBatch(batch); // then List<ProcessInstance> restartedProcessInstances = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition.getId()).active().list(); ProcessInstance restartedProcessInstance1 = restartedProcessInstances.get(0); ProcessInstance restartedProcessInstance2 = restartedProcessInstances.get(1); assertNull(restartedProcessInstance1.getBusinessKey()); assertNull(restartedProcessInstance2.getBusinessKey()); }
@Test public void shouldRestartProcessInstanceWithoutBusinessKey() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process", "businessKey", (String) null); runtimeService.deleteProcessInstance(processInstance.getId(), "test"); // when runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity("userTask1") .processInstanceIds(processInstance.getId()) .withoutBusinessKey() .execute(); // then ProcessInstance restartedProcessInstance = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition.getId()).active().singleResult(); assertNull(restartedProcessInstance.getBusinessKey()); }