use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class CoreExtensionModelTestCase method verifyOnError.
void verifyOnError(NestedRouteModel route) {
List<ParameterModel> allParameterModels = route.getAllParameterModels();
assertThat(allParameterModels, hasSize(4));
ParameterModel when = allParameterModels.get(0);
assertThat(when.getName(), is("when"));
assertThat(when.getType(), is(instanceOf(DefaultStringType.class)));
assertThat(when.getExpressionSupport(), is(SUPPORTED));
assertThat(when.isRequired(), is(false));
ParameterModel type = allParameterModels.get(1);
assertErrorType(type, "type");
ParameterModel log = allParameterModels.get(2);
assertThat(log.getName(), is("logException"));
assertThat(log.getType(), is(instanceOf(DefaultBooleanType.class)));
assertThat(log.getExpressionSupport(), is(SUPPORTED));
assertThat(log.isRequired(), is(false));
ParameterModel notifications = allParameterModels.get(3);
assertThat(notifications.getName(), is("enableNotifications"));
assertThat(notifications.getType(), is(instanceOf(DefaultBooleanType.class)));
assertThat(notifications.getExpressionSupport(), is(NOT_SUPPORTED));
assertThat(notifications.isRequired(), is(false));
assertThat(notifications.getDefaultValue(), is(true));
}
use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class CoreExtensionModelTestCase method firstSuccessful.
@Test
public void firstSuccessful() {
final ConstructModel tryModel = coreExtensionModel.getConstructModel("firstSuccessful").get();
List<ParameterModel> allParameterModels = tryModel.getAllParameterModels();
assertThat(allParameterModels, hasSize(0));
}
use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class CoreExtensionModelTestCase method scheduler.
@Test
public void scheduler() {
final SourceModel schedulerModel = coreExtensionModel.getSourceModel("scheduler").get();
assertThat(schedulerModel.getStereotype(), is(SOURCE));
assertThat(schedulerModel.getErrorModels(), empty());
assertThat(schedulerModel.hasResponse(), is(false));
assertThat(schedulerModel.getOutput().getType(), instanceOf(DefaultObjectType.class));
assertThat(schedulerModel.getOutput().hasDynamicType(), is(false));
assertThat(schedulerModel.getOutputAttributes().getType(), instanceOf(DefaultObjectType.class));
assertThat(schedulerModel.getOutputAttributes().hasDynamicType(), is(false));
final List<ParameterModel> paramModels = schedulerModel.getAllParameterModels();
assertThat(paramModels, hasSize(1));
assertSchedulingStrategy(paramModels.get(0));
}
use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class ExtensionDefinitionParser method parseCollectionParameter.
/**
* Registers a definition for a {@link ParameterModel} which represents an {@link ArrayType}
*
* @param key the key that the parsed value should have on the parsed parameter's map
* @param name the parameter's name
* @param arrayType the parameter's {@link ArrayType}
* @param defaultValue the parameter's default value
* @param expressionSupport the parameter's {@link ExpressionSupport}
* @param required whether the parameter is required
*/
protected void parseCollectionParameter(String key, String name, ArrayType arrayType, Object defaultValue, ExpressionSupport expressionSupport, boolean required, DslElementSyntax parameterDsl, Set<ModelProperty> modelProperties) {
parseAttributeParameter(key, name, arrayType, defaultValue, expressionSupport, required, modelProperties);
Class<?> collectionType = ExtensionMetadataTypeUtils.getType(arrayType).orElse(null);
if (Set.class.equals(collectionType)) {
collectionType = HashSet.class;
} else if (Collection.class.equals(collectionType) || Iterable.class.equals(collectionType) || collectionType == null) {
collectionType = List.class;
}
final String collectionElementName = parameterDsl.getElementName();
addParameter(getChildKey(key), fromChildConfiguration(collectionType).withWrapperIdentifier(collectionElementName));
addDefinition(baseDefinitionBuilder.withIdentifier(collectionElementName).withTypeDefinition(fromType(collectionType)).build());
Optional<DslElementSyntax> collectionItemDsl = parameterDsl.getGeneric(arrayType.getType());
if (parameterDsl.supportsChildDeclaration() && collectionItemDsl.isPresent()) {
String itemIdentifier = collectionItemDsl.get().getElementName();
String itemNamespace = collectionItemDsl.get().getPrefix();
arrayType.getType().accept(new BasicTypeMetadataVisitor() {
private void addBasicTypeDefinition(MetadataType metadataType) {
Builder itemDefinitionBuilder = baseDefinitionBuilder.withIdentifier(itemIdentifier).withNamespace(itemNamespace).withTypeDefinition(fromType(ExtensionMetadataTypeUtils.getType(metadataType).orElse(Object.class))).withTypeConverter(value -> resolverOf(name, metadataType, value, getDefaultValue(metadataType).orElse(null), getExpressionSupport(metadataType), false, emptySet()));
addDefinition(itemDefinitionBuilder.build());
}
@Override
protected void visitBasicType(MetadataType metadataType) {
addBasicTypeDefinition(metadataType);
}
@Override
public void visitDate(DateType dateType) {
addBasicTypeDefinition(dateType);
}
@Override
public void visitDateTime(DateTimeType dateTimeType) {
addBasicTypeDefinition(dateTimeType);
}
@Override
public void visitObject(ObjectType objectType) {
if (isMap(objectType)) {
return;
}
DslElementSyntax itemDsl = collectionItemDsl.get();
if ((itemDsl.supportsTopLevelDeclaration() || itemDsl.supportsChildDeclaration()) && !parsingContext.isRegistered(itemDsl.getElementName(), itemDsl.getPrefix())) {
try {
parsingContext.registerObjectType(itemDsl.getElementName(), itemDsl.getPrefix(), objectType);
new ObjectTypeParameterParser(baseDefinitionBuilder, objectType, getContextClassLoader(), dslResolver, parsingContext).parse().forEach(definition -> addDefinition(definition));
} catch (ConfigurationException e) {
throw new MuleRuntimeException(createStaticMessage("Could not create parser for collection complex type"), e);
}
}
}
});
}
}
use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class ExportedPackagesValidatorTestCase method setUpInvalidExtension.
private void setUpInvalidExtension() {
OutputModel appleList = mockOutputModel(InternalTestClass.class);
OperationModel firstOperation = mockOperationModel(appleList, mockOutputModel(InternalTestClass.class));
withMethod(firstOperation, getApiMethods(InternalTestClass.class).stream().filter(m -> m.getName().equals("someOperation")).findFirst());
ParameterModel parameter = mockParameterModel(Shape.class);
OutputModel resultList = mockOutputModel(new TypeToken<List<Result<Apple, VeganAttributes>>>() {
}.getType());
OperationModel secondOperation = mockOperationModel(resultList, mockOutputModel(List.class), parameter);
withMethod(secondOperation, empty());
when(extensionModel.getOperationModels()).thenReturn(asList(firstOperation, secondOperation));
visitableMock(firstOperation, secondOperation);
}
Aggregations