Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
Fixed all the unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jettro committed May 25, 2012
1 parent 239e7a0 commit 7183fec
Show file tree
Hide file tree
Showing 40 changed files with 296 additions and 180 deletions.
7 changes: 7 additions & 0 deletions companies-api/pom.xml
Expand Up @@ -36,6 +36,13 @@
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>


<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>axon-trader-trade-engine-api</artifactId>
<version>${project.version}</version>
</dependency>


<!-- External dependencies --> <!-- External dependencies -->
<dependency> <dependency>
<groupId>org.axonframework</groupId> <groupId>org.axonframework</groupId>
Expand Down
@@ -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;
}
}
@@ -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;
}
}
Expand Up @@ -21,6 +21,8 @@
import org.axonframework.eventsourcing.annotation.AggregateIdentifier; import org.axonframework.eventsourcing.annotation.AggregateIdentifier;
import org.axonframework.samples.trader.company.api.CompanyCreatedEvent; import org.axonframework.samples.trader.company.api.CompanyCreatedEvent;
import org.axonframework.samples.trader.company.api.CompanyId; 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 * @author Jettro Coenradie
Expand All @@ -39,6 +41,10 @@ public Company(CompanyId companyId, String name, long value, long amountOfShares
apply(new CompanyCreatedEvent(companyId, name, value, amountOfShares)); apply(new CompanyCreatedEvent(companyId, name, value, amountOfShares));
} }


public void addOrderBook(OrderBookId orderBookId) {
apply(new OrderBookAddedToCompanyEvent(companyId, orderBookId));
}

@Override @Override
public CompanyId getIdentifier() { public CompanyId getIdentifier() {
return this.companyId; return this.companyId;
Expand All @@ -48,5 +54,4 @@ public CompanyId getIdentifier() {
public void handle(CompanyCreatedEvent event) { public void handle(CompanyCreatedEvent event) {
this.companyId = event.getCompanyIdentifier(); this.companyId = event.getCompanyIdentifier();
} }

} }
Expand Up @@ -18,6 +18,7 @@


import org.axonframework.commandhandling.annotation.CommandHandler; import org.axonframework.commandhandling.annotation.CommandHandler;
import org.axonframework.repository.Repository; import org.axonframework.repository.Repository;
import org.axonframework.samples.trader.company.api.AddOrderBookToCompanyCommand;
import org.axonframework.samples.trader.company.api.CreateCompanyCommand; import org.axonframework.samples.trader.company.api.CreateCompanyCommand;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
Expand All @@ -38,6 +39,12 @@ public void handleCreateCompany(CreateCompanyCommand command) {
repository.add(company); repository.add(company);
} }


@CommandHandler
public void handleAddOrderBook(AddOrderBookToCompanyCommand command) {
Company company = repository.load(command.getCompanyId());
company.addOrderBook(command.getOrderBookId());
}

@Autowired @Autowired
@Qualifier("companyRepository") @Qualifier("companyRepository")
public void setRepository(Repository<Company> companyRepository) { public void setRepository(Repository<Company> companyRepository) {
Expand Down
Expand Up @@ -38,7 +38,6 @@ public void setUp() {
CompanyCommandHandler commandHandler = new CompanyCommandHandler(); CompanyCommandHandler commandHandler = new CompanyCommandHandler();
commandHandler.setRepository(fixture.getRepository()); commandHandler.setRepository(fixture.getRepository());
fixture.registerAnnotatedCommandHandler(commandHandler); fixture.registerAnnotatedCommandHandler(commandHandler);
// fixture.setAggregateIdentifier(new CompanyId());
} }


@Test @Test
Expand Down
Expand Up @@ -18,19 +18,22 @@


import org.axonframework.samples.trader.tradeengine.api.order.OrderBookId; 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.PortfolioId;
import org.axonframework.samples.trader.tradeengine.api.order.TransactionId;


/** /**
* @author Jettro Coenradie * @author Jettro Coenradie
*/ */
public abstract class AbstractStartTransactionCommand { public abstract class AbstractStartTransactionCommand {


private TransactionId transactionId;
private OrderBookId orderbookIdentifier; private OrderBookId orderbookIdentifier;
private PortfolioId portfolioIdentifier; private PortfolioId portfolioIdentifier;
private long tradeCount; private long tradeCount;
private long itemPrice; private long itemPrice;


public AbstractStartTransactionCommand(OrderBookId orderbookIdentifier, public AbstractStartTransactionCommand(TransactionId transactionId, OrderBookId orderbookIdentifier,
PortfolioId portfolioIdentifier, long tradeCount, long itemPrice) { PortfolioId portfolioIdentifier, long tradeCount, long itemPrice) {
this.transactionId = transactionId;
this.itemPrice = itemPrice; this.itemPrice = itemPrice;
this.orderbookIdentifier = orderbookIdentifier; this.orderbookIdentifier = orderbookIdentifier;
this.portfolioIdentifier = portfolioIdentifier; this.portfolioIdentifier = portfolioIdentifier;
Expand All @@ -49,6 +52,10 @@ public PortfolioId getPortfolioIdentifier() {
return portfolioIdentifier; return portfolioIdentifier;
} }


public TransactionId getTransactionIdentifier() {
return transactionId;
}

public long getTradeCount() { public long getTradeCount() {
return tradeCount; return tradeCount;
} }
Expand Down
Expand Up @@ -18,13 +18,14 @@


import org.axonframework.samples.trader.tradeengine.api.order.OrderBookId; 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.PortfolioId;
import org.axonframework.samples.trader.tradeengine.api.order.TransactionId;


/** /**
* @author Jettro Coenradie * @author Jettro Coenradie
*/ */
public class StartBuyTransactionCommand extends AbstractStartTransactionCommand { public class StartBuyTransactionCommand extends AbstractStartTransactionCommand {


public StartBuyTransactionCommand(OrderBookId orderbookIdentifier, PortfolioId portfolioIdentifier, long tradeCount, long itemPrice) { public StartBuyTransactionCommand(TransactionId transactionId, OrderBookId orderbookIdentifier, PortfolioId portfolioIdentifier, long tradeCount, long itemPrice) {
super(orderbookIdentifier, portfolioIdentifier, tradeCount, itemPrice); super(transactionId, orderbookIdentifier, portfolioIdentifier, tradeCount, itemPrice);
} }
} }
Expand Up @@ -18,13 +18,14 @@


import org.axonframework.samples.trader.tradeengine.api.order.OrderBookId; 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.PortfolioId;
import org.axonframework.samples.trader.tradeengine.api.order.TransactionId;


/** /**
* @author Jettro Coenradie * @author Jettro Coenradie
*/ */
public class StartSellTransactionCommand extends AbstractStartTransactionCommand { public class StartSellTransactionCommand extends AbstractStartTransactionCommand {


public StartSellTransactionCommand(OrderBookId orderbookIdentifier, PortfolioId portfolioIdentifier, long tradeCount, long itemPrice) { public StartSellTransactionCommand(TransactionId transactionId, OrderBookId orderbookIdentifier, PortfolioId portfolioIdentifier, long tradeCount, long itemPrice) {
super(orderbookIdentifier, portfolioIdentifier, tradeCount, itemPrice); super(transactionId, orderbookIdentifier, portfolioIdentifier, tradeCount, itemPrice);
} }
} }
Expand Up @@ -25,6 +25,7 @@
import org.axonframework.samples.trader.orders.api.portfolio.money.*; import org.axonframework.samples.trader.orders.api.portfolio.money.*;
import org.axonframework.samples.trader.orders.api.transaction.*; 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.CreateBuyOrderCommand;
import org.axonframework.samples.trader.tradeengine.api.order.OrderId;
import org.axonframework.samples.trader.tradeengine.api.order.TradeExecutedEvent; import org.axonframework.samples.trader.tradeengine.api.order.TradeExecutedEvent;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -96,7 +97,7 @@ public void handle(NotEnoughMoneyInPortfolioToMakeReservationEvent event) {
@SagaEventHandler(associationProperty = "transactionIdentifier") @SagaEventHandler(associationProperty = "transactionIdentifier")
public void handle(BuyTransactionConfirmedEvent event) { public void handle(BuyTransactionConfirmedEvent event) {
logger.debug("Buy Transaction {} is approved to make the buy order", event.getTransactionIdentifier()); 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(), getOrderbookIdentifier(),
getTransactionIdentifier(), getTransactionIdentifier(),
getTotalItems(), getTotalItems(),
Expand Down
Expand Up @@ -24,6 +24,7 @@
import org.axonframework.samples.trader.orders.api.portfolio.money.DepositMoneyToPortfolioCommand; import org.axonframework.samples.trader.orders.api.portfolio.money.DepositMoneyToPortfolioCommand;
import org.axonframework.samples.trader.orders.api.transaction.*; 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.CreateSellOrderCommand;
import org.axonframework.samples.trader.tradeengine.api.order.OrderId;
import org.axonframework.samples.trader.tradeengine.api.order.TradeExecutedEvent; import org.axonframework.samples.trader.tradeengine.api.order.TradeExecutedEvent;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -83,7 +84,8 @@ public void handle(NotEnoughItemsAvailableToReserveInPortfolio event) {
public void handle(SellTransactionConfirmedEvent event) { public void handle(SellTransactionConfirmedEvent event) {
logger.debug("Sell Transaction {} is approved to make the sell order", event.getTransactionIdentifier()); 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(), getOrderbookIdentifier(),
getTransactionIdentifier(), getTransactionIdentifier(),
getTotalItems(), getTotalItems(),
Expand Down
Expand Up @@ -41,7 +41,8 @@ public class Transaction extends AbstractAnnotatedAggregateRoot {
protected Transaction() { protected Transaction() {
} }


public Transaction(TransactionType type, public Transaction(TransactionId transactionId,
TransactionType type,
OrderBookId orderbookIdentifier, OrderBookId orderbookIdentifier,
PortfolioId portfolioIdentifier, PortfolioId portfolioIdentifier,
long amountOfItems, long amountOfItems,
Expand Down
Expand Up @@ -18,12 +18,7 @@


import org.axonframework.commandhandling.annotation.CommandHandler; import org.axonframework.commandhandling.annotation.CommandHandler;
import org.axonframework.repository.Repository; import org.axonframework.repository.Repository;
import org.axonframework.samples.trader.orders.api.transaction.CancelTransactionCommand; import org.axonframework.samples.trader.orders.api.transaction.*;
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.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
Expand All @@ -39,6 +34,7 @@ public class TransactionCommandHandler {
@CommandHandler @CommandHandler
public void handleStartBuyTransactionCommand(StartBuyTransactionCommand command) { public void handleStartBuyTransactionCommand(StartBuyTransactionCommand command) {
Transaction transaction = new Transaction( Transaction transaction = new Transaction(
command.getTransactionIdentifier(),
TransactionType.BUY, TransactionType.BUY,
command.getOrderbookIdentifier(), command.getOrderbookIdentifier(),
command.getPortfolioIdentifier(), command.getPortfolioIdentifier(),
Expand All @@ -50,6 +46,7 @@ public void handleStartBuyTransactionCommand(StartBuyTransactionCommand command)
@CommandHandler @CommandHandler
public void handleStartSellTransactionCommand(StartSellTransactionCommand command) { public void handleStartSellTransactionCommand(StartSellTransactionCommand command) {
Transaction transaction = new Transaction( Transaction transaction = new Transaction(
command.getTransactionIdentifier(),
TransactionType.SELL, TransactionType.SELL,
command.getOrderbookIdentifier(), command.getOrderbookIdentifier(),
command.getPortfolioIdentifier(), command.getPortfolioIdentifier(),
Expand Down

0 comments on commit 7183fec

Please sign in to comment.