From a5b86b073e0a476b34846e088e54aaed9f06cbeb Mon Sep 17 00:00:00 2001 From: kcichonczyk Date: Thu, 17 Nov 2022 16:45:38 +0100 Subject: [PATCH 01/17] [ACS-3973] Added PipelineSuite (and its test classes) that belonged to the master branch --- .../search/SearchCasesTest.java | 293 ++++++++++++++++++ e2e-test/src/test/resources/PipelineSuite.xml | 16 + 2 files changed, 309 insertions(+) create mode 100644 e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/SearchCasesTest.java create mode 100644 e2e-test/src/test/resources/PipelineSuite.xml 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 new file mode 100644 index 000000000..cf5d1f6fa --- /dev/null +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/SearchCasesTest.java @@ -0,0 +1,293 @@ +package org.alfresco.test.search.functional.searchServices.search; + +import org.alfresco.rest.search.FacetFieldBucket; +import org.alfresco.rest.search.RestRequestFacetFieldModel; +import org.alfresco.rest.search.RestRequestFacetFieldsModel; +import org.alfresco.rest.search.RestRequestQueryModel; +import org.alfresco.rest.search.RestResultBucketsModel; +import org.alfresco.rest.search.SearchRequest; +import org.alfresco.rest.search.SearchResponse; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.hamcrest.Matchers; +import org.springframework.http.HttpStatus; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.List; + +public class SearchCasesTest extends AbstractSearchServicesE2ETest +{ + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + searchServicesDataPreparation(); + Assert.assertTrue(waitForContentIndexing(file4.getContent(), true)); + } + + @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(); + RestRequestQueryModel queryReq = new RestRequestQueryModel(); + queryReq.setQuery("cm:content:unique"); + queryReq.setUserQuery("unique"); + searchReq.setQuery(queryReq); + SearchResponse response4 = queryAsUser(testUser, "cm:content:unique"); + restClient.assertStatusCodeIs(HttpStatus.OK); + response4.assertThat().entriesListIsNotEmpty(); + } + + @Test(priority=5) + public void testSearchUpdateContent() + { + SearchRequest searchReq = new SearchRequest(); + + SearchResponse response4 = queryAsUser(testUser, "cm:content:brown"); + restClient.assertStatusCodeIs(HttpStatus.OK); + response4.assertThat().entriesListIsNotEmpty(); + String newContent = "The quick red fox jumps over the lazy dog"; + + dataContent.usingUser(adminUserModel).usingSite(testSite).usingResource(file) + .updateContent(newContent); + + Assert.assertTrue(waitForContentIndexing("red", true)); + + SearchResponse response5 = queryAsUser(testUser, "cm:content:brown"); + restClient.assertStatusCodeIs(HttpStatus.OK); + response5.assertThat().entriesListIsEmpty(); + } + + @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) + public void testSearchODTFile() + { + SearchRequest searchReq = new SearchRequest(); + RestRequestQueryModel queryReq = new RestRequestQueryModel(); + 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(); + } + + /** + * { + * "query": { + * "query": "*" + * }, + * "facetFields": { + * "facets": [{"field": "cm:mimetype"},{"field": "modifier"}] + * } + * } + */ + @Test(priority=10) + public void searchWithFactedFields() + { + SearchRequest query = new SearchRequest(); + RestRequestQueryModel queryReq = new RestRequestQueryModel(); + queryReq.setQuery("cm:content:unique"); + query.setQuery(queryReq); + + RestRequestFacetFieldsModel facetFields = new RestRequestFacetFieldsModel(); + List facets = new ArrayList<>(); + facets.add(new RestRequestFacetFieldModel("cm:mimetype")); + facets.add(new RestRequestFacetFieldModel("modifier")); + facetFields.setFacets(facets); + query.setFacetFields(facetFields); + + SearchResponse response = query(query); + + Assert.assertNotNull(response.getContext().getFacetsFields()); + Assert.assertFalse(response.getContext().getFacetsFields().isEmpty()); + Assert.assertNull(response.getContext().getFacetQueries()); + Assert.assertNull(response.getContext().getFacets()); + + RestResultBucketsModel model = response.getContext().getFacetsFields().get(0); + Assert.assertEquals(model.getLabel(), "modifier"); + + model.assertThat().field("label").is("modifier"); + FacetFieldBucket bucket1 = model.getBuckets().get(0); + bucket1.assertThat().field("label").is(testUser.getUsername()); + bucket1.assertThat().field("display").is("FN-" + testUser.getUsername() + " LN-" + testUser.getUsername()); + bucket1.assertThat().field("filterQuery").is("modifier:\"" + testUser.getUsername() + "\""); + bucket1.assertThat().field("count").is(1); + } + + @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*"); + restClient.assertStatusCodeIs(HttpStatus.OK); + response6.assertThat().entriesListIsNotEmpty(); + } + + @Test(priority=18) + public void searchSpecialCharacters() + { + String specialCharfileName = "è¥äæ§ç§-åæ.pdf"; + FileModel file = new FileModel(specialCharfileName, "è¥äæ§ç§-忬¯¸" + "è¥äæ§ç§-忬¯¸", "è¥äæ§ç§-忬¯¸", FileType.TEXT_PLAIN, + "Text file with Special Characters: " + specialCharfileName); + dataContent.usingUser(testUser).usingSite(testSite).createContent(file); + + waitForIndexing(file.getName(), true); + + SearchRequest searchReq = createQuery("name:'" + specialCharfileName + "'"); + SearchResponse nodes = query(searchReq); + + restClient.assertStatusCodeIs(HttpStatus.OK); + nodes.assertThat().entriesListIsNotEmpty(); + + restClient.onResponse().assertThat().body("list.entries.entry[0].name", Matchers.equalToIgnoringCase(specialCharfileName)); + } +} diff --git a/e2e-test/src/test/resources/PipelineSuite.xml b/e2e-test/src/test/resources/PipelineSuite.xml new file mode 100644 index 000000000..8716f6015 --- /dev/null +++ b/e2e-test/src/test/resources/PipelineSuite.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + From cb30043b35b629524f446a38de8e1235490f51e7 Mon Sep 17 00:00:00 2001 From: kcichonczyk Date: Mon, 21 Nov 2022 16:38:44 +0100 Subject: [PATCH 02/17] added header --- .../searchServices/search/SearchCasesTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 cf5d1f6fa..ce6564642 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 @@ -1,3 +1,14 @@ +/*- + * #%L + * Alfresco Elasticsearch Connector :: Database Connector + * %% + * Copyright (C) 2022 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.test.search.functional.searchServices.search; import org.alfresco.rest.search.FacetFieldBucket; From 1c9aef6178ef2a69b20799025f416a625c487f7b Mon Sep 17 00:00:00 2001 From: kcichonczyk Date: Tue, 22 Nov 2022 10:33:41 +0100 Subject: [PATCH 03/17] Changed license header --- .../search/SearchCasesTest.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) 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 ce6564642..eb34138b7 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 @@ -1,12 +1,23 @@ -/*- +/* * #%L - * Alfresco Elasticsearch Connector :: Database Connector + * Alfresco Search Services E2E Test * %% - * Copyright (C) 2022 Alfresco Software Limited + * Copyright (C) 2005 - 2022 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. + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * 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 . * #L% */ package org.alfresco.test.search.functional.searchServices.search; From 6e4f1ddeb67e5a0ff156d78ad870ed6a70bb29b8 Mon Sep 17 00:00:00 2001 From: kcichonczyk Date: Wed, 23 Nov 2022 10:57:29 +0100 Subject: [PATCH 04/17] changed prepared file types --- .../search/AbstractSearchServicesE2ETest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 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 4ebb66e9f..cdbac2f77 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 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2022 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of @@ -71,13 +71,13 @@ public abstract class AbstractSearchServicesE2ETest extends AbstractE2EFunctiona file = new FileModel("pangram.txt", "pangram" + title, description, FileType.TEXT_PLAIN, description + " The quick brown fox jumps over the lazy dog"); - file2 = new FileModel("cars.txt", "cars" + title, description, FileType.TEXT_PLAIN, - "The landrover discovery is not a sports car "); + file2 = new FileModel("cars.PDF", "cars", description, FileType.TEXT_PLAIN, + "The landrover discovery is not a sports car"); - file3 = new FileModel("alfresco.txt", "alfresco", "alfresco", FileType.TEXT_PLAIN, + file3 = new FileModel("alfresco.docx", "alfresco", "alfresco", FileType.TEXT_PLAIN, "Alfresco text file for search "); - file4 = new FileModel(unique_searchString + ".txt", "uniquee" + title, description, FileType.TEXT_PLAIN, + file4 = new FileModel(unique_searchString + ".ODT", "uniquee" + title, description, FileType.TEXT_PLAIN, "Unique text file for search "); From f05cb17e5623633d7f541e449e3ff8c165715b3f Mon Sep 17 00:00:00 2001 From: kcichonczyk Date: Wed, 23 Nov 2022 11:36:50 +0100 Subject: [PATCH 05/17] changed files extensions according to extensions in data preparation method --- .../functional/searchServices/search/SearchTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/SearchTest.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/SearchTest.java index 3ecf2d9e2..6043656e7 100644 --- a/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/SearchTest.java +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/searchServices/search/SearchTest.java @@ -115,9 +115,9 @@ public class SearchTest extends AbstractSearchServicesE2ETest public void searchWithOneSortClause() { // Tests the ascending order first - List expectedOrder = asList("alfresco.txt", "cars.txt", "pangram.txt"); + List expectedOrder = asList("alfresco.docx", "cars.PDF", "pangram.txt"); - SearchRequest searchRequest = createQuery("cm_name:alfresco\\.txt cm_name:cars\\.txt cm_name:pangram\\.txt"); + SearchRequest searchRequest = createQuery("cm_name:alfresco\\.docx cm_name:cars\\.PDF cm_name:pangram\\.txt"); searchRequest.addSortClause("FIELD", "name", true); RestRequestFilterQueryModel filters = new RestRequestFilterQueryModel(); @@ -162,9 +162,9 @@ public class SearchTest extends AbstractSearchServicesE2ETest public void searchWithTwoSortClauses() { // Tests the ascending order first - List expectedOrder = asList("alfresco.txt", "cars.txt", "pangram.txt"); + List expectedOrder = asList("alfresco.docx", "cars.PDF", "pangram.txt"); - SearchRequest searchRequest = createQuery("cm_name:alfresco\\.txt cm_name:cars\\.txt cm_name:pangram\\.txt"); + SearchRequest searchRequest = createQuery("cm_name:alfresco\\.docx cm_name:cars\\.PDF cm_name:pangram\\.txt"); searchRequest.addSortClause("FIELD", "name", true); searchRequest.addSortClause("FIELD", "createdByUser.id", true); From f91962d08aef191a6518a0c324e667a03bb54547 Mon Sep 17 00:00:00 2001 From: kcichonczyk Date: Thu, 24 Nov 2022 12:42:28 +0100 Subject: [PATCH 06/17] changed assertions to match cases, when other tests interfere with buckets or repo. --- .../searchServices/search/SearchCasesTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 eb34138b7..35d69b0f6 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 @@ -104,8 +104,6 @@ public class SearchCasesTest extends AbstractSearchServicesE2ETest @Test(priority=5) public void testSearchUpdateContent() { - SearchRequest searchReq = new SearchRequest(); - SearchResponse response4 = queryAsUser(testUser, "cm:content:brown"); restClient.assertStatusCodeIs(HttpStatus.OK); response4.assertThat().entriesListIsNotEmpty(); @@ -117,8 +115,10 @@ public class SearchCasesTest extends AbstractSearchServicesE2ETest Assert.assertTrue(waitForContentIndexing("red", true)); SearchResponse response5 = queryAsUser(testUser, "cm:content:brown"); + restClient.assertStatusCodeIs(HttpStatus.OK); - response5.assertThat().entriesListIsEmpty(); + int initialEntriesSize = response4.getEntries().size(); + response5.assertThat().entriesListCountIs( initialEntriesSize - 1); } @Test(priority=6) @@ -184,7 +184,7 @@ public class SearchCasesTest extends AbstractSearchServicesE2ETest * } */ @Test(priority=10) - public void searchWithFactedFields() + public void searchWithFacedFields() { SearchRequest query = new SearchRequest(); RestRequestQueryModel queryReq = new RestRequestQueryModel(); @@ -213,7 +213,7 @@ public class SearchCasesTest extends AbstractSearchServicesE2ETest bucket1.assertThat().field("label").is(testUser.getUsername()); bucket1.assertThat().field("display").is("FN-" + testUser.getUsername() + " LN-" + testUser.getUsername()); bucket1.assertThat().field("filterQuery").is("modifier:\"" + testUser.getUsername() + "\""); - bucket1.assertThat().field("count").is(1); + bucket1.assertThat().field("count").isGreaterThan(0); } @Test(priority=12) From 4d566c30b9f6b77cac3d2492c7e15fcd8618d5ae Mon Sep 17 00:00:00 2001 From: Sara Aspery Date: Mon, 28 Nov 2022 16:56:05 +0000 Subject: [PATCH 07/17] add temporary delay for debugging --- .../search/SearchCasesTest.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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 35d69b0f6..88648e27d 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 @@ -29,6 +29,7 @@ import org.alfresco.rest.search.RestRequestQueryModel; import org.alfresco.rest.search.RestResultBucketsModel; import org.alfresco.rest.search.SearchRequest; import org.alfresco.rest.search.SearchResponse; +import org.alfresco.utility.Utility; import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FileType; import org.hamcrest.Matchers; @@ -107,16 +108,30 @@ public class SearchCasesTest extends AbstractSearchServicesE2ETest SearchResponse response4 = queryAsUser(testUser, "cm:content:brown"); restClient.assertStatusCodeIs(HttpStatus.OK); response4.assertThat().entriesListIsNotEmpty(); - String newContent = "The quick red fox jumps over the lazy dog"; + //TODO: remove - temp check for debugging + SearchResponse responseRB = queryAsUser(testUser, "cm:content:red"); + restClient.assertStatusCodeIs(HttpStatus.OK); + String beforeUpdate = "brown entries: " + response4.getEntries().size() + " red entries: " + responseRB.getEntries().size(); + Assert.assertEquals(beforeUpdate, "brown entries: 1 red entries: 0"); + + String newContent = "The quick red fox jumps over the lazy dog"; dataContent.usingUser(adminUserModel).usingSite(testSite).usingResource(file) .updateContent(newContent); - Assert.assertTrue(waitForContentIndexing("red", true)); - SearchResponse response5 = queryAsUser(testUser, "cm:content:brown"); + //TODO: remove - artificially long wait for debugging + Utility.waitToLoopTime(60); + SearchResponse response5 = queryAsUser(testUser, "cm:content:brown"); restClient.assertStatusCodeIs(HttpStatus.OK); + + //TODO: remove - temp check for debugging + SearchResponse responseRA = queryAsUser(testUser, "cm:content:red"); + restClient.assertStatusCodeIs(HttpStatus.OK); + String afterUpdate = "brown entries: " + response5.getEntries().size() + " red entries: " + responseRA.getEntries().size(); + Assert.assertEquals(afterUpdate, "brown entries: 0 red entries: 1"); + int initialEntriesSize = response4.getEntries().size(); response5.assertThat().entriesListCountIs( initialEntriesSize - 1); } From 072912bb29c73fd9ddcc84391e75d3c562762a41 Mon Sep 17 00:00:00 2001 From: Sara Aspery Date: Mon, 28 Nov 2022 22:54:26 +0000 Subject: [PATCH 08/17] change query to avoid common sequence --- .../searchServices/search/SearchCasesTest.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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 88648e27d..99601f9be 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 @@ -110,15 +110,15 @@ public class SearchCasesTest extends AbstractSearchServicesE2ETest response4.assertThat().entriesListIsNotEmpty(); //TODO: remove - temp check for debugging - SearchResponse responseRB = queryAsUser(testUser, "cm:content:red"); + SearchResponse responseRB = queryAsUser(testUser, "cm:content:purple"); restClient.assertStatusCodeIs(HttpStatus.OK); - String beforeUpdate = "brown entries: " + response4.getEntries().size() + " red entries: " + responseRB.getEntries().size(); - Assert.assertEquals(beforeUpdate, "brown entries: 1 red entries: 0"); + String beforeUpdate = "brown entries: " + response4.getEntries().size() + " purple entries: " + responseRB.getEntries().size(); + Assert.assertEquals(beforeUpdate, "brown entries: 1 purple entries: 0"); - String newContent = "The quick red fox jumps over the lazy dog"; + String newContent = "The quick purple fox jumps over the lazy dog"; dataContent.usingUser(adminUserModel).usingSite(testSite).usingResource(file) .updateContent(newContent); - Assert.assertTrue(waitForContentIndexing("red", true)); + Assert.assertTrue(waitForContentIndexing("purple", true)); //TODO: remove - artificially long wait for debugging Utility.waitToLoopTime(60); @@ -127,10 +127,10 @@ public class SearchCasesTest extends AbstractSearchServicesE2ETest restClient.assertStatusCodeIs(HttpStatus.OK); //TODO: remove - temp check for debugging - SearchResponse responseRA = queryAsUser(testUser, "cm:content:red"); + SearchResponse responseRA = queryAsUser(testUser, "cm:content:purple"); restClient.assertStatusCodeIs(HttpStatus.OK); - String afterUpdate = "brown entries: " + response5.getEntries().size() + " red entries: " + responseRA.getEntries().size(); - Assert.assertEquals(afterUpdate, "brown entries: 0 red entries: 1"); + String afterUpdate = "brown entries: " + response5.getEntries().size() + " purple entries: " + responseRA.getEntries().size(); + Assert.assertEquals(afterUpdate, "brown entries: 0 purple entries: 1"); int initialEntriesSize = response4.getEntries().size(); response5.assertThat().entriesListCountIs( initialEntriesSize - 1); From fad52fbfd9294118602e5f522d436366cde8efa6 Mon Sep 17 00:00:00 2001 From: Sara Aspery Date: Tue, 29 Nov 2022 07:12:58 +0000 Subject: [PATCH 09/17] add another debugging query --- .../functional/searchServices/search/SearchCasesTest.java | 6 ++++++ 1 file changed, 6 insertions(+) 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 99601f9be..0d5dce30e 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 @@ -105,6 +105,12 @@ public class SearchCasesTest extends AbstractSearchServicesE2ETest @Test(priority=5) public void testSearchUpdateContent() { + //TODO: remove - temp check for debugging + SearchResponse responsePB = queryAsUser(testUser, "cm:content:purpleisnotthereyet"); + restClient.assertStatusCodeIs(HttpStatus.OK); + String beforeAnything = "purple entries: " + responsePB.getEntries().size() + " purple entries: " + responsePB.getEntries().size(); + Assert.assertEquals(beforeAnything, "purpleisnotthereyet entries: 0"); + SearchResponse response4 = queryAsUser(testUser, "cm:content:brown"); restClient.assertStatusCodeIs(HttpStatus.OK); response4.assertThat().entriesListIsNotEmpty(); From 461e1348f43f2dfc8448d43d45e1ce7e7d7639a8 Mon Sep 17 00:00:00 2001 From: Sara Aspery Date: Tue, 29 Nov 2022 09:03:36 +0000 Subject: [PATCH 10/17] add another query for debugging --- .../searchServices/search/SearchCasesTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 0d5dce30e..503d2d8b0 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 @@ -106,20 +106,20 @@ public class SearchCasesTest extends AbstractSearchServicesE2ETest public void testSearchUpdateContent() { //TODO: remove - temp check for debugging - SearchResponse responsePB = queryAsUser(testUser, "cm:content:purpleisnotthereyet"); + SearchResponse responsePBQ = queryAsUser(testUser, "cm:content:purple"); restClient.assertStatusCodeIs(HttpStatus.OK); - String beforeAnything = "purple entries: " + responsePB.getEntries().size() + " purple entries: " + responsePB.getEntries().size(); - Assert.assertEquals(beforeAnything, "purpleisnotthereyet entries: 0"); + String beforeAnything = "purple entries: " + responsePBQ.getEntries().size(); + Assert.assertEquals(beforeAnything, "purple entries: 0"); SearchResponse response4 = queryAsUser(testUser, "cm:content:brown"); restClient.assertStatusCodeIs(HttpStatus.OK); response4.assertThat().entriesListIsNotEmpty(); //TODO: remove - temp check for debugging - SearchResponse responseRB = queryAsUser(testUser, "cm:content:purple"); + SearchResponse responsePAQ = queryAsUser(testUser, "cm:content:purple"); restClient.assertStatusCodeIs(HttpStatus.OK); - String beforeUpdate = "brown entries: " + response4.getEntries().size() + " purple entries: " + responseRB.getEntries().size(); - Assert.assertEquals(beforeUpdate, "brown entries: 1 purple entries: 0"); + String afterQuery = "purple entries after query: " + responsePAQ.getEntries().size(); + Assert.assertEquals(afterQuery, "purple entries after query: 0"); String newContent = "The quick purple fox jumps over the lazy dog"; dataContent.usingUser(adminUserModel).usingSite(testSite).usingResource(file) From fa1407e20f862f5038c1db36b623f10282e99fb4 Mon Sep 17 00:00:00 2001 From: Sara Aspery Date: Tue, 29 Nov 2022 11:23:38 +0000 Subject: [PATCH 11/17] check content for debugging --- .../search/SearchCasesTest.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) 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 503d2d8b0..7d97d45a4 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 @@ -22,6 +22,7 @@ */ package org.alfresco.test.search.functional.searchServices.search; +import org.alfresco.rest.exception.EmptyRestModelCollectionException; import org.alfresco.rest.search.FacetFieldBucket; import org.alfresco.rest.search.RestRequestFacetFieldModel; import org.alfresco.rest.search.RestRequestFacetFieldsModel; @@ -103,23 +104,29 @@ public class SearchCasesTest extends AbstractSearchServicesE2ETest } @Test(priority=5) - public void testSearchUpdateContent() + public void testSearchUpdateContent() throws EmptyRestModelCollectionException { //TODO: remove - temp check for debugging - SearchResponse responsePBQ = queryAsUser(testUser, "cm:content:purple"); + SearchResponse responsePBQ = queryAsUser(testUser, "cm:content:purplenotthereyet"); restClient.assertStatusCodeIs(HttpStatus.OK); - String beforeAnything = "purple entries: " + responsePBQ.getEntries().size(); - Assert.assertEquals(beforeAnything, "purple entries: 0"); + String beforeAnything = "purplenotthereyet entries: " + responsePBQ.getEntries().size(); + if (responsePBQ.getEntries().size() != 0) + { + String msg = "Name: " + responsePBQ.getEntryByIndex(0).getName(); + String content = " Content: " + responsePBQ.getEntryByIndex(0).getContent().toString(); + Assert.assertEquals( beforeAnything, msg + content); + } + Assert.assertEquals( beforeAnything, "purplenotthereyet entries: 0"); SearchResponse response4 = queryAsUser(testUser, "cm:content:brown"); restClient.assertStatusCodeIs(HttpStatus.OK); response4.assertThat().entriesListIsNotEmpty(); //TODO: remove - temp check for debugging - SearchResponse responsePAQ = queryAsUser(testUser, "cm:content:purple"); + SearchResponse responsePAQ = queryAsUser(testUser, "cm:content:purplenotthereyet"); restClient.assertStatusCodeIs(HttpStatus.OK); - String afterQuery = "purple entries after query: " + responsePAQ.getEntries().size(); - Assert.assertEquals(afterQuery, "purple entries after query: 0"); + String afterQuery = "purplenotthereyet entries after query: " + responsePAQ.getEntries().size(); + Assert.assertEquals(afterQuery, "purplenotthereyet entries after query: 0"); String newContent = "The quick purple fox jumps over the lazy dog"; dataContent.usingUser(adminUserModel).usingSite(testSite).usingResource(file) From def5cb6885a5d3f6ed26b95ac1fef58c6dcc3451 Mon Sep 17 00:00:00 2001 From: Sara Aspery Date: Wed, 30 Nov 2022 02:20:32 +0000 Subject: [PATCH 12/17] Create file exclusively for test method --- .../search/SearchCasesTest.java | 66 +++++++++---------- 1 file changed, 31 insertions(+), 35 deletions(-) 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 7d97d45a4..94a017547 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 @@ -22,7 +22,6 @@ */ package org.alfresco.test.search.functional.searchServices.search; -import org.alfresco.rest.exception.EmptyRestModelCollectionException; import org.alfresco.rest.search.FacetFieldBucket; import org.alfresco.rest.search.RestRequestFacetFieldModel; import org.alfresco.rest.search.RestRequestFacetFieldsModel; @@ -30,7 +29,7 @@ import org.alfresco.rest.search.RestRequestQueryModel; import org.alfresco.rest.search.RestResultBucketsModel; import org.alfresco.rest.search.SearchRequest; import org.alfresco.rest.search.SearchResponse; -import org.alfresco.utility.Utility; +import org.alfresco.util.GUID; import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FileType; import org.hamcrest.Matchers; @@ -104,49 +103,46 @@ public class SearchCasesTest extends AbstractSearchServicesE2ETest } @Test(priority=5) - public void testSearchUpdateContent() throws EmptyRestModelCollectionException + public void testSearchUpdateContent() { - //TODO: remove - temp check for debugging - SearchResponse responsePBQ = queryAsUser(testUser, "cm:content:purplenotthereyet"); - restClient.assertStatusCodeIs(HttpStatus.OK); - String beforeAnything = "purplenotthereyet entries: " + responsePBQ.getEntries().size(); - if (responsePBQ.getEntries().size() != 0) - { - String msg = "Name: " + responsePBQ.getEntryByIndex(0).getName(); - String content = " Content: " + responsePBQ.getEntryByIndex(0).getContent().toString(); - Assert.assertEquals( beforeAnything, msg + content); - } - Assert.assertEquals( beforeAnything, "purplenotthereyet entries: 0"); + FileModel updateableFile; + String originalText = GUID.generate(); + String newText = GUID.generate(); - SearchResponse response4 = queryAsUser(testUser, "cm:content:brown"); - restClient.assertStatusCodeIs(HttpStatus.OK); - response4.assertThat().entriesListIsNotEmpty(); + // Create test file to be accessed only by this test method to avoid inconsistency when querying updates + String filename = "File-" + originalText + ".txt"; + String title = "Title: File for testing by testSearchUpdateContent only"; + String description = "Description: Contains updatable unique string to test query after content update: "; + updateableFile = new FileModel(filename, title, description, FileType.TEXT_PLAIN, + description + originalText + " is a unique string"); + dataContent.usingUser(testUser).usingSite(testSite).usingResource(folder).createContent(updateableFile); + Assert.assertTrue(waitForContentIndexing(originalText, true)); - //TODO: remove - temp check for debugging - SearchResponse responsePAQ = queryAsUser(testUser, "cm:content:purplenotthereyet"); + // Verify that 1 occurrence of the original text is found + SearchResponse response1 = queryAsUser(testUser, "cm:content:" + originalText); restClient.assertStatusCodeIs(HttpStatus.OK); - String afterQuery = "purplenotthereyet entries after query: " + responsePAQ.getEntries().size(); - Assert.assertEquals(afterQuery, "purplenotthereyet entries after query: 0"); + Assert.assertEquals(response1.getEntries().size(), 1, "Expected 1 original text before update"); - String newContent = "The quick purple fox jumps over the lazy dog"; - dataContent.usingUser(adminUserModel).usingSite(testSite).usingResource(file) + // Verify that 0 occurrences of the replacement text are found + SearchResponse response2 = queryAsUser(testUser, "cm:content:" + newText); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response2.getEntries().size(), 0, "Expected 0 new text before update"); + + // Update the content + String newContent = description + newText + " is a unique string"; + dataContent.usingUser(adminUserModel).usingSite(testSite).usingResource(updateableFile) .updateContent(newContent); - Assert.assertTrue(waitForContentIndexing("purple", true)); + Assert.assertTrue(waitForContentIndexing(newText, true)); - //TODO: remove - artificially long wait for debugging - Utility.waitToLoopTime(60); - - SearchResponse response5 = queryAsUser(testUser, "cm:content:brown"); + // Verify that 0 occurrences of the original text are found + SearchResponse response3 = queryAsUser(testUser, "cm:content:" + originalText); restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(response3.getEntries().size(), 0, "Expected 0 original text after update"); - //TODO: remove - temp check for debugging - SearchResponse responseRA = queryAsUser(testUser, "cm:content:purple"); + // Verify that 1 occurrence of the replacement text is found + SearchResponse response4 = queryAsUser(testUser, "cm:content:" + newText); restClient.assertStatusCodeIs(HttpStatus.OK); - String afterUpdate = "brown entries: " + response5.getEntries().size() + " purple entries: " + responseRA.getEntries().size(); - Assert.assertEquals(afterUpdate, "brown entries: 0 purple entries: 1"); - - int initialEntriesSize = response4.getEntries().size(); - response5.assertThat().entriesListCountIs( initialEntriesSize - 1); + Assert.assertEquals(response4.getEntries().size(), 1, "Expected 1 new text before update"); } @Test(priority=6) From 9162f05b5e224ede203dd8be82ec9d2744f759f9 Mon Sep 17 00:00:00 2001 From: Sara Aspery Date: Wed, 30 Nov 2022 03:10:44 +0000 Subject: [PATCH 13/17] Use system time for content string --- .../functional/searchServices/search/SearchCasesTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 94a017547..bf04fcdb2 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 @@ -29,7 +29,6 @@ import org.alfresco.rest.search.RestRequestQueryModel; import org.alfresco.rest.search.RestResultBucketsModel; import org.alfresco.rest.search.SearchRequest; import org.alfresco.rest.search.SearchResponse; -import org.alfresco.util.GUID; import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FileType; import org.hamcrest.Matchers; @@ -106,8 +105,8 @@ public class SearchCasesTest extends AbstractSearchServicesE2ETest public void testSearchUpdateContent() { FileModel updateableFile; - String originalText = GUID.generate(); - String newText = GUID.generate(); + String originalText = String.valueOf(System.currentTimeMillis()); + String newText = String.valueOf(System.currentTimeMillis() + 300000); // Create test file to be accessed only by this test method to avoid inconsistency when querying updates String filename = "File-" + originalText + ".txt"; From 7b0ed0a492caf7b919d570cf7dcc93921e4b81f0 Mon Sep 17 00:00:00 2001 From: Sara Aspery Date: Thu, 1 Dec 2022 15:43:31 +0000 Subject: [PATCH 14/17] Create unique file for search with facet fields test --- .../search/AbstractSearchServicesE2ETest.java | 26 ++++++++++++++----- .../search/SearchCasesTest.java | 22 +++++++--------- 2 files changed, 29 insertions(+), 19 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 cdbac2f77..ead9c7565 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 @@ -4,21 +4,21 @@ * %% * Copyright (C) 2005 - 2022 Alfresco Software Limited * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is * provided under the following open source license terms: - * + * * 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 . * #L% @@ -30,6 +30,7 @@ import org.alfresco.test.search.functional.AbstractE2EFunctionalTest; import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FileType; import org.alfresco.utility.model.FolderModel; +import org.testng.Assert; import static java.util.List.of; @@ -83,8 +84,19 @@ public abstract class AbstractSearchServicesE2ETest extends AbstractE2EFunctiona of(file, file2, file3, file4).forEach( f -> dataContent.usingUser(testUser).usingSite(testSite).usingResource(folder).createContent(f) - ); + ); waitForMetadataIndexing(file4.getName(), true); } + + protected FileModel createFileWithProvidedText(String filename, String providedText) + { + String title = "Title: File containing " + providedText; + String description = "Description: Contains provided string: " + providedText; + FileModel uniqueFile = new FileModel(filename, title, description, FileType.TEXT_PLAIN, + "The content " + providedText + " is a provided string"); + dataContent.usingUser(testUser).usingSite(testSite).usingResource(folder).createContent(uniqueFile); + Assert.assertTrue(waitForContentIndexing(providedText, true)); + return uniqueFile; + } } 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 bf04fcdb2..644b1baab 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 @@ -104,18 +104,11 @@ public class SearchCasesTest extends AbstractSearchServicesE2ETest @Test(priority=5) public void testSearchUpdateContent() { - FileModel updateableFile; String originalText = String.valueOf(System.currentTimeMillis()); String newText = String.valueOf(System.currentTimeMillis() + 300000); - // Create test file to be accessed only by this test method to avoid inconsistency when querying updates - String filename = "File-" + originalText + ".txt"; - String title = "Title: File for testing by testSearchUpdateContent only"; - String description = "Description: Contains updatable unique string to test query after content update: "; - updateableFile = new FileModel(filename, title, description, FileType.TEXT_PLAIN, - description + originalText + " is a unique string"); - dataContent.usingUser(testUser).usingSite(testSite).usingResource(folder).createContent(updateableFile); - Assert.assertTrue(waitForContentIndexing(originalText, true)); + // Create test file to be accessed only by this test method to avoid inconsistent results when querying updates + FileModel updateableFile = createFileWithProvidedText(originalText + ".txt", originalText); // Verify that 1 occurrence of the original text is found SearchResponse response1 = queryAsUser(testUser, "cm:content:" + originalText); @@ -128,7 +121,7 @@ public class SearchCasesTest extends AbstractSearchServicesE2ETest Assert.assertEquals(response2.getEntries().size(), 0, "Expected 0 new text before update"); // Update the content - String newContent = description + newText + " is a unique string"; + String newContent = "Description: Contains provided string: " + newText; dataContent.usingUser(adminUserModel).usingSite(testSite).usingResource(updateableFile) .updateContent(newContent); Assert.assertTrue(waitForContentIndexing(newText, true)); @@ -209,9 +202,14 @@ public class SearchCasesTest extends AbstractSearchServicesE2ETest @Test(priority=10) public void searchWithFacedFields() { + String uniqueText = String.valueOf(System.currentTimeMillis()); + + // Create test file to be accessed only by this test method to avoid inconsistent results + createFileWithProvidedText(uniqueText + ".ODT", uniqueText); + SearchRequest query = new SearchRequest(); RestRequestQueryModel queryReq = new RestRequestQueryModel(); - queryReq.setQuery("cm:content:unique"); + queryReq.setQuery("cm:content:" + uniqueText); query.setQuery(queryReq); RestRequestFacetFieldsModel facetFields = new RestRequestFacetFieldsModel(); @@ -236,7 +234,7 @@ public class SearchCasesTest extends AbstractSearchServicesE2ETest bucket1.assertThat().field("label").is(testUser.getUsername()); bucket1.assertThat().field("display").is("FN-" + testUser.getUsername() + " LN-" + testUser.getUsername()); bucket1.assertThat().field("filterQuery").is("modifier:\"" + testUser.getUsername() + "\""); - bucket1.assertThat().field("count").isGreaterThan(0); + bucket1.assertThat().field("count").is(1); } @Test(priority=12) From bece9206284c8f76461d01878352ac93143963f8 Mon Sep 17 00:00:00 2001 From: Sara Aspery Date: Thu, 1 Dec 2022 23:19:44 +0000 Subject: [PATCH 15/17] Add sleep then retry for content indexing completed check in tests --- .../functional/searchServices/search/SearchCasesTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 644b1baab..429c45206 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 @@ -102,7 +102,7 @@ public class SearchCasesTest extends AbstractSearchServicesE2ETest } @Test(priority=5) - public void testSearchUpdateContent() + public void testSearchUpdateContent() throws InterruptedException { String originalText = String.valueOf(System.currentTimeMillis()); String newText = String.valueOf(System.currentTimeMillis() + 300000); @@ -200,7 +200,7 @@ public class SearchCasesTest extends AbstractSearchServicesE2ETest * } */ @Test(priority=10) - public void searchWithFacedFields() + public void searchWithFacedFields() throws InterruptedException { String uniqueText = String.valueOf(System.currentTimeMillis()); From fa1a59a2150e74193dad7f892820921ba15d2807 Mon Sep 17 00:00:00 2001 From: Sara Aspery Date: Thu, 1 Dec 2022 23:20:07 +0000 Subject: [PATCH 16/17] Add sleep then retry for content indexing completed check in tests --- .../search/AbstractSearchServicesE2ETest.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 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 ead9c7565..e8d295ceb 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 @@ -27,10 +27,12 @@ package org.alfresco.test.search.functional.searchServices.search; 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.testng.Assert; +import org.testng.annotations.BeforeClass; import static java.util.List.of; @@ -48,10 +50,15 @@ public abstract class AbstractSearchServicesE2ETest extends AbstractE2EFunctiona { private static final String SEARCH_DATA_SAMPLE_FOLDER = "FolderSearch"; + /** The maximum time to wait for content indexing to complete (in ms). */ + private static final int MAX_TIME = 120 * 1000; + /** The frequency to check the report (in ms). */ + private static final int RETRY_INTERVAL = 30000; + protected FileModel file, file2, file3, file4; protected FolderModel folder; - public void searchServicesDataPreparation() + public void searchServicesDataPreparation() throws InterruptedException { /* * Create the following file structure for preconditions : @@ -86,17 +93,23 @@ public abstract class AbstractSearchServicesE2ETest extends AbstractE2EFunctiona f -> dataContent.usingUser(testUser).usingSite(testSite).usingResource(folder).createContent(f) ); - waitForMetadataIndexing(file4.getName(), true); + Utility.sleep(RETRY_INTERVAL, MAX_TIME, () -> { + waitForMetadataIndexing(file4.getName(), true); + }); } - protected FileModel createFileWithProvidedText(String filename, String providedText) + protected FileModel createFileWithProvidedText(String filename, String providedText) throws InterruptedException { String title = "Title: File containing " + providedText; String description = "Description: Contains provided string: " + providedText; FileModel uniqueFile = new FileModel(filename, title, description, FileType.TEXT_PLAIN, "The content " + providedText + " is a provided string"); dataContent.usingUser(testUser).usingSite(testSite).usingResource(folder).createContent(uniqueFile); - Assert.assertTrue(waitForContentIndexing(providedText, true)); + + Utility.sleep(RETRY_INTERVAL, MAX_TIME, () -> { + Assert.assertTrue(waitForContentIndexing(providedText, true)); + }); + return uniqueFile; } } From 260914c979d81f03149cdf5f8ea1315f50f65abe Mon Sep 17 00:00:00 2001 From: Sara Aspery Date: Fri, 2 Dec 2022 07:56:26 +0000 Subject: [PATCH 17/17] Remove extra sleep and double retry attempts --- .../search/functional/AbstractE2EFunctionalTest.java | 2 +- .../search/AbstractSearchServicesE2ETest.java | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/e2e-test/src/test/java/org/alfresco/test/search/functional/AbstractE2EFunctionalTest.java b/e2e-test/src/test/java/org/alfresco/test/search/functional/AbstractE2EFunctionalTest.java index 81dd4430b..7a26b8b7d 100644 --- a/e2e-test/src/test/java/org/alfresco/test/search/functional/AbstractE2EFunctionalTest.java +++ b/e2e-test/src/test/java/org/alfresco/test/search/functional/AbstractE2EFunctionalTest.java @@ -83,7 +83,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringContextTests { /** The number of retries that a query will be tried before giving up. */ - protected static final int SEARCH_MAX_ATTEMPTS = 60; + protected static final int SEARCH_MAX_ATTEMPTS = 120; private static final Logger LOGGER = LogFactory.getLogger(); 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 e8d295ceb..9bc8ca2ce 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 @@ -27,12 +27,10 @@ package org.alfresco.test.search.functional.searchServices.search; 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.testng.Assert; -import org.testng.annotations.BeforeClass; import static java.util.List.of; @@ -92,10 +90,7 @@ public abstract class AbstractSearchServicesE2ETest extends AbstractE2EFunctiona of(file, file2, file3, file4).forEach( f -> dataContent.usingUser(testUser).usingSite(testSite).usingResource(folder).createContent(f) ); - - Utility.sleep(RETRY_INTERVAL, MAX_TIME, () -> { - waitForMetadataIndexing(file4.getName(), true); - }); + waitForMetadataIndexing(file4.getName(), true); } protected FileModel createFileWithProvidedText(String filename, String providedText) throws InterruptedException @@ -105,10 +100,7 @@ public abstract class AbstractSearchServicesE2ETest extends AbstractE2EFunctiona FileModel uniqueFile = new FileModel(filename, title, description, FileType.TEXT_PLAIN, "The content " + providedText + " is a provided string"); dataContent.usingUser(testUser).usingSite(testSite).usingResource(folder).createContent(uniqueFile); - - Utility.sleep(RETRY_INTERVAL, MAX_TIME, () -> { - Assert.assertTrue(waitForContentIndexing(providedText, true)); - }); + Assert.assertTrue(waitForContentIndexing(providedText, true)); return uniqueFile; }