CaseInstanceMigrationServiceImpl implements CaseInstanceMigrationService { @Override public CaseMigrationReport migrate(String caseId, String targetDeploymentId, Map<String, String> processMapping) { return migrate(caseId, targetDeploymentId, processMapping, Collections.emptyMap()); }  void setProcessService(ProcessService processService); void setCaseRuntimeDataService(CaseRuntimeDataService caseRuntimeDataService); void setProcessInstanceMigrationService(ProcessInstanceMigrationService processInstanceMigrationService); void setCommandService(TransactionalCommandService commandService); @Override CaseMigrationReport migrate(String caseId, String targetDeploymentId, Map<String, String> processMapping); @Override CaseMigrationReport migrate(String caseId, String targetDeploymentId, Map<String, String> processMapping, Map<String, String> nodeMapping);  }
@Test public void testMigrateSingleCaseInstance() { String caseId = createCaseInstanceV1(); try { assertCaseInstance(caseId, deploymentUnitV1.getIdentifier(), CASE_DEF_ID_V1); Map<String, String> processMapping = new HashMap<>(); processMapping.put(CASE_DEF_ID_V1, CASE_DEF_ID_V2); CaseMigrationReport report = caseInstanceMigrationService.migrate(caseId, deploymentUnitV2.getIdentifier(), processMapping); assertNotNull(report); assertThat(report.isSuccessful()).isTrue(); assertThat(report.getReports()).hasSize(1); assertCaseInstance(caseId, deploymentUnitV2.getIdentifier(), CASE_DEF_ID_V2); caseService.destroyCase(caseId); CaseInstance instance = caseService.getCaseInstance(caseId); Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId()); caseId = null; } catch (Exception e) { logger.error("Unexpected error {}", e.getMessage(), e); fail("Unexpected exception " + e.getMessage()); } finally { if (caseId != null) { caseService.cancelCase(caseId); } } }
@Test public void testMigrateSingleCaseInstanceMissingMapping() { String caseId = createCaseInstanceV1(); try { assertCaseInstance(caseId, deploymentUnitV1.getIdentifier(), CASE_DEF_ID_V1); Map<String, String> processMapping = new HashMap<>(); final String caseIdFinal = caseId; assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> { caseInstanceMigrationService.migrate(caseIdFinal, deploymentUnitV2.getIdentifier(), processMapping); }) .withMessageContaining("Not possible to migrate case instance " + caseId+ " due to missing process mapping"); assertCaseInstance(caseId, deploymentUnitV1.getIdentifier(), CASE_DEF_ID_V1); caseService.destroyCase(caseId); CaseInstance instance = caseService.getCaseInstance(caseId); Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId()); caseId = null; } catch (Exception e) { logger.error("Unexpected error {}", e.getMessage(), e); fail("Unexpected exception " + e.getMessage()); } finally { if (caseId != null) { caseService.cancelCase(caseId); } } }
@Test public void testMigrateSingleCaseInstanceNotExisting() { assertThatExceptionOfType(CaseNotFoundException.class).isThrownBy(() -> { caseInstanceMigrationService.migrate("not-existing", deploymentUnitV2.getIdentifier(), new HashMap<>()); }) .withMessageContaining("Case not-existing does not exist or is not active, cannot be migrated"); }
@Test public void testMigrateSingleCaseInstanceWithDynamicSubprocess() { String caseId = createCaseInstanceV1(); try { assertCaseInstance(caseId, deploymentUnitV1.getIdentifier(), CASE_DEF_ID_V1); caseService.addDynamicSubprocess(caseId, PROCESS_DEF_ID_V1, null); Collection<ProcessInstanceDesc> pInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext()); assertEquals(2, pInstances.size()); for (ProcessInstanceDesc instance : pInstances) { assertEquals(deploymentUnitV1.getIdentifier(), instance.getDeploymentId()); } List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter()); assertNotNull(tasks); assertThat(tasks).hasSize(2); Map<String, TaskSummary> mappedTasks = mapTaskSummaries(tasks); assertThat(mappedTasks).containsKeys("Hello1", "Hello_V1"); Map<String, String> processMapping = new HashMap<>(); processMapping.put(CASE_DEF_ID_V1, CASE_DEF_ID_V2); processMapping.put(PROCESS_DEF_ID_V1, PROCESS_DEF_ID_V2); CaseMigrationReport report = caseInstanceMigrationService.migrate(caseId, deploymentUnitV2.getIdentifier(), processMapping); assertNotNull(report); assertThat(report.isSuccessful()).isTrue(); assertThat(report.getReports()).hasSize(2); assertCaseInstance(caseId, deploymentUnitV2.getIdentifier(), CASE_DEF_ID_V2); pInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext()); assertEquals(2, pInstances.size()); for (ProcessInstanceDesc instance : pInstances) { assertEquals(deploymentUnitV2.getIdentifier(), instance.getDeploymentId()); } tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter()); assertNotNull(tasks); assertThat(tasks).hasSize(2); mappedTasks = mapTaskSummaries(tasks); assertThat(mappedTasks).containsKeys("Hello1", "Hello_V2"); userTaskService.completeAutoProgress(mappedTasks.get("Hello_V2").getId(), USER, null); caseService.destroyCase(caseId); CaseInstance instance = caseService.getCaseInstance(caseId); Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId()); caseId = null; } catch (Exception e) { logger.error("Unexpected error {}", e.getMessage(), e); fail("Unexpected exception " + e.getMessage()); } finally { if (caseId != null) { caseService.cancelCase(caseId); } } }
@Test public void testMigrateSingleCaseInstanceWithDynamicSubprocessNodeMapping() { String caseId = createCaseInstanceV1(); try { assertCaseInstance(caseId, deploymentUnitV1.getIdentifier(), CASE_DEF_ID_V1); caseService.addDynamicSubprocess(caseId, PROCESS_DEF_ID_V1, null); Collection<ProcessInstanceDesc> pInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext()); assertEquals(2, pInstances.size()); for (ProcessInstanceDesc instance : pInstances) { assertEquals(deploymentUnitV1.getIdentifier(), instance.getDeploymentId()); } List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter()); assertNotNull(tasks); assertThat(tasks).hasSize(2); Map<String, TaskSummary> mappedTasks = mapTaskSummaries(tasks); assertThat(mappedTasks).containsKeys("Hello1", "Hello_V1"); Map<String, String> processMapping = new HashMap<>(); processMapping.put(CASE_DEF_ID_V1, CASE_DEF_ID_V2); processMapping.put(PROCESS_DEF_ID_V1, PROCESS_DEF_ID_V3); Map<String, String> nodeMapping = new HashMap<>(); nodeMapping.put("_22", "_33"); CaseMigrationReport report = caseInstanceMigrationService.migrate(caseId, deploymentUnitV2.getIdentifier(), processMapping, nodeMapping); assertNotNull(report); assertThat(report.isSuccessful()).isTrue(); assertThat(report.getReports()).hasSize(2); assertCaseInstance(caseId, deploymentUnitV2.getIdentifier(), CASE_DEF_ID_V2); pInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext()); assertEquals(2, pInstances.size()); for (ProcessInstanceDesc instance : pInstances) { assertEquals(deploymentUnitV2.getIdentifier(), instance.getDeploymentId()); } tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter()); assertNotNull(tasks); assertThat(tasks).hasSize(2); mappedTasks = mapTaskSummaries(tasks); assertThat(mappedTasks).containsKeys("Hello1", "Hello_V3"); userTaskService.completeAutoProgress(mappedTasks.get("Hello_V3").getId(), USER, null); caseService.destroyCase(caseId); CaseInstance instance = caseService.getCaseInstance(caseId); Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId()); caseId = null; } catch (Exception e) { logger.error("Unexpected error {}", e.getMessage(), e); fail("Unexpected exception " + e.getMessage()); } finally { if (caseId != null) { caseService.cancelCase(caseId); } } }
@SuppressWarnings({"rawtypes", "unchecked"}) @Test public void testMigrateSingleCaseInstanceWithDynamicSubprocessRevert() { String caseId = createCaseInstanceV1(); try { assertCaseInstance(caseId, deploymentUnitV1.getIdentifier(), CASE_DEF_ID_V1); caseService.addDynamicSubprocess(caseId, PROCESS_DEF_ID_V1, null); Collection<ProcessInstanceDesc> pInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext()); assertEquals(2, pInstances.size()); for (ProcessInstanceDesc instance : pInstances) { assertEquals(deploymentUnitV1.getIdentifier(), instance.getDeploymentId()); } List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter()); assertNotNull(tasks); assertThat(tasks).hasSize(2); Map<String, TaskSummary> mappedTasks = mapTaskSummaries(tasks); assertThat(mappedTasks).containsKeys("Hello1", "Hello_V1"); Map<String, String> processMapping = new HashMap<>(); processMapping.put(CASE_DEF_ID_V1, CASE_DEF_ID_V2); processMapping.put(PROCESS_DEF_ID_V1, PROCESS_DEF_ID_V3); Map erronousMapping = Collections.singletonMap("_22", 2); CaseMigrationReport report = caseInstanceMigrationService.migrate(caseId, deploymentUnitV2.getIdentifier(), processMapping, erronousMapping); assertNotNull(report); assertThat(report.isSuccessful()).isFalse(); assertThat(report.getReports()).hasSize(2); assertCaseInstance(caseId, deploymentUnitV1.getIdentifier(), CASE_DEF_ID_V1); pInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext()); assertEquals(2, pInstances.size()); for (ProcessInstanceDesc instance : pInstances) { assertEquals(deploymentUnitV1.getIdentifier(), instance.getDeploymentId()); } tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter()); assertNotNull(tasks); assertThat(tasks).hasSize(2); mappedTasks = mapTaskSummaries(tasks); assertThat(mappedTasks).containsKeys("Hello1", "Hello_V1"); userTaskService.completeAutoProgress(mappedTasks.get("Hello_V1").getId(), USER, null); caseService.destroyCase(caseId); CaseInstance instance = caseService.getCaseInstance(caseId); Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId()); caseId = null; } catch (Exception e) { logger.error("Unexpected error {}", e.getMessage(), e); fail("Unexpected exception " + e.getMessage()); } finally { if (caseId != null) { caseService.cancelCase(caseId); } } }