@Test public void testHandlePayForCoins() throws Exception { final BigMoney tradeAmount = BigMoney.of(CurrencyUnit.of("BTC"), 10000); final BigMoney tradedPrice = BigMoney.zero(CurrencyUnit.CAD); final BigMoney executedMoney = BigMoney.of(CurrencyUnit.CAD, 0.00001); final BigMoney buyCommission = BigMoney.parse("CAD 1"); final BigMoney sellCommission = BigMoney.parse("BTC 1"); final Date tradeTime = currentTime(); final String buyOrderId = "buyOrderId"; final String sellOrderId = "sellOrderId"; final TransactionId buyTransactionId = new TransactionId("buyTransactionId"); final TransactionId sellTransactionId = new TransactionId("sellTransactionId"); final OrderBookId orderbookId = new OrderBookId("orderbookId"); final CoinId coinId = new CoinId("XPM"); final PortfolioId buyPortfolioId = new PortfolioId(); final PortfolioId sellPortfolioId = new PortfolioId(); final UserId buyUserId = new UserId(); final UserId sellUserId = new UserId(); final DateTimeZone zone = DateTimeZone.forID("America/New_York"); final Date dueDate = new DateTime(tradeTime, zone).toDate(); final DueDateService dueDateService = mock(DueDateService.class); when(dueDateService.computeDueDate(Mockito.any(Date.class))).thenReturn(dueDate); ExecutedTransactionFeeApplicationListener listener = new ExecutedTransactionFeeApplicationListener(); CommandGateway gateway = mock(CommandGateway.class); listener.setCommandGateway(gateway); listener.setDueDateService(dueDateService); listener.handlePayForCoins( new TradeExecutedEvent( orderbookId, coinId, tradeAmount, tradedPrice, executedMoney, buyOrderId, sellOrderId, buyCommission, sellCommission, buyTransactionId, sellTransactionId, buyPortfolioId, sellPortfolioId, buyUserId, sellUserId, tradeTime, TradeType.BUY)); ArgumentCaptor<PayBuyMoneyTransactionCommand> captor = ArgumentCaptor.forClass(PayBuyMoneyTransactionCommand.class); verify(gateway).send(captor.capture()); PayBuyMoneyTransactionCommand command = captor.getValue(); assertThat(command, notNullValue()); assertThat(command.getFeeTransactionId(), notNullValue()); assertThat(command.getPaidFeeId(), notNullValue()); assertThat(command.getAccountPayableFeeId(), notNullValue()); assertThat(command.getOffsetId(), notNullValue()); assertThat(command.getOrderId(), equalTo(buyOrderId)); assertThat(command.getOrderTransactionId(), equalTo(buyTransactionId)); assertThat(command.getPortfolioId(), equalTo(buyPortfolioId)); assertThat(command.getTradeTime(), equalTo(tradeTime)); assertThat(command.getDueDate(), equalTo(new DateTime(tradeTime, zone).toDate())); assertThat(command.getTradeType(), equalTo(TradeType.BUY)); assertThat(command.getTradedPrice(), equalTo(tradedPrice)); assertThat(command.getTradeAmount(), equalTo(tradeAmount)); assertThat(command.getExecutedMoney(), equalTo(executedMoney)); assertThat(command.getOrderBookId(), equalTo(orderbookId)); assertThat(command.getCoinId(), equalTo(coinId)); verify(dueDateService).computeDueDate(Mockito.any(Date.class)); }
@EventHandler public void handlePayForCoins(TradeExecutedEvent event) { notNull(event.getTradeTime()); logger.debug("About to pay for buying coins with executed event {}", event); Date dueDate = dueDateService.computeDueDate(event.getTradeTime()); PayBuyMoneyTransactionCommand command = new PayBuyMoneyTransactionCommand( new FeeTransactionId(), new FeeId(), new FeeId(), new OffsetId(), event.getBuyOrderId(), event.getBuyTransactionId(), event.getBuyPortfolioId(), event.getBuyUserId(), event.getTradeTime(), dueDate, event.getTradeType(), event.getTradedPrice(), event.getTradeAmount(), event.getExecutedMoney(), event.getOrderBookId(), event.getCoinId()); commandGateway.send(command); }
ExecutedTransactionFeeApplicationListener { @EventHandler public void handlePayForCoins(TradeExecutedEvent event) { notNull(event.getTradeTime()); logger.debug("About to pay for buying coins with executed event {}", event); Date dueDate = dueDateService.computeDueDate(event.getTradeTime()); PayBuyMoneyTransactionCommand command = new PayBuyMoneyTransactionCommand( new FeeTransactionId(), new FeeId(), new FeeId(), new OffsetId(), event.getBuyOrderId(), event.getBuyTransactionId(), event.getBuyPortfolioId(), event.getBuyUserId(), event.getTradeTime(), dueDate, event.getTradeType(), event.getTradedPrice(), event.getTradeAmount(), event.getExecutedMoney(), event.getOrderBookId(), event.getCoinId()); commandGateway.send(command); } }
ExecutedTransactionFeeApplicationListener { @EventHandler public void handlePayForCoins(TradeExecutedEvent event) { notNull(event.getTradeTime()); logger.debug("About to pay for buying coins with executed event {}", event); Date dueDate = dueDateService.computeDueDate(event.getTradeTime()); PayBuyMoneyTransactionCommand command = new PayBuyMoneyTransactionCommand( new FeeTransactionId(), new FeeId(), new FeeId(), new OffsetId(), event.getBuyOrderId(), event.getBuyTransactionId(), event.getBuyPortfolioId(), event.getBuyUserId(), event.getTradeTime(), dueDate, event.getTradeType(), event.getTradedPrice(), event.getTradeAmount(), event.getExecutedMoney(), event.getOrderBookId(), event.getCoinId()); commandGateway.send(command); }  }
ExecutedTransactionFeeApplicationListener { @EventHandler public void handlePayForCoins(TradeExecutedEvent event) { notNull(event.getTradeTime()); logger.debug("About to pay for buying coins with executed event {}", event); Date dueDate = dueDateService.computeDueDate(event.getTradeTime()); PayBuyMoneyTransactionCommand command = new PayBuyMoneyTransactionCommand( new FeeTransactionId(), new FeeId(), new FeeId(), new OffsetId(), event.getBuyOrderId(), event.getBuyTransactionId(), event.getBuyPortfolioId(), event.getBuyUserId(), event.getTradeTime(), dueDate, event.getTradeType(), event.getTradedPrice(), event.getTradeAmount(), event.getExecutedMoney(), event.getOrderBookId(), event.getCoinId()); commandGateway.send(command); }  @EventHandler void handlePaySellCommission(TradeExecutedEvent event); @EventHandler void handlePayBuyCommission(TradeExecutedEvent event); @EventHandler void handlePaySoldCoin(TradeExecutedEvent event); @EventHandler void handleReceiveMoneyFromSale(TradeExecutedEvent event); @EventHandler void handlePayForCoins(TradeExecutedEvent event); @EventHandler void handleReceiveCoinsFromSale(TradeExecutedEvent event); @SuppressWarnings("SpringJavaAutowiringInspection") @Resource(name = "fee.commandGateway") //todo check if it's needed to use Autowired void setCommandGateway(CommandGateway commandGateway); @Autowired void setDueDateService(DueDateService dueDateService); }
ExecutedTransactionFeeApplicationListener { @EventHandler public void handlePayForCoins(TradeExecutedEvent event) { notNull(event.getTradeTime()); logger.debug("About to pay for buying coins with executed event {}", event); Date dueDate = dueDateService.computeDueDate(event.getTradeTime()); PayBuyMoneyTransactionCommand command = new PayBuyMoneyTransactionCommand( new FeeTransactionId(), new FeeId(), new FeeId(), new OffsetId(), event.getBuyOrderId(), event.getBuyTransactionId(), event.getBuyPortfolioId(), event.getBuyUserId(), event.getTradeTime(), dueDate, event.getTradeType(), event.getTradedPrice(), event.getTradeAmount(), event.getExecutedMoney(), event.getOrderBookId(), event.getCoinId()); commandGateway.send(command); }  @EventHandler void handlePaySellCommission(TradeExecutedEvent event); @EventHandler void handlePayBuyCommission(TradeExecutedEvent event); @EventHandler void handlePaySoldCoin(TradeExecutedEvent event); @EventHandler void handleReceiveMoneyFromSale(TradeExecutedEvent event); @EventHandler void handlePayForCoins(TradeExecutedEvent event); @EventHandler void handleReceiveCoinsFromSale(TradeExecutedEvent event); @SuppressWarnings("SpringJavaAutowiringInspection") @Resource(name = "fee.commandGateway") //todo check if it's needed to use Autowired void setCommandGateway(CommandGateway commandGateway); @Autowired void setDueDateService(DueDateService dueDateService);  }