From 22eb2b6f1b89a88e80ea2c0ac37afec673167a27 Mon Sep 17 00:00:00 2001 From: Alessandro Benedetti Date: Wed, 12 Dec 2018 15:02:46 +0000 Subject: [PATCH] [MNT-19456] Integration test added to cover cascade reindexing --- .../search/AbstractSearchServiceE2E.java | 15 +++ .../CascadingTrackerIntegrationTest.java | 124 ++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 e2e-test/src/test/java/org/alfresco/service/search/e2e/searchservices/tracker/CascadingTrackerIntegrationTest.java diff --git a/e2e-test/src/test/java/org/alfresco/service/search/AbstractSearchServiceE2E.java b/e2e-test/src/test/java/org/alfresco/service/search/AbstractSearchServiceE2E.java index 10acedca1..9e1193614 100644 --- a/e2e-test/src/test/java/org/alfresco/service/search/AbstractSearchServiceE2E.java +++ b/e2e-test/src/test/java/org/alfresco/service/search/AbstractSearchServiceE2E.java @@ -255,4 +255,19 @@ public abstract class AbstractSearchServiceE2E extends AbstractTestNGSpringConte return resultAsExpected; } + + /** + * Run a search and return the response + * @param queryString: string to search for, unique search string will guarantee accurate results + * @return the search response from the API + * @throws Exception + */ + public SearchResponse query(String queryString) throws Exception + { + SearchRequest searchRequest = new SearchRequest(); + RestRequestQueryModel queryModel = new RestRequestQueryModel(); + queryModel.setQuery(queryString); + searchRequest.setQuery(queryModel); + return restClient.authenticateUser(dataUser.getAdminUser()).withSearchAPI().search(searchRequest); + } } diff --git a/e2e-test/src/test/java/org/alfresco/service/search/e2e/searchservices/tracker/CascadingTrackerIntegrationTest.java b/e2e-test/src/test/java/org/alfresco/service/search/e2e/searchservices/tracker/CascadingTrackerIntegrationTest.java new file mode 100644 index 000000000..23c8cc2c8 --- /dev/null +++ b/e2e-test/src/test/java/org/alfresco/service/search/e2e/searchservices/tracker/CascadingTrackerIntegrationTest.java @@ -0,0 +1,124 @@ +/* + * Copyright 2018 Alfresco Software, Ltd. All rights reserved. + * 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. + */ +package org.alfresco.service.search.e2e.searchservices.tracker; + +import org.alfresco.service.search.AbstractSearchServiceE2E; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataContent; +import org.alfresco.utility.data.DataSite; +import org.alfresco.utility.model.ContentModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.apache.chemistry.opencmis.commons.PropertyIds; +import org.apache.chemistry.opencmis.commons.enums.VersioningState; +import org.junit.Assert; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.hamcrest.core.Is.is; + +public class CascadingTrackerIntegrationTest extends AbstractSearchServiceE2E +{ + @Autowired + protected DataSite dataSite; + + @Autowired + protected DataContent dataContent; + + private SiteModel testSite; + + private UserModel testUser; + + private FolderModel testFolder; + + @BeforeClass(alwaysRun = true) + public void setupEnvironment() throws Exception + { + serverHealth.assertServerIsOnline(); + + testSite = dataSite.createPublicRandomSite(); + testUser = dataUser.createRandomTestUser(); + dataUser.addUserToSite(testUser, testSite, UserRole.SiteContributor); + } + + @Test(groups = { TestGroup.ASS_13 }) + public void testCascadingTracking_parentFolderRenaming_shouldReIndexChildren() throws Exception + { + testFolder = dataContent.usingSite(testSite).usingUser(testUser).createFolder(); + + FileModel customFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "custom content"); + Map properties = new HashMap<>(); + properties.put(PropertyIds.NAME, customFile.getName()); + + cmisApi.authenticateUser(testUser).usingSite(testSite).usingResource(testFolder) + .createFile(customFile, properties, VersioningState.MAJOR).assertThat().existsInRepo(); + + waitForIndexing(customFile.getName(), true); + + String parentQuery = "NPATH:\"4/Company Home/Sites/" + testSite.getTitle() + "/documentLibrary/" + testFolder.getName() + "\""; + int initialDescendantCount = query(parentQuery).getPagination().getCount(); + + String parentNewName = "parentRenamed"; + ContentModel parentNewNameModel = new ContentModel(parentNewName); + + this.dataContent.usingUser(testUser).usingResource(testFolder).renameContent(parentNewNameModel); + + testFolder.setName(parentNewName); + waitForIndexing(testFolder.getName(), true); + + String parentQueryAfterRename = "NPATH:\"4/Company Home/Sites/" + testSite.getTitle() + "/documentLibrary/" + parentNewName + "\""; + int descendantCountOfDismissedName = query(parentQuery).getPagination().getCount(); + int descendantCountOfNewName = query(parentQueryAfterRename).getPagination().getCount(); + + Assert.assertThat("New renamed path has not the same descendants as before renaming: " + parentQueryAfterRename,descendantCountOfNewName,is(initialDescendantCount)); + Assert.assertThat("Old path still has descendants: " + parentQuery,descendantCountOfDismissedName,is(0)); + } + + @Test(groups = { TestGroup.ASS_13 }) + public void testCascadingTracking_granParentFolderRenaming_shouldReIndexChildren() throws Exception + { + testFolder = dataContent.usingSite(testSite).usingUser(testUser).createFolder(); + + // Create child folder + FolderModel childFolder = dataContent.usingUser(testUser).usingResource(testFolder).createFolder(); + + // Create grandchild file + FileModel customFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "custom content"); + Map properties = new HashMap<>(); + properties.put(PropertyIds.NAME, customFile.getName()); + + cmisApi.authenticateUser(testUser).usingSite(testSite).usingResource(childFolder) + .createFile(customFile, properties, VersioningState.MAJOR).assertThat().existsInRepo(); + waitForIndexing(customFile.getName(), true); + + String parentQuery = "NPATH:\"4/Company Home/Sites/" + testSite.getTitle() + "/documentLibrary/" + testFolder.getName() + "\""; + int initialDescendantCount = query(parentQuery).getPagination().getCount(); + + // Edit grand parent folder name + String granParentNewName = "granParentRenamed"; + ContentModel granParentNewNameModel = new ContentModel(granParentNewName); + this.dataContent.usingUser(testUser).usingResource(testFolder).renameContent(granParentNewNameModel); + + waitForIndexing(granParentNewName, true); + + String parentQueryAfterRename = "NPATH:\"4/Company Home/Sites/" + testSite.getTitle() + "/documentLibrary/" + granParentNewName + "\""; + int descendantCountOfDismissedName = query(parentQuery).getPagination().getCount(); + int descendantCountOfNewName = query(parentQueryAfterRename).getPagination().getCount(); + + Assert.assertThat("New renamed path has not the same descendants as before renaming: " + parentQueryAfterRename,descendantCountOfNewName,is(initialDescendantCount)); + Assert.assertThat("Old path still has descendants: " + parentQuery,descendantCountOfDismissedName,is(0)); + } +} +