From c8da8c9081fafd51f9f7525a420327ffb8ca459c Mon Sep 17 00:00:00 2001 From: cagache Date: Tue, 12 Dec 2017 09:32:07 +0200 Subject: [PATCH] automated AC for MNT-15575, regarding share live search for words from RM Saved Searches (cherry picked from commit a33cb6e) --- .../org/alfresco/rest/core/v0/BaseAPI.java | 3 +- .../java/org/alfresco/rest/v0/SearchAPI.java | 32 +++++++++++++ .../rm/community/search/ShareLiveSearch.java | 45 +++++++++++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/ShareLiveSearch.java diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java index 3f5f0dbda8..dbe7fe3608 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java @@ -73,7 +73,7 @@ import org.springframework.beans.factory.annotation.Autowired; public abstract class BaseAPI { // logger - private static final Logger LOGGER = LoggerFactory.getLogger(BaseAPI.class); + protected static final Logger LOGGER = LoggerFactory.getLogger(BaseAPI.class); /** exception key in JSON response body */ private static final String EXCEPTION_KEY = "exception"; @@ -216,6 +216,7 @@ public abstract class BaseAPI client.getAlfrescoUrl(), URLEncodedUtils.format(parameters, "UTF-8")); } + LOGGER.info("On GET {}, received following response: ", requestURL); client.close(); return doGetRequest(username, password, requestURL); } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java index 176b51d2d8..0e4af8732e 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java @@ -36,6 +36,7 @@ import org.alfresco.rest.core.v0.BaseAPI; import org.apache.http.NameValuePair; import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.message.BasicNameValuePair; +import org.json.JSONException; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -56,6 +57,9 @@ public class SearchAPI extends BaseAPI /** faceted search API endpoint */ private static final String FACETED_SEARCH_ENDPOINT = "{0}alfresco/s/slingshot/rmsearch/faceted/rmsearch?{1}"; + /** share live search API endpoint */ + private static final String SHARE_LIVE_SEARCH_DOCS_ENDPOINT = "{0}alfresco/s/slingshot/live-search-docs?{1}"; + /** RM search URL template */ private static final String RM_SEARCH_ENDPOINT = "{0}alfresco/s/slingshot/rmsearch/{1}?{2}"; @@ -138,6 +142,20 @@ public class SearchAPI extends BaseAPI return facetedRequest(username, password, parameters, FACETED_SEARCH_ENDPOINT); } + /** + * Execute share live search for documents. + * + * @param searchUser + * @param searchPassword + * @param searchTerm + * @return search results (see API reference for more details) + */ + public JSONObject liveSearchForDocuments(String searchUser, String searchPassword, String searchTerm) + { + return facetedRequest(searchUser, searchPassword, Arrays.asList(new BasicNameValuePair("t", searchTerm)), + SHARE_LIVE_SEARCH_DOCS_ENDPOINT); + } + /** * Execute faceted search for term. * @param searchUser @@ -165,6 +183,20 @@ public class SearchAPI extends BaseAPI return getItemNames(facetedSearchForTerm(username, password, term)); } + /** + * Helper method to search for documents as a user using share live search. + * @param username to search as + * @param password for username + * @param term search term + * @return list of document names found + */ + public List liveSearchForDocumentsAsUser(String username, String password, String term) throws JSONException + { + JSONObject searchResult = liveSearchForDocuments(username, password, term); + LOGGER.info(searchResult.toString(3)); + return getItemNames(searchResult); + } + /** * Helper method to extract list of names from search result. * @param searchResult diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/ShareLiveSearch.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/ShareLiveSearch.java new file mode 100644 index 0000000000..361396b86b --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/ShareLiveSearch.java @@ -0,0 +1,45 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2017 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ + +package org.alfresco.rest.rm.community.search; + +import static org.testng.Assert.assertTrue; + +import java.util.Arrays; +import java.util.List; + +import org.alfresco.rest.rm.community.base.BaseRMRestTest; +import org.alfresco.rest.v0.SearchAPI; +import org.alfresco.test.AlfrescoTest; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.Test; + +public class ShareLiveSearch extends BaseRMRestTest +{ + @Autowired + SearchAPI searchApi; + + /** + * Given the RM site has been created When I search for "vital" Then the "Vital Records Due for Review" search + * object should not appear as a link in the quick search results drop down + */ + @Test + @AlfrescoTest(jira = "RM-5882") + public void liveSearchForVitalWord() throws Exception + { + createRMSiteIfNotExists(); + List results = searchApi.liveSearchForDocumentsAsUser(getAdminUser().getUsername(), getAdminUser().getPassword(), "vital"); + assertTrue(results.isEmpty() || !results.stream().anyMatch("Vital Records due for Review"::equalsIgnoreCase), + "Share Live Search should return 0 results when searching for RM Saved Search filter words, but it returned:" + + Arrays.toString(results.toArray())); + } +}