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
Checks that the expression is null.
o   #[MunitTools::nullValue()]
Checks that the expression is not null.
o   #[MunitTools::notNullValue()]
Checks that the expression’s media type is the one specified.
o   #[MunitTools::withMediaType('text/xml')]
Checks that the expression’s encoding is the one specified.
o   #[MunitTools::withEncoding('UTF-8')]
Checks that both provided matchers are successful.
o   #[MunitTools::both(MunitTools::notNullValue(),MunitTools::equalTo('example'))]
Checks that at least one of the matchers is successful.
o   #[MunitTools::either(MunitTools::nullValue(),MunitTools::equalTo(0))]
Checks if the provided matcher is not successful.
o   #[MunitTools::not(MunitTools::equalTo(0))]
Checks if any of the matchers are successful.
o   #[MunitTools::anyOf(MunitTools::notNullValue(),MunitTools::withMediaType('text/xml'),MunitTools::isEmptyString())]
Checks if all of the matchers are successful.
o   #[MunitTools::allOf(MunitTools::notNullValue(),MunitTo

String Matchers
These Matchers are meant to perform assertions over String expressions.
You can use these matchers to evaluate:

  • o   Whether the expression contains a specific String.
  • o   Whether the expression starts or ends with a specific String.
  • o   Whether the String in the expression has zero length.
  • o   Compare the String in the expression against a String determined by you.
These matchers are:
Matcher
Description
Example
Checks that the expression contains the specified String.
o   #[MunitTools::containsString('example')]
Checks that the expression starts with the specified String.
o   #[MunitTools::startsWith('exam')]
Checks that the expression ends with the specified String.
o   #[MunitTools::endsWith('ple')]
Checks that the expression has zero length.
o   #[MunitTools::isEmptyString()]
Checks that the expression is null, or has zero length.
o   #[MunitTools::isEmptyOrNullString()]
Checks that the expression is equal to the specified String, ignoring case.
o   #[MunitTools::equalToIgnoringCase('Example')]
Checks that the expression is equal to the string disregarding leading and trailing white spaces, and compression all inner white spaces to a single space.
o   #[MunitTools::equalToIgnoringWhiteSpace('An Example')]
Checks that the expression contains all of the specified substrings, regardless of the order of their appearance.
o   #[MunitTools::stringContainsInOrder('an', 'example')]


Jayaraman Pancharathinam
21 Nov 2018

Comments


  1. This is a nice article you shared great information I have read it thanks for giving such a wonderful Blog for the reader.
    Mulesoft Training in Hyderabad
    Mulesoft Online Training

    ReplyDelete
  2. This information is really awesome thanks for sharing most valuable information.
    Mulesoft Online Training
    Mulesoft Online Training in Hyderabad

    ReplyDelete
  3. Thank you for sharing the valuable information.
    msbi training online | msbi online training
    Contact Information:
    USA: +1 7327039066
    INDIA: +91 8885448788 , 9550102466
    Email: info@onlineitguru.com

    ReplyDelete

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?