From 547f356504796b60bfde8f6e695edee72fea9af2 Mon Sep 17 00:00:00 2001 From: Michael Suzuki Date: Mon, 6 Mar 2017 10:21:20 +0000 Subject: [PATCH] Complete spellcheck rest tests --- .../rest/search/SearchSpellCheckTest.java | 92 ++++++++++++++++--- 1 file changed, 80 insertions(+), 12 deletions(-) diff --git a/e2e-test/java/org/alfresco/rest/search/SearchSpellCheckTest.java b/e2e-test/java/org/alfresco/rest/search/SearchSpellCheckTest.java index 7e7c9442d..a13e447fb 100644 --- a/e2e-test/java/org/alfresco/rest/search/SearchSpellCheckTest.java +++ b/e2e-test/java/org/alfresco/rest/search/SearchSpellCheckTest.java @@ -20,32 +20,100 @@ package org.alfresco.rest.search; import org.alfresco.rest.model.RestRequestSpellcheckModel; import org.alfresco.utility.model.TestGroup; -import org.springframework.http.HttpStatus; +import org.junit.Assert; import org.testng.annotations.Test; /** * Search end point Public API test with spell checking enabled. * @author Michael Suzuki - * + *5 */ public class SearchSpellCheckTest extends AbstractSearchTest { -// @Test(groups={TestGroup.SEARCH, TestGroup.REST_API}) + /** + * Perform the below query + * { + * "spellcheck" : { }, + * "query" : { + * "userQuery" : "alfrezco", + * "query" : "cm:title:alfrezco" + * } + * to yeild the following result. + * { + * "list": { + * "pagination": { + * "count": 22, + * "hasMoreItems": false, + * "totalItems": 22, + * "skipCount": 0, + * "maxItems": 100 + * }, + * "context": { + * "spellCheck": { + * "type": "searchInsteadFor", + * "suggestions": [ + * "alfresco" + * ] + * } + * }, + * "entries": [...] + * } + * + * @throws Exception + */ + @Test(groups={TestGroup.SEARCH, TestGroup.REST_API}) public void searchMissSpelled() throws Exception { - - SearchResponse nodes = query("carz"); - restClient.assertStatusCodeIs(HttpStatus.OK); - nodes.assertThat().entriesListIsEmpty(); - SearchRequest searchReq = new SearchRequest(); RestRequestQueryModel queryReq = new RestRequestQueryModel(); - queryReq.setQuery("cm:content:carz"); - queryReq.setUserQuery("carz"); + queryReq.setQuery("cm:title:alfrezco"); + queryReq.setUserQuery("alfrezco"); searchReq.setQuery(queryReq); searchReq.setSpellcheck(new RestRequestSpellcheckModel()); - nodes = query(searchReq); + assertResponse(query(searchReq)); + } + private void assertResponse(SearchResponse nodes) throws Exception + { nodes.assertThat().entriesListIsNotEmpty(); + nodes.getContext().assertThat().field("spellCheck").isNotEmpty(); + nodes.getContext().getSpellCheck().assertThat().field("suggestions").contains("alfresco"); + } + @Test + /** + * Perform alternative way by setting the value in spellcheck object. + * + * { + * "query": { + * "query": "cm:title:alfrezco", + * "language": "afts" + * }, + * "spellcheck": {"query": "alfrezco"} + * } + * @throws Exception + */ + public void searchMissSpelledVersion2() throws Exception + { + SearchRequest searchReq = new SearchRequest(); + RestRequestQueryModel queryReq = new RestRequestQueryModel(); + queryReq.setQuery("cm:title:alfrezco"); + searchReq.setQuery(queryReq); + + RestRequestSpellcheckModel spellCheck = new RestRequestSpellcheckModel(); + spellCheck.setQuery("alfrezco"); + searchReq.setSpellcheck(spellCheck); + assertResponse(query(searchReq)); + } + @Test + public void searchWithSpellcheckerAndCorrectSpelling() throws Exception + { + SearchRequest searchReq = new SearchRequest(); + RestRequestQueryModel queryReq = new RestRequestQueryModel(); + queryReq.setQuery("cm:title:alfresco"); + queryReq.setUserQuery("alfresco"); + searchReq.setQuery(queryReq); + searchReq.setSpellcheck(new RestRequestSpellcheckModel()); + SearchResponse res = query(searchReq); + Assert.assertNull(res.getContext()); + res.assertThat().entriesListIsNotEmpty(); } - }