Skip to content

Commit a5ad7b1

Browse files
committed
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
1 parent 213f6f0 commit a5ad7b1

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

axon/src/main/java/com/baeldung/axon/gui/OrderRestEndpoint.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,21 @@ public OrderRestEndpoint(CommandGateway commandGateway, QueryGateway queryGatewa
3232
}
3333

3434
@PostMapping("/ship-order")
35-
public void shipOrder() {
35+
public CompletableFuture<Void> shipOrder() {
3636
String orderId = UUID.randomUUID().toString();
37-
commandGateway.send(new CreateOrderCommand(orderId));
38-
commandGateway.send(new AddProductCommand(orderId, "Deluxe Chair"));
39-
commandGateway.send(new ConfirmOrderCommand(orderId));
40-
commandGateway.send(new ShipOrderCommand(orderId));
37+
return commandGateway.send(new CreateOrderCommand(orderId))
38+
.thenCompose(result -> commandGateway.send(new AddProductCommand(orderId, "Deluxe Chair")))
39+
.thenCompose(result -> commandGateway.send(new ConfirmOrderCommand(orderId)))
40+
.thenCompose(result -> commandGateway.send(new ShipOrderCommand(orderId)));
4141
}
4242

4343
@PostMapping("/ship-unconfirmed-order")
44-
public void shipUnconfirmedOrder() {
44+
public CompletableFuture<Void> shipUnconfirmedOrder() {
4545
String orderId = UUID.randomUUID().toString();
46-
commandGateway.send(new CreateOrderCommand(orderId));
47-
commandGateway.send(new AddProductCommand(orderId, "Deluxe Chair"));
48-
// This throws an exception, as an Order cannot be shipped if it has not been confirmed yet.
49-
commandGateway.send(new ShipOrderCommand(orderId));
46+
return commandGateway.send(new CreateOrderCommand(orderId))
47+
.thenCompose(result -> commandGateway.send(new AddProductCommand(orderId, "Deluxe Chair")))
48+
// This throws an exception, as an Order cannot be shipped if it has not been confirmed yet.
49+
.thenCompose(result -> commandGateway.send(new ShipOrderCommand(orderId)));
5050
}
5151

5252
@PostMapping("/order")

0 commit comments

Comments
 (0)