From 4cd17d21f3358c0522c0eb5181ae785e4804604c Mon Sep 17 00:00:00 2001 From: Michael Suzuki Date: Mon, 13 Mar 2017 13:25:43 +0000 Subject: [PATCH] Adding test for grouping facets --- .../rest/search/FacetedSearchTest.java | 97 ++++++++++++++++--- 1 file changed, 85 insertions(+), 12 deletions(-) diff --git a/e2e-test/java/org/alfresco/rest/search/FacetedSearchTest.java b/e2e-test/java/org/alfresco/rest/search/FacetedSearchTest.java index 3e61dad1e..8ce825fcd 100644 --- a/e2e-test/java/org/alfresco/rest/search/FacetedSearchTest.java +++ b/e2e-test/java/org/alfresco/rest/search/FacetedSearchTest.java @@ -24,6 +24,7 @@ import java.util.List; import org.alfresco.utility.model.TestGroup; import org.alfresco.utility.testrail.ExecutionType; import org.alfresco.utility.testrail.annotation.TestRail; +import org.testng.Assert; import org.testng.annotations.Test; /** @@ -67,25 +68,20 @@ public class FacetedSearchTest extends AbstractSearchTest * "facetQueries": [ * { * "count": 61, - * "label": "small" + * "label": "small", + * "filterQuery": "content.size:[o TO 102400]" * }, * { * "count": 0, - * "label": "large" + * "label": "large", + * "filterQuery": "content.size:[o TO 102400]" * }, * { * "count": 0, - * "label": "medium" + * "label": "medium", + * "filterQuery": "content.size:[o TO 102400]" * } - * ], - * //Added below as part of SEARCH-374 - * "facetsFields": [ - * { "label": "woof", - * "buckets": [ - * { "label": "CreatedThisYear", "count": 75, "filterQuery": "created:2017"}, - * { "label": "CreatedLastYear", "count": 75, "filterQuery": "created:2016"} - * ] - * } + * ] * } * }} * @throws Exception @@ -122,6 +118,83 @@ public class FacetedSearchTest extends AbstractSearchTest response.getContext().getFacetQueries().get(2).assertThat().field("label").contains("medium") .and().field("count").isLessThan(1) .and().field("filterQuery").is("content.size:[102400 TO 1048576]"); + //We don't expect to see the FacetFields if group is being used. + Assert.assertNull(response.getContext().getFacetsFields()); + Assert.assertNull(response.getContext().getFacetIntervals()); + } + /** + * * Perform a group by faceting, below test groups the facet by group name foo. + * { + * "query": { + * "query": "cars", + * "language": "afts" + * }, + * "facetQueries": [ + * {"query": "content.size:[o TO 102400]", "label": "small","group":"foo"}, + * {"query": "content.size:[102400 TO 1048576]", "label": "medium","group":"foo"}, + * {"query": "content.size:[1048576 TO 16777216]", "label": "large","group":"foo"} + * ], + * "facetFields": {"facets": [{"field": "'content.size'"}]} + * } + * + * Expected response + * {"list": { + * "entries": [... All the results], + * "pagination": { + * "maxItems": 100, + * "hasMoreItems": false, + * "totalItems": 61, + * "count": 61, + * "skipCount": 0 + * }, + * "context": { + * "consistency": {"lastTxId": 512}, + * //Added below as part of SEARCH-374 + * "facetsFields": [ + * { "label": "foo", + * "buckets": [ + * { "label": "small", "count": 61, "filterQuery": "content.size:[o TO 102400]"}, + * { "label": "large", "count": 0, "filterQuery": "content.size:[1048576 TO 16777216]"}, + * { "label": "medium", "count": 61, "filterQuery": "content.size:[102400 TO 1048576]"} + * ] + * } + * } + * }} + * @throws Exception + */ + public void searchFacetGroup() throws Exception + { + SearchRequest query = new SearchRequest(); + RestRequestQueryModel queryReq = new RestRequestQueryModel(); + queryReq.setQuery("cars"); + query.setQuery(queryReq); + + List facets = new ArrayList(); + facets.add(new FacetQuery("content.size:[0 TO 102400]", "small", "foo")); + facets.add(new FacetQuery("content.size:[102400 TO 1048576]", "medium","foo")); + facets.add(new FacetQuery("content.size:[1048576 TO 16777216]", "large","foo")); + query.setFacetQueries(facets); + + RestRequestFacetFieldsModel facetFields = new RestRequestFacetFieldsModel(); + List list = new ArrayList(); + list.add(new FacetFieldQuery("'content.size'")); + facetFields.setFacets(list); + + query.setFacetFields(facetFields); + + SearchResponse response = query(query); + //We don't expect to see the FacetQueries if group is being used. + Assert.assertTrue(response.getContext().getFacetQueries().isEmpty()); + //Validate the facet field structure is correct. + Assert.assertFalse(response.getContext().getFacetsFields().isEmpty()); + RestResultBucketsModel bucket = response.getContext().getFacetsFields().get(0); + bucket.assertThat().field("label").isNotEmpty(); + bucket.assertThat().field("count").isNotEmpty(); + bucket.assertThat().field("filterQuery").isNotEmpty(); + Assert.assertEquals(bucket.getLabel(), "foo"); + bucket.assertThat().field("label").contains("small").and().field("filterQuery").is("content.size:[0 TO 102400]"); + bucket.assertThat().field("label").contains("medium").and().field("filterQuery").is("content.size:[1048576 TO 16777216]"); + bucket.assertThat().field("label").contains("large").and().field("filterQuery").is("content.size:[102400 TO 1048576]"); }