Reputation: 887
I am testing my Mule flows and want to make them modular in order to test individual parts. Take the following for example:
<flow name="in" doc:name="in">
<sftp:inbound-endpoint
connector-ref="sftp"
address="sftp://test:test@localhost:${sftp.port}/~/folder" autoDelete="false" doc:name="SFTP">
</sftp:inbound-endpoint>
<vm:outbound-endpoint path="out" />
</flow>
My Mule test then requests the message off the out VM queue to test that a file is correctly picked up etc:
MuleMessage message = muleClient.request("vm://out", 10000L);
Is this a good practice or would it be better using the FunctionalTestComponent to check the event received?
By using vm instead of the FunctionalTestComponent I don't need to change my flows for testing purposes which is a plus.
However by doing so , I am unsure of the consequences. I heard flow-ref was the preffered way to modularise flows, but that doesn't allow me to pick up the message in my test etc. Any advice or best practice appreciated.
Upvotes: 1
Views: 506
Reputation: 644
I think that my recent blog post can serve you well with your doubts. I wrote down what I recon as best practices in terms of Mule flow designing. I focused heavily on the testing side (using MUnit framework). With it you can easily mock any message processor (it includes flows and sub-flows): http://poznachowski.blogspot.co.uk/2014/04/munit-testing-mule-practices-and-some.html
Upvotes: 1
Reputation: 33413
Modularizing around request-response VM endpoints has several drawbacks including the loss of inbound properties and the introduction of an extra hop with potential performance cost, something flow-ref doesn't have. One-way VM endpoints offer a different functionality than flow-ref so can't really be compared.
The problem with private flows or sub-flows that you invoke with flow refs is that it's hard to invoke them from code. It's possible but hard.
One workaround I've found is to create test flows with VM inbound endpoints in a test configuration file and use them to inject test messages via flow-ref to private/sub flows. The advantage is that the main configuration files are unaffected.
Upvotes: 1