use of org.mule.runtime.core.internal.context.MuleContextWithRegistries in project mule by mulesoft.
the class MessageProcessorsTestCase method setup.
@Before
public void setup() throws MuleException {
flow = mock(Flow.class, RETURNS_DEEP_STUBS);
OnErrorPropagateHandler exceptionHandler = new OnErrorPropagateHandler();
exceptionHandler.setMuleContext(muleContext);
exceptionHandler.setNotificationFirer(((MuleContextWithRegistries) muleContext).getRegistry().lookupObject(NotificationDispatcher.class));
exceptionHandler.initialise();
when(flow.getExceptionListener()).thenReturn(exceptionHandler);
eventContext = (BaseEventContext) create(flow, TEST_CONNECTOR_LOCATION);
input = builder(eventContext).message(of(TEST_MESSAGE)).build();
output = builder(eventContext).message(of(TEST_MESSAGE)).build();
response = builder(eventContext).message(of(TEST_MESSAGE)).build();
responsePublisher = eventContext.getResponsePublisher();
}
use of org.mule.runtime.core.internal.context.MuleContextWithRegistries in project mule by mulesoft.
the class DefaultExceptionStrategyTestCase method testExceptionNotifications.
// MULE-1627
@Test
public void testExceptionNotifications() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicInteger notificationCount = new AtomicInteger(0);
((MuleContextWithRegistries) muleContext).getRegistry().lookupObject(NotificationListenerRegistry.class).registerListener((ExceptionNotificationListener) notification -> {
if (new IntegerAction(EXCEPTION_ACTION).equals(notification.getAction())) {
assertEquals("exception", notification.getActionName());
assertEquals("Wrong info type", TYPE_ERROR, notification.getType());
notificationCount.incrementAndGet();
latch.countDown();
}
});
// throwing exception
InstrumentedExceptionStrategy strategy = new InstrumentedExceptionStrategy(muleContext);
strategy.setAnnotations(singletonMap(LOCATION_KEY, TEST_CONNECTOR_LOCATION));
strategy.setMuleContext(muleContext);
strategy.setNotificationFirer(((MuleContextWithRegistries) muleContext).getRegistry().lookupObject(NotificationDispatcher.class));
strategy.handleException(new IllegalArgumentException("boom"));
// Wait for the notifcation event to be fired as they are queue
latch.await(2000, MILLISECONDS);
assertEquals(1, notificationCount.get());
}
use of org.mule.runtime.core.internal.context.MuleContextWithRegistries in project mule by mulesoft.
the class PipelineMessageNotificationTestCase method createMocks.
@Before
public void createMocks() throws Exception {
muleContext.dispose();
muleContext = mockContextWithServices();
when(muleContext.getStatistics()).thenReturn(new AllStatistics());
when(muleContext.getConfiguration()).thenReturn(new DefaultMuleConfiguration());
notificationFirer = ((MuleContextWithRegistries) muleContext).getRegistry().lookupObject(NotificationDispatcher.class);
when(muleContext.getDefaultErrorHandler(empty())).thenReturn(new ErrorHandlerFactory().createDefault(notificationFirer));
mockErrorTypeLocator();
when(muleContext.getTransformationService()).thenReturn(new ExtendedTransformationService(muleContext));
}
use of org.mule.runtime.core.internal.context.MuleContextWithRegistries in project mule by mulesoft.
the class MuleRegistryHelperTestCase method findsCompositeTransformerEvenIfDirectNotFound.
@Test
public void findsCompositeTransformerEvenIfDirectNotFound() throws Exception {
Transformer fruitToSeed = new MockConverterBuilder().named("fruitToSeed").from(FRUIT_DATA_TYPE).to(SEED_DATA_TYPE).build();
Transformer seedToApple = new MockConverterBuilder().named("seedToApple").from(SEED_DATA_TYPE).to(APPLE_DATA_TYPE).build();
Transformer appleToBanana = new MockConverterBuilder().named("appleToBanana").from(APPLE_DATA_TYPE).to(BANANA_DATA_TYPE).build();
Transformer bananaToBloodOrange = new MockConverterBuilder().named("bananaToBloodOrange").from(BANANA_DATA_TYPE).to(BLOOD_ORANGE_DATA_TYPE).build();
((MuleContextWithRegistries) muleContext).getRegistry().registerTransformer(fruitToSeed);
((MuleContextWithRegistries) muleContext).getRegistry().registerTransformer(seedToApple);
((MuleContextWithRegistries) muleContext).getRegistry().registerTransformer(appleToBanana);
((MuleContextWithRegistries) muleContext).getRegistry().registerTransformer(bananaToBloodOrange);
Transformer trans = ((MuleContextWithRegistries) muleContext).getRegistry().lookupTransformer(FRUIT_DATA_TYPE, BLOOD_ORANGE_DATA_TYPE);
assertThat(trans, is(notNullValue()));
assertThat(trans, instanceOf(CompositeConverter.class));
assertThat(trans.getName(), is("fruitToSeedseedToAppleappleToBananabananaToBloodOrange"));
// The same should be returned if we ask for it with compatible data types
trans = ((MuleContextWithRegistries) muleContext).getRegistry().lookupTransformer(FRUIT_DATA_TYPE, ORANGE_DATA_TYPE);
assertThat(trans, instanceOf(CompositeConverter.class));
assertThat(trans.getName(), is("fruitToSeedseedToAppleappleToBananabananaToBloodOrange"));
trans = ((MuleContextWithRegistries) muleContext).getRegistry().lookupTransformer(PEACH_DATA_TYPE, BLOOD_ORANGE_DATA_TYPE);
assertThat(trans, instanceOf(CompositeConverter.class));
assertThat(trans.getName(), is("fruitToSeedseedToAppleappleToBananabananaToBloodOrange"));
trans = ((MuleContextWithRegistries) muleContext).getRegistry().lookupTransformer(PEACH_DATA_TYPE, ORANGE_DATA_TYPE);
assertThat(trans, instanceOf(CompositeConverter.class));
assertThat(trans.getName(), is("fruitToSeedseedToAppleappleToBananabananaToBloodOrange"));
}
use of org.mule.runtime.core.internal.context.MuleContextWithRegistries in project mule by mulesoft.
the class DefaultsConfigurationBuilder method doConfigure.
@Override
protected void doConfigure(MuleContext muleContext) throws Exception {
MuleRegistry registry = ((MuleContextWithRegistries) muleContext).getRegistry();
new SimpleRegistryBootstrap(APP, muleContext).initialise();
configureQueueManager(muleContext);
registry.registerObject(OBJECT_MULE_CONTEXT, muleContext);
registerObject(OBJECT_SECURITY_MANAGER, new DefaultMuleSecurityManager(), muleContext);
registerObject(BASE_IN_MEMORY_OBJECT_STORE_KEY, createDefaultInMemoryObjectStore(), muleContext);
registerObject(BASE_PERSISTENT_OBJECT_STORE_KEY, createDefaultPersistentObjectStore(), muleContext);
registerLocalObjectStoreManager(muleContext, registry);
registerObject(OBJECT_SCHEDULER_POOLS_CONFIG, SchedulerContainerPoolsConfig.getInstance(), muleContext);
registerObject(OBJECT_SCHEDULER_BASE_CONFIG, config().withPrefix(muleContext.getConfiguration().getId()).withShutdownTimeout(() -> muleContext.getConfiguration().getShutdownTimeout(), MILLISECONDS), muleContext);
registerObject(OBJECT_STORE_MANAGER, new MuleObjectStoreManager(), muleContext);
registerObject(OBJECT_DEFAULT_MESSAGE_PROCESSING_MANAGER, new MuleMessageProcessingManager(), muleContext);
registerObject(OBJECT_MULE_STREAM_CLOSER_SERVICE, new DefaultStreamCloserService(), muleContext);
registerObject(OBJECT_LOCK_PROVIDER, new SingleServerLockProvider(), muleContext);
registerObject(OBJECT_LOCK_FACTORY, new MuleLockFactory(), muleContext);
registerObject(OBJECT_PROCESSING_TIME_WATCHER, new DefaultProcessingTimeWatcher(), muleContext);
registerObject(OBJECT_DEFAULT_RETRY_POLICY_TEMPLATE, new NoRetryPolicyTemplate(), muleContext);
registerObject(OBJECT_CONVERTER_RESOLVER, new DynamicDataTypeConversionResolver(muleContext), muleContext);
registerObject(DEFAULT_OBJECT_SERIALIZER_NAME, new JavaObjectSerializer(), muleContext);
registerObject(OBJECT_EXPRESSION_LANGUAGE, new MVELExpressionLanguage(muleContext), muleContext);
StreamingManager streamingManager = new DefaultStreamingManager();
registerObject(OBJECT_STREAMING_MANAGER, streamingManager, muleContext);
registerObject(OBJECT_EXPRESSION_MANAGER, new DefaultExpressionManager(), muleContext);
registerObject(OBJECT_TIME_SUPPLIER, new LocalTimeSupplier(), muleContext);
registerObject(OBJECT_CONNECTION_MANAGER, new DefaultConnectionManager(muleContext), muleContext);
registerObject(METADATA_SERVICE_KEY, new MuleMetadataService(), muleContext);
registerObject(VALUE_PROVIDER_SERVICE_KEY, new MuleValueProviderService(), muleContext);
registerObject(PROCESSOR_INTERCEPTOR_MANAGER_REGISTRY_KEY, new DefaultProcessorInterceptorManager(), muleContext);
registerObject(OBJECT_NOTIFICATION_DISPATCHER, new DefaultNotificationDispatcher(), muleContext);
registerObject(NotificationListenerRegistry.REGISTRY_KEY, new DefaultNotificationListenerRegistry(), muleContext);
registerObject(EventContextService.REGISTRY_KEY, new DefaultEventContextService(), muleContext);
registerObject(OBJECT_TRANSACTION_FACTORY_LOCATOR, new TransactionFactoryLocator(), muleContext);
registerObject(ComponentInitialStateManager.SERVICE_ID, new ComponentInitialStateManager() {
@Override
public boolean mustStartMessageSource(Component component) {
return true;
}
}, muleContext);
}
Aggregations