From: Kai Moritz Date: Sat, 21 May 2022 17:35:20 +0000 (+0200) Subject: WIP X-Git-Tag: wip-umbau-array-contains~2 X-Git-Url: https://juplo.de/gitweb/?a=commitdiff_plain;h=d9dcdbe4ecf53103212af0045ea8599f90a4e45e;p=demos%2Fexample-siren WIP --- diff --git a/consumer/pacts/Siren Order Provider-Siren Order Service.json b/consumer/pacts/Siren Order Provider-Siren Order Service.json index 138ef78..6facad7 100644 --- a/consumer/pacts/Siren Order Provider-Siren Order Service.json +++ b/consumer/pacts/Siren Order Provider-Siren Order Service.json @@ -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": { @@ -215,42 +166,5 @@ }, "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 +} 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 95074a5..8193d8b 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 @@ -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(); diff --git a/spring-consumer/target/pacts/SpringConsumer-Siren Order Provider.json b/spring-consumer/target/pacts/SpringConsumer-Siren Order Provider.json index dbc0978..ae1e66d 100644 --- a/spring-consumer/target/pacts/SpringConsumer-Siren Order Provider.json +++ b/spring-consumer/target/pacts/SpringConsumer-Siren Order Provider.json @@ -23,12 +23,28 @@ "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)$", @@ -129,6 +145,15 @@ ] } ] + }, + "$.links[0].href": { + "combine": "AND", + "matchers": [ + { + "match": "regex", + "regex": ".*\\/(\\Qorders\\E)$" + } + ] } } },