Search in sources :

Example 6 with ExtensionModelLoader

use of org.mule.runtime.extension.api.loader.ExtensionModelLoader in project mule by mulesoft.

the class ExtensionModelJsonGeneratorTestCase method data.

@Parameterized.Parameters(name = "{1}")
public static Collection<Object[]> data() {
    final ClassLoader classLoader = ExtensionModelJsonGeneratorTestCase.class.getClassLoader();
    final ServiceRegistry serviceRegistry = mock(ServiceRegistry.class);
    when(serviceRegistry.lookupProviders(DeclarationEnricher.class, classLoader)).thenReturn(asList(new JavaXmlDeclarationEnricher()));
    List<ExtensionJsonGeneratorTestUnit> extensions;
    extensions = asList(newTestUnit(javaLoader, VeganExtension.class, "vegan.json"), newTestUnit(javaLoader, PetStoreConnector.class, "petstore.json"), newTestUnit(javaLoader, MetadataExtension.class, "metadata.json"), newTestUnit(javaLoader, HeisenbergExtension.class, "heisenberg.json"), newTestUnit(javaLoader, SubstitutionGroupExtension.class, "substitutiongroup.json"), newTestUnit(javaLoader, TransactionalExtension.class, "tx-ext.json"), newTestUnit(javaLoader, SubTypesMappingConnector.class, "subtypes.json"), newTestUnit(javaLoader, MarvelExtension.class, "marvel.json"), newTestUnit(soapLoader, RickAndMortyExtension.class, "ram.json"), newTestUnit(javaLoader, TypedValueExtension.class, "typed-value.json"), newTestUnit(javaLoader, TestOAuthExtension.class, "test-oauth.json"), newTestUnit(javaLoader, WeaveFunctionExtension.class, "test-fn.json"), newTestUnit(javaLoader, ValuesExtension.class, "values.json"), newTestUnit(javaLoader, ReconnectionExtension.class, "reconnection-extension.json"));
    BiFunction<Class<?>, ExtensionModelLoader, ExtensionModel> createExtensionModel = (extension, loader) -> {
        ExtensionModel model = loadExtension(extension, loader);
        if (extensionModels.put(model.getName(), model) != null) {
            throw new IllegalArgumentException(format("Extension names must be unique. Name [%s] for extension [%s] was already used", model.getName(), extension.getName()));
        }
        return model;
    };
    return extensions.stream().map(e -> new Object[] { createExtensionModel.apply(e.getExtensionClass(), e.getLoader()), e.getFileName() }).collect(toList());
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) IOUtils.getResourceAsUrl(org.mule.runtime.core.api.util.IOUtils.getResourceAsUrl) TestOAuthExtension(org.mule.test.oauth.TestOAuthExtension) URISyntaxException(java.net.URISyntaxException) BiFunction(java.util.function.BiFunction) MetadataExtension(org.mule.test.metadata.extension.MetadataExtension) SmallTest(org.mule.tck.size.SmallTest) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) ServiceRegistry(org.mule.runtime.core.api.registry.ServiceRegistry) DeclarationEnricher(org.mule.runtime.extension.api.loader.DeclarationEnricher) Parameterized(org.junit.runners.Parameterized) ExtensionJsonGeneratorTestUnit.newTestUnit(org.mule.runtime.module.extension.internal.resources.ExtensionModelJsonGeneratorTestCase.ExtensionJsonGeneratorTestUnit.newTestUnit) DefaultJavaExtensionModelLoader(org.mule.runtime.module.extension.api.loader.java.DefaultJavaExtensionModelLoader) Collection(java.util.Collection) ExtensionModelJsonSerializer(org.mule.runtime.extension.api.persistence.ExtensionModelJsonSerializer) String.format(java.lang.String.format) List(java.util.List) IOUtils.getResourceAsString(org.mule.runtime.core.api.util.IOUtils.getResourceAsString) DslResolvingContext.getDefault(org.mule.runtime.api.dsl.DslResolvingContext.getDefault) FileUtils.stringToFile(org.mule.runtime.core.api.util.FileUtils.stringToFile) MarvelExtension(org.mule.test.marvel.MarvelExtension) Mockito.mock(org.mockito.Mockito.mock) RickAndMortyExtension(org.mule.test.ram.RickAndMortyExtension) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) WeaveFunctionExtension(org.mule.test.function.extension.WeaveFunctionExtension) JSONAssert(org.skyscreamer.jsonassert.JSONAssert) SoapExtensionModelLoader(org.mule.runtime.module.extension.soap.api.loader.SoapExtensionModelLoader) AbstractMuleTestCase(org.mule.tck.junit4.AbstractMuleTestCase) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ExtensionModelLoader(org.mule.runtime.extension.api.loader.ExtensionModelLoader) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) TransactionalExtension(org.mule.test.transactional.TransactionalExtension) TypedValueExtension(org.mule.test.typed.value.extension.extension.TypedValueExtension) Before(org.junit.Before) ValuesExtension(org.mule.test.values.extension.ValuesExtension) Collections.emptySet(java.util.Collections.emptySet) PetStoreConnector(org.mule.test.petstore.extension.PetStoreConnector) SubstitutionGroupExtension(org.mule.test.substitutiongroup.extension.SubstitutionGroupExtension) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) VERSION(org.mule.runtime.module.extension.api.loader.AbstractJavaExtensionModelLoader.VERSION) VeganExtension(org.mule.test.vegan.extension.VeganExtension) File(java.io.File) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) Collectors.toList(java.util.stream.Collectors.toList) ReconnectionExtension(org.mule.extension.test.extension.reconnection.ReconnectionExtension) TYPE_PROPERTY_NAME(org.mule.runtime.module.extension.api.loader.AbstractJavaExtensionModelLoader.TYPE_PROPERTY_NAME) SubTypesMappingConnector(org.mule.test.subtypes.extension.SubTypesMappingConnector) JavaXmlDeclarationEnricher(org.mule.runtime.module.extension.internal.loader.enricher.JavaXmlDeclarationEnricher) JavaXmlDeclarationEnricher(org.mule.runtime.module.extension.internal.loader.enricher.JavaXmlDeclarationEnricher) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) DefaultJavaExtensionModelLoader(org.mule.runtime.module.extension.api.loader.java.DefaultJavaExtensionModelLoader) SoapExtensionModelLoader(org.mule.runtime.module.extension.soap.api.loader.SoapExtensionModelLoader) ExtensionModelLoader(org.mule.runtime.extension.api.loader.ExtensionModelLoader) ServiceRegistry(org.mule.runtime.core.api.registry.ServiceRegistry)

Example 7 with ExtensionModelLoader

use of org.mule.runtime.extension.api.loader.ExtensionModelLoader in project mule by mulesoft.

the class ExtensionLoaderUtils method getLoaderById.

public static ExtensionModelLoader getLoaderById(String id) {
    final SpiServiceRegistry spiServiceRegistry = new SpiServiceRegistry();
    final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    final Collection<ExtensionModelLoader> extensionModelLoaders = spiServiceRegistry.lookupProviders(ExtensionModelLoader.class, classLoader);
    return extensionModelLoaders.stream().filter(extensionModelLoader -> extensionModelLoader.getId().equals(id)).findAny().orElseThrow(() -> new RuntimeException("No loader found for id:{" + id + "}"));
}
Also used : ExtensionModelLoader(org.mule.runtime.extension.api.loader.ExtensionModelLoader) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry)

Aggregations

ExtensionModelLoader (org.mule.runtime.extension.api.loader.ExtensionModelLoader)7 Test (org.junit.Test)5 SmallTest (org.mule.tck.size.SmallTest)5 Map (java.util.Map)4 File (java.io.File)3 String.format (java.lang.String.format)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Before (org.junit.Before)3 RunWith (org.junit.runner.RunWith)3 DslResolvingContext (org.mule.runtime.api.dsl.DslResolvingContext)3 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)3 ServiceRegistry (org.mule.runtime.core.api.registry.ServiceRegistry)3 IOException (java.io.IOException)2 Arrays.asList (java.util.Arrays.asList)2 List (java.util.List)2 Optional (java.util.Optional)2 BiFunction (java.util.function.BiFunction)2 Collectors.toList (java.util.stream.Collectors.toList)2 Parameterized (org.junit.runners.Parameterized)2