@Test public void testFacetOnMultipleFields() { FacetPage<ProductBean> facetPage = repo.findAllFacetOnPopularityAndAvailable(new PageRequest(0, 10)); Assert.assertEquals(2, facetPage.getFacetFields().size()); Page<FacetFieldEntry> popularityPage = facetPage.getFacetResultPage(new SimpleField("popularity")); Assert.assertEquals(3, popularityPage.getContent().size()); for (FacetFieldEntry entry : popularityPage) { Assert.assertEquals("popularity", entry.getField().getName()); } Page<FacetFieldEntry> availablePage = facetPage.getFacetResultPage(new SimpleField("inStock")); Assert.assertEquals(2, availablePage.getContent().size()); for (FacetFieldEntry entry : availablePage) { Assert.assertEquals("inStock", entry.getField().getName()); } }
@Test public void testFacetOnSingleField() { FacetPage<ProductBean> facetPage = repo.findAllFacetOnPopularity(new PageRequest(0, 10)); Assert.assertEquals(1, facetPage.getFacetFields().size()); Page<FacetFieldEntry> page = facetPage.getFacetResultPage(facetPage.getFacetFields().iterator().next()); Assert.assertEquals(3, page.getContent().size()); for (FacetFieldEntry entry : page) { Assert.assertEquals("popularity", entry.getField().getName()); } }
@Test public void testFacetQuery() { FacetPage<Product> facetPage = repo.findProductCategoryFacets(new PageRequest(0, 100)); Assert.assertEquals(repo.findAllProducts().size(), facetPage.getNumberOfElements()); Page<FacetFieldEntry> page = facetPage.getFacetResultPage(SolrProductField.CATEGORY); Assert.assertEquals(INITIAL_CATEGORY_COUNT, page.getNumberOfElements()); for (FacetFieldEntry entry : page) { Assert.assertEquals(SolrProductField.CATEGORY.getName(), entry.getField().getName()); Assert.assertEquals(repo.findByCategory(entry.getValue()).size(), entry.getValueCount()); } }