use of org.mule.metadata.java.api.annotation.ClassInformationAnnotation in project mule by mulesoft.
the class CoreExtensionModelTestCase method foreach.
@Test
public void foreach() {
final ConstructModel foreach = coreExtensionModel.getConstructModel("foreach").get();
assertThat(foreach.getNestedComponents().size(), is(1));
NestableElementModel processorsChain = foreach.getNestedComponents().get(0);
assertThat(processorsChain, instanceOf(NestedChainModel.class));
assertThat(processorsChain.isRequired(), is(true));
assertThat(foreach.getAllParameterModels(), hasSize(4));
ParameterModel collection = foreach.getAllParameterModels().get(0);
assertThat(collection.getName(), is("collection"));
assertThat(collection.getExpressionSupport(), is(REQUIRED));
assertThat(collection.getType(), instanceOf(ArrayType.class));
assertThat(collection.getType().getAnnotation(ClassInformationAnnotation.class).map(ClassInformationAnnotation::getClassname).orElse(""), is(Iterable.class.getName()));
assertThat(collection.isRequired(), is(false));
ParameterModel batchSize = foreach.getAllParameterModels().get(1);
assertThat(batchSize.getName(), is("batchSize"));
assertThat(batchSize.getExpressionSupport(), is(NOT_SUPPORTED));
assertThat(batchSize.getType(), instanceOf(DefaultNumberType.class));
assertThat(batchSize.isRequired(), is(false));
ParameterModel rootMessageName = foreach.getAllParameterModels().get(2);
assertThat(rootMessageName.getName(), is("rootMessageVariableName"));
assertThat(rootMessageName.getExpressionSupport(), is(NOT_SUPPORTED));
assertThat(rootMessageName.getType(), instanceOf(DefaultStringType.class));
assertThat(rootMessageName.isRequired(), is(false));
ParameterModel counter = foreach.getAllParameterModels().get(3);
assertThat(counter.getName(), is("counterVariableName"));
assertThat(counter.getExpressionSupport(), is(NOT_SUPPORTED));
assertThat(counter.getType(), instanceOf(DefaultStringType.class));
assertThat(counter.isRequired(), is(false));
}
use of org.mule.metadata.java.api.annotation.ClassInformationAnnotation in project mule by mulesoft.
the class MetadataOutputDelegate method adaptToListIfNecessary.
private MetadataType adaptToListIfNecessary(MetadataType resolvedType, Object key, MetadataContext metadataContext) throws MetadataResolvingException {
MetadataType componentOutputType = ((HasOutputModel) component).getOutput().getType();
if (!isCollection(componentOutputType) || isVoid(resolvedType) || isNullType(resolvedType)) {
return resolvedType;
}
MetadataType collectionValueType = ((ArrayType) componentOutputType).getType();
Class<?> collectionType = getCollectionType(collectionValueType);
if (Message.class.equals(collectionType)) {
MessageMetadataType message = (MessageMetadataType) collectionValueType;
resolvedType = wrapInMessageType(resolvedType, key, metadataContext, message.getAttributesType());
}
return metadataContext.getTypeBuilder().arrayType().with(new ClassInformationAnnotation(getCollectionType(componentOutputType))).of(resolvedType).build();
}
use of org.mule.metadata.java.api.annotation.ClassInformationAnnotation in project mule by mulesoft.
the class IntrospectionUtils method collectRelativeClassesAsString.
/**
* Given a {@link MetadataType} it adds all the {@link Class} that are related from that type. This includes generics of an
* {@link ArrayType}, open restriction of an {@link ObjectType} as well as its fields.
*
* @param type {@link MetadataType} to inspect
* @return {@link Set<Class>>} with the classes reachable from the {@code type}
*/
public static Set<String> collectRelativeClassesAsString(MetadataType type) {
Set<String> relativeClasses = new HashSet<>();
type.accept(new MetadataTypeVisitor() {
@Override
public void visitArrayType(ArrayType arrayType) {
arrayType.getType().accept(this);
}
@Override
public void visitObjectField(ObjectFieldType objectFieldType) {
objectFieldType.getValue().accept(this);
}
@Override
public void visitObject(ObjectType objectType) {
if (objectType.getMetadataFormat() != JAVA) {
return;
}
final String clazz = getId(objectType).orElse(null);
if (clazz == null || relativeClasses.contains(clazz)) {
return;
}
Optional<ClassInformationAnnotation> classInformation = objectType.getAnnotation(ClassInformationAnnotation.class);
classInformation.ifPresent(classInformationAnnotation -> relativeClasses.addAll(classInformationAnnotation.getGenericTypes()));
relativeClasses.add(clazz);
objectType.getFields().forEach(objectFieldType -> objectFieldType.accept(this));
objectType.getOpenRestriction().ifPresent(t -> t.accept(this));
}
@Override
public void visitString(StringType stringType) {
if (stringType.getMetadataFormat() == JAVA && isEnum(stringType)) {
getId(stringType).ifPresent(relativeClasses::add);
}
}
});
return relativeClasses;
}
use of org.mule.metadata.java.api.annotation.ClassInformationAnnotation in project mule by mulesoft.
the class JavaDeclarationDelegateTestCase method assertTestModuleConfiguration.
private void assertTestModuleConfiguration(ExtensionDeclaration extensionDeclaration) throws Exception {
assertThat(extensionDeclaration.getConfigurations(), hasSize(1));
ConfigurationDeclaration conf = extensionDeclaration.getConfigurations().get(0);
assertThat(conf.getName(), equalTo(DEFAULT_CONFIG_NAME));
List<ParameterDeclaration> parameters = conf.getAllParameters();
assertThat(parameters, hasSize(31));
assertParameter(parameters, "myName", "", STRING_TYPE, false, SUPPORTED, HEISENBERG);
assertParameter(parameters, "age", "", toMetadataType(Integer.class), false, SUPPORTED, AGE);
assertParameter(parameters, "enemies", "", listOfString(), true, SUPPORTED, null);
assertParameter(parameters, "money", "", toMetadataType(BigDecimal.class), true, SUPPORTED, null);
assertParameter(parameters, "cancer", "", toMetadataType(boolean.class), true, SUPPORTED, null);
assertParameter(parameters, "cancer", "", toMetadataType(boolean.class), true, SUPPORTED, null);
assertParameter(parameters, "dateOfBirth", "", toMetadataType(Date.class), false, SUPPORTED, null);
assertParameter(parameters, "dateOfDeath", "", toMetadataType(Calendar.class), false, SUPPORTED, null);
assertParameter(parameters, "dateOfConception", "", toMetadataType(LocalDateTime.class), false, SUPPORTED, null);
assertParameter(parameters, "dateOfGraduation", "", toMetadataType(Calendar.class), false, NOT_SUPPORTED, null);
assertParameter(parameters, "recipe", "", TYPE_BUILDER.objectType().openWith(TYPE_BUILDER.numberType().integer().with(new ClassInformationAnnotation(Long.class))).with(new ClassInformationAnnotation(Map.class, asList(String.class, Long.class))).build(), false, SUPPORTED, null);
assertParameter(parameters, "ricinPacks", "", arrayOf(Set.class, objectTypeBuilder(Ricin.class)), false, SUPPORTED, null);
assertParameter(parameters, "nextDoor", "", toMetadataType(KnockeableDoor.class), false, SUPPORTED, null);
assertParameter(parameters, "candidateDoors", "", TYPE_BUILDER.objectType().openWith((objectTypeBuilder(KnockeableDoor.class)).build()).with(new ClassInformationAnnotation(Map.class, asList(String.class, KnockeableDoor.class))).build(), false, SUPPORTED, null);
assertParameter(parameters, "initialHealth", "", toMetadataType(HealthStatus.class), false, SUPPORTED, "CANCER");
assertParameter(parameters, "finalHealth", "", toMetadataType(HealthStatus.class), true, SUPPORTED, null);
assertParameter(parameters, "labAddress", "", STRING_TYPE, false, REQUIRED, null);
assertParameter(parameters, "firstEndevour", "", STRING_TYPE, false, NOT_SUPPORTED, null);
assertParameter(parameters, "weapon", "", toMetadataType(Weapon.class), false, SUPPORTED, null);
assertParameter(parameters, "wildCardWeapons", "", arrayOf(List.class, objectTypeBuilder(Weapon.class)), false, SUPPORTED, null);
assertParameter(parameters, "wildCards", "", arrayOf(List.class, objectTypeBuilder(Object.class)), false, SUPPORTED, null);
assertParameter(parameters, "worksAtDEA", "", toMetadataType(boolean.class), false, SUPPORTED, valueOf(TRUE));
assertParameter(parameters, "lovesMinerals", "", toMetadataType(boolean.class), true, SUPPORTED, null);
assertParameter(parameters, "monthlyIncomes", "", arrayOf(List.class, longTypeBuilder()), true, SUPPORTED, null);
assertParameter(parameters, "labeledRicin", "", TYPE_BUILDER.objectType().openWith(objectTypeBuilder(Ricin.class)).with(new ClassInformationAnnotation(Map.class, asList(String.class, Ricin.class))).build(), false, SUPPORTED, null);
assertParameter(parameters, "deathsBySeasons", "", TYPE_BUILDER.objectType().with(new ClassInformationAnnotation(Map.class, asList(String.class, List.class))).openWith(TYPE_BUILDER.arrayType().of(TYPE_BUILDER.stringType())).build(), false, SUPPORTED, null);
assertParameter(parameters, "weaponValueMap", "", TYPE_BUILDER.objectType().with(new ClassInformationAnnotation(Map.class, asList(String.class, Weapon.class))).openWith(WEAPON_TYPE).build(), false, SUPPORTED, null);
assertParameter(parameters, "healthProgressions", "", TYPE_BUILDER.arrayType().of(TYPE_LOADER.load(HealthStatus.class)).build(), false, SUPPORTED, null);
}
use of org.mule.metadata.java.api.annotation.ClassInformationAnnotation in project mule by mulesoft.
the class IntrospectionUtilsTestCase method getDataTypeFromMap.
@Test
public void getDataTypeFromMap() {
Class<Date> dateClass = Date.class;
Class<Map> mapClass = Map.class;
ObjectTypeBuilder objectTypeBuilder = BaseTypeBuilder.create(JAVA).objectType().with(new ClassInformationAnnotation(Map.class));
objectTypeBuilder.openWith().objectType().id(dateClass.getName());
MapDataType dataType = (MapDataType) toDataType(objectTypeBuilder.build());
assertThat(dataType.getType(), is(equalTo(mapClass)));
assertThat(dataType.getKeyDataType().getType(), is(equalTo(String.class)));
assertThat(dataType.getValueDataType().getType(), is(equalTo(dateClass)));
}
Aggregations