use of org.mule.metadata.api.model.ArrayType in project mule by mulesoft.
the class IntrospectionUtilsTestCase method assertList.
private void assertList(MetadataType metadataType, Class<?> listItemType) {
assertThat(metadataType, is(instanceOf(ArrayType.class)));
assertType(metadataType, List.class);
MetadataType itemMetadataType = ((ArrayType) metadataType).getType();
assertType(itemMetadataType, listItemType);
}
use of org.mule.metadata.api.model.ArrayType in project mule by mulesoft.
the class JavaDeclarationDelegateTestCase method assertTestModuleOperations.
private void assertTestModuleOperations(ExtensionDeclaration extensionDeclaration) throws Exception {
assertThat(extensionDeclaration.getOperations(), hasSize(48));
WithOperationsDeclaration withOperationsDeclaration = extensionDeclaration.getConfigurations().get(0);
assertThat(withOperationsDeclaration.getOperations().size(), is(15));
assertOperation(withOperationsDeclaration, SAY_MY_NAME_OPERATION, "");
assertOperation(withOperationsDeclaration, NAME_AS_STREAM, "");
assertOperation(withOperationsDeclaration, GET_ENEMY_OPERATION, "");
assertOperation(withOperationsDeclaration, GET_ALL_ENEMIES_OPERATION, "");
assertOperation(extensionDeclaration, KILL_OPERATION, "");
assertOperation(extensionDeclaration, KILL_CUSTOM_OPERATION, "");
assertOperation(extensionDeclaration, KILL_WITH_WEAPON, "");
assertOperation(extensionDeclaration, KILL_WITH_RICINS, "");
assertOperation(extensionDeclaration, KILL_WITH_MULTIPLES_WEAPONS, "");
assertOperation(extensionDeclaration, KILL_WITH_MULTIPLE_WILDCARD_WEAPONS, "");
assertOperation(withOperationsDeclaration, DIE, "");
assertOperation(withOperationsDeclaration, LAUNDER_MONEY, "");
assertOperation(extensionDeclaration, INJECTED_EXTENSION_MANAGER, "");
assertOperation(extensionDeclaration, ALIAS, "");
assertOperation(withOperationsDeclaration, CALL_SAUL, "");
assertOperation(extensionDeclaration, CALL_GUS_FRING, "");
assertOperation(withOperationsDeclaration, GET_SAUL_PHONE, "");
assertOperation(extensionDeclaration, GET_MEDICAL_HISTORY, "");
assertOperation(extensionDeclaration, GET_GRAMS_IN_STORAGE, "");
assertOperation(extensionDeclaration, APPROVE_INVESTMENT, "");
assertOperation(withOperationsDeclaration, GET_PAGED_PERSONAL_INFO_OPERATION, "");
assertOperation(withOperationsDeclaration, EMPTY_PAGED_OPERATION, "");
assertOperation(withOperationsDeclaration, FAILING_PAGED_OPERATION, "");
assertOperation(withOperationsDeclaration, CONNECTION_PAGED_OPERATION, "");
assertOperation(extensionDeclaration, PROCESS_INFO, "");
assertOperation(extensionDeclaration, PROCESS_WEAPON, "");
assertOperation(extensionDeclaration, PROCESS_WEAPON_LIST, "");
assertOperation(extensionDeclaration, PROCESS_WEAPON_WITH_DEFAULT_VALUE, "");
assertOperation(extensionDeclaration, FAIL_TO_EXECUTE, "");
assertOperation(extensionDeclaration, THROW_ERROR, "");
assertOperation(extensionDeclaration, BY_PASS_WEAPON, "");
assertOperation(extensionDeclaration, ECHO_AN_OPERATION_WITH_ALIAS, "");
assertOperation(extensionDeclaration, "executeRemoteKill", "");
OperationDeclaration operation = getOperation(withOperationsDeclaration, SAY_MY_NAME_OPERATION);
assertThat(operation, is(notNullValue()));
assertThat(operation.getAllParameters().isEmpty(), is(true));
operation = getOperation(withOperationsDeclaration, GET_ENEMY_OPERATION);
assertThat(operation, is(notNullValue()));
assertThat(operation.getAllParameters(), hasSize(1));
assertThat(operation.getOutput().getType(), equalTo(STRING_TYPE));
assertThat(operation.getOutputAttributes().getType(), equalTo(toMetadataType(IntegerAttributes.class)));
assertParameter(operation.getAllParameters(), "index", "", INT_TYPE, false, SUPPORTED, "0");
assertConnected(operation, false);
assertTransactional(operation, false);
operation = getOperation(withOperationsDeclaration, GET_ALL_ENEMIES_OPERATION);
assertThat(operation, is(notNullValue()));
assertThat(operation.getAllParameters(), hasSize(0));
assertThat(operation.getOutput().getType(), is(instanceOf(ArrayType.class)));
assertMessageType(((ArrayType) operation.getOutput().getType()).getType(), STRING_TYPE, TYPE_LOADER.load(IntegerAttributes.class));
assertThat(operation.getOutputAttributes().getType(), is(instanceOf(VoidType.class)));
assertConnected(operation, false);
assertTransactional(operation, false);
operation = getOperation(extensionDeclaration, KILL_OPERATION);
assertThat(operation, is(notNullValue()));
assertThat(operation.getAllParameters(), hasSize(2));
assertThat(operation.getOutput().getType(), equalTo(STRING_TYPE));
assertThat(operation.getOutputAttributes().getType(), is(instanceOf(VoidType.class)));
assertParameter(operation.getAllParameters(), "victim", "", STRING_TYPE, false, SUPPORTED, "#[payload]");
assertParameter(operation.getAllParameters(), "goodbyeMessage", "", STRING_TYPE, true, SUPPORTED, null);
assertConnected(operation, false);
assertTransactional(operation, false);
operation = getOperation(extensionDeclaration, KILL_WITH_WEAPON);
assertThat(operation, is(notNullValue()));
assertThat(operation.getAllParameters(), hasSize(3));
assertParameter(operation.getAllParameters(), "weapon", "", WEAPON_TYPE, true, SUPPORTED, null);
assertParameter(operation.getAllParameters(), "type", "", toMetadataType(WeaponType.class), true, SUPPORTED, null);
assertParameter(operation.getAllParameters(), "attributesOfWeapon", "", toMetadataType(Weapon.WeaponAttributes.class), true, SUPPORTED, null);
assertConnected(operation, false);
assertTransactional(operation, false);
operation = getOperation(extensionDeclaration, KILL_WITH_RICINS);
assertThat(operation, is(notNullValue()));
assertThat(operation.getAllParameters(), hasSize(1));
assertParameter(operation.getAllParameters(), "ricins", "", arrayOf(List.class, objectTypeBuilder(Ricin.class)), false, SUPPORTED, "#[payload]");
assertConnected(operation, false);
assertTransactional(operation, false);
operation = getOperation(extensionDeclaration, KILL_WITH_MULTIPLES_WEAPONS);
assertThat(operation, is(notNullValue()));
assertThat(operation.getAllParameters(), hasSize(1));
assertParameter(operation.getAllParameters(), "weapons", "", arrayOf(List.class, objectTypeBuilder(Weapon.class)), false, SUPPORTED, "#[payload]");
assertConnected(operation, false);
assertTransactional(operation, false);
operation = getOperation(extensionDeclaration, KILL_WITH_MULTIPLE_WILDCARD_WEAPONS);
assertThat(operation, is(notNullValue()));
assertThat(operation.getAllParameters(), hasSize(1));
assertParameter(operation.getAllParameters(), "wildCardWeapons", "", arrayOf(List.class, objectTypeBuilder(Weapon.class)), true, SUPPORTED, null);
assertConnected(operation, false);
assertTransactional(operation, false);
operation = getOperation(extensionDeclaration, KILL_CUSTOM_OPERATION);
assertThat(operation, is(notNullValue()));
assertThat(operation.getAllParameters(), hasSize(2));
assertParameter(operation.getAllParameters(), "victim", "", STRING_TYPE, false, SUPPORTED, "#[payload]");
assertParameter(operation.getAllParameters(), "goodbyeMessage", "", STRING_TYPE, true, SUPPORTED, null);
assertConnected(operation, false);
assertTransactional(operation, false);
operation = getOperation(withOperationsDeclaration, LAUNDER_MONEY);
assertParameter(operation.getAllParameters(), "amount", "", toMetadataType(long.class), true, SUPPORTED, null);
assertConnected(operation, false);
assertTransactional(operation, false);
operation = getOperation(extensionDeclaration, INJECTED_EXTENSION_MANAGER);
assertThat(operation, is(notNullValue()));
assertThat(operation.getAllParameters().isEmpty(), is(true));
assertConnected(operation, false);
assertTransactional(operation, false);
operation = getOperation(extensionDeclaration, ALIAS);
assertParameter(operation.getAllParameters(), "greeting", "", STRING_TYPE, true, SUPPORTED, null);
assertParameter(operation.getAllParameters(), "myName", "", STRING_TYPE, false, SUPPORTED, HEISENBERG);
assertParameter(operation.getAllParameters(), "age", "", toMetadataType(Integer.class), false, SUPPORTED, AGE);
assertConnected(operation, false);
assertTransactional(operation, false);
operation = getOperation(extensionDeclaration, KNOCK);
assertParameter(operation.getAllParameters(), "knockedDoor", "", toMetadataType(KnockeableDoor.class), true, SUPPORTED, null);
assertConnected(operation, false);
assertTransactional(operation, false);
operation = getOperation(extensionDeclaration, KNOCK_MANY);
assertParameter(operation.getAllParameters(), "doors", "", arrayOf(List.class, objectTypeBuilder(KnockeableDoor.class)), true, SUPPORTED, null);
assertConnected(operation, false);
assertTransactional(operation, false);
operation = getOperation(withOperationsDeclaration, CALL_SAUL);
assertThat(operation.getAllParameters(), is(empty()));
assertConnected(operation, true);
assertTransactional(operation, false);
operation = getOperation(extensionDeclaration, CURE_CANCER);
assertThat(operation.getAllParameters(), is(empty()));
assertConnected(operation, false);
assertTransactional(operation, false);
java.util.Optional<ExceptionHandlerFactory> exceptionEnricherFactory = operation.getModelProperty(ExceptionHandlerModelProperty.class).map(ExceptionHandlerModelProperty::getExceptionHandlerFactory);
assertThat(exceptionEnricherFactory.isPresent(), is(true));
assertThat(exceptionEnricherFactory.get().createHandler(), instanceOf(CureCancerExceptionEnricher.class));
operation = getOperation(extensionDeclaration, GET_MEDICAL_HISTORY);
assertParameter(operation.getAllParameters(), "healthByYear", "", TYPE_BUILDER.objectType().with(new ClassInformationAnnotation(Map.class, asList(String.class, HealthStatus.class))).openWith(TYPE_LOADER.load(HealthStatus.class)).build(), true, SUPPORTED, null);
assertConnected(operation, false);
assertTransactional(operation, false);
operation = getOperation(extensionDeclaration, GET_GRAMS_IN_STORAGE);
assertThat(operation, is(notNullValue()));
assertParameter(operation.getAllParameters(), "grams", "", TYPE_LOADER.load(int[][].class), false, SUPPORTED, "#[payload]");
assertThat(operation.getOutput().getType(), is(TYPE_LOADER.load(int[][].class)));
assertConnected(operation, false);
assertTransactional(operation, false);
operation = getOperation(extensionDeclaration, APPROVE_INVESTMENT);
assertThat(operation, is(notNullValue()));
assertParameter(operation.getAllParameters(), "investment", "", TYPE_LOADER.load(Investment.class), true, SUPPORTED, null);
assertThat(getType(operation.getOutput().getType()), equalTo(getType(TYPE_LOADER.load(Investment.class))));
assertConnected(operation, false);
assertTransactional(operation, false);
operation = getOperation(extensionDeclaration, IGNORED_OPERATION);
assertThat(operation, is(nullValue()));
operation = getOperation(withOperationsDeclaration, GET_PAGED_PERSONAL_INFO_OPERATION);
assertThat(operation.getModelProperty(PagedOperationModelProperty.class).isPresent(), is(true));
assertThat(operation.getOutput().getType(), is(instanceOf(ArrayType.class)));
ArrayType outputType = (ArrayType) operation.getOutput().getType();
assertThat(outputType.getType(), is(TYPE_LOADER.load(PersonalInfo.class)));
assertConnected(operation, true);
assertTransactional(operation, false);
operation = getOperation(extensionDeclaration, PROCESS_INFO);
assertThat(operation, is(notNullValue()));
assertConnected(operation, false);
assertTransactional(operation, false);
assertParameter(operation.getAllParameters(), "sales", "", TYPE_LOADER.load(new TypeToken<Map<String, SaleInfo>>() {
}.getType()), true, SUPPORTED, null);
operation = getOperation(extensionDeclaration, PROCESS_WEAPON);
assertThat(operation, is(notNullValue()));
assertParameter(operation.getAllParameters(), "weapon", "", WEAPON_TYPE, false, SUPPORTED, null);
assertConnected(operation, false);
operation = getOperation(extensionDeclaration, PROCESS_WEAPON_LIST);
assertThat(operation, is(notNullValue()));
assertParameter(operation.getAllParameters(), "weapons", "", TYPE_LOADER.load(new TypeToken<List<Weapon>>() {
}.getType()), false, SUPPORTED, null);
assertConnected(operation, false);
assertTransactional(operation, false);
operation = getOperation(extensionDeclaration, PROCESS_WEAPON_WITH_DEFAULT_VALUE);
assertThat(operation, is(notNullValue()));
assertParameter(operation.getAllParameters(), "weapon", "", WEAPON_TYPE, false, SUPPORTED, PAYLOAD);
assertConnected(operation, false);
assertTransactional(operation, false);
operation = getOperation(extensionDeclaration, "processWeaponListWithDefaultValue");
assertThat(operation, is(notNullValue()));
assertParameter(operation.getAllParameters(), "weapons", "", TYPE_LOADER.load(new TypeToken<List<Weapon>>() {
}.getType()), false, SUPPORTED, PAYLOAD);
assertConnected(operation, false);
assertTransactional(operation, false);
operation = getOperation(extensionDeclaration, "processAddressBook");
assertThat(operation, is(notNullValue()));
assertParameter(operation.getAllParameters(), "phoneNumbers", "", TYPE_LOADER.load(new TypeToken<List<String>>() {
}.getType()), true, SUPPORTED, null);
assertConnected(operation, false);
assertTransactional(operation, false);
operation = getOperation(extensionDeclaration, FAIL_TO_EXECUTE);
assertThat(operation, is(notNullValue()));
assertThat(operation.getAllParameters(), is(empty()));
assertThat(operation.getOutput().getType(), is(instanceOf(VoidType.class)));
assertConnected(operation, false);
assertTransactional(operation, false);
operation = getOperation(extensionDeclaration, THROW_ERROR);
assertThat(operation, is(notNullValue()));
assertThat(operation.getAllParameters(), is(empty()));
assertThat(operation.getOutput().getType(), is(instanceOf(VoidType.class)));
assertConnected(operation, false);
assertTransactional(operation, false);
operation = getOperation(extensionDeclaration, BY_PASS_WEAPON);
assertThat(operation, is(notNullValue()));
assertParameter(operation.getAllParameters(), "awesomeWeapon", "", WEAPON_TYPE, true, SUPPORTED, null);
assertParameter(operation.getAllParameters(), "awesomeName", "", STRING_TYPE, true, SUPPORTED, null);
assertThat(operation.getOutput().getType(), is(instanceOf(ObjectType.class)));
assertConnected(operation, false);
assertTransactional(operation, false);
}
use of org.mule.metadata.api.model.ArrayType in project mule by mulesoft.
the class ConfigurationBasedElementModelFactory method addElementParameter.
private void addElementParameter(Multimap<ComponentIdentifier, ComponentConfiguration> innerComponents, Map<String, String> parameters, DslElementSyntax groupDsl, DslElementModel.Builder<ParameterGroupModel> groupElementBuilder, ParameterModel paramModel) {
groupDsl.getContainedElement(paramModel.getName()).ifPresent(paramDsl -> {
if (isInfrastructure(paramModel)) {
handleInfrastructure(paramModel, paramDsl, innerComponents, parameters, groupElementBuilder);
return;
}
ComponentConfiguration paramComponent = getSingleComponentConfiguration(innerComponents, getIdentifier(paramDsl));
if (paramDsl.isWrapped()) {
resolveWrappedElement(groupElementBuilder, paramModel, paramDsl, paramComponent);
return;
}
String value = paramDsl.supportsAttributeDeclaration() ? parameters.get(paramDsl.getAttributeName()) : null;
Optional<String> defaultValue = getDefaultValue(paramModel);
if (paramComponent != null || !isBlank(value) || defaultValue.isPresent()) {
DslElementModel.Builder<ParameterModel> paramElementBuilder = DslElementModel.<ParameterModel>builder().withModel(paramModel).withDsl(paramDsl);
if (paramComponent != null && !isContent(paramModel)) {
paramElementBuilder.withConfig(paramComponent);
paramModel.getType().accept(new MetadataTypeVisitor() {
@Override
public void visitArrayType(ArrayType arrayType) {
MetadataType itemType = arrayType.getType();
paramDsl.getGeneric(itemType).ifPresent(itemdsl -> {
ComponentIdentifier itemIdentifier = getIdentifier(itemdsl).get();
paramComponent.getNestedComponents().forEach(c -> {
if (c.getIdentifier().equals(itemIdentifier)) {
itemType.accept(getComponentChildVisitor(paramElementBuilder, c, itemType, VALUE_ATTRIBUTE_NAME, itemdsl, defaultValue, new ArrayDeque<>()));
}
});
});
}
@Override
public void visitObject(ObjectType objectType) {
if (isMap(objectType)) {
populateMapEntries(objectType, paramDsl, paramElementBuilder, paramComponent);
return;
}
populateObjectFields(objectType, paramComponent, paramDsl, paramElementBuilder, new ArrayDeque<>());
}
});
} else {
if (isBlank(value)) {
if (paramComponent != null && paramComponent.getValue().isPresent() && !isBlank(paramComponent.getValue().get())) {
value = paramComponent.getValue().get().trim();
} else if (defaultValue.isPresent()) {
value = defaultValue.get();
paramElementBuilder.isExplicitInDsl(false);
}
}
paramElementBuilder.withValue(value);
}
groupElementBuilder.containing(paramElementBuilder.build());
}
});
}
use of org.mule.metadata.api.model.ArrayType in project mule by mulesoft.
the class DeclarationBasedElementModelFactory method createList.
private void createList(ParameterListValue list, DslElementSyntax listDsl, Object model, ArrayType listType, InternalComponentConfiguration.Builder parentConfig, DslElementModel.Builder parentElement) {
final DslElementModel.Builder listElement = DslElementModel.builder().withModel(model).withDsl(listDsl);
final InternalComponentConfiguration.Builder listConfig = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(listDsl));
final MetadataType itemType = listType.getType();
listDsl.getGeneric(itemType).ifPresent(itemDsl -> list.getValues().forEach(value -> createListItemConfig(itemType, value, itemDsl, listConfig, listElement)));
ComponentConfiguration result = listConfig.build();
parentConfig.withNestedComponent(result);
parentElement.containing(listElement.withConfig(result).build());
}
use of org.mule.metadata.api.model.ArrayType in project mule by mulesoft.
the class IntrospectionUtils method collectRelativeClasses.
/**
* 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
* @param extensionClassLoader extension class loader
* @return {@link Set<Class<?>>} with the classes reachable from the {@code type}
*/
public static Set<Class<?>> collectRelativeClasses(MetadataType type, ClassLoader extensionClassLoader) {
Set<Class<?>> 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 Class<Object> clazz = getType(objectType).orElse(null);
if (clazz == null || relativeClasses.contains(clazz)) {
return;
}
Optional<ClassInformationAnnotation> classInformation = objectType.getAnnotation(ClassInformationAnnotation.class);
if (classInformation.isPresent()) {
classInformation.get().getGenericTypes().forEach(generic -> relativeClasses.add(loadClass(generic, extensionClassLoader)));
}
relativeClasses.add(clazz);
objectType.getFields().stream().forEach(objectFieldType -> objectFieldType.accept(this));
objectType.getOpenRestriction().ifPresent(t -> t.accept(this));
}
@Override
public void visitString(StringType stringType) {
if (stringType.getMetadataFormat() == JAVA && isEnum(stringType)) {
getType(stringType).ifPresent(relativeClasses::add);
}
}
});
return relativeClasses;
}
Aggregations