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
@@ -32,21 +32,21 @@ public class OrderRestEndpoint {
}
@PostMapping("/ship-order")
- public void shipOrder() {
+ public CompletableFuture<Void> shipOrder() {
String orderId = UUID.randomUUID().toString();
- commandGateway.send(new CreateOrderCommand(orderId));
- commandGateway.send(new AddProductCommand(orderId, "Deluxe Chair"));
- commandGateway.send(new ConfirmOrderCommand(orderId));
- commandGateway.send(new ShipOrderCommand(orderId));
+ return commandGateway.send(new CreateOrderCommand(orderId))
+ .thenCompose(result -> commandGateway.send(new AddProductCommand(orderId, "Deluxe Chair")))
+ .thenCompose(result -> commandGateway.send(new ConfirmOrderCommand(orderId)))
+ .thenCompose(result -> commandGateway.send(new ShipOrderCommand(orderId)));
}
@PostMapping("/ship-unconfirmed-order")
- public void shipUnconfirmedOrder() {
+ public CompletableFuture<Void> shipUnconfirmedOrder() {
String orderId = UUID.randomUUID().toString();
- commandGateway.send(new CreateOrderCommand(orderId));
- commandGateway.send(new AddProductCommand(orderId, "Deluxe Chair"));
+ return commandGateway.send(new CreateOrderCommand(orderId))
+ .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.
- commandGateway.send(new ShipOrderCommand(orderId));
+ .thenCompose(result -> commandGateway.send(new ShipOrderCommand(orderId)));
}
@PostMapping("/order")
