mirror of
https://github.com/Alfresco/SearchServices.git
synced 2026-09-16 18:12:56 +00:00
SEARCH-451: Switching to the new pivot format, and fixing stats tests
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
package org.alfresco.rest.search;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.rest.model.RestErrorModel;
|
||||
@@ -54,16 +55,16 @@ public class PivotFacetedSearchTest extends AbstractSearchTest
|
||||
RestRequestPivotModel pivots = new RestRequestPivotModel();
|
||||
pivotModelList.add(pivots);
|
||||
query.setPivots(pivotModelList);
|
||||
|
||||
SearchResponse response = query(query);
|
||||
|
||||
SearchResponse response = query(query);
|
||||
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError()
|
||||
.containsSummary(String.format(RestErrorModel.MANDATORY_PARAM, "pivot key"));
|
||||
|
||||
|
||||
pivots.setKey("none_like_this");
|
||||
response = query(query);
|
||||
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError()
|
||||
.containsSummary("Pivot parameter none_like_this is does not reference a facet Field");
|
||||
response = query(query);
|
||||
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
|
||||
.assertLastError().containsSummary("invalid argument was received")
|
||||
.containsSummary("Pivot parameter none_like_this does not reference");
|
||||
}
|
||||
|
||||
@Test(groups = { TestGroup.REST_API, TestGroup.SEARCH })
|
||||
@@ -94,6 +95,63 @@ public class PivotFacetedSearchTest extends AbstractSearchTest
|
||||
assertPivotResponse(response, "creator", null);
|
||||
}
|
||||
|
||||
@Test(groups = { TestGroup.REST_API, TestGroup.SEARCH })
|
||||
@TestRail(section = {TestGroup.REST_API, TestGroup.SEARCH }, executionType = ExecutionType.REGRESSION,
|
||||
description = "Checks nested pivot using Search api")
|
||||
public void searchWithNestedPivoting() throws Exception
|
||||
{
|
||||
SearchRequest query = carsQuery();
|
||||
|
||||
RestRequestFacetFieldsModel facetFields = new RestRequestFacetFieldsModel();
|
||||
List<RestRequestFacetFieldModel> list = new ArrayList<>();
|
||||
RestRequestFacetFieldModel restRequestFacetFieldModel = new RestRequestFacetFieldModel("SITE");
|
||||
restRequestFacetFieldModel.setLabel("site");
|
||||
list.add(restRequestFacetFieldModel);
|
||||
list.add(new RestRequestFacetFieldModel("creator"));
|
||||
list.add(new RestRequestFacetFieldModel("modifier"));
|
||||
facetFields.setFacets(list);
|
||||
query.setFacetFields(facetFields);
|
||||
query.setIncludeRequest(false);
|
||||
|
||||
List<RestRequestPivotModel> pivotModelList = new ArrayList<>();
|
||||
RestRequestPivotModel sitepivots = new RestRequestPivotModel();
|
||||
sitepivots.setKey("site");
|
||||
RestRequestPivotModel creatorpivot = new RestRequestPivotModel();
|
||||
creatorpivot.setKey("creator");
|
||||
RestRequestPivotModel modifierpivot = new RestRequestPivotModel();
|
||||
modifierpivot.setKey("modifier");
|
||||
sitepivots.setPivots(Arrays.asList(creatorpivot, modifierpivot));
|
||||
pivotModelList.add(sitepivots);
|
||||
query.setPivots(pivotModelList);
|
||||
|
||||
SearchResponse response = query(query);
|
||||
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
|
||||
.assertLastError().containsSummary("invalid argument was received")
|
||||
.containsSummary("Currently only 1 nested pivot is supported, you have 2");
|
||||
|
||||
pivotModelList = new ArrayList<>();
|
||||
sitepivots = new RestRequestPivotModel();
|
||||
sitepivots.setKey("site");
|
||||
sitepivots.setPivots(Arrays.asList(modifierpivot));
|
||||
pivotModelList.add(sitepivots);
|
||||
pivotModelList.add(creatorpivot);
|
||||
query.setPivots(pivotModelList);
|
||||
|
||||
response = query(query);
|
||||
assertPivotResponse(response, "SITE", "site");
|
||||
|
||||
RestGenericFacetResponseModel siteResponse = response.getContext().getFacets().get(0);
|
||||
RestGenericBucketModel bucket = siteResponse.getBuckets().get(0);
|
||||
RestGenericFacetResponseModel modifiedResponse = bucket.getFacets().get(0);
|
||||
modifiedResponse.assertThat().field("type").is("pivot");
|
||||
modifiedResponse.assertThat().field("label").is("modifier");
|
||||
|
||||
RestGenericFacetResponseModel creatorResponse = response.getContext().getFacets().get(1);
|
||||
creatorResponse.assertThat().field("type").is("pivot");
|
||||
creatorResponse.assertThat().field("label").is("creator");
|
||||
}
|
||||
|
||||
|
||||
private void assertPivotResponse(SearchResponse response, String field, String alabel) throws Exception
|
||||
{
|
||||
String label = alabel!=null?alabel:field;
|
||||
@@ -139,11 +197,11 @@ public class PivotFacetedSearchTest extends AbstractSearchTest
|
||||
assertPivotResponse(response, "creator", "create");
|
||||
|
||||
//Now check the nesting
|
||||
RestGenericFacetResponseModel facetResponseModel = response.getContext().getFacets().get(0);
|
||||
RestGenericFacetResponseModel nestedFacet = facetResponseModel.getBuckets().get(0).getFacets().get(0);
|
||||
RestGenericBucketModel bucket = nestedFacet.getBuckets().get(0);
|
||||
nestedFacet.assertThat().field("label").isNotEmpty();
|
||||
nestedFacet.assertThat().field("label").is("aLabel");
|
||||
RestGenericFacetResponseModel labelResponseModel = response.getContext().getFacets().get(1);
|
||||
labelResponseModel.assertThat().field("type").is("pivot");
|
||||
labelResponseModel.assertThat().field("label").isNotEmpty();
|
||||
labelResponseModel.assertThat().field("label").is("aLabel");
|
||||
RestGenericBucketModel bucket = labelResponseModel.getBuckets().get(0);
|
||||
bucket.assertThat().field("filterQuery").is("modifier:"+bucket.getLabel());
|
||||
Assert.assertEquals("count", bucket.getMetrics().get(0).getType());
|
||||
Assert.assertTrue(bucket.getMetrics().get(0).getValue().toString().contains("{count="));
|
||||
|
||||
@@ -203,7 +203,6 @@ public class StatsSearchTest extends AbstractSearchTest
|
||||
query.setFacetFields(facetFields);
|
||||
query.setIncludeRequest(false);
|
||||
|
||||
|
||||
List<RestRequestPivotModel> pivotModelList = new ArrayList<>();
|
||||
RestRequestPivotModel pivots = new RestRequestPivotModel();
|
||||
pivots.setKey("b0");
|
||||
@@ -211,9 +210,10 @@ public class StatsSearchTest extends AbstractSearchTest
|
||||
pivotn.setKey("created");
|
||||
RestRequestPivotModel pivot2 = new RestRequestPivotModel();
|
||||
pivot2.setKey("aNumber");
|
||||
|
||||
pivotn.setPivots(Arrays.asList(pivot2));
|
||||
pivots.setPivots(Arrays.asList(pivotn));
|
||||
pivotModelList.add(pivots);
|
||||
pivotModelList.add(pivotn);
|
||||
pivotModelList.add(pivot2);
|
||||
query.setPivots(pivotModelList);
|
||||
|
||||
List<RestRequestStatsModel> statsModels = new ArrayList<>();
|
||||
@@ -232,14 +232,13 @@ public class StatsSearchTest extends AbstractSearchTest
|
||||
RestGenericFacetResponseModel facetResponseModel = response.getContext().getFacets().get(0);
|
||||
facetResponseModel.assertThat().field("type").is("pivot");
|
||||
facetResponseModel.assertThat().field("label").is("b0");
|
||||
assertEquals(facetResponseModel.getBuckets().get(0).getMetrics().size(), 8, "Metrics on the pivot bucket");
|
||||
|
||||
//pivot created
|
||||
RestGenericFacetResponseModel created = facetResponseModel.getBuckets().get(0).getFacets().get(0);
|
||||
created.assertThat().field("type").is("pivot");
|
||||
created.assertThat().field("label").is("created");
|
||||
//Another nested stats
|
||||
assertEquals(facetResponseModel.getBuckets().get(0).getFacets().get(0).getBuckets().get(0).getMetrics().size(), 8, "Metrics are on the end of a pivot bucket");
|
||||
|
||||
RestGenericFacetResponseModel statsFacet = response.getContext().getFacets().get(1);
|
||||
statsFacet.assertThat().field("type").is("stats");
|
||||
statsFacet.assertThat().field("label").is("aNumber");
|
||||
assertEquals(created.getBuckets().get(0).getMetrics().size(), 8, "Metrics are on the end of a pivot bucket");
|
||||
|
||||
}
|
||||
|
||||
@@ -269,8 +268,9 @@ public class StatsSearchTest extends AbstractSearchTest
|
||||
pivots.setKey("creator");
|
||||
RestRequestPivotModel pivotn = new RestRequestPivotModel();
|
||||
pivotn.setKey("numericId");
|
||||
|
||||
pivots.setPivots(Arrays.asList(pivotn));
|
||||
pivotModelList.add(pivots);
|
||||
pivotModelList.add(pivotn);
|
||||
query.setPivots(pivotModelList);
|
||||
|
||||
List<RestRequestStatsModel> statsModels = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user