Search in sources :

Example 1 with NotificationListenerRegistry

use of org.mule.runtime.api.notification.NotificationListenerRegistry in project mule by mulesoft.

the class MuleContextUtils method mockContextWithServices.

/**
 * Creates and configures a mock {@link MuleContext} to return testing services implementations.
 *
 * @return the created {@code muleContext}.
 */
public static MuleContextWithRegistries mockContextWithServices() {
    final MuleContextWithRegistries muleContext = mockMuleContext();
    SchedulerService schedulerService = spy(new SimpleUnitTestSupportSchedulerService());
    when(muleContext.getSchedulerService()).thenReturn(schedulerService);
    ErrorTypeRepository errorTypeRepository = mock(ErrorTypeRepository.class);
    when(muleContext.getErrorTypeRepository()).thenReturn(errorTypeRepository);
    when(errorTypeRepository.getErrorType(any(ComponentIdentifier.class))).thenReturn(of(mock(ErrorType.class)));
    final MuleRegistry registry = muleContext.getRegistry();
    NotificationListenerRegistry notificationListenerRegistry = mock(NotificationListenerRegistry.class);
    ConfigurationProperties configProps = mock(ConfigurationProperties.class);
    when(configProps.resolveBooleanProperty(any())).thenReturn(empty());
    ConfigurationComponentLocator configurationComponentLocator = mock(ConfigurationComponentLocator.class);
    when(configurationComponentLocator.find(any(Location.class))).thenReturn(empty());
    when(configurationComponentLocator.find(any(ComponentIdentifier.class))).thenReturn(emptyList());
    try {
        when(registry.lookupObject(NotificationListenerRegistry.class)).thenReturn(notificationListenerRegistry);
        Map<Class, Object> injectableObjects = new HashMap<>();
        injectableObjects.put(MuleContext.class, muleContext);
        injectableObjects.put(SchedulerService.class, schedulerService);
        injectableObjects.put(ErrorTypeRepository.class, errorTypeRepository);
        injectableObjects.put(ExtendedExpressionManager.class, muleContext.getExpressionManager());
        injectableObjects.put(StreamingManager.class, muleContext.getRegistry().lookupObject(StreamingManager.class));
        injectableObjects.put(ObjectStoreManager.class, muleContext.getRegistry().lookupObject(OBJECT_STORE_MANAGER));
        injectableObjects.put(NotificationDispatcher.class, muleContext.getRegistry().lookupObject(NotificationDispatcher.class));
        injectableObjects.put(NotificationListenerRegistry.class, notificationListenerRegistry);
        injectableObjects.put(ConfigurationComponentLocator.class, configurationComponentLocator);
        injectableObjects.put(ConfigurationProperties.class, configProps);
        // Ensure injection of consistent mock objects
        when(muleContext.getInjector()).thenReturn(new MocksInjector(injectableObjects));
    } catch (RegistrationException e1) {
        throw new MuleRuntimeException(e1);
    }
    return muleContext;
}
Also used : RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) SimpleUnitTestSupportSchedulerService(org.mule.tck.SimpleUnitTestSupportSchedulerService) SchedulerService(org.mule.runtime.api.scheduler.SchedulerService) HashMap(java.util.HashMap) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) NotificationDispatcher(org.mule.runtime.api.notification.NotificationDispatcher) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) ConfigurationProperties(org.mule.runtime.api.component.ConfigurationProperties) ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) StreamingManager(org.mule.runtime.core.api.streaming.StreamingManager) NotificationListenerRegistry(org.mule.runtime.api.notification.NotificationListenerRegistry) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ConfigurationComponentLocator(org.mule.runtime.api.component.location.ConfigurationComponentLocator) SimpleUnitTestSupportSchedulerService(org.mule.tck.SimpleUnitTestSupportSchedulerService) Location(org.mule.runtime.api.component.location.Location)

Example 2 with NotificationListenerRegistry

use of org.mule.runtime.api.notification.NotificationListenerRegistry in project mule by mulesoft.

the class DefaultApplicationPolicyInstance method enableNotificationListeners.

private void enableNotificationListeners(List<NotificationListener> notificationListeners) {
    NotificationListenerRegistry listenerRegistry = policyContext.getRegistry().lookupByType(NotificationListenerRegistry.class).get();
    policyContext.getMuleContext().getNotificationManager().addInterfaceToType(PolicyNotificationListener.class, PolicyNotification.class);
    notificationListeners.forEach(listenerRegistry::registerListener);
}
Also used : NotificationListenerRegistry(org.mule.runtime.api.notification.NotificationListenerRegistry)

Aggregations

NotificationListenerRegistry (org.mule.runtime.api.notification.NotificationListenerRegistry)2 HashMap (java.util.HashMap)1 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)1 ConfigurationProperties (org.mule.runtime.api.component.ConfigurationProperties)1 ConfigurationComponentLocator (org.mule.runtime.api.component.location.ConfigurationComponentLocator)1 Location (org.mule.runtime.api.component.location.Location)1 ErrorTypeRepository (org.mule.runtime.api.exception.ErrorTypeRepository)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 NotificationDispatcher (org.mule.runtime.api.notification.NotificationDispatcher)1 SchedulerService (org.mule.runtime.api.scheduler.SchedulerService)1 StreamingManager (org.mule.runtime.core.api.streaming.StreamingManager)1 MuleContextWithRegistries (org.mule.runtime.core.internal.context.MuleContextWithRegistries)1 MuleRegistry (org.mule.runtime.core.internal.registry.MuleRegistry)1 RegistrationException (org.mule.runtime.core.privileged.registry.RegistrationException)1 SimpleUnitTestSupportSchedulerService (org.mule.tck.SimpleUnitTestSupportSchedulerService)1