Re-staged the contract for `delete order`
authorKai Moritz <kai@juplo.de>
Sat, 21 May 2022 19:11:49 +0000 (21:11 +0200)
committerKai Moritz <kai@juplo.de>
Fri, 3 Jun 2022 11:45:28 +0000 (13:45 +0200)
spring-consumer/src/test/java/de/juplo/demos/pact/ContractTest.java
spring-consumer/target/pacts/SpringConsumer-SirenOrderProvider.json

index 6262b15..b863b23 100644 (file)
@@ -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);
+    }
+  }
 }
index d4dbfff..d666dde 100644 (file)
@@ -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": {