From 520b9e7fcb0dc1e9c4a05091a73fbf0ebf72e1ba Mon Sep 17 00:00:00 2001 From: Tom Page Date: Tue, 27 Sep 2022 10:38:25 +0100 Subject: [PATCH 1/3] ACS-3488 Remove usage of XML data provider. This broke when we updated TestNG. --- .../org/alfresco/cmis/dsl/QueryExecutor.java | 22 ++- .../cmis/search/AbstractCmisE2ETest.java | 86 ++++++-- .../cmis/search/SearchInFolderTests.java | 185 +++++++++++++++++- 3 files changed, 259 insertions(+), 34 deletions(-) diff --git a/packaging/tests/tas-cmis/src/main/java/org/alfresco/cmis/dsl/QueryExecutor.java b/packaging/tests/tas-cmis/src/main/java/org/alfresco/cmis/dsl/QueryExecutor.java index b253d1bd15..381f2d05d2 100644 --- a/packaging/tests/tas-cmis/src/main/java/org/alfresco/cmis/dsl/QueryExecutor.java +++ b/packaging/tests/tas-cmis/src/main/java/org/alfresco/cmis/dsl/QueryExecutor.java @@ -12,6 +12,7 @@ import java.util.Collections; import java.util.List; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.StreamSupport; import com.google.common.collect.Streams; @@ -40,7 +41,7 @@ public class QueryExecutor CmisWrapper cmisWrapper; private long returnedResults = -1; private String currentQuery = ""; - private ItemIterable results; + private List results; public QueryExecutor(CmisWrapper cmisWrapper, String query) { @@ -56,19 +57,20 @@ public class QueryExecutor public QueryResultAssertion assertColumnIsOrdered() { - results = executeQuery(currentQuery); - return new QueryResultAssertion(); + return assertValues(); } public QueryResultAssertion assertColumnValuesRange() { - results = executeQuery(currentQuery); - return new QueryResultAssertion(); + return assertValues(); } public QueryResultAssertion assertValues() { - results = executeQuery(currentQuery); + STEP("Sending query " + currentQuery); + results = StreamSupport.stream(executeQuery(currentQuery).spliterator(), false) + .collect(toList()); + STEP("Received results " + results); return new QueryResultAssertion(); } @@ -160,7 +162,7 @@ public class QueryExecutor public class QueryResultAssertion { - public QueryResultAssertion equals(long expectedValue) + public QueryResultAssertion hasLength(long expectedValue) { STEP(String.format("Verify that query: '%s' has %d results count returned", currentQuery, expectedValue)); Assert.assertEquals(returnedResults, expectedValue, showErrorMessage()); @@ -232,8 +234,8 @@ public class QueryExecutor public QueryResultAssertion isReturningValues(String queryName, Set values) { STEP(String.format("Verify that query: '%s' returns the values from %s for column %s", currentQuery, values, queryName)); - Set resultSet = Streams.stream(results).map(r -> (T) r.getPropertyValueByQueryName(queryName)).collect(toSet()); - Assert.assertEquals(resultSet, values, "Values did not match"); + Set resultSet = results.stream().map(r -> (T) r.getPropertyValueByQueryName(queryName)).collect(toSet()); + Assert.assertEquals(resultSet, values, "Values did not match - expected " + values + " got " + resultSet); return this; } @@ -241,7 +243,7 @@ public class QueryExecutor public QueryResultAssertion isReturningOrderedValues(String queryName, List values) { STEP(String.format("Verify that query: '%s' returns the values from %s for column %s", currentQuery, values, queryName)); - List resultList = Streams.stream(results).map(r -> (T) r.getPropertyValueByQueryName(queryName)).collect(toList()); + List resultList = results.stream().map(r -> (T) r.getPropertyValueByQueryName(queryName)).collect(toList()); // Include both lists in assertion message as TestNG does not provide this information. Assert.assertEquals(resultList, values, "Values did not match expected " + values + " but found " + resultList); diff --git a/packaging/tests/tas-cmis/src/test/java/org/alfresco/cmis/search/AbstractCmisE2ETest.java b/packaging/tests/tas-cmis/src/test/java/org/alfresco/cmis/search/AbstractCmisE2ETest.java index df41d989ae..9083f303da 100644 --- a/packaging/tests/tas-cmis/src/test/java/org/alfresco/cmis/search/AbstractCmisE2ETest.java +++ b/packaging/tests/tas-cmis/src/test/java/org/alfresco/cmis/search/AbstractCmisE2ETest.java @@ -1,9 +1,21 @@ package org.alfresco.cmis.search; +import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toSet; + +import static org.alfresco.utility.report.log.Step.STEP; + import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.function.Consumer; +import java.util.stream.Collectors; import org.alfresco.cmis.CmisProperties; +import org.alfresco.cmis.dsl.QueryExecutor.QueryResultAssertion; import org.alfresco.utility.Utility; +import org.alfresco.utility.model.ContentModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -45,32 +57,76 @@ public abstract class AbstractCmisE2ETest extends AbstractE2EFunctionalTest /** * Repeat Elastic Query till results count returns expectedCountResults * @param query CMIS Query to be executed - * @param expectedCountResults Number of results expected + * @param expectedResultsCount Number of results expected * @return true when results count is equals to expectedCountResults */ - protected boolean waitForIndexing(String query, long expectedCountResults) + protected boolean waitForIndexing(String query, long expectedResultsCount) { - - for (int searchCount = 1; searchCount <= SEARCH_MAX_ATTEMPTS; searchCount++) + try { + waitForIndexing(query, execution -> execution.hasLength(expectedResultsCount)); + return true; + } + catch (AssertionError ae) + { + STEP("Received assertion error for query '" + query + "': " + ae); + return false; + } + } + /** + * Repeat Elastic Query until we get the expected results or we hit the retry limit. + * + * @param query CMIS Query to be executed + * @param expectedResults The expected results (unordered). + */ + protected void waitForIndexing(String query, ContentModel... expectedResults) + { + Set expectedNames = Arrays.stream(expectedResults).map(ContentModel::getName).collect(toSet()); + waitForIndexing(query, execution -> execution.isReturningValues("cmis:name", expectedNames)); + } + + /** + * Repeat Elastic Query until we get the expected results in the given order or we hit the retry limit. + * + * @param query CMIS Query to be executed + * @param expectedResults The expected results (ordered). + */ + protected void waitForIndexingOrdered(String query, ContentModel... expectedResults) + { + List expectedNames = Arrays.stream(expectedResults).map(ContentModel::getName).collect(toList()); + waitForIndexing(query, execution -> execution.isReturningOrderedValues("cmis:name", expectedNames)); + } + + /** + * Repeat Elastic Query until we get the expected results or we hit the retry limit. + * + * @param query CMIS Query to be executed + * @param assertionMethod A method that will be called to check the response and which will throw an AssertionError if they aren't what we want. + */ + protected void waitForIndexing(String query, Consumer assertionMethod) + { + int searchCount = 0; + while (true) + { try { - cmisApi.withQuery(query).assertResultsCount().equals(expectedCountResults); - return true; + assertionMethod.accept(cmisApi.withQuery(query).assertValues()); + return; } catch (AssertionError ae) { - LOGGER.info(String.format("WaitForIndexing in Progress: %s", ae)); + searchCount++; + if (searchCount < SEARCH_MAX_ATTEMPTS) + { + LOGGER.info(String.format("WaitForIndexing in Progress: %s", ae)); + Utility.waitToLoopTime(getElasticWaitTimeInSeconds(), "Wait For Indexing"); + } + else + { + throw ae; + } } - - - Utility.waitToLoopTime(getElasticWaitTimeInSeconds(), "Wait For Indexing"); - } - - return false; } - - } diff --git a/packaging/tests/tas-cmis/src/test/java/org/alfresco/cmis/search/SearchInFolderTests.java b/packaging/tests/tas-cmis/src/test/java/org/alfresco/cmis/search/SearchInFolderTests.java index edd25d9a8f..0c1e17fceb 100644 --- a/packaging/tests/tas-cmis/src/test/java/org/alfresco/cmis/search/SearchInFolderTests.java +++ b/packaging/tests/tas-cmis/src/test/java/org/alfresco/cmis/search/SearchInFolderTests.java @@ -1,12 +1,15 @@ package org.alfresco.cmis.search; +import static java.util.stream.Collectors.toList; + +import java.util.Arrays; +import java.util.List; + import org.alfresco.utility.Utility; -import org.alfresco.utility.data.provider.XMLDataConfig; -import org.alfresco.utility.data.provider.XMLTestDataProvider; +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.QueryModel; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; @@ -17,6 +20,21 @@ public class SearchInFolderTests extends AbstractCmisE2ETest private FolderModel parentFolder, subFolder1, subFolder2, subFolder3; private FileModel subFile1, subFile2, subFile3, subFile4, subFile5; + /** + * Create test data in the following format: + *
+     * testSite
+     * +- parentFolder
+     *    +- subFile5 (fifthFile.txt: "fifthFile content")
+     *    +- subFolder1
+     *    +- subFolder2
+     *    +- subFolder3 (subFolder)
+     *    +- subFile1 (firstFile.xls)
+     *    +- subFile2 (.pptx)
+     *    +- subFile3 (.txt)
+     *    +- subFile4 (fourthFile.docx: "fourthFileTitle", "fourthFileDescription")
+     * 
+ */ @BeforeClass(alwaysRun = true) public void createTestData() throws Exception { @@ -42,7 +60,7 @@ public class SearchInFolderTests extends AbstractCmisE2ETest .createFile(subFile3) .createFile(subFile4); // wait for index - Utility.waitToLoopTime(getElasticWaitTimeInSeconds()); + Utility.waitToLoopTime(5);//getElasticWaitTimeInSeconds()); } @AfterClass(alwaysRun = true) @@ -51,12 +69,161 @@ public class SearchInFolderTests extends AbstractCmisE2ETest dataContent.deleteSite(testSite); } - @Test(dataProviderClass = XMLTestDataProvider.class, dataProvider = "getQueriesData") - @XMLDataConfig(file = "src/test/resources/search-in-folder.xml") - public void executeCMISQuery(QueryModel query) + @Test + public void executeCMISQuery0() { - String currentQuery = String.format(query.getValue(), parentFolder.getNodeRef()); + String query = "SELECT cmis:name, cmis:parentId, cmis:path, cmis:allowedChildObjectTypeIds" + + " FROM cmis:folder where IN_FOLDER('%s') AND cmis:name = 'subFolder'"; + String currentQuery = String.format(query, parentFolder.getNodeRef()); cmisApi.authenticateUser(testUser); - Assert.assertTrue(waitForIndexing(currentQuery, query.getResults()), String.format("Result count not as expected for query: %s", currentQuery)); + waitForIndexing(currentQuery, subFolder3); + } + + @Test + public void executeCMISQuery1() + { + String query = "SELECT cmis:name, cmis:objectId, cmis:lastModifiedBy, cmis:creationDate, cmis:contentStreamFileName" + + " FROM cmis:document where IN_FOLDER('%s') AND cmis:name = 'fourthFile'"; + String currentQuery = String.format(query, parentFolder.getNodeRef()); + cmisApi.authenticateUser(testUser); + waitForIndexing(currentQuery, subFile4); + } + + @Test + public void executeCMISQuery2() + { + String query = "SELECT cmis:parentId FROM cmis:folder where IN_FOLDER('%s')"; + String currentQuery = String.format(query, parentFolder.getNodeRef()); + cmisApi.authenticateUser(testUser); + // Expect to get the same parent for each of the three matches. + String parentId = parentFolder.getNodeRef(); + List expectedParentIds = List.of(parentId, parentId, parentId); + waitForIndexing(query, execution -> execution.isReturningOrderedValues("cmis:parentId", expectedParentIds)); + } + + @Test + public void executeCMISQuery3() + { + String query = "SELECT * FROM cmis:document where IN_FOLDER('%s')"; + String currentQuery = String.format(query, parentFolder.getNodeRef()); + cmisApi.authenticateUser(testUser); + waitForIndexing(currentQuery, subFile1, subFile2, subFile3, subFile4, subFile5); + } + + @Test + public void executeCMISQuery4() + { + String query = "SELECT * FROM cmis:document where IN_FOLDER('%s') AND cmis:name NOT LIKE 'file%%' ORDER BY cmis:name ASC"; + String currentQuery = String.format(query, parentFolder.getNodeRef()); + cmisApi.authenticateUser(testUser); + waitForIndexingOrdered(currentQuery, subFile5, subFile1, subFile4); + } + + @Test + public void executeCMISQuery5() + { + String query = "SELECT * FROM cmis:document where IN_FOLDER('%s') ORDER BY cmis:name DESC"; + String currentQuery = String.format(query, parentFolder.getNodeRef()); + cmisApi.authenticateUser(testUser); + Assert.assertTrue(waitForIndexing(currentQuery, 5), String.format("Result count not as expected for query: %s", currentQuery)); + } + + @Test + public void executeCMISQuery6() + { + String query = "SELECT * FROM cmis:folder where IN_FOLDER('%s') ORDER BY cmis:lastModificationDate ASC"; + String currentQuery = String.format(query, parentFolder.getNodeRef()); + cmisApi.authenticateUser(testUser); + Assert.assertTrue(waitForIndexing(currentQuery, 3), String.format("Result count not as expected for query: %s", currentQuery)); + } + + @Test + public void executeCMISQuery7() + { + String query = "SELECT * FROM cmis:folder where IN_FOLDER('%s') ORDER BY cmis:lastModificationDate DESC"; + String currentQuery = String.format(query, parentFolder.getNodeRef()); + cmisApi.authenticateUser(testUser); + Assert.assertTrue(waitForIndexing(currentQuery, 3), String.format("Result count not as expected for query: %s", currentQuery)); + } + + @Test + public void executeCMISQuery8() + { + String query = "SELECT * FROM cmis:document where IN_FOLDER('%s') ORDER BY cmis:createdBy DESC"; + String currentQuery = String.format(query, parentFolder.getNodeRef()); + cmisApi.authenticateUser(testUser); + Assert.assertTrue(waitForIndexing(currentQuery, 5), String.format("Result count not as expected for query: %s", currentQuery)); + } + + @Test + public void executeCMISQuery9() + { + String query = "SELECT * FROM cmis:document where IN_FOLDER('%s') AND cmis:name IS NOT NULL"; + String currentQuery = String.format(query, parentFolder.getNodeRef()); + cmisApi.authenticateUser(testUser); + Assert.assertTrue(waitForIndexing(currentQuery, 5), String.format("Result count not as expected for query: %s", currentQuery)); + } + + @Test + public void executeCMISQuery10() + { + String query = "SELECT * FROM cmis:folder where IN_FOLDER('%s') AND cmis:name IS NOT NULL"; + String currentQuery = String.format(query, parentFolder.getNodeRef()); + cmisApi.authenticateUser(testUser); + Assert.assertTrue(waitForIndexing(currentQuery, 3), String.format("Result count not as expected for query: %s", currentQuery)); + } + + @Test + public void executeCMISQuery11() + { + String query = "SELECT * FROM cmis:document where IN_FOLDER('%s') AND cmis:name LIKE 'fourthFile'"; + String currentQuery = String.format(query, parentFolder.getNodeRef()); + cmisApi.authenticateUser(testUser); + Assert.assertTrue(waitForIndexing(currentQuery, 1), String.format("Result count not as expected for query: %s", currentQuery)); + } + + @Test + public void executeCMISQuery12() + { + String query = "SELECT * FROM cmis:folder where IN_FOLDER('%s') AND NOT(cmis:name NOT IN ('subFolder'))"; + String currentQuery = String.format(query, parentFolder.getNodeRef()); + cmisApi.authenticateUser(testUser); + Assert.assertTrue(waitForIndexing(currentQuery, 1), String.format("Result count not as expected for query: %s", currentQuery)); + } + + @Test + public void executeCMISQuery13() + { + String query = "SELECT * FROM cmis:document where IN_FOLDER('%s') AND cmis:name IN ('fourthFile', 'fifthFile.txt')"; + String currentQuery = String.format(query, parentFolder.getNodeRef()); + cmisApi.authenticateUser(testUser); + Assert.assertTrue(waitForIndexing(currentQuery, 2), String.format("Result count not as expected for query: %s", currentQuery)); + } + + @Test + public void executeCMISQuery14() + { + String query = "SELECT * FROM cmis:document where IN_FOLDER('%s') AND cmis:name NOT IN ('fourthFile', 'fifthFile.txt')"; + String currentQuery = String.format(query, parentFolder.getNodeRef()); + cmisApi.authenticateUser(testUser); + Assert.assertTrue(waitForIndexing(currentQuery, 3), String.format("Result count not as expected for query: %s", currentQuery)); + } + + @Test + public void executeCMISQuery15() + { + String query = "SELECT * FROM cmis:folder where IN_FOLDER('%s') AND cmis:name <> 'subFolder'"; + String currentQuery = String.format(query, parentFolder.getNodeRef()); + cmisApi.authenticateUser(testUser); + Assert.assertTrue(waitForIndexing(currentQuery, 2), String.format("Result count not as expected for query: %s", currentQuery)); + } + + @Test + public void executeCMISQuery16() + { + String query = "SELECT cmis:secondaryObjectTypeIds FROM cmis:folder where IN_FOLDER('%s') AND cmis:name = 'subFolder'"; + String currentQuery = String.format(query, parentFolder.getNodeRef()); + cmisApi.authenticateUser(testUser); + Assert.assertTrue(waitForIndexing(currentQuery, 1), String.format("Result count not as expected for query: %s", currentQuery)); } } From 47187ee12ed5b78a809a73041d462a3c21df3133 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Tue, 27 Sep 2022 14:05:49 +0100 Subject: [PATCH 2/3] ACS-3488 Refactor in-folder tests. --- packaging/tests/tas-cmis/pom.xml | 2 - .../org/alfresco/cmis/dsl/QueryExecutor.java | 59 ++++++++++++---- .../cmis/search/SearchInFolderTests.java | 68 +++++++++---------- 3 files changed, 78 insertions(+), 51 deletions(-) diff --git a/packaging/tests/tas-cmis/pom.xml b/packaging/tests/tas-cmis/pom.xml index e38d902499..77ed7ddbc9 100644 --- a/packaging/tests/tas-cmis/pom.xml +++ b/packaging/tests/tas-cmis/pom.xml @@ -18,7 +18,6 @@ 11 UTF-8 - 3.0.53 1.1.0 3.1.1 2.5.3 @@ -69,7 +68,6 @@ org.alfresco.tas utility - ${tas.utility.version} mysql diff --git a/packaging/tests/tas-cmis/src/main/java/org/alfresco/cmis/dsl/QueryExecutor.java b/packaging/tests/tas-cmis/src/main/java/org/alfresco/cmis/dsl/QueryExecutor.java index 381f2d05d2..040e8eee85 100644 --- a/packaging/tests/tas-cmis/src/main/java/org/alfresco/cmis/dsl/QueryExecutor.java +++ b/packaging/tests/tas-cmis/src/main/java/org/alfresco/cmis/dsl/QueryExecutor.java @@ -1,5 +1,6 @@ package org.alfresco.cmis.dsl; +import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toSet; @@ -10,12 +11,11 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.Set; -import java.util.stream.Collectors; +import java.util.function.Function; import java.util.stream.StreamSupport; -import com.google.common.collect.Streams; - import org.alfresco.cmis.CmisWrapper; import org.alfresco.utility.LogFactory; import org.alfresco.utility.data.provider.XMLTestData; @@ -27,6 +27,7 @@ import org.alfresco.utility.model.TestModel; import org.apache.chemistry.opencmis.client.api.ItemIterable; import org.apache.chemistry.opencmis.client.api.QueryResult; import org.apache.chemistry.opencmis.client.api.Session; +import org.apache.chemistry.opencmis.commons.data.PropertyData; import org.slf4j.Logger; import org.testng.Assert; @@ -39,7 +40,7 @@ public class QueryExecutor static Logger LOG = LogFactory.getLogger(); CmisWrapper cmisWrapper; - private long returnedResults = -1; + private long resultCount = -1; private String currentQuery = ""; private List results; @@ -51,7 +52,7 @@ public class QueryExecutor public QueryResultAssertion assertResultsCount() { - returnedResults = executeQuery(currentQuery).getPageNumItems(); + resultCount = executeQuery(currentQuery).getPageNumItems(); return new QueryResultAssertion(); } @@ -70,10 +71,26 @@ public class QueryExecutor STEP("Sending query " + currentQuery); results = StreamSupport.stream(executeQuery(currentQuery).spliterator(), false) .collect(toList()); - STEP("Received results " + results); + resultCount = results.size(); + STEP("Received results " + results.stream().map(this::resultToString).collect(toList())); return new QueryResultAssertion(); } + /** Try to return a useful string representation of the CMIS query result. */ + private String resultToString(QueryResult result) + { + if (result == null || result.getProperties() == null) + { + return "null"; + } + Optional> idProperty = result.getProperties().stream() + .filter(propertyData -> propertyData.getId().equals("cmis:objectId")) + .findFirst(); + return idProperty.map(PropertyData::getValues) + .map(values -> values.stream().map(Object::toString).collect(joining(","))) + .orElse(result.getProperties().toString()); + } + private ItemIterable executeQuery(String query) { Session session = cmisWrapper.getSession(); @@ -165,15 +182,15 @@ public class QueryExecutor public QueryResultAssertion hasLength(long expectedValue) { STEP(String.format("Verify that query: '%s' has %d results count returned", currentQuery, expectedValue)); - Assert.assertEquals(returnedResults, expectedValue, showErrorMessage()); + Assert.assertEquals(resultCount, expectedValue, showErrorMessage()); return this; } public QueryResultAssertion isGreaterThan(long expectedValue) { STEP(String.format("Verify that query: '%s' has more than %d results count returned", currentQuery, expectedValue)); - if (expectedValue <= returnedResults) - Assert.fail(String.format("%s expected to have more than %d results, but found %d", showErrorMessage(), expectedValue, returnedResults)); + if (expectedValue <= resultCount) + Assert.fail(String.format("%s expected to have more than %d results, but found %d", showErrorMessage(), expectedValue, resultCount)); return this; } @@ -181,8 +198,8 @@ public class QueryExecutor public QueryResultAssertion isLowerThan(long expectedValue) { STEP(String.format("Verify that query: '%s' has more than %d results count returned", currentQuery, expectedValue)); - if (returnedResults >= expectedValue) - Assert.fail(String.format("%s expected to have less than %d results, but found %d", showErrorMessage(), expectedValue, returnedResults)); + if (resultCount >= expectedValue) + Assert.fail(String.format("%s expected to have less than %d results, but found %d", showErrorMessage(), expectedValue, resultCount)); return this; } @@ -194,7 +211,7 @@ public class QueryExecutor results.forEach((r) -> { columnValues.add(r.getPropertyValueByQueryName(queryName)); }); - List orderedColumnValues = columnValues.stream().sorted().collect(Collectors.toList()); + List orderedColumnValues = columnValues.stream().sorted().collect(toList()); Assert.assertEquals(columnValues, orderedColumnValues, String.format("%s column values expected to be in ascendent order, but found %s", queryName, columnValues.toString())); @@ -209,7 +226,7 @@ public class QueryExecutor results.forEach((r) -> { columnValues.add(r.getPropertyValueByQueryName(queryName)); }); - List reverseOrderedColumnValues = columnValues.stream().sorted(Collections.reverseOrder()).collect(Collectors.toList()); + List reverseOrderedColumnValues = columnValues.stream().sorted(Collections.reverseOrder()).collect(toList()); Assert.assertEquals(columnValues, reverseOrderedColumnValues, String.format("%s column values expected to be in descendent order, but found %s", queryName, columnValues.toString())); @@ -232,18 +249,30 @@ public class QueryExecutor } public QueryResultAssertion isReturningValues(String queryName, Set values) + { + return isReturningValues(queryName, values, false); + } + + public QueryResultAssertion isReturningValues(String queryName, Set values, boolean multivalue) { STEP(String.format("Verify that query: '%s' returns the values from %s for column %s", currentQuery, values, queryName)); - Set resultSet = results.stream().map(r -> (T) r.getPropertyValueByQueryName(queryName)).collect(toSet()); + Function extractValue = (multivalue ? (r -> r.getPropertyMultivalueById(queryName)) : r -> r.getPropertyValueById(queryName)); + Set resultSet = results.stream().map(extractValue).collect(toSet()); Assert.assertEquals(resultSet, values, "Values did not match - expected " + values + " got " + resultSet); return this; } public QueryResultAssertion isReturningOrderedValues(String queryName, List values) + { + return isReturningOrderedValues(queryName, values, false); + } + + public QueryResultAssertion isReturningOrderedValues(String queryName, List values, boolean multivalue) { STEP(String.format("Verify that query: '%s' returns the values from %s for column %s", currentQuery, values, queryName)); - List resultList = results.stream().map(r -> (T) r.getPropertyValueByQueryName(queryName)).collect(toList()); + Function extractValue = (multivalue ? (r -> r.getPropertyMultivalueById(queryName)) : r -> r.getPropertyValueById(queryName)); + List resultList = results.stream().map(extractValue).collect(toList()); // Include both lists in assertion message as TestNG does not provide this information. Assert.assertEquals(resultList, values, "Values did not match expected " + values + " but found " + resultList); diff --git a/packaging/tests/tas-cmis/src/test/java/org/alfresco/cmis/search/SearchInFolderTests.java b/packaging/tests/tas-cmis/src/test/java/org/alfresco/cmis/search/SearchInFolderTests.java index 0c1e17fceb..1efe1d4834 100644 --- a/packaging/tests/tas-cmis/src/test/java/org/alfresco/cmis/search/SearchInFolderTests.java +++ b/packaging/tests/tas-cmis/src/test/java/org/alfresco/cmis/search/SearchInFolderTests.java @@ -1,12 +1,9 @@ package org.alfresco.cmis.search; -import static java.util.stream.Collectors.toList; - -import java.util.Arrays; import java.util.List; +import java.util.Set; import org.alfresco.utility.Utility; -import org.alfresco.utility.model.ContentModel; import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FileType; import org.alfresco.utility.model.FolderModel; @@ -70,7 +67,7 @@ public class SearchInFolderTests extends AbstractCmisE2ETest } @Test - public void executeCMISQuery0() + public void executeCMISQuery_selectFieldsFromFolder() { String query = "SELECT cmis:name, cmis:parentId, cmis:path, cmis:allowedChildObjectTypeIds" + " FROM cmis:folder where IN_FOLDER('%s') AND cmis:name = 'subFolder'"; @@ -80,7 +77,7 @@ public class SearchInFolderTests extends AbstractCmisE2ETest } @Test - public void executeCMISQuery1() + public void executeCMISQuery_selectFieldsFromDocument() { String query = "SELECT cmis:name, cmis:objectId, cmis:lastModifiedBy, cmis:creationDate, cmis:contentStreamFileName" + " FROM cmis:document where IN_FOLDER('%s') AND cmis:name = 'fourthFile'"; @@ -90,7 +87,7 @@ public class SearchInFolderTests extends AbstractCmisE2ETest } @Test - public void executeCMISQuery2() + public void executeCMISQuery_selectParentId() { String query = "SELECT cmis:parentId FROM cmis:folder where IN_FOLDER('%s')"; String currentQuery = String.format(query, parentFolder.getNodeRef()); @@ -98,11 +95,11 @@ public class SearchInFolderTests extends AbstractCmisE2ETest // Expect to get the same parent for each of the three matches. String parentId = parentFolder.getNodeRef(); List expectedParentIds = List.of(parentId, parentId, parentId); - waitForIndexing(query, execution -> execution.isReturningOrderedValues("cmis:parentId", expectedParentIds)); + waitForIndexing(currentQuery, execution -> execution.isReturningOrderedValues("cmis:parentId", expectedParentIds)); } @Test - public void executeCMISQuery3() + public void executeCMISQuery_inFolder() { String query = "SELECT * FROM cmis:document where IN_FOLDER('%s')"; String currentQuery = String.format(query, parentFolder.getNodeRef()); @@ -111,7 +108,7 @@ public class SearchInFolderTests extends AbstractCmisE2ETest } @Test - public void executeCMISQuery4() + public void executeCMISQuery_orderByNameAsc() { String query = "SELECT * FROM cmis:document where IN_FOLDER('%s') AND cmis:name NOT LIKE 'file%%' ORDER BY cmis:name ASC"; String currentQuery = String.format(query, parentFolder.getNodeRef()); @@ -120,110 +117,113 @@ public class SearchInFolderTests extends AbstractCmisE2ETest } @Test - public void executeCMISQuery5() + public void executeCMISQuery_orderByNameDesc() { - String query = "SELECT * FROM cmis:document where IN_FOLDER('%s') ORDER BY cmis:name DESC"; + String query = "SELECT * FROM cmis:document where IN_FOLDER('%s') AND cmis:name NOT LIKE 'file%%' ORDER BY cmis:name DESC"; String currentQuery = String.format(query, parentFolder.getNodeRef()); cmisApi.authenticateUser(testUser); - Assert.assertTrue(waitForIndexing(currentQuery, 5), String.format("Result count not as expected for query: %s", currentQuery)); + waitForIndexingOrdered(currentQuery, subFile4, subFile1, subFile5); } @Test - public void executeCMISQuery6() + public void executeCMISQuery_orderByLastModifiedAsc() { String query = "SELECT * FROM cmis:folder where IN_FOLDER('%s') ORDER BY cmis:lastModificationDate ASC"; String currentQuery = String.format(query, parentFolder.getNodeRef()); cmisApi.authenticateUser(testUser); - Assert.assertTrue(waitForIndexing(currentQuery, 3), String.format("Result count not as expected for query: %s", currentQuery)); + waitForIndexingOrdered(currentQuery, subFolder1, subFolder2, subFolder3); } @Test - public void executeCMISQuery7() + public void executeCMISQuery_orderByLastModifiedDesc() { String query = "SELECT * FROM cmis:folder where IN_FOLDER('%s') ORDER BY cmis:lastModificationDate DESC"; String currentQuery = String.format(query, parentFolder.getNodeRef()); cmisApi.authenticateUser(testUser); - Assert.assertTrue(waitForIndexing(currentQuery, 3), String.format("Result count not as expected for query: %s", currentQuery)); + waitForIndexingOrdered(currentQuery, subFolder3, subFolder2, subFolder1); } @Test - public void executeCMISQuery8() + public void executeCMISQuery_orderByCreatedBy() { String query = "SELECT * FROM cmis:document where IN_FOLDER('%s') ORDER BY cmis:createdBy DESC"; String currentQuery = String.format(query, parentFolder.getNodeRef()); cmisApi.authenticateUser(testUser); - Assert.assertTrue(waitForIndexing(currentQuery, 5), String.format("Result count not as expected for query: %s", currentQuery)); + // All the results were created by the same user, so we can't assert anything about the order. + waitForIndexing(currentQuery, subFile5, subFile1, subFile2, subFile3, subFile4); } @Test - public void executeCMISQuery9() + public void executeCMISQuery_documentNameNotNull() { String query = "SELECT * FROM cmis:document where IN_FOLDER('%s') AND cmis:name IS NOT NULL"; String currentQuery = String.format(query, parentFolder.getNodeRef()); cmisApi.authenticateUser(testUser); - Assert.assertTrue(waitForIndexing(currentQuery, 5), String.format("Result count not as expected for query: %s", currentQuery)); + waitForIndexing(currentQuery, subFile1, subFile2, subFile3, subFile4, subFile5); } @Test - public void executeCMISQuery10() + public void executeCMISQuery_folderNameNotNull() { String query = "SELECT * FROM cmis:folder where IN_FOLDER('%s') AND cmis:name IS NOT NULL"; String currentQuery = String.format(query, parentFolder.getNodeRef()); cmisApi.authenticateUser(testUser); - Assert.assertTrue(waitForIndexing(currentQuery, 3), String.format("Result count not as expected for query: %s", currentQuery)); + waitForIndexing(currentQuery, subFolder1, subFolder2, subFolder3); } @Test - public void executeCMISQuery11() + public void executeCMISQuery_nameLike() { String query = "SELECT * FROM cmis:document where IN_FOLDER('%s') AND cmis:name LIKE 'fourthFile'"; String currentQuery = String.format(query, parentFolder.getNodeRef()); cmisApi.authenticateUser(testUser); - Assert.assertTrue(waitForIndexing(currentQuery, 1), String.format("Result count not as expected for query: %s", currentQuery)); + waitForIndexingOrdered(currentQuery, subFile4); } @Test - public void executeCMISQuery12() + public void executeCMISQuery_doubleNegative() { String query = "SELECT * FROM cmis:folder where IN_FOLDER('%s') AND NOT(cmis:name NOT IN ('subFolder'))"; String currentQuery = String.format(query, parentFolder.getNodeRef()); cmisApi.authenticateUser(testUser); - Assert.assertTrue(waitForIndexing(currentQuery, 1), String.format("Result count not as expected for query: %s", currentQuery)); + waitForIndexingOrdered(currentQuery, subFolder3); } @Test - public void executeCMISQuery13() + public void executeCMISQuery_nameInList() { String query = "SELECT * FROM cmis:document where IN_FOLDER('%s') AND cmis:name IN ('fourthFile', 'fifthFile.txt')"; String currentQuery = String.format(query, parentFolder.getNodeRef()); cmisApi.authenticateUser(testUser); - Assert.assertTrue(waitForIndexing(currentQuery, 2), String.format("Result count not as expected for query: %s", currentQuery)); + waitForIndexing(currentQuery, subFile4, subFile5); } @Test - public void executeCMISQuery14() + public void executeCMISQuery_nameNotInList() { String query = "SELECT * FROM cmis:document where IN_FOLDER('%s') AND cmis:name NOT IN ('fourthFile', 'fifthFile.txt')"; String currentQuery = String.format(query, parentFolder.getNodeRef()); cmisApi.authenticateUser(testUser); - Assert.assertTrue(waitForIndexing(currentQuery, 3), String.format("Result count not as expected for query: %s", currentQuery)); + waitForIndexing(currentQuery, subFile1, subFile2, subFile3); } @Test - public void executeCMISQuery15() + public void executeCMISQuery_nameDifferentFrom() { String query = "SELECT * FROM cmis:folder where IN_FOLDER('%s') AND cmis:name <> 'subFolder'"; String currentQuery = String.format(query, parentFolder.getNodeRef()); cmisApi.authenticateUser(testUser); - Assert.assertTrue(waitForIndexing(currentQuery, 2), String.format("Result count not as expected for query: %s", currentQuery)); + waitForIndexing(currentQuery, subFolder1, subFolder2); } @Test - public void executeCMISQuery16() + public void executeCMISQuery_selectSecondaryObjectTypeIds() { String query = "SELECT cmis:secondaryObjectTypeIds FROM cmis:folder where IN_FOLDER('%s') AND cmis:name = 'subFolder'"; String currentQuery = String.format(query, parentFolder.getNodeRef()); cmisApi.authenticateUser(testUser); + Set> expectedSecondaryObjectTypeIds = Set.of(List.of("P:cm:titled", "P:sys:localized")); + waitForIndexing(currentQuery, execution -> execution.isReturningValues("cmis:secondaryObjectTypeIds", expectedSecondaryObjectTypeIds, true)); Assert.assertTrue(waitForIndexing(currentQuery, 1), String.format("Result count not as expected for query: %s", currentQuery)); } } From 529f6b31e836a928efd9836a09d31e474b063772 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Tue, 27 Sep 2022 16:22:09 +0100 Subject: [PATCH 3/3] Update SearchInFolderTests.java --- .../test/java/org/alfresco/cmis/search/SearchInFolderTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/tests/tas-cmis/src/test/java/org/alfresco/cmis/search/SearchInFolderTests.java b/packaging/tests/tas-cmis/src/test/java/org/alfresco/cmis/search/SearchInFolderTests.java index 1efe1d4834..5ef1738470 100644 --- a/packaging/tests/tas-cmis/src/test/java/org/alfresco/cmis/search/SearchInFolderTests.java +++ b/packaging/tests/tas-cmis/src/test/java/org/alfresco/cmis/search/SearchInFolderTests.java @@ -57,7 +57,7 @@ public class SearchInFolderTests extends AbstractCmisE2ETest .createFile(subFile3) .createFile(subFile4); // wait for index - Utility.waitToLoopTime(5);//getElasticWaitTimeInSeconds()); + Utility.waitToLoopTime(getElasticWaitTimeInSeconds()); } @AfterClass(alwaysRun = true)