diff --git a/companies/src/main/java/org/axonframework/samples/trader/company/command/CompanyOrderBookListener.java b/companies/src/main/java/org/axonframework/samples/trader/company/command/CompanyOrderBookListener.java index 6a1eeb8..dd22bb5 100644 --- a/companies/src/main/java/org/axonframework/samples/trader/company/command/CompanyOrderBookListener.java +++ b/companies/src/main/java/org/axonframework/samples/trader/company/command/CompanyOrderBookListener.java @@ -21,8 +21,8 @@ import org.axonframework.eventhandling.EventHandler; import org.axonframework.samples.trader.api.company.AddOrderBookToCompanyCommand; import org.axonframework.samples.trader.api.company.CompanyCreatedEvent; +import org.axonframework.samples.trader.api.orders.OrderBookId; import org.axonframework.samples.trader.api.orders.trades.CreateOrderBookCommand; -import org.axonframework.samples.trader.api.orders.trades.OrderBookId; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; diff --git a/companies/src/test/java/org/axonframework/samples/trader/company/command/CompanyCommandHandlerTest.java b/companies/src/test/java/org/axonframework/samples/trader/company/command/CompanyCommandHandlerTest.java deleted file mode 100644 index 80533e4..0000000 --- a/companies/src/test/java/org/axonframework/samples/trader/company/command/CompanyCommandHandlerTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2010-2012. Axon Framework - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.axonframework.samples.trader.company.command; - -import org.axonframework.samples.trader.api.company.CompanyCreatedEvent; -import org.axonframework.samples.trader.api.company.CompanyId; -import org.axonframework.samples.trader.api.company.CreateCompanyCommand; -import org.axonframework.samples.trader.api.users.UserId; -import org.axonframework.test.aggregate.AggregateTestFixture; -import org.junit.Before; -import org.junit.Test; - -/** - * @author Jettro Coenradie - */ -public class CompanyCommandHandlerTest { - - private AggregateTestFixture fixture; - - @Before - public void setUp() { - fixture = new AggregateTestFixture(Company.class); - CompanyCommandHandler commandHandler = new CompanyCommandHandler(); - commandHandler.setRepository(fixture.getRepository()); - fixture.registerAnnotatedCommandHandler(commandHandler); - } - - @Test - public void testCreateCompany() { - CompanyId aggregateIdentifier = new CompanyId(); - UserId userId = new UserId(); - CreateCompanyCommand command = new CreateCompanyCommand(aggregateIdentifier, userId, "TestItem", 1000, 10000); - - fixture.given() - .when(command) - .expectEvents(new CompanyCreatedEvent(aggregateIdentifier, "TestItem", 1000, 10000)); - } -} diff --git a/orders/src/main/java/org/axonframework/samples/trader/orders/command/BuyTradeManagerSaga.java b/orders/src/main/java/org/axonframework/samples/trader/orders/command/BuyTradeManagerSaga.java index a316922..d8d934e 100644 --- a/orders/src/main/java/org/axonframework/samples/trader/orders/command/BuyTradeManagerSaga.java +++ b/orders/src/main/java/org/axonframework/samples/trader/orders/command/BuyTradeManagerSaga.java @@ -22,12 +22,12 @@ import org.axonframework.eventhandling.saga.EndSaga; import org.axonframework.eventhandling.saga.SagaEventHandler; import org.axonframework.eventhandling.saga.StartSaga; -import org.axonframework.samples.trader.api.portfolio.stock.AddItemsToPortfolioCommand; -import org.axonframework.samples.trader.api.portfolio.cash.*; -import org.axonframework.samples.trader.api.orders.transaction.*; +import org.axonframework.samples.trader.api.orders.OrderId; import org.axonframework.samples.trader.api.orders.trades.CreateBuyOrderCommand; -import org.axonframework.samples.trader.api.orders.trades.OrderId; import org.axonframework.samples.trader.api.orders.trades.TradeExecutedEvent; +import org.axonframework.samples.trader.api.orders.transaction.*; +import org.axonframework.samples.trader.api.portfolio.cash.*; +import org.axonframework.samples.trader.api.portfolio.stock.AddItemsToPortfolioCommand; import org.axonframework.spring.stereotype.Saga; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,9 +62,9 @@ public void handle(BuyTransactionStartedEvent event) { setTotalItems(event.getTotalItems()); ReserveCashCommand command = new ReserveCashCommand(getPortfolioIdentifier(), - getTransactionIdentifier(), - getTotalItems() - * getPricePerItem()); + getTransactionIdentifier(), + getTotalItems() + * getPricePerItem()); getCommandBus().dispatch(new GenericCommandMessage<>(command)); } @@ -73,19 +73,19 @@ public void handle(CashReservedEvent event) { logger.debug("Money for transaction with identifier {} is reserved", getTransactionIdentifier()); ConfirmTransactionCommand command = new ConfirmTransactionCommand(getTransactionIdentifier()); getCommandBus().dispatch(new GenericCommandMessage<>(command), - new CommandCallback() { - - @Override - public void onSuccess(CommandMessage commandMessage, Void result) { - // TODO jettro : Do we really need this? - logger.debug("Confirm transaction is dispatched successfully!"); - } - - @Override - public void onFailure(CommandMessage commandMessage, Throwable cause) { - logger.error("********* WOW!!!", cause); - } - }); + new CommandCallback() { + + @Override + public void onSuccess(CommandMessage commandMessage, Void result) { + // TODO jettro : Do we really need this? + logger.debug("Confirm transaction is dispatched successfully!"); + } + + @Override + public void onFailure(CommandMessage commandMessage, Throwable cause) { + logger.error("********* WOW!!!", cause); + } + }); } @SagaEventHandler(associationProperty = "transactionIdentifier") @@ -102,10 +102,10 @@ public void handle(CashReservationRejectedEvent event) { public void handle(BuyTransactionConfirmedEvent event) { logger.debug("Buy Transaction {} is approved to make the buy order", event.getTransactionId()); CreateBuyOrderCommand command = new CreateBuyOrderCommand(new OrderId(), getPortfolioIdentifier(), - getOrderbookIdentifier(), - getTransactionIdentifier(), - getTotalItems(), - getPricePerItem()); + getOrderbookIdentifier(), + getTransactionIdentifier(), + getTotalItems(), + getPricePerItem()); getCommandBus().dispatch(new GenericCommandMessage<>(command)); } @@ -113,8 +113,8 @@ public void handle(BuyTransactionConfirmedEvent event) { public void handle(BuyTransactionCancelledEvent event) { long amountToCancel = (event.getTotalAmountOfItems() - event.getAmountOfExecutedItems()) * getPricePerItem(); logger.debug("Buy Transaction {} is cancelled, amount of cash reserved to cancel is {}", - event.getTransactionId(), - amountToCancel); + event.getTransactionId(), + amountToCancel); CancelCashReservationCommand command = new CancelCashReservationCommand( getPortfolioIdentifier(), getTransactionIdentifier(), @@ -127,8 +127,8 @@ public void handle(TradeExecutedEvent event) { logger.debug("Buy Transaction {} is executed, items for transaction are {} for a price of {}", getTransactionIdentifier(), event.getTradeCount(), event.getTradePrice()); ExecutedTransactionCommand command = new ExecutedTransactionCommand(getTransactionIdentifier(), - event.getTradeCount(), - event.getTradePrice()); + event.getTradeCount(), + event.getTradePrice()); getCommandBus().dispatch(new GenericCommandMessage<>(command)); } @@ -142,13 +142,13 @@ public void handle(BuyTransactionExecutedEvent event) { ConfirmCashReservationCommand confirmCommand = new ConfirmCashReservationCommand(getPortfolioIdentifier(), - getTransactionIdentifier(), - event.getAmountOfItems() * event.getItemPrice()); + getTransactionIdentifier(), + event.getAmountOfItems() * event.getItemPrice()); getCommandBus().dispatch(new GenericCommandMessage<>(confirmCommand)); AddItemsToPortfolioCommand addItemsCommand = new AddItemsToPortfolioCommand(getPortfolioIdentifier(), - getOrderbookIdentifier(), - event.getAmountOfItems()); + getOrderbookIdentifier(), + event.getAmountOfItems()); getCommandBus().dispatch(new GenericCommandMessage<>(addItemsCommand)); } @@ -165,14 +165,14 @@ public void handle(BuyTransactionPartiallyExecutedEvent event) { ConfirmCashReservationCommand confirmCommand = new ConfirmCashReservationCommand(getPortfolioIdentifier(), - getTransactionIdentifier(), - event.getAmountOfExecutedItems() * event - .getItemPrice()); + getTransactionIdentifier(), + event.getAmountOfExecutedItems() * event + .getItemPrice()); getCommandBus().dispatch(new GenericCommandMessage<>(confirmCommand)); AddItemsToPortfolioCommand addItemsCommand = new AddItemsToPortfolioCommand(getPortfolioIdentifier(), - getOrderbookIdentifier(), - event.getAmountOfExecutedItems()); + getOrderbookIdentifier(), + event.getAmountOfExecutedItems()); getCommandBus().dispatch(new GenericCommandMessage<>(addItemsCommand)); } @@ -189,5 +189,4 @@ private void returnDifferenceInBidPriceAndExecutedPrice(long bidPrice, long exec cancelCashReservationCommand)); } } - } diff --git a/orders/src/main/java/org/axonframework/samples/trader/orders/command/Portfolio.java b/orders/src/main/java/org/axonframework/samples/trader/orders/command/Portfolio.java index ef25b9f..185df7c 100644 --- a/orders/src/main/java/org/axonframework/samples/trader/orders/command/Portfolio.java +++ b/orders/src/main/java/org/axonframework/samples/trader/orders/command/Portfolio.java @@ -19,10 +19,10 @@ import org.axonframework.commandhandling.model.AggregateIdentifier; import org.axonframework.commandhandling.model.AggregateRoot; import org.axonframework.eventhandling.EventHandler; -import org.axonframework.samples.trader.api.orders.trades.OrderBookId; -import org.axonframework.samples.trader.api.orders.trades.PortfolioId; +import org.axonframework.samples.trader.api.orders.OrderBookId; import org.axonframework.samples.trader.api.orders.transaction.TransactionId; import org.axonframework.samples.trader.api.portfolio.PortfolioCreatedEvent; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.axonframework.samples.trader.api.portfolio.cash.*; import org.axonframework.samples.trader.api.portfolio.stock.*; import org.axonframework.samples.trader.api.users.UserId; @@ -43,6 +43,7 @@ */ @AggregateRoot public class Portfolio { + private static final long serialVersionUID = 996371335141649977L; @AggregateIdentifier @@ -64,16 +65,26 @@ public void addItems(OrderBookId orderBookIdentifier, long amountOfItemsToAdd) { apply(new ItemsAddedToPortfolioEvent(portfolioId, orderBookIdentifier, amountOfItemsToAdd)); } - public void reserveItems(OrderBookId orderBookIdentifier, TransactionId transactionIdentifier, long amountOfItemsToReserve) { + public void reserveItems(OrderBookId orderBookIdentifier, TransactionId transactionIdentifier, + long amountOfItemsToReserve) { if (!availableItems.containsKey(orderBookIdentifier)) { - apply(new ItemToReserveNotAvailableInPortfolioEvent(portfolioId, orderBookIdentifier, transactionIdentifier)); + apply(new ItemToReserveNotAvailableInPortfolioEvent(portfolioId, + orderBookIdentifier, + transactionIdentifier)); } else { Long availableAmountOfItems = availableItems.get(orderBookIdentifier); if (availableAmountOfItems < amountOfItemsToReserve) { apply(new NotEnoughItemsAvailableToReserveInPortfolioEvent( - portfolioId, orderBookIdentifier, transactionIdentifier, availableAmountOfItems, amountOfItemsToReserve)); + portfolioId, + orderBookIdentifier, + transactionIdentifier, + availableAmountOfItems, + amountOfItemsToReserve)); } else { - apply(new ItemsReservedEvent(portfolioId, orderBookIdentifier, transactionIdentifier, amountOfItemsToReserve)); + apply(new ItemsReservedEvent(portfolioId, + orderBookIdentifier, + transactionIdentifier, + amountOfItemsToReserve)); } } } @@ -87,7 +98,8 @@ public void confirmReservation(OrderBookId orderBookIdentifier, TransactionId tr amountOfItemsToConfirm)); } - public void cancelReservation(OrderBookId orderBookIdentifier, TransactionId transactionIdentifier, long amountOfItemsToCancel) { + public void cancelReservation(OrderBookId orderBookIdentifier, TransactionId transactionIdentifier, + long amountOfItemsToCancel) { apply(new ItemReservationCancelledForPortfolioEvent( portfolioId, orderBookIdentifier, @@ -133,11 +145,11 @@ public void onItemsAddedToPortfolio(ItemsAddedToPortfolioEvent event) { @EventHandler public void onItemsReserved(ItemsReservedEvent event) { - long available = obtainCurrentAvailableItems(event.getOrderBookIdentifier()); - availableItems.put(event.getOrderBookIdentifier(), available - event.getAmountOfItemsReserved()); + long available = obtainCurrentAvailableItems(event.getOrderBookId()); + availableItems.put(event.getOrderBookId(), available - event.getAmountOfItemsReserved()); - long reserved = obtainCurrentReservedItems(event.getOrderBookIdentifier()); - reservedItems.put(event.getOrderBookIdentifier(), reserved + event.getAmountOfItemsReserved()); + long reserved = obtainCurrentReservedItems(event.getOrderBookId()); + reservedItems.put(event.getOrderBookId(), reserved + event.getAmountOfItemsReserved()); } @EventHandler diff --git a/orders/src/main/java/org/axonframework/samples/trader/orders/command/PortfolioCommandHandler.java b/orders/src/main/java/org/axonframework/samples/trader/orders/command/PortfolioCommandHandler.java index 69c82be..e40fbcc 100644 --- a/orders/src/main/java/org/axonframework/samples/trader/orders/command/PortfolioCommandHandler.java +++ b/orders/src/main/java/org/axonframework/samples/trader/orders/command/PortfolioCommandHandler.java @@ -66,9 +66,9 @@ public void handleAddItemsToPortfolioCommand(AddItemsToPortfolioCommand command) @CommandHandler public void handleConfirmReservationCommand(ConfirmItemReservationForPortfolioCommand command) { - Aggregate portfolio = portfolioRepository.load(command.getPortfolioIdentifier().toString()); + Aggregate portfolio = portfolioRepository.load(command.getPortfolioId().toString()); portfolio.execute(aggregateRoot -> { - aggregateRoot.confirmReservation(command.getOrderBookIdentifier(), + aggregateRoot.confirmReservation(command.getOrderBookId(), command.getTransactionId(), command.getAmountOfItemsToConfirm()); }); @@ -76,7 +76,7 @@ public void handleConfirmReservationCommand(ConfirmItemReservationForPortfolioCo @CommandHandler public void handleCancelReservationCommand(CancelItemReservationForPortfolioCommand command) { - Aggregate portfolio = portfolioRepository.load(command.getPortfolioIdentifier().toString()); + Aggregate portfolio = portfolioRepository.load(command.getPortfolioId().toString()); portfolio.execute(aggregateRoot -> { aggregateRoot.cancelReservation(command.getOrderBookId(), command.getTransactionId(), diff --git a/orders/src/main/java/org/axonframework/samples/trader/orders/command/PortfolioManagementUserListener.java b/orders/src/main/java/org/axonframework/samples/trader/orders/command/PortfolioManagementUserListener.java index 83c52fe..eecd69b 100644 --- a/orders/src/main/java/org/axonframework/samples/trader/orders/command/PortfolioManagementUserListener.java +++ b/orders/src/main/java/org/axonframework/samples/trader/orders/command/PortfolioManagementUserListener.java @@ -20,7 +20,7 @@ import org.axonframework.commandhandling.GenericCommandMessage; import org.axonframework.eventhandling.EventHandler; import org.axonframework.samples.trader.api.portfolio.CreatePortfolioCommand; -import org.axonframework.samples.trader.api.orders.trades.PortfolioId; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.axonframework.samples.trader.api.users.UserCreatedEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/orders/src/main/java/org/axonframework/samples/trader/orders/command/SellTradeManagerSaga.java b/orders/src/main/java/org/axonframework/samples/trader/orders/command/SellTradeManagerSaga.java index e37bcea..447143e 100644 --- a/orders/src/main/java/org/axonframework/samples/trader/orders/command/SellTradeManagerSaga.java +++ b/orders/src/main/java/org/axonframework/samples/trader/orders/command/SellTradeManagerSaga.java @@ -20,12 +20,12 @@ import org.axonframework.eventhandling.saga.EndSaga; import org.axonframework.eventhandling.saga.SagaEventHandler; import org.axonframework.eventhandling.saga.StartSaga; -import org.axonframework.samples.trader.api.portfolio.stock.*; -import org.axonframework.samples.trader.api.portfolio.cash.DepositCashCommand; -import org.axonframework.samples.trader.api.orders.transaction.*; +import org.axonframework.samples.trader.api.orders.OrderId; import org.axonframework.samples.trader.api.orders.trades.CreateSellOrderCommand; -import org.axonframework.samples.trader.api.orders.trades.OrderId; import org.axonframework.samples.trader.api.orders.trades.TradeExecutedEvent; +import org.axonframework.samples.trader.api.orders.transaction.*; +import org.axonframework.samples.trader.api.portfolio.cash.DepositCashCommand; +import org.axonframework.samples.trader.api.portfolio.stock.*; import org.axonframework.spring.stereotype.Saga; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,9 +62,9 @@ public void handle(SellTransactionStartedEvent event) { ReserveItemsCommand reserveItemsCommand = new ReserveItemsCommand(getPortfolioIdentifier(), - getOrderbookIdentifier(), - getTransactionIdentifier(), - event.getTotalItems()); + getOrderbookIdentifier(), + getTransactionIdentifier(), + event.getTotalItems()); getCommandBus().dispatch(new GenericCommandMessage<>(reserveItemsCommand)); } @@ -79,7 +79,7 @@ public void handle(ItemsReservedEvent event) { @EndSaga public void handle(NotEnoughItemsAvailableToReserveInPortfolioEvent event) { logger.debug("Cannot continue with transaction with id {} since the items needed cannot be reserved", - getTotalItems()); + getTotalItems()); } @SagaEventHandler(associationProperty = "transactionIdentifier") @@ -87,11 +87,11 @@ public void handle(SellTransactionConfirmedEvent event) { logger.debug("Sell Transaction {} is approved to make the sell order", event.getTransactionId()); CreateSellOrderCommand command = new CreateSellOrderCommand(new OrderId(), - getPortfolioIdentifier(), - getOrderbookIdentifier(), - getTransactionIdentifier(), - getTotalItems(), - getPricePerItem()); + getPortfolioIdentifier(), + getOrderbookIdentifier(), + getTransactionIdentifier(), + getTotalItems(), + getPricePerItem()); getCommandBus().dispatch(new GenericCommandMessage<>(command)); } @@ -100,13 +100,13 @@ public void handle(SellTransactionConfirmedEvent event) { public void handle(SellTransactionCancelledEvent event) { long amountOfCancelledItems = event.getTotalAmountOfItems() - event.getAmountOfExecutedItems(); logger.debug("Sell Transaction {} is cancelled, amount of cash reserved to cancel is {}", - event.getTransactionId(), - amountOfCancelledItems); + event.getTransactionId(), + amountOfCancelledItems); CancelItemReservationForPortfolioCommand command = new CancelItemReservationForPortfolioCommand(getPortfolioIdentifier(), - getOrderbookIdentifier(), - getTransactionIdentifier(), - amountOfCancelledItems); + getOrderbookIdentifier(), + getTransactionIdentifier(), + amountOfCancelledItems); getCommandBus().dispatch(new GenericCommandMessage<>(command)); } @@ -115,8 +115,8 @@ public void handle(TradeExecutedEvent event) { logger.debug("Sell Transaction {} is executed, items for transaction are {} for a price of {}", getTransactionIdentifier(), event.getTradeCount(), event.getTradePrice()); ExecutedTransactionCommand command = new ExecutedTransactionCommand(getTransactionIdentifier(), - event.getTradeCount(), - event.getTradePrice()); + event.getTradeCount(), + event.getTradePrice()); getCommandBus().dispatch(new GenericCommandMessage<>(command)); } @@ -129,13 +129,13 @@ public void handle(SellTransactionExecutedEvent event) { ConfirmItemReservationForPortfolioCommand confirmCommand = new ConfirmItemReservationForPortfolioCommand(getPortfolioIdentifier(), - getOrderbookIdentifier(), - getTransactionIdentifier(), - event.getAmountOfItems()); + getOrderbookIdentifier(), + getTransactionIdentifier(), + event.getAmountOfItems()); getCommandBus().dispatch(new GenericCommandMessage<>(confirmCommand)); DepositCashCommand depositCommand = new DepositCashCommand(getPortfolioIdentifier(), - event.getItemPrice() * event.getAmountOfItems()); + event.getItemPrice() * event.getAmountOfItems()); getCommandBus().dispatch(new GenericCommandMessage<>(depositCommand)); } @@ -148,13 +148,13 @@ public void handle(SellTransactionPartiallyExecutedEvent event) { ConfirmItemReservationForPortfolioCommand confirmCommand = new ConfirmItemReservationForPortfolioCommand(getPortfolioIdentifier(), - getOrderbookIdentifier(), - getTransactionIdentifier(), - event.getAmountOfExecutedItems()); + getOrderbookIdentifier(), + getTransactionIdentifier(), + event.getAmountOfExecutedItems()); getCommandBus().dispatch(new GenericCommandMessage<>(confirmCommand)); DepositCashCommand depositCommand = new DepositCashCommand(getPortfolioIdentifier(), - event.getItemPrice() * event.getAmountOfExecutedItems()); + event.getItemPrice() * event.getAmountOfExecutedItems()); getCommandBus().dispatch(new GenericCommandMessage<>(depositCommand)); } } diff --git a/orders/src/main/java/org/axonframework/samples/trader/orders/command/TradeManagerSaga.java b/orders/src/main/java/org/axonframework/samples/trader/orders/command/TradeManagerSaga.java index a9da9cd..9eff5bf 100644 --- a/orders/src/main/java/org/axonframework/samples/trader/orders/command/TradeManagerSaga.java +++ b/orders/src/main/java/org/axonframework/samples/trader/orders/command/TradeManagerSaga.java @@ -17,14 +17,11 @@ package org.axonframework.samples.trader.orders.command; import org.axonframework.commandhandling.CommandBus; -import org.axonframework.samples.trader.api.orders.trades.OrderBookId; -import org.axonframework.samples.trader.api.orders.trades.PortfolioId; +import org.axonframework.samples.trader.api.orders.OrderBookId; import org.axonframework.samples.trader.api.orders.transaction.TransactionId; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.springframework.beans.factory.annotation.Autowired; -/** - * @author Jettro Coenradie - */ public abstract class TradeManagerSaga { private transient CommandBus commandBus; diff --git a/orders/src/main/java/org/axonframework/samples/trader/orders/command/Transaction.java b/orders/src/main/java/org/axonframework/samples/trader/orders/command/Transaction.java index 4e6c1a8..a628360 100644 --- a/orders/src/main/java/org/axonframework/samples/trader/orders/command/Transaction.java +++ b/orders/src/main/java/org/axonframework/samples/trader/orders/command/Transaction.java @@ -19,11 +19,10 @@ import org.axonframework.commandhandling.model.AggregateIdentifier; import org.axonframework.commandhandling.model.AggregateRoot; import org.axonframework.eventhandling.EventHandler; +import org.axonframework.samples.trader.api.orders.OrderBookId; import org.axonframework.samples.trader.api.orders.TransactionType; import org.axonframework.samples.trader.api.orders.transaction.*; -import org.axonframework.samples.trader.api.orders.trades.OrderBookId; -import org.axonframework.samples.trader.api.orders.trades.PortfolioId; -import org.axonframework.samples.trader.api.orders.transaction.TransactionId; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import static org.axonframework.commandhandling.model.AggregateLifecycle.apply; @@ -32,6 +31,7 @@ */ @AggregateRoot public class Transaction { + private static final long serialVersionUID = 1299083385130634014L; @AggregateIdentifier @@ -54,17 +54,17 @@ public Transaction(TransactionId transactionId, switch (type) { case BUY: apply(new BuyTransactionStartedEvent(transactionId, - orderbookIdentifier, - portfolioIdentifier, - amountOfItems, - pricePerItem)); + orderbookIdentifier, + portfolioIdentifier, + amountOfItems, + pricePerItem)); break; case SELL: apply(new SellTransactionStartedEvent(transactionId, - orderbookIdentifier, - portfolioIdentifier, - amountOfItems, - pricePerItem)); + orderbookIdentifier, + portfolioIdentifier, + amountOfItems, + pricePerItem)); break; } } @@ -96,9 +96,9 @@ public void execute(long amountOfItems, long itemPrice) { case BUY: if (isPartiallyExecuted(amountOfItems)) { apply(new BuyTransactionPartiallyExecutedEvent(transactionId, - amountOfItems, - amountOfItems + amountOfExecutedItems, - itemPrice)); + amountOfItems, + amountOfItems + amountOfExecutedItems, + itemPrice)); } else { apply(new BuyTransactionExecutedEvent(transactionId, amountOfItems, itemPrice)); } @@ -106,9 +106,9 @@ public void execute(long amountOfItems, long itemPrice) { case SELL: if (isPartiallyExecuted(amountOfItems)) { apply(new SellTransactionPartiallyExecutedEvent(transactionId, - amountOfItems, - amountOfItems + amountOfExecutedItems, - itemPrice)); + amountOfItems, + amountOfItems + amountOfExecutedItems, + itemPrice)); } else { apply(new SellTransactionExecutedEvent(transactionId, amountOfItems, itemPrice)); } diff --git a/orders/src/test/java/org/axonframework/samples/trader/orders/command/BuyTradeManagerSagaTest.java b/orders/src/test/java/org/axonframework/samples/trader/orders/command/BuyTradeManagerSagaTest.java index 0331c87..2bde8cc 100644 --- a/orders/src/test/java/org/axonframework/samples/trader/orders/command/BuyTradeManagerSagaTest.java +++ b/orders/src/test/java/org/axonframework/samples/trader/orders/command/BuyTradeManagerSagaTest.java @@ -16,8 +16,11 @@ package org.axonframework.samples.trader.orders.command; -import org.axonframework.samples.trader.api.orders.trades.*; +import org.axonframework.samples.trader.api.orders.OrderBookId; +import org.axonframework.samples.trader.api.orders.OrderId; +import org.axonframework.samples.trader.api.orders.trades.TradeExecutedEvent; import org.axonframework.samples.trader.api.orders.transaction.*; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.axonframework.samples.trader.api.portfolio.cash.CashReservationRejectedEvent; import org.axonframework.samples.trader.api.portfolio.cash.CashReservedEvent; import org.axonframework.samples.trader.orders.command.matchers.*; @@ -28,9 +31,6 @@ import static org.axonframework.test.matchers.Matchers.andNoMore; import static org.axonframework.test.matchers.Matchers.exactSequenceOf; -/** - * @author Jettro Coenradie - */ public class BuyTradeManagerSagaTest { private static final long TOTAL_ITEMS = 100; @@ -50,85 +50,91 @@ public void setUp() throws Exception { @Test public void testHandle_SellTransactionStarted() throws Exception { fixture.givenAggregate(transactionIdentifier.toString()).published() - .whenAggregate(transactionIdentifier.toString()).publishes( + .whenAggregate(transactionIdentifier.toString()).publishes( new BuyTransactionStartedEvent(transactionIdentifier, - orderbookIdentifier, - portfolioIdentifier, - TOTAL_ITEMS, - PRICE_PER_ITEM)) - .expectActiveSagas(1) - .expectDispatchedCommandsMatching( - exactSequenceOf(ReserveMoneyFromPortfolioCommandMatcher.newInstance( - portfolioIdentifier, - TOTAL_ITEMS * PRICE_PER_ITEM))); + orderbookIdentifier, + portfolioIdentifier, + TOTAL_ITEMS, + PRICE_PER_ITEM)) + .expectActiveSagas(1) + .expectDispatchedCommandsMatching( + exactSequenceOf(ReserveMoneyFromPortfolioCommandMatcher.newInstance( + portfolioIdentifier, + TOTAL_ITEMS * PRICE_PER_ITEM))); } @Test public void testHandle_MoneyIsReserved() throws Exception { fixture.givenAggregate(transactionIdentifier.toString()).published( new BuyTransactionStartedEvent(transactionIdentifier, - orderbookIdentifier, - portfolioIdentifier, - TOTAL_ITEMS, - PRICE_PER_ITEM)) - .whenAggregate(portfolioIdentifier.toString()).publishes( + orderbookIdentifier, + portfolioIdentifier, + TOTAL_ITEMS, + PRICE_PER_ITEM)) + .whenAggregate(portfolioIdentifier.toString()).publishes( new CashReservedEvent(portfolioIdentifier, transactionIdentifier, - TOTAL_ITEMS - * PRICE_PER_ITEM)) - .expectActiveSagas(1) - .expectDispatchedCommandsMatching( - exactSequenceOf(ConfirmTransactionCommandMatcher.newInstance( - transactionIdentifier))); + TOTAL_ITEMS + * PRICE_PER_ITEM)) + .expectActiveSagas(1) + .expectDispatchedCommandsMatching( + exactSequenceOf(ConfirmTransactionCommandMatcher.newInstance( + transactionIdentifier))); } @Test public void testHandle_NotEnoughMoneyToReserved() throws Exception { fixture.givenAggregate(transactionIdentifier.toString()).published( new BuyTransactionStartedEvent(transactionIdentifier, - orderbookIdentifier, - portfolioIdentifier, - TOTAL_ITEMS, - PRICE_PER_ITEM)) - .whenAggregate(portfolioIdentifier.toString()).publishes( + orderbookIdentifier, + portfolioIdentifier, + TOTAL_ITEMS, + PRICE_PER_ITEM)) + .whenAggregate(portfolioIdentifier.toString()).publishes( new CashReservationRejectedEvent( portfolioIdentifier, transactionIdentifier, TOTAL_ITEMS * PRICE_PER_ITEM)) - .expectActiveSagas(0); + .expectActiveSagas(0); } @Test public void testHandle_TransactionConfirmed() throws Exception { fixture.givenAggregate(transactionIdentifier.toString()).published( new BuyTransactionStartedEvent(transactionIdentifier, - orderbookIdentifier, - portfolioIdentifier, - TOTAL_ITEMS, - PRICE_PER_ITEM)) - .andThenAggregate(portfolioIdentifier.toString()).published( + orderbookIdentifier, + portfolioIdentifier, + TOTAL_ITEMS, + PRICE_PER_ITEM)) + .andThenAggregate(portfolioIdentifier.toString()).published( new CashReservedEvent( portfolioIdentifier, transactionIdentifier, TOTAL_ITEMS * PRICE_PER_ITEM)) - .whenAggregate(transactionIdentifier.toString()).publishes(new BuyTransactionConfirmedEvent(transactionIdentifier)) - .expectActiveSagas(1) - .expectDispatchedCommandsMatching(exactSequenceOf( - CreateBuyOrderCommandMatcher.newInstance(portfolioIdentifier, - orderbookIdentifier, - TOTAL_ITEMS, - PRICE_PER_ITEM))); + .whenAggregate(transactionIdentifier.toString()).publishes(new BuyTransactionConfirmedEvent( + transactionIdentifier)) + .expectActiveSagas(1) + .expectDispatchedCommandsMatching(exactSequenceOf( + CreateBuyOrderCommandMatcher.newInstance(portfolioIdentifier, + orderbookIdentifier, + TOTAL_ITEMS, + PRICE_PER_ITEM))); } @Test public void testHandle_TransactionCancelled() throws Exception { - fixture.givenAggregate(transactionIdentifier.toString()).published(new BuyTransactionStartedEvent(transactionIdentifier, + fixture.givenAggregate(transactionIdentifier.toString()).published(new BuyTransactionStartedEvent( + transactionIdentifier, orderbookIdentifier, portfolioIdentifier, TOTAL_ITEMS, PRICE_PER_ITEM)) - .whenAggregate(transactionIdentifier.toString()).publishes(new BuyTransactionCancelledEvent(transactionIdentifier, TOTAL_ITEMS, 0)) - .expectActiveSagas(1) - .expectDispatchedCommandsMatching(exactSequenceOf(CancelMoneyReservationFromPortfolioCommandMatcher.newInstance( - portfolioIdentifier, - TOTAL_ITEMS * PRICE_PER_ITEM))); + .whenAggregate(transactionIdentifier.toString()).publishes(new BuyTransactionCancelledEvent( + transactionIdentifier, + TOTAL_ITEMS, + 0)) + .expectActiveSagas(1) + .expectDispatchedCommandsMatching(exactSequenceOf(CancelMoneyReservationFromPortfolioCommandMatcher + .newInstance( + portfolioIdentifier, + TOTAL_ITEMS * PRICE_PER_ITEM))); } @Test @@ -137,27 +143,30 @@ public void testHandle_TradeExecutedPlaced() throws Exception { OrderId buyOrderIdentifier = new OrderId(); TransactionId sellTransactionIdentifier = new TransactionId(); - fixture.givenAggregate(transactionIdentifier.toString()).published(new BuyTransactionStartedEvent(transactionIdentifier, + fixture.givenAggregate(transactionIdentifier.toString()).published(new BuyTransactionStartedEvent( + transactionIdentifier, orderbookIdentifier, portfolioIdentifier, TOTAL_ITEMS, PRICE_PER_ITEM)) - .andThenAggregate(portfolioIdentifier.toString()).published(new CashReservedEvent( + .andThenAggregate(portfolioIdentifier.toString()).published(new CashReservedEvent( portfolioIdentifier, transactionIdentifier, TOTAL_ITEMS * PRICE_PER_ITEM)) - .andThenAggregate(transactionIdentifier.toString()).published(new BuyTransactionConfirmedEvent(transactionIdentifier)) - .whenAggregate(orderbookIdentifier.toString()).publishes(new TradeExecutedEvent(orderbookIdentifier, - TOTAL_ITEMS, - 99, - buyOrderIdentifier, - sellOrderIdentifier, - transactionIdentifier, - sellTransactionIdentifier)) - .expectActiveSagas(1) - .expectDispatchedCommandsMatching(exactSequenceOf(ExecutedTransactionCommandMatcher.newInstance(TOTAL_ITEMS, - 99, - transactionIdentifier), - andNoMore())); + .andThenAggregate(transactionIdentifier.toString()).published(new BuyTransactionConfirmedEvent( + transactionIdentifier)) + .whenAggregate(orderbookIdentifier.toString()).publishes(new TradeExecutedEvent(orderbookIdentifier, + TOTAL_ITEMS, + 99, + buyOrderIdentifier, + sellOrderIdentifier, + transactionIdentifier, + sellTransactionIdentifier)) + .expectActiveSagas(1) + .expectDispatchedCommandsMatching(exactSequenceOf(ExecutedTransactionCommandMatcher + .newInstance(TOTAL_ITEMS, + 99, + transactionIdentifier), + andNoMore())); } @Test @@ -166,30 +175,36 @@ public void testHandle_BuyTransactionExecuted() throws Exception { OrderId buyOrderIdentifier = new OrderId(); TransactionId sellTransactionIdentifier = new TransactionId(); - fixture.givenAggregate(transactionIdentifier.toString()).published(new BuyTransactionStartedEvent(transactionIdentifier, + fixture.givenAggregate(transactionIdentifier.toString()).published(new BuyTransactionStartedEvent( + transactionIdentifier, orderbookIdentifier, portfolioIdentifier, TOTAL_ITEMS, PRICE_PER_ITEM)) - .andThenAggregate(portfolioIdentifier.toString()).published(new CashReservedEvent( + .andThenAggregate(portfolioIdentifier.toString()).published(new CashReservedEvent( portfolioIdentifier, transactionIdentifier, TOTAL_ITEMS * PRICE_PER_ITEM)) - .andThenAggregate(transactionIdentifier.toString()).published(new BuyTransactionConfirmedEvent(transactionIdentifier)) - .andThenAggregate(orderbookIdentifier.toString()).published(new TradeExecutedEvent(orderbookIdentifier, TOTAL_ITEMS, - 99, - buyOrderIdentifier, - sellOrderIdentifier, + .andThenAggregate(transactionIdentifier.toString()).published(new BuyTransactionConfirmedEvent( + transactionIdentifier)) + .andThenAggregate(orderbookIdentifier.toString()).published(new TradeExecutedEvent(orderbookIdentifier, + TOTAL_ITEMS, + 99, + buyOrderIdentifier, + sellOrderIdentifier, + transactionIdentifier, + sellTransactionIdentifier)) + .whenAggregate(transactionIdentifier.toString()).publishes(new BuyTransactionExecutedEvent( transactionIdentifier, - sellTransactionIdentifier)) - .whenAggregate(transactionIdentifier.toString()).publishes(new BuyTransactionExecutedEvent(transactionIdentifier, TOTAL_ITEMS, 99)) - .expectActiveSagas(0) - .expectDispatchedCommandsMatching( - exactSequenceOf( - ConfirmMoneyReservationFromPortfolionCommandMatcher.newInstance(portfolioIdentifier, - TOTAL_ITEMS * 99), - AddItemsToPortfolioCommandMatcher.newInstance(portfolioIdentifier, - orderbookIdentifier, - TOTAL_ITEMS))); + TOTAL_ITEMS, + 99)) + .expectActiveSagas(0) + .expectDispatchedCommandsMatching( + exactSequenceOf( + ConfirmMoneyReservationFromPortfolionCommandMatcher.newInstance(portfolioIdentifier, + TOTAL_ITEMS * 99), + AddItemsToPortfolioCommandMatcher.newInstance(portfolioIdentifier, + orderbookIdentifier, + TOTAL_ITEMS))); } @Test @@ -204,33 +219,33 @@ public void testHandle_BuyTransactionExecutedWithLowerExecutedPriceThanBidPrice( portfolioIdentifier, TOTAL_ITEMS, PRICE_PER_ITEM)) - .andThenAggregate(portfolioIdentifier.toString()).published(new CashReservedEvent(portfolioIdentifier, - transactionIdentifier, - TOTAL_ITEMS - * PRICE_PER_ITEM)) - .andThenAggregate(transactionIdentifier.toString()) - .published(new BuyTransactionConfirmedEvent(transactionIdentifier)) - .andThenAggregate(orderbookIdentifier.toString()).published(new TradeExecutedEvent(orderbookIdentifier, - TOTAL_ITEMS, - 5, - buyOrderIdentifier, - sellOrderIdentifier, - transactionIdentifier, - sellTransactionIdentifier)) - .whenAggregate(transactionIdentifier.toString()).publishes(new BuyTransactionExecutedEvent( + .andThenAggregate(portfolioIdentifier.toString()).published(new CashReservedEvent(portfolioIdentifier, + transactionIdentifier, + TOTAL_ITEMS + * PRICE_PER_ITEM)) + .andThenAggregate(transactionIdentifier.toString()) + .published(new BuyTransactionConfirmedEvent(transactionIdentifier)) + .andThenAggregate(orderbookIdentifier.toString()).published(new TradeExecutedEvent(orderbookIdentifier, + TOTAL_ITEMS, + 5, + buyOrderIdentifier, + sellOrderIdentifier, + transactionIdentifier, + sellTransactionIdentifier)) + .whenAggregate(transactionIdentifier.toString()).publishes(new BuyTransactionExecutedEvent( transactionIdentifier, TOTAL_ITEMS, 5)) - .expectActiveSagas(0) - .expectDispatchedCommandsMatching( - exactSequenceOf( - CancelMoneyReservationFromPortfolioCommandMatcher.newInstance(portfolioIdentifier, - TOTAL_ITEMS * 5), - ConfirmMoneyReservationFromPortfolionCommandMatcher.newInstance(portfolioIdentifier, - TOTAL_ITEMS * 5), - AddItemsToPortfolioCommandMatcher.newInstance(portfolioIdentifier, - orderbookIdentifier, - TOTAL_ITEMS))); + .expectActiveSagas(0) + .expectDispatchedCommandsMatching( + exactSequenceOf( + CancelMoneyReservationFromPortfolioCommandMatcher.newInstance(portfolioIdentifier, + TOTAL_ITEMS * 5), + ConfirmMoneyReservationFromPortfolionCommandMatcher.newInstance(portfolioIdentifier, + TOTAL_ITEMS * 5), + AddItemsToPortfolioCommandMatcher.newInstance(portfolioIdentifier, + orderbookIdentifier, + TOTAL_ITEMS))); } @Test @@ -239,28 +254,36 @@ public void testHandle_BuyTransactionPartiallyExecuted() throws Exception { OrderId buyOrderIdentifier = new OrderId(); TransactionId sellTransactionIdentifier = new TransactionId(); - fixture.givenAggregate(transactionIdentifier.toString()).published(new BuyTransactionStartedEvent(transactionIdentifier, + fixture.givenAggregate(transactionIdentifier.toString()).published(new BuyTransactionStartedEvent( + transactionIdentifier, orderbookIdentifier, portfolioIdentifier, TOTAL_ITEMS, PRICE_PER_ITEM)) - .andThenAggregate(portfolioIdentifier.toString()).published(new CashReservedEvent( + .andThenAggregate(portfolioIdentifier.toString()).published(new CashReservedEvent( portfolioIdentifier, transactionIdentifier, TOTAL_ITEMS * PRICE_PER_ITEM)) - .andThenAggregate(transactionIdentifier.toString()).published(new BuyTransactionConfirmedEvent(transactionIdentifier)) - .andThenAggregate(orderbookIdentifier.toString()).published(new TradeExecutedEvent(orderbookIdentifier, - 50, - 99, - buyOrderIdentifier, - sellOrderIdentifier, + .andThenAggregate(transactionIdentifier.toString()).published(new BuyTransactionConfirmedEvent( + transactionIdentifier)) + .andThenAggregate(orderbookIdentifier.toString()).published(new TradeExecutedEvent(orderbookIdentifier, + 50, + 99, + buyOrderIdentifier, + sellOrderIdentifier, + transactionIdentifier, + sellTransactionIdentifier)) + .whenAggregate(transactionIdentifier.toString()).publishes(new BuyTransactionPartiallyExecutedEvent( transactionIdentifier, - sellTransactionIdentifier)) - .whenAggregate(transactionIdentifier.toString()).publishes(new BuyTransactionPartiallyExecutedEvent(transactionIdentifier, 50, 50, 99)) - .expectActiveSagas(1) - .expectDispatchedCommandsMatching( - exactSequenceOf( - ConfirmMoneyReservationFromPortfolionCommandMatcher.newInstance(portfolioIdentifier, 50 * 99), - AddItemsToPortfolioCommandMatcher.newInstance(portfolioIdentifier, orderbookIdentifier, 50))); + 50, + 50, + 99)) + .expectActiveSagas(1) + .expectDispatchedCommandsMatching( + exactSequenceOf( + ConfirmMoneyReservationFromPortfolionCommandMatcher + .newInstance(portfolioIdentifier, 50 * 99), + AddItemsToPortfolioCommandMatcher + .newInstance(portfolioIdentifier, orderbookIdentifier, 50))); } @Test @@ -275,30 +298,32 @@ public void testHandle_BuyTransactionPartiallyExecutedWithLowerExecutedPriceThan portfolioIdentifier, TOTAL_ITEMS, PRICE_PER_ITEM)) - .andThenAggregate(portfolioIdentifier.toString()).published(new CashReservedEvent(portfolioIdentifier, - transactionIdentifier, - TOTAL_ITEMS - * PRICE_PER_ITEM)) - .andThenAggregate(transactionIdentifier.toString()) - .published(new BuyTransactionConfirmedEvent(transactionIdentifier)) - .andThenAggregate(orderbookIdentifier.toString()).published(new TradeExecutedEvent(orderbookIdentifier, - 50, - 5, - buyOrderIdentifier, - sellOrderIdentifier, - transactionIdentifier, - sellTransactionIdentifier)) - .whenAggregate(transactionIdentifier.toString()).publishes(new BuyTransactionPartiallyExecutedEvent( + .andThenAggregate(portfolioIdentifier.toString()).published(new CashReservedEvent(portfolioIdentifier, + transactionIdentifier, + TOTAL_ITEMS + * PRICE_PER_ITEM)) + .andThenAggregate(transactionIdentifier.toString()) + .published(new BuyTransactionConfirmedEvent(transactionIdentifier)) + .andThenAggregate(orderbookIdentifier.toString()).published(new TradeExecutedEvent(orderbookIdentifier, + 50, + 5, + buyOrderIdentifier, + sellOrderIdentifier, + transactionIdentifier, + sellTransactionIdentifier)) + .whenAggregate(transactionIdentifier.toString()).publishes(new BuyTransactionPartiallyExecutedEvent( transactionIdentifier, 50, 50, 5)) - .expectActiveSagas(1) - .expectDispatchedCommandsMatching( - exactSequenceOf( - CancelMoneyReservationFromPortfolioCommandMatcher.newInstance(portfolioIdentifier, 250), - ConfirmMoneyReservationFromPortfolionCommandMatcher.newInstance(portfolioIdentifier, 50 * 5), - AddItemsToPortfolioCommandMatcher.newInstance(portfolioIdentifier, orderbookIdentifier, 50))); + .expectActiveSagas(1) + .expectDispatchedCommandsMatching( + exactSequenceOf( + CancelMoneyReservationFromPortfolioCommandMatcher.newInstance(portfolioIdentifier, 250), + ConfirmMoneyReservationFromPortfolionCommandMatcher + .newInstance(portfolioIdentifier, 50 * 5), + AddItemsToPortfolioCommandMatcher + .newInstance(portfolioIdentifier, orderbookIdentifier, 50))); } @Test @@ -307,27 +332,35 @@ public void testHandle_MultipleBuyTransactionPartiallyExecuted() throws Exceptio OrderId buyOrderIdentifier = new OrderId(); TransactionId sellTransactionIdentifier = new TransactionId(); - fixture.givenAggregate(transactionIdentifier.toString()).published(new BuyTransactionStartedEvent(transactionIdentifier, + fixture.givenAggregate(transactionIdentifier.toString()).published(new BuyTransactionStartedEvent( + transactionIdentifier, orderbookIdentifier, portfolioIdentifier, TOTAL_ITEMS, PRICE_PER_ITEM)) - .andThenAggregate(portfolioIdentifier.toString()).published(new CashReservedEvent( + .andThenAggregate(portfolioIdentifier.toString()).published(new CashReservedEvent( portfolioIdentifier, transactionIdentifier, TOTAL_ITEMS * PRICE_PER_ITEM)) - .andThenAggregate(transactionIdentifier.toString()).published(new BuyTransactionConfirmedEvent(transactionIdentifier)) - .andThenAggregate(orderbookIdentifier.toString()).published(new TradeExecutedEvent(orderbookIdentifier, - 50, - 99, - buyOrderIdentifier, - sellOrderIdentifier, + .andThenAggregate(transactionIdentifier.toString()).published(new BuyTransactionConfirmedEvent( + transactionIdentifier)) + .andThenAggregate(orderbookIdentifier.toString()).published(new TradeExecutedEvent(orderbookIdentifier, + 50, + 99, + buyOrderIdentifier, + sellOrderIdentifier, + transactionIdentifier, + sellTransactionIdentifier)) + .whenAggregate(transactionIdentifier.toString()).publishes(new BuyTransactionPartiallyExecutedEvent( transactionIdentifier, - sellTransactionIdentifier)) - .whenAggregate(transactionIdentifier.toString()).publishes(new BuyTransactionPartiallyExecutedEvent(transactionIdentifier, 50, 50, 99)) - .expectActiveSagas(1) - .expectDispatchedCommandsMatching( - exactSequenceOf( - ConfirmMoneyReservationFromPortfolionCommandMatcher.newInstance(portfolioIdentifier, 50 * 99), - AddItemsToPortfolioCommandMatcher.newInstance(portfolioIdentifier, orderbookIdentifier, 50))); + 50, + 50, + 99)) + .expectActiveSagas(1) + .expectDispatchedCommandsMatching( + exactSequenceOf( + ConfirmMoneyReservationFromPortfolionCommandMatcher + .newInstance(portfolioIdentifier, 50 * 99), + AddItemsToPortfolioCommandMatcher + .newInstance(portfolioIdentifier, orderbookIdentifier, 50))); } } diff --git a/orders/src/test/java/org/axonframework/samples/trader/orders/command/PortfolioCommandHandlerTest.java b/orders/src/test/java/org/axonframework/samples/trader/orders/command/PortfolioCommandHandlerTest.java index c40f4a9..8745772 100644 --- a/orders/src/test/java/org/axonframework/samples/trader/orders/command/PortfolioCommandHandlerTest.java +++ b/orders/src/test/java/org/axonframework/samples/trader/orders/command/PortfolioCommandHandlerTest.java @@ -16,11 +16,11 @@ package org.axonframework.samples.trader.orders.command; -import org.axonframework.samples.trader.api.orders.trades.OrderBookId; -import org.axonframework.samples.trader.api.orders.trades.PortfolioId; +import org.axonframework.samples.trader.api.orders.OrderBookId; import org.axonframework.samples.trader.api.orders.transaction.TransactionId; import org.axonframework.samples.trader.api.portfolio.CreatePortfolioCommand; import org.axonframework.samples.trader.api.portfolio.PortfolioCreatedEvent; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.axonframework.samples.trader.api.portfolio.cash.*; import org.axonframework.samples.trader.api.portfolio.stock.*; import org.axonframework.samples.trader.api.users.UserId; @@ -28,9 +28,6 @@ import org.junit.Before; import org.junit.Test; -/** - * @author Jettro Coenradie - */ public class PortfolioCommandHandlerTest { private AggregateTestFixture fixture; @@ -56,128 +53,139 @@ public void testCreatePortfolio() { CreatePortfolioCommand command = new CreatePortfolioCommand(portfolioIdentifier, userIdentifier); fixture.given() - .when(command) - .expectEvents(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier)); + .when(command) + .expectEvents(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier)); } /* Items related test methods */ @Test public void testAddItemsToPortfolio() { AddItemsToPortfolioCommand command = new AddItemsToPortfolioCommand(portfolioIdentifier, - orderBookIdentifier, - 100); + orderBookIdentifier, + 100); fixture.given(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier)) - .when(command) - .expectEvents(new ItemsAddedToPortfolioEvent(portfolioIdentifier, orderBookIdentifier, 100)); + .when(command) + .expectEvents(new ItemsAddedToPortfolioEvent(portfolioIdentifier, orderBookIdentifier, 100)); } @Test public void testReserveItems_noItemsAvailable() { ReserveItemsCommand command = new ReserveItemsCommand(portfolioIdentifier, - orderBookIdentifier, - transactionIdentifier, - 200); + orderBookIdentifier, + transactionIdentifier, + 200); fixture.given(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier)) - .when(command) - .expectEvents(new ItemToReserveNotAvailableInPortfolioEvent(portfolioIdentifier, orderBookIdentifier, transactionIdentifier)); + .when(command) + .expectEvents(new ItemToReserveNotAvailableInPortfolioEvent(portfolioIdentifier, + orderBookIdentifier, + transactionIdentifier)); } @Test public void testReserveItems_notEnoughItemsAvailable() { ReserveItemsCommand command = new ReserveItemsCommand(portfolioIdentifier, - orderBookIdentifier, - transactionIdentifier, - 200); + orderBookIdentifier, + transactionIdentifier, + 200); fixture.given(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier), - new ItemsAddedToPortfolioEvent(portfolioIdentifier, orderBookIdentifier, 100)) - .when(command) - .expectEvents(new NotEnoughItemsAvailableToReserveInPortfolioEvent(portfolioIdentifier, - orderBookIdentifier, - transactionIdentifier, - 100, - 200)); + new ItemsAddedToPortfolioEvent(portfolioIdentifier, orderBookIdentifier, 100)) + .when(command) + .expectEvents(new NotEnoughItemsAvailableToReserveInPortfolioEvent(portfolioIdentifier, + orderBookIdentifier, + transactionIdentifier, + 100, + 200)); } @Test public void testReserveItems_notEnoughItemsAvailableAfterResevation() { ReserveItemsCommand command = new ReserveItemsCommand(portfolioIdentifier, - orderBookIdentifier, - transactionIdentifier, - 100); + orderBookIdentifier, + transactionIdentifier, + 100); fixture.given(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier), - new ItemsAddedToPortfolioEvent(portfolioIdentifier, orderBookIdentifier, 100), - new ItemsReservedEvent(portfolioIdentifier, orderBookIdentifier, transactionIdentifier, 50), - new ItemReservationConfirmedForPortfolioEvent(portfolioIdentifier, orderBookIdentifier, transactionIdentifier, 50)) - .when(command) - .expectEvents(new NotEnoughItemsAvailableToReserveInPortfolioEvent(portfolioIdentifier, - orderBookIdentifier, - transactionIdentifier, - 50, - 100)); + new ItemsAddedToPortfolioEvent(portfolioIdentifier, orderBookIdentifier, 100), + new ItemsReservedEvent(portfolioIdentifier, orderBookIdentifier, transactionIdentifier, 50), + new ItemReservationConfirmedForPortfolioEvent(portfolioIdentifier, + orderBookIdentifier, + transactionIdentifier, + 50)) + .when(command) + .expectEvents(new NotEnoughItemsAvailableToReserveInPortfolioEvent(portfolioIdentifier, + orderBookIdentifier, + transactionIdentifier, + 50, + 100)); } @Test public void testReserveItems_notEnoughItemsAvailableAfterResevationConfirmation() { ReserveItemsCommand command = new ReserveItemsCommand(portfolioIdentifier, - orderBookIdentifier, - transactionIdentifier, - 75); + orderBookIdentifier, + transactionIdentifier, + 75); fixture.given(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier), - new ItemsAddedToPortfolioEvent(portfolioIdentifier, orderBookIdentifier, 100), - new ItemsReservedEvent(portfolioIdentifier, orderBookIdentifier, transactionIdentifier, 50), - new ItemReservationConfirmedForPortfolioEvent(portfolioIdentifier, orderBookIdentifier, transactionIdentifier, 50)) - .when(command) - .expectEvents(new NotEnoughItemsAvailableToReserveInPortfolioEvent(portfolioIdentifier, - orderBookIdentifier, - transactionIdentifier, - 50, - 75)); + new ItemsAddedToPortfolioEvent(portfolioIdentifier, orderBookIdentifier, 100), + new ItemsReservedEvent(portfolioIdentifier, orderBookIdentifier, transactionIdentifier, 50), + new ItemReservationConfirmedForPortfolioEvent(portfolioIdentifier, + orderBookIdentifier, + transactionIdentifier, + 50)) + .when(command) + .expectEvents(new NotEnoughItemsAvailableToReserveInPortfolioEvent(portfolioIdentifier, + orderBookIdentifier, + transactionIdentifier, + 50, + 75)); } @Test public void testReserveItems() { ReserveItemsCommand command = new ReserveItemsCommand(portfolioIdentifier, - orderBookIdentifier, - transactionIdentifier, - 200); + orderBookIdentifier, + transactionIdentifier, + 200); fixture.given(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier), - new ItemsAddedToPortfolioEvent(portfolioIdentifier, orderBookIdentifier, 400)) - .when(command) - .expectEvents(new ItemsReservedEvent(portfolioIdentifier, orderBookIdentifier, transactionIdentifier, 200)); + new ItemsAddedToPortfolioEvent(portfolioIdentifier, orderBookIdentifier, 400)) + .when(command) + .expectEvents(new ItemsReservedEvent(portfolioIdentifier, + orderBookIdentifier, + transactionIdentifier, + 200)); } @Test public void testConfirmationOfReservation() { ConfirmItemReservationForPortfolioCommand command = new ConfirmItemReservationForPortfolioCommand(portfolioIdentifier, - orderBookIdentifier, - transactionIdentifier, - 100); + orderBookIdentifier, + transactionIdentifier, + 100); fixture.given(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier), - new ItemsAddedToPortfolioEvent(portfolioIdentifier, orderBookIdentifier, 400), - new ItemsReservedEvent(portfolioIdentifier, orderBookIdentifier, transactionIdentifier, 100)) - .when(command) - .expectEvents(new ItemReservationConfirmedForPortfolioEvent(portfolioIdentifier, - orderBookIdentifier, - transactionIdentifier, - 100)); + new ItemsAddedToPortfolioEvent(portfolioIdentifier, orderBookIdentifier, 400), + new ItemsReservedEvent(portfolioIdentifier, orderBookIdentifier, transactionIdentifier, 100)) + .when(command) + .expectEvents(new ItemReservationConfirmedForPortfolioEvent(portfolioIdentifier, + orderBookIdentifier, + transactionIdentifier, + 100)); } @Test public void testCancellationOfReservation() { CancelItemReservationForPortfolioCommand command = new CancelItemReservationForPortfolioCommand(portfolioIdentifier, - orderBookIdentifier, - transactionIdentifier, - 100); + orderBookIdentifier, + transactionIdentifier, + 100); fixture.given(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier), - new ItemsAddedToPortfolioEvent(portfolioIdentifier, orderBookIdentifier, 400), - new ItemsReservedEvent(portfolioIdentifier, orderBookIdentifier, transactionIdentifier, 100)) - .when(command) - .expectEvents(new ItemReservationCancelledForPortfolioEvent(portfolioIdentifier, - orderBookIdentifier, - transactionIdentifier, - 100)); + new ItemsAddedToPortfolioEvent(portfolioIdentifier, orderBookIdentifier, 400), + new ItemsReservedEvent(portfolioIdentifier, orderBookIdentifier, transactionIdentifier, 100)) + .when(command) + .expectEvents(new ItemReservationCancelledForPortfolioEvent(portfolioIdentifier, + orderBookIdentifier, + transactionIdentifier, + 100)); } /* Money related test methods */ @@ -185,44 +193,48 @@ public void testCancellationOfReservation() { public void testDepositingMoneyToThePortfolio() { DepositCashCommand command = new DepositCashCommand(portfolioIdentifier, 2000l); fixture.given(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier)) - .when(command) - .expectEvents(new CashDepositedEvent(portfolioIdentifier, 2000l)); + .when(command) + .expectEvents(new CashDepositedEvent(portfolioIdentifier, 2000l)); } @Test public void testWithdrawingMoneyFromPortfolio() { WithdrawCashCommand command = new WithdrawCashCommand(portfolioIdentifier, 300l); - fixture.given(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier), new CashDepositedEvent(portfolioIdentifier, 400)) - .when(command) - .expectEvents(new CashWithdrawnEvent(portfolioIdentifier, 300l)); + fixture.given(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier), + new CashDepositedEvent(portfolioIdentifier, 400)) + .when(command) + .expectEvents(new CashWithdrawnEvent(portfolioIdentifier, 300l)); } @Test public void testWithdrawingMoneyFromPortfolio_withoutEnoughMoney() { WithdrawCashCommand command = new WithdrawCashCommand(portfolioIdentifier, 300l); - fixture.given(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier), new CashDepositedEvent(portfolioIdentifier, 200)) - .when(command) - .expectEvents(new CashWithdrawnEvent(portfolioIdentifier, 300l)); + fixture.given(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier), + new CashDepositedEvent(portfolioIdentifier, 200)) + .when(command) + .expectEvents(new CashWithdrawnEvent(portfolioIdentifier, 300l)); } @Test public void testMakingMoneyReservation() { ReserveCashCommand command = new ReserveCashCommand(portfolioIdentifier, - transactionIdentifier, - 300l); - fixture.given(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier), new CashDepositedEvent(portfolioIdentifier, 400)) - .when(command) - .expectEvents(new CashReservedEvent(portfolioIdentifier, transactionIdentifier, 300l)); + transactionIdentifier, + 300l); + fixture.given(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier), + new CashDepositedEvent(portfolioIdentifier, 400)) + .when(command) + .expectEvents(new CashReservedEvent(portfolioIdentifier, transactionIdentifier, 300l)); } @Test public void testMakingMoneyReservation_withoutEnoughMoney() { ReserveCashCommand command = new ReserveCashCommand(portfolioIdentifier, - transactionIdentifier, - 600l); - fixture.given(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier), new CashDepositedEvent(portfolioIdentifier, 400)) - .when(command) - .expectEvents(new CashReservationRejectedEvent(portfolioIdentifier, transactionIdentifier, 600)); + transactionIdentifier, + 600l); + fixture.given(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier), + new CashDepositedEvent(portfolioIdentifier, 400)) + .when(command) + .expectEvents(new CashReservationRejectedEvent(portfolioIdentifier, transactionIdentifier, 600)); } @Test @@ -231,9 +243,10 @@ public void testCancelMoneyReservation() { portfolioIdentifier, transactionIdentifier, 200l); - fixture.given(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier), new CashDepositedEvent(portfolioIdentifier, 400)) - .when(command) - .expectEvents(new CashReservationCancelledEvent(portfolioIdentifier, transactionIdentifier, 200l)); + fixture.given(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier), + new CashDepositedEvent(portfolioIdentifier, 400)) + .when(command) + .expectEvents(new CashReservationCancelledEvent(portfolioIdentifier, transactionIdentifier, 200l)); } @Test @@ -242,8 +255,9 @@ public void testConfirmMoneyReservation() { portfolioIdentifier, transactionIdentifier, 200l); - fixture.given(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier), new CashDepositedEvent(portfolioIdentifier, 400)) - .when(command) - .expectEvents(new CashReservationConfirmedEvent(portfolioIdentifier, transactionIdentifier, 200l)); + fixture.given(new PortfolioCreatedEvent(portfolioIdentifier, userIdentifier), + new CashDepositedEvent(portfolioIdentifier, 400)) + .when(command) + .expectEvents(new CashReservationConfirmedEvent(portfolioIdentifier, transactionIdentifier, 200l)); } } diff --git a/orders/src/test/java/org/axonframework/samples/trader/orders/command/SellTradeManagerSagaTest.java b/orders/src/test/java/org/axonframework/samples/trader/orders/command/SellTradeManagerSagaTest.java index ac98ccc..8e7dbb3 100644 --- a/orders/src/test/java/org/axonframework/samples/trader/orders/command/SellTradeManagerSagaTest.java +++ b/orders/src/test/java/org/axonframework/samples/trader/orders/command/SellTradeManagerSagaTest.java @@ -16,8 +16,11 @@ package org.axonframework.samples.trader.orders.command; +import org.axonframework.samples.trader.api.orders.OrderBookId; +import org.axonframework.samples.trader.api.orders.OrderId; import org.axonframework.samples.trader.api.orders.trades.*; import org.axonframework.samples.trader.api.orders.transaction.*; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.axonframework.samples.trader.api.portfolio.stock.ItemsReservedEvent; import org.axonframework.samples.trader.api.portfolio.stock.NotEnoughItemsAvailableToReserveInPortfolioEvent; import org.axonframework.samples.trader.orders.command.matchers.*; @@ -28,9 +31,6 @@ import static org.axonframework.test.matchers.Matchers.andNoMore; import static org.axonframework.test.matchers.Matchers.exactSequenceOf; -/** - * @author Jettro Coenradie - */ public class SellTradeManagerSagaTest { private TransactionId transactionIdentifier = new TransactionId(); diff --git a/orders/src/test/java/org/axonframework/samples/trader/orders/command/TransactionCommandHandlingTest.java b/orders/src/test/java/org/axonframework/samples/trader/orders/command/TransactionCommandHandlingTest.java index 36f0bc8..77aa40a 100644 --- a/orders/src/test/java/org/axonframework/samples/trader/orders/command/TransactionCommandHandlingTest.java +++ b/orders/src/test/java/org/axonframework/samples/trader/orders/command/TransactionCommandHandlingTest.java @@ -16,17 +16,13 @@ package org.axonframework.samples.trader.orders.command; -import org.axonframework.samples.trader.api.orders.trades.OrderBookId; -import org.axonframework.samples.trader.api.orders.trades.PortfolioId; -import org.axonframework.samples.trader.api.orders.transaction.TransactionId; +import org.axonframework.samples.trader.api.orders.OrderBookId; import org.axonframework.samples.trader.api.orders.transaction.*; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.axonframework.test.aggregate.AggregateTestFixture; import org.junit.Before; import org.junit.Test; -/** - * @author Jettro Coenradie - */ public class TransactionCommandHandlingTest { private AggregateTestFixture fixture; @@ -44,72 +40,80 @@ public void setUp() { @Test public void testStartBuyTransaction() { - StartBuyTransactionCommand command = new StartBuyTransactionCommand(transactionId, orderBook, portfolio, 200, 20); + StartBuyTransactionCommand command = new StartBuyTransactionCommand(transactionId, + orderBook, + portfolio, + 200, + 20); fixture.given() - .when(command) - .expectEvents(new BuyTransactionStartedEvent(transactionId, orderBook, portfolio, 200, 20)); + .when(command) + .expectEvents(new BuyTransactionStartedEvent(transactionId, orderBook, portfolio, 200, 20)); } @Test public void testStartSellTransaction() { - StartSellTransactionCommand command = new StartSellTransactionCommand(transactionId, orderBook, portfolio, 200, 20); + StartSellTransactionCommand command = new StartSellTransactionCommand(transactionId, + orderBook, + portfolio, + 200, + 20); fixture.given() - .when(command) - .expectEvents(new SellTransactionStartedEvent(transactionId, orderBook, portfolio, 200, 20)); + .when(command) + .expectEvents(new SellTransactionStartedEvent(transactionId, orderBook, portfolio, 200, 20)); } @Test public void testConfirmTransaction() { ConfirmTransactionCommand command = new ConfirmTransactionCommand(transactionId); fixture.given(new BuyTransactionStartedEvent(transactionId, orderBook, portfolio, 200, 20)) - .when(command) - .expectEvents(new BuyTransactionConfirmedEvent(transactionId)); + .when(command) + .expectEvents(new BuyTransactionConfirmedEvent(transactionId)); } @Test public void testCancelTransaction() { CancelTransactionCommand command = new CancelTransactionCommand(transactionId); fixture.given(new BuyTransactionStartedEvent(transactionId, orderBook, portfolio, 200, 20)) - .when(command) - .expectEvents(new BuyTransactionCancelledEvent(transactionId, 200, 0)); + .when(command) + .expectEvents(new BuyTransactionCancelledEvent(transactionId, 200, 0)); } @Test public void testCancelTransaction_partiallyExecuted() { CancelTransactionCommand command = new CancelTransactionCommand(transactionId); fixture.given(new BuyTransactionStartedEvent(transactionId, orderBook, portfolio, 200, 20), - new BuyTransactionPartiallyExecutedEvent(transactionId, 100, 100, 20)) - .when(command) - .expectEvents(new BuyTransactionCancelledEvent(transactionId, 200, 100)); + new BuyTransactionPartiallyExecutedEvent(transactionId, 100, 100, 20)) + .when(command) + .expectEvents(new BuyTransactionCancelledEvent(transactionId, 200, 100)); } @Test public void testExecuteTransaction() { ExecutedTransactionCommand command = new ExecutedTransactionCommand(transactionId, 200, 20); fixture.given(new BuyTransactionStartedEvent(transactionId, orderBook, portfolio, 200, 20), - new BuyTransactionConfirmedEvent(transactionId)) - .when(command) - .expectEvents(new BuyTransactionExecutedEvent(transactionId, 200, 20)); + new BuyTransactionConfirmedEvent(transactionId)) + .when(command) + .expectEvents(new BuyTransactionExecutedEvent(transactionId, 200, 20)); } @Test public void testExecuteTransaction_partiallyExecuted() { ExecutedTransactionCommand command = new ExecutedTransactionCommand(transactionId, 50, 20); fixture.given(new BuyTransactionStartedEvent(transactionId, orderBook, portfolio, 200, 20), - new BuyTransactionConfirmedEvent(transactionId)) - .when(command) - .expectEvents(new BuyTransactionPartiallyExecutedEvent(transactionId, 50, 50, 20)); + new BuyTransactionConfirmedEvent(transactionId)) + .when(command) + .expectEvents(new BuyTransactionPartiallyExecutedEvent(transactionId, 50, 50, 20)); } @Test public void testExecuteTransaction_completeAfterPartiallyExecuted() { ExecutedTransactionCommand command = new ExecutedTransactionCommand(transactionId, 150, 20); fixture.given(new BuyTransactionStartedEvent(transactionId, orderBook, portfolio, 200, 20), - new BuyTransactionConfirmedEvent(transactionId), - new BuyTransactionPartiallyExecutedEvent(transactionId, 50, 50, 20) + new BuyTransactionConfirmedEvent(transactionId), + new BuyTransactionPartiallyExecutedEvent(transactionId, 50, 50, 20) ) - .when(command) - .expectEvents(new BuyTransactionExecutedEvent(transactionId, 150, 20)); + .when(command) + .expectEvents(new BuyTransactionExecutedEvent(transactionId, 150, 20)); // TODO moeten we nu ook nog een partially executed event gooien? } } diff --git a/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/AddItemsToPortfolioCommandMatcher.java b/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/AddItemsToPortfolioCommandMatcher.java index c9d9540..5e9cf2c 100644 --- a/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/AddItemsToPortfolioCommandMatcher.java +++ b/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/AddItemsToPortfolioCommandMatcher.java @@ -16,15 +16,12 @@ package org.axonframework.samples.trader.orders.command.matchers; -import org.axonframework.samples.trader.api.orders.trades.OrderBookId; -import org.axonframework.samples.trader.api.orders.trades.PortfolioId; +import org.axonframework.samples.trader.api.orders.OrderBookId; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.axonframework.samples.trader.api.portfolio.stock.AddItemsToPortfolioCommand; import org.hamcrest.Description; import org.hamcrest.Matcher; -/** - * @author Jettro Coenradie - */ public class AddItemsToPortfolioCommandMatcher extends BaseCommandMatcher { private OrderBookId orderBookIdentifier; @@ -42,6 +39,7 @@ public static Matcher newInstance(PortfolioId portfolioIdentifier, OrderBookId orderBookIdentifier, long amountOfItemsToAdd) { return new AddItemsToPortfolioCommandMatcher(portfolioIdentifier, orderBookIdentifier, amountOfItemsToAdd); } + @Override protected boolean doMatches(AddItemsToPortfolioCommand command) { return command.getOrderBookId().equals(orderBookIdentifier) @@ -52,11 +50,11 @@ protected boolean doMatches(AddItemsToPortfolioCommand command) { @Override public void describeTo(Description description) { description.appendText("AddItemsToPortfolioCommand with amountOfItemsToAdd [") - .appendValue(amountOfItemsToAdd) - .appendText("] for OrderBook with identifier [") - .appendValue(orderBookIdentifier) - .appendText("] and for Portfolio with identifier [") - .appendValue(portfolioIdentifier) - .appendText("]"); + .appendValue(amountOfItemsToAdd) + .appendText("] for OrderBook with identifier [") + .appendValue(orderBookIdentifier) + .appendText("] and for Portfolio with identifier [") + .appendValue(portfolioIdentifier) + .appendText("]"); } } diff --git a/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/CancelItemReservationForPortfolioCommandMatcher.java b/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/CancelItemReservationForPortfolioCommandMatcher.java index 9ce3d6e..7997701 100644 --- a/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/CancelItemReservationForPortfolioCommandMatcher.java +++ b/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/CancelItemReservationForPortfolioCommandMatcher.java @@ -16,15 +16,12 @@ package org.axonframework.samples.trader.orders.command.matchers; -import org.axonframework.samples.trader.api.orders.trades.OrderBookId; -import org.axonframework.samples.trader.api.orders.trades.PortfolioId; +import org.axonframework.samples.trader.api.orders.OrderBookId; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.axonframework.samples.trader.api.portfolio.stock.CancelItemReservationForPortfolioCommand; import org.hamcrest.Description; import org.hamcrest.Matcher; -/** - * @author Jettro Coenradie - */ public class CancelItemReservationForPortfolioCommandMatcher extends BaseCommandMatcher { @@ -40,26 +37,28 @@ private CancelItemReservationForPortfolioCommandMatcher(OrderBookId orderBookIde this.orderBookIdentifier = orderBookIdentifier; } - public static Matcher newInstance(OrderBookId orderbookIdentifier, PortfolioId portfolioIdentifier, int amountOfItemsToCancel) { - return new CancelItemReservationForPortfolioCommandMatcher(orderbookIdentifier, portfolioIdentifier, amountOfItemsToCancel); + public static Matcher newInstance(OrderBookId orderbookIdentifier, PortfolioId portfolioIdentifier, + int amountOfItemsToCancel) { + return new CancelItemReservationForPortfolioCommandMatcher(orderbookIdentifier, + portfolioIdentifier, + amountOfItemsToCancel); } @Override protected boolean doMatches(CancelItemReservationForPortfolioCommand command) { return command.getOrderBookId().equals(orderBookIdentifier) - && command.getPortfolioIdentifier().equals(portfolioIdentifier) + && command.getPortfolioId().equals(portfolioIdentifier) && command.getAmountOfItemsToCancel() == amountOfItemsToCancel; } @Override public void describeTo(Description description) { description.appendText("CancelItemReservationForPortfolioCommand with amountOfItemsToCancel [") - .appendValue(amountOfItemsToCancel) - .appendText("] for Portfolio with identifier [") - .appendValue(portfolioIdentifier) - .appendText("] and for OrderBook with identifier [") - .appendValue(orderBookIdentifier) - .appendText("]"); + .appendValue(amountOfItemsToCancel) + .appendText("] for Portfolio with identifier [") + .appendValue(portfolioIdentifier) + .appendText("] and for OrderBook with identifier [") + .appendValue(orderBookIdentifier) + .appendText("]"); } - } diff --git a/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/CancelMoneyReservationFromPortfolioCommandMatcher.java b/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/CancelMoneyReservationFromPortfolioCommandMatcher.java index a158e17..2521de8 100644 --- a/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/CancelMoneyReservationFromPortfolioCommandMatcher.java +++ b/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/CancelMoneyReservationFromPortfolioCommandMatcher.java @@ -16,14 +16,11 @@ package org.axonframework.samples.trader.orders.command.matchers; -import org.axonframework.samples.trader.api.orders.trades.PortfolioId; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.axonframework.samples.trader.api.portfolio.cash.CancelCashReservationCommand; import org.hamcrest.Description; import org.hamcrest.Matcher; -/** - * @author Jettro Coenradie - */ public class CancelMoneyReservationFromPortfolioCommandMatcher extends BaseCommandMatcher { @@ -49,10 +46,9 @@ protected boolean doMatches(CancelCashReservationCommand command) { @Override public void describeTo(Description description) { description.appendText("CancelCashReservationCommand with amountOfMoneyToCancel [") - .appendValue(amountOfMoneyToCancel) - .appendText("] for Portfolio with identifier [") - .appendValue(portfolioIdentifier) - .appendText("]"); + .appendValue(amountOfMoneyToCancel) + .appendText("] for Portfolio with identifier [") + .appendValue(portfolioIdentifier) + .appendText("]"); } - } diff --git a/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/ConfirmItemReservationForPortfolioCommandMatcher.java b/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/ConfirmItemReservationForPortfolioCommandMatcher.java index c39b387..f325f65 100644 --- a/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/ConfirmItemReservationForPortfolioCommandMatcher.java +++ b/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/ConfirmItemReservationForPortfolioCommandMatcher.java @@ -16,15 +16,12 @@ package org.axonframework.samples.trader.orders.command.matchers; -import org.axonframework.samples.trader.api.orders.trades.OrderBookId; -import org.axonframework.samples.trader.api.orders.trades.PortfolioId; +import org.axonframework.samples.trader.api.orders.OrderBookId; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.axonframework.samples.trader.api.portfolio.stock.ConfirmItemReservationForPortfolioCommand; import org.hamcrest.Description; import org.hamcrest.Matcher; -/** - * @author Jettro Coenradie - */ public class ConfirmItemReservationForPortfolioCommandMatcher extends BaseCommandMatcher { @@ -39,25 +36,28 @@ public ConfirmItemReservationForPortfolioCommandMatcher( this.amountOfConfirmedItems = amountOfConfirmedItems; } - public static Matcher newInstance(OrderBookId orderbookIdentifier, PortfolioId portfolioIdentifier, int amountOfConfirmedItems) { - return new ConfirmItemReservationForPortfolioCommandMatcher(orderbookIdentifier, portfolioIdentifier, amountOfConfirmedItems); + public static Matcher newInstance(OrderBookId orderbookIdentifier, PortfolioId portfolioIdentifier, + int amountOfConfirmedItems) { + return new ConfirmItemReservationForPortfolioCommandMatcher(orderbookIdentifier, + portfolioIdentifier, + amountOfConfirmedItems); } @Override protected boolean doMatches(ConfirmItemReservationForPortfolioCommand command) { - return command.getOrderBookIdentifier().equals(orderbookIdentifier) - && command.getPortfolioIdentifier().equals(portfolioIdentifier) + return command.getOrderBookId().equals(orderbookIdentifier) + && command.getPortfolioId().equals(portfolioIdentifier) && amountOfConfirmedItems == command.getAmountOfItemsToConfirm(); } @Override public void describeTo(Description description) { description.appendText("ConfirmItemReservationForPortfolioCommand with amountOfConfirmedItems [") - .appendValue(amountOfConfirmedItems) - .appendText("] for OrderBook with identifier [") - .appendValue(orderbookIdentifier) - .appendText("] and for Portfolio with identifier [") - .appendValue(portfolioIdentifier) - .appendText("]"); + .appendValue(amountOfConfirmedItems) + .appendText("] for OrderBook with identifier [") + .appendValue(orderbookIdentifier) + .appendText("] and for Portfolio with identifier [") + .appendValue(portfolioIdentifier) + .appendText("]"); } } diff --git a/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/ConfirmMoneyReservationFromPortfolionCommandMatcher.java b/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/ConfirmMoneyReservationFromPortfolionCommandMatcher.java index 1d16a57..ba50b8b 100644 --- a/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/ConfirmMoneyReservationFromPortfolionCommandMatcher.java +++ b/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/ConfirmMoneyReservationFromPortfolionCommandMatcher.java @@ -16,21 +16,19 @@ package org.axonframework.samples.trader.orders.command.matchers; -import org.axonframework.samples.trader.api.orders.trades.PortfolioId; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.axonframework.samples.trader.api.portfolio.cash.ConfirmCashReservationCommand; import org.hamcrest.Description; import org.hamcrest.Matcher; -/** - * @author Jettro Coenradie - */ public class ConfirmMoneyReservationFromPortfolionCommandMatcher extends BaseCommandMatcher { private PortfolioId portfolioIdentifier; private long amountOfMoneyToconfirm; - private ConfirmMoneyReservationFromPortfolionCommandMatcher(PortfolioId portfolioIdentifier, long amountOfMoneyToConfirm) { + private ConfirmMoneyReservationFromPortfolionCommandMatcher(PortfolioId portfolioIdentifier, + long amountOfMoneyToConfirm) { this.portfolioIdentifier = portfolioIdentifier; this.amountOfMoneyToconfirm = amountOfMoneyToConfirm; } @@ -38,6 +36,7 @@ private ConfirmMoneyReservationFromPortfolionCommandMatcher(PortfolioId portfoli public static Matcher newInstance(PortfolioId portfolioIdentifier, long amountOfMoneyToConfirm) { return new ConfirmMoneyReservationFromPortfolionCommandMatcher(portfolioIdentifier, amountOfMoneyToConfirm); } + @Override protected boolean doMatches(ConfirmCashReservationCommand command) { return command.getPortfolioId().equals(portfolioIdentifier) @@ -47,9 +46,9 @@ protected boolean doMatches(ConfirmCashReservationCommand command) { @Override public void describeTo(Description description) { description.appendText("ConfirmCashReservationCommand with amountOfMoneyToConfirm [") - .appendValue(amountOfMoneyToconfirm) - .appendText("] for Portfolio with identifier [") - .appendValue(portfolioIdentifier) - .appendText("]"); + .appendValue(amountOfMoneyToconfirm) + .appendText("] for Portfolio with identifier [") + .appendValue(portfolioIdentifier) + .appendText("]"); } } diff --git a/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/CreateBuyOrderCommandMatcher.java b/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/CreateBuyOrderCommandMatcher.java index 4c1fc37..def20b2 100644 --- a/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/CreateBuyOrderCommandMatcher.java +++ b/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/CreateBuyOrderCommandMatcher.java @@ -16,15 +16,12 @@ package org.axonframework.samples.trader.orders.command.matchers; +import org.axonframework.samples.trader.api.orders.OrderBookId; import org.axonframework.samples.trader.api.orders.trades.CreateBuyOrderCommand; -import org.axonframework.samples.trader.api.orders.trades.OrderBookId; -import org.axonframework.samples.trader.api.orders.trades.PortfolioId; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.hamcrest.Description; import org.hamcrest.Matcher; -/** - * @author Jettro Coenradie - */ public class CreateBuyOrderCommandMatcher extends BaseCommandMatcher { private OrderBookId orderbookIdentifier; @@ -32,14 +29,16 @@ public class CreateBuyOrderCommandMatcher extends BaseCommandMatcher { private OrderBookId orderbookIdentifier; diff --git a/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/DepositMoneyToPortfolioCommandMatcher.java b/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/DepositMoneyToPortfolioCommandMatcher.java index 9fcc0fe..5b35b4b 100644 --- a/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/DepositMoneyToPortfolioCommandMatcher.java +++ b/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/DepositMoneyToPortfolioCommandMatcher.java @@ -16,14 +16,11 @@ package org.axonframework.samples.trader.orders.command.matchers; -import org.axonframework.samples.trader.api.orders.trades.PortfolioId; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.axonframework.samples.trader.api.portfolio.cash.DepositCashCommand; import org.hamcrest.Description; import org.hamcrest.Matcher; -/** - * @author Jettro Coenradie - */ public class DepositMoneyToPortfolioCommandMatcher extends BaseCommandMatcher { private long moneyToAddInCents; @@ -37,6 +34,7 @@ private DepositMoneyToPortfolioCommandMatcher(PortfolioId portfolioIdentifier, l public static Matcher newInstance(PortfolioId portfolioIdentifier, long moneyToAddInCents) { return new DepositMoneyToPortfolioCommandMatcher(portfolioIdentifier, moneyToAddInCents); } + @Override protected boolean doMatches(DepositCashCommand command) { return moneyToAddInCents == command.getMoneyToAddInCents() @@ -46,9 +44,9 @@ protected boolean doMatches(DepositCashCommand command) { @Override public void describeTo(Description description) { description.appendText("DepositCashCommand with moneyToAddInCents [") - .appendValue(moneyToAddInCents) - .appendText("] for Portfolio with identifier [") - .appendValue(portfolioIdentifier) - .appendText("]"); + .appendValue(moneyToAddInCents) + .appendText("] for Portfolio with identifier [") + .appendValue(portfolioIdentifier) + .appendText("]"); } } diff --git a/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/ReserveMoneyFromPortfolioCommandMatcher.java b/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/ReserveMoneyFromPortfolioCommandMatcher.java index 3153b74..d2cd56e 100644 --- a/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/ReserveMoneyFromPortfolioCommandMatcher.java +++ b/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/ReserveMoneyFromPortfolioCommandMatcher.java @@ -16,14 +16,11 @@ package org.axonframework.samples.trader.orders.command.matchers; -import org.axonframework.samples.trader.api.orders.trades.PortfolioId; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.axonframework.samples.trader.api.portfolio.cash.ReserveCashCommand; import org.hamcrest.Description; import org.hamcrest.Matcher; -/** - * @author Jettro Coenradie - */ public class ReserveMoneyFromPortfolioCommandMatcher extends BaseCommandMatcher { private PortfolioId portfolioIdentifier; @@ -47,9 +44,9 @@ protected boolean doMatches(ReserveCashCommand command) { @Override public void describeTo(Description description) { description.appendText("ReserveCashCommand with amountOfMoneyToReserve [") - .appendValue(amountOfMoneyToReserve) - .appendText("] for Portfolio with identifier [") - .appendValue(portfolioIdentifier) - .appendText("]"); + .appendValue(amountOfMoneyToReserve) + .appendText("] for Portfolio with identifier [") + .appendValue(portfolioIdentifier) + .appendText("]"); } } diff --git a/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/ReservedItemsCommandMatcher.java b/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/ReservedItemsCommandMatcher.java index a5ff740..a71a50c 100644 --- a/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/ReservedItemsCommandMatcher.java +++ b/orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/ReservedItemsCommandMatcher.java @@ -16,15 +16,12 @@ package org.axonframework.samples.trader.orders.command.matchers; -import org.axonframework.samples.trader.api.orders.trades.OrderBookId; -import org.axonframework.samples.trader.api.orders.trades.PortfolioId; +import org.axonframework.samples.trader.api.orders.OrderBookId; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.axonframework.samples.trader.api.portfolio.stock.ReserveItemsCommand; import org.hamcrest.Description; import org.hamcrest.Matcher; -/** - * @author Jettro Coenradie - */ public class ReservedItemsCommandMatcher extends BaseCommandMatcher { private OrderBookId orderbookIdentifier; @@ -38,7 +35,8 @@ private ReservedItemsCommandMatcher(OrderBookId orderbookIdentifier, PortfolioId this.amountOfReservedItems = amountOfReservedItems; } - public static Matcher newInstance(OrderBookId orderbookIdentifier, PortfolioId portfolioIdentifier, int amountOfReservedItems) { + public static Matcher newInstance(OrderBookId orderbookIdentifier, PortfolioId portfolioIdentifier, + int amountOfReservedItems) { return new ReservedItemsCommandMatcher(orderbookIdentifier, portfolioIdentifier, amountOfReservedItems); } @@ -52,11 +50,11 @@ protected boolean doMatches(ReserveItemsCommand command) { @Override public void describeTo(Description description) { description.appendText("ReserveItemsCommand with amountOfReservedItems [") - .appendValue(amountOfReservedItems) - .appendText("] for OrderBook with identifier [") - .appendValue(orderbookIdentifier) - .appendText("] and for Portfolio with identifier [") - .appendValue(portfolioIdentifier) - .appendText("]"); + .appendValue(amountOfReservedItems) + .appendText("] for OrderBook with identifier [") + .appendValue(orderbookIdentifier) + .appendText("] and for Portfolio with identifier [") + .appendValue(portfolioIdentifier) + .appendText("]"); } } diff --git a/query/src/main/java/org/axonframework/samples/trader/query/company/CompanyListener.java b/query/src/main/java/org/axonframework/samples/trader/query/company/CompanyListener.java index 29d9586..e2962d8 100644 --- a/query/src/main/java/org/axonframework/samples/trader/query/company/CompanyListener.java +++ b/query/src/main/java/org/axonframework/samples/trader/query/company/CompanyListener.java @@ -22,9 +22,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -/** - * @author Jettro Coenradie - */ @Component public class CompanyListener { @@ -33,7 +30,7 @@ public class CompanyListener { @EventHandler public void handleCompanyCreatedEvent(CompanyCreatedEvent event) { CompanyEntry companyEntry = new CompanyEntry(); - companyEntry.setIdentifier(event.getCompanyIdentifier().toString()); + companyEntry.setIdentifier(event.getCompanyId().toString()); companyEntry.setValue(event.getCompanyValue()); companyEntry.setAmountOfShares(event.getAmountOfShares()); companyEntry.setTradeStarted(true); diff --git a/query/src/main/java/org/axonframework/samples/trader/query/orderbook/OrderBookListener.java b/query/src/main/java/org/axonframework/samples/trader/query/orderbook/OrderBookListener.java index 09bba0c..c2db435 100644 --- a/query/src/main/java/org/axonframework/samples/trader/query/orderbook/OrderBookListener.java +++ b/query/src/main/java/org/axonframework/samples/trader/query/orderbook/OrderBookListener.java @@ -18,10 +18,10 @@ import org.axonframework.eventhandling.EventHandler; import org.axonframework.samples.trader.api.company.OrderBookAddedToCompanyEvent; +import org.axonframework.samples.trader.api.orders.OrderBookId; +import org.axonframework.samples.trader.api.orders.OrderId; import org.axonframework.samples.trader.api.orders.trades.AbstractOrderPlacedEvent; import org.axonframework.samples.trader.api.orders.trades.BuyOrderPlacedEvent; -import org.axonframework.samples.trader.api.orders.trades.OrderBookId; -import org.axonframework.samples.trader.api.orders.trades.OrderId; import org.axonframework.samples.trader.api.orders.trades.SellOrderPlacedEvent; import org.axonframework.samples.trader.api.orders.trades.TradeExecutedEvent; import org.axonframework.samples.trader.query.company.CompanyEntry; @@ -32,9 +32,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -/** - * @author Jettro Coenradie - */ @Component public class OrderBookListener { @@ -58,7 +55,7 @@ public void handleOrderBookAddedToCompanyEvent(OrderBookAddedToCompanyEvent even @EventHandler public void handleBuyOrderPlaced(BuyOrderPlacedEvent event) { - OrderBookEntry orderBook = orderBookRepository.findOne(event.orderBookIdentifier().toString()); + OrderBookEntry orderBook = orderBookRepository.findOne(event.getOrderBookId().toString()); OrderEntry buyOrder = createPlacedOrder(event, BUY); orderBook.buyOrders().add(buyOrder); @@ -68,7 +65,7 @@ public void handleBuyOrderPlaced(BuyOrderPlacedEvent event) { @EventHandler public void handleSellOrderPlaced(SellOrderPlacedEvent event) { - OrderBookEntry orderBook = orderBookRepository.findOne(event.orderBookIdentifier().toString()); + OrderBookEntry orderBook = orderBookRepository.findOne(event.getOrderBookId().toString()); OrderEntry sellOrder = createPlacedOrder(event, SELL); orderBook.sellOrders().add(sellOrder); diff --git a/query/src/main/java/org/axonframework/samples/trader/query/portfolio/PortfolioItemEventListener.java b/query/src/main/java/org/axonframework/samples/trader/query/portfolio/PortfolioItemEventListener.java index 8cf1002..8064811 100644 --- a/query/src/main/java/org/axonframework/samples/trader/query/portfolio/PortfolioItemEventListener.java +++ b/query/src/main/java/org/axonframework/samples/trader/query/portfolio/PortfolioItemEventListener.java @@ -29,9 +29,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -/** - * @author Jettro Coenradie - */ @Component public class PortfolioItemEventListener { @@ -79,8 +76,8 @@ public void handleEvent(ItemReservationConfirmedForPortfolioEvent event) { @EventHandler public void handleEvent(ItemsReservedEvent event) { - logger.debug("Handle ItemsReservedEvent for orderbook with identifier {}", event.getOrderBookIdentifier()); - ItemEntry itemEntry = createItemEntry(event.getOrderBookIdentifier().toString(), + logger.debug("Handle ItemsReservedEvent for orderbook with identifier {}", event.getOrderBookId()); + ItemEntry itemEntry = createItemEntry(event.getOrderBookId().toString(), event.getAmountOfItemsReserved()); PortfolioEntry portfolioEntry = portfolioRepository.findOne(event.getPortfolioId().toString()); diff --git a/query/src/test/java/org/axonframework/samples/trader/query/orderbook/OrderBookListenerIntegrationTest.java b/query/src/test/java/org/axonframework/samples/trader/query/orderbook/OrderBookListenerIntegrationTest.java index f91545d..9c07670 100644 --- a/query/src/test/java/org/axonframework/samples/trader/query/orderbook/OrderBookListenerIntegrationTest.java +++ b/query/src/test/java/org/axonframework/samples/trader/query/orderbook/OrderBookListenerIntegrationTest.java @@ -19,8 +19,13 @@ import org.axonframework.samples.trader.api.company.CompanyCreatedEvent; import org.axonframework.samples.trader.api.company.CompanyId; import org.axonframework.samples.trader.api.company.OrderBookAddedToCompanyEvent; -import org.axonframework.samples.trader.api.orders.trades.*; +import org.axonframework.samples.trader.api.orders.OrderBookId; +import org.axonframework.samples.trader.api.orders.OrderId; +import org.axonframework.samples.trader.api.orders.trades.BuyOrderPlacedEvent; +import org.axonframework.samples.trader.api.orders.trades.SellOrderPlacedEvent; +import org.axonframework.samples.trader.api.orders.trades.TradeExecutedEvent; import org.axonframework.samples.trader.api.orders.transaction.TransactionId; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.axonframework.samples.trader.infra.config.PersistenceInfrastructureConfig; import org.axonframework.samples.trader.query.company.CompanyEntry; import org.axonframework.samples.trader.query.company.CompanyListener; @@ -110,7 +115,12 @@ public void testHandleSellOrderPlaced() throws Exception { OrderBookEntry orderBook = createOrderBook(company); OrderBookId orderBookId = new OrderBookId(orderBook.getIdentifier()); - SellOrderPlacedEvent event = new SellOrderPlacedEvent(orderBookId, orderId, transactionId, 300, 100, portfolioId); + SellOrderPlacedEvent event = new SellOrderPlacedEvent(orderBookId, + orderId, + transactionId, + 300, + 100, + portfolioId); orderBookListener.handleSellOrderPlaced(event); Iterable all = orderBookRepository.findAll(); @@ -129,11 +139,11 @@ public void testHandleTradeExecuted() throws Exception { OrderId sellOrderId = new OrderId(); TransactionId sellTransactionId = new TransactionId(); SellOrderPlacedEvent sellOrderPlacedEvent = new SellOrderPlacedEvent(orderBookId, - sellOrderId, - sellTransactionId, - 400, - 100, - portfolioId); + sellOrderId, + sellTransactionId, + 400, + 100, + portfolioId); orderBookListener.handleSellOrderPlaced(sellOrderPlacedEvent); @@ -141,10 +151,10 @@ public void testHandleTradeExecuted() throws Exception { TransactionId buyTransactionId = new TransactionId(); BuyOrderPlacedEvent buyOrderPlacedEvent = new BuyOrderPlacedEvent(orderBookId , buyOrderId, - buyTransactionId, - 300, - 150, - portfolioId); + buyTransactionId, + 300, + 150, + portfolioId); orderBookListener.handleBuyOrderPlaced(buyOrderPlacedEvent); @@ -157,12 +167,12 @@ public void testHandleTradeExecuted() throws Exception { TradeExecutedEvent event = new TradeExecutedEvent(orderBookId, - 300, - 125, - buyOrderId, - sellOrderId, - buyTransactionId, - sellTransactionId); + 300, + 125, + buyOrderId, + sellOrderId, + buyTransactionId, + sellTransactionId); orderBookListener.handleTradeExecuted(event); Iterable tradeExecutedEntries = tradeExecutedRepository.findAll(); diff --git a/query/src/test/java/org/axonframework/samples/trader/query/portfolio/PortfolioItemEventListenerTest.java b/query/src/test/java/org/axonframework/samples/trader/query/portfolio/PortfolioItemEventListenerTest.java index 0f8f854..5db3788 100644 --- a/query/src/test/java/org/axonframework/samples/trader/query/portfolio/PortfolioItemEventListenerTest.java +++ b/query/src/test/java/org/axonframework/samples/trader/query/portfolio/PortfolioItemEventListenerTest.java @@ -17,6 +17,8 @@ package org.axonframework.samples.trader.query.portfolio; import org.axonframework.samples.trader.api.company.CompanyId; +import org.axonframework.samples.trader.api.orders.OrderBookId; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.axonframework.samples.trader.api.portfolio.stock.ItemReservationCancelledForPortfolioEvent; import org.axonframework.samples.trader.api.portfolio.stock.ItemReservationConfirmedForPortfolioEvent; import org.axonframework.samples.trader.api.portfolio.stock.ItemsAddedToPortfolioEvent; @@ -24,8 +26,6 @@ import org.axonframework.samples.trader.query.orderbook.OrderBookEntry; import org.axonframework.samples.trader.query.orderbook.repositories.OrderBookQueryRepository; import org.axonframework.samples.trader.query.portfolio.repositories.PortfolioQueryRepository; -import org.axonframework.samples.trader.api.orders.trades.OrderBookId; -import org.axonframework.samples.trader.api.orders.trades.PortfolioId; import org.axonframework.samples.trader.api.orders.transaction.TransactionId; import org.axonframework.samples.trader.api.users.UserId; import org.junit.Before; diff --git a/query/src/test/java/org/axonframework/samples/trader/query/transaction/TransactionEventListenerTest.java b/query/src/test/java/org/axonframework/samples/trader/query/transaction/TransactionEventListenerTest.java index 8b7c638..d29764f 100644 --- a/query/src/test/java/org/axonframework/samples/trader/query/transaction/TransactionEventListenerTest.java +++ b/query/src/test/java/org/axonframework/samples/trader/query/transaction/TransactionEventListenerTest.java @@ -17,15 +17,15 @@ package org.axonframework.samples.trader.query.transaction; import org.axonframework.samples.trader.api.company.CompanyId; +import org.axonframework.samples.trader.api.orders.OrderBookId; import org.axonframework.samples.trader.api.orders.transaction.BuyTransactionStartedEvent; import org.axonframework.samples.trader.api.orders.transaction.SellTransactionCancelledEvent; import org.axonframework.samples.trader.api.orders.transaction.SellTransactionStartedEvent; +import org.axonframework.samples.trader.api.orders.transaction.TransactionId; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.axonframework.samples.trader.query.orderbook.OrderBookEntry; import org.axonframework.samples.trader.query.orderbook.repositories.OrderBookQueryRepository; import org.axonframework.samples.trader.query.transaction.repositories.TransactionQueryRepository; -import org.axonframework.samples.trader.api.orders.trades.OrderBookId; -import org.axonframework.samples.trader.api.orders.trades.PortfolioId; -import org.axonframework.samples.trader.api.orders.transaction.TransactionId; import org.junit.Before; import org.junit.Test; import org.mockito.Matchers; @@ -36,10 +36,6 @@ import static org.axonframework.samples.trader.query.transaction.TransactionState.CANCELLED; import static org.axonframework.samples.trader.query.transaction.TransactionState.STARTED; - -/** - * @author Jettro Coenradie - */ public class TransactionEventListenerTest { public static final TransactionId transactionIdentifier = new TransactionId(); @@ -64,16 +60,16 @@ public void setUp() throws Exception { listener.setOrderBookQueryRepository(orderBookQueryRepository); Mockito.when(orderBookQueryRepository.findOne(orderBookIdentifier.toString())) - .thenReturn(createOrderBookEntry()); + .thenReturn(createOrderBookEntry()); } @Test public void handleBuyTransactionStartedEvent() { BuyTransactionStartedEvent event = new BuyTransactionStartedEvent(transactionIdentifier, - orderBookIdentifier, - portfolioIdentifier, - DEFAULT_TOTAL_ITEMS, - DEFAULT_ITEM_PRICE); + orderBookIdentifier, + portfolioIdentifier, + DEFAULT_TOTAL_ITEMS, + DEFAULT_ITEM_PRICE); listener.handleEvent(event); Mockito.verify(transactionQueryRepository).save(Matchers.argThat(new TransactionEntryMatcher( @@ -90,10 +86,10 @@ public void handleBuyTransactionStartedEvent() { @Test public void handleSellTransactionStartedEvent() { SellTransactionStartedEvent event = new SellTransactionStartedEvent(transactionIdentifier, - orderBookIdentifier, - portfolioIdentifier, - DEFAULT_TOTAL_ITEMS, - DEFAULT_ITEM_PRICE); + orderBookIdentifier, + portfolioIdentifier, + DEFAULT_TOTAL_ITEMS, + DEFAULT_ITEM_PRICE); listener.handleEvent(event); Mockito.verify(transactionQueryRepository).save(Matchers.argThat(new TransactionEntryMatcher( diff --git a/trade-engine/src/main/java/org/axonframework/samples/trader/tradeengine/command/Order.java b/trade-engine/src/main/java/org/axonframework/samples/trader/tradeengine/command/Order.java index 5c8a80d..557419d 100644 --- a/trade-engine/src/main/java/org/axonframework/samples/trader/tradeengine/command/Order.java +++ b/trade-engine/src/main/java/org/axonframework/samples/trader/tradeengine/command/Order.java @@ -17,14 +17,11 @@ package org.axonframework.samples.trader.tradeengine.command; import org.axonframework.eventhandling.EventHandler; -import org.axonframework.samples.trader.api.orders.trades.OrderId; -import org.axonframework.samples.trader.api.orders.trades.PortfolioId; +import org.axonframework.samples.trader.api.orders.OrderId; import org.axonframework.samples.trader.api.orders.trades.TradeExecutedEvent; import org.axonframework.samples.trader.api.orders.transaction.TransactionId; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; -/** - * @author Allard Buijze - */ class Order { private OrderId orderId; diff --git a/trade-engine/src/main/java/org/axonframework/samples/trader/tradeengine/command/OrderBook.java b/trade-engine/src/main/java/org/axonframework/samples/trader/tradeengine/command/OrderBook.java index ed75d4c..fd941d3 100644 --- a/trade-engine/src/main/java/org/axonframework/samples/trader/tradeengine/command/OrderBook.java +++ b/trade-engine/src/main/java/org/axonframework/samples/trader/tradeengine/command/OrderBook.java @@ -20,14 +20,14 @@ import org.axonframework.commandhandling.model.AggregateMember; import org.axonframework.commandhandling.model.AggregateRoot; import org.axonframework.eventhandling.EventHandler; +import org.axonframework.samples.trader.api.orders.OrderBookId; +import org.axonframework.samples.trader.api.orders.OrderId; import org.axonframework.samples.trader.api.orders.trades.BuyOrderPlacedEvent; import org.axonframework.samples.trader.api.orders.trades.OrderBookCreatedEvent; -import org.axonframework.samples.trader.api.orders.trades.OrderBookId; -import org.axonframework.samples.trader.api.orders.trades.OrderId; -import org.axonframework.samples.trader.api.orders.trades.PortfolioId; import org.axonframework.samples.trader.api.orders.trades.SellOrderPlacedEvent; import org.axonframework.samples.trader.api.orders.trades.TradeExecutedEvent; import org.axonframework.samples.trader.api.orders.transaction.TransactionId; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import java.util.Comparator; import java.util.SortedSet; @@ -35,12 +35,8 @@ import static org.axonframework.commandhandling.model.AggregateLifecycle.apply; -/** - * @author Allard Buijze - */ @AggregateRoot public class OrderBook { - private static final long serialVersionUID = 6778782949492587631L; @AggregateIdentifier private OrderBookId orderBookId; @@ -93,13 +89,13 @@ private void executeTrades() { @EventHandler protected void onOrderBookCreated(OrderBookCreatedEvent event) { - this.orderBookId = event.getOrderBookIdentifier(); + this.orderBookId = event.getOrderBookId(); } @EventHandler protected void onBuyPlaced(BuyOrderPlacedEvent event) { buyOrders.add(new Order(event.getOrderId(), - event.getTransactionIdentifier(), + event.getTransactionId(), event.getItemPrice(), event.getTradeCount(), event.getPortfolioId())); @@ -108,7 +104,7 @@ protected void onBuyPlaced(BuyOrderPlacedEvent event) { @EventHandler protected void onSellPlaced(SellOrderPlacedEvent event) { sellOrders.add(new Order(event.getOrderId(), - event.getTransactionIdentifier(), + event.getTransactionId(), event.getItemPrice(), event.getTradeCount(), event.getPortfolioId())); diff --git a/trade-engine/src/test/java/org/axonframework/samples/trader/tradeengine/command/OrderBookCommandHandlerTest.java b/trade-engine/src/test/java/org/axonframework/samples/trader/tradeengine/command/OrderBookCommandHandlerTest.java index 6da192f..b532a09 100644 --- a/trade-engine/src/test/java/org/axonframework/samples/trader/tradeengine/command/OrderBookCommandHandlerTest.java +++ b/trade-engine/src/test/java/org/axonframework/samples/trader/tradeengine/command/OrderBookCommandHandlerTest.java @@ -16,15 +16,15 @@ package org.axonframework.samples.trader.tradeengine.command; +import org.axonframework.samples.trader.api.orders.OrderBookId; +import org.axonframework.samples.trader.api.orders.OrderId; import org.axonframework.samples.trader.api.orders.trades.*; import org.axonframework.samples.trader.api.orders.transaction.TransactionId; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.axonframework.test.aggregate.AggregateTestFixture; import org.junit.Before; import org.junit.Test; -/** - * @author Allard Buijze - */ public class OrderBookCommandHandlerTest { private AggregateTestFixture fixture; diff --git a/users/src/test/java/org/axonframework/samples/trader/app/command/user/UserCommandHandlerTest.java b/users/src/test/java/org/axonframework/samples/trader/app/command/user/UserCommandHandlerTest.java index f93aa81..e62de66 100644 --- a/users/src/test/java/org/axonframework/samples/trader/app/command/user/UserCommandHandlerTest.java +++ b/users/src/test/java/org/axonframework/samples/trader/app/command/user/UserCommandHandlerTest.java @@ -27,9 +27,6 @@ import org.junit.Test; import org.mockito.Mockito; -/** - * @author Jettro Coenradie - */ public class UserCommandHandlerTest { private AggregateTestFixture fixture; @@ -49,7 +46,7 @@ public void setUp() { @Test - public void testHandleCreateUser() throws Exception { + public void testHandleCreateUser() { UserId aggregateIdentifier = new UserId(); fixture.given() .when(new CreateUserCommand(aggregateIdentifier, "Buyer 1", "buyer1", "buyer1")) @@ -57,7 +54,7 @@ public void testHandleCreateUser() throws Exception { } @Test - public void testHandleAuthenticateUser() throws Exception { + public void testHandleAuthenticateUser() { UserId aggregateIdentifier = new UserId(); UserEntry userEntry = new UserEntry(); @@ -67,7 +64,7 @@ public void testHandleAuthenticateUser() throws Exception { Mockito.when(userQueryRepository.findByUsername("buyer1")).thenReturn(userEntry); fixture.given(new UserCreatedEvent(aggregateIdentifier, "Buyer 1", "buyer1", DigestUtils.sha1("buyer1"))) - .when(new AuthenticateUserCommand("buyer1", "buyer1".toCharArray())) + .when(new AuthenticateUserCommand(aggregateIdentifier, "buyer1", "buyer1".toCharArray())) .expectEvents(new UserAuthenticatedEvent(aggregateIdentifier)); } } diff --git a/web-ui/src/main/java/org/axonframework/samples/trader/webui/admin/AdminController.java b/web-ui/src/main/java/org/axonframework/samples/trader/webui/admin/AdminController.java index 45d4546..ff8e4b1 100644 --- a/web-ui/src/main/java/org/axonframework/samples/trader/webui/admin/AdminController.java +++ b/web-ui/src/main/java/org/axonframework/samples/trader/webui/admin/AdminController.java @@ -18,14 +18,14 @@ import org.axonframework.commandhandling.CommandBus; import org.axonframework.commandhandling.GenericCommandMessage; -import org.axonframework.samples.trader.api.portfolio.stock.AddItemsToPortfolioCommand; +import org.axonframework.samples.trader.api.orders.OrderBookId; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.axonframework.samples.trader.api.portfolio.cash.DepositCashCommand; +import org.axonframework.samples.trader.api.portfolio.stock.AddItemsToPortfolioCommand; import org.axonframework.samples.trader.query.orderbook.OrderBookEntry; import org.axonframework.samples.trader.query.orderbook.repositories.OrderBookQueryRepository; import org.axonframework.samples.trader.query.portfolio.PortfolioEntry; import org.axonframework.samples.trader.query.portfolio.repositories.PortfolioQueryRepository; -import org.axonframework.samples.trader.api.orders.trades.OrderBookId; -import org.axonframework.samples.trader.api.orders.trades.PortfolioId; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -33,9 +33,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -/** - * @author Jettro Coenradie - */ @Controller @RequestMapping("/admin") public class AdminController { @@ -81,9 +78,9 @@ public String addItem(@PathVariable("identifier") String portfolioIdentifier, ) { AddItemsToPortfolioCommand command = new AddItemsToPortfolioCommand(new PortfolioId( portfolioIdentifier), - new OrderBookId( - orderBookIdentifier), - amount); + new OrderBookId( + orderBookIdentifier), + amount); commandBus.dispatch(new GenericCommandMessage<>(command)); return "redirect:/admin/portfolio/{identifier}"; } diff --git a/web-ui/src/main/java/org/axonframework/samples/trader/webui/companies/CompanyController.java b/web-ui/src/main/java/org/axonframework/samples/trader/webui/companies/CompanyController.java index 5cd9806..a8837cf 100644 --- a/web-ui/src/main/java/org/axonframework/samples/trader/webui/companies/CompanyController.java +++ b/web-ui/src/main/java/org/axonframework/samples/trader/webui/companies/CompanyController.java @@ -18,8 +18,11 @@ import org.axonframework.commandhandling.CommandBus; import org.axonframework.commandhandling.GenericCommandMessage; +import org.axonframework.samples.trader.api.orders.OrderBookId; import org.axonframework.samples.trader.api.orders.transaction.StartBuyTransactionCommand; import org.axonframework.samples.trader.api.orders.transaction.StartSellTransactionCommand; +import org.axonframework.samples.trader.api.orders.transaction.TransactionId; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.axonframework.samples.trader.query.company.CompanyEntry; import org.axonframework.samples.trader.query.company.repositories.CompanyQueryRepository; import org.axonframework.samples.trader.query.orderbook.OrderBookEntry; @@ -30,9 +33,6 @@ import org.axonframework.samples.trader.query.tradeexecuted.repositories.TradeExecutedQueryRepository; import org.axonframework.samples.trader.query.users.UserEntry; import org.axonframework.samples.trader.query.users.repositories.UserQueryRepository; -import org.axonframework.samples.trader.api.orders.trades.OrderBookId; -import org.axonframework.samples.trader.api.orders.trades.PortfolioId; -import org.axonframework.samples.trader.api.orders.transaction.TransactionId; import org.axonframework.samples.trader.webui.order.AbstractOrder; import org.axonframework.samples.trader.webui.order.BuyOrder; import org.axonframework.samples.trader.webui.order.SellOrder; @@ -46,8 +46,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import javax.validation.Valid; import java.util.List; +import javax.validation.Valid; /** * @author Jettro Coenradie @@ -90,7 +90,7 @@ public String details(@PathVariable String companyId, Model model) { CompanyEntry company = companyRepository.findOne(companyId); OrderBookEntry bookEntry = orderBookRepository.findByCompanyIdentifier(company.getIdentifier()).get(0); List executedTrades = tradeExecutedRepository.findByOrderBookIdentifier(bookEntry - .getIdentifier()); + .getIdentifier()); model.addAttribute("company", company); model.addAttribute("sellOrders", bookEntry.sellOrders()); model.addAttribute("buyOrders", bookEntry.buyOrders()); @@ -127,17 +127,19 @@ public String sell(@ModelAttribute("order") @Valid SellOrder order, BindingResul if (portfolioEntry.obtainAmountOfAvailableItemsFor(bookEntry.getIdentifier()) < order.getTradeCount()) { bindingResult.rejectValue("tradeCount", - "error.order.sell.tomanyitems", - "Not enough items available to create sell order."); + "error.order.sell.tomanyitems", + "Not enough items available to create sell order."); addPortfolioItemInfoToModel(order.getCompanyId(), model); return "company/sell"; } StartSellTransactionCommand command = new StartSellTransactionCommand(new TransactionId(), - new OrderBookId(bookEntry.getIdentifier()), - new PortfolioId(portfolioEntry.getIdentifier()), - order.getTradeCount(), - order.getItemPrice()); + new OrderBookId(bookEntry + .getIdentifier()), + new PortfolioId(portfolioEntry + .getIdentifier()), + order.getTradeCount(), + order.getItemPrice()); commandBus.dispatch(new GenericCommandMessage<>(command)); @@ -157,17 +159,19 @@ public String buy(@ModelAttribute("order") @Valid BuyOrder order, BindingResult if (portfolioEntry.obtainMoneyToSpend() < order.getTradeCount() * order.getItemPrice()) { bindingResult.rejectValue("tradeCount", - "error.order.buy.notenoughmoney", - "Not enough cash to spend to buy the items for the price you want"); + "error.order.buy.notenoughmoney", + "Not enough cash to spend to buy the items for the price you want"); addPortfolioMoneyInfoToModel(portfolioEntry, model); return "company/buy"; } StartBuyTransactionCommand command = new StartBuyTransactionCommand(new TransactionId(), - new OrderBookId(bookEntry.getIdentifier()), - new PortfolioId(portfolioEntry.getIdentifier()), - order.getTradeCount(), - order.getItemPrice()); + new OrderBookId(bookEntry + .getIdentifier()), + new PortfolioId(portfolioEntry + .getIdentifier()), + order.getTradeCount(), + order.getItemPrice()); commandBus.dispatch(new GenericCommandMessage<>(command)); return "redirect:/company/{companyId}"; } diff --git a/web-ui/src/main/java/org/axonframework/samples/trader/webui/init/BaseDBInit.java b/web-ui/src/main/java/org/axonframework/samples/trader/webui/init/BaseDBInit.java index 3c89f4c..23fb8fd 100644 --- a/web-ui/src/main/java/org/axonframework/samples/trader/webui/init/BaseDBInit.java +++ b/web-ui/src/main/java/org/axonframework/samples/trader/webui/init/BaseDBInit.java @@ -4,8 +4,8 @@ import org.axonframework.commandhandling.GenericCommandMessage; import org.axonframework.samples.trader.api.company.CompanyId; import org.axonframework.samples.trader.api.company.CreateCompanyCommand; -import org.axonframework.samples.trader.api.orders.trades.OrderBookId; -import org.axonframework.samples.trader.api.orders.trades.PortfolioId; +import org.axonframework.samples.trader.api.orders.OrderBookId; +import org.axonframework.samples.trader.api.portfolio.PortfolioId; import org.axonframework.samples.trader.api.portfolio.cash.DepositCashCommand; import org.axonframework.samples.trader.api.portfolio.stock.AddItemsToPortfolioCommand; import org.axonframework.samples.trader.api.users.CreateUserCommand; @@ -23,12 +23,14 @@ * Base class for all DBInit implementations */ public abstract class BaseDBInit implements DBInit { + private CommandBus commandBus; private CompanyQueryRepository companyRepository; private PortfolioQueryRepository portfolioRepository; private OrderBookQueryRepository orderBookRepository; - protected BaseDBInit(CommandBus commandBus, CompanyQueryRepository companyRepository, PortfolioQueryRepository portfolioRepository, OrderBookQueryRepository orderBookRepository) { + protected BaseDBInit(CommandBus commandBus, CompanyQueryRepository companyRepository, + PortfolioQueryRepository portfolioRepository, OrderBookQueryRepository orderBookRepository) { this.commandBus = commandBus; this.companyRepository = companyRepository; this.portfolioRepository = portfolioRepository; @@ -72,7 +74,11 @@ UserId createuser(String longName, String userName) { } void createCompanies(UserId userIdentifier) { - CreateCompanyCommand command = new CreateCompanyCommand(new CompanyId(), userIdentifier, "Philips", 1000, 10000); + CreateCompanyCommand command = new CreateCompanyCommand(new CompanyId(), + userIdentifier, + "Philips", + 1000, + 10000); commandBus.dispatch(new GenericCommandMessage<>(command)); command = new CreateCompanyCommand(new CompanyId(), userIdentifier, "Shell", 500, 5000); diff --git a/web-ui/src/main/java/org/axonframework/samples/trader/webui/security/TraderAuthenticationProvider.java b/web-ui/src/main/java/org/axonframework/samples/trader/webui/security/TraderAuthenticationProvider.java index 16d65ba..8ff560b 100644 --- a/web-ui/src/main/java/org/axonframework/samples/trader/webui/security/TraderAuthenticationProvider.java +++ b/web-ui/src/main/java/org/axonframework/samples/trader/webui/security/TraderAuthenticationProvider.java @@ -22,6 +22,7 @@ import org.axonframework.messaging.interceptors.JSR303ViolationException; import org.axonframework.samples.trader.api.users.AuthenticateUserCommand; import org.axonframework.samples.trader.api.users.UserAccount; +import org.axonframework.samples.trader.api.users.UserId; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.authentication.AuthenticationServiceException; @@ -69,7 +70,8 @@ public Authentication authenticate(Authentication authentication) throws Authent String username = token.getName(); String password = String.valueOf(token.getCredentials()); FutureCallback accountCallback = new FutureCallback<>(); - AuthenticateUserCommand command = new AuthenticateUserCommand(username, password.toCharArray()); + UserId userId = new UserId(); // TODO replace this with the actual aggregate identifier + AuthenticateUserCommand command = new AuthenticateUserCommand(userId, username, password.toCharArray()); try { commandBus.dispatch(new GenericCommandMessage<>(command), accountCallback); // the bean validating interceptor is defined as a dispatch interceptor, meaning it is executed before