PlannerFieldMetadataProvider implements FieldMetadataProvider { @Override public Optional<FieldMetadata> getFieldMetadata(ObjectProperty objectProperty) { if (objectProperty.getAnnotations() != null) { return objectProperty.getAnnotations() .stream() .map(p -> PLANNER_ANNOTATION_DESCRIPTION_MAP.get(p.getClassName())) .filter(Objects::nonNull) .findFirst() .map(description -> { ImageResource imageResource = DomainImageResources.INSTANCE.optaPlannerDomainEditorFieldIcon(); ImageWrapper imageWrapper = new ImageWrapper(imageResource.getSafeUri().asString(), description); return new FieldMetadata(imageWrapper); }); } return Optional.empty(); } @Inject  PlannerFieldMetadataProvider(final TranslationService translationService); @PostConstruct void init(); @Override Optional<FieldMetadata> getFieldMetadata(ObjectProperty objectProperty);  }
@Test public void getFieldMetadataMatchingField() { Annotation planningScoreAnnotation = new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningScore.class)); ObjectProperty matchingField = new ObjectPropertyImpl("matchingField", HardSoftScore.class.getName(), false); matchingField.addAnnotation(planningScoreAnnotation); Optional<FieldMetadata> fieldMetadata = fieldMetadataProvider.getFieldMetadata(matchingField); assertTrue(fieldMetadata.isPresent()); }
@Test public void getFieldMetadataNonMatchingField() { Annotation generatedAnnotation = new AnnotationImpl(DriverUtils.buildAnnotationDefinition(Generated.class)); ObjectProperty nonMatchingField = new ObjectPropertyImpl("nonMatchingField", Integer.class.getName(), false); nonMatchingField.addAnnotation(generatedAnnotation); Optional<FieldMetadata> fieldMetadata = fieldMetadataProvider.getFieldMetadata(nonMatchingField); assertFalse(fieldMetadata.isPresent()); }