Search in sources :

Example 21 with ConfigurationInstance

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

the class ConfigurationInstanceFactoryTestCase method createFromResolverSetResult.

@Test
public void createFromResolverSetResult() throws Exception {
    ResolverSetResult result = ResolverSetResult.newBuilder().build();
    ConfigurationInstance configurationInstance = factory.createConfiguration(CONFIG_NAME, result, event, empty());
    assertConfiguration(configurationInstance);
    assertThat(configurationInstance.getConnectionProvider().isPresent(), is(false));
}
Also used : ResolverSetResult(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSetResult) 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 22 with ConfigurationInstance

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

the class DynamicConfigurationProviderTestCase method getExpired.

@Test
public void getExpired() throws Exception {
    HeisenbergExtension instance1 = (HeisenbergExtension) provider.get(event).getValue();
    HeisenbergExtension instance2 = makeAlternateInstance();
    DynamicConfigurationProvider provider = (DynamicConfigurationProvider) this.provider;
    timeSupplier.move(1, MINUTES);
    List<ConfigurationInstance> expired = provider.getExpired();
    assertThat(expired.isEmpty(), is(true));
    timeSupplier.move(10, MINUTES);
    expired = provider.getExpired();
    assertThat(expired.isEmpty(), is(false));
    List<Object> configs = expired.stream().map(config -> config.getValue()).collect(toImmutableList());
    assertThat(configs, containsInAnyOrder(instance1, instance2));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) ExtensionsTestUtils.mockInterceptors(org.mule.test.module.extension.internal.util.ExtensionsTestUtils.mockInterceptors) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Optional.of(java.util.Optional.of) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) Assert.assertThat(org.junit.Assert.assertThat) Mockito.doThrow(org.mockito.Mockito.doThrow) ExpirationPolicy(org.mule.runtime.extension.api.runtime.ExpirationPolicy) SmallTest(org.mule.tck.size.SmallTest) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) Pair(org.mule.runtime.api.util.Pair) RETURNS_DEEP_STUBS(org.mockito.Answers.RETURNS_DEEP_STUBS) Collectors.toImmutableList(org.mule.runtime.api.util.collection.Collectors.toImmutableList) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider) ReflectionCache(org.mule.runtime.module.extension.internal.util.ReflectionCache) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) Matchers.any(org.mockito.Matchers.any) Lifecycle(org.mule.runtime.api.lifecycle.Lifecycle) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Mockito.withSettings(org.mockito.Mockito.withSettings) Mockito.mock(org.mockito.Mockito.mock) ValueResolvingContext.from(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolvingContext.from) Optional.empty(java.util.Optional.empty) Mock(org.mockito.Mock) CoreMatchers.not(org.hamcrest.CoreMatchers.not) RunWith(org.junit.runner.RunWith) MINUTES(java.util.concurrent.TimeUnit.MINUTES) HashMap(java.util.HashMap) ResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet) ImmutableList(com.google.common.collect.ImmutableList) MuleException(org.mule.runtime.api.exception.MuleException) ExpectedException.none(org.junit.rules.ExpectedException.none) ExtensionModelTestUtils.visitableMock(org.mule.runtime.api.util.ExtensionModelTestUtils.visitableMock) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) ExpectedException(org.junit.rules.ExpectedException) CoreMatchers.sameInstance(org.hamcrest.CoreMatchers.sameInstance) Before(org.junit.Before) ThrowableMessageMatcher.hasMessage(org.junit.internal.matchers.ThrowableMessageMatcher.hasMessage) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Mockito.never(org.mockito.Mockito.never) ImmutableExpirationPolicy(org.mule.runtime.core.internal.config.ImmutableExpirationPolicy) ConnectionProviderResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ConnectionProviderResolver) Rule(org.junit.Rule) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) ExtensionsTestUtils.mockConfigurationInstance(org.mule.test.module.extension.internal.util.ExtensionsTestUtils.mockConfigurationInstance) ExtensionsTestUtils.mockClassLoaderModelProperty(org.mule.test.module.extension.internal.util.ExtensionsTestUtils.mockClassLoaderModelProperty) ResolverSetResult(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSetResult) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) 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 23 with ConfigurationInstance

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

the class ExtensionConnectionSupplierTestCase method xaTransaction.

@Test
public void xaTransaction() throws Exception {
    muleContext.setTransactionManager(mock(TransactionManager.class, RETURNS_DEEP_STUBS));
    XaTransaction transaction = spy(new XaTransaction(muleContext));
    XATransactionalConnection connection = mock(XATransactionalConnection.class, RETURNS_DEEP_STUBS);
    Object config = new Object();
    ExecutionContextAdapter operationContext = mock(ExecutionContextAdapter.class, RETURNS_DEEP_STUBS);
    ConnectionProvider connectionProvider = mock(ConnectionProvider.class);
    ConfigurationInstance configurationInstance = mock(ConfigurationInstance.class);
    when(configurationInstance.getConnectionProvider()).thenReturn(of(connectionProvider));
    when(operationContext.getConfiguration()).thenReturn(of(configurationInstance));
    when(configurationInstance.getValue()).thenReturn(config);
    when(connectionProvider.connect()).thenReturn(connection);
    TransactionConfig transactionConfig = mock(TransactionConfig.class);
    when(transactionConfig.getAction()).thenReturn(ACTION_ALWAYS_JOIN);
    when(transactionConfig.isTransacted()).thenReturn(true);
    when(operationContext.getTransactionConfig()).thenReturn(of(transactionConfig));
    connectionManager.bind(config, connectionProvider);
    TransactionCoordination.getInstance().bindTransaction(transaction);
    adapter.getConnection(operationContext);
    verify(transaction).bindResource(any(), any(XAExtensionTransactionalResource.class));
}
Also used : XaTransaction(org.mule.runtime.core.privileged.transaction.XaTransaction) XAExtensionTransactionalResource(org.mule.runtime.module.extension.internal.runtime.transaction.XAExtensionTransactionalResource) TransactionManager(javax.transaction.TransactionManager) TransactionConfig(org.mule.runtime.core.api.transaction.TransactionConfig) XATransactionalConnection(org.mule.runtime.extension.api.connectivity.XATransactionalConnection) ExecutionContextAdapter(org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) Test(org.junit.Test)

Example 24 with ConfigurationInstance

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

the class DefaultExtensionManager method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
public Optional<ConfigurationInstance> getConfiguration(ExtensionModel extensionModel, ComponentModel componentModel, CoreEvent muleEvent) {
    ConfigurationInstance instance = getConfigurationProvider(extensionModel, componentModel).map(p -> p.get(muleEvent)).orElse(null);
    if (instance != null) {
        return of(instance);
    }
    Optional<ConfigurationModel> configurationModel = getConfigurationModelForExtension(extensionModel, getConfigurationForComponent(extensionModel, componentModel));
    if (configurationModel.isPresent()) {
        createImplicitConfiguration(extensionModel, configurationModel.get(), muleEvent);
        return of(getConfiguration(getImplicitConfigurationProviderName(extensionModel, configurationModel.get()), muleEvent));
    }
    return empty();
}
Also used : Optional.empty(java.util.Optional.empty) Optional.of(java.util.Optional.of) MuleExtensionUtils.getClassLoader(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.getClassLoader) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) LoggerFactory(org.slf4j.LoggerFactory) ExtensionModelUtils.getConfigurationForComponent(org.mule.runtime.extension.api.util.ExtensionModelUtils.getConfigurationForComponent) Preconditions.checkArgument(org.mule.runtime.api.util.Preconditions.checkArgument) MuleContextAware(org.mule.runtime.core.api.context.MuleContextAware) DefaultRegistry(org.mule.runtime.core.internal.registry.DefaultRegistry) Inject(javax.inject.Inject) MuleContext(org.mule.runtime.core.api.MuleContext) DefaultImplicitConfigurationProviderFactory(org.mule.runtime.module.extension.internal.runtime.config.DefaultImplicitConfigurationProviderFactory) MuleException(org.mule.runtime.api.exception.MuleException) LifecycleUtils.stopIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.stopIfNeeded) Registry(org.mule.runtime.api.artifact.Registry) ClassUtils.withContextClassLoader(org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader) Builder.newBuilder(org.mule.runtime.module.extension.internal.manager.DefaultConfigurationExpirationMonitor.Builder.newBuilder) Time(org.mule.runtime.api.time.Time) StringUtils(org.mule.runtime.core.api.util.StringUtils) PrivilegedMuleContext(org.mule.runtime.core.privileged.PrivilegedMuleContext) Startable(org.mule.runtime.api.lifecycle.Startable) ImplicitConfigurationProviderFactory(org.mule.runtime.module.extension.internal.runtime.config.ImplicitConfigurationProviderFactory) Logger(org.slf4j.Logger) ConfigurationProvider(org.mule.runtime.extension.api.runtime.config.ConfigurationProvider) Optional.ofNullable(java.util.Optional.ofNullable) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Set(java.util.Set) ReflectionCache(org.mule.runtime.module.extension.internal.util.ReflectionCache) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) Initialisable(org.mule.runtime.api.lifecycle.Initialisable) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) ExtensionModelUtils.requiresConfig(org.mule.runtime.extension.api.util.ExtensionModelUtils.requiresConfig) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ExtensionModelUtils(org.mule.runtime.extension.api.util.ExtensionModelUtils) LifecycleUtils.disposeIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.disposeIfNeeded) List(java.util.List) ExtensionManager(org.mule.runtime.core.api.extension.ExtensionManager) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) Optional(java.util.Optional) MuleExtensionUtils.getImplicitConfigurationProviderName(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.getImplicitConfigurationProviderName) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)

Example 25 with ConfigurationInstance

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

the class DefaultExtensionManagerTestCase method getConfigurationByName.

@Test
public void getConfigurationByName() throws Exception {
    registerConfigurationProvider();
    ConfigurationInstance configurationInstance = extensionsManager.getConfiguration(EXTENSION1_CONFIG_INSTANCE_NAME, event);
    assertThat(configurationInstance.getValue(), is(sameInstance(configInstance)));
}
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)

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