@Test public void shouldNotRestartActiveProcessInstance() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId()); // then thrown.expect(ProcessEngineException.class); // when runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity("userTask1") .initialSetOfVariables() .processInstanceIds(processInstance.getId()) .execute(); }
@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); }
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; }
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(); } };
@Test public void restartProcessInstanceWithNullProcessInstanceId() { try { runtimeService.restartProcessInstances("foo") .startAfterActivity("bar") .processInstanceIds((String) null) .executeAsync(); fail("exception expected"); } catch (BadUserRequestException e) { Assert.assertThat(e.getMessage(), containsString("processInstanceIds contains null value")); } }
@Test public void restartNotExistingProcessInstance() { ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); try { runtimeService.restartProcessInstances(processDefinition.getId()).startBeforeActivity("bar").processInstanceIds("aaa").execute(); fail("exception expected"); } catch (BadUserRequestException e) { Assert.assertThat(e.getMessage(), containsString("Historic process instance cannot be found")); } }
@Test public void testRestartProcessInstanceWithInitialVariablesAsync() { 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("initialVariables", true); given() .pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID) .contentType(ContentType.JSON) .body(json) .then() .expect() .statusCode(Status.OK.getStatusCode()) .contentType(ContentType.JSON) .when() .post(RESTART_PROCESS_INSTANCE_ASYNC_URL); verify(builderMock).processInstanceIds(Arrays.asList("processInstance1", "processInstance2")); verify(builderMock).initialSetOfVariables(); verify(builderMock).startBeforeActivity("activityId"); verify(builderMock).executeAsync(); }
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) public void testFailToRestartProcessInstanceAsyncWithOtherTenantId() { // given ProcessInstance processInstance = startAndDeleteProcessInstance(TENANT_ONE, PROCESS); identityService.setAuthentication("user", null, Collections.singletonList(TENANT_TWO)); try { // when runtimeService.restartProcessInstances(processInstance.getProcessDefinitionId()) .startBeforeActivity("userTask") .processInstanceIds(processInstance.getId()) .executeAsync(); } catch (ProcessEngineException e) { assertThat(e.getMessage(), containsString("Cannot restart process instances of process definition '" + processInstance.getProcessDefinitionId() + "' because it belongs to no authenticated tenant.")); } }
@Test public void restartProcessInstanceWithNullProcessInstanceId() { ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); try { runtimeService.restartProcessInstances(processDefinition.getId()).startAfterActivity("bar").processInstanceIds((String) null).execute(); fail("exception expected"); } catch (BadUserRequestException e) { Assert.assertThat(e.getMessage(), containsString("Process instance ids cannot be null")); } }
@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(); }
@Test public void testRestartProcessInstanceWithSkipIoMappingsSync() { 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("skipIoMappings", 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).skipIoMappings(); verify(builderMock).startBeforeActivity("activityId"); verify(builderMock).execute(); }
@Test public void testRestartProcessInstanceWithSkipCustomListenersSync() { 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("skipCustomListeners", 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).skipCustomListeners(); verify(builderMock).startBeforeActivity("activityId"); verify(builderMock).execute(); }
@Test public void testRestartProcessInstanceWithSkipCustomListenersAsync() { 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("skipCustomListeners", true); given() .pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID) .contentType(ContentType.JSON) .body(json) .then() .expect() .statusCode(Status.OK.getStatusCode()) .contentType(ContentType.JSON) .when() .post(RESTART_PROCESS_INSTANCE_ASYNC_URL); verify(builderMock).processInstanceIds(Arrays.asList("processInstance1", "processInstance2")); verify(builderMock).skipCustomListeners(); verify(builderMock).startBeforeActivity("activityId"); verify(builderMock).executeAsync(); }
@Test public void testRestartProcessInstanceWithSkipIoMappingsAsync() { 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("skipIoMappings", true); given() .pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID) .contentType(ContentType.JSON) .body(json) .then() .expect() .statusCode(Status.OK.getStatusCode()) .contentType(ContentType.JSON) .when() .post(RESTART_PROCESS_INSTANCE_ASYNC_URL); verify(builderMock).processInstanceIds(Arrays.asList("processInstance1", "processInstance2")); verify(builderMock).skipIoMappings(); verify(builderMock).startBeforeActivity("activityId"); verify(builderMock).executeAsync(); }
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) public void testFailToRestartProcessInstanceSyncWithOtherTenantIdByHistoricProcessInstanceQuery() { // given ProcessInstance processInstance = startAndDeleteProcessInstance(TENANT_ONE, PROCESS); HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery().processDefinitionId(processInstance.getProcessDefinitionId()); identityService.setAuthentication("user", null, Collections.singletonList(TENANT_TWO)); try { // when runtimeService.restartProcessInstances(processInstance.getProcessDefinitionId()) .startBeforeActivity("userTask") .historicProcessInstanceQuery(query) .execute(); fail("expected exception"); } catch (BadUserRequestException e) { // then assertThat(e.getMessage(), containsString("processInstanceIds is empty")); } }
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) public void testFailToRestartProcessInstanceAsyncWithOtherTenantIdByHistoricProcessInstanceQuery() { // given ProcessInstance processInstance = startAndDeleteProcessInstance(TENANT_ONE, PROCESS); HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery().processDefinitionId(processInstance.getProcessDefinitionId()); identityService.setAuthentication("user", null, Collections.singletonList(TENANT_TWO)); try { // when runtimeService.restartProcessInstances(processInstance.getProcessDefinitionId()) .startBeforeActivity("userTask") .historicProcessInstanceQuery(query) .executeAsync(); } catch (ProcessEngineException e) { assertThat(e.getMessage(), containsString("processInstanceIds is empty")); } }
@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 testBatchCreationWithOverlappingProcessInstanceIdsAndQuery() { // given int processInstanceCount = 2; ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process"); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); // when HistoricProcessInstanceQuery processInstanceQuery = engineRule.getHistoryService() .createHistoricProcessInstanceQuery() .processDefinitionId(processDefinition.getId()); Batch batch = runtimeService .restartProcessInstances(processDefinition.getId()) .startTransition("flow1") .processInstanceIds(processInstance1.getId(), processInstance2.getId()) .historicProcessInstanceQuery(processInstanceQuery) .executeAsync(); helper.completeBatch(batch); // then List<ProcessInstance> restartedProcessInstances = engineRule.getRuntimeService().createProcessInstanceQuery().processDefinitionId(processDefinition.getId()).list(); assertEquals(restartedProcessInstances.size(), processInstanceCount); }
@Test public void restartProcessInstanceWithoutInstructions() { try { runtimeService.restartProcessInstances("foo").processInstanceIds("bar").execute(); fail("exception expected"); } catch (BadUserRequestException e) { Assert.assertThat(e.getMessage(), containsString("Restart instructions cannot be empty")); } }
@Test public void restartProcessInstanceWithoutInstructions() { ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process"); try { Batch batch = runtimeService.restartProcessInstances(processDefinition.getId()).processInstanceIds(processInstance.getId()).executeAsync(); helper.completeBatch(batch); fail("exception expected"); } catch (BadUserRequestException e) { Assert.assertThat(e.getMessage(), containsString("instructions is empty")); } }