Search in sources :

Example 21 with MuleContext

use of org.mule.runtime.core.api.MuleContext 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 22 with MuleContext

use of org.mule.runtime.core.api.MuleContext in project mule by mulesoft.

the class QueueStoreTestCase method createQueueWithCapacity.

protected QueueStore createQueueWithCapacity(int capacity) {
    MuleContext mockMuleContext = mock(MuleContext.class, Answers.RETURNS_DEEP_STUBS.get());
    when(mockMuleContext.getConfiguration().getWorkingDirectory()).thenReturn(temporaryFolder.getRoot().getAbsolutePath());
    when(mockMuleContext.getExecutionClassLoader()).thenReturn(muleContext.getExecutionClassLoader());
    when(mockMuleContext.getObjectSerializer()).thenReturn(muleContext.getObjectSerializer());
    QueueStore queue = createQueueInfoDelegate(capacity, mockMuleContext);
    return queue;
}
Also used : MuleContext(org.mule.runtime.core.api.MuleContext) QueueStore(org.mule.runtime.core.internal.util.queue.QueueStore)

Example 23 with MuleContext

use of org.mule.runtime.core.api.MuleContext in project mule by mulesoft.

the class DefaultMuleContextBuilderTestCase method testBuildMuleContextCustom.

@Test
public void testBuildMuleContextCustom() {
    // Build
    MuleContext muleContext = build();
    // Assert
    assertThat(muleContext, notNullValue());
    assertThat(muleContext.getConfiguration(), instanceOf(MyMuleConfiguration.class));
    assertThat(muleContext.getLifecycleManager(), instanceOf(MyLifeCycleManager.class));
    assertThat(muleContext.getNotificationManager(), instanceOf(MyServerNotificationManager.class));
}
Also used : MuleContext(org.mule.runtime.core.api.MuleContext) Test(org.junit.Test)

Example 24 with MuleContext

use of org.mule.runtime.core.api.MuleContext in project mule by mulesoft.

the class DefaultMuleContextBuilderTestCase method notificationManagerContainsTheCorrectInterfaces.

/**
 * <p>
 * After the mule context is built it has to contain the proper notification interfaces in the notification manager
 * </p>
 */
@Test
public void notificationManagerContainsTheCorrectInterfaces() {
    DefaultMuleContextBuilder builder = new DefaultMuleContextBuilder(APP);
    builder.setMuleConfiguration(new MyMuleConfiguration());
    builder.setLifecycleManager(new MyLifeCycleManager());
    MuleContext muleContext = builder.buildMuleContext();
    Map<Class<? extends NotificationListener>, Set<Class<? extends Notification>>> interfaces = muleContext.getNotificationManager().getInterfaceToTypes();
    assertEquals(MuleContextNotification.class, interfaces.get(MuleContextNotificationListener.class).toArray()[0]);
    assertEquals(RoutingNotification.class, interfaces.get(RoutingNotificationListener.class).toArray()[0]);
    assertEquals(SecurityNotification.class, interfaces.get(SecurityNotificationListener.class).toArray()[0]);
    assertEquals(ManagementNotification.class, interfaces.get(ManagementNotificationListener.class).toArray()[0]);
    assertEquals(CustomNotification.class, interfaces.get(CustomNotificationListener.class).toArray()[0]);
    assertEquals(ConnectionNotification.class, interfaces.get(ConnectionNotificationListener.class).toArray()[0]);
    assertEquals(ExceptionNotification.class, interfaces.get(ExceptionNotificationListener.class).toArray()[0]);
    assertEquals(TransactionNotification.class, interfaces.get(TransactionNotificationListener.class).toArray()[0]);
    assertEquals(PipelineMessageNotification.class, interfaces.get(PipelineMessageNotificationListener.class).toArray()[0]);
    assertEquals(AsyncMessageNotification.class, interfaces.get(AsyncMessageNotificationListener.class).toArray()[0]);
    assertEquals(ClusterNodeNotification.class, interfaces.get(ClusterNodeNotificationListener.class).toArray()[0]);
}
Also used : ClusterNodeNotificationListener(org.mule.runtime.api.notification.ClusterNodeNotificationListener) Set(java.util.Set) CustomNotificationListener(org.mule.runtime.api.notification.CustomNotificationListener) TransactionNotificationListener(org.mule.runtime.api.notification.TransactionNotificationListener) MuleContext(org.mule.runtime.core.api.MuleContext) SecurityNotificationListener(org.mule.runtime.api.notification.SecurityNotificationListener) ExceptionNotificationListener(org.mule.runtime.api.notification.ExceptionNotificationListener) ConnectionNotificationListener(org.mule.runtime.api.notification.ConnectionNotificationListener) RoutingNotificationListener(org.mule.runtime.api.notification.RoutingNotificationListener) MuleContextNotificationListener(org.mule.runtime.core.api.context.notification.MuleContextNotificationListener) AsyncMessageNotificationListener(org.mule.runtime.api.notification.AsyncMessageNotificationListener) ManagementNotificationListener(org.mule.runtime.api.notification.ManagementNotificationListener) PipelineMessageNotificationListener(org.mule.runtime.api.notification.PipelineMessageNotificationListener) CustomNotificationListener(org.mule.runtime.api.notification.CustomNotificationListener) MuleContextNotificationListener(org.mule.runtime.core.api.context.notification.MuleContextNotificationListener) PipelineMessageNotificationListener(org.mule.runtime.api.notification.PipelineMessageNotificationListener) SecurityNotificationListener(org.mule.runtime.api.notification.SecurityNotificationListener) ClusterNodeNotificationListener(org.mule.runtime.api.notification.ClusterNodeNotificationListener) AsyncMessageNotificationListener(org.mule.runtime.api.notification.AsyncMessageNotificationListener) ConnectionNotificationListener(org.mule.runtime.api.notification.ConnectionNotificationListener) ManagementNotificationListener(org.mule.runtime.api.notification.ManagementNotificationListener) ExceptionNotificationListener(org.mule.runtime.api.notification.ExceptionNotificationListener) NotificationListener(org.mule.runtime.api.notification.NotificationListener) TransactionNotificationListener(org.mule.runtime.api.notification.TransactionNotificationListener) RoutingNotificationListener(org.mule.runtime.api.notification.RoutingNotificationListener) Test(org.junit.Test)

Example 25 with MuleContext

use of org.mule.runtime.core.api.MuleContext in project mule by mulesoft.

the class MessageProcessingFlowTraceManagerTestCase method before.

@Before
public void before() {
    manager = new MessageProcessingFlowTraceManager();
    MuleContext context = mock(MuleContext.class);
    MuleConfiguration config = mock(MuleConfiguration.class);
    when(config.getId()).thenReturn(APP_ID);
    when(context.getConfiguration()).thenReturn(config);
    manager.setMuleContext(context);
    rootFlowConstruct = mock(FlowConstruct.class);
    ComponentLocation mockComponentLocation = mock(ComponentLocation.class);
    when(mockComponentLocation.getFileName()).thenReturn(of(CONFIG_FILE_NAME));
    when(mockComponentLocation.getLineInFile()).thenReturn(of(LINE_NUMBER));
    when(rootFlowConstruct.getLocation()).thenReturn(mockComponentLocation);
    when(rootFlowConstruct.getName()).thenReturn(ROOT_FLOW_NAME);
    when(rootFlowConstruct.getMuleContext()).thenReturn(context);
    nestedFlowConstruct = mock(FlowConstruct.class);
    when(nestedFlowConstruct.getLocation()).thenReturn(mockComponentLocation);
    when(nestedFlowConstruct.getName()).thenReturn(NESTED_FLOW_NAME);
    when(nestedFlowConstruct.getMuleContext()).thenReturn(context);
    messageContext = create(rootFlowConstruct, TEST_CONNECTOR_LOCATION);
}
Also used : MuleContext(org.mule.runtime.core.api.MuleContext) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) DefaultMuleConfiguration(org.mule.runtime.core.api.config.DefaultMuleConfiguration) MuleConfiguration(org.mule.runtime.core.api.config.MuleConfiguration) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) Before(org.junit.Before)

Aggregations

MuleContext (org.mule.runtime.core.api.MuleContext)46 Test (org.junit.Test)17 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Before (org.junit.Before)8 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)8 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)8 MuleException (org.mule.runtime.api.exception.MuleException)7 LifecycleUtils.initialiseIfNeeded (org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded)7 Map (java.util.Map)6 Optional (java.util.Optional)6 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)6 ComponentLocation (org.mule.runtime.api.component.location.ComponentLocation)5 ConfigurationBuilder (org.mule.runtime.core.api.config.ConfigurationBuilder)5 ConfigurationException (org.mule.runtime.core.api.config.ConfigurationException)5 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4 Optional.ofNullable (java.util.Optional.ofNullable)4 MuleConfiguration (org.mule.runtime.core.api.config.MuleConfiguration)4