@Test public void testHandleEventAddItems() throws Exception { Date time = currentTime(); ItemAddedToPortfolioEvent event = new ItemAddedToPortfolioEvent( portfolioIdentifier, coinIdentifier, BigMoney.of(CurrencyUnit.of(Currencies.LTC), BigDecimal.valueOf(100)), time); listener.handleEvent(event); Mockito.verify(portfolioQueryRepository).save(Matchers.argThat( new PortfolioEntryMatcher( coinIdentifier.toString(), DEFAULT_AMOUNT_ITEM.multipliedBy(BigDecimal.valueOf(2)), BigMoney.zero(CurrencyUnit.of(Currencies.LTC))))); }
@EventHandler public void handleEvent(ItemAddedToPortfolioEvent event) { if (logger.isDebugEnabled()) { logger.debug("Handle ItemAddedToPortfolioEvent {} for coin {} with amount {}", event.getPortfolioIdentifier(), event.getCoinId(), event.getAmountOfItemAdded()); } CoinEntry coin = findCoinEntry(event.getCoinId()); if (coin == null) { logger.error("coin {} cannot be found.", event.getCoinId()); return; } PortfolioEntry portfolioEntry = portfolioRepository.findOne(event.getPortfolioIdentifier().toString()); if (!portfolioEntry.hasItem(event.getCoinId().toString())) { portfolioEntry.createItem(coin.getPrimaryKey(), coin.getName()); } portfolioEntry.addItemInPossession(coin.getPrimaryKey(), event.getAmountOfItemAdded()); portfolioRepository.save(portfolioEntry); }
PortfolioItemEventListener { @EventHandler public void handleEvent(ItemAddedToPortfolioEvent event) { if (logger.isDebugEnabled()) { logger.debug("Handle ItemAddedToPortfolioEvent {} for coin {} with amount {}", event.getPortfolioIdentifier(), event.getCoinId(), event.getAmountOfItemAdded()); } CoinEntry coin = findCoinEntry(event.getCoinId()); if (coin == null) { logger.error("coin {} cannot be found.", event.getCoinId()); return; } PortfolioEntry portfolioEntry = portfolioRepository.findOne(event.getPortfolioIdentifier().toString()); if (!portfolioEntry.hasItem(event.getCoinId().toString())) { portfolioEntry.createItem(coin.getPrimaryKey(), coin.getName()); } portfolioEntry.addItemInPossession(coin.getPrimaryKey(), event.getAmountOfItemAdded()); portfolioRepository.save(portfolioEntry); } }
PortfolioItemEventListener { @EventHandler public void handleEvent(ItemAddedToPortfolioEvent event) { if (logger.isDebugEnabled()) { logger.debug("Handle ItemAddedToPortfolioEvent {} for coin {} with amount {}", event.getPortfolioIdentifier(), event.getCoinId(), event.getAmountOfItemAdded()); } CoinEntry coin = findCoinEntry(event.getCoinId()); if (coin == null) { logger.error("coin {} cannot be found.", event.getCoinId()); return; } PortfolioEntry portfolioEntry = portfolioRepository.findOne(event.getPortfolioIdentifier().toString()); if (!portfolioEntry.hasItem(event.getCoinId().toString())) { portfolioEntry.createItem(coin.getPrimaryKey(), coin.getName()); } portfolioEntry.addItemInPossession(coin.getPrimaryKey(), event.getAmountOfItemAdded()); portfolioRepository.save(portfolioEntry); }  }
PortfolioItemEventListener { @EventHandler public void handleEvent(ItemAddedToPortfolioEvent event) { if (logger.isDebugEnabled()) { logger.debug("Handle ItemAddedToPortfolioEvent {} for coin {} with amount {}", event.getPortfolioIdentifier(), event.getCoinId(), event.getAmountOfItemAdded()); } CoinEntry coin = findCoinEntry(event.getCoinId()); if (coin == null) { logger.error("coin {} cannot be found.", event.getCoinId()); return; } PortfolioEntry portfolioEntry = portfolioRepository.findOne(event.getPortfolioIdentifier().toString()); if (!portfolioEntry.hasItem(event.getCoinId().toString())) { portfolioEntry.createItem(coin.getPrimaryKey(), coin.getName()); } portfolioEntry.addItemInPossession(coin.getPrimaryKey(), event.getAmountOfItemAdded()); portfolioRepository.save(portfolioEntry); }  @EventHandler void handleEvent(ItemAddedToPortfolioEvent event); @EventHandler void handleEvent(ItemReservationCancelledForPortfolioEvent event); @EventHandler void handleEvent(ItemReservationConfirmedForPortfolioEvent event); @EventHandler void handleEvent(ItemReservedEvent event); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setPortfolioRepository(PortfolioQueryRepository portfolioRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setCoinQueryRepository(CoinQueryRepository coinQueryRepository); }
PortfolioItemEventListener { @EventHandler public void handleEvent(ItemAddedToPortfolioEvent event) { if (logger.isDebugEnabled()) { logger.debug("Handle ItemAddedToPortfolioEvent {} for coin {} with amount {}", event.getPortfolioIdentifier(), event.getCoinId(), event.getAmountOfItemAdded()); } CoinEntry coin = findCoinEntry(event.getCoinId()); if (coin == null) { logger.error("coin {} cannot be found.", event.getCoinId()); return; } PortfolioEntry portfolioEntry = portfolioRepository.findOne(event.getPortfolioIdentifier().toString()); if (!portfolioEntry.hasItem(event.getCoinId().toString())) { portfolioEntry.createItem(coin.getPrimaryKey(), coin.getName()); } portfolioEntry.addItemInPossession(coin.getPrimaryKey(), event.getAmountOfItemAdded()); portfolioRepository.save(portfolioEntry); }  @EventHandler void handleEvent(ItemAddedToPortfolioEvent event); @EventHandler void handleEvent(ItemReservationCancelledForPortfolioEvent event); @EventHandler void handleEvent(ItemReservationConfirmedForPortfolioEvent event); @EventHandler void handleEvent(ItemReservedEvent event); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setPortfolioRepository(PortfolioQueryRepository portfolioRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setCoinQueryRepository(CoinQueryRepository coinQueryRepository);  }