PlanningSolutionCopyValidator implements CopyValidator<DataObject> { @Override public Collection<ValidationMessage> validate(final Path dataObjectPath, final DataObject dataObject) { if (dataObject != null && dataObject.getAnnotation(PLANNING_SOLUTION_ANNOTATION) != null) { return Arrays.asList(new PlanningSolutionToBeDuplicatedMessage(Level.ERROR)); } return Collections.emptyList(); } @Inject  PlanningSolutionCopyValidator(final DataModelerService dataModelerService,
                                         @Named("ioStrategy") final IOService ioService); @Override Collection<ValidationMessage> validate(final Path dataObjectPath,
                                                  final DataObject dataObject); @Override Collection<ValidationMessage> validate(final Path path); @Override boolean accept(final Path path);  }
@Test public void checkDataObjectIsNotAPlanningSolution() { DataObject dataObject = new DataObjectImpl("test", "Test"); Collection<ValidationMessage> result = copyValidator.validate(dataObjectPath, dataObject); assertTrue(result.isEmpty()); }
@Test public void checkDataObjectIsAPlanningSolution() { DataObject dataObject = new DataObjectImpl("test", "Test"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); Collection<ValidationMessage> result = copyValidator.validate(dataObjectPath, dataObject); assertEquals(1, result.size()); ValidationMessage message = result.iterator().next(); assertTrue(message instanceof PlanningSolutionToBeDuplicatedMessage); }
@Test public void checkDataObjectIsNull() { Collection<ValidationMessage> result = copyValidator.validate(dataObjectPath, null); assertEquals(0, result.size()); }
@Test public void pathValidation_dataObjectPathIsPassedToIoService() { when(dataModelerService.loadDataObject(any(), anyString(), any())).thenReturn(new GenerationResult()); copyValidator.validate(dataObjectPath); verify(ioService).readAllString(Paths.convert(dataObjectPath)); }
@Test public void pathValidation_pathIsNull() { Collection<ValidationMessage> result = copyValidator.validate(null); assertEquals(0, result.size()); }
@Test public void pathValidation_noMessagesWhenGenerationFails() { GenerationResult generationResult = new GenerationResult(); generationResult.setErrors(Collections.singletonList(new DataModelerError())); DataObject dataObject = new DataObjectImpl("test", "Test"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); generationResult.setDataObject(dataObject); when(dataModelerService.loadDataObject(any(), anyString(), any())).thenReturn(generationResult); Collection<ValidationMessage> result = copyValidator.validate(dataObjectPath); assertEquals(0, result.size()); }
@Test public void pathValidation_dataObjectIsNull() { GenerationResult generationResult = new GenerationResult(); generationResult.setDataObject(null); when(dataModelerService.loadDataObject(any(), anyString(), any())).thenReturn(generationResult); Collection<ValidationMessage> result = copyValidator.validate(dataObjectPath); assertEquals(0, result.size()); }
@Test public void pathValidation_dataObjectIsNotPlanningSolution() { DataObject dataObject = new DataObjectImpl("test", "Test"); GenerationResult generationResult = new GenerationResult(); generationResult.setDataObject(dataObject); when(dataModelerService.loadDataObject(any(), anyString(), any())).thenReturn(generationResult); Collection<ValidationMessage> result = copyValidator.validate(dataObjectPath); assertEquals(0, result.size()); }
@Test public void pathValidation_dataObjectIsPlanningSolution() { DataObject dataObject = new DataObjectImpl("test", "Test"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); GenerationResult generationResult = new GenerationResult(); generationResult.setDataObject(dataObject); when(dataModelerService.loadDataObject(any(), anyString(), any())).thenReturn(generationResult); Collection<ValidationMessage> result = copyValidator.validate(dataObjectPath); assertEquals(1, result.size()); assertTrue(result.iterator().next() instanceof PlanningSolutionToBeDuplicatedMessage); }