@Test public void refreshFAQs() throws IOException { final String faqsXml = "fadgszdbg"; final List<FaqItemDto> faqItems1 = Arrays.asList(mock(FaqItemDto.class)); final List<FaqItemDto> faqItems2 = Arrays.asList(mock(FaqItemDto.class), mock(FaqItemDto.class)); final List<FaqItemDto> faqItems3 = Arrays.asList(mock(FaqItemDto.class), null, mock(FaqItemDto.class)); final Cache cache = mock(Cache.class); final Page page1 = Page.builder().name("gfs").subtitle("oenoewfxsc").faqs(new ArrayList<>()).build(); final Page page2 = Page.builder().name("ghc").subtitle("hfgdljhhkj").faqs(new ArrayList<>()).build(); final Page page3 = Page.builder().name("daf").subtitle("kdbcgaadcf").faqs(new ArrayList<>()).build(); when(githubGateway.getContentsAsRaw(OWNER, REPO, MASTER, FILE_PATH)).thenReturn(faqsXml); when(xmlMapper.readValue(faqsXml, Faqs.class)).thenReturn(Faqs.builder().pages(Arrays.asList(page1, page2, page3)).build()); when(faqItemDtoMapper.mapToList(same(page1.getFaqs()))).thenReturn(faqItems1); when(faqItemDtoMapper.mapToList(same(page2.getFaqs()))).thenReturn(faqItems2); when(faqItemDtoMapper.mapToList(same(page3.getFaqs()))).thenReturn(faqItems3); when(cacheManager.getCache("faqs")).thenReturn(cache); service.refreshFAQs(); verify(cache).put(eq(page1.getName()), refEq(new FaqItemsDto(page1.getSubtitle(), faqItems1))); verify(cache).put(eq(page2.getName()), refEq(new FaqItemsDto(page2.getSubtitle(), faqItems2))); verify(cache).put(eq(page3.getName()), refEq(new FaqItemsDto(page3.getSubtitle(), faqItems3.stream().filter(Objects::nonNull).collect(toList())))); }
@Scheduled(fixedRate = DAY_IN_MILLIS) public void refreshFAQs() { fetchFAQs().getPages() .forEach(page -> cacheManager.getCache("faqs") .put(page.getName(), processFAQs(page.getFaqs(), page.getSubtitle()))); LOGGER.info("FAQ's are fetched from GitHub and stored in cache"); }
GithubFAQServiceImpl implements FAQService { @Scheduled(fixedRate = DAY_IN_MILLIS) public void refreshFAQs() { fetchFAQs().getPages() .forEach(page -> cacheManager.getCache("faqs") .put(page.getName(), processFAQs(page.getFaqs(), page.getSubtitle()))); LOGGER.info("FAQ's are fetched from GitHub and stored in cache"); } }
GithubFAQServiceImpl implements FAQService { @Scheduled(fixedRate = DAY_IN_MILLIS) public void refreshFAQs() { fetchFAQs().getPages() .forEach(page -> cacheManager.getCache("faqs") .put(page.getName(), processFAQs(page.getFaqs(), page.getSubtitle()))); LOGGER.info("FAQ's are fetched from GitHub and stored in cache"); } GithubFAQServiceImpl(final GithubGateway githubGateway,
                                @Value("${io.fundrequest.faq.owner:FundRequest}") final String owner,
                                @Value("${io.fundrequest.faq.repo:FAQ}") final String repo,
                                @Value("${io.fundrequest.faq.branch:master}") final String branch,
                                @Value("${io.fundrequest.faq.filePath:FAQ.xml}") final String filePath,
                                final XmlMapper xmlMapper,
                                final FaqItemDtoMapper faqItemDtoMapper,
                                final CacheManager cacheManager); }
GithubFAQServiceImpl implements FAQService { @Scheduled(fixedRate = DAY_IN_MILLIS) public void refreshFAQs() { fetchFAQs().getPages() .forEach(page -> cacheManager.getCache("faqs") .put(page.getName(), processFAQs(page.getFaqs(), page.getSubtitle()))); LOGGER.info("FAQ's are fetched from GitHub and stored in cache"); } GithubFAQServiceImpl(final GithubGateway githubGateway,
                                @Value("${io.fundrequest.faq.owner:FundRequest}") final String owner,
                                @Value("${io.fundrequest.faq.repo:FAQ}") final String repo,
                                @Value("${io.fundrequest.faq.branch:master}") final String branch,
                                @Value("${io.fundrequest.faq.filePath:FAQ.xml}") final String filePath,
                                final XmlMapper xmlMapper,
                                final FaqItemDtoMapper faqItemDtoMapper,
                                final CacheManager cacheManager); @Scheduled(fixedRate = DAY_IN_MILLIS) void refreshFAQs(); @Cacheable(cacheNames = "faqs", key = "#pageName") FaqItemsDto getFAQsForPage(final String pageName); }
GithubFAQServiceImpl implements FAQService { @Scheduled(fixedRate = DAY_IN_MILLIS) public void refreshFAQs() { fetchFAQs().getPages() .forEach(page -> cacheManager.getCache("faqs") .put(page.getName(), processFAQs(page.getFaqs(), page.getSubtitle()))); LOGGER.info("FAQ's are fetched from GitHub and stored in cache"); } GithubFAQServiceImpl(final GithubGateway githubGateway,
                                @Value("${io.fundrequest.faq.owner:FundRequest}") final String owner,
                                @Value("${io.fundrequest.faq.repo:FAQ}") final String repo,
                                @Value("${io.fundrequest.faq.branch:master}") final String branch,
                                @Value("${io.fundrequest.faq.filePath:FAQ.xml}") final String filePath,
                                final XmlMapper xmlMapper,
                                final FaqItemDtoMapper faqItemDtoMapper,
                                final CacheManager cacheManager); @Scheduled(fixedRate = DAY_IN_MILLIS) void refreshFAQs(); @Cacheable(cacheNames = "faqs", key = "#pageName") FaqItemsDto getFAQsForPage(final String pageName);  }