Skip to content

Instantly share code, notes, and snippets.

@dnno
Created December 22, 2022 14:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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