From: Ronald Holshausen Date: Tue, 29 Sep 2020 08:20:13 +0000 (+1000) Subject: feat: passing pact verification X-Git-Tag: wip-umbau-array-contains~28 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=faa5a56666438860e7fc29f638f0c4f0812020a0;p=demos%2Fexample-siren feat: passing pact verification --- diff --git a/provider/build.gradle b/provider/build.gradle index d9c520f..888cca5 100644 --- a/provider/build.gradle +++ b/provider/build.gradle @@ -3,10 +3,12 @@ plugins { id 'io.spring.dependency-management' version '1.0.10.RELEASE' id 'java' id "io.freefair.lombok" version "5.2.1" + id "au.com.dius.pact" version "4.1.7" + id "com.wiredforcode.spawn" version "0.8.2" } group = 'io.pactflow.example' -version = '0.0.1-SNAPSHOT' +version = '0.0.1' sourceCompatibility = '11' repositories { @@ -26,3 +28,24 @@ dependencies { test { useJUnitPlatform() } + +task startServer(type: SpawnProcessTask, dependsOn: 'assemble') { + command "java -jar ${projectDir}/build/libs/siren-provider-0.0.1.jar" + ready 'Started SirenProviderApplication' +} + +task stopServer(type: KillProcessTask) + +pact { + serviceProviders { + "Siren Order Provider" { + + startProviderTask = startServer + terminateProviderTask = stopServer + + hasPactWith("Siren Consumer") { + pactSource = file("${projectDir}/../consumer/pacts/Siren Order Provider-Siren Order Service.json") + } + } + } +} diff --git a/provider/src/main/java/io/pactflow/example/sirenprovider/controllers/OrderController.java b/provider/src/main/java/io/pactflow/example/sirenprovider/controllers/OrderController.java index 6881069..0fb6f36 100644 --- a/provider/src/main/java/io/pactflow/example/sirenprovider/controllers/OrderController.java +++ b/provider/src/main/java/io/pactflow/example/sirenprovider/controllers/OrderController.java @@ -20,11 +20,11 @@ import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; @RestController @ExposesResourceFor(Order.class) -@RequestMapping("/orders") +@RequestMapping(value = "/orders") public class OrderController { - @GetMapping("/orders") - public RepresentationModel orders() { + @GetMapping + public ResponseEntity> orders() { Order order = new Order(1234L); Link selfLink = linkTo(methodOn(OrderController.class).order(order.getId())).withSelfRel() .andAffordance(afford(methodOn(OrderController.class).update(order.getId(), null))) @@ -32,20 +32,20 @@ public class OrderController { EntityModel model = EntityModel.of(order, selfLink); RepresentationModel orders = CollectionModel.of(model); orders.add(linkTo(methodOn(OrderController.class).orders()).withSelfRel()); - return orders; + return ResponseEntity.ok(orders); } - @GetMapping("/orders/{id}") - public EntityModel order(@PathVariable(value = "id", required = true) Long id) { + @GetMapping(value = "/{id}") + public ResponseEntity> order(@PathVariable(value = "id", required = true) Long id) { Order order = new Order(id); Link selfLink = linkTo(methodOn(OrderController.class).order(order.getId())).withSelfRel() .andAffordance(afford(methodOn(OrderController.class).update(order.getId(), null))) .andAffordance(afford(methodOn(OrderController.class).delete(order.getId()))); EntityModel model = EntityModel.of(order, selfLink); - return model; + return ResponseEntity.ok(model); } - @PutMapping("/orders/{id}") + @PutMapping("/{id}") public EntityModel update(@PathVariable(value = "id", required = true) Long id, Order order) { Link selfLink = linkTo(methodOn(OrderController.class).order(order.getId())).withSelfRel() .andAffordance(afford(methodOn(OrderController.class).update(order.getId(), null))) @@ -54,7 +54,7 @@ public class OrderController { return model; } - @DeleteMapping("/orders/{id}") + @DeleteMapping("/{id}") public ResponseEntity delete(@PathVariable(value = "id", required = true) Long id) { return ResponseEntity.ok().build(); } diff --git a/provider/src/main/java/io/pactflow/example/sirenprovider/controllers/RootController.java b/provider/src/main/java/io/pactflow/example/sirenprovider/controllers/RootController.java index ee649f4..71c81d8 100644 --- a/provider/src/main/java/io/pactflow/example/sirenprovider/controllers/RootController.java +++ b/provider/src/main/java/io/pactflow/example/sirenprovider/controllers/RootController.java @@ -6,10 +6,12 @@ import org.springframework.hateoas.Link; import org.springframework.hateoas.RepresentationModel; import org.springframework.hateoas.server.EntityLinks; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; @RestController +@RequestMapping(value = "/", method = RequestMethod.GET) public class RootController { static class Root extends RepresentationModel {} @@ -17,8 +19,8 @@ public class RootController { @Autowired private EntityLinks entityLinks; - @GetMapping("/") - public ResponseEntity> orders() { + @RequestMapping("/") + public ResponseEntity> root() { Link link = entityLinks.linkToCollectionResource(Order.class).withRel("orders"); return ResponseEntity.ok().body(new Root().add(link)); }