WIP
authorKai Moritz <kai@juplo.de>
Sat, 21 May 2022 17:35:20 +0000 (19:35 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 21 May 2022 17:35:20 +0000 (19:35 +0200)
consumer/pacts/Siren Order Provider-Siren Order Service.json
spring-consumer/src/test/java/de/juplo/demos/pact/ContractTest.java
spring-consumer/target/pacts/SpringConsumer-Siren Order Provider.json

index 138ef78..6facad7 100644 (file)
@@ -3,55 +3,6 @@
     "name": "Siren Order Provider"
   },
   "interactions": [
-    {
-      "description": "get root",
-      "request": {
-        "method": "GET",
-        "path": "/"
-      },
-      "response": {
-        "body": {
-          "class": [
-            "representation"
-          ],
-          "links": [
-            {
-              "href": "http://localhost:8080/orders",
-              "rel": [
-                "orders"
-              ]
-            }
-          ]
-        },
-        "generators": {
-          "body": {
-            "$.links[0].href": {
-              "example": "http://localhost:8080/orders",
-              "regex": ".*(\\/orders)$",
-              "type": "MockServerURL"
-            }
-          }
-        },
-        "headers": {
-          "Content-Type": "application/vnd.siren+json"
-        },
-        "matchingRules": {
-          "body": {
-            "$.links[0].href": {
-              "combine": "AND",
-              "matchers": [
-                {
-                  "match": "regex",
-                  "regex": ".*(\\/orders)$"
-                }
-              ]
-            }
-          },
-          "header": {}
-        },
-        "status": 200
-      }
-    },
     {
       "description": "get all orders",
       "request": {
         },
         "status": 200
       }
-    },
-    {
-      "description": "delete order",
-      "request": {
-        "matchingRules": {
-          "path": {
-            "combine": "AND",
-            "matchers": [
-              {
-                "match": "regex",
-                "regex": "/orders/\\d+"
-              }
-            ]
-          }
-        },
-        "method": "DELETE",
-        "path": "/orders/1234"
-      },
-      "response": {
-        "status": 200
-      }
-    }
-  ],
-  "metadata": {
-    "pact-js": {
-      "version": "10.0.0-beta.59"
-    },
-    "pactRust": {
-      "ffi": "0.2.4",
-      "models": "0.3.1"
-    },
-    "pactSpecification": {
-      "version": "3.0.0"
     }
-  },
-  "provider": {
-    "name": "Siren Order Service"
-  }
-}
\ No newline at end of file
+}
index 95074a5..8193d8b 100644 (file)
@@ -32,23 +32,38 @@ public class ContractTest
             .headers(Map.of("Content-Type", "application/vnd.siren+json"))
             .body(LambdaDsl.newJsonBody(body ->
             {
+              body.array("class", classArray ->
+              {
+                classArray.stringValue("entity");
+              });
               body.array("entities", entities ->
               {
-                body.arrayContaining("actions", actions ->
+                body.arrayContaining("actions", actionsArray ->
                 {
-                  actions.object(object ->
+                  actionsArray.object(object ->
                   {
                     object.stringType("name","update");
                     object.stringType("method", "PUT");
                     object.matchUrl2("href", Matchers.regexp("\\d+", "1234").getValue());
                   });
-                  actions.object(object ->
+                  actionsArray.object(object ->
                   {
                     object.stringType("name","delete");
                     object.stringType("method", "DELETE");
                     object.matchUrl2("href", Matchers.regexp("\\d+", "1234").getValue());
                   });
                 });
+                body.array("links", linksArray ->
+                {
+                  linksArray.object(object->
+                  {
+                    object.matchUrl2("href", "orders");
+                    object.array("rel", relArray ->
+                    {
+                      relArray.stringValue("self");
+                    });
+                  });
+                });
               });
             }).build())
         .toPact();
index dbc0978..ae1e66d 100644 (file)
               "name": "delete"
             }
           ],
+          "class": [
+            "entity"
+          ],
           "entities": [
 
+          ],
+          "links": [
+            {
+              "href": "http://localhost:8080/orders",
+              "rel": [
+                "self"
+              ]
+            }
           ]
         },
         "generators": {
           "body": {
+            "$.links[0].href": {
+              "example": "http://localhost:8080/orders",
+              "regex": ".*\\/(\\Qorders\\E)$",
+              "type": "MockServerURL"
+            },
             "$[0].href": {
               "example": "http://localhost:8080/1234",
               "regex": ".*\\/(\\Q1234\\E)$",
                   ]
                 }
               ]
+            },
+            "$.links[0].href": {
+              "combine": "AND",
+              "matchers": [
+                {
+                  "match": "regex",
+                  "regex": ".*\\/(\\Qorders\\E)$"
+                }
+              ]
             }
           }
         },