-
-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add tests for array contains with simple values in Groovy DSL #1318
- Loading branch information
Ronald Holshausen
committed
Mar 6, 2021
1 parent
2c90ff1
commit 48acb7a
Showing
1 changed file
with
87 additions
and
0 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
consumer/groovy/src/test/groovy/au/com/dius/pact/consumer/groovy/ArrayContainsSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package au.com.dius.pact.consumer.groovy | ||
|
||
import au.com.dius.pact.core.model.generators.DateGenerator | ||
import au.com.dius.pact.core.model.generators.UuidGenerator | ||
import au.com.dius.pact.core.model.matchingrules.MatchingRuleCategory | ||
import au.com.dius.pact.core.model.matchingrules.MatchingRuleGroup | ||
import au.com.dius.pact.core.model.matchingrules.NumberTypeMatcher | ||
import au.com.dius.pact.core.model.matchingrules.RegexMatcher | ||
import kotlin.Triple | ||
import spock.lang.Issue | ||
import spock.lang.Specification | ||
|
||
class ArrayContainsSpec extends Specification{ | ||
@Issue('#1318') | ||
def 'array contains with simple values'() { | ||
given: | ||
def builder = new PactBodyBuilder(mimetype: 'application/json') | ||
|
||
when: | ||
builder { | ||
array arrayContaining([ | ||
string('a'), | ||
numeric(100) | ||
]) | ||
} | ||
def rules = builder.matchers.matchingRules | ||
|
||
then: | ||
builder.body == '''{ | ||
| "array": [ | ||
| "a", | ||
| 100 | ||
| ] | ||
|}'''.stripMargin() | ||
rules.keySet() == ['$.array'] as Set | ||
rules['$.array'].rules.size() == 1 | ||
rules['$.array'].rules[0] instanceof au.com.dius.pact.core.model.matchingrules.ArrayContainsMatcher | ||
rules['$.array'].rules[0].variants == [ | ||
new Triple(0, new MatchingRuleCategory('body', ['$': new MatchingRuleGroup([au.com.dius.pact.core.model.matchingrules.TypeMatcher.INSTANCE])]), [:]), | ||
new Triple(1, new MatchingRuleCategory('body', ['$': new MatchingRuleGroup([new NumberTypeMatcher(NumberTypeMatcher.NumberType.NUMBER)])]), [:]) | ||
] | ||
} | ||
|
||
@Issue('#1318') | ||
def 'array contains with simple values and generators'() { | ||
given: | ||
def builder = new PactBodyBuilder(mimetype: 'application/json') | ||
|
||
when: | ||
builder { | ||
array arrayContaining([ | ||
date('yyyy-MM-dd'), | ||
equalTo("Test"), | ||
uuid() | ||
]) | ||
} | ||
def rules = builder.matchers.matchingRules | ||
|
||
then: | ||
builder.body == '''{ | ||
| "array": [ | ||
| "2000-02-01", | ||
| "Test", | ||
| "e2490de5-5bd3-43d5-b7c4-526e33f71304" | ||
| ] | ||
|}'''.stripMargin() | ||
rules.keySet() == ['$.array'] as Set | ||
rules['$.array'].rules.size() == 1 | ||
rules['$.array'].rules[0] instanceof au.com.dius.pact.core.model.matchingrules.ArrayContainsMatcher | ||
rules['$.array'].rules[0].variants.size() == 3 | ||
rules['$.array'].rules[0].variants[0] == new Triple( | ||
0, | ||
new MatchingRuleCategory('body', ['$': new MatchingRuleGroup([new au.com.dius.pact.core.model.matchingrules.DateMatcher('yyyy-MM-dd')])]), | ||
['$': new DateGenerator('yyyy-MM-dd')] | ||
) | ||
rules['$.array'].rules[0].variants[1] == new Triple( | ||
1, | ||
new MatchingRuleCategory('body', ['$': new MatchingRuleGroup([au.com.dius.pact.core.model.matchingrules.EqualsMatcher.INSTANCE])]), | ||
[:] | ||
) | ||
rules['$.array'].rules[0].variants[2] == new Triple( | ||
2, | ||
new MatchingRuleCategory('body', ['$': new MatchingRuleGroup([new RegexMatcher('[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}')])]), | ||
['$': UuidGenerator.INSTANCE] | ||
) | ||
} | ||
} |