Skip to content

Instantly share code, notes, and snippets.

@dnno
Created December 22, 2022 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnno/ec4cd5f4d9e6cec2aa6ffe91eed18f23 to your computer and use it in GitHub Desktop.
Save dnno/ec4cd5f4d9e6cec2aa6ffe91eed18f23 to your computer and use it in GitHub Desktop.
Pact definition with matching dsl
@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