From: Kai Moritz Date: Sat, 21 May 2022 18:54:42 +0000 (+0200) Subject: Re-staged the contract for `get root` X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=9e571f48beb035de3fd36a1f21a7958aace4d121;p=demos%2Fexample-siren Re-staged the contract for `get root` --- 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 16c6815..6262b15 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 @@ -20,6 +20,55 @@ import static org.assertj.core.api.Assertions.fail; @PactTestFor(providerName = "SirenOrderProvider") public class ContractTest { + @Pact(consumer="SpringConsumer") + public RequestResponsePact getRoot(PactDslWithProvider builder) + { + return builder + .uponReceiving("get root") + .path("/") + .method("GET") + .willRespondWith() + .status(200) + .headers(Map.of("Content-Type", "application/vnd.siren+json")) + .body(LambdaDsl.newJsonBody(body -> + { + body.array("class", classArray -> + { + classArray.stringValue("representation"); + }); + body.array("links", linksArray -> + { + linksArray.object(object-> + { + object.matchUrl2("href", "orders"); + object.array("rel", relArray -> + { + relArray.stringValue("orders"); + }); + }); + }); + }).build()) + .toPact(); + } + + @Test + @PactTestFor(pactMethod = "getRoot") + public void testGetRoot(MockServer mockServer) + { + RestTemplate restTemplate = + new RestTemplateBuilder() + .rootUri(mockServer.getUrl()) + .build(); + try + { + restTemplate.getForEntity("/", String.class); + } + catch (Exception e) + { + fail("Unexpected exception", e); + } + } + @Pact(consumer="SpringConsumer") public RequestResponsePact getAllOrders(PactDslWithProvider builder) { diff --git a/spring-consumer/target/pacts/SpringConsumer-SirenOrderProvider.json b/spring-consumer/target/pacts/SpringConsumer-SirenOrderProvider.json index 1d1fbd3..d4dbfff 100644 --- a/spring-consumer/target/pacts/SpringConsumer-SirenOrderProvider.json +++ b/spring-consumer/target/pacts/SpringConsumer-SirenOrderProvider.json @@ -207,6 +207,54 @@ }, "status": 200 } + }, + { + "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": ".*\\/(\\Qorders\\E)$", + "type": "MockServerURL" + } + } + }, + "headers": { + "Content-Type": "application/vnd.siren+json" + }, + "matchingRules": { + "body": { + "$.links[0].href": { + "combine": "AND", + "matchers": [ + { + "match": "regex", + "regex": ".*\\/(\\Qorders\\E)$" + } + ] + } + } + }, + "status": 200 + } } ], "metadata": {