Created
December 22, 2022 14:00
-
-
Save dnno/ec4cd5f4d9e6cec2aa6ffe91eed18f23 to your computer and use it in GitHub Desktop.
Pact definition with matching dsl
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
@Pact(provider = "UserServiceJUnit5", consumer = "UserConsumer") | |
public V4Pact getAllUsers(PactBuilder builder) { | |
return builder | |
.usingLegacyDsl() | |
.given("A running user service") | |
.uponReceiving("A request for a user list") | |
.path("/users") | |
.method("GET") | |
.willRespondWith() | |
.status(200) | |
.headers(Map.of("Content-Type", "application/json")) | |
.body(new PactDslJsonArray() | |
.object() | |
.integerMatching("id", "[0-9]*", 1) | |
.stringMatcher("name", "[a-zA-Z ]*", "Jane Doe") | |
.closeObject() | |
.object() | |
.integerMatching("id", "[0-9]*", 2) | |
.stringMatcher("name", "[a-zA-Z ]*", "John Doe") | |
.closeObject() | |
) | |
.toPact() | |
.asV4Pact() | |
.get(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment