munit matchers

Post on 13-Feb-2017

140 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

MUNIT MATCHERS

Shanky Gupta

OVERVIEW

MUnit matchers are a set of MEL functions that help in the creation of mocks and validations (verifications/assertions). They enable you to define mocks, verifications and assertions in terms of general values rather than specific hardcoded values.

A matcher is a boolean function. In most of the MUnit matchers, this function is a class type comparison. Its purpose is to validate if an argument belongs to a certain class type.

A matcher does not receive parameters; rather, it’s a parameter itself.

isNull()• Matches if the evaluated object is Null.

isNotNull()• Matches if the evaluated object is not Null.

anyObject()• Matches if the evaluated object is an Object.

anyBoolean()• Matches if the evaluated object is a Boolean.

anyByte()

anyByteArray()

• Matches if the evaluated object is a Byte.

• Matches if the evaluated object is a ByteArray.

anyInt()

anyDouble()

• Matches if the evaluated object is a Double.

• Matches if the evaluated object is an Integer.

anyFloat()

anyShort()• Matches if the evaluated object is a Short.

• Matches if the evaluated object is a Float.

anyString()

anyCollection()• Matches if the evaluated object is a Collection.

• Matches if the evaluated object is a String.

anyList()

anySet()

anyMap()

• Matches if the evaluated object is a List.

• Matches if the evaluated object is a Set.

• Matches if the evaluated object is a Map.

…MATCHER FUNCTIONS CONTINUEDMUnit also offers some additional, rather specific, type of matchers.

These matchers evaluate thecontent of the parameter, not its type; even so, they do not evaluate by specific values.

matchRegex(<regex>)

matchContains(<string_to_look_for>)

• Matches if the value of the attribute during the test run verifies the user-provided regular expression

• Matches if the value of the attribute during the test run contains the specified user-provided string.

USAGE INSTRUCTION• MUnit matchers are always used in combination with the Mocks, Spy, Verify and Assert message processors, but never on their own.

MUNIT MATCHERS OVER MULE MESSAGE PROPERTIES

• If you wish to run assertions over Mule message properties and use MUnit matchers, you can use the valueOf() function.

• To make it easier to write this type of assertions, MUnit offers a another set of MEL functions that provide direct access for Mule message’s properties ElementMatcher.

messageInboundProperty(propertyName)• Returns an ElementMatcher for the inbound property with

the name provided.

messageOutboundProperty(propertyName)

messageInvocationProperty(propertyName)

• Returns an ElementMatcher for the outbound property with the name provided.

• Returns an ElementMatcher for the invocation property with the name provided.

messageInboundAttachment(propertyName)

messageOutboundAttachment(propertyName)

• Returns an ElementMatcher for the inbound attachment with the name provided.

• Returns an ElementMatcher for the outbound attachment with the name provided.

top related