feat: passing pact verification
authorRonald Holshausen <rholshausen@dius.com.au>
Tue, 29 Sep 2020 08:20:13 +0000 (18:20 +1000)
committerRonald Holshausen <rholshausen@dius.com.au>
Tue, 29 Sep 2020 08:20:13 +0000 (18:20 +1000)
provider/build.gradle
provider/src/main/java/io/pactflow/example/sirenprovider/controllers/OrderController.java
provider/src/main/java/io/pactflow/example/sirenprovider/controllers/RootController.java

index d9c520f..888cca5 100644 (file)
@@ -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")
+                       }
+               }
+       }
+}
index 6881069..0fb6f36 100644 (file)
@@ -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<RepresentationModel<?>> 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<Order> 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> order(@PathVariable(value = "id", required = true) Long id) {
+  @GetMapping(value = "/{id}")
+  public ResponseEntity<EntityModel<Order>> 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<Order> model = EntityModel.of(order, selfLink);
-    return model;
+    return ResponseEntity.ok(model);
   }
 
-  @PutMapping("/orders/{id}")
+  @PutMapping("/{id}")
   public EntityModel<Order> 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<Void> delete(@PathVariable(value = "id", required = true) Long id) {
     return ResponseEntity.ok().build();
   }
index ee649f4..71c81d8 100644 (file)
@@ -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<Root> {}
@@ -17,8 +19,8 @@ public class RootController {
   @Autowired
   private EntityLinks entityLinks;
 
-  @GetMapping("/")
-  public ResponseEntity<RepresentationModel<?>> orders() {
+  @RequestMapping("/")
+  public ResponseEntity<RepresentationModel<?>> root() {
     Link link = entityLinks.linkToCollectionResource(Order.class).withRel("orders");
     return ResponseEntity.ok().body(new Root().add(link));
   }