From 8aae0779fffef6c1d42decfbd942a8a824061e01 Mon Sep 17 00:00:00 2001 From: Sara Aspery Date: Thu, 26 Jan 2023 09:07:50 +0000 Subject: [PATCH] Check for non-empty results and move some tests out of pipeline suite --- .../search/AbstractSearchServicesE2ETest.java | 53 +++++- .../search/SearchCasesTest.java | 162 ++++++++++++++++- .../search/SearchSimpleCasesTest.java | 164 +----------------- 3 files changed, 215 insertions(+), 164 deletions(-) diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/AbstractSearchServicesE2ETest.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/AbstractSearchServicesE2ETest.java index 9bc8ca2ce..919f3928f 100644 --- a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/AbstractSearchServicesE2ETest.java +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/AbstractSearchServicesE2ETest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Search Services E2E Test * %% - * Copyright (C) 2005 - 2022 Alfresco Software Limited + * Copyright (C) 2005 - 2023 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of @@ -26,10 +26,15 @@ package org.alfresco.test.search.functional.searchServices.search; +import org.alfresco.rest.exception.EmptyJsonResponseException; +import org.alfresco.rest.search.SearchResponse; import org.alfresco.test.search.functional.AbstractE2EFunctionalTest; +import org.alfresco.utility.Utility; import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FileType; import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.UserModel; +import org.springframework.http.HttpStatus; import org.testng.Assert; import static java.util.List.of; @@ -47,6 +52,10 @@ public abstract class AbstractSearchServicesE2ETest extends AbstractE2EFunctionalTest { private static final String SEARCH_DATA_SAMPLE_FOLDER = "FolderSearch"; + private static final int MAX_ATTEMPTS_TO_RETRY_QUERY = 10; + private static final int MAX_WAIT_IN_SECONDS_BEFORE_RETRY_QUERY = 5; + private static final int MAX_ATTEMPTS_TO_READ_RESPONSE = 10; + private static final int MAX_WAIT_IN_SECONDS_BEFORE_REREAD_RESPONSE = 2; /** The maximum time to wait for content indexing to complete (in ms). */ private static final int MAX_TIME = 120 * 1000; @@ -104,4 +113,46 @@ protected FileModel createFileWithProvidedText(String filename, String providedT return uniqueFile; } + + protected SearchResponse queryUntilResponseEntriesListNotEmpty(UserModel user, String queryString) + { + SearchResponse response = queryUntilStatusIsOk(user, queryString); + if (restClient.getStatusCode().matches(HttpStatus.OK.toString())) + { + for (int readAttempts = 0; readAttempts < MAX_ATTEMPTS_TO_READ_RESPONSE; readAttempts++) + { + if (!response.isEmpty()) + { + return response; + } + Utility.waitToLoopTime(MAX_WAIT_IN_SECONDS_BEFORE_REREAD_RESPONSE, "Re-reading empty response. Retry Attempt: " + (readAttempts + 1)); + } + } + + return response; + } + + private SearchResponse queryUntilStatusIsOk(UserModel user, String queryString) + { + // Repeat query until status is OK or Query Retry limit is hit + for (int queryAttempts = 0; queryAttempts < MAX_ATTEMPTS_TO_RETRY_QUERY - 1; queryAttempts++) + { + try + { + SearchResponse response = queryAsUser(user, queryString); + if (restClient.getStatusCode().matches(HttpStatus.OK.toString())) + { + return response; + } + + // Wait for pipeline to calm down + Utility.waitToLoopTime(MAX_WAIT_IN_SECONDS_BEFORE_RETRY_QUERY, "Re-trying query for valid status code. Retry Attempt: " + (queryAttempts + 1)); + } + catch (EmptyJsonResponseException ignore) + { + } + } + // Final attempt + return queryAsUser(user, queryString); + } } diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/SearchCasesTest.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/SearchCasesTest.java index ca732af73..0f7fd8084 100644 --- a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/SearchCasesTest.java +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/SearchCasesTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Search Services E2E Test * %% - * Copyright (C) 2005 - 2022 Alfresco Software Limited + * Copyright (C) 2005 - 2023 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of @@ -51,6 +51,162 @@ public void dataPreparation() throws Exception } @Test(priority=1) + public void testSearchNameField() + { + SearchRequest searchReq = new SearchRequest(); + RestRequestQueryModel queryReq = new RestRequestQueryModel(); + queryReq.setQuery("cm:name:pangram"); + queryReq.setUserQuery("pangram"); + searchReq.setQuery(queryReq); + SearchResponse response = queryAsUser(testUser, "cm:name:pangram"); + restClient.assertStatusCodeIs(HttpStatus.OK); + response.assertThat().entriesListIsNotEmpty(); + } + + @Test(priority=2) + public void testSearchTitleField() + { + SearchRequest searchReq = new SearchRequest(); + RestRequestQueryModel queryReq = new RestRequestQueryModel(); + queryReq.setQuery("cm:title:cars"); + queryReq.setUserQuery("cars"); + searchReq.setQuery(queryReq); + SearchResponse response2 = queryAsUser(testUser, "cm:title:cars"); + restClient.assertStatusCodeIs(HttpStatus.OK); + response2.assertThat().entriesListIsNotEmpty(); + } + + @Test(priority=3) + public void testSearchDescriptionField() + { + SearchRequest searchReq = new SearchRequest(); + RestRequestQueryModel queryReq = new RestRequestQueryModel(); + queryReq.setQuery("cm:description:alfresco"); + queryReq.setUserQuery("alfresco"); + searchReq.setQuery(queryReq); + SearchResponse response3 = queryAsUser(testUser, "cm:description:alfresco"); + restClient.assertStatusCodeIs(HttpStatus.OK); + response3.assertThat().entriesListIsNotEmpty(); + } + + @Test(priority=4) + public void testSearchTextFile() + { + SearchRequest searchReq = new SearchRequest(); + RestRequestQueryModel queryReq = new RestRequestQueryModel(); + queryReq.setQuery("cm:name:pangram.txt"); + queryReq.setUserQuery("pangram.txt"); + searchReq.setQuery(queryReq); + SearchResponse response6 = queryAsUser(testUser, "cm:name:pangram.txt"); + restClient.assertStatusCodeIs(HttpStatus.OK); + response6.assertThat().entriesListIsNotEmpty(); + } + + @Test(priority=5) + public void testSearchPDFFile() + { + SearchRequest searchReq = new SearchRequest(); + RestRequestQueryModel queryReq = new RestRequestQueryModel(); + queryReq.setQuery("cm:name:cars.PDF"); + queryReq.setUserQuery("cars.PDF"); + searchReq.setQuery(queryReq); + SearchResponse response6 = queryAsUser(testUser, "cm:name:cars.PDF"); + restClient.assertStatusCodeIs(HttpStatus.OK); + response6.assertThat().entriesListIsNotEmpty(); + } + + @Test(priority=6) + public void testSearchDocxFile() + { + SearchRequest searchReq = new SearchRequest(); + RestRequestQueryModel queryReq = new RestRequestQueryModel(); + queryReq.setQuery("cm:name:alfresco.docx"); + queryReq.setUserQuery("alfresco.docx"); + searchReq.setQuery(queryReq); + SearchResponse response6 = queryAsUser(testUser, "cm:name:alfresco.docx"); + restClient.assertStatusCodeIs(HttpStatus.OK); + response6.assertThat().entriesListIsNotEmpty(); + } + + @Test(priority=7) + public void testSearchPhraseQueries() + { + SearchRequest searchReq = new SearchRequest(); + RestRequestQueryModel queryReq = new RestRequestQueryModel(); + queryReq.setQuery("cm:name:alfresco"); + queryReq.setUserQuery("alfresco"); + searchReq.setQuery(queryReq); + SearchResponse response6 = queryAsUser(testUser, "The quick brown fox jumps over the lazy dog"); + restClient.assertStatusCodeIs(HttpStatus.OK); + response6.assertThat().entriesListIsNotEmpty(); + } + + @Test(priority=8) + public void testSearchExactTermQueries() + { + SearchRequest searchReq = new SearchRequest(); + RestRequestQueryModel queryReq = new RestRequestQueryModel(); + queryReq.setQuery("cm:name:alfresco"); + queryReq.setUserQuery("alfresco"); + searchReq.setQuery(queryReq); + SearchResponse response6 = queryAsUser(testUser, "=alfresco"); + restClient.assertStatusCodeIs(HttpStatus.OK); + response6.assertThat().entriesListIsNotEmpty(); + } + + @Test(priority=9) + public void testSearchConjunctionQueries() + { + SearchRequest searchReq = new SearchRequest(); + RestRequestQueryModel queryReq = new RestRequestQueryModel(); + queryReq.setQuery("cm:name:unique"); + queryReq.setUserQuery("unique"); + searchReq.setQuery(queryReq); + SearchResponse response6 = queryAsUser(testUser, "unique AND search"); + restClient.assertStatusCodeIs(HttpStatus.OK); + response6.assertThat().entriesListIsNotEmpty(); + } + + @Test(priority=10) + public void testSearchDisjunctionQueries() + { + SearchRequest searchReq = new SearchRequest(); + RestRequestQueryModel queryReq = new RestRequestQueryModel(); + queryReq.setQuery("cm:name:cars"); + queryReq.setUserQuery("cars"); + searchReq.setQuery(queryReq); + SearchResponse response6 = queryAsUser(testUser, "file OR discovery"); + restClient.assertStatusCodeIs(HttpStatus.OK); + response6.assertThat().entriesListIsNotEmpty(); + } + + @Test(priority=11) + public void testSearchNegationQueries() + { + SearchRequest searchReq = new SearchRequest(); + RestRequestQueryModel queryReq = new RestRequestQueryModel(); + queryReq.setQuery("cm:name:pangram"); + queryReq.setUserQuery("pangram"); + searchReq.setQuery(queryReq); + SearchResponse response6 = queryAsUser(testUser, "pangram NOT pan"); + restClient.assertStatusCodeIs(HttpStatus.OK); + response6.assertThat().entriesListIsNotEmpty(); + } + + @Test(priority=12) + public void testSearchWildcardQueries() + { + SearchRequest searchReq = new SearchRequest(); + RestRequestQueryModel queryReq = new RestRequestQueryModel(); + queryReq.setQuery("cm:name:alfresco"); + queryReq.setUserQuery("alfresco"); + searchReq.setQuery(queryReq); + SearchResponse response6 = queryAsUser(testUser, "al?res*"); + restClient.assertStatusCodeIs(HttpStatus.OK); + response6.assertThat().entriesListIsNotEmpty(); + } + + @Test(priority=13) public void testSearchUpdateContent() throws InterruptedException { String originalText = String.valueOf(System.currentTimeMillis()); @@ -96,7 +252,7 @@ public void testSearchUpdateContent() throws InterruptedException * } * } */ - @Test(priority=2) + @Test(priority=14) public void searchWithFacedFields() throws InterruptedException { String uniqueText = String.valueOf(System.currentTimeMillis()); @@ -134,7 +290,7 @@ public void searchWithFacedFields() throws InterruptedException bucket1.assertThat().field("count").is(1); } - @Test(priority=3) + @Test(priority=15) public void searchSpecialCharacters() { String specialCharfileName = "è¥äæ§ç§-åæ.pdf"; diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/SearchSimpleCasesTest.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/SearchSimpleCasesTest.java index 72b34811c..8fa3ace31 100644 --- a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/SearchSimpleCasesTest.java +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/SearchSimpleCasesTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Search Services E2E Test * %% - * Copyright (C) 2005 - 2022 Alfresco Software Limited + * Copyright (C) 2005 - 2023 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of @@ -39,45 +39,6 @@ public void dataPreparation() throws Exception } @Test(priority=1) - public void testSearchNameField() - { - SearchRequest searchReq = new SearchRequest(); - RestRequestQueryModel queryReq = new RestRequestQueryModel(); - queryReq.setQuery("cm:name:pangram"); - queryReq.setUserQuery("pangram"); - searchReq.setQuery(queryReq); - SearchResponse response = queryAsUser(testUser, "cm:name:pangram"); - restClient.assertStatusCodeIs(HttpStatus.OK); - response.assertThat().entriesListIsNotEmpty(); - } - - @Test(priority=2) - public void testSearchTitleField() - { - SearchRequest searchReq = new SearchRequest(); - RestRequestQueryModel queryReq = new RestRequestQueryModel(); - queryReq.setQuery("cm:title:cars"); - queryReq.setUserQuery("cars"); - searchReq.setQuery(queryReq); - SearchResponse response2 = queryAsUser(testUser, "cm:title:cars"); - restClient.assertStatusCodeIs(HttpStatus.OK); - response2.assertThat().entriesListIsNotEmpty(); - } - - @Test(priority=3) - public void testSearchDescriptionField() - { - SearchRequest searchReq = new SearchRequest(); - RestRequestQueryModel queryReq = new RestRequestQueryModel(); - queryReq.setQuery("cm:description:alfresco"); - queryReq.setUserQuery("alfresco"); - searchReq.setQuery(queryReq); - SearchResponse response3 = queryAsUser(testUser, "cm:description:alfresco"); - restClient.assertStatusCodeIs(HttpStatus.OK); - response3.assertThat().entriesListIsNotEmpty(); - } - - @Test(priority=4) public void testSearchContentField() { SearchRequest searchReq = new SearchRequest(); @@ -85,51 +46,12 @@ public void testSearchContentField() queryReq.setQuery("cm:content:unique"); queryReq.setUserQuery("unique"); searchReq.setQuery(queryReq); - SearchResponse response4 = queryAsUser(testUser, "cm:content:unique"); + SearchResponse response4 = queryUntilResponseEntriesListNotEmpty(testUser, "cm:content:unique"); restClient.assertStatusCodeIs(HttpStatus.OK); response4.assertThat().entriesListIsNotEmpty(); } - @Test(priority=6) - public void testSearchTextFile() - { - SearchRequest searchReq = new SearchRequest(); - RestRequestQueryModel queryReq = new RestRequestQueryModel(); - queryReq.setQuery("cm:name:pangram.txt"); - queryReq.setUserQuery("pangram.txt"); - searchReq.setQuery(queryReq); - SearchResponse response6 = queryAsUser(testUser, "cm:name:pangram.txt"); - restClient.assertStatusCodeIs(HttpStatus.OK); - response6.assertThat().entriesListIsNotEmpty(); - } - - @Test(priority=7) - public void testSearchPDFFile() - { - SearchRequest searchReq = new SearchRequest(); - RestRequestQueryModel queryReq = new RestRequestQueryModel(); - queryReq.setQuery("cm:name:cars.PDF"); - queryReq.setUserQuery("cars.PDF"); - searchReq.setQuery(queryReq); - SearchResponse response6 = queryAsUser(testUser, "cm:name:cars.PDF"); - restClient.assertStatusCodeIs(HttpStatus.OK); - response6.assertThat().entriesListIsNotEmpty(); - } - - @Test(priority=8) - public void testSearchDocxFile() - { - SearchRequest searchReq = new SearchRequest(); - RestRequestQueryModel queryReq = new RestRequestQueryModel(); - queryReq.setQuery("cm:name:alfresco.docx"); - queryReq.setUserQuery("alfresco.docx"); - searchReq.setQuery(queryReq); - SearchResponse response6 = queryAsUser(testUser, "cm:name:alfresco.docx"); - restClient.assertStatusCodeIs(HttpStatus.OK); - response6.assertThat().entriesListIsNotEmpty(); - } - - @Test(priority=9) + @Test(priority=2) public void testSearchODTFile() { SearchRequest searchReq = new SearchRequest(); @@ -137,85 +59,7 @@ public void testSearchODTFile() queryReq.setQuery("cm:name:unique.ODT"); queryReq.setUserQuery("unique.ODT"); searchReq.setQuery(queryReq); - SearchResponse response6 = queryAsUser(testUser, "cm:name:unique.ODT"); - restClient.assertStatusCodeIs(HttpStatus.OK); - response6.assertThat().entriesListIsNotEmpty(); - } - - @Test(priority=12) - public void testSearchPhraseQueries() - { - SearchRequest searchReq = new SearchRequest(); - RestRequestQueryModel queryReq = new RestRequestQueryModel(); - queryReq.setQuery("cm:name:alfresco"); - queryReq.setUserQuery("alfresco"); - searchReq.setQuery(queryReq); - SearchResponse response6 = queryAsUser(testUser, "The quick brown fox jumps over the lazy dog"); - restClient.assertStatusCodeIs(HttpStatus.OK); - response6.assertThat().entriesListIsNotEmpty(); - } - - @Test(priority=13) - public void testSearchExactTermQueries() - { - SearchRequest searchReq = new SearchRequest(); - RestRequestQueryModel queryReq = new RestRequestQueryModel(); - queryReq.setQuery("cm:name:alfresco"); - queryReq.setUserQuery("alfresco"); - searchReq.setQuery(queryReq); - SearchResponse response6 = queryAsUser(testUser, "=alfresco"); - restClient.assertStatusCodeIs(HttpStatus.OK); - response6.assertThat().entriesListIsNotEmpty(); - } - - @Test(priority=14) - public void testSearchConjunctionQueries() - { - SearchRequest searchReq = new SearchRequest(); - RestRequestQueryModel queryReq = new RestRequestQueryModel(); - queryReq.setQuery("cm:name:unique"); - queryReq.setUserQuery("unique"); - searchReq.setQuery(queryReq); - SearchResponse response6 = queryAsUser(testUser, "unique AND search"); - restClient.assertStatusCodeIs(HttpStatus.OK); - response6.assertThat().entriesListIsNotEmpty(); - } - - @Test(priority=15) - public void testSearchDisjunctionQueries() - { - SearchRequest searchReq = new SearchRequest(); - RestRequestQueryModel queryReq = new RestRequestQueryModel(); - queryReq.setQuery("cm:name:cars"); - queryReq.setUserQuery("cars"); - searchReq.setQuery(queryReq); - SearchResponse response6 = queryAsUser(testUser, "file OR discovery"); - restClient.assertStatusCodeIs(HttpStatus.OK); - response6.assertThat().entriesListIsNotEmpty(); - } - - @Test(priority=16) - public void testSearchNegationQueries() - { - SearchRequest searchReq = new SearchRequest(); - RestRequestQueryModel queryReq = new RestRequestQueryModel(); - queryReq.setQuery("cm:name:pangram"); - queryReq.setUserQuery("pangram"); - searchReq.setQuery(queryReq); - SearchResponse response6 = queryAsUser(testUser, "pangram NOT pan"); - restClient.assertStatusCodeIs(HttpStatus.OK); - response6.assertThat().entriesListIsNotEmpty(); - } - - @Test(priority=17) - public void testSearchWildcardQueries() - { - SearchRequest searchReq = new SearchRequest(); - RestRequestQueryModel queryReq = new RestRequestQueryModel(); - queryReq.setQuery("cm:name:alfresco"); - queryReq.setUserQuery("alfresco"); - searchReq.setQuery(queryReq); - SearchResponse response6 = queryAsUser(testUser, "al?res*"); + SearchResponse response6 = queryUntilResponseEntriesListNotEmpty(testUser, "cm:name:unique.ODT"); restClient.assertStatusCodeIs(HttpStatus.OK); response6.assertThat().entriesListIsNotEmpty(); }