@Test public void getFAQsForPage() throws IOException { final String faqsXml = "fadgszdbg"; final String pageName = "fghggfsshdg"; final String subtitle = "afdsgdasoif"; final List<Faq> faqs = new ArrayList<>(); final List<FaqItemDto> faqItems = Arrays.asList(mock(FaqItemDto.class), null, mock(FaqItemDto.class)); when(githubGateway.getContentsAsRaw(OWNER, REPO, MASTER, FILE_PATH)).thenReturn(faqsXml); when(xmlMapper.readValue(faqsXml, Faqs.class)).thenReturn(buildFaqsObjectWithPage(pageName, subtitle, faqs)); when(faqItemDtoMapper.mapToList(same(faqs))).thenReturn(faqItems); final FaqItemsDto result = service.getFAQsForPage(pageName); assertThat(result.getFaqItems()).isEqualTo(faqItems.stream().filter(Objects::nonNull).collect(toList())); assertThat(result.getSubtitle()).isEqualTo(subtitle); }
@Cacheable(cacheNames = "faqs", key = "#pageName") public FaqItemsDto getFAQsForPage(final String pageName) { return fetchFAQs().getPages() .stream() .filter(page -> page.getName().equalsIgnoreCase(pageName)) .findFirst().map(page -> processFAQs(page.getFaqs(), page.getSubtitle())) .orElse(new FaqItemsDto(StringUtils.EMPTY, new ArrayList<>())); }
GithubFAQServiceImpl implements FAQService { @Cacheable(cacheNames = "faqs", key = "#pageName") public FaqItemsDto getFAQsForPage(final String pageName) { return fetchFAQs().getPages() .stream() .filter(page -> page.getName().equalsIgnoreCase(pageName)) .findFirst().map(page -> processFAQs(page.getFaqs(), page.getSubtitle())) .orElse(new FaqItemsDto(StringUtils.EMPTY, new ArrayList<>())); } }
GithubFAQServiceImpl implements FAQService { @Cacheable(cacheNames = "faqs", key = "#pageName") public FaqItemsDto getFAQsForPage(final String pageName) { return fetchFAQs().getPages() .stream() .filter(page -> page.getName().equalsIgnoreCase(pageName)) .findFirst().map(page -> processFAQs(page.getFaqs(), page.getSubtitle())) .orElse(new FaqItemsDto(StringUtils.EMPTY, new ArrayList<>())); } 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 { @Cacheable(cacheNames = "faqs", key = "#pageName") public FaqItemsDto getFAQsForPage(final String pageName) { return fetchFAQs().getPages() .stream() .filter(page -> page.getName().equalsIgnoreCase(pageName)) .findFirst().map(page -> processFAQs(page.getFaqs(), page.getSubtitle())) .orElse(new FaqItemsDto(StringUtils.EMPTY, new ArrayList<>())); } 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 { @Cacheable(cacheNames = "faqs", key = "#pageName") public FaqItemsDto getFAQsForPage(final String pageName) { return fetchFAQs().getPages() .stream() .filter(page -> page.getName().equalsIgnoreCase(pageName)) .findFirst().map(page -> processFAQs(page.getFaqs(), page.getSubtitle())) .orElse(new FaqItemsDto(StringUtils.EMPTY, new ArrayList<>())); } 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);  }