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;
}
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;
}
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));
}
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]);
}
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);
}
Aggregations