From 9f095aea8c4472df9ada9c066ad9d38d6c776102 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Fri, 3 May 2019 15:54:08 +0300 Subject: [PATCH] remove some of the method duplicated and change the action service class into a component --- .../alfresco/rest/core/RestAPIFactory.java | 11 ++ .../community/requests/gscore/GSCoreAPI.java | 11 ++ .../gscore/api/ActionsExecutionAPI.java} | 46 +++--- .../alfresco/rest/v0/service/RoleService.java | 82 +++++++++++ .../rm/community/base/BaseRMRestTest.java | 136 +++++++++++------- .../DeclareAndFileDocumentAsRecordTests.java | 110 ++------------ .../community/records/DeleteRecordTests.java | 6 +- .../community/records/UpdateRecordsTests.java | 7 +- 8 files changed, 235 insertions(+), 174 deletions(-) rename rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/{core/service/ActionsService.java => rm/community/requests/gscore/api/ActionsExecutionAPI.java} (58%) 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 05e5c3db21..ac0a6025cc 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 @@ -34,6 +34,7 @@ import org.alfresco.rest.requests.Node; import org.alfresco.rest.requests.coreAPI.RestCoreAPI; import org.alfresco.rest.requests.search.SearchAPI; import org.alfresco.rest.rm.community.requests.gscore.GSCoreAPI; +import org.alfresco.rest.rm.community.requests.gscore.api.ActionsExecutionAPI; import org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI; import org.alfresco.rest.rm.community.requests.gscore.api.FilesAPI; import org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI; @@ -225,4 +226,14 @@ public class RestAPIFactory { return getGSCoreAPI(userModel).usingUnfiledRecordFolder(); } + + public ActionsExecutionAPI getActionsAPI(UserModel userModel) + { + return getGSCoreAPI(userModel).usingActionsExecutionsAPI(); + } + + public ActionsExecutionAPI getActionsAPI() + { + return getGSCoreAPI(null).usingActionsExecutionsAPI(); + } } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/GSCoreAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/GSCoreAPI.java index febd2b5427..f0e2e241ed 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/GSCoreAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/GSCoreAPI.java @@ -33,6 +33,7 @@ import com.jayway.restassured.RestAssured; import org.alfresco.rest.core.RMRestProperties; import org.alfresco.rest.core.RMRestWrapper; +import org.alfresco.rest.rm.community.requests.gscore.api.ActionsExecutionAPI; import org.alfresco.rest.rm.community.requests.RMModelRequest; import org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI; import org.alfresco.rest.rm.community.requests.gscore.api.FilesAPI; @@ -179,4 +180,14 @@ public class GSCoreAPI extends RMModelRequest { return new RMUserAPI(getRmRestWrapper()); } + + /** + * Provides DSL for ActionExecution API + * + * @return {@link ActionsExecutionAPI} + */ + public ActionsExecutionAPI usingActionsExecutionsAPI() + { + return new ActionsExecutionAPI(restWrapper); + } } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/service/ActionsService.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/ActionsExecutionAPI.java similarity index 58% rename from rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/service/ActionsService.java rename to rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/ActionsExecutionAPI.java index 03a54d5c24..d6e2475624 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/service/ActionsService.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/ActionsExecutionAPI.java @@ -24,18 +24,16 @@ * along with Alfresco. If not, see . * #L% */ -package org.alfresco.rest.core.service; +package org.alfresco.rest.rm.community.requests.gscore.api; import com.google.common.collect.ImmutableMap; -import org.alfresco.rest.core.RMRestWrapper; -import org.alfresco.rest.core.RestAPIFactory; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.requests.ModelRequest; import org.alfresco.rest.rm.community.model.rules.ActionsOnRule; import org.alfresco.utility.model.RepoTestModel; -import org.alfresco.utility.model.UserModel; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Service; +import org.json.JSONObject; +import org.springframework.stereotype.Component; /** * Produces processed results from Core Actions API calls @@ -43,43 +41,43 @@ import org.springframework.stereotype.Service; * @author Claudia Agache * @since 3.1 */ -@Service -public class ActionsService +@Component +public class ActionsExecutionAPI extends ModelRequest { - @Autowired - private RestAPIFactory restAPIFactory; + + /** + * @param rmRestWrapper + */ + public ActionsExecutionAPI(RestWrapper rmRestWrapper) + { + super(rmRestWrapper); + } + /** * Declares and files a document as record to a record folder using v1 actions api * - * @param userModel user who executes the action * @param targetNode the node on which the action is executed * @param destinationPath the path to the record folder * @throws Exception */ - public void declareAndFile(UserModel userModel, RepoTestModel targetNode, String destinationPath) throws Exception + public JSONObject declareAndFile(RepoTestModel targetNode, String destinationPath) throws Exception { - RMRestWrapper rmRestWrapper = restAPIFactory.getRmRestWrapper(); - rmRestWrapper.getRestWrapper() - .authenticateUser(userModel).withCoreAPI().usingActions() + return restWrapper.withCoreAPI().usingActions() .executeAction(ActionsOnRule.DECLARE_AS_RECORD.getActionValue(), targetNode, ImmutableMap.of("path", destinationPath)); - rmRestWrapper.assertStatusCodeIs(HttpStatus.ACCEPTED); + } /** * Declares a document as record using v1 actions api * - * @param userModel user who executes the action * @param targetNode the node on which the action is executed * @throws Exception */ - public void declareAsRecord(UserModel userModel, RepoTestModel targetNode) throws Exception + public JSONObject declareAsRecord(RepoTestModel targetNode) throws Exception { - RMRestWrapper rmRestWrapper = restAPIFactory.getRmRestWrapper(); - rmRestWrapper.getRestWrapper() - .authenticateUser(userModel).withCoreAPI().usingActions() - .executeAction(ActionsOnRule.DECLARE_AS_RECORD.getActionValue(), targetNode); - rmRestWrapper.assertStatusCodeIs(HttpStatus.ACCEPTED); + return restWrapper.withCoreAPI().usingActions() + .executeAction(ActionsOnRule.DECLARE_AS_RECORD.getActionValue(), targetNode); } } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/service/RoleService.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/service/RoleService.java index ccf2785cd8..d126fb92a0 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/service/RoleService.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/service/RoleService.java @@ -26,12 +26,22 @@ */ package org.alfresco.rest.v0.service; +import static lombok.AccessLevel.PROTECTED; +import static org.springframework.http.HttpStatus.OK; + import java.util.HashSet; import java.util.Set; +import lombok.Getter; +import org.alfresco.rest.core.RestAPIFactory; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; +import org.alfresco.rest.rm.community.model.user.UserPermissions; import org.alfresco.rest.rm.community.model.user.UserRoles; import org.alfresco.rest.v0.RMRolesAndActionsAPI; +import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.UserModel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -50,6 +60,10 @@ public class RoleService @Autowired private DataUser dataUser; + @Autowired + @Getter (value = PROTECTED) + private RestAPIFactory restAPIFactory; + /** * Add capabilities to a role * @@ -81,4 +95,72 @@ public class RoleService rmRolesAndActionsAPI.updateRole(dataUser.getAdminUser().getUsername(), dataUser.getAdminUser().getPassword(), role.roleId, role.displayName, roleCapabilities); } + + /** + * Assign permission on a record category and give the user RM role + * + * @param user the user to assign rm role and permissions + * @param categoryId the id of the category to assign permissions for + * @param userPermission the permissions to be assigned to the user + * @param userRole the rm role to be assigned to the user + */ + public void assignUserPermissionsOnCategoryAndRMRole(UserModel user, String categoryId, UserPermissions userPermission, + String userRole) + { + getRestAPIFactory().getRMUserAPI().addUserPermission(categoryId, user, userPermission); + rmRolesAndActionsAPI.assignRoleToUser(dataUser.getAdminUser().getUsername(), dataUser.getAdminUser().getPassword(), + user.getUsername(), userRole); + } + + /** + * Helper method to create a test user with rm role + * + * @param userRole the rm role + * @return the created user model + */ + public UserModel createUserWithRMRole(String userRole) + { + UserModel rmUser = dataUser.createRandomTestUser(); + getRestAPIFactory().getRMUserAPI().assignRoleToUser(rmUser.getUsername(), userRole); + getRestAPIFactory().getRmRestWrapper().assertStatusCodeIs(OK); + return rmUser; + } + + /** + * Helper method to create a test user with rm role and permissions over the record category + * + * @param userRole the rm role + * @param userPermission the permissions over the record category + * @param recordCategory the category on which user has permissions + * @return the created user model + */ + public UserModel createUserWithRMRoleAndCategoryPermission(String userRole, RecordCategory recordCategory, + UserPermissions userPermission) + { + UserModel rmUser = createUserWithRMRole(userRole); + getRestAPIFactory().getRMUserAPI().addUserPermission(recordCategory.getId(), rmUser, userPermission); + getRestAPIFactory().getRmRestWrapper().assertStatusCodeIs(OK); + return rmUser; + } + + /** + * Helper method to create a test user with rm role and permissions over the recordCategory and collaborator role + * in collaboration site + * + * @param siteModel collaboration site + * @param recordCategory the category on which permission should be given + * @param userRole the rm role + * @param userPermission the permissions over the recordCategory + * @return the created user model + * @throws Exception + */ + public UserModel createCollaboratorWithRMRoleAndPermission(SiteModel siteModel, RecordCategory recordCategory, + UserRoles userRole, UserPermissions userPermission) + { + UserModel rmUser = createUserWithRMRoleAndCategoryPermission(userRole.roleId, recordCategory, + userPermission); + dataUser.addUserToSite(rmUser, siteModel, UserRole.SiteCollaborator); + return rmUser; + } + } diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java index ff69f85d1a..64f244019c 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java @@ -52,6 +52,7 @@ import static org.testng.Assert.assertTrue; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import lombok.Getter; @@ -65,12 +66,13 @@ import org.alfresco.rest.rm.community.model.record.Record; import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild; import org.alfresco.rest.rm.community.model.recordfolder.RecordFolder; +import org.alfresco.rest.rm.community.model.recordfolder.RecordFolderEntry; import org.alfresco.rest.rm.community.model.recordfolder.RecordFolderProperties; import org.alfresco.rest.rm.community.model.site.RMSite; import org.alfresco.rest.rm.community.model.transfercontainer.TransferContainer; import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer; import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild; -import org.alfresco.rest.rm.community.model.user.UserPermissions; +import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildEntry; import org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI; import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI; import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI; @@ -80,8 +82,10 @@ import org.alfresco.rest.search.SearchNodeModel; import org.alfresco.rest.search.SearchRequest; import org.alfresco.rest.v0.RMRolesAndActionsAPI; import org.alfresco.rest.v0.SearchAPI; +import org.alfresco.utility.Utility; import org.alfresco.utility.data.DataUser; import org.alfresco.utility.model.ContentModel; +import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FolderModel; import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.UserModel; @@ -614,53 +618,6 @@ public class BaseRMRestTest extends RestTest recordCategoryAPI.deleteRecordCategory(recordCategoryId); } - /** - * Assign permission on a record category and give the user RM role - * - * @param user the user to assign rm role and permissions - * @param categoryId the id of the category to assign permissions for - * @param userPermission the permissions to be assigned to the user - * @param userRole the rm role to be assigned to the user - */ - public void assignUserPermissionsOnCategoryAndRMRole(UserModel user, String categoryId, UserPermissions userPermission, - String userRole) - { - getRestAPIFactory().getRMUserAPI().addUserPermission(categoryId, user, userPermission); - rmRolesAndActionsAPI.assignRoleToUser(getAdminUser().getUsername(), getAdminUser().getPassword(), - user.getUsername(), userRole); - } - - /** - * Helper method to create a test user with rm role - * - * @param userRole the rm role - * @return the created user model - */ - protected UserModel createUserWithRMRole(String userRole) - { - UserModel rmUser = getDataUser().createRandomTestUser(); - getRestAPIFactory().getRMUserAPI().assignRoleToUser(rmUser.getUsername(), userRole); - assertStatusCode(OK); - return rmUser; - } - - /** - * Helper method to create a test user with rm role and permissions over the record category - * - * @param userRole the rm role - * @param userPermission the permissions over the record category - * @param recordCategory the category on which user has permissions - * @return the created user model - */ - protected UserModel createUserWithRMRoleAndCategoryPermission(String userRole, RecordCategory recordCategory, - UserPermissions userPermission) - { - UserModel rmUser = createUserWithRMRole(userRole); - getRestAPIFactory().getRMUserAPI().addUserPermission(recordCategory.getId(), rmUser, userPermission); - assertStatusCode(OK); - return rmUser; - } - /** * Returns search results for the given search term * @@ -825,4 +782,87 @@ public class BaseRMRestTest extends RestTest documentLibrary.setNodeRef(nodes.get(0).onModel().getId()); return documentLibrary; } + + /** + * Checks if the given file has record aspect + * + * @param testFile the file to be checked + * @return true if the file has the aspect, false otherwise + */ + protected boolean hasRecordAspect(FileModel testFile) throws Exception + { + return hasAspect(testFile,RECORD_TYPE); + } + + /** + * Checks if the given file has the given aspect + * + * @param testFile the file to be checked + * @param aspectName the matching aspect + * @return true if the file has the aspect, false otherwise + */ + private boolean hasAspect(FileModel testFile, String aspectName) throws Exception + { + return getRestAPIFactory().getNodeAPI(testFile).getNode() + .getAspectNames().contains(aspectName); + } + + /** + * Helper method to verify if the declared record is in Unfiled Records location + * + * @param testFile the file declared as record + * @return true if the matching record is found in Unfiled Records, false otherwise + */ + protected boolean isMatchingRecordInUnfiledRecords(FileModel testFile) + { + try + { + Utility.sleep(5000, 15000, + () -> { + Optional matchingRecord = getRestAPIFactory().getUnfiledContainersAPI() + .getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS) + .getEntries() + .stream() + .filter(e -> e.getEntry().getId() + .equals(testFile.getNodeRefWithoutVersion())) + .findAny(); + assertTrue(matchingRecord.isPresent()); + }); + return true; + } + catch (AssertionError | Exception e) + { + return false; + } + } + + /** + * Helper method to verify if the declared record is filed to the record folder location + * + * @param testFile the file declared as record + * @param recFolder the record folder where the declared record has been filed + * @return true if matching record is found in record folder, null otherwise + */ + protected boolean isMatchingRecordInRecordFolder(FileModel testFile, RecordCategoryChild recFolder) + { + try + { + Utility.sleep(5000, 15000, + () -> { + Optional matchingRecord = getRestAPIFactory().getRecordFolderAPI() + .getRecordFolderChildren(recFolder.getId()) + .getEntries() + .stream() + .filter(e -> e.getEntry().getId() + .equals(testFile.getNodeRefWithoutVersion())) + .findAny(); + assertTrue(matchingRecord.isPresent()); + }); + return true; + } + catch (AssertionError | Exception e) + { + return false; + } + } } diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/DeclareAndFileDocumentAsRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/DeclareAndFileDocumentAsRecordTests.java index c4d0634eeb..da36124ada 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/DeclareAndFileDocumentAsRecordTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/DeclareAndFileDocumentAsRecordTests.java @@ -27,7 +27,6 @@ package org.alfresco.rest.rm.community.files; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS; -import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE; import static org.alfresco.rest.rm.community.model.user.UserPermissions.PERMISSION_FILING; import static org.alfresco.rest.rm.community.model.user.UserPermissions.PERMISSION_READ_RECORDS; @@ -36,6 +35,7 @@ import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_USER; import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; import static org.alfresco.utility.data.RandomData.getRandomName; import static org.alfresco.utility.report.log.Step.STEP; +import static org.springframework.http.HttpStatus.ACCEPTED; import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.FORBIDDEN; import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY; @@ -44,20 +44,15 @@ import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; import java.util.List; -import java.util.Optional; import org.alfresco.dataprep.CMISUtil; -import org.alfresco.rest.core.service.ActionsService; import org.alfresco.rest.rm.community.base.BaseRMRestTest; import org.alfresco.rest.rm.community.model.record.Record; import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild; -import org.alfresco.rest.rm.community.model.recordfolder.RecordFolderEntry; import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild; -import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildEntry; -import org.alfresco.rest.rm.community.model.user.UserPermissions; -import org.alfresco.rest.rm.community.model.user.UserRoles; import org.alfresco.rest.rm.community.util.DockerHelper; +import org.alfresco.rest.v0.service.RoleService; import org.alfresco.test.AlfrescoTest; import org.alfresco.utility.Utility; import org.alfresco.utility.constants.UserRole; @@ -90,11 +85,12 @@ public class DeclareAndFileDocumentAsRecordTests extends BaseRMRestTest private RecordCategoryChild recordFolder, subcategoryRecordFolder, subCategory; private UnfiledContainerChild unfiledContainerFolder; - @Autowired - private ActionsService actionsService; @Autowired private DockerHelper dockerHelper; + @Autowired + private RoleService roleService; + /** * Invalid containers where in-place records can't be filed */ @@ -136,8 +132,8 @@ public class DeclareAndFileDocumentAsRecordTests extends BaseRMRestTest subcategoryRecordFolder = createFolder(subCategory.getId(), getRandomName("recordFolder")); STEP("Create rm users with different permissions on the record category"); - userFillingPermission = createCollaboratorWithRMRoleAndPermission(ROLE_RM_POWER_USER, PERMISSION_FILING); - userReadOnlyPermission = createCollaboratorWithRMRoleAndPermission(ROLE_RM_USER, PERMISSION_READ_RECORDS); + userFillingPermission = roleService.createCollaboratorWithRMRoleAndPermission(publicSite, recordCategory, ROLE_RM_POWER_USER, PERMISSION_FILING); + userReadOnlyPermission = roleService.createCollaboratorWithRMRoleAndPermission(publicSite, recordCategory,ROLE_RM_USER, PERMISSION_READ_RECORDS); } /** @@ -156,7 +152,7 @@ public class DeclareAndFileDocumentAsRecordTests extends BaseRMRestTest .createContent(CMISUtil.DocumentType.TEXT_PLAIN); STEP("Declare document as record without providing a location parameter value using v1 actions api"); - actionsService.declareAsRecord(userReadOnlyPermission, testFile); + getRestAPIFactory().getActionsAPI(userReadOnlyPermission).declareAsRecord(testFile); STEP("Verify the declared record is placed in the Unfiled Records folder"); assertTrue(isMatchingRecordInUnfiledRecords(testFile), "Record should be filed to Unfiled Records folder"); @@ -181,7 +177,7 @@ public class DeclareAndFileDocumentAsRecordTests extends BaseRMRestTest .createContent(CMISUtil.DocumentType.TEXT_PLAIN); STEP("Declare document as record with a location parameter value"); - actionsService.declareAndFile(userFillingPermission, testFile, + getRestAPIFactory().getActionsAPI(userFillingPermission).declareAndFile(testFile, Utility.buildPath(recordCategory.getName(), recordFolder.getName())); STEP("Verify the declared record is placed in the record folder"); @@ -207,7 +203,8 @@ public class DeclareAndFileDocumentAsRecordTests extends BaseRMRestTest .createContent(CMISUtil.DocumentType.TEXT_PLAIN); STEP("Declare document as record with an invalid location parameter value"); - actionsService.declareAndFile(getAdminUser(), testFile, containerPath); + getRestAPIFactory().getActionsAPI().declareAndFile(testFile, containerPath); + assertStatusCode(ACCEPTED); STEP("Check the exception thrown in alfresco logs"); //Retry the operation because sometimes it takes few seconds to throw the exception @@ -327,92 +324,7 @@ public class DeclareAndFileDocumentAsRecordTests extends BaseRMRestTest "Record should not be filed to subcategoryRecordFolder"); } - /** - * Helper method to verify if the declared record is in Unfiled Records location - * - * @param testFile the file declared as record - * @return true if the matching record is found in Unfiled Records, false otherwise - */ - private boolean isMatchingRecordInUnfiledRecords(FileModel testFile) - { - try - { - Utility.sleep(5000, 15000, - () -> { - Optional matchingRecord = getRestAPIFactory().getUnfiledContainersAPI() - .getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS) - .getEntries() - .stream() - .filter(e -> e.getEntry().getId() - .equals(testFile.getNodeRefWithoutVersion())) - .findAny(); - assertTrue(matchingRecord.isPresent()); - }); - return true; - } - catch (AssertionError | Exception e) - { - return false; - } - } - /** - * Helper method to verify if the declared record is filed to the record folder location - * - * @param testFile the file declared as record - * @param recFolder the record folder where the declared record has been filed - * @return true if matching record is found in record folder, null otherwise - */ - private boolean isMatchingRecordInRecordFolder(FileModel testFile, RecordCategoryChild recFolder) - { - try - { - Utility.sleep(5000, 15000, - () -> { - Optional matchingRecord = getRestAPIFactory().getRecordFolderAPI() - .getRecordFolderChildren(recFolder.getId()) - .getEntries() - .stream() - .filter(e -> e.getEntry().getId() - .equals(testFile.getNodeRefWithoutVersion())) - .findAny(); - assertTrue(matchingRecord.isPresent()); - }); - return true; - } - catch (AssertionError | Exception e) - { - return false; - } - } - - /** - * Helper method to create a test user with rm role and permissions over the recordCategory and collaborator role - * in collaboration site - * - * @param userRole the rm role - * @param userPermission the permissions over the recordCategory - * @return the created user model - * @throws Exception - */ - private UserModel createCollaboratorWithRMRoleAndPermission(UserRoles userRole, UserPermissions userPermission) - { - UserModel rmUser = createUserWithRMRoleAndCategoryPermission(userRole.roleId, recordCategory, userPermission); - getDataUser().addUserToSite(rmUser, publicSite, UserRole.SiteCollaborator); - return rmUser; - } - - /** - * Checks if the given file has record aspect - * - * @param testFile the file to be checked - * @return true if the file has the aspect, false otherwise - */ - private boolean hasRecordAspect(FileModel testFile) throws Exception - { - return getRestAPIFactory().getNodeAPI(testFile).getNode() - .getAspectNames().contains(RECORD_TYPE); - } @AfterClass(alwaysRun = true) public void declareAndFileDocumentAsRecordCleanup() diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/DeleteRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/DeleteRecordTests.java index 387e263460..bc88c6a6d6 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/DeleteRecordTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/DeleteRecordTests.java @@ -49,7 +49,6 @@ import static org.springframework.http.HttpStatus.NO_CONTENT; import static org.springframework.http.HttpStatus.OK; import org.alfresco.dataprep.CMISUtil; -import org.alfresco.rest.core.JsonBodyGenerator; import org.alfresco.rest.core.RestResponse; import org.alfresco.rest.core.v0.BaseAPI.RM_ACTIONS; import org.alfresco.rest.model.RestNodeBodyMoveCopyModel; @@ -66,6 +65,7 @@ import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI; import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI; import org.alfresco.rest.v0.RMRolesAndActionsAPI; import org.alfresco.rest.v0.service.DispositionScheduleService; +import org.alfresco.rest.v0.service.RoleService; import org.alfresco.test.AlfrescoTest; import org.alfresco.utility.data.RandomData; import org.alfresco.utility.model.FileModel; @@ -90,6 +90,8 @@ public class DeleteRecordTests extends BaseRMRestTest private RMRolesAndActionsAPI rmRolesAndActionsAPI; @Autowired private org.alfresco.rest.v0.RecordsAPI recordsAPI; + @Autowired + private RoleService roleService; /** *
@@ -237,7 +239,7 @@ public class DeleteRecordTests extends BaseRMRestTest
     {
         // Create test user and add it with collaboration privileges
         // Add RM role to user, RM Power User doesn't have the "Delete Record" capabilities
-        UserModel deleteUser = createUserWithRMRole(ROLE_RM_POWER_USER.roleId);
+        UserModel deleteUser = roleService.createUserWithRMRole(ROLE_RM_POWER_USER.roleId);
         getDataUser().addUserToSite(deleteUser, new SiteModel(getRestAPIFactory().getRMSiteAPI().getSite().getId()), SiteCollaborator);
         String username = deleteUser.getUsername();
         logger.info("Test user: " + username);
diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/UpdateRecordsTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/UpdateRecordsTests.java
index c433c99dc6..35c2eee056 100644
--- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/UpdateRecordsTests.java
+++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/UpdateRecordsTests.java
@@ -66,10 +66,12 @@ import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
 import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI;
 import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI;
 import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledRecordFolderAPI;
+import org.alfresco.rest.v0.service.RoleService;
 import org.alfresco.test.AlfrescoTest;
 import org.alfresco.utility.constants.UserRole;
 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.DataProvider;
 import org.testng.annotations.Test;
@@ -87,6 +89,9 @@ public class UpdateRecordsTests extends BaseRMRestTest
     /* to be used to append to modifications */
     private final String MODIFIED_PREFIX = "modified_";
 
+    @Autowired
+    private RoleService roleService;
+
     /** Incomplete electronic and non electronic records created in one record folder, unfiled records container and one unfiled record folder */
     @DataProvider(name = "incompleteRecords")
     public Object[][] getIncompleteRecords() throws Exception
@@ -236,7 +241,7 @@ public class UpdateRecordsTests extends BaseRMRestTest
         RMUserAPI rmUserAPI = getRestAPIFactory().getRMUserAPI();
         // Create test user and add it with collab. privileges.
         // RM Security Officer is the lowest role with Edit Record Metadata capabilities
-        UserModel updateUser = createUserWithRMRole(ROLE_RM_SECURITY_OFFICER.roleId);
+        UserModel updateUser = roleService.createUserWithRMRole(ROLE_RM_SECURITY_OFFICER.roleId);
         updateUser.setUserRole(UserRole.SiteCollaborator);
         getDataUser().addUserToSite(updateUser, new SiteModel(getRestAPIFactory().getRMSiteAPI().getSite().getId()), UserRole.SiteCollaborator);