diff --git a/e2e-test/java/org/alfresco/rest/search/AbstractSearchTest.java b/e2e-test/java/org/alfresco/rest/search/AbstractSearchTest.java
index 67df467c3..47d1d8b6d 100644
--- a/e2e-test/java/org/alfresco/rest/search/AbstractSearchTest.java
+++ b/e2e-test/java/org/alfresco/rest/search/AbstractSearchTest.java
@@ -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);
+ }
}
diff --git a/e2e-test/java/org/alfresco/rest/search/SearchHighLightTest.java b/e2e-test/java/org/alfresco/rest/search/SearchHighLightTest.java
new file mode 100644
index 000000000..08aa6c473
--- /dev/null
+++ b/e2e-test/java/org/alfresco/rest/search/SearchHighLightTest.java
@@ -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 .
+ */
+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 fields = new ArrayList();
+ 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 fields = new ArrayList();
+ fields.add(new RestRequestFieldsModel("cm:title"));
+ highlight.setFields(fields);
+ SearchResponse nodes = query(queryReq, highlight);
+ nodes.assertThat().entriesListDoesNotContain("highlight");
+ }
+}