Skip to content

Instantly share code, notes, and snippets.

@rafaroca
Created July 19, 2019 07:42
Show Gist options
  • Save rafaroca/5aca21c79d4676b5ea28d005884976d1 to your computer and use it in GitHub Desktop.
Save rafaroca/5aca21c79d4676b5ea28d005884976d1 to your computer and use it in GitHub Desktop.
Consumer-driven asynchronous contract tests
@Pact(consumer = "fulfillment-service", provider = "order-service")
fun exportAnOrderTo(builder: MessagePactBuilder): MessagePact = builder.hasPactWith("order-service")
.given("An order with three items")
.expectsToReceive("an order to export")
.withContent(
newJsonBody { o ->
o.stringType("customerId", testCustomerId)
o.array("items") { a ->
a.newObject { item ->
item.stringType("name", "A Teddy Bear")
item.numberType("price", 1295)
}
a.newObject { item ->
item.stringType("name", "Googly Eyes")
item.numberType("price", 59)
}
a.newObject { item ->
item.stringType("name", "Goofy Socks")
item.numberType("price", 100)
}
}
}.build()
)
.toPact()
@rafaroca
Copy link
Author

message-pact-services

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment