@Override public BatchDto executeModificationAsync(ModificationDto modificationExecutionDto) { Batch batch = null; try { batch = createModificationBuilder(modificationExecutionDto).executeAsync(); } catch (BadUserRequestException e) { throw new InvalidRequestException(Status.BAD_REQUEST, e.getMessage()); } return BatchDto.fromBatch(batch); }
@Override public BatchDto executeModificationAsync(ModificationDto modificationExecutionDto) { Batch batch = null; try { batch = createModificationBuilder(modificationExecutionDto).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); modificationBuilderMock = mock(ModificationBuilder.class); when(modificationBuilderMock.cancelAllForActivity(anyString())).thenReturn(modificationBuilderMock); when(modificationBuilderMock.startAfterActivity(anyString())).thenReturn(modificationBuilderMock); when(modificationBuilderMock.startBeforeActivity(anyString())).thenReturn(modificationBuilderMock); when(modificationBuilderMock.startTransition(anyString())).thenReturn(modificationBuilderMock); when(modificationBuilderMock.processInstanceIds(anyListOf(String.class))).thenReturn(modificationBuilderMock); Batch batchMock = createMockBatch(); when(modificationBuilderMock.executeAsync()).thenReturn(batchMock); when(runtimeServiceMock.createModification(anyString())).thenReturn(modificationBuilderMock); }
@Test public void createModificationWithNullProcessDefinitionId() { try { runtimeService.createModification(null).cancelAllForActivity("activityId").processInstanceIds(Arrays.asList("20", "1--0")).executeAsync(); fail("Should not succed"); } catch (ProcessEngineException e) { assertThat(e.getMessage(), containsString("processDefinitionId is null")); } }
@Test public void createModificationWithEmptyProcessInstanceIdsListAsync() { try { runtimeService.createModification("processDefinitionId").startAfterActivity("user1").processInstanceIds(Collections.<String> emptyList()).executeAsync(); fail("Should not succeed"); } catch (ProcessEngineException e) { assertThat(e.getMessage(), containsString("Process instance ids is empty")); } }
@Test public void createModificationUsingProcessInstanceIdsListWithNullValueAsync() { try { runtimeService.createModification("processDefinitionId").startAfterActivity("user1").processInstanceIds(Arrays.asList("foo", null, "bar")).executeAsync(); fail("Should not succeed"); } catch (ProcessEngineException e) { assertThat(e.getMessage(), containsString("Process instance ids contains null value")); } }
public Batch startAfterAsync(String key, int numberOfProcessInstances, String activityId, String processDefinitionId) { RuntimeService runtimeService = engineRule.getRuntimeService(); List<String> processInstanceIds = startInstances(key, numberOfProcessInstances); return runtimeService .createModification(processDefinitionId) .startAfterActivity(activityId) .processInstanceIds(processInstanceIds) .executeAsync(); }
@Test public void testNullProcessInstanceQueryAsync() { try { runtimeService.createModification("processDefinitionId").startAfterActivity("user1").processInstanceQuery(null).executeAsync(); fail("Should not succeed"); } catch (ProcessEngineException e) { assertThat(e.getMessage(), containsString("Process instance ids is empty")); } }
public Batch cancelAllAsync(String key, int numberOfProcessInstances, String activityId, String processDefinitionId) { RuntimeService runtimeService = engineRule.getRuntimeService(); List<String> processInstanceIds = startInstances(key, numberOfProcessInstances); return runtimeService.createModification(processDefinitionId).cancelAllForActivity(activityId).processInstanceIds(processInstanceIds).executeAsync(); }
@Test public void createModificationWithNullProcessInstanceIdsArrayAsync() { try { runtimeService.createModification("processDefinitionId").startAfterActivity("user1").processInstanceIds((String[]) null).executeAsync(); fail("Should not be able to modify"); } catch (ProcessEngineException e) { assertThat(e.getMessage(), CoreMatchers.containsString("Process instance ids is empty")); } }
public Batch startBeforeAsync(String key, int numberOfProcessInstances, String activityId, String processDefinitionId) { RuntimeService runtimeService = engineRule.getRuntimeService(); List<String> processInstanceIds = startInstances(key, numberOfProcessInstances); return runtimeService.createModification(processDefinitionId).startBeforeActivity(activityId).processInstanceIds(processInstanceIds).executeAsync(); }
public Batch startTransitionAsync(String key, int numberOfProcessInstances, String transitionId, String processDefinitionId) { RuntimeService runtimeService = engineRule.getRuntimeService(); List<String> processInstanceIds = startInstances(key, numberOfProcessInstances); return runtimeService.createModification(processDefinitionId).startTransition(transitionId).processInstanceIds(processInstanceIds).executeAsync(); }
@Test public void createModificationWithNullProcessInstanceIdsListAsync() { try { runtimeService.createModification("processDefinitionId").startAfterActivity("user1").processInstanceIds((List<String>) null).executeAsync(); fail("Should not succeed"); } catch (ProcessEngineException e) { assertThat(e.getMessage(), containsString("Process instance ids is empty")); } }
@Test public void createModificationUsingProcessInstanceIdsArrayWithNullValueAsync() { try { runtimeService.createModification("processDefinitionId").cancelAllForActivity("user1").processInstanceIds("foo", null, "bar").executeAsync(); fail("Should not be able to modify"); } catch (ProcessEngineException e) { assertThat(e.getMessage(), containsString("Process instance ids contains null value")); } }
@Test public void createModificationWithNonExistingProcessDefinitionId() { DeploymentWithDefinitions deployment = testRule.deploy(instance); deployment.getDeployedProcessDefinitions().get(0); List<String> processInstanceIds = helper.startInstances("process1", 2); try { runtimeService.createModification("foo").cancelAllForActivity("activityId").processInstanceIds(processInstanceIds).executeAsync(); fail("Should not succed"); } catch (ProcessEngineException e) { assertThat(e.getMessage(), containsString("processDefinition is null")); } }
@Test public void createBatchModification() { ProcessDefinition processDefinition = testRule.deployAndGetDefinition(instance); List<String> processInstanceIds = helper.startInstances("process1", 2); Batch batch = runtimeService.createModification(processDefinition.getId()).startAfterActivity("user2").processInstanceIds(processInstanceIds).executeAsync(); assertBatchCreated(batch, 2); }
@Test public void testNoCreationOnJobExecutorBatchJobExecution() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(instance); ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId()); runtimeService.createModification(processDefinition.getId()) .cancelAllForActivity("user1") .processInstanceIds(Arrays.asList(processInstance.getId())) .executeAsync(); // when testRule.waitForJobExecutorToProcessAllJobs(5000L); // then Assert.assertEquals(0, rule.getHistoryService().createUserOperationLogQuery().count()); }
@Test public void testBatchCreationWithProcessInstanceQuery() { int processInstanceCount = 15; DeploymentWithDefinitions deployment = testRule.deploy(instance); ProcessDefinition processDefinition = deployment.getDeployedProcessDefinitions().get(0); helper.startInstances("process1", 15); ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition.getId()); assertEquals(processInstanceCount, processInstanceQuery.count()); // when Batch batch = runtimeService .createModification(processDefinition.getId()) .startAfterActivity("user1") .processInstanceQuery(processInstanceQuery) .executeAsync(); // then a batch is created assertBatchCreated(batch, processInstanceCount); }
@Test public void testBatchCreationWithOverlappingProcessInstanceIdsAndQuery() { int processInstanceCount = 15; DeploymentWithDefinitions deployment = testRule.deploy(instance); ProcessDefinition processDefinition = deployment.getDeployedProcessDefinitions().get(0); List<String> processInstanceIds = helper.startInstances("process1", 15); ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition.getId()); assertEquals(processInstanceCount, processInstanceQuery.count()); // when Batch batch = runtimeService .createModification(processDefinition.getId()) .startTransition("seq") .processInstanceIds(processInstanceIds) .processInstanceQuery(processInstanceQuery) .executeAsync(); // then a batch is created assertBatchCreated(batch, processInstanceCount); }
@Test public void testNoCreationOnSyncBatchJobExecution() { // given ProcessDefinition processDefinition = testRule.deployAndGetDefinition(instance); ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId()); Batch batch = runtimeService.createModification(processDefinition.getId()) .startAfterActivity("user2") .processInstanceIds(Arrays.asList(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()); }