Added highlighting tests

This commit is contained in:
Michael Suzuki
2017-02-24 14:55:55 +00:00
parent 69aa70a5fc
commit db3e175135
2 changed files with 89 additions and 3 deletions
@@ -44,6 +44,7 @@ public class AbstractSearchTest extends RestTest
SiteModel siteModel;
UserModel searchedUser;
NodesBuilder nodesBuilder;
protected FileModel file,file2;
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws Exception
@@ -61,8 +62,8 @@ public class AbstractSearchTest extends RestTest
FolderModel folder = new FolderModel(SEARCH_DATA_SAMPLE_FOLDER);
dataContent.usingSite(siteModel).createFolder(folder);
//Create files
FileModel file = new FileModel("pangram.txt", FileType.TEXT_PLAIN, "The quick brown fox jumps over the lazy dog");
FileModel file2 = new FileModel("cars.txt", FileType.TEXT_PLAIN, "The landrover discovery is not a sports car");
file = new FileModel("pangram.txt", FileType.TEXT_PLAIN, "The quick brown fox jumps over the lazy dog");
file2 = new FileModel("cars.txt", FileType.TEXT_PLAIN, "The landrover discovery is not a sports car");
ContentModel cm = new ContentModel();
cm.setCmisLocation(folder.getCmisLocation());
cm.setName(folder.getName());
@@ -74,15 +75,29 @@ public class AbstractSearchTest extends RestTest
* @param term String search term
* @return {@link SearchResponse} response.
* @throws Exception if error
*
*/
protected SearchResponse query(String term) throws Exception
{
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setLanguage("afts");
queryReq.setQuery(term);
SearchRequest query = new SearchRequest(queryReq);
return restClient.authenticateUser(dataUser.getAdminUser()).withSearchAPI().search(query);
}
/**
* Helper method which create an http post request to Search API end point.
* @param term String search term
* @return {@link SearchResponse} response.
* @throws Exception if error
*
*/
protected SearchResponse query(RestRequestQueryModel queryReq,RestRequestHighlightModel highlight) throws Exception
{
SearchRequest query = new SearchRequest(queryReq);
query.setHighlight(highlight);
System.out.println(query.toString());
return restClient.authenticateUser(dataUser.getAdminUser()).withSearchAPI().search(query);
}
}
@@ -0,0 +1,71 @@
/*
* 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.utility.model.TestGroup;
import org.testng.annotations.Test;
/**
* Search high lighting test.
* @author Michael Suzuki
*
*/
public class SearchHighLightTest extends AbstractSearchTest
{
@Test(groups={TestGroup.SEARCH, TestGroup.REST_API})
public void searchWithHighLight() throws Exception
{
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery("description:workflow");
queryReq.setUserQuery("workflow");
RestRequestHighlightModel highlight = new RestRequestHighlightModel();
highlight.setPrefix("¿");
highlight.setPostfix("?");
highlight.setMergeContiguous(true);
List<RestRequestFieldsModel> fields = new ArrayList<RestRequestFieldsModel>();
fields.add(new RestRequestFieldsModel("cm:title"));
highlight.setFields(fields);
SearchResponse nodes = query(queryReq, highlight);
nodes.assertThat().entriesListIsNotEmpty();
ResponseHighLightModel hl = nodes.getEntryByIndex(0).getSearch().getHighlight().get(0);
hl.assertThat().field("snippets").contains("Customized ¿Workflow? Process Definitions");
}
@Test(groups={TestGroup.SEARCH,TestGroup.REST_API})
public void searchNonIndexedData() throws Exception
{
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery("cm:title");
queryReq.setUserQuery("zoro");
RestRequestHighlightModel highlight = new RestRequestHighlightModel();
highlight.setPrefix("¿");
highlight.setPostfix("?");
highlight.setMergeContiguous(true);
List<RestRequestFieldsModel> fields = new ArrayList<RestRequestFieldsModel>();
fields.add(new RestRequestFieldsModel("cm:title"));
highlight.setFields(fields);
SearchResponse nodes = query(queryReq, highlight);
nodes.assertThat().entriesListDoesNotContain("highlight");
}
}