Search in sources :

Example 6 with SimpleConfigurationBuilder

use of org.mule.runtime.core.api.config.builders.SimpleConfigurationBuilder in project mule by mulesoft.

the class AbstractMuleContextTestCase method createMuleContext.

protected MuleContext createMuleContext() throws Exception {
    // Should we set up the manager for every method?
    MuleContext context;
    if (isDisposeContextPerClass() && muleContext != null) {
        context = muleContext;
    } else {
        final ClassLoader executionClassLoader = getExecutionClassLoader();
        final ClassLoader originalContextClassLoader = currentThread().getContextClassLoader();
        try {
            currentThread().setContextClassLoader(executionClassLoader);
            MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
            List<ConfigurationBuilder> builders = new ArrayList<>();
            builders.add(new SimpleConfigurationBuilder(getStartUpRegistryObjects()));
            addBuilders(builders);
            builders.add(getBuilder());
            MuleContextBuilder contextBuilder = MuleContextBuilder.builder(APP);
            DefaultMuleConfiguration muleConfiguration = new DefaultMuleConfiguration();
            String workingDirectory = this.workingDirectory.getRoot().getAbsolutePath();
            LOGGER.info("Using working directory for test: " + workingDirectory);
            muleConfiguration.setWorkingDirectory(workingDirectory);
            muleConfiguration.setId(this.getClass().getSimpleName() + "#" + name.getMethodName());
            contextBuilder.setMuleConfiguration(muleConfiguration);
            contextBuilder.setExecutionClassLoader(executionClassLoader);
            contextBuilder.setObjectSerializer(getObjectSerializer());
            contextBuilder.setDeploymentProperties(getDeploymentProperties());
            configureMuleContext(contextBuilder);
            context = muleContextFactory.createMuleContext(builders, contextBuilder);
            recordSchedulersOnInit(context);
            if (!isGracefulShutdown()) {
                // Even though graceful shutdown is disabled allow small amount of time to avoid rejection errors when stream emits
                // complete signal
                ((DefaultMuleConfiguration) context.getConfiguration()).setShutdownTimeout(NON_GRACEFUL_SHUTDOWN_TIMEOUT);
            }
        } finally {
            currentThread().setContextClassLoader(originalContextClassLoader);
        }
    }
    return context;
}
Also used : MuleContext(org.mule.runtime.core.api.MuleContext) DefaultMuleContextFactory(org.mule.runtime.core.api.context.DefaultMuleContextFactory) SimpleConfigurationBuilder(org.mule.runtime.core.api.config.builders.SimpleConfigurationBuilder) DefaultsConfigurationBuilder(org.mule.runtime.core.internal.config.builders.DefaultsConfigurationBuilder) ConfigurationBuilder(org.mule.runtime.core.api.config.ConfigurationBuilder) TestServicesConfigurationBuilder(org.mule.tck.config.TestServicesConfigurationBuilder) MuleContextFactory(org.mule.runtime.core.api.context.MuleContextFactory) DefaultMuleContextFactory(org.mule.runtime.core.api.context.DefaultMuleContextFactory) DefaultMuleConfiguration(org.mule.runtime.core.api.config.DefaultMuleConfiguration) ArrayList(java.util.ArrayList) SimpleConfigurationBuilder(org.mule.runtime.core.api.config.builders.SimpleConfigurationBuilder) MuleContextBuilder(org.mule.runtime.core.api.context.MuleContextBuilder)

Example 7 with SimpleConfigurationBuilder

use of org.mule.runtime.core.api.config.builders.SimpleConfigurationBuilder in project mule by mulesoft.

the class ArtifactFunctionalTestCase method addBuilders.

/**
 * Adds a {@link ConfigurationBuilder} that sets the {@link org.mule.runtime.core.api.extension.ExtensionManager} into the
 * {@link #muleContext}. This {@link ConfigurationBuilder} is set as the first element of the {@code builders} {@link List}
 *
 * @param builders the list of {@link ConfigurationBuilder}s that will be used to initialise the {@link #muleContext}
 */
@Override
protected void addBuilders(List<ConfigurationBuilder> builders) {
    Class<?> runner = getAnnotationAttributeFrom(this.getClass(), RunWith.class, "value");
    if (runner == null || !runner.equals(ArtifactClassLoaderRunner.class)) {
        throw new IllegalStateException(this.getClass().getName() + " extends " + ArtifactFunctionalTestCase.class.getName() + " so it should be annotated to only run with: " + ArtifactClassLoaderRunner.class + ". See " + RunnerDelegateTo.class + " for defining a delegate runner to be used.");
    }
    if (extensionsManagerConfigurationBuilder != null) {
        builders.add(0, extensionsManagerConfigurationBuilder);
    }
    builders.add(0, new TestBootstrapServiceDiscovererConfigurationBuilder(containerClassLoader, getExecutionClassLoader(), pluginClassLoaders));
    builders.add(0, new SimpleConfigurationBuilder(singletonMap(OBJECT_CLASSLOADER_REPOSITORY, classLoaderRepository)));
}
Also used : SimpleConfigurationBuilder(org.mule.runtime.core.api.config.builders.SimpleConfigurationBuilder)

Aggregations

SimpleConfigurationBuilder (org.mule.runtime.core.api.config.builders.SimpleConfigurationBuilder)7 Before (org.junit.Before)3 MuleContext (org.mule.runtime.core.api.MuleContext)3 ConfigurationBuilder (org.mule.runtime.core.api.config.ConfigurationBuilder)3 HashMap (java.util.HashMap)2 DefaultMuleContextFactory (org.mule.runtime.core.api.context.DefaultMuleContextFactory)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 ConfigurationException (org.mule.runtime.core.api.config.ConfigurationException)1 DefaultMuleConfiguration (org.mule.runtime.core.api.config.DefaultMuleConfiguration)1 MuleContextBuilder (org.mule.runtime.core.api.context.MuleContextBuilder)1 MuleContextFactory (org.mule.runtime.core.api.context.MuleContextFactory)1 AutoConfigurationBuilder (org.mule.runtime.core.internal.config.builders.AutoConfigurationBuilder)1 DefaultsConfigurationBuilder (org.mule.runtime.core.internal.config.builders.DefaultsConfigurationBuilder)1 DefaultMuleContextBuilder (org.mule.runtime.core.internal.context.DefaultMuleContextBuilder)1 ProcessorInterceptorManager (org.mule.runtime.core.internal.interception.ProcessorInterceptorManager)1 DefaultMuleSecurityManager (org.mule.runtime.core.internal.security.DefaultMuleSecurityManager)1 TestServicesConfigurationBuilder (org.mule.tck.config.TestServicesConfigurationBuilder)1 Banana (org.mule.tck.testmodels.fruit.Banana)1