I have to use a Mule Requester Inside MUnit test case to read a file under src/test/resources so that i can assert the payload . With the current implementation I have Ftp connector inside MUnits xml which I am referring from mule requester . I clearly see that mule requester is trying to access the connector even before it it initialized . Is there any way i can tell mule to early intialize ftp connector ?
Exception :
********************************************************************************
Message : Cannot perform an action on a connector when it is not started. Connector "no-delete-file-connector-test" is currently in lifecycle phase "initialise"
Element : /no-delete-file-connector-test @ app:haz001-test-suite.xml:33 (File)
--------------------------------------------------------------------------------
Exception stack is:
Cannot perform an action on a connector when it is not started. Connector "no-delete-file-connector-test" is currently in lifecycle phase "initialise" (org.mule.api.lifecycle.LifecycleException)
org.mule.transport.AbstractConnector.getRequester(AbstractConnector.java:1178)
org.mule.transport.AbstractConnector.request(AbstractConnector.java:2269)
org.mule.transport.file.FileConnector$$EnhancerByCGLIB$$d6c65eff.CGLIB$request$75(<generated>:-1)
(97 more...)
(set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
Following is my configuration :
<flow-ref name="processMainFlow" doc:name="processMainFlow" />
<mulerequester:request resource="file://src/test/resources/expected-discrete.csv?connector=no-delete-file-connector-test" doc:name="Mule Requester" returnClass="java.lang.String"/>
<munit:assert-payload-equals expectedValue="#[flowVars.outputCSV]" doc:name="Assert Payload"/>
<logger message="response for test #[payload] actual data : #[flowVars.outputCSV]" level="INFO"
doc:name="Logger" />
To load a file in your Munit test, you don't need the file connector, use a Set Payload or Set Message, eg:
<set-payload value="#[getResource('expected-discrete.csv').asStream()]" doc:name="Set Payload"/>
The path inside getResource is relative to testResources specified in your pom file (defaults to src/test/munit and src/test/resources).
The file connector is stopped because that is the default behaviour of connectors in Munit tests. There is more info about this in the Mulesoft forums: https://forums.mulesoft.com/questions/44649/munit-config-mock-inbounds-mock-connectors.html