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 {
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")
+ }
+ }
+ }
+}
@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)))
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)))
return model;
}
- @DeleteMapping("/orders/{id}")
+ @DeleteMapping("/{id}")
public ResponseEntity<Void> delete(@PathVariable(value = "id", required = true) Long id) {
return ResponseEntity.ok().build();
}
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> {}
@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));
}