Update previous complete test endpoints

The test endpoints used to create an order, add a product, confirm the
order and ship it are not embracing the asynchronous approach of the
CommandGateway. Make sure that all commands are composed with one
another and return the completable future for Spring to resolve

#BAEL-4767
This commit is contained in:
Steven van Beelen 2021-03-19 11:54:20 +01:00
parent 2b351eda7a
commit af4e82b089
1 changed files with 10 additions and 10 deletions

View File

@ -32,21 +32,21 @@ public class OrderRestEndpoint {
} }
@PostMapping("/ship-order") @PostMapping("/ship-order")
public void shipOrder() { public CompletableFuture<Void> shipOrder() {
String orderId = UUID.randomUUID().toString(); String orderId = UUID.randomUUID().toString();
commandGateway.send(new CreateOrderCommand(orderId)); return commandGateway.send(new CreateOrderCommand(orderId))
commandGateway.send(new AddProductCommand(orderId, "Deluxe Chair")); .thenCompose(result -> commandGateway.send(new AddProductCommand(orderId, "Deluxe Chair")))
commandGateway.send(new ConfirmOrderCommand(orderId)); .thenCompose(result -> commandGateway.send(new ConfirmOrderCommand(orderId)))
commandGateway.send(new ShipOrderCommand(orderId)); .thenCompose(result -> commandGateway.send(new ShipOrderCommand(orderId)));
} }
@PostMapping("/ship-unconfirmed-order") @PostMapping("/ship-unconfirmed-order")
public void shipUnconfirmedOrder() { public CompletableFuture<Void> shipUnconfirmedOrder() {
String orderId = UUID.randomUUID().toString(); String orderId = UUID.randomUUID().toString();
commandGateway.send(new CreateOrderCommand(orderId)); return commandGateway.send(new CreateOrderCommand(orderId))
commandGateway.send(new AddProductCommand(orderId, "Deluxe Chair")); .thenCompose(result -> commandGateway.send(new AddProductCommand(orderId, "Deluxe Chair")))
// This throws an exception, as an Order cannot be shipped if it has not been confirmed yet. // This throws an exception, as an Order cannot be shipped if it has not been confirmed yet.
commandGateway.send(new ShipOrderCommand(orderId)); .thenCompose(result -> commandGateway.send(new ShipOrderCommand(orderId)));
} }
@PostMapping("/order") @PostMapping("/order")