PortalImpl implements Portal { @Override public List<Page> findPages(PageQuery query) { Pagination pagination = query.getPagination(); Iterator<PageContext> iterator; if (pagination == null) { if (query.getSiteType() == null || query.getSiteName() == null) throw new IllegalArgumentException("Pagination is required when site type or site name is null."); SiteKey siteKey = Util.from(new SiteId(query.getSiteType(), query.getSiteName())); if (pageService instanceof PageServiceImpl) { iterator = ((PageServiceImpl) pageService).loadPages(siteKey).iterator(); } else if (pageService instanceof PageServiceWrapper) { iterator = ((PageServiceWrapper) pageService).loadPages(siteKey).iterator(); } else { throw new RuntimeException("Unable to retrieve all pages for " + siteKey); } } else { QueryResult<PageContext> result = pageService.findPages(pagination.getOffset(), pagination.getLimit(), Util.from(query.getSiteType()), query.getSiteName(), null, query.getDisplayName()); iterator = result.iterator(); } List<Page> pages = new ArrayList<Page>(); while (iterator.hasNext()) { pages.add(new PageImpl(this, iterator.next())); } filter(pages, query.getFilter()); return pages; } PortalImpl(DataStorage dataStorage, PageService pageService, NavigationService navigationService,
                      DescriptionService descriptionService, ResourceBundleManager bundleManager, Authenticator authenticator,
                      IdentityRegistry identityRegistry, UserACL acl, UserPortalConfigService userPortalConfigService,
                      OAuthProviderAccessor oauthProviderAccessor); @Override Site getSite(SiteId siteId); @Override Site createSite(SiteId siteId); @Override Site createSite(SiteId siteId, String templateName); @Override List<Site> findSites(SiteQuery query); @Override void saveSite(Site site); @Override boolean removeSite(SiteId siteId); @Override Navigation getNavigation(SiteId siteId); @Override PageBuilder newPageBuilder(); @Override ApplicationRegistry getApplicationRegistry(); @Override Page getPage(PageId pageId); List<ContainerItem> getPageRootContainer(PageContext pageContext); @Override Page createPage(PageId pageId); @Override List<Page> findPages(PageQuery query); @Override void savePage(Page page); @Override boolean removePage(PageId pageId); @Override boolean hasPermission(User user, Permission permission); @Override OAuthProvider getOAuthProvider(String oauthProviderKey);  }
@Test public void findPages() { createSite(new SiteId("find-pages"), "page3", "page1", "page5", "page2", "page4"); List<Page> pages = portal.findPages(new PageQuery.Builder().withSiteId(new SiteId("find-pages")).build()); assertNotNull(pages); assertEquals(5, pages.size()); }