public MigrationPlanValidationException failingMigrationPlanValidation(MigrationPlanValidationReportImpl validationReport) { StringBuilder sb = new StringBuilder(); validationReport.writeTo(sb); return new MigrationPlanValidationException(exceptionMessage( "001", "{}", sb.toString()), validationReport); }
public MigrationPlanReportDto validateMigrationPlan(MigrationPlanDto migrationPlanDto) { try { createMigrationPlan(migrationPlanDto); // return an empty report if not errors are found return MigrationPlanReportDto.emptyReport(); } catch (MigrationPlanValidationException e) { return MigrationPlanReportDto.form(e.getValidationReport()); } }
public static MigrationPlanValidationExceptionDto from(MigrationPlanValidationException exception) { MigrationPlanValidationExceptionDto dto = new MigrationPlanValidationExceptionDto(); dto.message = exception.getMessage(); dto.type = exception.getClass().getSimpleName(); dto.setValidationReport(MigrationPlanReportDto.form(exception.getValidationReport())); return dto; }
@Test public void testAddMultiInstanceBodyWithDeeperNestedMapping() { // given ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(MultiInstanceProcessModels.PAR_MI_SUBPROCESS_PROCESS); try { rule.getRuntimeService() .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()) .mapActivities("userTask", "userTask") .build(); fail("Should not succeed"); } catch (MigrationPlanValidationException e) { e.printStackTrace(); assertThat(e.getValidationReport()) .hasInstructionFailures("userTask", "Target activity 'userTask' is a descendant of multi-instance body 'subProcess#multiInstanceBody' " + "that is not mapped from the source process definition" ); } }
@Test public void testAddMultiInstanceBodyWithDeeperNestedMapping() { // given ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(MultiInstanceProcessModels.PAR_MI_SUBPROCESS_PROCESS); try { rule.getRuntimeService() .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()) .mapActivities("userTask", "userTask") .build(); fail("Should not succeed"); } catch (MigrationPlanValidationException e) { e.printStackTrace(); assertThat(e.getValidationReport()) .hasInstructionFailures("userTask", "Target activity 'userTask' is a descendant of multi-instance body 'subProcess#multiInstanceBody' " + "that is not mapped from the source process definition" ); } }
public MigrationPlanReportDto validateMigrationPlan(MigrationPlanDto migrationPlanDto) { try { createMigrationPlan(migrationPlanDto); // return an empty report if not errors are found return MigrationPlanReportDto.emptyReport(); } catch (MigrationPlanValidationException e) { return MigrationPlanReportDto.form(e.getValidationReport()); } }
public MigrationPlanValidationException failingMigrationPlanValidation(MigrationPlanValidationReportImpl validationReport) { StringBuilder sb = new StringBuilder(); validationReport.writeTo(sb); return new MigrationPlanValidationException(exceptionMessage( "001", "{}", sb.toString()), validationReport); }
public static MigrationPlanValidationExceptionDto from(MigrationPlanValidationException exception) { MigrationPlanValidationExceptionDto dto = new MigrationPlanValidationExceptionDto(); dto.message = exception.getMessage(); dto.type = exception.getClass().getSimpleName(); dto.setValidationReport(MigrationPlanReportDto.form(exception.getValidationReport())); return dto; }
@Test public void testMigrateNullSourceActivityId() { ProcessDefinition sourceDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); ProcessDefinition targetDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); try { runtimeService .createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId()) .mapActivities(null, "userTask") .build(); fail("Should not succeed"); } catch (MigrationPlanValidationException e) { assertThat(e.getValidationReport()) .hasInstructionFailures(null, "Source activity id is null"); } }
@Test public void executeMigrationPlanAsyncWithEmptyInstructions() { MigrationInstructionValidationReport instructionReport = mock(MigrationInstructionValidationReport.class); when(instructionReport.getMigrationInstruction()).thenReturn(null); when(instructionReport.getFailures()).thenReturn(Collections.singletonList("failure")); MigrationPlanValidationReport validationReport = mock(MigrationPlanValidationReport.class); when(validationReport.getInstructionReports()).thenReturn(Collections.singletonList(instructionReport)); when(migrationPlanBuilderMock.build()).thenThrow(new MigrationPlanValidationException("fooo", validationReport)); Map<String, Object> migrationExecution = new MigrationExecutionDtoBuilder() .migrationPlan(EXAMPLE_PROCESS_DEFINITION_ID, ANOTHER_EXAMPLE_PROCESS_DEFINITION_ID) .done() .processInstances(EXAMPLE_PROCESS_INSTANCE_ID, ANOTHER_EXAMPLE_PROCESS_INSTANCE_ID) .build(); ((Map<String, Object>) migrationExecution.get(MigrationExecutionDtoBuilder.PROP_MIGRATION_PLAN)) .put(MigrationPlanDtoBuilder.PROP_INSTRUCTIONS, Collections.<MigrationInstructionDto>emptyList()); given() .contentType(POST_JSON_CONTENT_TYPE) .body(migrationExecution) .then().expect() .statusCode(Status.BAD_REQUEST.getStatusCode()) .body("type", equalTo(MigrationPlanValidationException.class.getSimpleName())) .body("message", is("fooo")) .body("validationReport.instructionReports", hasSize(1)) .body("validationReport.instructionReports[0].instruction", nullValue()) .body("validationReport.instructionReports[0].failures", hasSize(1)) .body("validationReport.instructionReports[0].failures[0]", is("failure")) .when() .post(EXECUTE_MIGRATION_ASYNC_URL); }
public static MigrationPlanValidationExceptionDto from(MigrationPlanValidationException exception) { MigrationPlanValidationExceptionDto dto = new MigrationPlanValidationExceptionDto(); dto.message = exception.getMessage(); dto.type = exception.getClass().getSimpleName(); dto.setValidationReport(MigrationPlanReportDto.form(exception.getValidationReport())); return dto; }
@Test public void testMigrateNullTargetActivityId() { ProcessDefinition sourceDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); ProcessDefinition targetDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); try { runtimeService .createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId()) .mapActivities("userTask", null) .build(); fail("Should not succeed"); } catch (MigrationPlanValidationException e) { assertThat(e.getValidationReport()) .hasInstructionFailures("userTask", "Target activity id is null"); } }
when(validationReport.getInstructionReports()).thenReturn(Arrays.asList(instructionReport1, instructionReport2)); when(migrationPlanBuilderMock.build()).thenThrow(new MigrationPlanValidationException("fooo", validationReport));
@Test public void testMigrateNonExistingSourceActivityId() { ProcessDefinition sourceDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); ProcessDefinition targetDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); try { runtimeService .createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId()) .mapActivities("thisActivityDoesNotExist", "userTask") .build(); fail("Should not succeed"); } catch (MigrationPlanValidationException e) { assertThat(e.getValidationReport()) .hasInstructionFailures("thisActivityDoesNotExist", "Source activity 'thisActivityDoesNotExist' does not exist"); } }
when(validationReport.getInstructionReports()).thenReturn(Arrays.asList(instructionReport1, instructionReport2)); when(migrationPlanBuilderMock.build()).thenThrow(new MigrationPlanValidationException("fooo", validationReport));
@Test public void testMigrateNonExistingTargetActivityId() { ProcessDefinition sourceDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); ProcessDefinition targetDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); try { runtimeService .createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId()) .mapActivities("userTask", "thisActivityDoesNotExist") .build(); fail("Should not succeed"); } catch (MigrationPlanValidationException e) { assertThat(e.getValidationReport()) .hasInstructionFailures("userTask", "Target activity 'thisActivityDoesNotExist' does not exist"); } }
@Test public void executeMigrationPlanWithNullInstructions() { MigrationInstructionValidationReport instructionReport = mock(MigrationInstructionValidationReport.class); when(instructionReport.getMigrationInstruction()).thenReturn(null); when(instructionReport.getFailures()).thenReturn(Collections.singletonList("failure")); MigrationPlanValidationReport validationReport = mock(MigrationPlanValidationReport.class); when(validationReport.getInstructionReports()).thenReturn(Collections.singletonList(instructionReport)); when(migrationPlanBuilderMock.build()).thenThrow(new MigrationPlanValidationException("fooo", validationReport)); Map<String, Object> migrationExecution = new MigrationExecutionDtoBuilder() .migrationPlan(EXAMPLE_PROCESS_DEFINITION_ID, ANOTHER_EXAMPLE_PROCESS_DEFINITION_ID) .done() .processInstances(EXAMPLE_PROCESS_INSTANCE_ID, ANOTHER_EXAMPLE_PROCESS_INSTANCE_ID) .build(); given() .contentType(POST_JSON_CONTENT_TYPE) .body(migrationExecution) .then().expect() .statusCode(Status.BAD_REQUEST.getStatusCode()) .body("type", equalTo(MigrationPlanValidationException.class.getSimpleName())) .body("message", is("fooo")) .body("validationReport.instructionReports", hasSize(1)) .body("validationReport.instructionReports[0].instruction", nullValue()) .body("validationReport.instructionReports[0].failures", hasSize(1)) .body("validationReport.instructionReports[0].failures[0]", is("failure")) .when() .post(EXECUTE_MIGRATION_URL); }
@Test public void testMigrateToUnsupportedActivityType() { ProcessDefinition sourceDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); ProcessDefinition targetDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_RECEIVE_TASK_PROCESS); try { runtimeService .createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId()) .mapActivities("userTask", "receiveTask") .build(); fail("Should not succeed"); } catch (MigrationPlanValidationException e) { assertThat(e.getValidationReport()) .hasInstructionFailures("userTask", "Activities have incompatible types (UserTaskActivityBehavior is not compatible with ReceiveTaskActivityBehavior)" ); } }
@Test public void executeMigrationPlanWithEmptyInstructions() { MigrationInstructionValidationReport instructionReport = mock(MigrationInstructionValidationReport.class); when(instructionReport.getMigrationInstruction()).thenReturn(null); when(instructionReport.getFailures()).thenReturn(Collections.singletonList("failure")); MigrationPlanValidationReport validationReport = mock(MigrationPlanValidationReport.class); when(validationReport.getInstructionReports()).thenReturn(Collections.singletonList(instructionReport)); when(migrationPlanBuilderMock.build()).thenThrow(new MigrationPlanValidationException("fooo", validationReport)); Map<String, Object> migrationExecution = new MigrationExecutionDtoBuilder() .migrationPlan(EXAMPLE_PROCESS_DEFINITION_ID, ANOTHER_EXAMPLE_PROCESS_DEFINITION_ID) .done() .processInstances(EXAMPLE_PROCESS_INSTANCE_ID, ANOTHER_EXAMPLE_PROCESS_INSTANCE_ID) .build(); ((Map<String, Object>) migrationExecution.get(MigrationExecutionDtoBuilder.PROP_MIGRATION_PLAN)) .put(MigrationPlanDtoBuilder.PROP_INSTRUCTIONS, Collections.<MigrationInstructionDto>emptyList()); given() .contentType(POST_JSON_CONTENT_TYPE) .body(migrationExecution) .then().expect() .statusCode(Status.BAD_REQUEST.getStatusCode()) .body("type", equalTo(MigrationPlanValidationException.class.getSimpleName())) .body("message", is("fooo")) .body("validationReport.instructionReports", hasSize(1)) .body("validationReport.instructionReports[0].instruction", nullValue()) .body("validationReport.instructionReports[0].failures", hasSize(1)) .body("validationReport.instructionReports[0].failures[0]", is("failure")) .when() .post(EXECUTE_MIGRATION_URL); }
@Test public void testCannotUpdateEventTriggerForEventSubProcess() { ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(EventSubProcessModels.TIMER_EVENT_SUBPROCESS_PROCESS); ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(EventSubProcessModels.TIMER_EVENT_SUBPROCESS_PROCESS); try { runtimeService .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()) .mapActivities("eventSubProcess", "eventSubProcess").updateEventTrigger() .build(); fail("Should not succeed"); } catch (MigrationPlanValidationException e) { assertThat(e.getValidationReport()) .hasInstructionFailures("eventSubProcess", "Cannot update event trigger because the activity does not define a persistent event trigger" ); } }