@Test public void testBuyOrder() { final TransactionId transactionId = new TransactionId(); final OrderBookId orderBookId = new OrderBookId(); final CoinId coinId = new CoinId("BTC"); final PortfolioId portfolioId = new PortfolioId(); CurrencyPair currencyPair = CurrencyPair.BTC_CNY; BigMoney price = BigMoney.of(currencyPair.getCounterCurrencyUnit(), 100); BigMoney amount = BigMoney.of(currencyPair.getBaseCurrencyUnit(), 300); final StartBuyTransactionCommand command = new StartBuyTransactionCommand(transactionId, coinId, currencyPair, orderBookId, portfolioId, amount, price); CommandGateway gateway = mock(CommandGateway.class); doNothing().when(gateway).send(eq(command)); TradeServiceFacadeImpl facade = new TradeServiceFacadeImpl(); facade.setCommandGateway(gateway); facade.buyOrder(transactionId, coinId.toString(), currencyPair, orderBookId.toString(), portfolioId.toString(), amount, price); verify(gateway).send(eq(command)); }
@Override public void buyOrder(final TransactionId transactionId, String coinId, CurrencyPair currencyPair, String orderBookId, String portfolioId, BigMoney tradeAmount, BigMoney price) { StartBuyTransactionCommand command = new StartBuyTransactionCommand( transactionId, new CoinId(coinId), currencyPair, new OrderBookId(orderBookId), new PortfolioId(portfolioId), tradeAmount, price, currentTime()); commandGateway.send(command); }
TradeServiceFacadeImpl implements TradeServiceFacade { @Override public void buyOrder(final TransactionId transactionId, String coinId, CurrencyPair currencyPair, String orderBookId, String portfolioId, BigMoney tradeAmount, BigMoney price) { StartBuyTransactionCommand command = new StartBuyTransactionCommand( transactionId, new CoinId(coinId), currencyPair, new OrderBookId(orderBookId), new PortfolioId(portfolioId), tradeAmount, price, currentTime()); commandGateway.send(command); } }
TradeServiceFacadeImpl implements TradeServiceFacade { @Override public void buyOrder(final TransactionId transactionId, String coinId, CurrencyPair currencyPair, String orderBookId, String portfolioId, BigMoney tradeAmount, BigMoney price) { StartBuyTransactionCommand command = new StartBuyTransactionCommand( transactionId, new CoinId(coinId), currencyPair, new OrderBookId(orderBookId), new PortfolioId(portfolioId), tradeAmount, price, currentTime()); commandGateway.send(command); }  }
TradeServiceFacadeImpl implements TradeServiceFacade { @Override public void buyOrder(final TransactionId transactionId, String coinId, CurrencyPair currencyPair, String orderBookId, String portfolioId, BigMoney tradeAmount, BigMoney price) { StartBuyTransactionCommand command = new StartBuyTransactionCommand( transactionId, new CoinId(coinId), currencyPair, new OrderBookId(orderBookId), new PortfolioId(portfolioId), tradeAmount, price, currentTime()); commandGateway.send(command); }  @Override OrderBookEntry loadOrderBookByCurrencyPair(CurrencyPair currencyPair); CoinEntry loadCoin(String coinId); @Override BigMoney calculateSellOrderEffectiveAmount(SellOrder order); @Override BigMoney calculateBuyOrderEffectiveAmount(BuyOrder order); @Override BuyOrder prepareBuyOrder(String coinId,
                                    CurrencyPair currencyPair,
                                    OrderBookEntry orderBookEntry,
                                    PortfolioEntry portfolioEntry); @Override SellOrder prepareSellOrder(String coinId,
                                      CurrencyPair currencyPair,
                                      OrderBookEntry orderBookEntry,
                                      PortfolioEntry portfolioEntry); @Override List<TradeExecutedEntry> findExecutedTrades(String orderBookIdentifier); @Override List<OrderEntry> findUserActiveOrders(String userId, String orderBookId); @Override List<PriceAggregate> findOrderAggregatedPrice(String orderBookIdentifier,
                                                         OrderType type,
                                                         Date toDate); @Override List<OrderEntry> findOrderForOrderBook(String orderBookIdentifier,
                                                  OrderType type,
                                                  OrderStatus orderStatus,
                                                  Pageable pageable); @Override void sellOrder(final TransactionId transactionId,
                          String coinId,
                          CurrencyPair currencyPair,
                          String orderBookId,
                          String portfolioId,
                          BigMoney tradeAmount,
                          BigMoney price); @Override void buyOrder(final TransactionId transactionId,
                         String coinId,
                         CurrencyPair currencyPair,
                         String orderBookId,
                         String portfolioId,
                         BigMoney tradeAmount,
                         BigMoney price); @Override void refreshOrderBookPrice(); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserServiceFacade(UserServiceFacade userServiceFacade); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setCoinRepository(CoinQueryRepository coinRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setOrderBookRepository(OrderBookQueryRepository orderBookRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setTradeExecutedRepository(TradeExecutedQueryRepository tradeExecutedRepository); @Autowired void setCommandGateway(CommandGateway commandGateway); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setOrderQueryRepository(OrderQueryRepository orderQueryRepository); @Autowired void setCommissionPolicyFactory(CommissionPolicyFactory commissionPolicyFactory); }
TradeServiceFacadeImpl implements TradeServiceFacade { @Override public void buyOrder(final TransactionId transactionId, String coinId, CurrencyPair currencyPair, String orderBookId, String portfolioId, BigMoney tradeAmount, BigMoney price) { StartBuyTransactionCommand command = new StartBuyTransactionCommand( transactionId, new CoinId(coinId), currencyPair, new OrderBookId(orderBookId), new PortfolioId(portfolioId), tradeAmount, price, currentTime()); commandGateway.send(command); }  @Override OrderBookEntry loadOrderBookByCurrencyPair(CurrencyPair currencyPair); CoinEntry loadCoin(String coinId); @Override BigMoney calculateSellOrderEffectiveAmount(SellOrder order); @Override BigMoney calculateBuyOrderEffectiveAmount(BuyOrder order); @Override BuyOrder prepareBuyOrder(String coinId,
                                    CurrencyPair currencyPair,
                                    OrderBookEntry orderBookEntry,
                                    PortfolioEntry portfolioEntry); @Override SellOrder prepareSellOrder(String coinId,
                                      CurrencyPair currencyPair,
                                      OrderBookEntry orderBookEntry,
                                      PortfolioEntry portfolioEntry); @Override List<TradeExecutedEntry> findExecutedTrades(String orderBookIdentifier); @Override List<OrderEntry> findUserActiveOrders(String userId, String orderBookId); @Override List<PriceAggregate> findOrderAggregatedPrice(String orderBookIdentifier,
                                                         OrderType type,
                                                         Date toDate); @Override List<OrderEntry> findOrderForOrderBook(String orderBookIdentifier,
                                                  OrderType type,
                                                  OrderStatus orderStatus,
                                                  Pageable pageable); @Override void sellOrder(final TransactionId transactionId,
                          String coinId,
                          CurrencyPair currencyPair,
                          String orderBookId,
                          String portfolioId,
                          BigMoney tradeAmount,
                          BigMoney price); @Override void buyOrder(final TransactionId transactionId,
                         String coinId,
                         CurrencyPair currencyPair,
                         String orderBookId,
                         String portfolioId,
                         BigMoney tradeAmount,
                         BigMoney price); @Override void refreshOrderBookPrice(); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserServiceFacade(UserServiceFacade userServiceFacade); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setCoinRepository(CoinQueryRepository coinRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setOrderBookRepository(OrderBookQueryRepository orderBookRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setTradeExecutedRepository(TradeExecutedQueryRepository tradeExecutedRepository); @Autowired void setCommandGateway(CommandGateway commandGateway); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setOrderQueryRepository(OrderQueryRepository orderQueryRepository); @Autowired void setCommissionPolicyFactory(CommissionPolicyFactory commissionPolicyFactory);  }