0

I am implementing Munit for a flow which involves Mule Requester. This mule requester would be picking up a file.

So, when i run the java class as Junit, it throws out an exception as, Cannot perform the operation on the FileConnector as it is stopped.

The expression used in mule requester is ,

file ://${path}?connector=FileConnector

I have also defined a global file connector.

Please let me know how to resolve this issue.

Thank you.

2 Answers2

1

All connectors and inbound-endpoints are disabled by default in MUnit. This is to prevent flow accidentally processing/generating real data. (Some explanation here). For the same reason File Connector is also disabled.

To enable connectors, you need to override a method in your MUnitsuite as below -

@Override
protected boolean haveToMockMuleConnectors() {
    return false;
}

For XML Munit, see this to enable connectors.

Note: This will enable and start all the connectors that you are using in your mule-configs under test. If you have SMTP connector, DB connector, MQ connector etc, they all be started during test, so use it with caution.

Manik Magar
  • 1,403
  • 2
  • 10
  • 20
  • Thanks Manik.. It does work now. However why can't it work when we disable the mock . Because ideally, it's recommended not to connect to endpoints. – Shivchetan Sambaragimath Jul 28 '16 at 05:14
  • Yes, it is recommended to keep inbound endpoints and connectors mocked and they are mocked by default. If you keep connectors mocked then you would also need to mock your any **outbound-endpoints**. So if you mock the `mulerequester:request` that is triggering your file connector, you wouldn't need to unmock the connectors. – Manik Magar Jul 28 '16 at 12:53
0

Check whether the file connector is defined in the files you loaded for munit.

 <spring:beans>
    <spring:import resource="classpath:api.xml"/>
 </spring:beans>

You may also try mocking the mule requester.

tortoise
  • 613
  • 1
  • 7
  • 19