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()));
}
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);
}
}
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);
}
}
Aggregations