Search in sources :

Example 91 with ExtensionModel

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

the class ExtensionActivator method registerEnumTransformers.

private void registerEnumTransformers(ExtensionModel extensionModel) {
    ClassLoader classLoader = getClassLoader(extensionModel);
    Set<Class<?>> parameterClasses = new HashSet<>();
    parameterClasses.addAll(getParameterClasses(extensionModel, classLoader));
    parameterClasses.addAll(getSubtypeClasses(extensionModel, classLoader));
    parameterClasses.stream().filter(type -> Enum.class.isAssignableFrom(type)).forEach(type -> {
        final Class<Enum> enumClass = (Class<Enum>) type;
        if (enumTypes.add(enumClass)) {
            try {
                StringToEnum stringToEnum = new StringToEnum(enumClass);
                registerObject(muleContext, getName(stringToEnum), stringToEnum, Transformer.class);
            } catch (MuleException e) {
                throw new MuleRuntimeException(createStaticMessage("Could not register transformer for enum " + enumClass.getName()), e);
            }
        }
    });
}
Also used : IntrospectionUtils.getSubtypeClasses(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getSubtypeClasses) FunctionModel(org.mule.runtime.api.meta.model.function.FunctionModel) IntrospectionUtils.getParameterClasses(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getParameterClasses) FunctionExecutor(org.mule.runtime.module.extension.internal.runtime.function.FunctionExecutor) MuleExtensionUtils.getClassLoader(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.getClassLoader) BindingContext(org.mule.runtime.api.el.BindingContext) StringToEnum(org.mule.runtime.core.internal.transformer.simple.StringToEnum) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) DefaultExpressionModuleBuilder(org.mule.runtime.core.internal.el.DefaultExpressionModuleBuilder) HashSet(java.util.HashSet) MuleContext(org.mule.runtime.core.api.MuleContext) MuleException(org.mule.runtime.api.exception.MuleException) FunctionExecutorModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.FunctionExecutorModelProperty) BeanUtils.getName(org.mule.runtime.core.privileged.util.BeanUtils.getName) LifecycleUtils.stopIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.stopIfNeeded) LinkedList(java.util.LinkedList) Startable(org.mule.runtime.api.lifecycle.Startable) FunctionParameterDefaultValueResolverFactory(org.mule.runtime.module.extension.internal.runtime.function.FunctionParameterDefaultValueResolverFactory) DataType.fromFunction(org.mule.runtime.api.metadata.DataType.fromFunction) DefaultBindingContextBuilder(org.mule.runtime.core.internal.el.DefaultBindingContextBuilder) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) Set(java.util.Set) LifecycleUtils.startIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.startIfNeeded) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Transformer(org.mule.runtime.core.api.transformer.Transformer) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) TypedValue(org.mule.runtime.api.metadata.TypedValue) List(java.util.List) Stream(java.util.stream.Stream) ExpressionModule(org.mule.runtime.api.el.ExpressionModule) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) LegacyRegistryUtils.registerObject(org.mule.runtime.core.privileged.registry.LegacyRegistryUtils.registerObject) ModuleNamespace(org.mule.runtime.api.el.ModuleNamespace) ExtendedExpressionManager(org.mule.runtime.core.api.el.ExtendedExpressionManager) GlobalBindingContextProvider(org.mule.runtime.core.privileged.el.GlobalBindingContextProvider) StringToEnum(org.mule.runtime.core.internal.transformer.simple.StringToEnum) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleExtensionUtils.getClassLoader(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.getClassLoader) StringToEnum(org.mule.runtime.core.internal.transformer.simple.StringToEnum) MuleException(org.mule.runtime.api.exception.MuleException) HashSet(java.util.HashSet)

Example 92 with ExtensionModel

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

the class CoreExtensionModelSerializationTestCase method serializeDeserialize.

@Test
public void serializeDeserialize() throws Exception {
    ExtensionModel extensionModel = MuleExtensionModelProvider.getExtensionModel();
    ExtensionModelJsonSerializer jsonSerializer = new ExtensionModelJsonSerializer(true);
    String serialized = jsonSerializer.serialize(extensionModel);
    ExtensionModel deserialized = jsonSerializer.deserialize(serialized);
    assertThat(extensionModel, equalTo(deserialized));
}
Also used : ExtensionModelJsonSerializer(org.mule.runtime.extension.api.persistence.ExtensionModelJsonSerializer) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) Test(org.junit.Test)

Example 93 with ExtensionModel

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

the class ErrorsDeclarationEnricherTestCase method operationInheritsExtensionErrorThrows.

@Test
public void operationInheritsExtensionErrorThrows() {
    extensionModel = loadExtension(HeisenbergWithExtensionThrows.class);
    OperationModel someOperation = extensionModel.getOperationModel("someOperation").get();
    Optional<ErrorModel> operationError = someOperation.getErrorModels().stream().filter(errorModel -> errorModel.getType().equals(EXTENSION.getType())).findFirst();
    assertThat(operationError.isPresent(), is(true));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Optional.empty(java.util.Optional.empty) HEALTH(org.mule.test.heisenberg.extension.HeisenbergErrors.HEALTH) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Operations(org.mule.runtime.extension.api.annotation.Operations) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Extension(org.mule.runtime.extension.api.annotation.Extension) HeisenbergOperations(org.mule.test.heisenberg.extension.HeisenbergOperations) HeisenbergScopes(org.mule.test.heisenberg.extension.HeisenbergScopes) EXTENSION(org.mule.runtime.module.extension.internal.loader.enricher.LevelErrorTypes.EXTENSION) KillingOperations(org.mule.test.heisenberg.extension.KillingOperations) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel) AbstractMuleTestCase(org.mule.tck.junit4.AbstractMuleTestCase) Collections.singleton(java.util.Collections.singleton) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) CONNECTIVITY_ERROR_IDENTIFIER(org.mule.runtime.core.api.exception.Errors.Identifiers.CONNECTIVITY_ERROR_IDENTIFIER) ExpectedException.none(org.junit.rules.ExpectedException.none) EnricherTestUtils.getNamedObject(org.mule.runtime.module.extension.internal.loader.enricher.EnricherTestUtils.getNamedObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) ExpectedException(org.junit.rules.ExpectedException) ErrorTypes(org.mule.runtime.extension.api.annotation.error.ErrorTypes) MuleExtensionUtils.loadExtension(org.mule.runtime.module.extension.api.util.MuleExtensionUtils.loadExtension) Set(java.util.Set) Throws(org.mule.runtime.extension.api.annotation.error.Throws) Test(org.junit.Test) OPERATION(org.mule.runtime.module.extension.internal.loader.enricher.LevelErrorTypes.OPERATION) ANY(org.mule.runtime.extension.api.error.MuleErrors.ANY) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ErrorTypeDefinition(org.mule.runtime.extension.api.error.ErrorTypeDefinition) MoneyLaunderingOperation(org.mule.test.heisenberg.extension.MoneyLaunderingOperation) Rule(org.junit.Rule) HeisenbergErrors(org.mule.test.heisenberg.extension.HeisenbergErrors) ErrorTypeProvider(org.mule.runtime.extension.api.annotation.error.ErrorTypeProvider) Optional(java.util.Optional) HeisenbergRouters(org.mule.test.heisenberg.extension.HeisenbergRouters) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test)

Example 94 with ExtensionModel

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

the class ParameterLayoutOrderDeclarationEnricherTestCase method parameters.

@Parameterized.Parameters(name = "{1}")
public static List<Object[]> parameters() {
    ExtensionModel extensionModel = loadExtension(OrderedExtension.class);
    List<Object[]> objects = new ArrayList<>();
    objects.add(new Object[] { extensionModel.getOperationModel("implicitOrder").get(), "Operation - Implicit Order" });
    objects.add(new Object[] { extensionModel.getOperationModel("explicitOrder").get(), "Operation - Explicit Order" });
    objects.add(new Object[] { extensionModel.getOperationModel("mixedOrder").get(), "Operation - Mixed Order" });
    objects.add(new Object[] { extensionModel.getConfigurationModel("ImplicitOrderConfig").get(), "Config - Implicit Order" });
    objects.add(new Object[] { extensionModel.getConfigurationModel("ExplicitOrderConfig").get(), "Config - Explicit Order" });
    objects.add(new Object[] { extensionModel.getConfigurationModel("MixedOrderConfig").get(), "Config - Mixed Order" });
    objects.add(new Object[] { extensionModel.getConfigurationModel("InheritsOrderConfig").get(), "Config - Inherited Order" });
    objects.add(new Object[] { extensionModel.getConnectionProviderModel("implicit").get(), "Conn Provider - Implicit Order" });
    objects.add(new Object[] { extensionModel.getConnectionProviderModel("explicit").get(), "Conn Provider - Explicit Order" });
    objects.add(new Object[] { extensionModel.getConnectionProviderModel("mixed").get(), "Conn Provider - Mixed Order" });
    objects.add(new Object[] { extensionModel.getSourceModel("ImplicitSourceOrder").get(), "Source - Implicit Order" });
    objects.add(new Object[] { extensionModel.getSourceModel("ExplicitSourceOrder").get(), "Source - Explicit Order" });
    objects.add(new Object[] { extensionModel.getSourceModel("MixedSourceOrder").get(), "Source - Mixed Order" });
    objects.add(new Object[] { extensionModel.getSourceModel("ExplicitSourceOrderWithCallbacks").get(), "Source - With Callbacks Explicit Order" });
    objects.add(new Object[] { extensionModel.getSourceModel("MixedSourceOrderWithCallbacks").get(), "Source - With Callbacks Mixed Order" });
    return objects;
}
Also used : ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ArrayList(java.util.ArrayList)

Aggregations

ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)94 Test (org.junit.Test)50 SmallTest (org.mule.tck.size.SmallTest)34 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)31 Optional (java.util.Optional)26 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)24 List (java.util.List)22 Set (java.util.Set)19 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)19 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)19 ConnectionProviderModel (org.mule.runtime.api.meta.model.connection.ConnectionProviderModel)16 HashMap (java.util.HashMap)15 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)15 String.format (java.lang.String.format)13 Collectors.toList (java.util.stream.Collectors.toList)13 HashSet (java.util.HashSet)12 Map (java.util.Map)12 Reference (org.mule.runtime.api.util.Reference)12 Optional.empty (java.util.Optional.empty)11 ObjectType (org.mule.metadata.api.model.ObjectType)11