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)); } }