use of org.mule.runtime.api.meta.model.operation.OperationModel in project mule by mulesoft.
the class DefaultExtensionModelFactoryTestCase method objectStoreParameters.
@Test
public void objectStoreParameters() {
ExtensionModel extensionModel = createExtension(HeisenbergExtension.class);
OperationModel operationModel = extensionModel.getOperationModel("storeMoney").get();
ParameterModel parameter = operationModel.getAllParameterModels().stream().filter(p -> "objectStore".equals(p.getName())).findFirst().get();
StereotypeModel stereotype = parameter.getAllowedStereotypes().stream().filter(s -> s.getType().equals(OBJECT_STORE.getType())).findFirst().get();
assertThat(stereotype.getNamespace(), equalTo(OBJECT_STORE.getNamespace()));
Optional<ImportedTypeModel> typeImport = extensionModel.getImportedTypes().stream().filter(i -> getTypeId(i.getImportedType()).map(id -> ObjectStore.class.getName().equals(id)).orElse(false)).findFirst();
assertThat(typeImport.isPresent(), is(true));
}
use of org.mule.runtime.api.meta.model.operation.OperationModel in project mule by mulesoft.
the class DefaultExtensionModelFactoryTestCase method defaultStereotype.
@Test
public void defaultStereotype() {
ExtensionModel extensionModel = createExtension(VeganExtension.class);
OperationModel operation = extensionModel.getConfigurationModel(APPLE).get().getOperationModel("eatApple").get();
StereotypeModel stereotypeModel = operation.getStereotype();
assertThat(stereotypeModel.isAssignableTo(PROCESSOR), is(true));
assertThat(stereotypeModel.getType(), is(PROCESSOR_DEFINITION.getName()));
assertThat(stereotypeModel.getNamespace(), is("MULE"));
assertThat(stereotypeModel.getParent().isPresent(), is(false));
}
use of org.mule.runtime.api.meta.model.operation.OperationModel in project mule by mulesoft.
the class MetadataComponentModelValidator method validate.
@Override
public void validate(ExtensionModel extensionModel, ProblemsReporter problemsReporter) {
// TODO - MULE-14397 - Improve Dynamic Metadata Enricher to enrich without requiring Classes
// This is skipped if the extension is loaded with java, but it doesn't have classes which means AST Mode
Optional<ExtensionTypeDescriptorModelProperty> property = extensionModel.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
if (property.isPresent()) {
if (!property.get().getType().getDeclaringClass().isPresent()) {
return;
}
}
final Table<String, String, Class<?>> names = HashBasedTable.create();
new ExtensionWalker() {
@Override
public void onOperation(HasOperationModels owner, OperationModel model) {
validateComponent(model);
}
@Override
public void onSource(HasSourceModels owner, SourceModel model) {
validateComponent(model);
}
private void validateComponent(ConnectableComponentModel model) {
validateMetadataReturnType(extensionModel, model, problemsReporter);
MetadataResolverFactory resolverFactory = MuleExtensionUtils.getMetadataResolverFactory(model);
validateMetadataOutputAttributes(model, resolverFactory, problemsReporter);
validateMetadataKeyId(model, resolverFactory, problemsReporter);
validateCategoriesInScope(model, resolverFactory, problemsReporter);
validateResolversName(model, resolverFactory, names, problemsReporter);
}
}.walk(extensionModel);
}
use of org.mule.runtime.api.meta.model.operation.OperationModel in project mule by mulesoft.
the class DeclarationElementModelFactoryTestCase method testOperationDeclarationToElement.
@Test
public void testOperationDeclarationToElement() {
ElementDeclarer ext = ElementDeclarer.forExtension(EXTENSION_NAME);
OperationElementDeclaration declaration = ext.newOperation(OPERATION_NAME).withConfig(CONFIGURATION_NAME).withParameterGroup(newParameterGroup().withParameter(CONTENT_NAME, "#[{field: value}]").withParameter(BEHAVIOUR_NAME, "additional").getDeclaration()).getDeclaration();
DslElementModel<OperationModel> element = create(declaration);
assertThat(element.getModel(), is(operation));
assertThat(element.getContainedElements().size(), is(2));
assertThat(element.findElement(BEHAVIOUR_NAME).isPresent(), is(true));
assertThat(element.findElement(CONTENT_NAME).get().getConfiguration().get().getValue().get(), is("#[{field: value}]"));
assertThat(element.getConfiguration().get().getParameters().get(BEHAVIOUR_NAME), is("additional"));
}
use of org.mule.runtime.api.meta.model.operation.OperationModel in project mule by mulesoft.
the class MetadataMediator method getTypedModel.
/**
* Returns a {@link ComponentModel} with its types resolved.
*
* @param inputMetadataDescriptor {@link InputMetadataDescriptor} describes the input parameters of the component
* @param outputMetadataDescriptor {@link OutputMetadataDescriptor} describes the component output
* @return model with its types resolved by the metadata resolution process
*/
private T getTypedModel(InputMetadataDescriptor inputMetadataDescriptor, OutputMetadataDescriptor outputMetadataDescriptor) {
Reference<T> typedModel = new Reference<>();
component.accept(new ComponentModelVisitor() {
@Override
public void visit(ConstructModel constructModel) {
typedModel.set((T) new ImmutableConstructModel(constructModel.getName(), constructModel.getDescription(), resolveParameterGroupModelType(constructModel.getParameterGroupModels(), inputMetadataDescriptor.getAllParameters()), constructModel.getNestedComponents(), constructModel.allowsTopLevelDeclaration(), constructModel.getDisplayModel().orElse(null), constructModel.getErrorModels(), constructModel.getStereotype(), constructModel.getModelProperties()));
}
@Override
public void visit(OperationModel operationModel) {
OutputModel typedOutputModel = resolveOutputModelType(operationModel.getOutput(), outputMetadataDescriptor.getPayloadMetadata());
OutputModel typedAttributesModel = resolveOutputModelType(operationModel.getOutputAttributes(), outputMetadataDescriptor.getAttributesMetadata());
typedModel.set((T) new ImmutableOperationModel(operationModel.getName(), operationModel.getDescription(), resolveParameterGroupModelType(operationModel.getParameterGroupModels(), inputMetadataDescriptor.getAllParameters()), operationModel.getNestedComponents(), typedOutputModel, typedAttributesModel, operationModel.isBlocking(), operationModel.getExecutionType(), operationModel.requiresConnection(), operationModel.isTransactional(), operationModel.supportsStreaming(), operationModel.getDisplayModel().orElse(null), operationModel.getErrorModels(), operationModel.getStereotype(), operationModel.getModelProperties(), operationModel.getNotificationModels()));
}
@Override
public void visit(SourceModel sourceModel) {
OutputModel typedOutputModel = resolveOutputModelType(sourceModel.getOutput(), outputMetadataDescriptor.getPayloadMetadata());
OutputModel typedAttributesModel = resolveOutputModelType(sourceModel.getOutputAttributes(), outputMetadataDescriptor.getAttributesMetadata());
typedModel.set((T) new ImmutableSourceModel(sourceModel.getName(), sourceModel.getDescription(), sourceModel.hasResponse(), true, resolveParameterGroupModelType(sourceModel.getParameterGroupModels(), inputMetadataDescriptor.getAllParameters()), sourceModel.getNestedComponents(), typedOutputModel, typedAttributesModel, resolveSourceCallbackType(sourceModel.getSuccessCallback(), inputMetadataDescriptor.getAllParameters()), resolveSourceCallbackType(sourceModel.getErrorCallback(), inputMetadataDescriptor.getAllParameters()), resolveSourceCallbackType(sourceModel.getTerminateCallback(), inputMetadataDescriptor.getAllParameters()), sourceModel.requiresConnection(), sourceModel.isTransactional(), sourceModel.supportsStreaming(), sourceModel.getDisplayModel().orElse(null), sourceModel.getStereotype(), sourceModel.getErrorModels(), sourceModel.getModelProperties(), sourceModel.getNotificationModels()));
}
});
return typedModel.get();
}
Aggregations