From b687127d57764c3ca5775662b89c3f932dc64d0b Mon Sep 17 00:00:00 2001 From: rodicasutu Date: Wed, 1 Apr 2020 08:59:06 +0300 Subject: [PATCH 1/7] wip CMIS tests for MNT-20822 --- .../rm-automation-community-rest-api/pom.xml | 8 +- .../alfresco/rest/core/RestAPIFactory.java | 8 +- .../src/main/resources/config.properties | 3 +- .../rest/rm/community/search/CMISTests.java | 68 ++++++ .../search/SearchDocumentsV1CmisTest.java | 142 ++++++++++++ .../search/SearchRecordsV1CmisTests.java | 209 ++++++++++++++++++ 6 files changed, 434 insertions(+), 4 deletions(-) create mode 100644 rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/CMISTests.java create mode 100644 rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchDocumentsV1CmisTest.java create mode 100644 rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchRecordsV1CmisTests.java diff --git a/rm-automation/rm-automation-community-rest-api/pom.xml b/rm-automation/rm-automation-community-rest-api/pom.xml index 68715e4554..66ad5026d9 100644 --- a/rm-automation/rm-automation-community-rest-api/pom.xml +++ b/rm-automation/rm-automation-community-rest-api/pom.xml @@ -15,7 +15,7 @@ 1.8 alfresco-rm-community-share alfresco-rm-community-repo - 5.2.0-10 + 5.2.0.15 2.0.0 @@ -73,5 +73,11 @@ alfresco-testng 1.1 + + org.alfresco.tas + restapi-test + ${tas.restapi.version} + compile + diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java index d88cab3a43..36a2ffe628 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java @@ -86,11 +86,15 @@ public class RestAPIFactory return getRmRestWrapper().withCoreAPI(); } - private SearchAPI getSearchAPI(UserModel userModel) + public SearchAPI getSearchAPI(UserModel userModel) { getRmRestWrapper().authenticateUser(userModel != null ? userModel : getDataUser().getAdminUser()); return getRmRestWrapper().withSearchAPI(); - } + } + public SearchAPI getSearchAPI() + { + return getSearchAPI(null); + } public Node getNodeAPI(RepoTestModel model) throws RuntimeException { diff --git a/rm-automation/rm-automation-community-rest-api/src/main/resources/config.properties b/rm-automation/rm-automation-community-rest-api/src/main/resources/config.properties index 8b94951ea5..727a2d00e7 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/resources/config.properties +++ b/rm-automation/rm-automation-community-rest-api/src/main/resources/config.properties @@ -1,2 +1,3 @@ alfresco.server=localhost -rest.rmPath=alfresco/api/-default-/public/gs/versions/1 \ No newline at end of file +rest.rmPath=alfresco/api/-default-/public/gs/versions/1 +alfresco.port=8080 \ No newline at end of file diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/CMISTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/CMISTests.java new file mode 100644 index 0000000000..6b612b3523 --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/CMISTests.java @@ -0,0 +1,68 @@ +/* + * #%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 org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertTrue; + +import org.alfresco.dataprep.ContentActions; +import org.alfresco.rest.rm.community.base.BaseRMRestTest; +import org.alfresco.test.AlfrescoTest; +import org.apache.chemistry.opencmis.client.api.ItemIterable; +import org.apache.chemistry.opencmis.client.api.QueryResult; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.Test; + +public class CMISTests extends BaseRMRestTest +{ + @Autowired + private ContentActions contentActions; + + /** + *
+     * Given the RM site created
+     * When I execute cmis query
+     * Then I get the correct response
+     * 
+ */ + @Test + @AlfrescoTest (jira="MNT-19442") + public void executeCmisQuery() + { + // execute the cmis query + String cql = "SELECT cmis:name FROM cmis:document"; + ItemIterable results = + contentActions.getCMISSession(getAdminUser().getUsername(), getAdminUser().getPassword()).query(cql, + false); + + // check the total number of items is 100 and has more items is true + assertTrue("Has more items not true. ", results.getHasMoreItems()); + assertTrue("Total number of items is greater than 100 ", results.getTotalNumItems() > 100); + assertEquals("Pagination supports only 100 items per page", results.getPageNumItems(), 100); + } + +} 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 new file mode 100644 index 0000000000..38cd3cc6ec --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchDocumentsV1CmisTest.java @@ -0,0 +1,142 @@ +/* + * #%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.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.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.SiteModel; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * This class contains the tests for v1 Search API with CMIS query + * + * @author Rodica Sutu + * @since 2.6.0.2 + */ +public class SearchDocumentsV1CmisTest extends BaseRMRestTest +{ + private static final String SEARCH_TERM = generateTestPrefix(SearchDocumentsV1CmisTest.class); + private SiteModel collaborationSite; + private FileModel fileModel; + private RestRequestQueryModel queryModel; + /** + * Create a collaboration site and some in place records. + */ + @BeforeClass (alwaysRun = true) + public void setupSearchAPIWithCMIS() throws Exception + { + STEP("Create a collaboration site"); + collaborationSite = dataSite.usingAdmin().createPrivateRandomSite(); + + STEP("Create 10 documents ending with SEARCH_TERM"); + for (int i=0;++i<=10;) + { + fileModel = new FileModel(String.format("%s.%s", "Doc" + i + SEARCH_TERM, FileType.TEXT_PLAIN.extention)); + dataContent.usingAdmin().usingSite(collaborationSite).createContent(fileModel); + } + queryModel = new RestRequestQueryModel(); + queryModel.setQuery("select * from cmis:document WHERE cmis:name LIKE '%" + SEARCH_TERM + ".txt'"); + queryModel.setLanguage("cmis"); + } + + /** + * Given some documents ending with a particular text + * 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 + { + + final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) + .setPagingBuilder(new SearchRequestBuilder().setPagination(5, 5)) + .setFieldsBuilder(asList("id", "name")); + + SearchResponse searchResponse = getRestAPIFactory().getSearchAPI().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 + private 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().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 false + */ + @Test + private 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().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/SearchRecordsV1CmisTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchRecordsV1CmisTests.java new file mode 100644 index 0000000000..673223a54d --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchRecordsV1CmisTests.java @@ -0,0 +1,209 @@ +/* + * #%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.model.user.UserRoles.ROLE_RM_MANAGER; +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.rest.core.search.SearchRequestBuilder; +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.rest.search.RestRequestQueryModel; +import org.alfresco.rest.search.SearchResponse; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.UserModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * This class contains the tests for v1 Search API with records with CMIS query + * + * @author Rodica Sutu + * @since 2.6.0.2 + */ +public class SearchRecordsV1CmisTests extends BaseRMRestTest +{ + private static final String SEARCH_TERM = generateTestPrefix(SearchRecordsV1CmisTests.class); + private SiteModel collaborationSite; + private UserModel nonRMUser, rmUser; + private FileModel fileModel; + private RestRequestQueryModel queryModel; + + + + /** + * Create a collaboration site and some in place records. + */ + @BeforeClass (alwaysRun = true) + public void setupSearchRecordsV1Cmis() throws Exception + { + STEP("Create a collaboration site"); + collaborationSite = dataSite.usingAdmin().createPrivateRandomSite(); + + STEP("Create a collaborator user for the collaboration site"); + nonRMUser = getDataUser().createRandomTestUser(); + getDataUser().addUserToSite(nonRMUser, collaborationSite, UserRole.SiteManager); + + STEP("Create an rm user"); + rmUser = getDataUser().createRandomTestUser(); + + STEP("Create 10 documents and declare as records"); + for (int i=0;++i<=10;) + { + fileModel = new FileModel(String.format("%s.%s", "Record" + SEARCH_TERM + i, FileType.TEXT_PLAIN.extention)); + fileModel = dataContent.usingUser(nonRMUser).usingSite(collaborationSite).createContent(fileModel); + getRestAPIFactory().getFilesAPI(nonRMUser).declareAsRecord(fileModel.getNodeRefWithoutVersion()); + } + STEP("Create record folder and some records "); + RecordCategoryChild recordFolder = createCategoryFolderInFilePlan(); + assignFillingPermissionsOnCategory(rmUser, recordFolder.getId(), UserPermissions.PERMISSION_READ_RECORDS, + ROLE_RM_MANAGER); + for (int i=0;++i<=10;) + { + createElectronicRecord(recordFolder.getId(),"Record" + SEARCH_TERM + i ); + } + + queryModel = new RestRequestQueryModel(); + queryModel.setQuery("select * from cmis:document WHERE cmis:name LIKE 'Record" + SEARCH_TERM + "%'"); + queryModel.setLanguage("cmis"); + } + /** + * Given some documents with names starting with a particular test + * 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 searchWhenTotalItemsReach () throws Exception + { + final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) + .setPagingBuilder(new SearchRequestBuilder().setPagination(5, 15)) + .setFieldsBuilder(asList("id", "name")); + + SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(rmUser).search(sqlRequest); + assertEquals(searchResponse.getPagination().getCount(), 5); + assertEquals(searchResponse.getPagination().getSkipCount(), 15); + assertFalse(searchResponse.getPagination().isHasMoreItems()); + assertEquals(searchResponse.getEntries().size(), 5); + } + + @Test + private void searchWhenTotalItemsReachWithNonRM () throws Exception + { + final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) + .setPagingBuilder(new SearchRequestBuilder().setPagination(5, 5)) + .setFieldsBuilder(asList("id", "name")); + + SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(nonRMUser).search(sqlRequest); + assertEquals(searchResponse.getPagination().getCount(), 5); + assertEquals(searchResponse.getPagination().getSkipCount(), 5); + assertFalse(searchResponse.getPagination().isHasMoreItems()); + assertEquals(searchResponse.getEntries().size(), 5); + } + /** + * Given some documents with names starting 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 + private void searchWhenTotalItemsExceedRMUser () throws Exception + { + + final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) + .setPagingBuilder(new SearchRequestBuilder().setPagination(5, 16)) + .setFieldsBuilder(asList("id", "name")); + + SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(rmUser).search(sqlRequest); + assertEquals(searchResponse.getPagination().getCount(), 4); + assertEquals(searchResponse.getPagination().getSkipCount(), 16); + assertFalse(searchResponse.getPagination().isHasMoreItems()); + assertEquals(searchResponse.getEntries().size(), 4); + } + + @Test + private void searchWhenTotalItemsExceedNonRMUser () throws Exception + { + + final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) + .setPagingBuilder(new SearchRequestBuilder().setPagination(5, 6)) + .setFieldsBuilder(asList("id", "name")); + + SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(nonRMUser).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 false + */ + @Test + private void searchResultsUnderTotalItemsRMUser() throws Exception + { + + final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) + .setPagingBuilder(new SearchRequestBuilder().setPagination(4, 15)) + .setFieldsBuilder(asList("id", "name")); + + SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(rmUser).search(sqlRequest); + assertEquals(searchResponse.getPagination().getCount(), 4); + assertEquals(searchResponse.getPagination().getSkipCount(), 15); + assertTrue(searchResponse.getPagination().isHasMoreItems()); + assertEquals(searchResponse.getEntries().size(), 4); + } + @Test + private void searchResultsUnderTotalItemsNonRMUser() throws Exception + { + + final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) + .setPagingBuilder(new SearchRequestBuilder().setPagination(4, 5)) + .setFieldsBuilder(asList("id", "name")); + + SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(nonRMUser).search(sqlRequest); + assertEquals(searchResponse.getPagination().getCount(), 4); + assertEquals(searchResponse.getPagination().getSkipCount(), 5); + assertTrue(searchResponse.getPagination().isHasMoreItems()); + assertEquals(searchResponse.getEntries().size(), 4); + } +} From 8f5c44d4a6607e8110adb3b23cbb62f02615f768 Mon Sep 17 00:00:00 2001 From: rodicasutu Date: Thu, 2 Apr 2020 08:34:34 +0300 Subject: [PATCH 2/7] add the missing class --- .../core/search/SearchRequestBuilder.java | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/search/SearchRequestBuilder.java diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/search/SearchRequestBuilder.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/search/SearchRequestBuilder.java new file mode 100644 index 0000000000..034977307b --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/search/SearchRequestBuilder.java @@ -0,0 +1,96 @@ +/* + * #%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.core.search; + +import java.util.List; + +import org.alfresco.rest.search.Pagination; +import org.alfresco.rest.search.RestRequestQueryModel; +import org.alfresco.rest.search.SearchRequest; + +/** + * Builder class for creating a search api request + * @author Rodica Sutu + * @since 2.6.0.2 + */ +public class SearchRequestBuilder extends SearchRequest +{ + /** + * Constructor for Search API Request + */ + public SearchRequestBuilder() + { + new SearchRequest(); + } + /** + * Set the sql statement for the SearchRequest + * + * @param query + * @return search request + */ + public SearchRequestBuilder setQueryBuilder(RestRequestQueryModel query) + { + super.setQuery(query); + return this; + } + + /** + * Set the paging statement for the SearchRequest + * + * @param paging + * @return search request + */ + public SearchRequestBuilder setPagingBuilder(Pagination paging) + { + super.setPaging(paging); + return this; + } + + /** + * Set the pagination properties + */ + public Pagination setPagination(Integer maxItems, Integer skipCount) + { + Pagination pagination = new Pagination(); + pagination.setMaxItems(maxItems); + pagination.setSkipCount(skipCount); + return pagination; + } + + /** + * Set the paging statement for the SearchRequest + * + * @param fields + * @return search request + */ + public SearchRequestBuilder setFieldsBuilder(List fields) + { + super.setFields(fields); + return this; + } + +} From f02f4044da93df19a3a5a4ec6b0ca2155171102c Mon Sep 17 00:00:00 2001 From: Roxana Lucanu Date: Mon, 6 Apr 2020 17:10:56 +0300 Subject: [PATCH 3/7] 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) From 3e4ce77328a769df0762c4927828c91f1837e291 Mon Sep 17 00:00:00 2001 From: Roxana Lucanu Date: Tue, 7 Apr 2020 18:27:58 +0300 Subject: [PATCH 4/7] RM-7145 Addressed code review comments --- .../alfresco/rest/core/RestAPIFactory.java | 6 +- .../search/SearchDocumentsV1AftsTest.java | 163 ------------------ ...isTest.java => SearchDocumentsV1Test.java} | 115 ++++++++---- .../search/SearchRecordsV1CmisTests.java | 44 +++-- 4 files changed, 103 insertions(+), 225 deletions(-) delete mode 100644 rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchDocumentsV1AftsTest.java rename rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/{SearchDocumentsV1CmisTest.java => SearchDocumentsV1Test.java} (65%) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java index 36a2ffe628..2cf961590d 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java @@ -85,12 +85,16 @@ public class RestAPIFactory getRmRestWrapper().authenticateUser(userModel != null ? userModel : getDataUser().getAdminUser()); return getRmRestWrapper().withCoreAPI(); } - + public SearchAPI getSearchAPI(UserModel userModel) { getRmRestWrapper().authenticateUser(userModel != null ? userModel : getDataUser().getAdminUser()); return getRmRestWrapper().withSearchAPI(); } + + /** + * When no user is given the default is set to admin + */ public SearchAPI getSearchAPI() { return getSearchAPI(null); 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 deleted file mode 100644 index 23f6faea50..0000000000 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchDocumentsV1AftsTest.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * #%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/SearchDocumentsV1Test.java similarity index 65% rename from rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchDocumentsV1CmisTest.java rename to rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchDocumentsV1Test.java index 10039cfcbc..5570de00a1 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/SearchDocumentsV1Test.java @@ -38,53 +38,83 @@ 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.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.AfterClass; +import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; /** - * This class contains the tests for v1 Search API with documents with CMIS query - * - * @author Rodica Sutu - * @since 2.6.0.2 + * This class contains the tests for v1 Search API with documents with CMIS and AFTS queries */ -public class SearchDocumentsV1CmisTest extends BaseRMRestTest +public class SearchDocumentsV1Test extends BaseRMRestTest { - private static final String SEARCH_TERM = generateTestPrefix(SearchDocumentsV1CmisTest.class); + private static final String SEARCH_TERM = generateTestPrefix(SearchDocumentsV1Test.class); private SiteModel collaborationSite; private FileModel fileModel; - private RestRequestQueryModel queryModel; + + @Autowired + private UserTrashcanAPI userTrashcanAPI; + + /** + * Data Provider with: queries using CMIS and AFTS languages + */ + @DataProvider + public static Object[][] queryTypes() + { + RestRequestQueryModel cmisQueryModel = new RestRequestQueryModel(); + cmisQueryModel.setQuery("select * from cmis:document WHERE cmis:name LIKE '%" + SEARCH_TERM + ".txt'"); + cmisQueryModel.setLanguage("cmis"); + + RestRequestQueryModel aftsQueryModel = new RestRequestQueryModel(); + aftsQueryModel.setQuery("cm:name:*" + SEARCH_TERM); + aftsQueryModel.setLanguage("afts"); + + return new RestRequestQueryModel[][] { + { cmisQueryModel }, + { aftsQueryModel } + }; + } + /** * Create a collaboration site and some documents. */ @BeforeClass (alwaysRun = true) - public void setupSearchAPIWithCMIS() throws Exception + public void beforeClass() throws Exception { STEP("Create a collaboration site"); collaborationSite = dataSite.usingAdmin().createPrivateRandomSite(); STEP("Create 10 documents ending with SEARCH_TERM"); - for (int i=0;++i<=10;) + for (int i = 0; ++i <= 10; ) { fileModel = new FileModel(String.format("%s.%s", "Doc" + i + SEARCH_TERM, FileType.TEXT_PLAIN.extention)); dataContent.usingAdmin().usingSite(collaborationSite).createContent(fileModel); } - 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, () -> + /** + * Do the query to wait for solr indexing + * + * @param queryType the query being executed + * @throws Exception when maximum retry period is reached + */ + private void waitIndexing(RestRequestQueryModel queryType) throws Exception + { + Utility.sleep(1000, 80000, () -> { - SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) + SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryType) .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"); + "Total number of items is not retrieved yet"); }); } @@ -95,18 +125,19 @@ public class SearchDocumentsV1CmisTest extends BaseRMRestTest * Then hasMoreItems will be set to false */ @Test - public void searchWhenMaxItemReach () throws Exception + (dataProvider = "queryTypes") + public void searchWhenMaxItemsReach(RestRequestQueryModel queryType) throws Exception { - - final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) + waitIndexing(queryType); + final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryType) .setPagingBuilder(new SearchRequestBuilder().setPagination(5, 5)) .setFieldsBuilder(asList("id", "name")); SearchResponse searchResponse = getRestAPIFactory().getSearchAPI().search(sqlRequest); - assertEquals(searchResponse.getPagination().getCount(), 5); - assertEquals(searchResponse.getPagination().getSkipCount(), 5); - assertFalse(searchResponse.getPagination().isHasMoreItems()); - assertEquals(searchResponse.getEntries().size(), 5); + assertEquals(searchResponse.getPagination().getCount(), 5, "Expected maxItems to be five"); + assertEquals(searchResponse.getPagination().getSkipCount(), 5, "Expected skip count to be five"); + assertFalse(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be false"); + assertEquals(searchResponse.getEntries().size(), 5, "Expected total entries to be five"); } /** @@ -116,18 +147,19 @@ public class SearchDocumentsV1CmisTest extends BaseRMRestTest * Then hasMoreItems will be set to false */ @Test - public void searchWhenTotalItemsExceed () throws Exception + (dataProvider = "queryTypes") + public void searchWhenTotalItemsExceed(RestRequestQueryModel queryType) throws Exception { - - final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) + waitIndexing(queryType); + final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryType) .setPagingBuilder(new SearchRequestBuilder().setPagination(5, 6)) .setFieldsBuilder(asList("id", "name")); SearchResponse searchResponse = getRestAPIFactory().getSearchAPI().search(sqlRequest); - assertEquals(searchResponse.getPagination().getCount(), 4); - assertEquals(searchResponse.getPagination().getSkipCount(), 6); - assertFalse(searchResponse.getPagination().isHasMoreItems()); - assertEquals(searchResponse.getEntries().size(), 4); + assertEquals(searchResponse.getPagination().getCount(), 4, "Expected maxItems to be four"); + assertEquals(searchResponse.getPagination().getSkipCount(), 6, "Expected skip count to be six"); + assertFalse(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be false"); + assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four"); } /** @@ -137,18 +169,27 @@ public class SearchDocumentsV1CmisTest extends BaseRMRestTest * Then hasMoreItems will be set to true */ @Test - public void searchResultsUnderTotalItems() throws Exception + (dataProvider = "queryTypes") + public void searchResultsUnderTotalItems(RestRequestQueryModel queryType) throws Exception { - - final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) + waitIndexing(queryType); + final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryType) .setPagingBuilder(new SearchRequestBuilder().setPagination(4, 5)) .setFieldsBuilder(asList("id", "name")); SearchResponse searchResponse = getRestAPIFactory().getSearchAPI().search(sqlRequest); - assertEquals(searchResponse.getPagination().getCount(), 4); - assertEquals(searchResponse.getPagination().getSkipCount(), 5); - assertTrue(searchResponse.getPagination().isHasMoreItems()); - assertEquals(searchResponse.getEntries().size(), 4); + assertEquals(searchResponse.getPagination().getCount(), 4, "Expected maxItems to be four"); + assertEquals(searchResponse.getPagination().getSkipCount(), 5, "Expected skip count to be five"); + assertTrue(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be true"); + assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four"); + } + + @AfterTest + @AfterClass (alwaysRun = true) + public void tearDown() + { + dataSite.usingAdmin().deleteSite(collaborationSite); + userTrashcanAPI.emptyTrashcan(getAdminUser().getUsername(), getAdminUser().getPassword()); } } diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchRecordsV1CmisTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchRecordsV1CmisTests.java index 673223a54d..de5f9f23fc 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchRecordsV1CmisTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchRecordsV1CmisTests.java @@ -46,8 +46,6 @@ import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FileType; import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.UserModel; -import org.springframework.beans.factory.annotation.Autowired; -import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -66,7 +64,6 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest private RestRequestQueryModel queryModel; - /** * Create a collaboration site and some in place records. */ @@ -76,7 +73,7 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest STEP("Create a collaboration site"); collaborationSite = dataSite.usingAdmin().createPrivateRandomSite(); - STEP("Create a collaborator user for the collaboration site"); + STEP("Create a site manager user for the collaboration site"); nonRMUser = getDataUser().createRandomTestUser(); getDataUser().addUserToSite(nonRMUser, collaborationSite, UserRole.SiteManager); @@ -84,7 +81,7 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest rmUser = getDataUser().createRandomTestUser(); STEP("Create 10 documents and declare as records"); - for (int i=0;++i<=10;) + for (int i = 0; ++i <= 10; ) { fileModel = new FileModel(String.format("%s.%s", "Record" + SEARCH_TERM + i, FileType.TEXT_PLAIN.extention)); fileModel = dataContent.usingUser(nonRMUser).usingSite(collaborationSite).createContent(fileModel); @@ -93,24 +90,25 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest STEP("Create record folder and some records "); RecordCategoryChild recordFolder = createCategoryFolderInFilePlan(); assignFillingPermissionsOnCategory(rmUser, recordFolder.getId(), UserPermissions.PERMISSION_READ_RECORDS, - ROLE_RM_MANAGER); - for (int i=0;++i<=10;) + ROLE_RM_MANAGER); + for (int i = 0; ++i <= 10; ) { - createElectronicRecord(recordFolder.getId(),"Record" + SEARCH_TERM + i ); + createElectronicRecord(recordFolder.getId(), "Record" + SEARCH_TERM + i); } queryModel = new RestRequestQueryModel(); queryModel.setQuery("select * from cmis:document WHERE cmis:name LIKE 'Record" + SEARCH_TERM + "%'"); queryModel.setLanguage("cmis"); } + /** * Given some documents with names starting with a particular test - * 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 searchWhenTotalItemsReach () throws Exception + public void searchWhenTotalItemsReach() throws Exception { final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) .setPagingBuilder(new SearchRequestBuilder().setPagination(5, 15)) @@ -124,10 +122,10 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest } @Test - private void searchWhenTotalItemsReachWithNonRM () throws Exception + public void searchWhenTotalItemsReachWithNonRM() throws Exception { final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) - .setPagingBuilder(new SearchRequestBuilder().setPagination(5, 5)) + .setPagingBuilder(new SearchRequestBuilder().setPagination(5, 0)) .setFieldsBuilder(asList("id", "name")); SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(nonRMUser).search(sqlRequest); @@ -136,16 +134,16 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest assertFalse(searchResponse.getPagination().isHasMoreItems()); assertEquals(searchResponse.getEntries().size(), 5); } + /** * Given some documents with names starting 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 searchWhenTotalItemsExceedRMUser () throws Exception + public void searchWhenTotalItemsExceedRMUser() throws Exception { - final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) .setPagingBuilder(new SearchRequestBuilder().setPagination(5, 16)) .setFieldsBuilder(asList("id", "name")); @@ -158,9 +156,8 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest } @Test - private void searchWhenTotalItemsExceedNonRMUser () throws Exception + public void searchWhenTotalItemsExceedNonRMUser() throws Exception { - final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) .setPagingBuilder(new SearchRequestBuilder().setPagination(5, 6)) .setFieldsBuilder(asList("id", "name")); @@ -174,14 +171,13 @@ public class SearchRecordsV1CmisTests 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 searchResultsUnderTotalItemsRMUser() throws Exception + public void searchResultsUnderTotalItemsRMUser() throws Exception { - final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) .setPagingBuilder(new SearchRequestBuilder().setPagination(4, 15)) .setFieldsBuilder(asList("id", "name")); @@ -192,10 +188,10 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest assertTrue(searchResponse.getPagination().isHasMoreItems()); assertEquals(searchResponse.getEntries().size(), 4); } - @Test - private void searchResultsUnderTotalItemsNonRMUser() throws Exception - { + @Test + public void searchResultsUnderTotalItemsNonRMUser() throws Exception + { final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel) .setPagingBuilder(new SearchRequestBuilder().setPagination(4, 5)) .setFieldsBuilder(asList("id", "name")); From 021e09acddd2d30921443955df8a1763bb910d64 Mon Sep 17 00:00:00 2001 From: Roxana Lucanu Date: Wed, 8 Apr 2020 13:43:51 +0300 Subject: [PATCH 5/7] RM-7145 Addressed code review comments --- .../rm-automation-community-rest-api/pom.xml | 7 +- .../core/search/SearchRequestBuilder.java | 10 ++- .../rest/rm/community/search/CMISTests.java | 68 ------------------- .../search/SearchDocumentsV1Test.java | 20 +++--- .../search/SearchRecordsV1CmisTests.java | 63 +++++++++-------- 5 files changed, 49 insertions(+), 119 deletions(-) delete mode 100644 rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/CMISTests.java diff --git a/rm-automation/rm-automation-community-rest-api/pom.xml b/rm-automation/rm-automation-community-rest-api/pom.xml index 66ad5026d9..78daea7318 100644 --- a/rm-automation/rm-automation-community-rest-api/pom.xml +++ b/rm-automation/rm-automation-community-rest-api/pom.xml @@ -49,6 +49,7 @@ org.alfresco.tas restapi-test ${tas.restapi.version} + compile org.alfresco.tas @@ -73,11 +74,5 @@ alfresco-testng 1.1 - - org.alfresco.tas - restapi-test - ${tas.restapi.version} - compile - diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/search/SearchRequestBuilder.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/search/SearchRequestBuilder.java index 034977307b..c25b48a81a 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/search/SearchRequestBuilder.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/search/SearchRequestBuilder.java @@ -34,8 +34,6 @@ import org.alfresco.rest.search.SearchRequest; /** * Builder class for creating a search api request - * @author Rodica Sutu - * @since 2.6.0.2 */ public class SearchRequestBuilder extends SearchRequest { @@ -49,7 +47,7 @@ public class SearchRequestBuilder extends SearchRequest /** * Set the sql statement for the SearchRequest * - * @param query + * @param query sql statement * @return search request */ public SearchRequestBuilder setQueryBuilder(RestRequestQueryModel query) @@ -61,7 +59,7 @@ public class SearchRequestBuilder extends SearchRequest /** * Set the paging statement for the SearchRequest * - * @param paging + * @param paging pagination requested * @return search request */ public SearchRequestBuilder setPagingBuilder(Pagination paging) @@ -82,9 +80,9 @@ public class SearchRequestBuilder extends SearchRequest } /** - * Set the paging statement for the SearchRequest + * Set the requested fields for the SearchRequest * - * @param fields + * @param fields requested fields * @return search request */ public SearchRequestBuilder setFieldsBuilder(List fields) diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/CMISTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/CMISTests.java deleted file mode 100644 index 6b612b3523..0000000000 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/CMISTests.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * #%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 org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertTrue; - -import org.alfresco.dataprep.ContentActions; -import org.alfresco.rest.rm.community.base.BaseRMRestTest; -import org.alfresco.test.AlfrescoTest; -import org.apache.chemistry.opencmis.client.api.ItemIterable; -import org.apache.chemistry.opencmis.client.api.QueryResult; -import org.springframework.beans.factory.annotation.Autowired; -import org.testng.annotations.Test; - -public class CMISTests extends BaseRMRestTest -{ - @Autowired - private ContentActions contentActions; - - /** - *
-     * Given the RM site created
-     * When I execute cmis query
-     * Then I get the correct response
-     * 
- */ - @Test - @AlfrescoTest (jira="MNT-19442") - public void executeCmisQuery() - { - // execute the cmis query - String cql = "SELECT cmis:name FROM cmis:document"; - ItemIterable results = - contentActions.getCMISSession(getAdminUser().getUsername(), getAdminUser().getPassword()).query(cql, - false); - - // check the total number of items is 100 and has more items is true - assertTrue("Has more items not true. ", results.getHasMoreItems()); - assertTrue("Total number of items is greater than 100 ", results.getTotalNumItems() > 100); - assertEquals("Pagination supports only 100 items per page", results.getPageNumItems(), 100); - } - -} diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchDocumentsV1Test.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchDocumentsV1Test.java index 5570de00a1..69b503dada 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchDocumentsV1Test.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchDocumentsV1Test.java @@ -97,16 +97,19 @@ public class SearchDocumentsV1Test extends BaseRMRestTest fileModel = new FileModel(String.format("%s.%s", "Doc" + i + SEARCH_TERM, FileType.TEXT_PLAIN.extention)); dataContent.usingAdmin().usingSite(collaborationSite).createContent(fileModel); } + waitIndexing(); } /** * Do the query to wait for solr indexing * - * @param queryType the query being executed * @throws Exception when maximum retry period is reached */ - private void waitIndexing(RestRequestQueryModel queryType) throws Exception + private void waitIndexing() throws Exception { + RestRequestQueryModel queryType = new RestRequestQueryModel(); + queryType.setQuery("cm:name:*" + SEARCH_TERM); + queryType.setLanguage("afts"); Utility.sleep(1000, 80000, () -> { SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryType) @@ -124,11 +127,9 @@ public class SearchDocumentsV1Test extends BaseRMRestTest * And setting the skipCount and maxItems to reach the number of total items * Then hasMoreItems will be set to false */ - @Test - (dataProvider = "queryTypes") + @Test(dataProvider = "queryTypes") public void searchWhenMaxItemsReach(RestRequestQueryModel queryType) throws Exception { - waitIndexing(queryType); final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryType) .setPagingBuilder(new SearchRequestBuilder().setPagination(5, 5)) .setFieldsBuilder(asList("id", "name")); @@ -146,11 +147,9 @@ public class SearchDocumentsV1Test extends BaseRMRestTest * And setting skipCount and maxItems to exceed the number of total items * Then hasMoreItems will be set to false */ - @Test - (dataProvider = "queryTypes") + @Test(dataProvider = "queryTypes") public void searchWhenTotalItemsExceed(RestRequestQueryModel queryType) throws Exception { - waitIndexing(queryType); final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryType) .setPagingBuilder(new SearchRequestBuilder().setPagination(5, 6)) .setFieldsBuilder(asList("id", "name")); @@ -168,11 +167,9 @@ public class SearchDocumentsV1Test extends BaseRMRestTest * And setting skipCount and maxItems under the number of total items * Then hasMoreItems will be set to true */ - @Test - (dataProvider = "queryTypes") + @Test(dataProvider = "queryTypes") public void searchResultsUnderTotalItems(RestRequestQueryModel queryType) throws Exception { - waitIndexing(queryType); final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryType) .setPagingBuilder(new SearchRequestBuilder().setPagination(4, 5)) .setFieldsBuilder(asList("id", "name")); @@ -184,7 +181,6 @@ public class SearchDocumentsV1Test extends BaseRMRestTest assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four"); } - @AfterTest @AfterClass (alwaysRun = true) public void tearDown() { diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchRecordsV1CmisTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchRecordsV1CmisTests.java index de5f9f23fc..050a634a53 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchRecordsV1CmisTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchRecordsV1CmisTests.java @@ -41,19 +41,19 @@ import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild; import org.alfresco.rest.rm.community.model.user.UserPermissions; import org.alfresco.rest.search.RestRequestQueryModel; import org.alfresco.rest.search.SearchResponse; +import org.alfresco.rest.v0.UserTrashcanAPI; import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FileType; import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.UserModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; /** * This class contains the tests for v1 Search API with records with CMIS query - * - * @author Rodica Sutu - * @since 2.6.0.2 */ public class SearchRecordsV1CmisTests extends BaseRMRestTest { @@ -63,6 +63,8 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest private FileModel fileModel; private RestRequestQueryModel queryModel; + @Autowired + private UserTrashcanAPI userTrashcanAPI; /** * Create a collaboration site and some in place records. @@ -115,10 +117,10 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest .setFieldsBuilder(asList("id", "name")); SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(rmUser).search(sqlRequest); - assertEquals(searchResponse.getPagination().getCount(), 5); - assertEquals(searchResponse.getPagination().getSkipCount(), 15); - assertFalse(searchResponse.getPagination().isHasMoreItems()); - assertEquals(searchResponse.getEntries().size(), 5); + assertEquals(searchResponse.getPagination().getCount(), 5, "Expected maxItems to be five"); + assertEquals(searchResponse.getPagination().getSkipCount(), 15, "Expected skip count to be fifteen"); + assertFalse(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be false"); + assertEquals(searchResponse.getEntries().size(), 5, "Expected total entries to be five"); } @Test @@ -129,10 +131,10 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest .setFieldsBuilder(asList("id", "name")); SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(nonRMUser).search(sqlRequest); - assertEquals(searchResponse.getPagination().getCount(), 5); - assertEquals(searchResponse.getPagination().getSkipCount(), 5); - assertFalse(searchResponse.getPagination().isHasMoreItems()); - assertEquals(searchResponse.getEntries().size(), 5); + assertEquals(searchResponse.getPagination().getCount(), 5, "Expected maxItems to be five"); + assertEquals(searchResponse.getPagination().getSkipCount(), 5, "Expected skip count to be five"); + assertFalse(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be false"); + assertEquals(searchResponse.getEntries().size(), 5, "Expected total entries to be five"); } /** @@ -149,10 +151,10 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest .setFieldsBuilder(asList("id", "name")); SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(rmUser).search(sqlRequest); - assertEquals(searchResponse.getPagination().getCount(), 4); - assertEquals(searchResponse.getPagination().getSkipCount(), 16); - assertFalse(searchResponse.getPagination().isHasMoreItems()); - assertEquals(searchResponse.getEntries().size(), 4); + assertEquals(searchResponse.getPagination().getCount(), 4, "Expected maxItems to be four"); + assertEquals(searchResponse.getPagination().getSkipCount(), 16, "Expected skip count to be sixteen"); + assertFalse(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be false"); + assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four"); } @Test @@ -163,10 +165,10 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest .setFieldsBuilder(asList("id", "name")); SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(nonRMUser).search(sqlRequest); - assertEquals(searchResponse.getPagination().getCount(), 4); - assertEquals(searchResponse.getPagination().getSkipCount(), 6); - assertFalse(searchResponse.getPagination().isHasMoreItems()); - assertEquals(searchResponse.getEntries().size(), 4); + assertEquals(searchResponse.getPagination().getCount(), 4, "Expected maxItems to be four"); + assertEquals(searchResponse.getPagination().getSkipCount(), 6, "Expected skip count to be six"); + assertFalse(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be false"); + assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four"); } /** @@ -183,10 +185,10 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest .setFieldsBuilder(asList("id", "name")); SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(rmUser).search(sqlRequest); - assertEquals(searchResponse.getPagination().getCount(), 4); - assertEquals(searchResponse.getPagination().getSkipCount(), 15); - assertTrue(searchResponse.getPagination().isHasMoreItems()); - assertEquals(searchResponse.getEntries().size(), 4); + assertEquals(searchResponse.getPagination().getCount(), 4, "Expected maxItems to be four"); + assertEquals(searchResponse.getPagination().getSkipCount(), 15, "Expected skip count to be fifteen"); + assertTrue(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be true"); + assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four"); } @Test @@ -197,9 +199,16 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest .setFieldsBuilder(asList("id", "name")); SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(nonRMUser).search(sqlRequest); - assertEquals(searchResponse.getPagination().getCount(), 4); - assertEquals(searchResponse.getPagination().getSkipCount(), 5); - assertTrue(searchResponse.getPagination().isHasMoreItems()); - assertEquals(searchResponse.getEntries().size(), 4); + assertEquals(searchResponse.getPagination().getCount(), 4, "Expected maxItems to be four"); + assertEquals(searchResponse.getPagination().getSkipCount(), 5, "Expected skip count to be five"); + assertTrue(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be true"); + assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four"); + } + + @AfterClass (alwaysRun = true) + public void tearDown() + { + dataSite.usingAdmin().deleteSite(collaborationSite); + userTrashcanAPI.emptyTrashcan(getAdminUser().getUsername(), getAdminUser().getPassword()); } } From fce0793fd2de1e15a0c945d75e6a5ce3f4a63b80 Mon Sep 17 00:00:00 2001 From: Roxana Lucanu Date: Wed, 8 Apr 2020 14:32:22 +0300 Subject: [PATCH 6/7] RM-7145 Code review changes --- rm-automation/rm-automation-community-rest-api/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/rm-automation/rm-automation-community-rest-api/pom.xml b/rm-automation/rm-automation-community-rest-api/pom.xml index 78daea7318..58d62900da 100644 --- a/rm-automation/rm-automation-community-rest-api/pom.xml +++ b/rm-automation/rm-automation-community-rest-api/pom.xml @@ -49,7 +49,6 @@ org.alfresco.tas restapi-test ${tas.restapi.version} - compile org.alfresco.tas From 64ddf0657bec9544d5c1410d15ea0d00bff20dd0 Mon Sep 17 00:00:00 2001 From: Claudia Agache Date: Wed, 8 Apr 2020 19:07:33 +0300 Subject: [PATCH 7/7] fix the parameter --- .../rest/rm/community/search/SearchRecordsV1CmisTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchRecordsV1CmisTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchRecordsV1CmisTests.java index 050a634a53..323908fac5 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchRecordsV1CmisTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchRecordsV1CmisTests.java @@ -92,7 +92,7 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest STEP("Create record folder and some records "); RecordCategoryChild recordFolder = createCategoryFolderInFilePlan(); assignFillingPermissionsOnCategory(rmUser, recordFolder.getId(), UserPermissions.PERMISSION_READ_RECORDS, - ROLE_RM_MANAGER); + ROLE_RM_MANAGER.roleId); for (int i = 0; ++i <= 10; ) { createElectronicRecord(recordFolder.getId(), "Record" + SEARCH_TERM + i);