Search in sources :

Example 1 with ServiceRegistry

use of org.mule.runtime.core.api.registry.ServiceRegistry in project mule by mulesoft.

the class CraftedExtensionModelLoaderTestCase method spiDiscoverable.

@Test
public void spiDiscoverable() throws Exception {
    ServiceRegistry registry = new SpiServiceRegistry();
    Optional<ExtensionModelLoader> craftedLoader = registry.lookupProviders(ExtensionModelLoader.class, classLoader).stream().filter(p -> p instanceof CraftedExtensionModelLoader).findAny();
    assertThat(craftedLoader.isPresent(), is(true));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) Assert.assertThat(org.junit.Assert.assertThat) AbstractMuleTestCase(org.mule.tck.junit4.AbstractMuleTestCase) SmallTest(org.mule.tck.size.SmallTest) Map(java.util.Map) ExpectedException.none(org.junit.rules.ExpectedException.none) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) ExtensionLoadingDelegate(org.mule.runtime.extension.api.loader.ExtensionLoadingDelegate) ServiceRegistry(org.mule.runtime.core.api.registry.ServiceRegistry) ExtensionModelLoader(org.mule.runtime.extension.api.loader.ExtensionModelLoader) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) COMMUNITY(org.mule.runtime.api.meta.Category.COMMUNITY) ExtensionLoadingContext(org.mule.runtime.extension.api.loader.ExtensionLoadingContext) Test(org.junit.Test) TYPE_PROPERTY_NAME(org.mule.runtime.module.extension.api.loader.java.CraftedExtensionModelLoader.TYPE_PROPERTY_NAME) CraftedExtensionModelLoader(org.mule.runtime.module.extension.api.loader.java.CraftedExtensionModelLoader) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) MuleVersion(org.mule.runtime.api.meta.MuleVersion) Rule(org.junit.Rule) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) Optional(java.util.Optional) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) CraftedExtensionModelLoader(org.mule.runtime.module.extension.api.loader.java.CraftedExtensionModelLoader) ExtensionModelLoader(org.mule.runtime.extension.api.loader.ExtensionModelLoader) CraftedExtensionModelLoader(org.mule.runtime.module.extension.api.loader.java.CraftedExtensionModelLoader) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) ServiceRegistry(org.mule.runtime.core.api.registry.ServiceRegistry) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 2 with ServiceRegistry

use of org.mule.runtime.core.api.registry.ServiceRegistry in project mule by mulesoft.

the class DefaultExtensionSchemaGeneratorTestCase method data.

@Parameterized.Parameters(name = "{1}")
public static Collection<Object[]> data() {
    final ClassLoader classLoader = DefaultExtensionSchemaGeneratorTestCase.class.getClassLoader();
    final ServiceRegistry serviceRegistry = mock(ServiceRegistry.class);
    when(serviceRegistry.lookupProviders(DeclarationEnricher.class, classLoader)).thenReturn(asList(new JavaXmlDeclarationEnricher()));
    final List<SchemaGeneratorTestUnit> extensions;
    extensions = asList(newTestUnit(javaLoader, MapConnector.class, "map.xsd"), newTestUnit(javaLoader, ListConnector.class, "list.xsd"), newTestUnit(javaLoader, TestConnector.class, "basic.xsd"), newTestUnit(javaLoader, StringListConnector.class, "string-list.xsd"), newTestUnit(javaLoader, GlobalPojoConnector.class, "global-pojo.xsd"), newTestUnit(javaLoader, GlobalInnerPojoConnector.class, "global-inner-pojo.xsd"), newTestUnit(javaLoader, VeganExtension.class, "vegan.xsd"), newTestUnit(javaLoader, PetStoreConnector.class, "petstore.xsd"), newTestUnit(javaLoader, MetadataExtension.class, "metadata.xsd"), newTestUnit(javaLoader, HeisenbergExtension.class, "heisenberg.xsd"), newTestUnit(javaLoader, SubstitutionGroupExtension.class, "substitutiongroup.xsd"), newTestUnit(javaLoader, TransactionalExtension.class, "tx-ext.xsd"), newTestUnit(javaLoader, SubTypesMappingConnector.class, "subtypes.xsd"), newTestUnit(javaLoader, MarvelExtension.class, "marvel.xsd"), newTestUnit(soapLoader, FootballSoapExtension.class, "soap.xsd"), newTestUnit(soapLoader, RickAndMortyExtension.class, "ram.xsd"), newTestUnit(javaLoader, TypedValueExtension.class, "typed-value.xsd"), newTestUnit(javaLoader, TestOAuthExtension.class, "test-oauth.xsd"), newTestUnit(javaLoader, WeaveFunctionExtension.class, "test-fn.xsd"), newTestUnit(javaLoader, ValuesExtension.class, "values.xsd"), newTestUnit(javaLoader, ReconnectionExtension.class, "reconnection-extension.xsd"));
    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 : IOUtils.getResourceAsUrl(org.mule.runtime.core.api.util.IOUtils.getResourceAsUrl) TestOAuthExtension(org.mule.test.oauth.TestOAuthExtension) FootballSoapExtension(org.mule.test.soap.extension.FootballSoapExtension) BiFunction(java.util.function.BiFunction) MapConnector(org.mule.runtime.module.extension.internal.runtime.connectivity.basic.MapConnector) 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) DefaultJavaExtensionModelLoader(org.mule.runtime.module.extension.api.loader.java.DefaultJavaExtensionModelLoader) Collection(java.util.Collection) Set(java.util.Set) String.format(java.lang.String.format) List(java.util.List) ExtensionSchemaGenerator(org.mule.runtime.extension.api.dsl.syntax.resources.spi.ExtensionSchemaGenerator) ListConnector(org.mule.runtime.module.extension.internal.runtime.connectivity.basic.ListConnector) Optional(java.util.Optional) 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) MuleManifest.getProductVersion(org.mule.runtime.core.api.config.MuleManifest.getProductVersion) RickAndMortyExtension(org.mule.test.ram.RickAndMortyExtension) StringListConnector(org.mule.runtime.module.extension.internal.runtime.connectivity.basic.StringListConnector) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) TypeCatalog(org.mule.runtime.api.meta.type.TypeCatalog) WeaveFunctionExtension(org.mule.test.function.extension.WeaveFunctionExtension) SoapExtensionModelLoader(org.mule.runtime.module.extension.soap.api.loader.SoapExtensionModelLoader) GlobalInnerPojoConnector(org.mule.runtime.module.extension.internal.runtime.connectivity.basic.GlobalInnerPojoConnector) AbstractMuleTestCase(org.mule.tck.junit4.AbstractMuleTestCase) GlobalPojoConnector(org.mule.runtime.module.extension.internal.runtime.connectivity.basic.GlobalPojoConnector) TestConnector(org.mule.runtime.module.extension.internal.runtime.connectivity.basic.TestConnector) ExtensionModelLoader(org.mule.runtime.extension.api.loader.ExtensionModelLoader) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) LinkedHashSet(java.util.LinkedHashSet) TransactionalExtension(org.mule.test.transactional.TransactionalExtension) TypedValueExtension(org.mule.test.typed.value.extension.extension.TypedValueExtension) Before(org.junit.Before) DefaultExtensionSchemaGenerator(org.mule.runtime.module.extension.internal.capability.xml.schema.DefaultExtensionSchemaGenerator) ValuesExtension(org.mule.test.values.extension.ValuesExtension) ImmutableSet.copyOf(com.google.common.collect.ImmutableSet.copyOf) Optional.ofNullable(java.util.Optional.ofNullable) 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) ExtensionsTestUtils.compareXML(org.mule.test.module.extension.internal.util.ExtensionsTestUtils.compareXML) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) Collectors.toList(java.util.stream.Collectors.toList) ReconnectionExtension(org.mule.extension.test.extension.reconnection.ReconnectionExtension) SchemaGeneratorTestUnit.newTestUnit(org.mule.runtime.module.extension.internal.capability.xml.DefaultExtensionSchemaGeneratorTestCase.SchemaGeneratorTestUnit.newTestUnit) 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 3 with ServiceRegistry

use of org.mule.runtime.core.api.registry.ServiceRegistry 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 4 with ServiceRegistry

use of org.mule.runtime.core.api.registry.ServiceRegistry in project mule by mulesoft.

the class MuleArtifactContext method createApplicationParser.

private XmlApplicationParser createApplicationParser(List<ClassLoader> pluginsClassLoaders) {
    ExtensionManager extensionManager = muleContext.getExtensionManager();
    ServiceRegistry customRegistry = extensionManager != null ? new XmlApplicationServiceRegistry(serviceRegistry, DslResolvingContext.getDefault(extensionManager.getExtensions())) : serviceRegistry;
    return new XmlApplicationParser(customRegistry, pluginsClassLoaders);
}
Also used : XmlApplicationParser(org.mule.runtime.config.api.dsl.processor.xml.XmlApplicationParser) ExtensionManager(org.mule.runtime.core.api.extension.ExtensionManager) XmlApplicationServiceRegistry(org.mule.runtime.config.api.dsl.processor.xml.XmlApplicationServiceRegistry) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) ServiceRegistry(org.mule.runtime.core.api.registry.ServiceRegistry) XmlApplicationServiceRegistry(org.mule.runtime.config.api.dsl.processor.xml.XmlApplicationServiceRegistry)

Aggregations

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