Search in sources :

Example 1 with TYPE_ERROR

use of org.mule.runtime.api.notification.AbstractServerNotification.TYPE_ERROR 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());
}
Also used : Test(org.junit.Test) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) NotificationListenerRegistry(org.mule.runtime.api.notification.NotificationListenerRegistry) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) CountDownLatch(java.util.concurrent.CountDownLatch) IntegerAction(org.mule.runtime.api.notification.IntegerAction) MuleContext(org.mule.runtime.core.api.MuleContext) AbstractMuleContextTestCase(org.mule.tck.junit4.AbstractMuleContextTestCase) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TYPE_ERROR(org.mule.runtime.api.notification.AbstractServerNotification.TYPE_ERROR) Collections.singletonMap(java.util.Collections.singletonMap) EXCEPTION_ACTION(org.mule.runtime.api.notification.ExceptionNotification.EXCEPTION_ACTION) ExceptionNotificationListener(org.mule.runtime.api.notification.ExceptionNotificationListener) NotificationDispatcher(org.mule.runtime.api.notification.NotificationDispatcher) LOCATION_KEY(org.mule.runtime.api.component.AbstractComponent.LOCATION_KEY) Assert.assertEquals(org.junit.Assert.assertEquals) IntegerAction(org.mule.runtime.api.notification.IntegerAction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) NotificationListenerRegistry(org.mule.runtime.api.notification.NotificationListenerRegistry) NotificationDispatcher(org.mule.runtime.api.notification.NotificationDispatcher) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

Collections.singletonMap (java.util.Collections.singletonMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Test (org.junit.Test)1 LOCATION_KEY (org.mule.runtime.api.component.AbstractComponent.LOCATION_KEY)1 TYPE_ERROR (org.mule.runtime.api.notification.AbstractServerNotification.TYPE_ERROR)1 EXCEPTION_ACTION (org.mule.runtime.api.notification.ExceptionNotification.EXCEPTION_ACTION)1 ExceptionNotificationListener (org.mule.runtime.api.notification.ExceptionNotificationListener)1 IntegerAction (org.mule.runtime.api.notification.IntegerAction)1 NotificationDispatcher (org.mule.runtime.api.notification.NotificationDispatcher)1 NotificationListenerRegistry (org.mule.runtime.api.notification.NotificationListenerRegistry)1 MuleContext (org.mule.runtime.core.api.MuleContext)1 MuleContextWithRegistries (org.mule.runtime.core.internal.context.MuleContextWithRegistries)1 AbstractMuleContextTestCase (org.mule.tck.junit4.AbstractMuleContextTestCase)1