@Test public void testFindAllCompaniesReturnsAllCompanyViews() { CompanyView testView = new CompanyView(); testView.setIdentifier(testCompanyId.getIdentifier()); testView.setName(COMPANY_NAME); testView.setValue(COMPANY_VALUE); testView.setAmountOfShares(AMOUNT_OF_SHARES); testView.setTradeStarted(false); when(companyViewRepository.findAll(any(Pageable.class))).thenReturn(new PageImpl<>(singletonList(testView))); List<CompanyView> result = testSubject.find(new FindAllCompaniesQuery(0, 50)); assertEquals(testView, result.get(0)); }
@QueryHandler public CompanyView find(CompanyByIdQuery query) { String companyId = query.getCompanyId().getIdentifier(); return Optional.ofNullable(companyRepository.getOne(companyId)) .orElseGet(() -> { logger.warn("Tried to retrieve a Company query model with a non existent company id [{}]", companyId); return null; }); }
CompanyEventHandler { @QueryHandler public CompanyView find(CompanyByIdQuery query) { String companyId = query.getCompanyId().getIdentifier(); return Optional.ofNullable(companyRepository.getOne(companyId)) .orElseGet(() -> { logger.warn("Tried to retrieve a Company query model with a non existent company id [{}]", companyId); return null; }); } }
CompanyEventHandler { @QueryHandler public CompanyView find(CompanyByIdQuery query) { String companyId = query.getCompanyId().getIdentifier(); return Optional.ofNullable(companyRepository.getOne(companyId)) .orElseGet(() -> { logger.warn("Tried to retrieve a Company query model with a non existent company id [{}]", companyId); return null; }); } CompanyEventHandler(CompanyViewRepository companyRepository); }
CompanyEventHandler { @QueryHandler public CompanyView find(CompanyByIdQuery query) { String companyId = query.getCompanyId().getIdentifier(); return Optional.ofNullable(companyRepository.getOne(companyId)) .orElseGet(() -> { logger.warn("Tried to retrieve a Company query model with a non existent company id [{}]", companyId); return null; }); } CompanyEventHandler(CompanyViewRepository companyRepository); @EventHandler void on(CompanyCreatedEvent event); @QueryHandler CompanyView find(CompanyByIdQuery query); @QueryHandler List<CompanyView> find(FindAllCompaniesQuery query); }
CompanyEventHandler { @QueryHandler public CompanyView find(CompanyByIdQuery query) { String companyId = query.getCompanyId().getIdentifier(); return Optional.ofNullable(companyRepository.getOne(companyId)) .orElseGet(() -> { logger.warn("Tried to retrieve a Company query model with a non existent company id [{}]", companyId); return null; }); } CompanyEventHandler(CompanyViewRepository companyRepository); @EventHandler void on(CompanyCreatedEvent event); @QueryHandler CompanyView find(CompanyByIdQuery query); @QueryHandler List<CompanyView> find(FindAllCompaniesQuery query);  }