%dw 2.0
import dw::tests::Asserts
---
payload must beObject()
dataweave
DataWeave Assertions Library
dw::test::Asserts
This module contains the set of core Matchers to use in your tests
Validates if a payload is of type Object
Functions
anyOf
anyOf(Array<Matcher<Any>>): Matcher<Any>
Validates that the value satisfies at least one of the given matchers
%dw 2.0
import dw::tests::Asserts
---
"A Text" must anyOf(beObject(), beString())
dataweave
beArray
beArray(): Matcher
Validates that a given value is of type Array
%dw 2.0
import dw::tests::Asserts
---
[1, 4, 7] must beArray()
dataweave
beBlank
beBlank(): Matcher<String | Null>
Validates that the String value is blank
%dw 2.0
import dw::tests::Asserts
---
" " must beBlank()
dataweave
beBoolean
beBoolean(): Matcher
Validates that a given value is of type Boolean
%dw 2.0
import dw::tests::Asserts
---
true must beBoolean()
dataweave
beEmpty
beEmpty(): Matcher<String | Object | Array | Null>
Validates that the value (String, Object or Array) is empty
%dw 2.0
import dw::tests::Asserts
---
[] must beEmpty()
dataweave
beGreaterThan
beGreaterThan(Comparable, Boolean): Matcher<Comparable>
Validates that the asserted Comparable value is greater than the given one
Can be equal to when using the inclusive argument
%dw 2.0
import dw::tests::Asserts
---
3 must beGreaterThan(2)
dataweave
beLowerThan
beLowerThan(Comparable, Boolean): Matcher<Comparable>
Validates that the asserted Comparable value is lower than the given one
Can be equal to when using the inclusive argument
%dw 2.0
import dw::tests::Asserts
---
1 must beLowerThan(2)
dataweave
beNull
beNull(): Matcher
Validates that a given value is of type Null
%dw 2.0
import dw::tests::Asserts
---
null must beNull()
dataweave
beNumber
beNumber(): Matcher
Validates that a given value is of type Number
%dw 2.0
import dw::tests::Asserts
---
123 must beNumber()
dataweave
beObject
beObject(): Matcher
Validates that a given value is of type Object
%dw 2.0
import dw::tests::Asserts
---
{ name : "Lionel", lastName: "Messi"} must beObject()
dataweave
beOneOf
beOneOf(Array<Any>): Matcher
Validates that the value is contained in the given Array
%dw 2.0
import dw::tests::Asserts
---
1 must beOneOf([1, "A Text", true])
dataweave
beString
beString(): Matcher
Validates that a given value is of type String
%dw 2.0
import dw::tests::Asserts
---
"A Text" must beString()
dataweave
contain
contain(String): Matcher<String>
Validates that the asserted String contains the given String
%dw 2.0
import dw::tests::Asserts
---
"A Text" must contain("ex")
dataweave
contain(Any): Matcher<Array<Any>>
Validates that the asserted Array contains the given value
%dw 2.0
import dw::tests::Asserts
---
[1, "A Text", true] must contain(1)
dataweave
eachItem
eachItem(Matcher<Any>): Matcher<Array<Any>>
Validates that each item of the array satisfies the given matcher
%dw 2.0
import dw::tests::Asserts
---
[1,2,3] must eachItem(beNumber())
dataweave
endWith
endWith(String): Matcher<String>
Validates that the asserted String ends with the given String
%dw 2.0
import dw::tests::Asserts
---
"A Text" must endWith("xt")
dataweave
equalTo
equalTo(Any, { unordered?: Boolean }): Matcher<Any>
Validates that a value is equal to another one
%dw 2.0
import dw::tests::Asserts
---
(1 + 2) must equalTo(3)
dataweave
equalToResource
equalToResource(String, String, Object): Matcher<Any>
Validates that the given value is equal to the content of a resource file
The resource file must belong to the classpath
%dw 2.0
import dw::tests::Asserts
---
{ name: "Lionel", lastName: "Messi" } must equalToResource("user.json", "application/json")
dataweave
haveItem
haveItem(Matcher<Any>): Matcher<Array<Any>>
Validates that at least one item of the array satisfies the given matcher
%dw 2.0
import dw::tests::Asserts
---
[1, true, "a text"] must haveItem(beNumber())
dataweave
haveKey
haveKey(String): Matcher<Object>
Validates that the Object has the given key
%dw 2.0
import dw::tests::Asserts
---
{ name: "Lionel", lastName: "Messi" } must haveKey("name")
dataweave
haveSize
haveSize(Number): Matcher<Array | String | Object>
Validates that the array has the given size
%dw 2.0
import dw::tests::Asserts
---
[1, 4, 7] must haveSize(3)
dataweave
haveValue
haveValue(Any): Matcher<Object>
Validates that the Object has the given value
%dw 2.0
import dw::tests::Asserts
---
{ name: "Lionel", lastName: "Messi" } must haveValue("Messi")
dataweave
must
must(T, Array<(value: T) → Matcher<T> | MatcherResult | Boolean>): MatcherResult
This function allows to assert a value with with a list of Matcher of Expressions
%dw 2.0
import dw::tests::Asserts
---
payload must [
beObject(),
$.foo is Null
]
dataweave
must(T, (value: T) → Matcher<T> | Boolean): MatcherResult
This function allows to assert a value with a Matcher of Expressions
%dw 2.0
import dw::tests::Asserts
---
payload must beObject()
dataweave
notBe
notBe(Matcher<T>): Matcher<T>
Validates that the value doesn’t satisfy the given matcher
%dw 2.0
import dw::tests::Asserts
---
1 must notBe(equalTo(2))
dataweave
notBeNull
notBeNull(): Matcher
Validates that a given value isn’t of type Null
%dw 2.0
import dw::tests::Asserts
---
"A Text" must notBeNull()
dataweave
startWith
startWith(String): Matcher<String>
Validates that the asserted String starts with the given String
%dw 2.0
import dw::tests::Asserts
---
"A Text" must startWith("A")
dataweave
Variables
MATCHED
Constant that represents a successful match
Types
Matcher
Data Type that represents a Matcher to perform assertions
%dw 2.0
import dw::tests::Asserts
fun beEqualToOne(): Matcher<Any> =
(actual) -> do {
{
matches: actual == 1,
description: { expected: "To be 1", actual: write(actual) as String }
}
}
dataweave
(value: T) -> MatcherResult
dataweave
MatcherResult
Data Type that represents the result of an Assertion
{
"matches": false,
description : { expected : "Number type", actual: "A Text" }
}
dataweave
{ matches: Boolean, description: { expected: String, actual: String }, reasons?: Array<String> }
dataweave