Search in sources :

Example 6 with ConfigurationInstance

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

the class SourceAdapter method setConnection.

private void setConnection() throws MuleException {
    if (!connectionSetter.isPresent()) {
        return;
    }
    FieldSetter<Object, ConnectionProvider> setter = connectionSetter.get();
    ConfigurationInstance config = configurationInstance.orElseThrow(() -> new DefaultMuleException(createStaticMessage("Message Source on root component '%s' requires a connection but it doesn't point to any configuration. Please review your " + "application", component.getLocation().getRootContainerName())));
    if (!config.getConnectionProvider().isPresent()) {
        throw new DefaultMuleException(createStaticMessage(format("Message Source on root component '%s' requires a connection, but points to config '%s' which doesn't specify any. " + "Please review your application", component.getLocation().getRootContainerName(), config.getName())));
    }
    ConnectionProvider<Object> connectionProvider = new SourceConnectionProvider(connectionManager, config);
    setter.set(sourceInvokationTarget.get(), connectionProvider);
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)

Example 7 with ConfigurationInstance

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

the class DefaultExtensionManagerTestCase method getOperationExecutorThroughImplicitConfigurationConcurrently.

@Test
public void getOperationExecutorThroughImplicitConfigurationConcurrently() throws Exception {
    final int threadCount = 2;
    final CountDownLatch joinerLatch = new CountDownLatch(threadCount);
    MuleRegistry registry = muleContext.getRegistry();
    when(extension1ConfigurationModel.getModelProperty(ParameterGroupModelProperty.class)).thenReturn(empty());
    doAnswer(invocation -> {
        registerIntoMockContext(muleContext, getImplicitConfigurationProviderName(extensionModel1, extension1ConfigurationModel), extension1ConfigurationProvider);
        new Thread(() -> extensionsManager.getConfiguration(extensionModel1, extension1OperationModel, event)).start();
        joinerLatch.countDown();
        return null;
    }).when(registry).registerObject(anyString(), anyObject());
    Optional<ConfigurationInstance> configurationInstance = extensionsManager.getConfiguration(extensionModel1, extension1OperationModel, event);
    joinerLatch.countDown();
    assertThat(configurationInstance.isPresent(), is(true));
    assertThat(joinerLatch.await(5, TimeUnit.SECONDS), is(true));
    assertThat(configurationInstance.get().getValue(), is(sameInstance(configInstance)));
}
Also used : MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) CountDownLatch(java.util.concurrent.CountDownLatch) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) ExtensionsTestUtils.mockConfigurationInstance(org.mule.test.module.extension.internal.util.ExtensionsTestUtils.mockConfigurationInstance) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 8 with ConfigurationInstance

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

the class ConfigurationInstanceFactoryTestCase method createFromEvent.

@Test
public void createFromEvent() throws Exception {
    ConfigurationInstance configurationInstance = factory.createConfiguration(CONFIG_NAME, event, connectionProviderValueResolver);
    assertConfiguration(configurationInstance);
}
Also used : ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) ExtensionsTestUtils.mockConfigurationInstance(org.mule.test.module.extension.internal.util.ExtensionsTestUtils.mockConfigurationInstance) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 9 with ConfigurationInstance

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

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

Aggregations

ConfigurationInstance (org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)25 Test (org.junit.Test)12 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)9 SmallTest (org.mule.tck.size.SmallTest)9 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)7 ConfigurationProvider (org.mule.runtime.extension.api.runtime.config.ConfigurationProvider)7 MuleException (org.mule.runtime.api.exception.MuleException)5 ExtensionsTestUtils.mockConfigurationInstance (org.mule.test.module.extension.internal.util.ExtensionsTestUtils.mockConfigurationInstance)5 List (java.util.List)4 ConnectionProvider (org.mule.runtime.api.connection.ConnectionProvider)4 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)4 ReflectionCache (org.mule.runtime.module.extension.internal.util.ReflectionCache)4 String.format (java.lang.String.format)3 Optional (java.util.Optional)3 Optional.empty (java.util.Optional.empty)3 Optional.of (java.util.Optional.of)3 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)3 ComponentModel (org.mule.runtime.api.meta.model.ComponentModel)3 ResolverSet (org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet)3 ResolverSetResult (org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSetResult)3