Search in sources :

Example 6 with StereotypeModel

use of org.mule.runtime.api.meta.model.stereotype.StereotypeModel in project mule by mulesoft.

the class DefaultExtensionModelFactoryTestCase method validatorStereotype.

@Test
public void validatorStereotype() {
    ExtensionModel extensionModel = createExtension(HeisenbergExtension.class);
    OperationModel operation = extensionModel.getOperationModel("validateMoney").get();
    StereotypeModel stereotypeModel = operation.getStereotype();
    assertThat(stereotypeModel.isAssignableTo(PROCESSOR), is(true));
    assertThat(stereotypeModel.isAssignableTo(VALIDATOR), is(true));
    assertThat(stereotypeModel.getType(), is(VALIDATOR_DEFINITION.getName()));
    assertThat(stereotypeModel.getNamespace(), is(HEISENBERG.toUpperCase()));
    assertThat(stereotypeModel.getParent().get(), is(VALIDATOR));
}
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 7 with StereotypeModel

use of org.mule.runtime.api.meta.model.stereotype.StereotypeModel 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 8 with StereotypeModel

use of org.mule.runtime.api.meta.model.stereotype.StereotypeModel 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 9 with StereotypeModel

use of org.mule.runtime.api.meta.model.stereotype.StereotypeModel in project mule by mulesoft.

the class ParameterAllowedStereotypesDeclarionEnricher method getStereotypes.

private List<StereotypeModel> getStereotypes(AnnotatedElement element) {
    ConfigReferences references = element.getAnnotation(ConfigReferences.class);
    if (references != null) {
        return stream(references.value()).map(ref -> newStereotype(ref.name(), ref.namespace()).withParent(CONFIG).build()).collect(toList());
    }
    ConfigReference ref = element.getAnnotation(ConfigReference.class);
    if (ref != null) {
        return singletonList(newStereotype(ref.name(), ref.namespace()).withParent(CONFIG).build());
    }
    if (element.getAnnotation(FlowReference.class) != null) {
        return singletonList(FLOW);
    }
    if (element.getAnnotation(ObjectStoreReference.class) != null) {
        return singletonList(OBJECT_STORE);
    }
    return emptyList();
}
Also used : ConfigReferences(org.mule.runtime.extension.api.annotation.ConfigReferences) OBJECT_STORE(org.mule.runtime.extension.api.stereotype.MuleStereotypes.OBJECT_STORE) ParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration) StereotypeModel(org.mule.runtime.api.meta.model.stereotype.StereotypeModel) Collections.emptyList(java.util.Collections.emptyList) ExtensionLoadingContext(org.mule.runtime.extension.api.loader.ExtensionLoadingContext) FlowReference(org.mule.runtime.extension.api.annotation.param.reference.FlowReference) ImplementingParameterModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingParameterModelProperty) Collections.singletonList(java.util.Collections.singletonList) DeclaringMemberModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.DeclaringMemberModelProperty) CONFIG(org.mule.runtime.extension.api.stereotype.MuleStereotypes.CONFIG) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) StereotypeModelBuilder.newStereotype(org.mule.runtime.api.meta.model.stereotype.StereotypeModelBuilder.newStereotype) ConfigReference(org.mule.runtime.extension.api.annotation.param.reference.ConfigReference) ObjectStoreReference(org.mule.runtime.extension.api.annotation.param.reference.ObjectStoreReference) ParameterGroupDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclaration) Arrays.stream(java.util.Arrays.stream) FLOW(org.mule.runtime.extension.api.stereotype.MuleStereotypes.FLOW) IdempotentDeclarationWalker(org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker) AnnotatedElement(java.lang.reflect.AnnotatedElement) ObjectStoreReference(org.mule.runtime.extension.api.annotation.param.reference.ObjectStoreReference) ConfigReferences(org.mule.runtime.extension.api.annotation.ConfigReferences) ConfigReference(org.mule.runtime.extension.api.annotation.param.reference.ConfigReference) FlowReference(org.mule.runtime.extension.api.annotation.param.reference.FlowReference)

Example 10 with StereotypeModel

use of org.mule.runtime.api.meta.model.stereotype.StereotypeModel in project mule by mulesoft.

the class StereotypesDeclarationEnricherTestCase method assertStereotype.

private void assertStereotype(StereotypeModel stereotypeModel, String ns, String name, StereotypeModel parent) {
    StereotypeModel expected = newStereotype(name, ns).withParent(parent).build();
    assertThat(stereotypeModel.getNamespace(), is(expected.getNamespace()));
    assertThat(stereotypeModel.getType(), is(expected.getType()));
    if (stereotypeModel.getParent().isPresent()) {
        assertThat(expected.getParent().isPresent(), is(true));
        assertStereotype(stereotypeModel.getParent().get(), parent.getNamespace(), parent.getType(), parent.getParent().orElse(null));
    } else {
        assertThat(expected.getParent().isPresent(), is(false));
    }
}
Also used : StereotypeModel(org.mule.runtime.api.meta.model.stereotype.StereotypeModel)

Aggregations

StereotypeModel (org.mule.runtime.api.meta.model.stereotype.StereotypeModel)10 Test (org.junit.Test)8 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)5 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)4 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)4 SmallTest (org.mule.tck.size.SmallTest)4 List (java.util.List)2 Collectors.toList (java.util.stream.Collectors.toList)2 OBJECT_STORE (org.mule.runtime.extension.api.stereotype.MuleStereotypes.OBJECT_STORE)2 EmpireStereotype (org.mule.test.heisenberg.extension.stereotypes.EmpireStereotype)2 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Arrays.stream (java.util.Arrays.stream)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 NoSuchElementException (java.util.NoSuchElementException)1 Optional (java.util.Optional)1 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)1 CoreMatchers.instanceOf (org.hamcrest.CoreMatchers.instanceOf)1