From f02f4044da93df19a3a5a4ec6b0ca2155171102c Mon Sep 17 00:00:00 2001 From: Roxana Lucanu Date: Mon, 6 Apr 2020 17:10:56 +0300 Subject: [PATCH] RM-7145 Added test for AFTS query --- .../rm/community/search/CmisQueryTests.java | 33 ++-- .../search/SearchDocumentsV1AftsTest.java | 163 ++++++++++++++++++ .../search/SearchDocumentsV1CmisTest.java | 30 +++- 3 files changed, 194 insertions(+), 32 deletions(-) create mode 100644 rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchDocumentsV1AftsTest.java diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/CmisQueryTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/CmisQueryTests.java index 8be8ff293d..b76d855b7a 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/CmisQueryTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/CmisQueryTests.java @@ -39,6 +39,7 @@ import org.alfresco.rest.rm.community.base.BaseRMRestTest; import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild; import org.alfresco.rest.rm.community.model.user.UserPermissions; import org.alfresco.test.AlfrescoTest; +import org.alfresco.utility.Utility; import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FileType; @@ -49,6 +50,7 @@ import org.apache.chemistry.opencmis.client.api.OperationContext; import org.apache.chemistry.opencmis.client.api.QueryResult; import org.apache.chemistry.opencmis.client.runtime.OperationContextImpl; import org.springframework.beans.factory.annotation.Autowired; +import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -125,28 +127,13 @@ public class CmisQueryTests extends BaseRMRestTest //do a cmis query to wait for solr indexing - long currentTime = System.currentTimeMillis(); - long endTime = 0; - do + Utility.sleep(5000, 80000, () -> { - try - { - endTime = System.currentTimeMillis(); - ItemIterable results = contentActions.getCMISSession(getAdminUser().getUsername(), - getAdminUser().getPassword()).query(SQL_WITH_NAME, false); - assertEquals("Total number of items is not 30, got " + results.getTotalNumItems() + "total items", - 30, results.getTotalNumItems()); - break; - } - catch (AssertionError | Exception e) - { - if (endTime - currentTime > 30000) - { - throw new AssertionError("Maximum retry period reached, test failed.", e); - } - Thread.sleep(5000); - } - } while (true); + ItemIterable results = contentActions.getCMISSession(getAdminUser().getUsername(), + getAdminUser().getPassword()).query(SQL_WITH_NAME, false); + Assert.assertEquals(results.getTotalNumItems(), 30, + "Total number of items is not 10, got " + results.getTotalNumItems() + " total items"); + }); } /** @@ -183,7 +170,7 @@ public class CmisQueryTests extends BaseRMRestTest */ @Test @AlfrescoTest (jira = "MNT-19442") - public void getDocumentsWithSpecificNamesCmisQuery() throws Exception + public void getDocumentsWithSpecificNamesCmisQuery() { // execute the cmis query ItemIterable results = @@ -206,7 +193,7 @@ public class CmisQueryTests extends BaseRMRestTest */ @Test @AlfrescoTest (jira = "MNT-19442") - public void getDocumentsCmisQueryWithPagination() throws Exception + public void getDocumentsCmisQueryWithPagination() { OperationContext oc = new OperationContextImpl(); oc.setMaxItemsPerPage(10); diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchDocumentsV1AftsTest.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchDocumentsV1AftsTest.java new file mode 100644 index 0000000000..23f6faea50 --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchDocumentsV1AftsTest.java @@ -0,0 +1,163 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2020 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 + * 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 . + * #L% + */ +package org.alfresco.rest.rm.community.search; + +import static java.util.Arrays.asList; + +import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix; +import static org.alfresco.utility.report.log.Step.STEP; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import org.alfresco.dataprep.ContentActions; +import org.alfresco.rest.core.search.SearchRequestBuilder; +import org.alfresco.rest.rm.community.base.BaseRMRestTest; +import org.alfresco.rest.search.RestRequestQueryModel; +import org.alfresco.rest.search.SearchResponse; +import org.alfresco.rest.v0.UserTrashcanAPI; +import org.alfresco.test.AlfrescoTest; +import org.alfresco.utility.Utility; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.SiteModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * This class contains the tests for v1 Search API for documents using AFTS query + * + * @author Roxana Lucanu + * @since 2.6.3 + */ +public class SearchDocumentsV1AftsTest extends BaseRMRestTest +{ + private static final String SEARCH_TERM = generateTestPrefix(SearchDocumentsV1AftsTest.class); + private SiteModel collaborationSite; + private FileModel fileModel; + private RestRequestQueryModel queryModel; + + @Autowired + private UserTrashcanAPI userTrashcanAPI; + + @Autowired + private ContentActions contentActions; + + /** + * Create a collaboration site and some documents in it. + */ + @BeforeClass (alwaysRun = true) + public void setupSearchAPI() throws Exception + { + STEP("Create a collaboration site"); + collaborationSite = dataSite.usingAdmin().createPrivateRandomSite(); + + STEP("Create 10 documents with name ending with SEARCH_TERM"); + for (int i = 0; ++i <= 10; ) + { + fileModel = new FileModel("Doc" + i + SEARCH_TERM, FileType.UNDEFINED); + fileModel = dataContent.usingAdmin().usingSite(collaborationSite).createContent(fileModel); + } + queryModel = new RestRequestQueryModel(); + queryModel.setLanguage("afts"); + queryModel.setQuery("cm:name:*" + SEARCH_TERM); + + //do a cmis query to wait for solr indexing + Utility.sleep(5000, 80000, () -> + { + SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) + .setPagingBuilder(new SearchRequestBuilder().setPagination(100, 0)) + .setFieldsBuilder(asList("id", "name")); + SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(null).search(sqlRequest); + assertEquals(searchResponse.getPagination().getTotalItems().intValue(), 10, + "Total number of items is not 10, got " + searchResponse.getPagination().getTotalItems() + " total items"); + }); + } + + /** + * Given some documents having a common term in the name + * When executing the search query with paging + * And setting the skipCount and maxItems to reach the number of total items + * Then hasMoreItems will be set to false + */ + @Test + @AlfrescoTest (jira = "RM-7145") + public void searchWhenMaxItemsReached() throws Exception + { + final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) + .setPagingBuilder(new SearchRequestBuilder().setPagination(5, 5)) + .setFieldsBuilder(asList("id", "name")); + + SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(null).search(sqlRequest); + assertEquals(searchResponse.getPagination().getCount(), 5); + assertEquals(searchResponse.getPagination().getSkipCount(), 5); + assertFalse(searchResponse.getPagination().isHasMoreItems()); + assertEquals(searchResponse.getEntries().size(), 5); + } + + /** + * Given some documents ending with a particular text + * When executing the search query with paging + * And setting skipCount and maxItems to exceed the number of total items + * Then hasMoreItems will be set to false + */ + @Test + public void searchWhenTotalItemsExceed() throws Exception + { + final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) + .setPagingBuilder(new SearchRequestBuilder().setPagination(5, 6)) + .setFieldsBuilder(asList("id", "name")); + + SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(null).search(sqlRequest); + assertEquals(searchResponse.getPagination().getCount(), 4); + assertEquals(searchResponse.getPagination().getSkipCount(), 6); + assertFalse(searchResponse.getPagination().isHasMoreItems()); + assertEquals(searchResponse.getEntries().size(), 4); + } + + /** + * Given some documents ending with a particular text + * When executing the search query with paging + * And setting skipCount and maxItems under the number of total items + * Then hasMoreItems will be set to true + */ + @Test + public void searchResultsUnderTotalItems() throws Exception + { + final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) + .setPagingBuilder(new SearchRequestBuilder().setPagination(4, 5)) + .setFieldsBuilder(asList("id", "name")); + + SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(null).search(sqlRequest); + assertEquals(searchResponse.getPagination().getCount(), 4); + assertEquals(searchResponse.getPagination().getSkipCount(), 5); + assertTrue(searchResponse.getPagination().isHasMoreItems()); + assertEquals(searchResponse.getEntries().size(), 4); + } + +} diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchDocumentsV1CmisTest.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchDocumentsV1CmisTest.java index 38cd3cc6ec..10039cfcbc 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchDocumentsV1CmisTest.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchDocumentsV1CmisTest.java @@ -38,6 +38,7 @@ import org.alfresco.rest.core.search.SearchRequestBuilder; import org.alfresco.rest.rm.community.base.BaseRMRestTest; import org.alfresco.rest.search.RestRequestQueryModel; import org.alfresco.rest.search.SearchResponse; +import org.alfresco.utility.Utility; import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FileType; import org.alfresco.utility.model.SiteModel; @@ -45,7 +46,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; /** - * This class contains the tests for v1 Search API with CMIS query + * This class contains the tests for v1 Search API with documents with CMIS query * * @author Rodica Sutu * @since 2.6.0.2 @@ -57,7 +58,7 @@ public class SearchDocumentsV1CmisTest extends BaseRMRestTest private FileModel fileModel; private RestRequestQueryModel queryModel; /** - * Create a collaboration site and some in place records. + * Create a collaboration site and some documents. */ @BeforeClass (alwaysRun = true) public void setupSearchAPIWithCMIS() throws Exception @@ -74,16 +75,27 @@ public class SearchDocumentsV1CmisTest extends BaseRMRestTest queryModel = new RestRequestQueryModel(); queryModel.setQuery("select * from cmis:document WHERE cmis:name LIKE '%" + SEARCH_TERM + ".txt'"); queryModel.setLanguage("cmis"); + + //do a cmis query to wait for solr indexing + Utility.sleep(5000, 80000, () -> + { + SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) + .setPagingBuilder(new SearchRequestBuilder().setPagination(100, 0)) + .setFieldsBuilder(asList("id", "name")); + SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(null).search(sqlRequest); + assertEquals(searchResponse.getPagination().getTotalItems().intValue(), 10, + "Total number of items is not 10, got " + searchResponse.getPagination().getTotalItems() + " total items"); + }); } /** * Given some documents ending with a particular text - * When executing the search query with paging + * When executing the search query with paging * And setting the skipCount and maxItems to reach the number of total items * Then hasMoreItems will be set to false */ @Test - private void searchWhenMaxItemReach () throws Exception + public void searchWhenMaxItemReach () throws Exception { final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) @@ -99,12 +111,12 @@ public class SearchDocumentsV1CmisTest extends BaseRMRestTest /** * Given some documents ending with a particular text - * When executing the search query with paging + * When executing the search query with paging * And setting skipCount and maxItems to exceed the number of total items * Then hasMoreItems will be set to false */ @Test - private void searchWhenTotalItemsExceed () throws Exception + public void searchWhenTotalItemsExceed () throws Exception { final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) @@ -120,12 +132,12 @@ public class SearchDocumentsV1CmisTest extends BaseRMRestTest /** * Given some documents ending with a particular text - * When executing the search query with paging + * When executing the search query with paging * And setting skipCount and maxItems under the number of total items - * Then hasMoreItems will be set to false + * Then hasMoreItems will be set to true */ @Test - private void searchResultsUnderTotalItems() throws Exception + public void searchResultsUnderTotalItems() throws Exception { final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)