Search in sources :

Example 1 with MessageProcessorNotification

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

the class DefaultMessageProcessorChainTestCase method testSuccessNotifications.

@Test
public void testSuccessNotifications() throws Exception {
    List<MessageProcessorNotification> notificationList = new ArrayList<>();
    setupMessageProcessorNotificationListener(notificationList);
    DefaultMessageProcessorChainBuilder builder = new DefaultMessageProcessorChainBuilder();
    builder.chain(getAppendingMP("1"));
    final CoreEvent inEvent = getTestEventUsingFlow("0");
    final String resultPayload = "01";
    assertThat(process(builder.build(), inEvent).getMessage().getPayload().getValue(), equalTo(resultPayload));
    assertThat(notificationList, hasSize(2));
    MessageProcessorNotification preNotification = notificationList.get(0);
    MessageProcessorNotification postNotification = notificationList.get(1);
    assertPreNotification(inEvent, preNotification);
    assertThat(postNotification.getAction().getActionId(), equalTo(MESSAGE_PROCESSOR_POST_INVOKE));
    assertThat(postNotification.getEventContext(), equalTo(inEvent.getContext()));
    assertThat(postNotification.getEvent(), not(equalTo(inEvent)));
    assertThat(postNotification.getEvent().getMessage().getPayload().getValue(), equalTo(resultPayload));
    assertThat(postNotification.getException(), is(nullValue()));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ArrayList(java.util.ArrayList) MessageProcessorNotification(org.mule.runtime.api.notification.MessageProcessorNotification) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 2 with MessageProcessorNotification

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

the class DefaultMessageProcessorChainTestCase method testErrorNotificationsMessagingException.

@Test
public void testErrorNotificationsMessagingException() throws Exception {
    List<MessageProcessorNotification> notificationList = new ArrayList<>();
    setupMessageProcessorNotificationListener(notificationList);
    DefaultMessageProcessorChainBuilder builder = new DefaultMessageProcessorChainBuilder();
    final CoreEvent messagingExceptionEvent = getTestEventUsingFlow("other");
    final MessagingException messagingException = new MessagingException(messagingExceptionEvent, illegalStateException);
    builder.chain(new ExceptionThrowingMessageProcessor(messagingException));
    final CoreEvent inEvent = getTestEventUsingFlow("0");
    try {
        process(builder.build(), inEvent);
    } catch (Throwable t) {
        assertThat(t, instanceOf(IllegalStateException.class));
        assertThat(notificationList, hasSize(2));
        MessageProcessorNotification preNotification = notificationList.get(0);
        MessageProcessorNotification postNotification = notificationList.get(1);
        assertPreNotification(inEvent, preNotification);
        assertThat(postNotification.getAction().getActionId(), equalTo(MESSAGE_PROCESSOR_POST_INVOKE));
        // Existing MessagingException.event is updated to include error
        assertThat(postNotification.getEvent(), not(messagingExceptionEvent));
        assertPostErrorNotification(inEvent, postNotification);
    }
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) ArrayList(java.util.ArrayList) MessageProcessorNotification(org.mule.runtime.api.notification.MessageProcessorNotification) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 3 with MessageProcessorNotification

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

the class DefaultMessageProcessorChainTestCase method testErrorNotifications.

@Test
public void testErrorNotifications() throws Exception {
    List<MessageProcessorNotification> notificationList = new ArrayList<>();
    setupMessageProcessorNotificationListener(notificationList);
    DefaultMessageProcessorChainBuilder builder = new DefaultMessageProcessorChainBuilder();
    builder.chain(new ExceptionThrowingMessageProcessor(illegalStateException));
    final CoreEvent inEvent = getTestEventUsingFlow("0");
    try {
        process(builder.build(), inEvent);
    } catch (Throwable t) {
        assertThat(t, is(illegalStateException));
        assertThat(notificationList, hasSize(2));
        MessageProcessorNotification preNotification = notificationList.get(0);
        MessageProcessorNotification postNotification = notificationList.get(1);
        assertPreNotification(inEvent, preNotification);
        assertThat(postNotification.getAction().getActionId(), equalTo(MESSAGE_PROCESSOR_POST_INVOKE));
        assertThat(postNotification.getEventContext(), equalTo(inEvent.getContext()));
        assertPostErrorNotification(inEvent, postNotification);
    }
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ArrayList(java.util.ArrayList) MessageProcessorNotification(org.mule.runtime.api.notification.MessageProcessorNotification) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 MessageProcessorNotification (org.mule.runtime.api.notification.MessageProcessorNotification)3 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)3 SmallTest (org.mule.tck.size.SmallTest)3 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)1