How to read xml file and set as mock response for an http web service call in MUnit 2.1.3 in Mule 4?
Reading XML file from src/test/resources folder and set as mock response for a http web service call in MUnit 2.1.3 in mule 4
You need to place the XML file under src/test/resources in order read by MUnit tools. And it has to be mentioned as below.
<munit-tools:mock-when doc:name="Mock when" doc:id="9bc2c6a1-dd68-4d19-a8b0-0ad1b892b015" processor="wsc:consume">
<munit-tools:with-attributes >
<munit-tools:with-attribute attributeName="doc:name" whereValue="Get Token" />
</munit-tools:with-attributes>
<munit-tools:then-return >
<munit-tools:payload value="#[MunitTools::getResourceAsString('getTokenWS_response.xml')]"
mediaType="application/xml"/>
</munit-tools:then-return>
</munit-tools:mock-when>
In case the file located in the sub folder, it need to be specified as below.
<munit-tools:payload value="#[MunitTools::getResourceAsString('scaffolder/mockData/getTokenWS_response.xml')]"
mediaType="application/xml"/>
Thanks
Jayaraman Pancharathinam
28 Nov 2018
Keywords: Mulesoft, Mule 4, MUnit 2.1.3, Anypoint Studio, Mocking, SOAP web service call, Transform processor, Dataweave, %dw 2.0
Hi Jayaraman,
ReplyDeleteI am sorry to ask but is this working example ? because the output of wsc:consume is not XML nut a java object.
Hi vasanth/Jayaraman,
ReplyDeleteAs we are not getting response java and xml from wsc:consume.
did you guys have any solution for this , how we will store the response for munit 2.0
Thanks,
Jitendra
This post is wonderful and thanks for sharing
ReplyDeleteMulesoft Online Training
Mulesoft Training in Hyderabad
ReplyDeleteThank you for sharing wonderful information
Mulesoft Online Training in Hyderabad
Mulesoft Online Training Hyderabad
Thanks for the blog article.Thanks Again. Keep writing.
ReplyDeleteMuleSoft training
MuleSoft online training