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, Mule 4, MUnit 2.1.3, Anypoint Studio, Mocking, SOAP web service call, Transform processor, Dataweave, %dw 2.0

Comments

Post a Comment

Popular posts from this blog

How to read xml file and set as mock response for an http web service call in MUnit 2.1.3 in Mule 4?

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?