Posts

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 lo...

How to validate Http 401 Unauthorized error using vars.httpStatus returned by Dataweave 2.0 in MUnit 2.1.3 in Mule 4?

Validating or Asserting http status code which is returned by data weave 2.0 in mule 4 In case the httpStatus is set by Transform and here is the way to validate it. Please note that by default the error code is type of Number.  Ensure that you are considered as number during validation and not adding any quotes around code.   < munit:validation >        < munit-tools:assert-that doc:name = "Check http.Status 401" doc:id = "93e077c8-012c-46b8-ad41-14367f695fbc" expression = "#[vars . httpStatus]" is = " #[MunitTools::equalTo (401) ] " message = 'Expected output is Http Unauthorized error' />        < logger level = "INFO" doc:name = "Logger" doc:id = "40df23fa-e9e1-4061-83bb-d806518a5010" message = " #[payload] " /> </ munit:validation > Thanks Jayaraman Pancharathinam 28 Nov 2018 Keywords: Mulesoft, Mul...

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

Image
Setting Headers and UriParams in MUnit test case in Mule 4 Set Event Processor can be used to pass headers before calling any sub-flow in MUnit test flow.  Uri Parameters also can be set in the same way. Headers < munit:set-event doc:name = "Set Event" doc:id = "70453df1-e368-488b-abcc-f8522185dd4f" >        < munit:payload value = " #[''] " encoding = "UTF-16" />        < munit:attributes value = " #[{headers : {' token ' :' b536b9a9-5e11-4773-93d3-8c973519ad54 ' , ' role ' :' Administrator,User '}}] " encoding = "UTF-16" /> </ munit:set-event >   UriParams < munit:set-event doc:name = "Set Event" doc:id = "70453df1-e368-488b-abcc-f8522185dd4f" >        < munit:payload value = " #[''] " encoding = "UTF-16" />        < munit:attributes...

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

Creating a test case with mocking of SOAP web service call using MUnit 2.1.3 in Mulesoft Transform processor will not work if you are just providing the original response of SOAP service as mock response. So you need to you tweak little in order to make it work with Transform message processor. Look at the following example.  The is the complete SOAP message taken from the original response. <? xml version = '1.0' encoding = 'windows-1252' ?> < body > < env:Envelope xmlns:env = " http://schemas.xmlsoap.org/soap/envelope/ " >    < env:Header />    < env:Body >       < m:getTokenWSResponse xmlns:m = " http://example.net/example-services " >          < m:SessionResponse >             < com:RequestStatus xmlns:com = " http://example.net/security/common " > 0 </ com:R...

MUnit Matchers - MUnit Tools - v2.1

MUnit Matchers MUnit matchers are a set of DataWeave functions to define assertion conditions in terms of general values instead of specific hardcoded values . When defining matchers you need to add the  MunitTools::  prefix to the expression. Matchers are grouped according to the type of conditions you want to validate. You can find: Core Matchers These matchers evaluate core values in the expression. You can use these matchers to evaluate: o    Whether the expression is null or not. o    Media Type or Encoding of the expression. o    Whether the returns false. o    Whether two evaluations were successful. These matchers are: Matcher Description Example nullValue() Checks that the expression is null. o    #[MunitTools::nullValue()] notNullValue() Checks that the expression is not null. o    #[MunitTools::notNullValue(...