-
-
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.
Implemented wildcards for map keys in the Groovy DSL #313
- Loading branch information
Ronald Holshausen
committed
Sep 10, 2016
1 parent
1fa05bd
commit b483572
Showing
3 changed files
with
133 additions
and
14 deletions.
There are no files selected for viewing
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
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
77 changes: 77 additions & 0 deletions
77
...-consumer-groovy/src/test/groovy/au/com/dius/pact/consumer/groovy/WildcardPactSpec.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,77 @@ | ||
package au.com.dius.pact.consumer.groovy | ||
|
||
@SuppressWarnings('UnusedImport') | ||
import au.com.dius.pact.consumer.PactVerified$ | ||
import au.com.dius.pact.consumer.VerificationResult | ||
import au.com.dius.pact.model.PactSpecVersion | ||
import groovyx.net.http.RESTClient | ||
import spock.lang.Specification | ||
|
||
import static groovyx.net.http.ContentType.JSON | ||
|
||
@SuppressWarnings(['AbcMetric']) | ||
class WildcardPactSpec extends Specification { | ||
|
||
@SuppressWarnings(['NestedBlockDepth']) | ||
def 'pact test requiring wildcards'() { | ||
given: | ||
def articleService = new PactBuilder() | ||
articleService { | ||
serviceConsumer 'ArticleConsumer' | ||
hasPactWith 'ArticleService' | ||
port 1234 | ||
} | ||
|
||
articleService { | ||
uponReceiving('a request for an article') | ||
withAttributes(method: 'get', path: '/') | ||
willRespondWith(status: 200) | ||
withBody(mimeType: JSON.toString()) { | ||
articles eachLike { | ||
variants eachLike { | ||
keyLike '001', eachLike { | ||
bundles eachLike { | ||
keyLike('001-A') { | ||
description string('some description') | ||
referencedArticles eachLike { | ||
bundleId identifier() | ||
keyLike '001-A-1', identifier() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
when: | ||
VerificationResult result = articleService.run(specificationVersion: PactSpecVersion.V3) { | ||
def client = new RESTClient('http://localhost:1234/') | ||
def response = client.get(requestContentType: JSON) | ||
|
||
assert response.status == 200 | ||
assert response.data.articles.size() == 1 | ||
assert response.data.articles[0].variants.size() == 1 | ||
assert response.data.articles[0].variants[0].keySet() == ['001'] as Set | ||
assert response.data.articles[0].variants[0].'001'.size() == 1 | ||
assert response.data.articles[0].variants[0].'001'[0].bundles.size() == 1 | ||
assert response.data.articles[0].variants[0].'001'[0].bundles[0].keySet() == ['001-A'] as Set | ||
} | ||
|
||
then: | ||
result == PactVerified$.MODULE$ | ||
articleService.interactions.size() == 1 | ||
articleService.interactions[0].response.matchingRules == [ | ||
'$.body.articles': [match: 'type'], | ||
'$.body.articles[*].variants': [match: 'type'], | ||
'$.body.articles[*].variants[*].*': [match: 'type'], | ||
'$.body.articles[*].variants[*].*[*].bundles': [match: 'type'], | ||
'$.body.articles[*].variants[*].*[*].bundles[*].*.description': [match: 'type'], | ||
'$.body.articles[*].variants[*].*[*].bundles[*].*.referencedArticles': [match: 'type'], | ||
'$.body.articles[*].variants[*].*[*].bundles[*].*.referencedArticles[*].bundleId': [match: 'type'], | ||
'$.body.articles[*].variants[*].*[*].bundles[*].*.referencedArticles[*].*': [match: 'type'] | ||
] | ||
|
||
} | ||
} |