Search in sources :

Example 1 with EVENT_RECEIVED

use of org.mule.runtime.core.api.context.notification.ServerNotificationsTestCase.DummyNotification.EVENT_RECEIVED in project mule by mulesoft.

the class ServerNotificationsTestCase method testCustomNotifications.

@Test
public void testCustomNotifications() throws Exception {
    final CountDownLatch latch = new CountDownLatch(2);
    getNotificationListenerRegistry().registerListener((DummyNotificationListener) notification -> {
        if (new IntegerAction(EVENT_RECEIVED).equals(notification.getAction())) {
            customNotificationCount.incrementAndGet();
            assertEquals("hello", ((EventObject) notification).getSource());
            latch.countDown();
        }
    });
    getNotificationDispatcher().dispatch(new DummyNotification("hello", EVENT_RECEIVED));
    getNotificationDispatcher().dispatch(new DummyNotification("hello", EVENT_RECEIVED));
    // Wait for the notifcation event to be fired as they are queued
    latch.await(2000, MILLISECONDS);
    assertEquals(2, customNotificationCount.get());
}
Also used : EVENT_RECEIVED(org.mule.runtime.core.api.context.notification.ServerNotificationsTestCase.DummyNotification.EVENT_RECEIVED) CustomNotificationListener(org.mule.runtime.api.notification.CustomNotificationListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callable(java.util.concurrent.Callable) EventObject(java.util.EventObject) Mockito.doThrow(org.mockito.Mockito.doThrow) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Notification(org.mule.runtime.api.notification.Notification) MuleContext(org.mule.runtime.core.api.MuleContext) Scheduler(org.mule.runtime.api.scheduler.Scheduler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CONTEXT_STOPPED(org.mule.runtime.core.api.context.notification.MuleContextNotification.CONTEXT_STOPPED) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) SchedulerService(org.mule.runtime.api.scheduler.SchedulerService) Test(org.junit.Test) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Mockito.when(org.mockito.Mockito.when) CustomNotification(org.mule.runtime.api.notification.CustomNotification) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) NotificationListenerRegistry(org.mule.runtime.api.notification.NotificationListenerRegistry) CountDownLatch(java.util.concurrent.CountDownLatch) Mockito.never(org.mockito.Mockito.never) IntegerAction(org.mule.runtime.api.notification.IntegerAction) AbstractMuleContextTestCase(org.mule.tck.junit4.AbstractMuleContextTestCase) Assert.assertFalse(org.junit.Assert.assertFalse) NotificationDispatcher(org.mule.runtime.api.notification.NotificationDispatcher) NotificationListener(org.mule.runtime.api.notification.NotificationListener) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) IntegerAction(org.mule.runtime.api.notification.IntegerAction) CountDownLatch(java.util.concurrent.CountDownLatch) EventObject(java.util.EventObject) Test(org.junit.Test)

Aggregations

EventObject (java.util.EventObject)1 Callable (java.util.concurrent.Callable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Test (org.junit.Test)1 Matchers.any (org.mockito.Matchers.any)1 Mockito.doThrow (org.mockito.Mockito.doThrow)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.never (org.mockito.Mockito.never)1 Mockito.times (org.mockito.Mockito.times)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.when (org.mockito.Mockito.when)1 CustomNotification (org.mule.runtime.api.notification.CustomNotification)1 CustomNotificationListener (org.mule.runtime.api.notification.CustomNotificationListener)1