@Test public void testOnCompanyCreatedEventACreatesAndAssociatesOrderBookCommandIsPublished() { CompanyId testCompanyId = new CompanyId(); testSubject.on(new CompanyCreatedEvent(testCompanyId, "AxonIQ", 1337L, 50L)); ArgumentCaptor<Object> commandCaptor = ArgumentCaptor.forClass(Object.class); verify(commandGateway, times(2)).send(commandCaptor.capture()); List<Object> results = commandCaptor.getAllValues(); CreateOrderBookCommand firstCommand = (CreateOrderBookCommand) results.get(0); assertNotNull(firstCommand); assertNotNull(firstCommand.getOrderBookId()); AddOrderBookToCompanyCommand secondCommand = (AddOrderBookToCompanyCommand) results.get(1); assertNotNull(secondCommand); assertEquals(testCompanyId, secondCommand.getCompanyId()); assertNotNull(secondCommand.getOrderBookId()); }
@EventHandler public void on(CompanyCreatedEvent event) { logger.debug("About to dispatch a new command to create an OrderBook for the company {}", event.getCompanyId()); OrderBookId orderBookId = new OrderBookId(); commandGateway.send(new CreateOrderBookCommand(orderBookId)); commandGateway.send(new AddOrderBookToCompanyCommand(event.getCompanyId(), orderBookId)); }
CompanyOrderBookListener { @EventHandler public void on(CompanyCreatedEvent event) { logger.debug("About to dispatch a new command to create an OrderBook for the company {}", event.getCompanyId()); OrderBookId orderBookId = new OrderBookId(); commandGateway.send(new CreateOrderBookCommand(orderBookId)); commandGateway.send(new AddOrderBookToCompanyCommand(event.getCompanyId(), orderBookId)); } }
CompanyOrderBookListener { @EventHandler public void on(CompanyCreatedEvent event) { logger.debug("About to dispatch a new command to create an OrderBook for the company {}", event.getCompanyId()); OrderBookId orderBookId = new OrderBookId(); commandGateway.send(new CreateOrderBookCommand(orderBookId)); commandGateway.send(new AddOrderBookToCompanyCommand(event.getCompanyId(), orderBookId)); } CompanyOrderBookListener(CommandGateway commandGateway); }
CompanyOrderBookListener { @EventHandler public void on(CompanyCreatedEvent event) { logger.debug("About to dispatch a new command to create an OrderBook for the company {}", event.getCompanyId()); OrderBookId orderBookId = new OrderBookId(); commandGateway.send(new CreateOrderBookCommand(orderBookId)); commandGateway.send(new AddOrderBookToCompanyCommand(event.getCompanyId(), orderBookId)); } CompanyOrderBookListener(CommandGateway commandGateway); @EventHandler void on(CompanyCreatedEvent event); }
CompanyOrderBookListener { @EventHandler public void on(CompanyCreatedEvent event) { logger.debug("About to dispatch a new command to create an OrderBook for the company {}", event.getCompanyId()); OrderBookId orderBookId = new OrderBookId(); commandGateway.send(new CreateOrderBookCommand(orderBookId)); commandGateway.send(new AddOrderBookToCompanyCommand(event.getCompanyId(), orderBookId)); } CompanyOrderBookListener(CommandGateway commandGateway); @EventHandler void on(CompanyCreatedEvent event);  }