Create unique file for search with facet fields test

This commit is contained in:
Sara Aspery
2022-12-01 15:43:31 +00:00
parent 9162f05b5e
commit 7b0ed0a492
2 changed files with 29 additions and 19 deletions

View File

@@ -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 <http://www.gnu.org/licenses/>.
* #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;
}
}

View File

@@ -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)