From 969dd5ded4aa8c4938f533c84118e1cad606667a Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sat, 21 May 2022 21:11:49 +0200 Subject: [PATCH] Re-staged the contract for `delete order` --- .../de/juplo/demos/pact/ContractTest.java | 30 +++++++++++++++++++ .../SpringConsumer-SirenOrderProvider.json | 21 +++++++++++++ 2 files changed, 51 insertions(+) diff --git a/spring-consumer/src/test/java/de/juplo/demos/pact/ContractTest.java b/spring-consumer/src/test/java/de/juplo/demos/pact/ContractTest.java index 6262b15..b863b23 100644 --- a/spring-consumer/src/test/java/de/juplo/demos/pact/ContractTest.java +++ b/spring-consumer/src/test/java/de/juplo/demos/pact/ContractTest.java @@ -158,4 +158,34 @@ public class ContractTest fail("Unexpected exception", e); } } + + @Pact(consumer="SpringConsumer") + public RequestResponsePact deleteOrder(PactDslWithProvider builder) + { + return builder + .uponReceiving("delete order") + .matchPath("/orders/\\d+", "/orders/1234") + .method("DELETE") + .willRespondWith() + .status(200) + .toPact(); + } + + @Test + @PactTestFor(pactMethod = "deleteOrder") + public void testDeleteOrder(MockServer mockServer) + { + RestTemplate restTemplate = + new RestTemplateBuilder() + .rootUri(mockServer.getUrl()) + .build(); + try + { + restTemplate.delete("/orders/1234"); + } + catch (Exception e) + { + fail("Unexpected exception", e); + } + } } diff --git a/spring-consumer/target/pacts/SpringConsumer-SirenOrderProvider.json b/spring-consumer/target/pacts/SpringConsumer-SirenOrderProvider.json index d4dbfff..d666dde 100644 --- a/spring-consumer/target/pacts/SpringConsumer-SirenOrderProvider.json +++ b/spring-consumer/target/pacts/SpringConsumer-SirenOrderProvider.json @@ -3,6 +3,27 @@ "name": "SpringConsumer" }, "interactions": [ + { + "description": "delete order", + "request": { + "matchingRules": { + "path": { + "combine": "AND", + "matchers": [ + { + "match": "regex", + "regex": "/orders/\\d+" + } + ] + } + }, + "method": "DELETE", + "path": "/orders/1234" + }, + "response": { + "status": 200 + } + }, { "description": "get all orders", "request": { -- 2.20.1