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

Comments

  1. Hi Jayaraman,
    I am sorry to ask but is this working example ? because the output of wsc:consume is not XML nut a java object.

    ReplyDelete
  2. Hi vasanth/Jayaraman,

    As 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

    ReplyDelete

Post a Comment

Popular posts from this blog

How to set headers before calling a sub-flow in MUnit 2.1.3 in Mule 4?

How to mock SOAP web service call with a SOAP message in MUnit 2.1.3?