mirror of
https://github.com/Alfresco/SearchServices.git
synced 2026-09-16 18:12:56 +00:00
Added APATH end 2 end tests
This commit is contained in:
@@ -34,6 +34,7 @@ import org.testng.annotations.BeforeClass;
|
||||
* <ul>
|
||||
* <li>Preparing the data to index.
|
||||
* <li>Preparing search requests.
|
||||
*
|
||||
* @author Michael Suzuki
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -70,7 +70,7 @@ public class FingerPrintTest extends AbstractSearchTest
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
// @Test(groups= {TestGroup.REST_API, TestGroup.SEARCH})
|
||||
@Test(groups= {TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ASS_1})
|
||||
public void search() throws Exception
|
||||
{
|
||||
String uuid = file1.getNodeRefWithoutVersion();
|
||||
@@ -99,12 +99,13 @@ public class FingerPrintTest extends AbstractSearchTest
|
||||
m.getModel().assertThat().field("name").isNot("cars.txt");
|
||||
}
|
||||
}
|
||||
// @Test(groups= {TestGroup.REST_API, TestGroup.SEARCH})
|
||||
@Test(groups= {TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ASS_1})
|
||||
public void searchSimilar() throws Exception
|
||||
{
|
||||
String uuid = file2.getNodeRefWithoutVersion();
|
||||
Assert.assertNotNull(uuid);
|
||||
String fingerprint = String.format("FINGERPRINT:%s_68", uuid);
|
||||
// In the response eneity there is a score of each doc, change below threshold to bring more like or less.
|
||||
String fingerprint = String.format("FINGERPRINT:%s_68", uuid);
|
||||
SearchResponse response = query(fingerprint);
|
||||
int count = response.getEntries().size();
|
||||
Assert.assertTrue(count > 1);
|
||||
@@ -125,7 +126,7 @@ public class FingerPrintTest extends AbstractSearchTest
|
||||
m.getModel().assertThat().field("name").isNot("cars.txt");
|
||||
}
|
||||
}
|
||||
// @Test(groups= {TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ass})
|
||||
@Test(groups= {TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ASS_1})
|
||||
public void searchSimilar67Percent() throws Exception
|
||||
{
|
||||
String uuid = file2.getNodeRefWithoutVersion();
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.rest.search;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.rest.model.RestRequestFacetFieldsModel;
|
||||
import org.alfresco.utility.model.TestGroup;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests the search functionality using an ancestor path.
|
||||
* Using the category as an example, it is a node that is located
|
||||
* in root/rootCategory/classifiable. We now provide the ability to search by path
|
||||
* so that we can return all the child elements of our target path.
|
||||
* A search on root/rootCategory/classifiable should return Regions, Languages
|
||||
* as they are the child elements of the given path.
|
||||
*
|
||||
* @author Michael Suzuki
|
||||
*
|
||||
*/
|
||||
public class SearchAPATHTest extends AbstractSearchTest
|
||||
{
|
||||
|
||||
@Test(groups={TestGroup.SEARCH, TestGroup.REST_API, TestGroup.ASS_1})
|
||||
/**
|
||||
* {
|
||||
* "query": {
|
||||
* "query": "name:*"
|
||||
* },
|
||||
* "facetFields": {
|
||||
* "facets": [
|
||||
* {"field": "APATH", "prefix": "0" }
|
||||
* ]
|
||||
* }
|
||||
* }
|
||||
* Expected result
|
||||
* entries[],
|
||||
* "pagination": {
|
||||
* "maxItems": 100,
|
||||
* "hasMoreItems": true,
|
||||
* "totalItems": 914,
|
||||
* "count": 100,
|
||||
* "skipCount": 0
|
||||
* },
|
||||
* "context": {
|
||||
* "facetsFields": [{
|
||||
* "buckets": [
|
||||
* {
|
||||
* "count": 913,
|
||||
* "label": "0/5c09534f-3ca2-4272-bc25-064a7c1762b4"
|
||||
* },
|
||||
* {
|
||||
* "count": 2,
|
||||
* "label": "0/"
|
||||
* }
|
||||
* ],
|
||||
* "label": "APATH"
|
||||
* }],
|
||||
* "consistency": {"lastTxId": 89}
|
||||
* }
|
||||
*}}
|
||||
*
|
||||
*/
|
||||
public void searchLevel0() throws Exception
|
||||
{
|
||||
SearchRequest searchQuery = new SearchRequest();
|
||||
RestRequestQueryModel queryReq = new RestRequestQueryModel();
|
||||
queryReq.setQuery("name:*");
|
||||
searchQuery.setQuery(queryReq);
|
||||
|
||||
RestRequestFacetFieldsModel facetFields = new RestRequestFacetFieldsModel();
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
list.add(new FacetFieldQuery("APATH","0"));
|
||||
facetFields.setFacets(list);
|
||||
searchQuery.setFacetFields(facetFields);
|
||||
SearchResponse response = query(searchQuery);
|
||||
FacetFieldResponse fresponse = response.getContext().getFacetsFields().get(0);
|
||||
fresponse.assertThat().field("buckets").isNotEmpty();
|
||||
Assert.assertEquals(2,fresponse.getBuckets().size());
|
||||
fresponse.getBuckets().get(0).assertThat().field("label").contains("0/");
|
||||
fresponse.getBuckets().get(1).assertThat().field("label").is("0/");
|
||||
}
|
||||
@Test(groups={TestGroup.SEARCH, TestGroup.REST_API, TestGroup.ASS_1})
|
||||
public void searchLevel0andIncludeSubLevel1() throws Exception
|
||||
{
|
||||
SearchRequest searchQuery = new SearchRequest();
|
||||
RestRequestQueryModel queryReq = new RestRequestQueryModel();
|
||||
queryReq.setQuery("name:*");
|
||||
searchQuery.setQuery(queryReq);
|
||||
|
||||
RestRequestFacetFieldsModel facetFields = new RestRequestFacetFieldsModel();
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
list.add(new FacetFieldQuery("APATH","1"));
|
||||
facetFields.setFacets(list);
|
||||
searchQuery.setFacetFields(facetFields);
|
||||
SearchResponse response = query(searchQuery);
|
||||
FacetFieldResponse fresponse = response.getContext().getFacetsFields().get(0);
|
||||
Assert.assertEquals(4,fresponse.getBuckets().size());
|
||||
fresponse.getBuckets().get(0).assertThat().field("label").contains("1/");
|
||||
}
|
||||
@Test(groups={TestGroup.SEARCH, TestGroup.REST_API, TestGroup.ASS_1})
|
||||
public void searchLevel2() throws Exception
|
||||
{
|
||||
SearchRequest searchQuery = new SearchRequest();
|
||||
RestRequestQueryModel queryReq = new RestRequestQueryModel();
|
||||
queryReq.setQuery("name:*");
|
||||
searchQuery.setQuery(queryReq);
|
||||
|
||||
RestRequestFacetFieldsModel facetFields = new RestRequestFacetFieldsModel();
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
list.add(new FacetFieldQuery("APATH","1/"));
|
||||
facetFields.setFacets(list);
|
||||
searchQuery.setFacetFields(facetFields);
|
||||
|
||||
SearchResponse response = query(searchQuery);
|
||||
FacetFieldResponse fresponse = response.getContext().getFacetsFields().get(0);
|
||||
String path = fresponse.getBuckets().get(0).getLabel().replace("1/", "2/");
|
||||
list.remove(0);
|
||||
list.add(new FacetFieldQuery("APATH", path));
|
||||
|
||||
facetFields.setFacets(list);
|
||||
searchQuery.setFacetFields(facetFields);
|
||||
response = query(searchQuery);
|
||||
fresponse = response.getContext().getFacetsFields().get(0);
|
||||
Assert.assertEquals(fresponse.getBuckets().size(),3);
|
||||
fresponse.getBuckets().get(0).assertThat().field("label").contains("2/");
|
||||
fresponse.getBuckets().get(0).assertThat().field("label").contains(path);
|
||||
/**
|
||||
* To return the contents of the path and its sub directory change the prefix
|
||||
* Below 2/path/path -> will return whats in path/path only
|
||||
* if 3/path/path -> will return contents from path/path/path
|
||||
* @throws Exception
|
||||
*/
|
||||
searchQuery = new SearchRequest();
|
||||
queryReq = new RestRequestQueryModel();
|
||||
queryReq.setQuery("name:*");
|
||||
searchQuery.setQuery(queryReq);
|
||||
facetFields = new RestRequestFacetFieldsModel();
|
||||
list.remove(0);
|
||||
list.add(new FacetFieldQuery("APATH",path.replace("2/", "3/")));
|
||||
facetFields.setFacets(list);
|
||||
searchQuery.setFacetFields(facetFields);
|
||||
response = query(searchQuery);
|
||||
fresponse = response.getContext().getFacetsFields().get(0);
|
||||
System.out.println(response);
|
||||
Assert.assertTrue(fresponse.getBuckets().size() > 5);
|
||||
fresponse.getBuckets().get(0).assertThat().field("label").contains("3/");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user