Browse files

Fixed all the unit tests

  • Loading branch information...
1 parent 239e7a0 commit 7183fec72e402445b29249918b7bce6ccddc135a @jettro jettro committed May 25, 2012
Showing with 296 additions and 180 deletions.
  1. +7 −0 companies-api/pom.xml
  2. +42 −0 ...-api/src/main/java/org/axonframework/samples/trader/company/api/AddOrderBookToCompanyCommand.java
  3. +42 −0 ...-api/src/main/java/org/axonframework/samples/trader/company/api/OrderBookAddedToCompanyEvent.java
  4. +6 −1 companies/src/main/java/org/axonframework/samples/trader/company/command/Company.java
  5. +7 −0 companies/src/main/java/org/axonframework/samples/trader/company/command/CompanyCommandHandler.java
  6. +0 −1 ...ies/src/test/java/org/axonframework/samples/trader/company/command/CompanyCommandHandlerTest.java
  7. +8 −1 ...java/org/axonframework/samples/trader/orders/api/transaction/AbstractStartTransactionCommand.java
  8. +3 −2 ...main/java/org/axonframework/samples/trader/orders/api/transaction/StartBuyTransactionCommand.java
  9. +3 −2 ...ain/java/org/axonframework/samples/trader/orders/api/transaction/StartSellTransactionCommand.java
  10. +2 −1 orders/src/main/java/org/axonframework/samples/trader/orders/command/BuyTradeManagerSaga.java
  11. +3 −1 orders/src/main/java/org/axonframework/samples/trader/orders/command/SellTradeManagerSaga.java
  12. +2 −1 orders/src/main/java/org/axonframework/samples/trader/orders/command/Transaction.java
  13. +3 −6 orders/src/main/java/org/axonframework/samples/trader/orders/command/TransactionCommandHandler.java
  14. +48 −38 orders/src/test/java/org/axonframework/samples/trader/orders/command/BuyTradeManagerSagaTest.java
  15. +1 −1 ...est/java/org/axonframework/samples/trader/orders/command/PortfolioManagementUserListenerTest.java
  16. +2 −2 ...src/test/java/org/axonframework/samples/trader/orders/command/TransactionCommandHandlingTest.java
  17. +2 −8 ...a/org/axonframework/samples/trader/orders/command/matchers/AddItemsToPortfolioCommandMatcher.java
  18. +37 −0 ...rs/src/test/java/org/axonframework/samples/trader/orders/command/matchers/BaseCommandMatcher.java
  19. +2 −7 ...ework/samples/trader/orders/command/matchers/CancelItemReservationForPortfolioCommandMatcher.java
  20. +2 −8 ...ork/samples/trader/orders/command/matchers/CancelMoneyReservationFromPortfolioCommandMatcher.java
  21. +2 −7 ...ava/org/axonframework/samples/trader/orders/command/matchers/CancelTransactionCommandMatcher.java
  22. +2 −7 ...work/samples/trader/orders/command/matchers/ConfirmItemReservationForPortfolioCommandMatcher.java
  23. +2 −8 ...k/samples/trader/orders/command/matchers/ConfirmMoneyReservationFromPortfolionCommandMatcher.java
  24. +2 −7 ...va/org/axonframework/samples/trader/orders/command/matchers/ConfirmTransactionCommandMatcher.java
  25. +2 −8 ...t/java/org/axonframework/samples/trader/orders/command/matchers/CreateBuyOrderCommandMatcher.java
  26. +2 −8 .../java/org/axonframework/samples/trader/orders/command/matchers/CreateSellOrderCommandMatcher.java
  27. +2 −7 ...g/axonframework/samples/trader/orders/command/matchers/DepositMoneyToPortfolioCommandMatcher.java
  28. +2 −7 ...a/org/axonframework/samples/trader/orders/command/matchers/ExecutedTransactionCommandMatcher.java
  29. +2 −7 ...axonframework/samples/trader/orders/command/matchers/ReserveMoneyFromPortfolioCommandMatcher.java
  30. +2 −7 ...st/java/org/axonframework/samples/trader/orders/command/matchers/ReservedItemsCommandMatcher.java
  31. +7 −6 query/src/main/java/org/axonframework/samples/trader/query/orderbook/OrderBookListener.java
  32. +11 −3 .../test/java/org/axonframework/samples/trader/query/orderbook/OrderBookListenerIntegrationTest.java
  33. +2 −2 ...pi/src/main/java/org/axonframework/samples/trader/tradeengine/api/order/AbstractOrderCommand.java
  34. +2 −2 ...i/src/main/java/org/axonframework/samples/trader/tradeengine/api/order/CreateBuyOrderCommand.java
  35. +2 −2 .../src/main/java/org/axonframework/samples/trader/tradeengine/api/order/CreateSellOrderCommand.java
  36. +1 −1 trade-engine/src/main/java/org/axonframework/samples/trader/tradeengine/command/Order.java
  37. +12 −1 trade-engine/src/main/java/org/axonframework/samples/trader/tradeengine/command/OrderBook.java
  38. +13 −7 ...c/test/java/org/axonframework/samples/trader/tradeengine/command/OrderBookCommandHandlerTest.java
  39. +1 −1 users/src/main/java/org/axonframework/samples/trader/users/command/UserCommandHandler.java
  40. +3 −2 web-ui/src/main/java/org/axonframework/samples/trader/webui/companies/CompanyController.java
View
7 companies-api/pom.xml
@@ -36,6 +36,13 @@
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>axon-trader-trade-engine-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+
<!-- External dependencies -->
<dependency>
<groupId>org.axonframework</groupId>
View
42 .../main/java/org/axonframework/samples/trader/company/api/AddOrderBookToCompanyCommand.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 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.api;
+
+import org.axonframework.samples.trader.tradeengine.api.order.OrderBookId;
+
+/**
+ * <p>Create the relation between a company and an OrderBook</p>
+ *
+ * @author Jettro Coenradie
+ */
+public class AddOrderBookToCompanyCommand {
+ private CompanyId companyId;
+ private OrderBookId orderBookId;
+
+ public AddOrderBookToCompanyCommand(CompanyId companyId, OrderBookId orderBookId) {
+ this.companyId = companyId;
+ this.orderBookId = orderBookId;
+ }
+
+ public CompanyId getCompanyId() {
+ return companyId;
+ }
+
+ public OrderBookId getOrderBookId() {
+ return orderBookId;
+ }
+}
View
42 .../main/java/org/axonframework/samples/trader/company/api/OrderBookAddedToCompanyEvent.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 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.api;
+
+import org.axonframework.samples.trader.tradeengine.api.order.OrderBookId;
+
+/**
+ * <p>A new OrderBook is added to the Company</p>
+ *
+ * @author Jettro Coenradie
+ */
+public class OrderBookAddedToCompanyEvent {
+ private CompanyId companyId;
+ private OrderBookId orderBookId;
+
+ public OrderBookAddedToCompanyEvent(CompanyId companyId, OrderBookId orderBookId) {
+ this.companyId = companyId;
+ this.orderBookId = orderBookId;
+ }
+
+ public CompanyId getCompanyId() {
+ return companyId;
+ }
+
+ public OrderBookId getOrderBookId() {
+ return orderBookId;
+ }
+}
View
7 companies/src/main/java/org/axonframework/samples/trader/company/command/Company.java
@@ -21,6 +21,8 @@
import org.axonframework.eventsourcing.annotation.AggregateIdentifier;
import org.axonframework.samples.trader.company.api.CompanyCreatedEvent;
import org.axonframework.samples.trader.company.api.CompanyId;
+import org.axonframework.samples.trader.company.api.OrderBookAddedToCompanyEvent;
+import org.axonframework.samples.trader.tradeengine.api.order.OrderBookId;
/**
* @author Jettro Coenradie
@@ -39,6 +41,10 @@ public Company(CompanyId companyId, String name, long value, long amountOfShares
apply(new CompanyCreatedEvent(companyId, name, value, amountOfShares));
}
+ public void addOrderBook(OrderBookId orderBookId) {
+ apply(new OrderBookAddedToCompanyEvent(companyId, orderBookId));
+ }
+
@Override
public CompanyId getIdentifier() {
return this.companyId;
@@ -48,5 +54,4 @@ public CompanyId getIdentifier() {
public void handle(CompanyCreatedEvent event) {
this.companyId = event.getCompanyIdentifier();
}
-
}
View
7 ...src/main/java/org/axonframework/samples/trader/company/command/CompanyCommandHandler.java
@@ -18,6 +18,7 @@
import org.axonframework.commandhandling.annotation.CommandHandler;
import org.axonframework.repository.Repository;
+import org.axonframework.samples.trader.company.api.AddOrderBookToCompanyCommand;
import org.axonframework.samples.trader.company.api.CreateCompanyCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -38,6 +39,12 @@ public void handleCreateCompany(CreateCompanyCommand command) {
repository.add(company);
}
+ @CommandHandler
+ public void handleAddOrderBook(AddOrderBookToCompanyCommand command) {
+ Company company = repository.load(command.getCompanyId());
+ company.addOrderBook(command.getOrderBookId());
+ }
+
@Autowired
@Qualifier("companyRepository")
public void setRepository(Repository<Company> companyRepository) {
View
1 ...test/java/org/axonframework/samples/trader/company/command/CompanyCommandHandlerTest.java
@@ -38,7 +38,6 @@ public void setUp() {
CompanyCommandHandler commandHandler = new CompanyCommandHandler();
commandHandler.setRepository(fixture.getRepository());
fixture.registerAnnotatedCommandHandler(commandHandler);
-// fixture.setAggregateIdentifier(new CompanyId());
}
@Test
View
9 .../axonframework/samples/trader/orders/api/transaction/AbstractStartTransactionCommand.java
@@ -18,19 +18,22 @@
import org.axonframework.samples.trader.tradeengine.api.order.OrderBookId;
import org.axonframework.samples.trader.tradeengine.api.order.PortfolioId;
+import org.axonframework.samples.trader.tradeengine.api.order.TransactionId;
/**
* @author Jettro Coenradie
*/
public abstract class AbstractStartTransactionCommand {
+ private TransactionId transactionId;
private OrderBookId orderbookIdentifier;
private PortfolioId portfolioIdentifier;
private long tradeCount;
private long itemPrice;
- public AbstractStartTransactionCommand(OrderBookId orderbookIdentifier,
+ public AbstractStartTransactionCommand(TransactionId transactionId, OrderBookId orderbookIdentifier,
PortfolioId portfolioIdentifier, long tradeCount, long itemPrice) {
+ this.transactionId = transactionId;
this.itemPrice = itemPrice;
this.orderbookIdentifier = orderbookIdentifier;
this.portfolioIdentifier = portfolioIdentifier;
@@ -49,6 +52,10 @@ public PortfolioId getPortfolioIdentifier() {
return portfolioIdentifier;
}
+ public TransactionId getTransactionIdentifier() {
+ return transactionId;
+ }
+
public long getTradeCount() {
return tradeCount;
}
View
5 ...a/org/axonframework/samples/trader/orders/api/transaction/StartBuyTransactionCommand.java
@@ -18,13 +18,14 @@
import org.axonframework.samples.trader.tradeengine.api.order.OrderBookId;
import org.axonframework.samples.trader.tradeengine.api.order.PortfolioId;
+import org.axonframework.samples.trader.tradeengine.api.order.TransactionId;
/**
* @author Jettro Coenradie
*/
public class StartBuyTransactionCommand extends AbstractStartTransactionCommand {
- public StartBuyTransactionCommand(OrderBookId orderbookIdentifier, PortfolioId portfolioIdentifier, long tradeCount, long itemPrice) {
- super(orderbookIdentifier, portfolioIdentifier, tradeCount, itemPrice);
+ public StartBuyTransactionCommand(TransactionId transactionId, OrderBookId orderbookIdentifier, PortfolioId portfolioIdentifier, long tradeCount, long itemPrice) {
+ super(transactionId, orderbookIdentifier, portfolioIdentifier, tradeCount, itemPrice);
}
}
View
5 .../org/axonframework/samples/trader/orders/api/transaction/StartSellTransactionCommand.java
@@ -18,13 +18,14 @@
import org.axonframework.samples.trader.tradeengine.api.order.OrderBookId;
import org.axonframework.samples.trader.tradeengine.api.order.PortfolioId;
+import org.axonframework.samples.trader.tradeengine.api.order.TransactionId;
/**
* @author Jettro Coenradie
*/
public class StartSellTransactionCommand extends AbstractStartTransactionCommand {
- public StartSellTransactionCommand(OrderBookId orderbookIdentifier, PortfolioId portfolioIdentifier, long tradeCount, long itemPrice) {
- super(orderbookIdentifier, portfolioIdentifier, tradeCount, itemPrice);
+ public StartSellTransactionCommand(TransactionId transactionId, OrderBookId orderbookIdentifier, PortfolioId portfolioIdentifier, long tradeCount, long itemPrice) {
+ super(transactionId, orderbookIdentifier, portfolioIdentifier, tradeCount, itemPrice);
}
}
View
3 ...rs/src/main/java/org/axonframework/samples/trader/orders/command/BuyTradeManagerSaga.java
@@ -25,6 +25,7 @@
import org.axonframework.samples.trader.orders.api.portfolio.money.*;
import org.axonframework.samples.trader.orders.api.transaction.*;
import org.axonframework.samples.trader.tradeengine.api.order.CreateBuyOrderCommand;
+import org.axonframework.samples.trader.tradeengine.api.order.OrderId;
import org.axonframework.samples.trader.tradeengine.api.order.TradeExecutedEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -96,7 +97,7 @@ public void handle(NotEnoughMoneyInPortfolioToMakeReservationEvent event) {
@SagaEventHandler(associationProperty = "transactionIdentifier")
public void handle(BuyTransactionConfirmedEvent event) {
logger.debug("Buy Transaction {} is approved to make the buy order", event.getTransactionIdentifier());
- CreateBuyOrderCommand command = new CreateBuyOrderCommand(getPortfolioIdentifier(),
+ CreateBuyOrderCommand command = new CreateBuyOrderCommand(new OrderId(), getPortfolioIdentifier(),
getOrderbookIdentifier(),
getTransactionIdentifier(),
getTotalItems(),
View
4 ...s/src/main/java/org/axonframework/samples/trader/orders/command/SellTradeManagerSaga.java
@@ -24,6 +24,7 @@
import org.axonframework.samples.trader.orders.api.portfolio.money.DepositMoneyToPortfolioCommand;
import org.axonframework.samples.trader.orders.api.transaction.*;
import org.axonframework.samples.trader.tradeengine.api.order.CreateSellOrderCommand;
+import org.axonframework.samples.trader.tradeengine.api.order.OrderId;
import org.axonframework.samples.trader.tradeengine.api.order.TradeExecutedEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -83,7 +84,8 @@ public void handle(NotEnoughItemsAvailableToReserveInPortfolio event) {
public void handle(SellTransactionConfirmedEvent event) {
logger.debug("Sell Transaction {} is approved to make the sell order", event.getTransactionIdentifier());
- CreateSellOrderCommand command = new CreateSellOrderCommand(getPortfolioIdentifier(),
+ CreateSellOrderCommand command = new CreateSellOrderCommand(new OrderId(),
+ getPortfolioIdentifier(),
getOrderbookIdentifier(),
getTransactionIdentifier(),
getTotalItems(),
View
3 orders/src/main/java/org/axonframework/samples/trader/orders/command/Transaction.java
@@ -41,7 +41,8 @@
protected Transaction() {
}
- public Transaction(TransactionType type,
+ public Transaction(TransactionId transactionId,
+ TransactionType type,
OrderBookId orderbookIdentifier,
PortfolioId portfolioIdentifier,
long amountOfItems,
View
9 .../main/java/org/axonframework/samples/trader/orders/command/TransactionCommandHandler.java
@@ -18,12 +18,7 @@
import org.axonframework.commandhandling.annotation.CommandHandler;
import org.axonframework.repository.Repository;
-import org.axonframework.samples.trader.orders.api.transaction.CancelTransactionCommand;
-import org.axonframework.samples.trader.orders.api.transaction.ConfirmTransactionCommand;
-import org.axonframework.samples.trader.orders.api.transaction.ExecutedTransactionCommand;
-import org.axonframework.samples.trader.orders.api.transaction.StartBuyTransactionCommand;
-import org.axonframework.samples.trader.orders.api.transaction.StartSellTransactionCommand;
-import org.axonframework.samples.trader.orders.api.transaction.TransactionType;
+import org.axonframework.samples.trader.orders.api.transaction.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
@@ -39,6 +34,7 @@
@CommandHandler
public void handleStartBuyTransactionCommand(StartBuyTransactionCommand command) {
Transaction transaction = new Transaction(
+ command.getTransactionIdentifier(),
TransactionType.BUY,
command.getOrderbookIdentifier(),
command.getPortfolioIdentifier(),
@@ -50,6 +46,7 @@ public void handleStartBuyTransactionCommand(StartBuyTransactionCommand command)
@CommandHandler
public void handleStartSellTransactionCommand(StartSellTransactionCommand command) {
Transaction transaction = new Transaction(
+ command.getTransactionIdentifier(),
TransactionType.SELL,
command.getOrderbookIdentifier(),
command.getPortfolioIdentifier(),
View
86 ...rc/test/java/org/axonframework/samples/trader/orders/command/BuyTradeManagerSagaTest.java
@@ -50,61 +50,71 @@ public void setUp() throws Exception {
@Test
public void testHandle_SellTransactionStarted() throws Exception {
fixture.givenAggregate(transactionIdentifier).published()
- .whenAggregate(transactionIdentifier).publishes(new BuyTransactionStartedEvent(transactionIdentifier,
- orderbookIdentifier,
- portfolioIdentifier,
- TOTAL_ITEMS,
- PRICE_PER_ITEM))
- .expectActiveSagas(1)
- .expectDispatchedCommandsMatching(exactSequenceOf(new ReserveMoneyFromPortfolioCommandMatcher(
+ .whenAggregate(transactionIdentifier).publishes(
+ new BuyTransactionStartedEvent(transactionIdentifier,
+ orderbookIdentifier,
portfolioIdentifier,
- TOTAL_ITEMS * PRICE_PER_ITEM)));
+ TOTAL_ITEMS,
+ PRICE_PER_ITEM))
+ .expectActiveSagas(1)
+ .expectDispatchedCommandsMatching(
+ exactSequenceOf(new ReserveMoneyFromPortfolioCommandMatcher(
+ portfolioIdentifier,
+ TOTAL_ITEMS * PRICE_PER_ITEM)));
}
@Test
public void testHandle_MoneyIsReserved() {
- fixture.givenAggregate(transactionIdentifier).published(new BuyTransactionStartedEvent(transactionIdentifier,
- orderbookIdentifier,
- portfolioIdentifier,
- TOTAL_ITEMS,
- PRICE_PER_ITEM))
- .whenAggregate(portfolioIdentifier).publishes(new MoneyReservedFromPortfolioEvent(portfolioIdentifier, transactionIdentifier,
- TOTAL_ITEMS
- * PRICE_PER_ITEM))
+ fixture.givenAggregate(transactionIdentifier).published(
+ new BuyTransactionStartedEvent(transactionIdentifier,
+ orderbookIdentifier,
+ portfolioIdentifier,
+ TOTAL_ITEMS,
+ PRICE_PER_ITEM))
+ .whenAggregate(portfolioIdentifier).publishes(
+ new MoneyReservedFromPortfolioEvent(portfolioIdentifier, transactionIdentifier,
+ TOTAL_ITEMS
+ * PRICE_PER_ITEM))
.expectActiveSagas(1)
- .expectDispatchedCommandsMatching(exactSequenceOf(new ConfirmTransactionCommandMatcher(
- transactionIdentifier)));
+ .expectDispatchedCommandsMatching(
+ exactSequenceOf(new ConfirmTransactionCommandMatcher(
+ transactionIdentifier)));
}
@Test
public void testHandle_NotEnoughMoneyToReserved() {
- fixture.givenAggregate(transactionIdentifier).published(new BuyTransactionStartedEvent(transactionIdentifier,
- orderbookIdentifier,
- portfolioIdentifier,
- TOTAL_ITEMS,
- PRICE_PER_ITEM))
- .whenAggregate(portfolioIdentifier).publishes(new NotEnoughMoneyInPortfolioToMakeReservationEvent(
- portfolioIdentifier, transactionIdentifier,
- TOTAL_ITEMS * PRICE_PER_ITEM))
+ fixture.givenAggregate(transactionIdentifier).published(
+ new BuyTransactionStartedEvent(transactionIdentifier,
+ orderbookIdentifier,
+ portfolioIdentifier,
+ TOTAL_ITEMS,
+ PRICE_PER_ITEM))
+ .whenAggregate(portfolioIdentifier).publishes(
+ new NotEnoughMoneyInPortfolioToMakeReservationEvent(
+ portfolioIdentifier, transactionIdentifier, TOTAL_ITEMS * PRICE_PER_ITEM))
.expectActiveSagas(0);
}
@Test
public void testHandle_TransactionConfirmed() {
- fixture.givenAggregate(transactionIdentifier).published(new BuyTransactionStartedEvent(transactionIdentifier,
- orderbookIdentifier,
- portfolioIdentifier,
- TOTAL_ITEMS,
- PRICE_PER_ITEM))
- .andThenAggregate(portfolioIdentifier).published(new MoneyReservedFromPortfolioEvent(
- portfolioIdentifier, transactionIdentifier,
- TOTAL_ITEMS * PRICE_PER_ITEM))
- .whenAggregate(transactionIdentifier).publishes(new BuyTransactionConfirmedEvent(transactionIdentifier))
- .expectActiveSagas(1)
- .expectDispatchedCommandsMatching(exactSequenceOf(new CreateBuyOrderCommandMatcher(portfolioIdentifier,
+ fixture.givenAggregate(transactionIdentifier).published(
+ new BuyTransactionStartedEvent(transactionIdentifier,
orderbookIdentifier,
+ portfolioIdentifier,
TOTAL_ITEMS,
- PRICE_PER_ITEM)));
+ PRICE_PER_ITEM))
+ .andThenAggregate(portfolioIdentifier).published(
+ new MoneyReservedFromPortfolioEvent(
+ portfolioIdentifier,
+ transactionIdentifier,
+ TOTAL_ITEMS * PRICE_PER_ITEM))
+ .whenAggregate(transactionIdentifier).publishes(new BuyTransactionConfirmedEvent(transactionIdentifier))
+ .expectActiveSagas(1)
+ .expectDispatchedCommandsMatching(exactSequenceOf(
+ new CreateBuyOrderCommandMatcher(portfolioIdentifier,
+ orderbookIdentifier,
+ TOTAL_ITEMS,
+ PRICE_PER_ITEM)));
}
@Test
View
2 .../org/axonframework/samples/trader/orders/command/PortfolioManagementUserListenerTest.java
@@ -61,7 +61,7 @@ public boolean matches(Object argument) {
if (!(((GenericCommandMessage) argument).getPayload() instanceof CreatePortfolioCommand)) {
return false;
}
- CreatePortfolioCommand createPortfolioCommand = (CreatePortfolioCommand) argument;
+ CreatePortfolioCommand createPortfolioCommand = ((GenericCommandMessage<CreatePortfolioCommand>) argument).getPayload();
return createPortfolioCommand.getUserId().equals(userId);
}
}
View
4 .../java/org/axonframework/samples/trader/orders/command/TransactionCommandHandlingTest.java
@@ -45,15 +45,15 @@ public void setUp() {
@Test
public void testStartBuyTransaction() {
- StartBuyTransactionCommand command = new StartBuyTransactionCommand(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));
}
@Test
public void testStartSellTransaction() {
- StartSellTransactionCommand command = new StartSellTransactionCommand(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));
View
10 ...onframework/samples/trader/orders/command/matchers/AddItemsToPortfolioCommandMatcher.java
@@ -19,13 +19,12 @@
import org.axonframework.samples.trader.orders.api.portfolio.item.AddItemsToPortfolioCommand;
import org.axonframework.samples.trader.tradeengine.api.order.OrderBookId;
import org.axonframework.samples.trader.tradeengine.api.order.PortfolioId;
-import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
/**
* @author Jettro Coenradie
*/
-public class AddItemsToPortfolioCommandMatcher extends BaseMatcher<AddItemsToPortfolioCommand> {
+public class AddItemsToPortfolioCommandMatcher extends BaseCommandMatcher<AddItemsToPortfolioCommand> {
private OrderBookId orderBookIdentifier;
private PortfolioId portfolioIdentifier;
@@ -39,12 +38,7 @@ public AddItemsToPortfolioCommandMatcher(PortfolioId portfolioIdentifier,
}
@Override
- public boolean matches(Object object) {
- if (!(object instanceof AddItemsToPortfolioCommand)) {
- return false;
- }
-
- AddItemsToPortfolioCommand command = (AddItemsToPortfolioCommand) object;
+ protected boolean doMatches(AddItemsToPortfolioCommand command) {
return command.getOrderBookIdentifier().equals(orderBookIdentifier)
&& command.getPortfolioIdentifier().equals(portfolioIdentifier)
&& command.getAmountOfItemsToAdd() == amountOfItemsToAdd;
View
37 ...est/java/org/axonframework/samples/trader/orders/command/matchers/BaseCommandMatcher.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 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.orders.command.matchers;
+
+import org.axonframework.commandhandling.CommandMessage;
+import org.hamcrest.BaseMatcher;
+
+/**
+ * @author Jettro Coenradie
+ */
+public abstract class BaseCommandMatcher<T> extends BaseMatcher<T> {
+ @Override
+ public final boolean matches(Object o) {
+ if (!(o instanceof CommandMessage)) {
+ return false;
+ }
+ CommandMessage<T> message = (CommandMessage<T>) o;
+
+ return doMatches(message.getPayload());
+ }
+
+ protected abstract boolean doMatches(T message);
+}
View
9 ...mples/trader/orders/command/matchers/CancelItemReservationForPortfolioCommandMatcher.java
@@ -19,14 +19,13 @@
import org.axonframework.samples.trader.orders.api.portfolio.item.CancelItemReservationForPortfolioCommand;
import org.axonframework.samples.trader.tradeengine.api.order.OrderBookId;
import org.axonframework.samples.trader.tradeengine.api.order.PortfolioId;
-import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
/**
* @author Jettro Coenradie
*/
public class CancelItemReservationForPortfolioCommandMatcher
- extends BaseMatcher<CancelItemReservationForPortfolioCommand> {
+ extends BaseCommandMatcher<CancelItemReservationForPortfolioCommand> {
private OrderBookId orderBookIdentifier;
private PortfolioId portfolioIdentifier;
@@ -41,11 +40,7 @@ public CancelItemReservationForPortfolioCommandMatcher(OrderBookId orderBookIden
}
@Override
- public boolean matches(Object o) {
- if (!(o instanceof CancelItemReservationForPortfolioCommand)) {
- return false;
- }
- CancelItemReservationForPortfolioCommand command = (CancelItemReservationForPortfolioCommand) o;
+ protected boolean doMatches(CancelItemReservationForPortfolioCommand command) {
return command.getOrderBookIdentifier().equals(orderBookIdentifier)
&& command.getPortfolioIdentifier().equals(portfolioIdentifier)
&& command.getAmountOfItemsToCancel() == amountOfItemsToCancel;
View
10 ...les/trader/orders/command/matchers/CancelMoneyReservationFromPortfolioCommandMatcher.java
@@ -18,14 +18,13 @@
import org.axonframework.samples.trader.orders.api.portfolio.money.CancelMoneyReservationFromPortfolioCommand;
import org.axonframework.samples.trader.tradeengine.api.order.PortfolioId;
-import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
/**
* @author Jettro Coenradie
*/
public class CancelMoneyReservationFromPortfolioCommandMatcher
- extends BaseMatcher<CancelMoneyReservationFromPortfolioCommand> {
+ extends BaseCommandMatcher<CancelMoneyReservationFromPortfolioCommand> {
public CancelMoneyReservationFromPortfolioCommandMatcher(PortfolioId portfolioIdentifier,
long amountOfMoneyToCancel) {
@@ -37,12 +36,7 @@ public CancelMoneyReservationFromPortfolioCommandMatcher(PortfolioId portfolioId
private long amountOfMoneyToCancel;
@Override
- public boolean matches(Object o) {
- if (!(o instanceof CancelMoneyReservationFromPortfolioCommand)) {
- return false;
- }
- CancelMoneyReservationFromPortfolioCommand command = (CancelMoneyReservationFromPortfolioCommand) o;
-
+ protected boolean doMatches(CancelMoneyReservationFromPortfolioCommand command) {
return command.getPortfolioIdentifier().equals(portfolioIdentifier)
&& command.getAmountOfMoneyToCancel() == amountOfMoneyToCancel;
}
View
9 ...axonframework/samples/trader/orders/command/matchers/CancelTransactionCommandMatcher.java
@@ -18,13 +18,12 @@
import org.axonframework.samples.trader.orders.api.transaction.CancelTransactionCommand;
import org.axonframework.samples.trader.tradeengine.api.order.TransactionId;
-import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
/**
* @author Jettro Coenradie
*/
-public class CancelTransactionCommandMatcher extends BaseMatcher<CancelTransactionCommand> {
+public class CancelTransactionCommandMatcher extends BaseCommandMatcher<CancelTransactionCommand> {
private TransactionId transactionIdentifier;
@@ -33,11 +32,7 @@ public CancelTransactionCommandMatcher(TransactionId transactionIdentifier) {
}
@Override
- public boolean matches(Object o) {
- if (!(o instanceof CancelTransactionCommand)) {
- return false;
- }
- CancelTransactionCommand command = (CancelTransactionCommand) o;
+ protected boolean doMatches(CancelTransactionCommand command) {
return command.getTransactionIdentifier().equals(transactionIdentifier);
}
View
9 ...ples/trader/orders/command/matchers/ConfirmItemReservationForPortfolioCommandMatcher.java
@@ -19,14 +19,13 @@
import org.axonframework.samples.trader.orders.api.portfolio.item.ConfirmItemReservationForPortfolioCommand;
import org.axonframework.samples.trader.tradeengine.api.order.OrderBookId;
import org.axonframework.samples.trader.tradeengine.api.order.PortfolioId;
-import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
/**
* @author Jettro Coenradie
*/
public class ConfirmItemReservationForPortfolioCommandMatcher
- extends BaseMatcher<ConfirmItemReservationForPortfolioCommand> {
+ extends BaseCommandMatcher<ConfirmItemReservationForPortfolioCommand> {
private OrderBookId orderbookIdentifier;
private PortfolioId portfolioIdentifier;
@@ -40,11 +39,7 @@ public ConfirmItemReservationForPortfolioCommandMatcher(
}
@Override
- public boolean matches(Object object) {
- if (!(object instanceof ConfirmItemReservationForPortfolioCommand)) {
- return false;
- }
- ConfirmItemReservationForPortfolioCommand command = (ConfirmItemReservationForPortfolioCommand) object;
+ protected boolean doMatches(ConfirmItemReservationForPortfolioCommand command) {
return command.getOrderBookIdentifier().equals(orderbookIdentifier)
&& command.getPortfolioIdentifier().equals(portfolioIdentifier)
&& amountOfConfirmedItems == command.getAmountOfItemsToConfirm();
View
10 ...s/trader/orders/command/matchers/ConfirmMoneyReservationFromPortfolionCommandMatcher.java
@@ -18,14 +18,13 @@
import org.axonframework.samples.trader.orders.api.portfolio.money.ConfirmMoneyReservationFromPortfolionCommand;
import org.axonframework.samples.trader.tradeengine.api.order.PortfolioId;
-import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
/**
* @author Jettro Coenradie
*/
public class ConfirmMoneyReservationFromPortfolionCommandMatcher
- extends BaseMatcher<ConfirmMoneyReservationFromPortfolionCommand> {
+ extends BaseCommandMatcher<ConfirmMoneyReservationFromPortfolionCommand> {
private PortfolioId portfolioIdentifier;
private long amountOfMoneyToconfirm;
@@ -37,12 +36,7 @@ public ConfirmMoneyReservationFromPortfolionCommandMatcher(PortfolioId portfolio
}
@Override
- public boolean matches(Object object) {
- if (!(object instanceof ConfirmMoneyReservationFromPortfolionCommand)) {
- return false;
- }
- ConfirmMoneyReservationFromPortfolionCommand command = (ConfirmMoneyReservationFromPortfolionCommand) object;
-
+ protected boolean doMatches(ConfirmMoneyReservationFromPortfolionCommand command) {
return command.getPortfolioIdentifier().equals(portfolioIdentifier)
&& command.getAmountOfMoneyToConfirmInCents() == amountOfMoneyToconfirm;
}
View
9 ...xonframework/samples/trader/orders/command/matchers/ConfirmTransactionCommandMatcher.java
@@ -18,13 +18,12 @@
import org.axonframework.samples.trader.orders.api.transaction.ConfirmTransactionCommand;
import org.axonframework.samples.trader.tradeengine.api.order.TransactionId;
-import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
/**
* @author Jettro Coenradie
*/
-public class ConfirmTransactionCommandMatcher extends BaseMatcher<ConfirmTransactionCommand> {
+public class ConfirmTransactionCommandMatcher extends BaseCommandMatcher<ConfirmTransactionCommand> {
private TransactionId transactionIdentifier;
@@ -33,11 +32,7 @@ public ConfirmTransactionCommandMatcher(TransactionId transactionIdentifier) {
}
@Override
- public boolean matches(Object o) {
- if (!(o instanceof ConfirmTransactionCommand)) {
- return false;
- }
- ConfirmTransactionCommand command = (ConfirmTransactionCommand) o;
+ protected boolean doMatches(ConfirmTransactionCommand command) {
return command.getTransactionIdentifier().equals(transactionIdentifier);
}
View
10 ...rg/axonframework/samples/trader/orders/command/matchers/CreateBuyOrderCommandMatcher.java
@@ -19,13 +19,12 @@
import org.axonframework.samples.trader.tradeengine.api.order.CreateBuyOrderCommand;
import org.axonframework.samples.trader.tradeengine.api.order.OrderBookId;
import org.axonframework.samples.trader.tradeengine.api.order.PortfolioId;
-import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
/**
* @author Jettro Coenradie
*/
-public class CreateBuyOrderCommandMatcher extends BaseMatcher<CreateBuyOrderCommand> {
+public class CreateBuyOrderCommandMatcher extends BaseCommandMatcher<CreateBuyOrderCommand> {
private OrderBookId orderbookIdentifier;
private PortfolioId portfolioIdentifier;
@@ -39,13 +38,8 @@ public CreateBuyOrderCommandMatcher(PortfolioId portfolioId, OrderBookId orderbo
this.itemPrice = itemPrice;
}
-
@Override
- public boolean matches(Object object) {
- if (!(object instanceof CreateBuyOrderCommand)) {
- return false;
- }
- CreateBuyOrderCommand command = (CreateBuyOrderCommand) object;
+ protected boolean doMatches(CreateBuyOrderCommand command) {
return command.getOrderBookId().equals(orderbookIdentifier)
&& command.getPortfolioId().equals(portfolioIdentifier)
&& tradeCount == command.getTradeCount()
View
10 ...g/axonframework/samples/trader/orders/command/matchers/CreateSellOrderCommandMatcher.java
@@ -19,13 +19,12 @@
import org.axonframework.samples.trader.tradeengine.api.order.CreateSellOrderCommand;
import org.axonframework.samples.trader.tradeengine.api.order.OrderBookId;
import org.axonframework.samples.trader.tradeengine.api.order.PortfolioId;
-import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
/**
* @author Jettro Coenradie
*/
-public class CreateSellOrderCommandMatcher extends BaseMatcher<CreateSellOrderCommand> {
+public class CreateSellOrderCommandMatcher extends BaseCommandMatcher<CreateSellOrderCommand> {
private OrderBookId orderbookIdentifier;
private PortfolioId portfolioIdentifier;
@@ -39,13 +38,8 @@ public CreateSellOrderCommandMatcher(PortfolioId portfolioId, OrderBookId orderb
this.itemPrice = itemPrice;
}
-
@Override
- public boolean matches(Object object) {
- if (!(object instanceof CreateSellOrderCommand)) {
- return false;
- }
- CreateSellOrderCommand command = (CreateSellOrderCommand) object;
+ protected boolean doMatches(CreateSellOrderCommand command) {
return command.getOrderBookId().equals(orderbookIdentifier)
&& command.getPortfolioId().equals(portfolioIdentifier)
&& tradeCount == command.getTradeCount()
View
9 ...amework/samples/trader/orders/command/matchers/DepositMoneyToPortfolioCommandMatcher.java
@@ -18,13 +18,12 @@
import org.axonframework.samples.trader.orders.api.portfolio.money.DepositMoneyToPortfolioCommand;
import org.axonframework.samples.trader.tradeengine.api.order.PortfolioId;
-import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
/**
* @author Jettro Coenradie
*/
-public class DepositMoneyToPortfolioCommandMatcher extends BaseMatcher<DepositMoneyToPortfolioCommand> {
+public class DepositMoneyToPortfolioCommandMatcher extends BaseCommandMatcher<DepositMoneyToPortfolioCommand> {
private long moneyToAddInCents;
private PortfolioId portfolioIdentifier;
@@ -35,11 +34,7 @@ public DepositMoneyToPortfolioCommandMatcher(PortfolioId portfolioIdentifier, lo
}
@Override
- public boolean matches(Object o) {
- if (!(o instanceof DepositMoneyToPortfolioCommand)) {
- return false;
- }
- DepositMoneyToPortfolioCommand command = (DepositMoneyToPortfolioCommand) o;
+ protected boolean doMatches(DepositMoneyToPortfolioCommand command) {
return moneyToAddInCents == command.getMoneyToAddInCents()
&& portfolioIdentifier.equals(command.getPortfolioIdentifier());
}
View
9 ...onframework/samples/trader/orders/command/matchers/ExecutedTransactionCommandMatcher.java
@@ -18,13 +18,12 @@
import org.axonframework.samples.trader.orders.api.transaction.ExecutedTransactionCommand;
import org.axonframework.samples.trader.tradeengine.api.order.TransactionId;
-import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
/**
* @author Jettro Coenradie
*/
-public class ExecutedTransactionCommandMatcher extends BaseMatcher<ExecutedTransactionCommand> {
+public class ExecutedTransactionCommandMatcher extends BaseCommandMatcher<ExecutedTransactionCommand> {
private TransactionId transactionIdentifier;
private long amountOfItems;
@@ -37,11 +36,7 @@ public ExecutedTransactionCommandMatcher(long amountOfItems, long itemPrice, Tra
}
@Override
- public boolean matches(Object object) {
- if (!(object instanceof ExecutedTransactionCommand)) {
- return false;
- }
- ExecutedTransactionCommand command = (ExecutedTransactionCommand) object;
+ protected boolean doMatches(ExecutedTransactionCommand command) {
return command.getTransactionIdentifier().equals(transactionIdentifier)
&& command.getAmountOfItems() == amountOfItems
&& command.getItemPrice() == itemPrice;
View
9 ...ework/samples/trader/orders/command/matchers/ReserveMoneyFromPortfolioCommandMatcher.java
@@ -18,13 +18,12 @@
import org.axonframework.samples.trader.orders.api.portfolio.money.ReserveMoneyFromPortfolioCommand;
import org.axonframework.samples.trader.tradeengine.api.order.PortfolioId;
-import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
/**
* @author Jettro Coenradie
*/
-public class ReserveMoneyFromPortfolioCommandMatcher extends BaseMatcher<ReserveMoneyFromPortfolioCommand> {
+public class ReserveMoneyFromPortfolioCommandMatcher extends BaseCommandMatcher<ReserveMoneyFromPortfolioCommand> {
private PortfolioId portfolioIdentifier;
private long amountOfMoneyToReserve;
@@ -35,11 +34,7 @@ public ReserveMoneyFromPortfolioCommandMatcher(PortfolioId portfolioIdentifier,
}
@Override
- public boolean matches(Object o) {
- if (!(o instanceof ReserveMoneyFromPortfolioCommand)) {
- return false;
- }
- ReserveMoneyFromPortfolioCommand command = (ReserveMoneyFromPortfolioCommand) o;
+ protected boolean doMatches(ReserveMoneyFromPortfolioCommand command) {
return command.getPortfolioIdentifier().equals(portfolioIdentifier)
&& command.getAmountOfMoneyToReserve() == amountOfMoneyToReserve;
}
View
9 ...org/axonframework/samples/trader/orders/command/matchers/ReservedItemsCommandMatcher.java
@@ -19,13 +19,12 @@
import org.axonframework.samples.trader.orders.api.portfolio.item.ReserveItemsCommand;
import org.axonframework.samples.trader.tradeengine.api.order.OrderBookId;
import org.axonframework.samples.trader.tradeengine.api.order.PortfolioId;
-import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
/**
* @author Jettro Coenradie
*/
-public class ReservedItemsCommandMatcher extends BaseMatcher<ReserveItemsCommand> {
+public class ReservedItemsCommandMatcher extends BaseCommandMatcher<ReserveItemsCommand> {
private OrderBookId orderbookIdentifier;
private PortfolioId portfolioIdentifier;
@@ -39,11 +38,7 @@ public ReservedItemsCommandMatcher(OrderBookId orderbookIdentifier, PortfolioId
}
@Override
- public boolean matches(Object o) {
- if (!(o instanceof ReserveItemsCommand)) {
- return false;
- }
- ReserveItemsCommand command = (ReserveItemsCommand) o;
+ protected boolean doMatches(ReserveItemsCommand command) {
return command.getOrderBookIdentifier().equals(orderbookIdentifier)
&& command.getPortfolioIdentifier().equals(portfolioIdentifier)
&& amountOfReservedItems == command.getAmountOfItemsToReserve();
View
13 query/src/main/java/org/axonframework/samples/trader/query/orderbook/OrderBookListener.java
@@ -17,6 +17,8 @@
package org.axonframework.samples.trader.query.orderbook;
import org.axonframework.eventhandling.annotation.EventHandler;
+import org.axonframework.samples.trader.company.api.OrderBookAddedToCompanyEvent;
+import org.axonframework.samples.trader.query.company.CompanyEntry;
import org.axonframework.samples.trader.query.company.repositories.CompanyQueryRepository;
import org.axonframework.samples.trader.query.orderbook.repositories.OrderBookQueryRepository;
import org.axonframework.samples.trader.query.tradeexecuted.TradeExecutedEntry;
@@ -40,13 +42,12 @@
@EventHandler
- public void handleOrderBookCreatedEvent(OrderBookCreatedEvent event) {
-// TODO jettro: I must add company info to the order book? Or make some other combination of the two
-// CompanyEntry companyEntry = companyRepository.findOne(event.getOrderBookIdentifier());
+ public void handleOrderBookAddedToCompanyEvent(OrderBookAddedToCompanyEvent event) {
+ CompanyEntry companyEntry = companyRepository.findOne(event.getCompanyId().toString());
OrderBookEntry orderBookEntry = new OrderBookEntry();
-// orderBookEntry.setCompanyIdentifier(event.getCompanyIdentifier().asString());
-// orderBookEntry.setCompanyName(companyEntry.getName());
- orderBookEntry.setIdentifier(event.getOrderBookIdentifier().toString());
+ orderBookEntry.setCompanyIdentifier(event.getCompanyId().toString());
+ orderBookEntry.setCompanyName(companyEntry.getName());
+ orderBookEntry.setIdentifier(event.getOrderBookId().toString());
orderBookRepository.save(orderBookEntry);
}
View
14 ...va/org/axonframework/samples/trader/query/orderbook/OrderBookListenerIntegrationTest.java
@@ -16,8 +16,11 @@
package org.axonframework.samples.trader.query.orderbook;
+import org.axonframework.samples.trader.company.api.CompanyCreatedEvent;
import org.axonframework.samples.trader.company.api.CompanyId;
+import org.axonframework.samples.trader.company.api.OrderBookAddedToCompanyEvent;
import org.axonframework.samples.trader.query.company.CompanyEntry;
+import org.axonframework.samples.trader.query.company.CompanyListener;
import org.axonframework.samples.trader.query.company.repositories.CompanyQueryRepository;
import org.axonframework.samples.trader.query.orderbook.repositories.OrderBookQueryRepository;
import org.axonframework.samples.trader.query.tradeexecuted.TradeExecutedEntry;
@@ -59,13 +62,18 @@
PortfolioId portfolioId = new PortfolioId();
TransactionId transactionId = new TransactionId();
OrderBookId orderBookId = new OrderBookId();
+ CompanyId companyId = new CompanyId();
@Before
public void setUp() throws Exception {
mongoTemplate.dropCollection(OrderBookEntry.class);
mongoTemplate.dropCollection(CompanyEntry.class);
mongoTemplate.dropCollection(TradeExecutedEntry.class);
+ CompanyListener companyListener = new CompanyListener();
+ companyListener.setCompanyRepository(companyRepository);
+ companyListener.handleCompanyCreatedEvent(new CompanyCreatedEvent(companyId, "Test Company", 100, 100));
+
orderBookListener = new OrderBookListener();
orderBookListener.setCompanyRepository(companyRepository);
orderBookListener.setOrderBookRepository(orderBookRepository);
@@ -74,9 +82,9 @@ public void setUp() throws Exception {
@Test
public void testHandleOrderBookCreatedEvent() throws Exception {
- OrderBookCreatedEvent event = new OrderBookCreatedEvent(orderBookId);
+ OrderBookAddedToCompanyEvent event = new OrderBookAddedToCompanyEvent(companyId, orderBookId);
- orderBookListener.handleOrderBookCreatedEvent(event);
+ orderBookListener.handleOrderBookAddedToCompanyEvent(event);
Iterable<OrderBookEntry> all = orderBookRepository.findAll();
OrderBookEntry orderBookEntry = all.iterator().next();
assertNotNull("The first item of the iterator for orderbooks should not be null", orderBookEntry);
@@ -104,7 +112,7 @@ public void testHandleSellOrderPlaced() throws Exception {
CompanyEntry company = createCompany();
OrderBookEntry orderBook = createOrderBook(company);
- OrderBookId orderBookId = new OrderBookId();
+ OrderBookId orderBookId = new OrderBookId(orderBook.getIdentifier());
SellOrderPlacedEvent event = new SellOrderPlacedEvent(orderBookId, orderId, transactionId, 300, 100, portfolioId);
orderBookListener.handleSellOrderPlaced(event);
View
4 ...ain/java/org/axonframework/samples/trader/tradeengine/api/order/AbstractOrderCommand.java
@@ -30,14 +30,14 @@
private long itemPrice;
private OrderId orderId;
- protected AbstractOrderCommand(PortfolioId portfolioId, OrderBookId orderBookId,
+ protected AbstractOrderCommand(OrderId orderId, PortfolioId portfolioId, OrderBookId orderBookId,
TransactionId transactionId, long tradeCount, long itemPrice) {
this.portfolioId = portfolioId;
this.orderBookId = orderBookId;
this.tradeCount = tradeCount;
this.itemPrice = itemPrice;
this.transactionId = transactionId;
- this.orderId = new OrderId();
+ this.orderId = orderId;
}
public PortfolioId getPortfolioId() {
View
4 ...in/java/org/axonframework/samples/trader/tradeengine/api/order/CreateBuyOrderCommand.java
@@ -23,8 +23,8 @@
*/
public class CreateBuyOrderCommand extends AbstractOrderCommand {
- public CreateBuyOrderCommand(PortfolioId portfolioId, OrderBookId orderBookId,
+ public CreateBuyOrderCommand(OrderId orderId, PortfolioId portfolioId, OrderBookId orderBookId,
TransactionId transactionId, long tradeCount, long itemPrice) {
- super(portfolioId, orderBookId, transactionId, tradeCount, itemPrice);
+ super(orderId, portfolioId, orderBookId, transactionId, tradeCount, itemPrice);
}
}
View
4 ...n/java/org/axonframework/samples/trader/tradeengine/api/order/CreateSellOrderCommand.java
@@ -23,8 +23,8 @@
*/
public class CreateSellOrderCommand extends AbstractOrderCommand {
- public CreateSellOrderCommand(PortfolioId portfolioId, OrderBookId orderBookId,
+ public CreateSellOrderCommand(OrderId orderId, PortfolioId portfolioId, OrderBookId orderBookId,
TransactionId transactionId, long tradeCount, long itemPrice) {
- super(portfolioId, orderBookId, transactionId, tradeCount, itemPrice);
+ super(orderId, portfolioId, orderBookId, transactionId, tradeCount, itemPrice);
}
}
View
2 trade-engine/src/main/java/org/axonframework/samples/trader/tradeengine/command/Order.java
@@ -32,12 +32,12 @@
*/
class Order extends AbstractAnnotatedEntity {
+ private OrderId orderId;
private TransactionId transactionId;
private final long itemPrice;
private final long tradeCount;
private final PortfolioId portfolioId;
private long itemsRemaining;
- private OrderId orderId;
public Order(OrderId orderId, TransactionId transactionId, long itemPrice, long tradeCount, PortfolioId portfolioId) {
this.orderId = orderId;
View
13 ...-engine/src/main/java/org/axonframework/samples/trader/tradeengine/command/OrderBook.java
@@ -19,6 +19,7 @@
import org.axonframework.eventhandling.annotation.EventHandler;
import org.axonframework.eventsourcing.AbstractEventSourcedEntity;
import org.axonframework.eventsourcing.annotation.AbstractAnnotatedAggregateRoot;
+import org.axonframework.eventsourcing.annotation.AggregateIdentifier;
import org.axonframework.samples.trader.tradeengine.api.order.*;
import java.util.*;
@@ -29,12 +30,17 @@
class OrderBook extends AbstractAnnotatedAggregateRoot {
private static final long serialVersionUID = 6778782949492587631L;
+ @AggregateIdentifier
private OrderBookId orderBookId;
+
private SortedSet<Order> buyOrders = new TreeSet<Order>(new OrderComparator());
private SortedSet<Order> sellOrders = new TreeSet<Order>(new OrderComparator());
+ @SuppressWarnings("UnusedDeclaration")
+ protected OrderBook() {
+ }
+
public OrderBook(OrderBookId identifier) {
- this.orderBookId = identifier;
apply(new OrderBookCreatedEvent(identifier));
}
@@ -77,6 +83,11 @@ private void executeTrades() {
}
@EventHandler
+ protected void onOrderBookCreated(OrderBookCreatedEvent event) {
+ this.orderBookId = event.getOrderBookIdentifier();
+ }
+
+ @EventHandler
protected void onBuyPlaced(BuyOrderPlacedEvent event) {
buyOrders.add(new Order(event.getOrderId(),
event.getTransactionIdentifier(),
View
20 ...ava/org/axonframework/samples/trader/tradeengine/command/OrderBookCommandHandlerTest.java
@@ -39,18 +39,22 @@ public void setUp() {
@Test
public void testSimpleTradeExecution() {
- OrderId buyOrder = new OrderId();
+ OrderId sellOrder = new OrderId();
PortfolioId sellingUser = new PortfolioId();
TransactionId sellingTransaction = new TransactionId();
OrderBookId orderBookId = new OrderBookId();
- CreateSellOrderCommand orderCommand = new CreateSellOrderCommand(sellingUser,
+ CreateSellOrderCommand orderCommand = new CreateSellOrderCommand(sellOrder,
+ sellingUser,
orderBookId,
sellingTransaction,
100,
100);
- OrderId sellOrder = orderCommand.getOrderId();
+
+ OrderId buyOrder = new OrderId();
TransactionId buyTransactionId = new TransactionId();
- fixture.given(new BuyOrderPlacedEvent(orderBookId, buyOrder, buyTransactionId, 200, 100, new PortfolioId()))
+ PortfolioId buyPortfolioId = new PortfolioId();
+ fixture.given(new OrderBookCreatedEvent(orderBookId),
+ new BuyOrderPlacedEvent(orderBookId, buyOrder, buyTransactionId, 200, 100, buyPortfolioId))
.when(orderCommand)
.expectEvents(new SellOrderPlacedEvent(orderBookId, sellOrder, sellingTransaction, 100, 100, sellingUser),
new TradeExecutedEvent(orderBookId,
@@ -64,6 +68,7 @@ public void testSimpleTradeExecution() {
@Test
public void testMassiveSellerTradeExecution() {
+ OrderId sellOrderId = new OrderId();
OrderId buyOrder1 = new OrderId();
OrderId buyOrder2 = new OrderId();
OrderId buyOrder3 = new OrderId();
@@ -76,13 +81,14 @@ public void testMassiveSellerTradeExecution() {
OrderBookId orderBookId = new OrderBookId();
- CreateSellOrderCommand sellOrder = new CreateSellOrderCommand(sellingUser,
+ CreateSellOrderCommand sellOrder = new CreateSellOrderCommand(sellOrderId,
+ sellingUser,
orderBookId,
sellingTransaction,
200,
100);
- OrderId sellOrderId = sellOrder.getOrderId();
- fixture.given(new BuyOrderPlacedEvent(orderBookId, buyOrder1, buyTransaction1, 100, 100, new PortfolioId()),
+ fixture.given(new OrderBookCreatedEvent(orderBookId),
+ new BuyOrderPlacedEvent(orderBookId, buyOrder1, buyTransaction1, 100, 100, new PortfolioId()),
new BuyOrderPlacedEvent(orderBookId, buyOrder2, buyTransaction2, 66, 120, new PortfolioId()),
new BuyOrderPlacedEvent(orderBookId, buyOrder3, buyTransaction3, 44, 140, new PortfolioId()))
.when(sellOrder)
View
2 users/src/main/java/org/axonframework/samples/trader/users/command/UserCommandHandler.java
@@ -39,7 +39,7 @@
@CommandHandler
public UserId handleCreateUser(CreateUserCommand command) {
- UserId identifier = new UserId();
+ UserId identifier = command.getUserId();
User user = new User(identifier, command.getUsername(), command.getName(), command.getPassword());
repository.add(user);
return identifier;
View
5 web-ui/src/main/java/org/axonframework/samples/trader/webui/companies/CompanyController.java
@@ -32,6 +32,7 @@
import org.axonframework.samples.trader.query.users.repositories.UserQueryRepository;
import org.axonframework.samples.trader.tradeengine.api.order.OrderBookId;
import org.axonframework.samples.trader.tradeengine.api.order.PortfolioId;
+import org.axonframework.samples.trader.tradeengine.api.order.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;
@@ -132,7 +133,7 @@ public String sell(@ModelAttribute("order") @Valid SellOrder order, BindingResul
return "company/sell";
}
- StartSellTransactionCommand command = new StartSellTransactionCommand(
+ StartSellTransactionCommand command = new StartSellTransactionCommand(new TransactionId(),
new OrderBookId(bookEntry.getIdentifier()),
new PortfolioId(portfolioEntry.getIdentifier()),
order.getTradeCount(),
@@ -162,7 +163,7 @@ public String buy(@ModelAttribute("order") @Valid BuyOrder order, BindingResult
return "company/buy";
}
- StartBuyTransactionCommand command = new StartBuyTransactionCommand(
+ StartBuyTransactionCommand command = new StartBuyTransactionCommand(new TransactionId(),
new OrderBookId(bookEntry.getIdentifier()),
new PortfolioId(portfolioEntry.getIdentifier()),
order.getTradeCount(),

0 comments on commit 7183fec

Please sign in to comment.