Search in sources :

Example 1 with NotificationsProvider

use of org.mule.runtime.core.api.context.notification.NotificationsProvider in project mule by mulesoft.

the class ServerNotificationManagerConfiguratorTestCase method compliantDisabledNotificationByInterface.

@Test
public void compliantDisabledNotificationByInterface() throws InitialisationException {
    doReturn(singletonList((NotificationsProvider) () -> singletonMap("test:COMPLIANT", new Pair(CompliantNotification.class, CompliantNotificationListener.class)))).when(registry).lookupAllByType(NotificationsProvider.class);
    final DisabledNotificationConfig disableNotificationConfig = new DisabledNotificationConfig();
    disableNotificationConfig.setInterfaceClass(CompliantNotificationListener.class);
    configurator.setDisabledNotifications(singletonList(disableNotificationConfig));
    configurator.initialise();
    verify(notificationManager).disableInterface(CompliantNotificationListener.class);
}
Also used : DisabledNotificationConfig(org.mule.runtime.config.internal.NotificationConfig.DisabledNotificationConfig) NotificationsProvider(org.mule.runtime.core.api.context.notification.NotificationsProvider) Pair(org.mule.runtime.api.util.Pair) Test(org.junit.Test)

Example 2 with NotificationsProvider

use of org.mule.runtime.core.api.context.notification.NotificationsProvider in project mule by mulesoft.

the class ServerNotificationManagerConfiguratorTestCase method compliantDisabledNotificationByEventClass.

@Test
public void compliantDisabledNotificationByEventClass() throws InitialisationException {
    doReturn(singletonList((NotificationsProvider) () -> singletonMap("test:COMPLIANT", new Pair(CompliantNotification.class, CompliantNotificationListener.class)))).when(registry).lookupAllByType(NotificationsProvider.class);
    final DisabledNotificationConfig disableNotificationConfig = new DisabledNotificationConfig();
    disableNotificationConfig.setEventClass(CompliantNotification.class);
    configurator.setDisabledNotifications(singletonList(disableNotificationConfig));
    configurator.initialise();
    verify(notificationManager).disableType(CompliantNotification.class);
}
Also used : DisabledNotificationConfig(org.mule.runtime.config.internal.NotificationConfig.DisabledNotificationConfig) NotificationsProvider(org.mule.runtime.core.api.context.notification.NotificationsProvider) Pair(org.mule.runtime.api.util.Pair) Test(org.junit.Test)

Example 3 with NotificationsProvider

use of org.mule.runtime.core.api.context.notification.NotificationsProvider in project mule by mulesoft.

the class ServerNotificationManagerConfiguratorTestCase method compliantDisabledNotificationByEventName.

@Test
public void compliantDisabledNotificationByEventName() throws InitialisationException {
    doReturn(singletonList((NotificationsProvider) () -> singletonMap("test:COMPLIANT", new Pair(CompliantNotification.class, CompliantNotificationListener.class)))).when(registry).lookupAllByType(NotificationsProvider.class);
    final DisabledNotificationConfig disableNotificationConfig = new DisabledNotificationConfig();
    disableNotificationConfig.setEventName("test:COMPLIANT");
    configurator.setDisabledNotifications(singletonList(disableNotificationConfig));
    configurator.initialise();
    verify(notificationManager).disableType(CompliantNotification.class);
}
Also used : DisabledNotificationConfig(org.mule.runtime.config.internal.NotificationConfig.DisabledNotificationConfig) NotificationsProvider(org.mule.runtime.core.api.context.notification.NotificationsProvider) Pair(org.mule.runtime.api.util.Pair) Test(org.junit.Test)

Example 4 with NotificationsProvider

use of org.mule.runtime.core.api.context.notification.NotificationsProvider in project mule by mulesoft.

the class ServerNotificationManagerConfigurator method populateNotificationTypeMappings.

public ServerNotificationManager populateNotificationTypeMappings(Map<String, Class<? extends Notification>> eventMap, Map<String, Class<? extends NotificationListener>> interfaceMap) throws InitialisationException {
    Map<String, NotificationsProvider> providersMap = new HashMap<>();
    for (NotificationsProvider provider : registry.lookupAllByType(NotificationsProvider.class)) {
        for (Entry<String, Pair<Class<? extends Notification>, Class<? extends NotificationListener>>> entry : provider.getEventListenerMapping().entrySet()) {
            final String notificationType = entry.getKey();
            if (!notificationType.matches("[a-zA-Z]+:[A-Z\\-]+")) {
                throw new InitialisationException(createStaticMessage("Notification '%s' declared in '%s' doesn't comply with the '[artifactID]:[NOTIFICATION-ID]' format", notificationType, provider.toString()), this);
            }
            if (eventMap.containsKey(notificationType)) {
                throw new InitialisationException(createStaticMessage("Notification '%s' declared in '%s' is already declared for another artifact in provider '%s'.", notificationType, provider.toString(), eventMap.get(notificationType)), this);
            }
            eventMap.put(notificationType, entry.getValue().getFirst());
            interfaceMap.put(notificationType, entry.getValue().getSecond());
            providersMap.put(notificationType, provider);
        }
    }
    ServerNotificationManager notificationManager = muleContext.getNotificationManager();
    if (dynamic != null) {
        notificationManager.setNotificationDynamic(dynamic.booleanValue());
    }
    return notificationManager;
}
Also used : HashMap(java.util.HashMap) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) ServerNotificationManager(org.mule.runtime.core.api.context.notification.ServerNotificationManager) NotificationsProvider(org.mule.runtime.core.api.context.notification.NotificationsProvider) ListenerSubscriptionPair(org.mule.runtime.core.api.context.notification.ListenerSubscriptionPair) Pair(org.mule.runtime.api.util.Pair)

Aggregations

Pair (org.mule.runtime.api.util.Pair)4 NotificationsProvider (org.mule.runtime.core.api.context.notification.NotificationsProvider)4 Test (org.junit.Test)3 DisabledNotificationConfig (org.mule.runtime.config.internal.NotificationConfig.DisabledNotificationConfig)3 HashMap (java.util.HashMap)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 ListenerSubscriptionPair (org.mule.runtime.core.api.context.notification.ListenerSubscriptionPair)1 ServerNotificationManager (org.mule.runtime.core.api.context.notification.ServerNotificationManager)1