@Override public void restartProcessInstance(RestartProcessInstanceDto restartProcessInstanceDto) { try { createRestartProcessInstanceBuilder(restartProcessInstanceDto).execute(); } catch (BadUserRequestException e) { throw new InvalidRequestException(Status.BAD_REQUEST, e.getMessage()); } }
@Override public void restartProcessInstance(RestartProcessInstanceDto restartProcessInstanceDto) { try { createRestartProcessInstanceBuilder(restartProcessInstanceDto).execute(); } catch (BadUserRequestException e) { throw new InvalidRequestException(Status.BAD_REQUEST, e.getMessage()); } }
@Test public void restartProcessInstanceWithNullProcessDefinitionId() { try { runtimeService.restartProcessInstances(null).execute(); fail("exception expected"); } catch (BadUserRequestException e) { Assert.assertThat(e.getMessage(), containsString("processDefinitionId is null")); } }
@Test public void restartProcessInstanceWithoutProcessInstanceIds() { try { runtimeService.restartProcessInstances("foo").startAfterActivity("bar").execute(); fail("exception expected"); } catch (BadUserRequestException e) { Assert.assertThat(e.getMessage(), containsString("processInstanceIds is empty")); } }
@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 testRestartProcessInstanceWithNullInstructionsSync() { doThrow(new BadUserRequestException("instructions is null")).when(builderMock).execute(); HashMap<String, Object> json = new HashMap<String, Object>(); json.put("processInstanceIds", "processInstanceId"); given() .pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID) .contentType(ContentType.JSON) .body(json) .then().expect() .statusCode(Status.BAD_REQUEST.getStatusCode()) .when() .post(RESTART_PROCESS_INSTANCE_URL); }
@Test public void testRestartProcessInstanceWithNullProcessInstanceIdsSync() { doThrow(new BadUserRequestException("processInstanceIds is null")).when(builderMock).execute(); HashMap<String, Object> json = new HashMap<String, Object>(); List<Map<String, Object>> instructions = new ArrayList<Map<String, Object>>(); instructions.add(ModificationInstructionBuilder.startBefore().activityId("activityId").getJson()); json.put("instructions", instructions); given() .pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID) .contentType(ContentType.JSON) .body(json) .then().expect() .statusCode(Status.BAD_REQUEST.getStatusCode()) .when() .post(RESTART_PROCESS_INSTANCE_URL); }
@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 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")); } }
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) public void testFailToRestartProcessInstanceSyncWithOtherTenantId() { // 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()) .execute(); fail("expected exception"); } catch (BadUserRequestException e) { // then assertThat(e.getMessage(), containsString("Historic process instance cannot be found: historicProcessInstanceId is null")); } }
@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")); } }
@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(); }
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) public void testRestartProcessInstanceSyncWithTenantId() { // given ProcessInstance processInstance = startAndDeleteProcessInstance(TENANT_ONE, PROCESS); identityService.setAuthentication("user", null, Collections.singletonList(TENANT_ONE)); // when runtimeService.restartProcessInstances(processInstance.getProcessDefinitionId()) .startBeforeActivity("userTask") .processInstanceIds(processInstance.getId()) .execute(); // then ProcessInstance restartedInstance = runtimeService.createProcessInstanceQuery().active() .processDefinitionId(processInstance.getProcessDefinitionId()).singleResult(); assertNotNull(restartedInstance); assertEquals(restartedInstance.getTenantId(), TENANT_ONE); }
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) public void testRestartProcessInstanceSyncWithTenantIdByHistoricProcessInstanceQuery() { // given ProcessInstance processInstance = startAndDeleteProcessInstance(TENANT_ONE, PROCESS); HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery().processDefinitionId(processInstance.getProcessDefinitionId()); identityService.setAuthentication("user", null, Collections.singletonList(TENANT_ONE)); // when runtimeService.restartProcessInstances(processInstance.getProcessDefinitionId()) .startBeforeActivity("userTask") .historicProcessInstanceQuery(query) .execute(); // then ProcessInstance restartedInstance = runtimeService.createProcessInstanceQuery().active() .processDefinitionId(processInstance.getProcessDefinitionId()).singleResult(); assertNotNull(restartedInstance); assertEquals(restartedInstance.getTenantId(), TENANT_ONE); }
@Test public void restartProcessInstanceWithNotMatchingProcessDefinition() { BpmnModelInstance instance = Bpmn.createExecutableProcess("Process2").startEvent().userTask().endEvent().done(); ProcessDefinition processDefinition = testRule.deployAndGetDefinition(instance); ProcessDefinition processDefinition2 = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance.getId(), null); try { runtimeService.restartProcessInstances(processDefinition.getId()).startBeforeActivity("userTask").processInstanceIds(processInstance.getId()).execute(); fail("exception expected"); } catch (ProcessEngineException e) { Assert.assertThat(e.getMessage(), containsString("Its process definition '" + processDefinition2.getId() + "' does not match given process definition '" + processDefinition.getId() +"'" )); } }
@Test public void shouldRestartProcessInstanceWithoutCaseInstanceId() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process", null, "caseInstanceId"); runtimeService.deleteProcessInstance(processInstance.getId(), "test"); // when runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity("userTask1") .processInstanceIds(processInstance.getId()) .execute(); // then ProcessInstance restartedProcessInstance = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition.getId()).active().singleResult(); assertNull(restartedProcessInstance.getCaseInstanceId()); }
@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()); }
@Test public void shouldRestartProcessInstanceWithBusinessKey() { // 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()) .execute(); // then ProcessInstance restartedProcessInstance = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition.getId()).active().singleResult(); assertNotNull(restartedProcessInstance.getBusinessKey()); assertEquals("businessKey", restartedProcessInstance.getBusinessKey()); }
@Test public void shouldRestartProcessInstanceWithTenant() { // given ProcessDefinition processDefinition = testRule.deployForTenantAndGetDefinition("tenantId", ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance.getId(), "test"); // when runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity("userTask1") .processInstanceIds(processInstance.getId()) .execute(); // then ProcessInstance restartedProcessInstance = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition.getId()).active().singleResult(); assertNotNull(restartedProcessInstance.getTenantId()); assertEquals(processInstance.getTenantId(), restartedProcessInstance.getTenantId()); }
@Test public void shouldSkipIoMappings() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition( modify(ProcessModels.TWO_TASKS_PROCESS).activityBuilder("userTask1").camundaInputParameter("foo", "bar").done()); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance.getId(), "test"); // when runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity("userTask1") .skipIoMappings() .processInstanceIds(processInstance.getId()) .execute(); // then Execution task1Execution = runtimeService.createExecutionQuery().activityId("userTask1").singleResult(); assertNotNull(task1Execution); assertNull(runtimeService.getVariable(task1Execution.getId(), "foo")); }