@Override public BatchDto restartProcessInstanceAsync(RestartProcessInstanceDto restartProcessInstanceDto) { Batch batch = null; try { batch = createRestartProcessInstanceBuilder(restartProcessInstanceDto).executeAsync(); } catch (BadUserRequestException e) { throw new InvalidRequestException(Status.BAD_REQUEST, e.getMessage()); } return BatchDto.fromBatch(batch); }
@Override public BatchDto restartProcessInstanceAsync(RestartProcessInstanceDto restartProcessInstanceDto) { Batch batch = null; try { batch = createRestartProcessInstanceBuilder(restartProcessInstanceDto).executeAsync(); } catch (BadUserRequestException e) { throw new InvalidRequestException(Status.BAD_REQUEST, e.getMessage()); } return BatchDto.fromBatch(batch); }
@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 restartProcessInstanceWithNullProcessDefinitionId() { try { runtimeService.restartProcessInstances(null) .executeAsync(); fail("exception expected"); } catch (BadUserRequestException e) { Assert.assertThat(e.getMessage(), containsString("processDefinitionId is null")); } }
@Test public void restartProcessInstanceWithoutProcessInstanceIds() { try { runtimeService.restartProcessInstances("foo").startAfterActivity("bar").executeAsync(); fail("exception expected"); } catch (BadUserRequestException e) { Assert.assertThat(e.getMessage(), containsString("processInstanceIds is empty")); } }
@Test public void testRestartProcessInstanceWithNullInstructionsAsync() { doThrow(new BadUserRequestException("instructions is null")).when(builderMock).executeAsync(); 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_ASYNC_URL); }
@Test public void testRestartProcessInstanceWithNullProcessInstanceIdsAsync() { doThrow(new BadUserRequestException("processInstanceIds is null")).when(builderMock).executeAsync(); 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_ASYNC_URL); }
@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")); } }
@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 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")); } }
@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 restartNotExistingProcessInstance() { ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); Batch batch = runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity("bar") .processInstanceIds("aaa") .executeAsync(); helper.executeSeedJob(batch); try { helper.executeJobs(batch); fail("exception expected"); } catch (BadUserRequestException e) { Assert.assertThat(e.getMessage(), containsString("Historic process instance cannot be found")); } }
@Test public void testNoCreationOnJobExecutorBatchJobExecution() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(instance); ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId()); runtimeService.deleteProcessInstance(processInstance.getId(), "test"); runtimeService.restartProcessInstances(processDefinition.getId()) .startAfterActivity("user1") .processInstanceIds(Arrays.asList(processInstance.getId())) .executeAsync(); // when testRule.waitForJobExecutorToProcessAllJobs(5000L); // then Assert.assertEquals(0, rule.getHistoryService().createUserOperationLogQuery().count()); }
@Test public void createBatchRestart() { // given 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"); List<String> processInstanceIds = Arrays.asList(processInstance1.getId(), processInstance2.getId()); // when Batch batch = runtimeService.restartProcessInstances(processDefinition.getId()) .startAfterActivity("userTask2") .processInstanceIds(processInstanceIds) .executeAsync(); // then assertBatchCreated(batch, 2); }
@Test public void shouldRestartProcessInstanceWithTenant() { // given ProcessDefinition processDefinition = testRule.deployForTenantAndGetDefinition("tenantId", 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 Batch batch = runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity("userTask1") .processInstanceIds(processInstance1.getId(), processInstance2.getId()) .executeAsync(); helper.completeBatch(batch); // then List<ProcessInstance> restartedProcessInstances = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition.getId()).active().list(); assertNotNull(restartedProcessInstances.get(0).getTenantId()); assertNotNull(restartedProcessInstances.get(1).getTenantId()); assertEquals("tenantId", restartedProcessInstances.get(0).getTenantId()); assertEquals("tenantId", restartedProcessInstances.get(1).getTenantId()); }
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) public void testRestartProcessInstanceAsyncWithTenantId() { // given ProcessInstance processInstance = startAndDeleteProcessInstance(TENANT_ONE, PROCESS); identityService.setAuthentication("user", null, Collections.singletonList(TENANT_ONE)); // when Batch batch = runtimeService.restartProcessInstances(processInstance.getProcessDefinitionId()) .startBeforeActivity("userTask") .processInstanceIds(processInstance.getId()) .executeAsync(); batchHelper.completeBatch(batch); // then ProcessInstance restartedInstance = runtimeService.createProcessInstanceQuery().active() .processDefinitionId(processInstance.getProcessDefinitionId()).singleResult(); assertNotNull(restartedInstance); assertEquals(restartedInstance.getTenantId(), TENANT_ONE); }
@Test public void shouldRestartProcessInstanceWithoutCaseInstanceId() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process", null, "caseInstanceId1"); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process", null, "caseInstanceId2"); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); // when Batch batch = runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity("userTask1") .processInstanceIds(processInstance1.getId(), processInstance2.getId()) .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.getCaseInstanceId()); assertNull(restartedProcessInstance2.getCaseInstanceId()); }
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) public void testRestartProcessInstanceAsyncWithTenantIdByHistoricProcessInstanceQuery() { // given ProcessInstance processInstance = startAndDeleteProcessInstance(TENANT_ONE, PROCESS); HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery().processDefinitionId(processInstance.getProcessDefinitionId()); identityService.setAuthentication("user", null, Collections.singletonList(TENANT_ONE)); // when Batch batch = runtimeService.restartProcessInstances(processInstance.getProcessDefinitionId()) .startBeforeActivity("userTask") .historicProcessInstanceQuery(query) .executeAsync(); batchHelper.completeBatch(batch); // then ProcessInstance restartedInstance = runtimeService.createProcessInstanceQuery().active() .processDefinitionId(processInstance.getProcessDefinitionId()).singleResult(); assertNotNull(restartedInstance); assertEquals(restartedInstance.getTenantId(), TENANT_ONE); }
@Test public void testNoCreationOnSyncBatchJobExecution() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(instance); ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId()); runtimeService.deleteProcessInstance(processInstance.getId(), "test"); Batch batch = runtimeService.restartProcessInstances(processDefinition.getId()).startBeforeActivity("user1").processInstanceIds(processInstance.getId()).executeAsync(); helper.executeSeedJob(batch); // when rule.getIdentityService().setAuthenticatedUserId("userId"); helper.executeJobs(batch); rule.getIdentityService().clearAuthentication(); // then Assert.assertEquals(0, rule.getHistoryService().createUserOperationLogQuery().count()); }
@Test public void shouldRetainTenantIdOfSharedProcessDefinition() { // given engineRule.getProcessEngineConfiguration() .setTenantIdProvider(new TestTenantIdProvider()); ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId()); assertEquals(processInstance.getTenantId(), TestTenantIdProvider.TENANT_ID); runtimeService.deleteProcessInstance(processInstance.getId(), "test"); // when Batch batch = runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity(ProcessModels.USER_TASK_ID) .processInstanceIds(processInstance.getId()) .executeAsync(); helper.completeBatch(batch); // then ProcessInstance restartedInstance = runtimeService.createProcessInstanceQuery().active() .processDefinitionId(processDefinition.getId()).singleResult(); assertNotNull(restartedInstance); assertEquals(restartedInstance.getTenantId(), TestTenantIdProvider.TENANT_ID); }