munit matchers

14
MUNIT MATCHERS Shanky Gupta

Upload: shanky-gupta

Post on 13-Feb-2017

137 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: MUnit matchers

MUNIT MATCHERS

Shanky Gupta

Page 2: MUnit matchers

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.

Page 3: MUnit matchers

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

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

Page 4: MUnit matchers

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

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

Page 5: MUnit matchers

anyByte()

anyByteArray()

• Matches if the evaluated object is a Byte.

• Matches if the evaluated object is a ByteArray.

Page 6: MUnit matchers

anyInt()

anyDouble()

• Matches if the evaluated object is a Double.

• Matches if the evaluated object is an Integer.

Page 7: MUnit matchers

anyFloat()

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

• Matches if the evaluated object is a Float.

Page 8: MUnit matchers

anyString()

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

• Matches if the evaluated object is a String.

Page 9: MUnit matchers

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.

Page 10: MUnit matchers

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

Page 11: MUnit matchers

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

Page 12: MUnit matchers

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.

Page 13: MUnit matchers

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.

Page 14: MUnit matchers

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.