Search in sources :

Example 56 with OperationModel

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));
}
Also used : StereotypeModel(org.mule.runtime.api.meta.model.stereotype.StereotypeModel) Arrays(java.util.Arrays) ImportedTypeModel(org.mule.runtime.api.meta.model.ImportedTypeModel) HeisenbergOperations(org.mule.test.heisenberg.extension.HeisenbergOperations) VALIDATOR(org.mule.runtime.extension.api.stereotype.MuleStereotypes.VALIDATOR) HeisenbergScopes(org.mule.test.heisenberg.extension.HeisenbergScopes) DROP(org.mule.runtime.extension.api.runtime.source.BackPressureMode.DROP) VALIDATOR_DEFINITION(org.mule.runtime.extension.api.stereotype.MuleStereotypes.VALIDATOR_DEFINITION) Export(org.mule.runtime.extension.api.annotation.Export) KillingOperations(org.mule.test.heisenberg.extension.KillingOperations) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) CPU_LITE(org.mule.runtime.api.meta.model.operation.ExecutionType.CPU_LITE) Arrays.asList(java.util.Arrays.asList) OnException(org.mule.runtime.extension.api.annotation.OnException) ClassTypeLoader(org.mule.metadata.api.ClassTypeLoader) ObjectStore(org.mule.runtime.api.store.ObjectStore) MuleExtensionUtils.loadExtension(org.mule.runtime.module.extension.api.util.MuleExtensionUtils.loadExtension) SELECT(org.mule.runtime.api.meta.Category.SELECT) EmpireStereotype(org.mule.test.heisenberg.extension.stereotypes.EmpireStereotype) HeisenbergConnectionExceptionEnricher(org.mule.test.heisenberg.extension.exception.HeisenbergConnectionExceptionEnricher) CarDealer(org.mule.test.heisenberg.extension.model.CarDealer) EnumAnnotation(org.mule.metadata.api.annotation.EnumAnnotation) StringType(org.mule.metadata.api.model.StringType) Sources(org.mule.runtime.extension.api.annotation.Sources) MarvelExtension(org.mule.test.marvel.MarvelExtension) Operations(org.mule.runtime.extension.api.annotation.Operations) StereotypeModel(org.mule.runtime.api.meta.model.stereotype.StereotypeModel) Extension(org.mule.runtime.extension.api.annotation.Extension) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) Ricin(org.mule.test.heisenberg.extension.model.Ricin) ExtensionsTypeLoaderFactory(org.mule.runtime.extension.api.declaration.type.ExtensionsTypeLoaderFactory) ExternalLibraryModel(org.mule.runtime.api.meta.model.ExternalLibraryModel) PaulMcCartneySource(org.mule.test.vegan.extension.PaulMcCartneySource) EmitsResponse(org.mule.runtime.extension.api.annotation.source.EmitsResponse) BackPressure(org.mule.runtime.extension.api.annotation.source.BackPressure) SecureHeisenbergConnectionProvider(org.mule.test.heisenberg.extension.SecureHeisenbergConnectionProvider) AbstractMuleTestCase(org.mule.tck.junit4.AbstractMuleTestCase) PAYLOAD(org.mule.runtime.extension.api.annotation.param.Optional.PAYLOAD) Matchers.hasSize(org.hamcrest.Matchers.hasSize) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) CONFIG_NAME(org.mule.test.marvel.ironman.IronMan.CONFIG_NAME) HasExternalLibraries(org.mule.runtime.api.meta.model.HasExternalLibraries) Investment(org.mule.test.heisenberg.extension.model.Investment) Test(org.junit.Test) HEISENBERG_LIB_DESCRIPTION(org.mule.test.heisenberg.extension.HeisenbergExtension.HEISENBERG_LIB_DESCRIPTION) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) BLOCKING(org.mule.runtime.api.meta.model.operation.ExecutionType.BLOCKING) VeganExtension(org.mule.test.vegan.extension.VeganExtension) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) MoneyLaunderingOperation(org.mule.test.heisenberg.extension.MoneyLaunderingOperation) STREAMING_STRATEGY_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.STREAMING_STRATEGY_PARAMETER_NAME) Streaming(org.mule.runtime.extension.api.annotation.Streaming) MediaType(org.mule.runtime.extension.api.annotation.param.MediaType) HeisenbergErrors(org.mule.test.heisenberg.extension.HeisenbergErrors) Reference(org.mule.runtime.api.util.Reference) HEISENBERG_LIB_FILE_NAME(org.mule.test.heisenberg.extension.HeisenbergExtension.HEISENBERG_LIB_FILE_NAME) NOT_SUPPORTED(org.mule.runtime.api.meta.ExpressionSupport.NOT_SUPPORTED) CoreMatchers.is(org.hamcrest.CoreMatchers.is) TEXT_PLAIN(org.mule.runtime.extension.api.annotation.param.MediaType.TEXT_PLAIN) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Assert.assertThat(org.junit.Assert.assertThat) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) APPLE(org.mule.test.vegan.extension.VeganExtension.APPLE) SmallTest(org.mule.tck.size.SmallTest) WAIT(org.mule.runtime.extension.api.runtime.source.BackPressureMode.WAIT) MetadataTypeUtils.getTypeId(org.mule.metadata.api.utils.MetadataTypeUtils.getTypeId) HEISENBERG(org.mule.test.heisenberg.extension.HeisenbergExtension.HEISENBERG) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) SubTypeMapping(org.mule.runtime.extension.api.annotation.SubTypeMapping) StreamingStrategyTypeBuilder(org.mule.runtime.extension.api.declaration.type.StreamingStrategyTypeBuilder) Weapon(org.mule.test.heisenberg.extension.model.Weapon) ConnectionProviders(org.mule.runtime.extension.api.annotation.connectivity.ConnectionProviders) HeisenbergException(org.mule.test.heisenberg.extension.exception.HeisenbergException) PROCESSOR_DEFINITION(org.mule.runtime.extension.api.stereotype.MuleStereotypes.PROCESSOR_DEFINITION) BACK_PRESSURE_STRATEGY_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.BACK_PRESSURE_STRATEGY_PARAMETER_NAME) PRIMARY_CONTENT(org.mule.runtime.api.meta.model.parameter.ParameterRole.PRIMARY_CONTENT) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Optional(java.util.Optional) HeisenbergRouters(org.mule.test.heisenberg.extension.HeisenbergRouters) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) Alias(org.mule.runtime.extension.api.annotation.Alias) HeisenbergSource(org.mule.test.heisenberg.extension.HeisenbergSource) CPU_INTENSIVE(org.mule.runtime.api.meta.model.operation.ExecutionType.CPU_INTENSIVE) ExpectedException.none(org.junit.rules.ExpectedException.none) HeisenbergConnectionProvider(org.mule.test.heisenberg.extension.HeisenbergConnectionProvider) HEISENBERG_LIB_CLASS_NAME(org.mule.test.heisenberg.extension.HeisenbergExtension.HEISENBERG_LIB_CLASS_NAME) NoSuchElementException(java.util.NoSuchElementException) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) ExpectedException(org.junit.rules.ExpectedException) ErrorTypes(org.mule.runtime.extension.api.annotation.error.ErrorTypes) CoreMatchers.sameInstance(org.hamcrest.CoreMatchers.sameInstance) OBJECT_STORE(org.mule.runtime.extension.api.stereotype.MuleStereotypes.OBJECT_STORE) HEISENBERG_LIB_NAME(org.mule.test.heisenberg.extension.HeisenbergExtension.HEISENBERG_LIB_NAME) BANANA(org.mule.test.vegan.extension.VeganExtension.BANANA) ExtensionModelUtils(org.mule.runtime.extension.api.util.ExtensionModelUtils) Collectors.toList(java.util.stream.Collectors.toList) Rule(org.junit.Rule) PROCESSOR(org.mule.runtime.extension.api.stereotype.MuleStereotypes.PROCESSOR) CarWash(org.mule.test.heisenberg.extension.model.CarWash) FAIL(org.mule.runtime.extension.api.runtime.source.BackPressureMode.FAIL) ObjectStore(org.mule.runtime.api.store.ObjectStore) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) ImportedTypeModel(org.mule.runtime.api.meta.model.ImportedTypeModel) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 57 with OperationModel

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));
}
Also used : StereotypeModel(org.mule.runtime.api.meta.model.stereotype.StereotypeModel) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 58 with OperationModel

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);
}
Also used : HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ConnectableComponentModel(org.mule.runtime.api.meta.model.ConnectableComponentModel) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) MetadataResolverFactory(org.mule.runtime.extension.api.metadata.MetadataResolverFactory) HasSourceModels(org.mule.runtime.api.meta.model.source.HasSourceModels) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Example 59 with OperationModel

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"));
}
Also used : OperationElementDeclaration(org.mule.runtime.app.declaration.api.OperationElementDeclaration) ElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ElementDeclarer) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test)

Example 60 with OperationModel

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();
}
Also used : SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ImmutableSourceModel(org.mule.runtime.extension.api.model.source.ImmutableSourceModel) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) ImmutableConstructModel(org.mule.runtime.extension.api.model.construct.ImmutableConstructModel) ImmutableOperationModel(org.mule.runtime.extension.api.model.operation.ImmutableOperationModel) ImmutableSourceModel(org.mule.runtime.extension.api.model.source.ImmutableSourceModel) Reference(org.mule.runtime.api.util.Reference) ComponentModelVisitor(org.mule.runtime.api.meta.model.ComponentModelVisitor) ImmutableConstructModel(org.mule.runtime.extension.api.model.construct.ImmutableConstructModel) ImmutableOutputModel(org.mule.runtime.extension.api.model.ImmutableOutputModel) OutputModel(org.mule.runtime.api.meta.model.OutputModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) ImmutableOperationModel(org.mule.runtime.extension.api.model.operation.ImmutableOperationModel)

Aggregations

OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)96 Test (org.junit.Test)68 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)29 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)27 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)15 SmallTest (org.mule.tck.size.SmallTest)14 Optional (java.util.Optional)13 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)12 MetadataType (org.mule.metadata.api.model.MetadataType)11 List (java.util.List)10 Set (java.util.Set)9 ConnectionProviderModel (org.mule.runtime.api.meta.model.connection.ConnectionProviderModel)9 Optional.empty (java.util.Optional.empty)8 IdempotentExtensionWalker (org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker)8 ObjectType (org.mule.metadata.api.model.ObjectType)7 OutputModel (org.mule.runtime.api.meta.model.OutputModel)7 ConstructModel (org.mule.runtime.api.meta.model.construct.ConstructModel)7 HasOperationModels (org.mule.runtime.api.meta.model.operation.HasOperationModels)7 ExtensionWalker (org.mule.runtime.api.meta.model.util.ExtensionWalker)7 OperationComponentModelModelProperty (org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty)6