Search in sources :

Example 46 with ExtensionModel

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

the class CompositeArtifactExtensionManagerTestCase method returnsEmptyExtensionWhenNonRegistered.

@Test
public void returnsEmptyExtensionWhenNonRegistered() throws Exception {
    ExtensionModel parentExtension = mock(ExtensionModel.class);
    when(parentExtension.getName()).thenReturn("testExtension");
    Set<ExtensionModel> parentExtensions = singleton(parentExtension);
    when(parentExtensionManager.getExtensions()).thenReturn(parentExtensions);
    CompositeArtifactExtensionManager extensionManager = new CompositeArtifactExtensionManager(parentExtensionManager, childExtensionManager);
    Optional<ExtensionModel> extension = extensionManager.getExtension("fooExtension");
    assertThat(extension.isPresent(), is(false));
}
Also used : ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 47 with ExtensionModel

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

the class CompositeArtifactExtensionManagerTestCase method returnsConfigurationFromModel.

@Test
public void returnsConfigurationFromModel() throws Exception {
    ExtensionModel childExtension = mock(ExtensionModel.class);
    Set<ExtensionModel> childExtensions = singleton(childExtension);
    when(childExtensionManager.getExtensions()).thenReturn(childExtensions);
    when(parentExtensionManager.getExtensions()).thenReturn(emptySet());
    CompositeArtifactExtensionManager extensionManager = new CompositeArtifactExtensionManager(parentExtensionManager, childExtensionManager);
    CoreEvent event = mock(CoreEvent.class);
    ConfigurationProvider childConfigurationProvider = mock(ConfigurationProvider.class);
    ConfigurationInstance configurationInstance = mock(ConfigurationInstance.class);
    when(childConfigurationProvider.get(event)).thenReturn(configurationInstance);
    when(childExtensionManager.getConfiguration(childExtension, operationModel, event)).thenReturn(ofNullable(configurationInstance));
    when(parentExtensionManager.getConfigurationProvider(childExtension, operationModel)).thenReturn(empty());
    Optional<ConfigurationInstance> configuration = extensionManager.getConfiguration(childExtension, operationModel, event);
    assertThat(configuration.isPresent(), is(true));
    assertThat(configuration.get(), is(configurationInstance));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ConfigurationProvider(org.mule.runtime.extension.api.runtime.config.ConfigurationProvider) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 48 with ExtensionModel

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

the class CompositeArtifactExtensionManagerTestCase method failsToObtainMissingConfigurationFromProviderName.

@Test
public void failsToObtainMissingConfigurationFromProviderName() throws Exception {
    ExtensionModel childExtension = mock(ExtensionModel.class);
    Set<ExtensionModel> childExtensions = singleton(childExtension);
    when(childExtensionManager.getExtensions()).thenReturn(childExtensions);
    when(parentExtensionManager.getExtensions()).thenReturn(emptySet());
    CompositeArtifactExtensionManager extensionManager = new CompositeArtifactExtensionManager(parentExtensionManager, childExtensionManager);
    CoreEvent event = mock(CoreEvent.class);
    ConfigurationProvider childConfigurationProvider = mock(ConfigurationProvider.class);
    ConfigurationInstance configurationInstance = mock(ConfigurationInstance.class);
    when(childConfigurationProvider.get(event)).thenReturn(configurationInstance);
    when(childExtensionManager.getConfigurationProvider(PROVIDER_NAME)).thenReturn(empty());
    when(parentExtensionManager.getConfigurationProvider(PROVIDER_NAME)).thenReturn(empty());
    expectedException.expect(IllegalArgumentException.class);
    extensionManager.getConfiguration(PROVIDER_NAME, event);
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ConfigurationProvider(org.mule.runtime.extension.api.runtime.config.ConfigurationProvider) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 49 with ExtensionModel

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

the class ConfigurationSchemaDelegate method addConnectionProviderElement.

private Optional<TopLevelElement> addConnectionProviderElement(ConfigurationModel configurationModel) {
    ExtensionModel extensionModel = builder.getExtensionModel();
    if (!extensionModel.getConnectionProviders().isEmpty() || !configurationModel.getConnectionProviders().isEmpty()) {
        TopLevelElement objectElement = new TopLevelElement();
        boolean hasImplicitConnection = getFirstImplicit(extensionModel.getConnectionProviders()) != null || getFirstImplicit(configurationModel.getConnectionProviders()) != null;
        objectElement.setMinOccurs(hasImplicitConnection ? ZERO : ONE);
        objectElement.setMaxOccurs(MAX_ONE);
        objectElement.setRef(MULE_CONNECTION_PROVIDER_ELEMENT);
        return Optional.of(objectElement);
    }
    return empty();
}
Also used : TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel)

Example 50 with ExtensionModel

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

the class SoapExtensionDeclarationTestCase method assertSoapExtensionModel.

@Test
public void assertSoapExtensionModel() {
    Map<String, Object> params = new HashMap<>();
    params.put(TYPE_PROPERTY_NAME, FootballSoapExtension.class.getName());
    params.put(VERSION, getProductVersion());
    ExtensionModel model = loader.loadExtensionModel(FootballSoapExtension.class.getClassLoader(), getDefault(emptySet()), params);
    assertErrorModels(model.getErrorModels());
    assertThat(model.getConfigurationModels(), hasSize(1));
    ConfigurationModel configuration = model.getConfigurationModels().get(0);
    assertThat(configuration.getName(), is(DEFAULT_CONFIG_NAME));
    assertThat(configuration.getDescription(), is(DEFAULT_CONFIG_DESCRIPTION));
    assertThat(configuration.getOperationModels(), hasSize(1));
    assertOperation(configuration.getOperationModels().get(0));
    List<ConnectionProviderModel> providers = configuration.getConnectionProviders();
    assertThat(providers, hasSize(3));
    assertConnectionProvider(providers.get(0), "base-connection", "", false, new ParameterProber("laLigaAddress", null, StringType.class, true), new ParameterProber("leaguesAddress", "http://some-url.com", StringType.class, false));
    assertConnectionProvider(providers.get(1), CALCIO_ID + "-connection", CALCIO_DESC, false);
    assertConnectionProvider(providers.get(2), "la-liga-connection", "", true, new ParameterProber("firstDivision", StringType.class), new ParameterProber("secondDivision", StringType.class), new ParameterProber("wsdlLocation", StringType.class));
}
Also used : ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) HashMap(java.util.HashMap) FootballSoapExtension(org.mule.test.soap.extension.FootballSoapExtension) StringType(org.mule.metadata.api.model.StringType) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) Test(org.junit.Test)

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