use of org.mule.runtime.module.extension.internal.loader.java.property.RequireNameField in project mule by mulesoft.
the class RefNameDeclarationEnricher method doEnrich.
private void doEnrich(BaseDeclaration<?> declaration) {
declaration.getModelProperty(ImplementingTypeModelProperty.class).ifPresent(typeProperty -> {
Collection<Field> fields = getAllFields(typeProperty.getType(), withAnnotation(RefName.class));
if (isEmpty(fields)) {
return;
}
if (fields.size() > 1) {
throw new IllegalConfigurationModelDefinitionException(String.format("Only one field is allowed to be annotated with @%s, but class '%s' has %d fields " + "with such annotation. Offending fields are: [%s]", RefName.class.getSimpleName(), typeProperty.getType().getName(), fields.size(), Joiner.on(", ").join(fields.stream().map(Field::getName).collect(toList()))));
}
final Field configNameField = fields.iterator().next();
if (!String.class.equals(configNameField.getType())) {
throw new IllegalConfigurationModelDefinitionException(String.format("Class '%s' declares the field '%s' which is annotated with @%s and is of type '%s'. Only " + "fields of type String are allowed to carry such annotation", typeProperty.getType().getName(), configNameField.getName(), RefName.class.getSimpleName(), configNameField.getType().getName()));
}
declaration.addModelProperty(new RequireNameField(configNameField));
});
}
use of org.mule.runtime.module.extension.internal.loader.java.property.RequireNameField in project mule by mulesoft.
the class RefNameDeclarationEnricherTestCase method assertModelPropertyAdded.
private void assertModelPropertyAdded(BaseDeclaration declaration, Field injectionField) {
ArgumentCaptor<RequireNameField> captor = ArgumentCaptor.forClass(RequireNameField.class);
verify(declaration).addModelProperty(captor.capture());
RequireNameField property = captor.getValue();
assertThat(property, is(notNullValue()));
assertThat(property.getField(), equalTo(injectionField));
}
Aggregations