I am trying to write MUnit tests for my Mule flows. I want to write a test for the below flow
The interesting bit is the exception sub-flow, especially the collection-aggregator
My unit test is
@Test
public void whenMultipleExceptionsOccurInFlow_itShouldSendOnlyOneFailureEmail() throws Exception {
whenMessageProcessor("collection-aggregator")
.withAttributes(attribute("name").ofNamespace("doc").withValue("Exception Aggregator")).thenReturnSameEvent();
destinationSFTP.thenThrow(new RuntimeException("Dummy Exception destinationSFTP"));
MuleEvent testEvent = PropertyEnricher.enrich(testEvent(IOUtils.toInputStream("hello,dummy,payload"))).get();
runFlow("DownloadFTPFileIntoLocalFlow", testEvent);
verifyCallOfMessageProcessor("outbound-endpoint").ofNamespace("smtp")
.withAttributes(attribute("name").ofNamespace("doc").withValue("ErrorEmail"))
.times(1);
}
Now if I do not mock the collection aggregator out my test does not pass, I can understand that this is tricky as the aggregator has a "pause" within it and hence is not an ideal candidate for a unit test, however from a technical standpoint I want to understand what is causing the unit test to fail (when collection-aggregator is not mocked).
The exception I get when the collection-aggregator is not mocked is as follows
Message : Dummy Exception destinationSFTP (java.lang.RuntimeException). Message payload is of type: String
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Dummy Exception destinationSFTP (java.lang.RuntimeException)
nz.co.mightyriver.ProcessCsvTest:87 (null)
2. Dummy Exception destinationSFTP (java.lang.RuntimeException). Message payload is of type: String (org.mule.api.MessagingException)
org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:32 (http://ift.tt/1fnsxr9)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.RuntimeException: Dummy Exception destinationSFTP
at nz.co.mightyriver.ProcessCsvTest.whenMultipleExceptionsOccurInFlow_itShouldSendOnlyOneFailureEmail(ProcessCsvTest.java:87)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
The exception does not pinpoint the root cause.
Aucun commentaire:
Enregistrer un commentaire