PlanningScoreDeleteValidator implements ObjectPropertyDeleteValidator { @Override public Collection<ValidationMessage> validate(final DataObject dataObject, final ObjectProperty objectProperty) { final boolean isGeneratedPlanningScoreField = dataObject != null && dataObject.getAnnotation(PlanningSolution.class.getName()) != null && objectProperty != null && "score".equals(objectProperty.getName()) && objectProperty.getAnnotation(PlanningScore.class.getName()) != null && objectProperty.getAnnotation(Generated.class.getName()) != null; return isGeneratedPlanningScoreField ? Arrays.asList(new PlanningScoreToBeDeletedMessage()) : Collections.emptyList(); }  @Override Collection<ValidationMessage> validate(final DataObject dataObject,
                                                  final ObjectProperty objectProperty);  }
@Test public void validateIsAPlanningScore() { DataObject dataObject = new DataObjectImpl("test", "PlanningSolution"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); ObjectProperty objectProperty = new ObjectPropertyImpl("score", HardSoftScore.class.getName(), false); objectProperty.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningScore.class))); objectProperty.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(Generated.class))); Collection<ValidationMessage> result = deleteValidator.validate(dataObject, objectProperty); assertEquals(1, result.size()); assertTrue(result.iterator().next() instanceof PlanningScoreToBeDeletedMessage); }
@Test public void validateIsNotAPlanningScore() { DataObject dataObject = new DataObjectImpl("test", "PlainDataObject"); ObjectProperty objectProperty = new ObjectPropertyImpl("notAPlanningScore", Integer.class.getName(), false); Collection<ValidationMessage> result = deleteValidator.validate(dataObject, objectProperty); assertEquals(0, result.size()); }
@Test public void validateNullObject() { assertEquals(0, deleteValidator.validate(null, null).size()); }
@Test public void validateNullProperty() { DataObject dataObject = new DataObjectImpl("test", "PlanningSolution"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); assertEquals(0, deleteValidator.validate(dataObject, null).size()); }