ACS-3488 Remove usage of XML data provider.

This broke when we updated TestNG.
This commit is contained in:
Tom Page
2022-09-27 10:38:25 +01:00
parent 73518a0342
commit 520b9e7fcb
3 changed files with 259 additions and 34 deletions

View File

@@ -12,6 +12,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import com.google.common.collect.Streams; import com.google.common.collect.Streams;
@@ -40,7 +41,7 @@ public class QueryExecutor
CmisWrapper cmisWrapper; CmisWrapper cmisWrapper;
private long returnedResults = -1; private long returnedResults = -1;
private String currentQuery = ""; private String currentQuery = "";
private ItemIterable<QueryResult> results; private List<QueryResult> results;
public QueryExecutor(CmisWrapper cmisWrapper, String query) public QueryExecutor(CmisWrapper cmisWrapper, String query)
{ {
@@ -56,19 +57,20 @@ public class QueryExecutor
public QueryResultAssertion assertColumnIsOrdered() public QueryResultAssertion assertColumnIsOrdered()
{ {
results = executeQuery(currentQuery); return assertValues();
return new QueryResultAssertion();
} }
public QueryResultAssertion assertColumnValuesRange() public QueryResultAssertion assertColumnValuesRange()
{ {
results = executeQuery(currentQuery); return assertValues();
return new QueryResultAssertion();
} }
public QueryResultAssertion 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(); return new QueryResultAssertion();
} }
@@ -160,7 +162,7 @@ public class QueryExecutor
public class QueryResultAssertion 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)); STEP(String.format("Verify that query: '%s' has %d results count returned", currentQuery, expectedValue));
Assert.assertEquals(returnedResults, expectedValue, showErrorMessage()); Assert.assertEquals(returnedResults, expectedValue, showErrorMessage());
@@ -232,8 +234,8 @@ public class QueryExecutor
public <T> QueryResultAssertion isReturningValues(String queryName, Set<T> values) public <T> QueryResultAssertion isReturningValues(String queryName, Set<T> values)
{ {
STEP(String.format("Verify that query: '%s' returns the values from %s for column %s", currentQuery, values, queryName)); STEP(String.format("Verify that query: '%s' returns the values from %s for column %s", currentQuery, values, queryName));
Set<T> resultSet = Streams.stream(results).map(r -> (T) r.getPropertyValueByQueryName(queryName)).collect(toSet()); Set<T> resultSet = results.stream().map(r -> (T) r.getPropertyValueByQueryName(queryName)).collect(toSet());
Assert.assertEquals(resultSet, values, "Values did not match"); Assert.assertEquals(resultSet, values, "Values did not match - expected " + values + " got " + resultSet);
return this; return this;
} }
@@ -241,7 +243,7 @@ public class QueryExecutor
public <T> QueryResultAssertion isReturningOrderedValues(String queryName, List<T> values) public <T> QueryResultAssertion isReturningOrderedValues(String queryName, List<T> values)
{ {
STEP(String.format("Verify that query: '%s' returns the values from %s for column %s", currentQuery, values, queryName)); STEP(String.format("Verify that query: '%s' returns the values from %s for column %s", currentQuery, values, queryName));
List<T> resultList = Streams.stream(results).map(r -> (T) r.getPropertyValueByQueryName(queryName)).collect(toList()); List<T> resultList = results.stream().map(r -> (T) r.getPropertyValueByQueryName(queryName)).collect(toList());
// Include both lists in assertion message as TestNG does not provide this information. // 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); Assert.assertEquals(resultList, values, "Values did not match expected " + values + " but found " + resultList);

View File

@@ -1,9 +1,21 @@
package org.alfresco.cmis.search; 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.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.CmisProperties;
import org.alfresco.cmis.dsl.QueryExecutor.QueryResultAssertion;
import org.alfresco.utility.Utility; import org.alfresco.utility.Utility;
import org.alfresco.utility.model.ContentModel;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; 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 * Repeat Elastic Query till results count returns expectedCountResults
* @param query CMIS Query to be executed * @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 * @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 try
{ {
cmisApi.withQuery(query).assertResultsCount().equals(expectedCountResults); waitForIndexing(query, execution -> execution.hasLength(expectedResultsCount));
return true; return true;
} }
catch (AssertionError ae) catch (AssertionError ae)
{ {
LOGGER.info(String.format("WaitForIndexing in Progress: %s", ae)); STEP("Received assertion error for query '" + query + "': " + ae);
}
Utility.waitToLoopTime(getElasticWaitTimeInSeconds(), "Wait For Indexing");
}
return false; 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<String> 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<String> 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<QueryResultAssertion> assertionMethod)
{
int searchCount = 0;
while (true)
{
try
{
assertionMethod.accept(cmisApi.withQuery(query).assertValues());
return;
}
catch (AssertionError 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;
}
}
}
}
} }

View File

@@ -1,12 +1,15 @@
package org.alfresco.cmis.search; 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.Utility;
import org.alfresco.utility.data.provider.XMLDataConfig; import org.alfresco.utility.model.ContentModel;
import org.alfresco.utility.data.provider.XMLTestDataProvider;
import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FileType; import org.alfresco.utility.model.FileType;
import org.alfresco.utility.model.FolderModel; import org.alfresco.utility.model.FolderModel;
import org.alfresco.utility.model.QueryModel;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
@@ -17,6 +20,21 @@ public class SearchInFolderTests extends AbstractCmisE2ETest
private FolderModel parentFolder, subFolder1, subFolder2, subFolder3; private FolderModel parentFolder, subFolder1, subFolder2, subFolder3;
private FileModel subFile1, subFile2, subFile3, subFile4, subFile5; private FileModel subFile1, subFile2, subFile3, subFile4, subFile5;
/**
* Create test data in the following format:
* <pre>
* testSite
* +- parentFolder
* +- subFile5 (fifthFile.txt: "fifthFile content")
* +- subFolder1
* +- subFolder2
* +- subFolder3 (subFolder)
* +- subFile1 (firstFile.xls)
* +- subFile2 (.pptx)
* +- subFile3 (.txt)
* +- subFile4 (fourthFile.docx: "fourthFileTitle", "fourthFileDescription")
* </pre>
*/
@BeforeClass(alwaysRun = true) @BeforeClass(alwaysRun = true)
public void createTestData() throws Exception public void createTestData() throws Exception
{ {
@@ -42,7 +60,7 @@ public class SearchInFolderTests extends AbstractCmisE2ETest
.createFile(subFile3) .createFile(subFile3)
.createFile(subFile4); .createFile(subFile4);
// wait for index // wait for index
Utility.waitToLoopTime(getElasticWaitTimeInSeconds()); Utility.waitToLoopTime(5);//getElasticWaitTimeInSeconds());
} }
@AfterClass(alwaysRun = true) @AfterClass(alwaysRun = true)
@@ -51,12 +69,161 @@ public class SearchInFolderTests extends AbstractCmisE2ETest
dataContent.deleteSite(testSite); dataContent.deleteSite(testSite);
} }
@Test(dataProviderClass = XMLTestDataProvider.class, dataProvider = "getQueriesData") @Test
@XMLDataConfig(file = "src/test/resources/search-in-folder.xml") public void executeCMISQuery0()
public void executeCMISQuery(QueryModel query)
{ {
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); 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<String> 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));
} }
} }