mirror of
https://github.com/Alfresco/SearchServices.git
synced 2026-09-16 18:12:56 +00:00
Merge branch 'feature/RefactorAbstractTests' into 'master'
Refactor abstract test classes using changes to TAS. See merge request search_discovery/insightengine!118
This commit is contained in:
+4
-3
@@ -11,9 +11,9 @@
|
||||
<name>Search Analytics E2E Tests</name>
|
||||
<description>Test Project to test Search Service and Analytics Features on a complete setup of Alfresco, Share</description>
|
||||
<properties>
|
||||
<tas.rest.api.version>6.0.0.3</tas.rest.api.version>
|
||||
<tas.cmis.api.version>6.0.0.1</tas.cmis.api.version>
|
||||
<tas.utility.version>2.0.12</tas.utility.version>
|
||||
<tas.rest.api.version>6.0.1.2</tas.rest.api.version>
|
||||
<tas.cmis.api.version>6.0.0.4</tas.cmis.api.version>
|
||||
<tas.utility.version>3.0.9</tas.utility.version>
|
||||
<rm.version>2.6.0</rm.version>
|
||||
<suiteXmlFile>src/test/resources/SearchSuite.xml</suiteXmlFile>
|
||||
<test.exclude></test.exclude>
|
||||
@@ -45,6 +45,7 @@
|
||||
</suiteXmlFiles>
|
||||
<excludedGroups>${test.exclude}</excludedGroups>
|
||||
<groups>${test.include}</groups>
|
||||
<redirectTestOutputToFile>true</redirectTestOutputToFile>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
+33
-57
@@ -47,9 +47,10 @@ import static lombok.AccessLevel.PROTECTED;
|
||||
@ContextConfiguration("classpath:alfresco-search-e2e-context.xml")
|
||||
public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringContextTests
|
||||
{
|
||||
public static final int SEARCH_MAX_ATTEMPS = 6;
|
||||
/** The number of retries that a query will be tried before giving up. */
|
||||
private static final int SEARCH_MAX_ATTEMPTS = 6;
|
||||
|
||||
private static Logger LOG = LogFactory.getLogger();
|
||||
private static final Logger LOGGER = LogFactory.getLogger();
|
||||
|
||||
@Autowired
|
||||
protected RestProperties restProperties;
|
||||
@@ -85,8 +86,6 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont
|
||||
|
||||
protected static String unique_searchString;
|
||||
|
||||
public static final String NODE_PREFIX = "workspace/SpacesStore/";
|
||||
|
||||
@BeforeSuite(alwaysRun = true)
|
||||
public void beforeSuite() throws Exception
|
||||
{
|
||||
@@ -97,7 +96,7 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont
|
||||
}
|
||||
|
||||
@BeforeClass(alwaysRun = true)
|
||||
public void setup() throws Exception
|
||||
public void setup()
|
||||
{
|
||||
serverHealth.assertServerIsOnline();
|
||||
|
||||
@@ -127,7 +126,7 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOG.warn("Error Loading Custom Model", e);
|
||||
LOGGER.warn("Error Loading Custom Model", e);
|
||||
}
|
||||
}
|
||||
return modelDeployed;
|
||||
@@ -135,8 +134,6 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont
|
||||
|
||||
public boolean deactivateCustomModel(String fileName)
|
||||
{
|
||||
Boolean modelDeactivated = false;
|
||||
|
||||
try
|
||||
{
|
||||
FileModel customModel = getCustomModel(fileName);
|
||||
@@ -144,17 +141,16 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont
|
||||
// Deactivate the model if found
|
||||
if (customModel != null)
|
||||
{
|
||||
|
||||
cmisApi.authenticateUser(dataUser.getAdminUser()).usingResource(customModel).updateProperty("cm:modelActive", false);
|
||||
|
||||
modelDeactivated = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOG.warn("Error Deactivating Custom Model", e);
|
||||
LOGGER.warn("Error Deactivating Custom Model", e);
|
||||
}
|
||||
return modelDeactivated;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean deleteCustomModel(String fileName)
|
||||
@@ -176,12 +172,12 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG.error("Custom Content Model [{}] is not available under [/Data Dictionary/Models/] location", fileName);
|
||||
LOGGER.error("Custom Content Model [{}] is not available under [/Data Dictionary/Models/] location", fileName);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOG.error("Custom Content Model [{}] is not available under [/Data Dictionary/Models/] location", fileName);
|
||||
LOGGER.error("Custom Content Model [{}] is not available under [/Data Dictionary/Models/] location", fileName);
|
||||
}
|
||||
|
||||
return modelDeleted;
|
||||
@@ -206,17 +202,17 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont
|
||||
customModel.setNodeRef(modelInRepo.getId());
|
||||
customModel.setNodeRef(customModel.getNodeRefWithoutVersion());
|
||||
customModel.setCmisLocation(String.format("/Data Dictionary/Models/%s", fileName));
|
||||
LOG.info("Custom Model file: " + customModel.getCmisLocation());
|
||||
LOGGER.info("Custom Model file: " + customModel.getCmisLocation());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG.info("Custom Content Model [{}] is not available under [/Data Dictionary/Models/] location", fileName);
|
||||
LOGGER.info("Custom Content Model [{}] is not available under [/Data Dictionary/Models/] location", fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOG.warn("Error Getting Custom Model: " + fileName, e);
|
||||
LOGGER.warn("Error Getting Custom Model: " + fileName, e);
|
||||
}
|
||||
|
||||
return customModel;
|
||||
@@ -231,22 +227,15 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont
|
||||
*/
|
||||
protected SearchResponse query(SearchRequest query)
|
||||
{
|
||||
try
|
||||
{
|
||||
return restClient.authenticateUser(testUser).withSearchAPI().search(query);
|
||||
}
|
||||
catch (final Exception exception)
|
||||
{
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
return restClient.authenticateUser(testUser).withSearchAPI().search(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for Solr to finish indexing and search to return appropriate results
|
||||
*
|
||||
* @param userQuery: Search Query
|
||||
* @param userQuery Search Query
|
||||
* @param contentToFind that's expected to be included / excluded from the results
|
||||
* @param expectedInResults
|
||||
* @param expectedInResults Whether we expect the content in the results or not.
|
||||
* @return true if search returns expected results, i.e. is given content is found or excluded from the results
|
||||
*/
|
||||
public boolean isContentInSearchResults(String userQuery, String contentToFind, boolean expectedInResults) {
|
||||
@@ -254,30 +243,27 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont
|
||||
String expectedStatusCode = HttpStatus.OK.toString();
|
||||
String contentName = (contentToFind == null) ? "" : contentToFind;
|
||||
|
||||
SearchRequest searchRequest = createQuery(userQuery);
|
||||
|
||||
// Repeat search until the query results are as expected or Search Retry count is hit
|
||||
for (int searchCount = 0; searchCount < SEARCH_MAX_ATTEMPS; searchCount++)
|
||||
for (int searchCount = 0; searchCount < SEARCH_MAX_ATTEMPTS; searchCount++)
|
||||
{
|
||||
SearchRequest searchRequest = createQuery(userQuery);
|
||||
SearchResponse response = query(searchRequest);
|
||||
|
||||
if (restClient.getStatusCode().matches(expectedStatusCode))
|
||||
{
|
||||
|
||||
boolean found = response.getEntries().stream()
|
||||
.map(entry -> entry.getModel().getName())
|
||||
.filter(name -> name.equalsIgnoreCase(contentName) || contentName.isBlank())
|
||||
.count() > 0;
|
||||
|
||||
// Loop again if result is not as expected: To cater for solr lag: eventual consistency
|
||||
// Exit loop if result is as expected.
|
||||
if (expectedInResults == found)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Wait for the solr indexing.
|
||||
Utility.waitToLoopTime(properties.getSolrWaitTimeInSeconds(), "Wait For Indexing. Retry Attempt: " + searchCount);
|
||||
}
|
||||
// Wait for the solr indexing (eventual consistency).
|
||||
Utility.waitToLoopTime(properties.getSolrWaitTimeInSeconds(), "Wait For Indexing. Retry Attempt: " + (searchCount + 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -294,9 +280,8 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont
|
||||
* @param userQuery: search query, this can include the fieldname, unique search string will guarantee accurate results
|
||||
* @param expectedInResults, true if entry is expected in the results set
|
||||
* @return true (indexing is finished) if search returns appropriate results
|
||||
* @throws Exception
|
||||
*/
|
||||
public boolean waitForIndexing(String userQuery, boolean expectedInResults) throws Exception
|
||||
public boolean waitForIndexing(String userQuery, boolean expectedInResults)
|
||||
{
|
||||
// Use the search query as is: fieldname(s) may or may not be specified within the userQuery
|
||||
return waitForIndexing(null, userQuery, expectedInResults);
|
||||
@@ -308,9 +293,8 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont
|
||||
* @param userQuery
|
||||
* @param expectedInResults
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public boolean waitForMetadataIndexing(String userQuery, boolean expectedInResults) throws Exception
|
||||
public boolean waitForMetadataIndexing(String userQuery, boolean expectedInResults)
|
||||
{
|
||||
return waitForIndexing("name", userQuery, expectedInResults);
|
||||
}
|
||||
@@ -322,9 +306,8 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont
|
||||
* @param userQuery
|
||||
* @param expectedInResults
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public boolean waitForContentIndexing(String userQuery, boolean expectedInResults) throws Exception
|
||||
public boolean waitForContentIndexing(String userQuery, boolean expectedInResults)
|
||||
{
|
||||
return waitForIndexing("cm:content", userQuery, expectedInResults);
|
||||
}
|
||||
@@ -336,9 +319,8 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont
|
||||
* @param userQuery: search string, unique search string will guarantee accurate results
|
||||
* @param expectedInResults, true if entry is expected in the results set
|
||||
* @return true (indexing is finished) if search returns appropriate results
|
||||
* @throws Exception
|
||||
*/
|
||||
private boolean waitForIndexing(String fieldName, String userQuery, boolean expectedInResults) throws Exception
|
||||
private boolean waitForIndexing(String fieldName, String userQuery, boolean expectedInResults)
|
||||
{
|
||||
String query = (fieldName == null) ? userQuery : String.format("%s:'%s'", fieldName, userQuery);
|
||||
|
||||
@@ -365,16 +347,11 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont
|
||||
*/
|
||||
protected SearchResponse queryAsUser(UserModel user, String queryString)
|
||||
{
|
||||
try {
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
RestRequestQueryModel queryModel = new RestRequestQueryModel();
|
||||
queryModel.setQuery(queryString);
|
||||
searchRequest.setQuery(queryModel);
|
||||
return restClient.authenticateUser(user).withSearchAPI().search(searchRequest);
|
||||
} catch (final Exception exception)
|
||||
{
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
RestRequestQueryModel queryModel = new RestRequestQueryModel();
|
||||
queryModel.setQuery(queryString);
|
||||
searchRequest.setQuery(queryModel);
|
||||
return restClient.authenticateUser(user).withSearchAPI().search(searchRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -384,7 +361,7 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont
|
||||
* @param queryModel: The queryModel to search for, containing the query
|
||||
* @return the search response from the API
|
||||
*/
|
||||
protected SearchResponse queryAsUser(UserModel user, RestRequestQueryModel queryModel) throws Exception
|
||||
protected SearchResponse queryAsUser(UserModel user, RestRequestQueryModel queryModel)
|
||||
{
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
searchRequest.setQuery(queryModel);
|
||||
@@ -396,9 +373,8 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont
|
||||
* Helper method which create an http post request to Search API end point.
|
||||
*
|
||||
* @return {@link SearchResponse} response.
|
||||
* @throws Exception if error
|
||||
*/
|
||||
protected SearchResponse query(RestRequestQueryModel queryReq, RestRequestHighlightModel highlight) throws Exception
|
||||
protected SearchResponse query(RestRequestQueryModel queryReq, RestRequestHighlightModel highlight)
|
||||
{
|
||||
SearchRequest query = new SearchRequest(queryReq);
|
||||
query.setHighlight(highlight);
|
||||
|
||||
+1
-2
@@ -57,9 +57,8 @@ public abstract class AbstractCmisE2ETest extends AbstractE2EFunctionalTest
|
||||
* @param query CMIS Query to be executed
|
||||
* @param expectedCountResults Number of results expected
|
||||
* @return true when results count is equals to expectedCountResults
|
||||
* @throws Exception
|
||||
*/
|
||||
protected boolean waitForIndexing(String query, long expectedCountResults) throws Exception
|
||||
protected boolean waitForIndexing(String query, long expectedCountResults)
|
||||
{
|
||||
|
||||
for (int searchCount = 1; searchCount <= 3; searchCount++)
|
||||
|
||||
+2
-2
@@ -38,7 +38,7 @@ public class SolrSearchByPathTests extends AbstractCmisE2ETest
|
||||
|
||||
@Test(dataProviderClass = XMLTestDataProvider.class, dataProvider = "getAllData")
|
||||
@XMLDataConfig(file = "src/test/resources/testdata/search-by-path.xml")
|
||||
public void prepareDataForSearchByPath(XMLTestData testData) throws Exception
|
||||
public void prepareDataForSearchByPath(XMLTestData testData)
|
||||
{
|
||||
this.testData = testData;
|
||||
testData.createUsers(dataUser);
|
||||
@@ -49,7 +49,7 @@ public class SolrSearchByPathTests extends AbstractCmisE2ETest
|
||||
|
||||
@Test(dependsOnMethods = "prepareDataForSearchByPath", dataProviderClass = XMLTestDataProvider.class, dataProvider = "getQueriesData")
|
||||
@XMLDataConfig(file = "src/test/resources/testdata/search-by-path.xml")
|
||||
public void executeSearchByPathQueries(QueryModel query) throws Exception
|
||||
public void executeSearchByPathQueries(QueryModel query)
|
||||
{
|
||||
cmisApi.withQuery(query.getValue()).assertResultsCount().equals(query.getResults());
|
||||
}
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ public class SolrSearchScoreQueryTests extends AbstractCmisE2ETest
|
||||
* @see org.alfresco.test.search.functional.AbstractE2EFunctionalTest#dataPreparation()
|
||||
*/
|
||||
@Override
|
||||
public void setup() throws Exception
|
||||
public void setup()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ public abstract class AbstractSearchServicesE2ETest extends AbstractE2EFunctiona
|
||||
|
||||
protected FileModel file, file2, file3, file4;
|
||||
|
||||
public void searchServicesDataPreparation() throws Exception
|
||||
public void searchServicesDataPreparation()
|
||||
{
|
||||
/*
|
||||
* Create the following file structure for preconditions :
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ public class FingerPrintTest extends AbstractE2EFunctionalTest
|
||||
public void makeSureFingerprintQueryWorksAfterMetadataUpdate() throws Exception
|
||||
{
|
||||
// Index a new file with content
|
||||
FileModel file = new FileModel("Project_Contract.pdf", FileType.TEXT_PLAIN, "A content which is completely different from other indexed files.");
|
||||
FileModel file = new FileModel("Project_Contract.txt", FileType.TEXT_PLAIN, "A content which is completely different from other indexed files.");
|
||||
dataContent.usingUser(testUser).usingSite(testSite).usingResource(folder).createContent(file);
|
||||
|
||||
// make sure the content has been indexed (i.e. the ContentTracker fingerprint has been correctly computed
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ public class SearchTest extends AbstractSearchServicesE2ETest
|
||||
|
||||
SearchNodeModel entity = nodes.getEntryByIndex(0);
|
||||
entity.assertThat().field("search").contains("score");
|
||||
entity.getSearch().assertThat().field("score").isNotEmpty();
|
||||
entity.getSearch().assertThat().field("score").isNotNull();
|
||||
Assert.assertEquals(entity.getName(),"pangram.txt");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public abstract class AbstractUpgradeE2ETest extends AbstractTestNGSpringContext
|
||||
protected XMLTestData testData;
|
||||
|
||||
@BeforeClass(alwaysRun = true)
|
||||
public void checkServerHealth() throws Exception
|
||||
public void checkServerHealth()
|
||||
{
|
||||
serverHealth.assertServerIsOnline();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user