1. dw::test::Asserts
This module contains the set of core Matchers to use in your tests
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
payload must beObject()
Validates if a payload is of type Object
1.1. Functions
1.1.1. anyOf
anyOf(Array<Matcher<Any>>): Matcher<Any>
Validates that the value satisfies at least one of the given matchers
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
"A Text" must anyOf(beObject(), beString())
1.1.2. beArray
beArray(): Matcher
Validates that a given value is of type Array
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
[1, 4, 7] must beArray()
1.1.3. beBlank
beBlank(): Matcher<String | Null>
Validates that the String value is blank
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
" " must beBlank()
1.1.4. beBoolean
beBoolean(): Matcher
Validates that a given value is of type Boolean
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
true must beBoolean()
1.1.5. beEmpty
beEmpty(): Matcher<String | Object | Array | Null>
Validates that the value (String, Object or Array) is empty
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
[] must beEmpty()
1.1.6. 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
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
3 must beGreaterThan(2)
1.1.7. 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
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
1 must beLowerThan(2)
1.1.8. beNull
beNull(): Matcher
Validates that a given value is of type Null
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
null must beNull()
1.1.9. beNumber
beNumber(): Matcher
Validates that a given value is of type Number
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
123 must beNumber()
1.1.10. beObject
beObject(): Matcher
Validates that a given value is of type Object
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
{ name : "Lionel", lastName: "Messi"} must beObject()
1.1.11. beOneOf
beOneOf(Array<Any>): Matcher
Validates that the value is contained in the given Array
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
1 must beOneOf([1, "A Text", true])
1.1.12. beString
beString(): Matcher
Validates that a given value is of type String
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
"A Text" must beString()
1.1.13. contain
contain(String): Matcher<String>
Validates that the asserted String contains the given String
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
"A Text" must contain("ex")
contain(Any): Matcher<Array<Any>>
Validates that the asserted Array contains the given value
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
[1, "A Text", true] must contain(1)
1.1.14. eachItem
eachItem(Matcher<Any>): Matcher<Array<Any>>
Validates that each item of the array satisfies the given matcher
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
[1,2,3] must eachItem(beNumber())
1.1.15. endWith
endWith(String): Matcher<String>
Validates that the asserted String ends with the given String
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
"A Text" must endWith("xt")
1.1.16. equalTo
equalTo(Any, { unordered?: Boolean }): Matcher<Any>
Validates that a value is equal to another one
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
(1 + 2) must equalTo(3)
1.1.17. 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
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
{ name: "Lionel", lastName: "Messi" } must equalToResource("user.json", "application/json")
1.1.18. haveItem
haveItem(Matcher<Any>): Matcher<Array<Any>>
Validates that at least one item of the array satisfies the given matcher
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
[1, true, "a text"] must haveItem(beNumber())
1.1.19. haveKey
haveKey(String): Matcher<Object>
Validates that the Object has the given key
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
{ name: "Lionel", lastName: "Messi" } must haveKey("name")
1.1.20. haveSize
haveSize(Number): Matcher<Array | String | Object>
Validates that the array has the given size
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
[1, 4, 7] must haveSize(3)
1.1.21. haveValue
haveValue(Any): Matcher<Object>
Validates that the Object has the given value
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
{ name: "Lionel", lastName: "Messi" } must haveValue("Messi")
1.1.22. 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
1
2
3
4
5
6
7
%dw 2.0
import dw::tests::Asserts
---
payload must [
beObject(),
$.foo is Null
]
must(T, (value: T) → Matcher<T> | Boolean): MatcherResult
This function allows to assert a value with a Matcher of Expressions
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
payload must beObject()
1.1.23. notBe
notBe(Matcher<T>): Matcher<T>
Validates that the value doesn’t satisfy the given matcher
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
1 must notBe(equalTo(2))
1.1.24. notBeNull
notBeNull(): Matcher
Validates that a given value isn’t of type Null
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
"A Text" must notBeNull()
1.1.25. startWith
startWith(String): Matcher<String>
Validates that the asserted String starts with the given String
1
2
3
4
%dw 2.0
import dw::tests::Asserts
---
"A Text" must startWith("A")
1.2. Variables
1.2.1. MATCHED
Constant that represents a successful match
1.3. Types
1.3.1. Matcher
Data Type that represents a Matcher to perform assertions
1
2
3
4
5
6
7
8
9
10
%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 }
}
}
1
(value: T) -> MatcherResult
1.3.2. MatcherResult
Data Type that represents the result of an Assertion
1
2
3
4
{
"matches": false,
description : { expected : "Number type", actual: "A Text" }
}
1
{ matches: Boolean, description: { expected: String, actual: String }, reasons?: Array<String> }
2. dw::test::internal::Utils
2.1. Functions
2.1.1. toReadableText
toReadableText(Any): String
Generates a human readable toString of the value