Search in sources :

Example 6 with ConfigurationProvider

use of org.mule.runtime.extension.api.runtime.config.ConfigurationProvider in project mule by mulesoft.

the class DefaultExtensionsClient method createProcessor.

/**
 * Creates a new {@link OperationMessageProcessor} for the required operation and parses all the parameters passed by the client
 * user.
 */
private OperationMessageProcessor createProcessor(String extensionName, String operationName, OperationParameters parameters) {
    ExtensionModel extension = findExtension(extensionName);
    OperationModel operation = findOperation(extension, operationName);
    ConfigurationProvider config = parameters.getConfigName().map(this::findConfiguration).orElse(null);
    Map<String, ValueResolver> resolvedParams = resolveParameters(parameters.get(), getEvent());
    try {
        OperationMessageProcessor processor = new OperationMessageProcessorBuilder(extension, operation, policyManager, muleContext, registry).setConfigurationProvider(config).setParameters(resolvedParams).build();
        initialiseIfNeeded(processor, muleContext);
        processor.start();
        return processor;
    } catch (Exception e) {
        throw new MuleRuntimeException(createStaticMessage("Could not create Operation Message Processor"), e);
    }
}
Also used : OperationMessageProcessorBuilder(org.mule.runtime.module.extension.internal.runtime.operation.OperationMessageProcessorBuilder) ConfigurationProvider(org.mule.runtime.extension.api.runtime.config.ConfigurationProvider) StaticValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.StaticValueResolver) ValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver) ExpressionValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionValueResolver) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) OperationMessageProcessor(org.mule.runtime.module.extension.internal.runtime.operation.OperationMessageProcessor) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Example 7 with ConfigurationProvider

use of org.mule.runtime.extension.api.runtime.config.ConfigurationProvider in project mule by mulesoft.

the class CompositeArtifactExtensionManagerTestCase method returnsChildConfigurationProviderFromProviderName.

@Test
public void returnsChildConfigurationProviderFromProviderName() 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);
    ConfigurationProvider childConfigurationProvider = mock(ConfigurationProvider.class);
    when(childExtensionManager.getConfigurationProvider(PROVIDER_NAME)).thenReturn(of(childConfigurationProvider));
    when(parentExtensionManager.getConfigurationProvider(PROVIDER_NAME)).thenReturn(empty());
    Optional<ConfigurationProvider> configurationProvider = extensionManager.getConfigurationProvider(PROVIDER_NAME);
    assertThat(configurationProvider.get(), is(childConfigurationProvider));
}
Also used : ConfigurationProvider(org.mule.runtime.extension.api.runtime.config.ConfigurationProvider) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 8 with ConfigurationProvider

use of org.mule.runtime.extension.api.runtime.config.ConfigurationProvider in project mule by mulesoft.

the class CompositeArtifactExtensionManagerTestCase method failsToObtainMissingConfigurationFromModel.

@Test
public void failsToObtainMissingConfigurationFromModel() 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(empty());
    when(childExtensionManager.getConfigurationProvider(childExtension, operationModel)).thenReturn(empty());
    when(parentExtensionManager.getConfigurationProvider(childExtension, operationModel)).thenReturn(empty());
    expectedException.expect(IllegalArgumentException.class);
    extensionManager.getConfiguration(childExtension, operationModel, 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 9 with ConfigurationProvider

use of org.mule.runtime.extension.api.runtime.config.ConfigurationProvider 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 10 with ConfigurationProvider

use of org.mule.runtime.extension.api.runtime.config.ConfigurationProvider 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)

Aggregations

ConfigurationProvider (org.mule.runtime.extension.api.runtime.config.ConfigurationProvider)11 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)10 Test (org.junit.Test)8 SmallTest (org.mule.tck.size.SmallTest)8 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)5 ConfigurationInstance (org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)5 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)2 String.format (java.lang.String.format)1 Thread.currentThread (java.lang.Thread.currentThread)1 Optional (java.util.Optional)1 Optional.empty (java.util.Optional.empty)1 Optional.ofNullable (java.util.Optional.ofNullable)1 ExecutionException (java.util.concurrent.ExecutionException)1 MuleException (org.mule.runtime.api.exception.MuleException)1 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)1 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)1 MetadataResolvingException (org.mule.runtime.api.metadata.MetadataResolvingException)1 MuleContext (org.mule.runtime.core.api.MuleContext)1