diff --git a/axon/src/main/java/com/baeldung/axon/commandmodel/order/OrderAggregate.java b/axon/src/main/java/com/baeldung/axon/commandmodel/order/OrderAggregate.java index 883d51241d..97342bdb3a 100644 --- a/axon/src/main/java/com/baeldung/axon/commandmodel/order/OrderAggregate.java +++ b/axon/src/main/java/com/baeldung/axon/commandmodel/order/OrderAggregate.java @@ -2,10 +2,10 @@ package com.baeldung.axon.commandmodel.order; import com.baeldung.axon.coreapi.commands.AddProductCommand; import com.baeldung.axon.coreapi.commands.ConfirmOrderCommand; -import com.baeldung.axon.coreapi.commands.PlaceOrderCommand; +import com.baeldung.axon.coreapi.commands.CreateOrderCommand; import com.baeldung.axon.coreapi.commands.ShipOrderCommand; import com.baeldung.axon.coreapi.events.OrderConfirmedEvent; -import com.baeldung.axon.coreapi.events.OrderPlacedEvent; +import com.baeldung.axon.coreapi.events.OrderCreatedEvent; import com.baeldung.axon.coreapi.events.OrderShippedEvent; import com.baeldung.axon.coreapi.events.ProductAddedEvent; import com.baeldung.axon.coreapi.events.ProductRemovedEvent; @@ -34,8 +34,8 @@ public class OrderAggregate { private Map orderLines; @CommandHandler - public OrderAggregate(PlaceOrderCommand command) { - apply(new OrderPlacedEvent(command.getOrderId())); + public OrderAggregate(CreateOrderCommand command) { + apply(new OrderCreatedEvent(command.getOrderId())); } @CommandHandler @@ -70,7 +70,7 @@ public class OrderAggregate { } @EventSourcingHandler - public void on(OrderPlacedEvent event) { + public void on(OrderCreatedEvent event) { this.orderId = event.getOrderId(); this.orderConfirmed = false; this.orderLines = new HashMap<>(); diff --git a/axon/src/main/java/com/baeldung/axon/coreapi/commands/PlaceOrderCommand.java b/axon/src/main/java/com/baeldung/axon/coreapi/commands/CreateOrderCommand.java similarity index 81% rename from axon/src/main/java/com/baeldung/axon/coreapi/commands/PlaceOrderCommand.java rename to axon/src/main/java/com/baeldung/axon/coreapi/commands/CreateOrderCommand.java index b631272366..ceb7fd6a08 100644 --- a/axon/src/main/java/com/baeldung/axon/coreapi/commands/PlaceOrderCommand.java +++ b/axon/src/main/java/com/baeldung/axon/coreapi/commands/CreateOrderCommand.java @@ -4,12 +4,12 @@ import org.axonframework.modelling.command.TargetAggregateIdentifier; import java.util.Objects; -public class PlaceOrderCommand { +public class CreateOrderCommand { @TargetAggregateIdentifier private final String orderId; - public PlaceOrderCommand(String orderId) { + public CreateOrderCommand(String orderId) { this.orderId = orderId; } @@ -25,7 +25,7 @@ public class PlaceOrderCommand { if (o == null || getClass() != o.getClass()) { return false; } - PlaceOrderCommand that = (PlaceOrderCommand) o; + CreateOrderCommand that = (CreateOrderCommand) o; return Objects.equals(orderId, that.orderId); } @@ -36,7 +36,7 @@ public class PlaceOrderCommand { @Override public String toString() { - return "PlaceOrderCommand{" + + return "CreateOrderCommand{" + "orderId='" + orderId + '\'' + '}'; } diff --git a/axon/src/main/java/com/baeldung/axon/coreapi/events/OrderPlacedEvent.java b/axon/src/main/java/com/baeldung/axon/coreapi/events/OrderCreatedEvent.java similarity index 79% rename from axon/src/main/java/com/baeldung/axon/coreapi/events/OrderPlacedEvent.java rename to axon/src/main/java/com/baeldung/axon/coreapi/events/OrderCreatedEvent.java index 3b9994fc33..5d2d8b7f55 100644 --- a/axon/src/main/java/com/baeldung/axon/coreapi/events/OrderPlacedEvent.java +++ b/axon/src/main/java/com/baeldung/axon/coreapi/events/OrderCreatedEvent.java @@ -2,11 +2,11 @@ package com.baeldung.axon.coreapi.events; import java.util.Objects; -public class OrderPlacedEvent { +public class OrderCreatedEvent { private final String orderId; - public OrderPlacedEvent(String orderId) { + public OrderCreatedEvent(String orderId) { this.orderId = orderId; } @@ -22,7 +22,7 @@ public class OrderPlacedEvent { if (o == null || getClass() != o.getClass()) { return false; } - OrderPlacedEvent that = (OrderPlacedEvent) o; + OrderCreatedEvent that = (OrderCreatedEvent) o; return Objects.equals(orderId, that.orderId); } @@ -33,7 +33,7 @@ public class OrderPlacedEvent { @Override public String toString() { - return "OrderPlacedEvent{" + + return "OrderCreatedEvent{" + "orderId='" + orderId + '\'' + '}'; } diff --git a/axon/src/main/java/com/baeldung/axon/coreapi/queries/OrderedProduct.java b/axon/src/main/java/com/baeldung/axon/coreapi/queries/Order.java similarity index 85% rename from axon/src/main/java/com/baeldung/axon/coreapi/queries/OrderedProduct.java rename to axon/src/main/java/com/baeldung/axon/coreapi/queries/Order.java index 69e705c2f6..1810a053d3 100644 --- a/axon/src/main/java/com/baeldung/axon/coreapi/queries/OrderedProduct.java +++ b/axon/src/main/java/com/baeldung/axon/coreapi/queries/Order.java @@ -4,16 +4,16 @@ import java.util.HashMap; import java.util.Map; import java.util.Objects; -public class OrderedProduct { +public class Order { private final String orderId; private final Map products; private OrderStatus orderStatus; - public OrderedProduct(String orderId) { + public Order(String orderId) { this.orderId = orderId; this.products = new HashMap<>(); - orderStatus = OrderStatus.PLACED; + orderStatus = OrderStatus.CREATED; } public String getOrderId() { @@ -61,8 +61,9 @@ public class OrderedProduct { if (o == null || getClass() != o.getClass()) { return false; } - OrderedProduct that = (OrderedProduct) o; - return Objects.equals(orderId, that.orderId) && Objects.equals(products, that.products) + Order that = (Order) o; + return Objects.equals(orderId, that.orderId) + && Objects.equals(products, that.products) && orderStatus == that.orderStatus; } @@ -73,7 +74,7 @@ public class OrderedProduct { @Override public String toString() { - return "OrderedProduct{" + + return "Order{" + "orderId='" + orderId + '\'' + ", products=" + products + ", orderStatus=" + orderStatus + diff --git a/axon/src/main/java/com/baeldung/axon/coreapi/queries/OrderStatus.java b/axon/src/main/java/com/baeldung/axon/coreapi/queries/OrderStatus.java index d215c5fc32..fc5da5d77e 100644 --- a/axon/src/main/java/com/baeldung/axon/coreapi/queries/OrderStatus.java +++ b/axon/src/main/java/com/baeldung/axon/coreapi/queries/OrderStatus.java @@ -2,6 +2,5 @@ package com.baeldung.axon.coreapi.queries; public enum OrderStatus { - PLACED, CONFIRMED, SHIPPED - + CREATED, CONFIRMED, SHIPPED } diff --git a/axon/src/main/java/com/baeldung/axon/gui/OrderRestEndpoint.java b/axon/src/main/java/com/baeldung/axon/gui/OrderRestEndpoint.java index f9e1748cbe..5c385c487f 100644 --- a/axon/src/main/java/com/baeldung/axon/gui/OrderRestEndpoint.java +++ b/axon/src/main/java/com/baeldung/axon/gui/OrderRestEndpoint.java @@ -2,12 +2,12 @@ package com.baeldung.axon.gui; import com.baeldung.axon.coreapi.commands.AddProductCommand; import com.baeldung.axon.coreapi.commands.ConfirmOrderCommand; +import com.baeldung.axon.coreapi.commands.CreateOrderCommand; import com.baeldung.axon.coreapi.commands.DecrementProductCountCommand; import com.baeldung.axon.coreapi.commands.IncrementProductCountCommand; -import com.baeldung.axon.coreapi.commands.PlaceOrderCommand; import com.baeldung.axon.coreapi.commands.ShipOrderCommand; import com.baeldung.axon.coreapi.queries.FindAllOrderedProductsQuery; -import com.baeldung.axon.coreapi.queries.OrderedProduct; +import com.baeldung.axon.coreapi.queries.Order; import org.axonframework.commandhandling.gateway.CommandGateway; import org.axonframework.messaging.responsetypes.ResponseTypes; import org.axonframework.queryhandling.QueryGateway; @@ -34,7 +34,7 @@ public class OrderRestEndpoint { @PostMapping("/ship-order") public void shipOrder() { String orderId = UUID.randomUUID().toString(); - commandGateway.send(new PlaceOrderCommand(orderId)); + commandGateway.send(new CreateOrderCommand(orderId)); commandGateway.send(new AddProductCommand(orderId, "Deluxe Chair")); commandGateway.send(new ConfirmOrderCommand(orderId)); commandGateway.send(new ShipOrderCommand(orderId)); @@ -43,20 +43,20 @@ public class OrderRestEndpoint { @PostMapping("/ship-unconfirmed-order") public void shipUnconfirmedOrder() { String orderId = UUID.randomUUID().toString(); - commandGateway.send(new PlaceOrderCommand(orderId)); + commandGateway.send(new CreateOrderCommand(orderId)); 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)); } @PostMapping("/order") - public CompletableFuture placeOrder() { - return placeOrder(UUID.randomUUID().toString()); + public CompletableFuture createOrder() { + return createOrder(UUID.randomUUID().toString()); } @PostMapping("/order/{order-id}") - public CompletableFuture placeOrder(@PathVariable("order-id") String orderId) { - return commandGateway.send(new PlaceOrderCommand(orderId)); + public CompletableFuture createOrder(@PathVariable("order-id") String orderId) { + return commandGateway.send(new CreateOrderCommand(orderId)); } @PostMapping("/order/{order-id}/product/{product-id}") @@ -88,9 +88,7 @@ public class OrderRestEndpoint { } @GetMapping("/all-orders") - public CompletableFuture> findAllOrderedProducts() { - return queryGateway.query( - new FindAllOrderedProductsQuery(), ResponseTypes.multipleInstancesOf(OrderedProduct.class) - ); + public CompletableFuture> findAllOrders() { + return queryGateway.query(new FindAllOrderedProductsQuery(), ResponseTypes.multipleInstancesOf(Order.class)); } } diff --git a/axon/src/main/java/com/baeldung/axon/querymodel/OrderedProductsEventHandler.java b/axon/src/main/java/com/baeldung/axon/querymodel/OrderedProductsEventHandler.java deleted file mode 100644 index 3efd81fd37..0000000000 --- a/axon/src/main/java/com/baeldung/axon/querymodel/OrderedProductsEventHandler.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.baeldung.axon.querymodel; - -import com.baeldung.axon.coreapi.events.OrderConfirmedEvent; -import com.baeldung.axon.coreapi.events.OrderPlacedEvent; -import com.baeldung.axon.coreapi.events.OrderShippedEvent; -import com.baeldung.axon.coreapi.events.ProductAddedEvent; -import com.baeldung.axon.coreapi.events.ProductCountDecrementedEvent; -import com.baeldung.axon.coreapi.events.ProductCountIncrementedEvent; -import com.baeldung.axon.coreapi.events.ProductRemovedEvent; -import com.baeldung.axon.coreapi.queries.FindAllOrderedProductsQuery; -import com.baeldung.axon.coreapi.queries.OrderedProduct; -import org.axonframework.config.ProcessingGroup; -import org.axonframework.eventhandling.EventHandler; -import org.axonframework.queryhandling.QueryHandler; -import org.springframework.stereotype.Service; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@Service -@ProcessingGroup("ordered-products") -public class OrderedProductsEventHandler { - - private final Map orderedProducts = new HashMap<>(); - - @EventHandler - public void on(OrderPlacedEvent event) { - String orderId = event.getOrderId(); - orderedProducts.put(orderId, new OrderedProduct(orderId)); - } - - @EventHandler - public void on(ProductAddedEvent event) { - orderedProducts.computeIfPresent(event.getOrderId(), (orderId, orderedProduct) -> { - orderedProduct.addProduct(event.getProductId()); - return orderedProduct; - }); - } - - @EventHandler - public void on(ProductCountIncrementedEvent event) { - orderedProducts.computeIfPresent(event.getOrderId(), (orderId, orderedProduct) -> { - orderedProduct.incrementProductInstance(event.getProductId()); - return orderedProduct; - }); - } - - @EventHandler - public void on(ProductCountDecrementedEvent event) { - orderedProducts.computeIfPresent(event.getOrderId(), (orderId, orderedProduct) -> { - orderedProduct.decrementProductInstance(event.getProductId()); - return orderedProduct; - }); - } - - @EventHandler - public void on(ProductRemovedEvent event) { - orderedProducts.computeIfPresent(event.getOrderId(), (orderId, orderedProduct) -> { - orderedProduct.removeProduct(event.getProductId()); - return orderedProduct; - }); - } - - @EventHandler - public void on(OrderConfirmedEvent event) { - orderedProducts.computeIfPresent(event.getOrderId(), (orderId, orderedProduct) -> { - orderedProduct.setOrderConfirmed(); - return orderedProduct; - }); - } - - @EventHandler - public void on(OrderShippedEvent event) { - orderedProducts.computeIfPresent(event.getOrderId(), (orderId, orderedProduct) -> { - orderedProduct.setOrderShipped(); - return orderedProduct; - }); - } - - @QueryHandler - public List handle(FindAllOrderedProductsQuery query) { - return new ArrayList<>(orderedProducts.values()); - } -} \ No newline at end of file diff --git a/axon/src/main/java/com/baeldung/axon/querymodel/OrdersEventHandler.java b/axon/src/main/java/com/baeldung/axon/querymodel/OrdersEventHandler.java new file mode 100644 index 0000000000..25666b0bf3 --- /dev/null +++ b/axon/src/main/java/com/baeldung/axon/querymodel/OrdersEventHandler.java @@ -0,0 +1,86 @@ +package com.baeldung.axon.querymodel; + +import com.baeldung.axon.coreapi.events.OrderConfirmedEvent; +import com.baeldung.axon.coreapi.events.OrderCreatedEvent; +import com.baeldung.axon.coreapi.events.OrderShippedEvent; +import com.baeldung.axon.coreapi.events.ProductAddedEvent; +import com.baeldung.axon.coreapi.events.ProductCountDecrementedEvent; +import com.baeldung.axon.coreapi.events.ProductCountIncrementedEvent; +import com.baeldung.axon.coreapi.events.ProductRemovedEvent; +import com.baeldung.axon.coreapi.queries.FindAllOrderedProductsQuery; +import com.baeldung.axon.coreapi.queries.Order; +import org.axonframework.config.ProcessingGroup; +import org.axonframework.eventhandling.EventHandler; +import org.axonframework.queryhandling.QueryHandler; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +@ProcessingGroup("orders") +public class OrdersEventHandler { + + private final Map orders = new HashMap<>(); + + @EventHandler + public void on(OrderCreatedEvent event) { + String orderId = event.getOrderId(); + orders.put(orderId, new Order(orderId)); + } + + @EventHandler + public void on(ProductAddedEvent event) { + orders.computeIfPresent(event.getOrderId(), (orderId, order) -> { + order.addProduct(event.getProductId()); + return order; + }); + } + + @EventHandler + public void on(ProductCountIncrementedEvent event) { + orders.computeIfPresent(event.getOrderId(), (orderId, order) -> { + order.incrementProductInstance(event.getProductId()); + return order; + }); + } + + @EventHandler + public void on(ProductCountDecrementedEvent event) { + orders.computeIfPresent(event.getOrderId(), (orderId, order) -> { + order.decrementProductInstance(event.getProductId()); + return order; + }); + } + + @EventHandler + public void on(ProductRemovedEvent event) { + orders.computeIfPresent(event.getOrderId(), (orderId, order) -> { + order.removeProduct(event.getProductId()); + return order; + }); + } + + @EventHandler + public void on(OrderConfirmedEvent event) { + orders.computeIfPresent(event.getOrderId(), (orderId, order) -> { + order.setOrderConfirmed(); + return order; + }); + } + + @EventHandler + public void on(OrderShippedEvent event) { + orders.computeIfPresent(event.getOrderId(), (orderId, order) -> { + order.setOrderShipped(); + return order; + }); + } + + @QueryHandler + public List handle(FindAllOrderedProductsQuery query) { + return new ArrayList<>(orders.values()); + } +} \ No newline at end of file diff --git a/axon/src/main/resources/order-api.http b/axon/src/main/resources/order-api.http index aceb5a97ba..6c06c48989 100644 --- a/axon/src/main/resources/order-api.http +++ b/axon/src/main/resources/order-api.http @@ -1,8 +1,8 @@ -### Place Order, Add Product, Confirm and Ship Order +### Create Order, Add Product, Confirm and Ship Order POST http://localhost:8080/ship-order -### Place Order, Add Product and Ship Order +### Create Order, Add Product and Ship Order POST http://localhost:8080/ship-unconfirmed-order @@ -10,7 +10,7 @@ POST http://localhost:8080/ship-unconfirmed-order GET http://localhost:8080/all-orders -### Place Order with id 666a1661-474d-4046-8b12-8b5896312768 +### Create Order with id 666a1661-474d-4046-8b12-8b5896312768 POST http://localhost:8080/order/666a1661-474d-4046-8b12-8b5896312768 diff --git a/axon/src/test/java/com/baeldung/axon/commandmodel/OrderAggregateUnitTest.java b/axon/src/test/java/com/baeldung/axon/commandmodel/OrderAggregateUnitTest.java index 262a8f1e03..c1d6bdccc2 100644 --- a/axon/src/test/java/com/baeldung/axon/commandmodel/OrderAggregateUnitTest.java +++ b/axon/src/test/java/com/baeldung/axon/commandmodel/OrderAggregateUnitTest.java @@ -3,12 +3,12 @@ package com.baeldung.axon.commandmodel; import com.baeldung.axon.commandmodel.order.OrderAggregate; import com.baeldung.axon.coreapi.commands.AddProductCommand; import com.baeldung.axon.coreapi.commands.ConfirmOrderCommand; +import com.baeldung.axon.coreapi.commands.CreateOrderCommand; import com.baeldung.axon.coreapi.commands.DecrementProductCountCommand; import com.baeldung.axon.coreapi.commands.IncrementProductCountCommand; -import com.baeldung.axon.coreapi.commands.PlaceOrderCommand; import com.baeldung.axon.coreapi.commands.ShipOrderCommand; import com.baeldung.axon.coreapi.events.OrderConfirmedEvent; -import com.baeldung.axon.coreapi.events.OrderPlacedEvent; +import com.baeldung.axon.coreapi.events.OrderCreatedEvent; import com.baeldung.axon.coreapi.events.OrderShippedEvent; import com.baeldung.axon.coreapi.events.ProductAddedEvent; import com.baeldung.axon.coreapi.events.ProductCountDecrementedEvent; @@ -37,37 +37,37 @@ class OrderAggregateUnitTest { } @Test - void giveNoPriorActivity_whenPlaceOrderCommand_thenShouldPublishOrderPlacedEvent() { + void giveNoPriorActivity_whenCreateOrderCommand_thenShouldPublishOrderCreatedEvent() { fixture.givenNoPriorActivity() - .when(new PlaceOrderCommand(ORDER_ID)) - .expectEvents(new OrderPlacedEvent(ORDER_ID)); + .when(new CreateOrderCommand(ORDER_ID)) + .expectEvents(new OrderCreatedEvent(ORDER_ID)); } @Test - void givenOrderPlacedEvent_whenAddProductCommand_thenShouldPublishProductAddedEvent() { - fixture.given(new OrderPlacedEvent(ORDER_ID)) + void givenOrderCreatedEvent_whenAddProductCommand_thenShouldPublishProductAddedEvent() { + fixture.given(new OrderCreatedEvent(ORDER_ID)) .when(new AddProductCommand(ORDER_ID, PRODUCT_ID)) .expectEvents(new ProductAddedEvent(ORDER_ID, PRODUCT_ID)); } @Test - void givenOrderPlacedEventAndProductAddedEvent_whenAddProductCommandForSameProductId_thenShouldThrowDuplicateOrderLineException() { - fixture.given(new OrderPlacedEvent(ORDER_ID), new ProductAddedEvent(ORDER_ID, PRODUCT_ID)) + void givenOrderCreatedEventAndProductAddedEvent_whenAddProductCommandForSameProductId_thenShouldThrowDuplicateOrderLineException() { + fixture.given(new OrderCreatedEvent(ORDER_ID), new ProductAddedEvent(ORDER_ID, PRODUCT_ID)) .when(new AddProductCommand(ORDER_ID, PRODUCT_ID)) .expectException(DuplicateOrderLineException.class) .expectExceptionMessage(Matchers.predicate(message -> ((String) message).contains(PRODUCT_ID))); } @Test - void givenOrderPlacedEventAndProductAddedEvent_whenIncrementProductCountCommand_thenShouldPublishProductCountIncrementedEvent() { - fixture.given(new OrderPlacedEvent(ORDER_ID), new ProductAddedEvent(ORDER_ID, PRODUCT_ID)) + void givenOrderCreatedEventAndProductAddedEvent_whenIncrementProductCountCommand_thenShouldPublishProductCountIncrementedEvent() { + fixture.given(new OrderCreatedEvent(ORDER_ID), new ProductAddedEvent(ORDER_ID, PRODUCT_ID)) .when(new IncrementProductCountCommand(ORDER_ID, PRODUCT_ID)) .expectEvents(new ProductCountIncrementedEvent(ORDER_ID, PRODUCT_ID)); } @Test - void givenOrderPlacedEventProductAddedEventAndProductCountIncrementedEvent_whenDecrementProductCountCommand_thenShouldPublishProductCountDecrementedEvent() { - fixture.given(new OrderPlacedEvent(ORDER_ID), + void givenOrderCreatedEventProductAddedEventAndProductCountIncrementedEvent_whenDecrementProductCountCommand_thenShouldPublishProductCountDecrementedEvent() { + fixture.given(new OrderCreatedEvent(ORDER_ID), new ProductAddedEvent(ORDER_ID, PRODUCT_ID), new ProductCountIncrementedEvent(ORDER_ID, PRODUCT_ID)) .when(new DecrementProductCountCommand(ORDER_ID, PRODUCT_ID)) @@ -75,51 +75,51 @@ class OrderAggregateUnitTest { } @Test - void givenOrderPlacedEventAndProductAddedEvent_whenDecrementProductCountCommand_thenShouldPublishProductRemovedEvent() { - fixture.given(new OrderPlacedEvent(ORDER_ID), new ProductAddedEvent(ORDER_ID, PRODUCT_ID)) + void givenOrderCreatedEventAndProductAddedEvent_whenDecrementProductCountCommand_thenShouldPublishProductRemovedEvent() { + fixture.given(new OrderCreatedEvent(ORDER_ID), new ProductAddedEvent(ORDER_ID, PRODUCT_ID)) .when(new DecrementProductCountCommand(ORDER_ID, PRODUCT_ID)) .expectEvents(new ProductRemovedEvent(ORDER_ID, PRODUCT_ID)); } @Test - void givenOrderPlacedEvent_whenConfirmOrderCommand_thenShouldPublishOrderConfirmedEvent() { - fixture.given(new OrderPlacedEvent(ORDER_ID)) + void givenOrderCreatedEvent_whenConfirmOrderCommand_thenShouldPublishOrderConfirmedEvent() { + fixture.given(new OrderCreatedEvent(ORDER_ID)) .when(new ConfirmOrderCommand(ORDER_ID)) .expectEvents(new OrderConfirmedEvent(ORDER_ID)); } @Test - void givenOrderPlacedEventAndOrderConfirmedEvent_whenConfirmOrderCommand_thenExpectNoEvents() { - fixture.given(new OrderPlacedEvent(ORDER_ID), new OrderConfirmedEvent(ORDER_ID)) + void givenOrderCreatedEventAndOrderConfirmedEvent_whenConfirmOrderCommand_thenExpectNoEvents() { + fixture.given(new OrderCreatedEvent(ORDER_ID), new OrderConfirmedEvent(ORDER_ID)) .when(new ConfirmOrderCommand(ORDER_ID)) .expectNoEvents(); } @Test - void givenOrderPlacedEvent_whenShipOrderCommand_thenShouldThrowUnconfirmedOrderException() { - fixture.given(new OrderPlacedEvent(ORDER_ID)) + void givenOrderCreatedEvent_whenShipOrderCommand_thenShouldThrowUnconfirmedOrderException() { + fixture.given(new OrderCreatedEvent(ORDER_ID)) .when(new ShipOrderCommand(ORDER_ID)) .expectException(UnconfirmedOrderException.class); } @Test - void givenOrderPlacedEventAndOrderConfirmedEvent_whenShipOrderCommand_thenShouldPublishOrderShippedEvent() { - fixture.given(new OrderPlacedEvent(ORDER_ID), new OrderConfirmedEvent(ORDER_ID)) + void givenOrderCreatedEventAndOrderConfirmedEvent_whenShipOrderCommand_thenShouldPublishOrderShippedEvent() { + fixture.given(new OrderCreatedEvent(ORDER_ID), new OrderConfirmedEvent(ORDER_ID)) .when(new ShipOrderCommand(ORDER_ID)) .expectEvents(new OrderShippedEvent(ORDER_ID)); } @Test - void givenOrderPlacedEventProductAndOrderConfirmedEvent_whenAddProductCommand_thenShouldThrowOrderAlreadyConfirmedException() { - fixture.given(new OrderPlacedEvent(ORDER_ID), new OrderConfirmedEvent(ORDER_ID)) + void givenOrderCreatedEventProductAndOrderConfirmedEvent_whenAddProductCommand_thenShouldThrowOrderAlreadyConfirmedException() { + fixture.given(new OrderCreatedEvent(ORDER_ID), new OrderConfirmedEvent(ORDER_ID)) .when(new AddProductCommand(ORDER_ID, PRODUCT_ID)) .expectException(OrderAlreadyConfirmedException.class) .expectExceptionMessage(Matchers.predicate(message -> ((String) message).contains(ORDER_ID))); } @Test - void givenOrderPlacedEventProductAddedEventAndOrderConfirmedEvent_whenIncrementProductCountCommand_thenShouldThrowOrderAlreadyConfirmedException() { - fixture.given(new OrderPlacedEvent(ORDER_ID), + void givenOrderCreatedEventProductAddedEventAndOrderConfirmedEvent_whenIncrementProductCountCommand_thenShouldThrowOrderAlreadyConfirmedException() { + fixture.given(new OrderCreatedEvent(ORDER_ID), new ProductAddedEvent(ORDER_ID, PRODUCT_ID), new OrderConfirmedEvent(ORDER_ID)) .when(new IncrementProductCountCommand(ORDER_ID, PRODUCT_ID)) @@ -128,8 +128,8 @@ class OrderAggregateUnitTest { } @Test - void givenOrderPlacedEventProductAddedEventAndOrderConfirmedEvent_whenDecrementProductCountCommand_thenShouldThrowOrderAlreadyConfirmedException() { - fixture.given(new OrderPlacedEvent(ORDER_ID), + void givenOrderCreatedEventProductAddedEventAndOrderConfirmedEvent_whenDecrementProductCountCommand_thenShouldThrowOrderAlreadyConfirmedException() { + fixture.given(new OrderCreatedEvent(ORDER_ID), new ProductAddedEvent(ORDER_ID, PRODUCT_ID), new OrderConfirmedEvent(ORDER_ID)) .when(new DecrementProductCountCommand(ORDER_ID, PRODUCT_ID))