Skip to content

Commit

Permalink
feat(engine): Tests
Browse files Browse the repository at this point in the history
related to camunda#4205
  • Loading branch information
punitdarira committed Sep 2, 2024
1 parent c374253 commit 3af25b9
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.camunda.bpm.engine.test.api.history;

import static org.assertj.core.api.Assertions.assertThat;

import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.not;
Expand Down Expand Up @@ -109,6 +111,21 @@ public void testDeleteHistoryProcessInstancesAsyncWithList() throws Exception {
assertAllHistoricProcessInstancesAreDeleted();
}

@Test
public void testDeleteHistoryProcessInstances_shouldCreateProcessInstanceRelatedBatchJobsForSingleInvocations() {
//when
Batch batch = historyService.deleteHistoricProcessInstancesAsync(historicProcessInstances, TEST_REASON);

completeSeedJobs(batch);
List<Job> executionJobs = managementService.createJobQuery().jobDefinitionId(batch.getBatchJobDefinitionId()).list();

// then
//Making sure that processInstanceId is set in execution jobs #4205
assertThat(executionJobs)
.extracting("processInstanceId")
.containsExactlyInAnyOrder(historicProcessInstances.toArray());
}

@Test
public void testDeleteHistoryProcessInstancesAsyncWithListForDeletedDeployment() throws Exception {
// given a second deployment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ public void createBatchModification() {
Batch batch = runtimeService.createModification(processDefinition.getId()).startAfterActivity("user2").processInstanceIds(processInstanceIds).executeAsync();

assertBatchCreated(batch, 2);

//Making sure that processInstanceId is set in execution jobs #4205
helper.executeSeedJob(batch);
List<Job> executionJobs = helper.getExecutionJobs(batch);
assertThat(executionJobs)
.extracting("processInstanceId")
.containsExactlyInAnyOrder(processInstanceIds.toArray());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,27 @@ public void testDeleteProcessInstancesAsyncWithList() throws Exception {
assertProcessInstancesAreDeleted();
}

@Deployment(resources = {
"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"})
@Test
public void testDeleteProcessInstances_shouldCreateProcessInstanceRelatedBatchJobsForSingleInvocations() {
// given
List<String> processIds = startTestProcesses(2);

// when
Batch batch = runtimeService.deleteProcessInstancesAsync(processIds, null, TESTING_INSTANCE_DELETE);
completeSeedJobs(batch);

List<Job> executionJobs = managementService.createJobQuery().jobDefinitionId(batch.getBatchJobDefinitionId()).list();

// then
//Making sure that processInstanceId is set in execution jobs #4205
assertThat(executionJobs)
.extracting("processInstanceId")
.containsExactlyInAnyOrder(processIds.toArray());
}


@Deployment(resources = {
"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"})
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,41 @@ public void shouldSetExecutionStartTimeInBatchAndHistory() {
Assertions.assertThat(historicBatch.getExecutionStartTime()).isEqualToIgnoringMillis(TEST_DATE);
}

@Test
public void shouldCreateProcessInstanceRelatedBatchJobsForSingleInvocations() {
RuntimeService runtimeService = engineRule.getRuntimeService();
int processInstanceCount = 2;

ProcessDefinition sourceProcessDefinition = migrationRule.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
ProcessDefinition targetProcessDefinition = migrationRule.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);

List<String> processInstanceIds = new ArrayList<>();
for (int i = 0; i < processInstanceCount; i++) {
processInstanceIds.add(
runtimeService.startProcessInstanceById(sourceProcessDefinition.getId()).getId()
);
}

MigrationPlan migrationPlan = engineRule.getRuntimeService()
.createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId())
.mapEqualActivities()
.build();

// when
Batch batch = runtimeService.newMigration(migrationPlan)
.processInstanceIds(processInstanceIds)
.executeAsync();

helper.executeSeedJob(batch);
List<Job> executionJobs = helper.getExecutionJobs(batch);

// then
//Making sure that processInstanceId is set in execution jobs #4205
assertThat(executionJobs)
.extracting("processInstanceId")
.containsExactlyInAnyOrder(processInstanceIds.toArray());
}

protected void assertBatchCreated(Batch batch, int processInstanceCount) {
assertNotNull(batch);
assertNotNull(batch.getId());
Expand Down

0 comments on commit 3af25b9

Please sign in to comment.