From 4df615671bb2f34eff5f2f3c7ed5ca6b4de036f2 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Tue, 3 Oct 2017 12:10:31 +0300 Subject: [PATCH 1/4] adding tests for Prevent Classified Items Being Moved/Copied/Linked into Folders with Lower Classification --- .../rm-automation-community-rest-api/pom.xml | 2 +- .../rest/rm/community/model/common/Owner.java | 4 +- .../rm/community/model/record/Record.java | 26 +++++++++++- .../java/org/alfresco/rest/v0/RecordsAPI.java | 29 +++++++++++++ .../rm/community/base/BaseRMRestTest.java | 41 +++++++++++++++++-- 5 files changed, 96 insertions(+), 6 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/pom.xml b/rm-automation/rm-automation-community-rest-api/pom.xml index 0fc4781ef4..a3a94a7b55 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-9 + 5.2.0-10 2.0.0 diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/common/Owner.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/common/Owner.java index db8973d980..76a80f6ed6 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/common/Owner.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/common/Owner.java @@ -26,11 +26,12 @@ */ package org.alfresco.rest.rm.community.model.common; -import org.alfresco.utility.model.TestModel; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import lombok.Builder; import lombok.Data; import lombok.EqualsAndHashCode; +import org.alfresco.utility.model.TestModel; /** * POJO for owner parameter @@ -43,6 +44,7 @@ import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = true) //@NoArgsConstructor //@AllArgsConstructor +@JsonIgnoreProperties (ignoreUnknown = true) public class Owner extends TestModel { diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/record/Record.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/record/Record.java index 6ebd2bf33a..e3468e86a4 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/record/Record.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/record/Record.java @@ -30,7 +30,10 @@ import java.util.List; import com.fasterxml.jackson.annotation.JsonProperty; +import org.alfresco.rest.core.IRestModel; +import org.alfresco.rest.core.assertion.ModelAssertion; import org.alfresco.rest.model.RestByUserModel; +import org.alfresco.rest.model.RestNodeModel; import org.alfresco.rest.rm.community.model.common.Path; import org.alfresco.utility.model.TestModel; @@ -51,7 +54,7 @@ import lombok.NoArgsConstructor; @EqualsAndHashCode(callSuper = true) @NoArgsConstructor @AllArgsConstructor -public class Record extends TestModel +public class Record extends TestModel implements IRestModel { /*************************/ /** Mandatory parameters */ @@ -100,4 +103,25 @@ public class Record extends TestModel @JsonProperty private Path path; + + @Override + public ModelAssertion assertThat() + { + return new ModelAssertion(this); + } + + @Override + public ModelAssertion and() + { + return assertThat(); + } + + @JsonProperty (value = "entry") + RestNodeModel model; + + @Override + public RestNodeModel onModel() + { + return model; + } } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordsAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordsAPI.java index 4c68f65eef..2888a70adf 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordsAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RecordsAPI.java @@ -114,6 +114,35 @@ public class RecordsAPI extends BaseAPI } + /** + * Reject the record given as parameter + * + * @param user the user declaring the document as record + * @param password the user's password + * @param recordName the record name + * @param reason reject reason + * @return true if the action completed successfully + */ + public boolean rejectRecord(String user, String password, String recordName, String reason) + { + String recNodeRef = getNodeRefSpacesStore() + contentService.getNodeRef(user, password, RM_SITE_ID, recordName); + + try + { + JSONObject requestParams = new JSONObject(); + requestParams.put("name", "reject"); + requestParams.put("nodeRef", recNodeRef); + requestParams.put("params",new JSONObject() + .put("reason",reason)); + + return doPostJsonRequest(user, password, requestParams, RM_ACTIONS_API); + } + catch (JSONException error) + { + LOGGER.error("Unable to extract response parameter", error); + } + return false; + } /** * Declare document version as record * 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 124df6907a..43178fdb4d 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 @@ -27,7 +27,6 @@ package org.alfresco.rest.rm.community.base; import static lombok.AccessLevel.PROTECTED; - import static org.alfresco.rest.rm.community.base.TestData.ELECTRONIC_RECORD_NAME; import static org.alfresco.rest.rm.community.base.TestData.RECORD_CATEGORY_TITLE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; @@ -39,8 +38,6 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_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.UserRoles.ROLE_RM_USER; import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createRecordCategoryChildModel; import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createRecordCategoryModel; import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createTempFile; @@ -54,10 +51,12 @@ import static org.testng.Assert.assertTrue; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import org.alfresco.dataprep.ContentService; import org.alfresco.rest.RestTest; import org.alfresco.rest.core.RestAPIFactory; +import org.alfresco.rest.model.RestNodeModel; import org.alfresco.rest.rm.community.model.fileplan.FilePlan; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType; import org.alfresco.rest.rm.community.model.record.Record; @@ -77,6 +76,7 @@ import org.alfresco.rest.search.SearchNodeModel; import org.alfresco.rest.search.SearchRequest; import org.alfresco.rest.v0.RMRolesAndActionsAPI; import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.ContentModel; import org.alfresco.utility.model.FolderModel; import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.UserModel; @@ -615,4 +615,39 @@ public class BaseRMRestTest extends RestTest } return names; } + + /** + * Helper method to return site document library content model + * + * @return ContentModel + * @throws Exception + */ + public ContentModel getDocumentLibrary(UserModel usermodel, SiteModel testSite) throws Exception + { + ContentModel siteModel = new ContentModel(); + siteModel.setNodeRef(testSite.getGuid()); + + restClient.authenticateUser(usermodel); + + List nodes = restClient.withCoreAPI().usingNode(siteModel) + .listChildren().getEntries().stream().collect(Collectors.toList()); + ContentModel documentLibrary = new ContentModel(); + documentLibrary.setName(nodes.get(0).onModel().getName()); + documentLibrary.setNodeRef(nodes.get(0).onModel().getId()); + return documentLibrary; + } + + /** + * Helper method to create a Content Model + * + * @return ContentModel + * @throws Exception + */ + public ContentModel toContentModel(String nodeId) + { + ContentModel node = new ContentModel(); + node.setNodeRef(nodeId); + return node; + } + } From c814258e80ea0e0fd44d06217ad979b111a60f9a Mon Sep 17 00:00:00 2001 From: Ramona Popa Date: Tue, 3 Oct 2017 12:13:16 +0300 Subject: [PATCH 2/4] RM-5647 - added java api functionality and some integration tests --- .../org_alfresco_module_rm/test/util/BaseRMTestCase.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java index d29d38c9dc..8d19bc0f33 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java @@ -70,6 +70,8 @@ import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.repository.ContentService; +import org.alfresco.service.cmr.repository.CopyService; +import org.alfresco.service.cmr.repository.DocumentLinkService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.StoreRef; @@ -147,6 +149,8 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase protected ActionService actionService; protected OwnableService ownableService; protected VersionService versionService; + protected CopyService copyService; + protected DocumentLinkService documentLinkService; /** RM Services */ protected DispositionService dispositionService; @@ -388,6 +392,8 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase actionService = (ActionService)applicationContext.getBean("ActionService"); ownableService = (OwnableService)applicationContext.getBean("OwnableService"); versionService = (VersionService)applicationContext.getBean("VersionService"); + copyService = (CopyService)applicationContext.getBean("CopyService"); + documentLinkService = (DocumentLinkService)applicationContext.getBean("DocumentLinkService"); // Get RM services dispositionService = (DispositionService)applicationContext.getBean("DispositionService"); From 61cc5fec91ed8e2039528dedb0aa33556503d339 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Tue, 3 Oct 2017 15:13:57 +0300 Subject: [PATCH 3/4] minor test refactoring --- .../rest/rm/community/utils/CoreUtil.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/CoreUtil.java diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/CoreUtil.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/CoreUtil.java new file mode 100644 index 0000000000..a67c6aa26d --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/CoreUtil.java @@ -0,0 +1,56 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2017 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.utils; + +import org.alfresco.rest.model.RestNodeBodyMoveCopyModel; + +/** + * Utility class for core components models + * + * @author Rodica Sutu + * @since 2.6 + */ +public class CoreUtil +{ + private CoreUtil() + { + // Intentionally blank + } + + /** + * Creates a body model for move/copy with the given the target node id + * + * @param nodeId The node id + * @return The {@link RestNodeBodyMoveCopyModel} with for the given node id + */ + public static RestNodeBodyMoveCopyModel createBodyForMoveCopy(String nodeId) + { + RestNodeBodyMoveCopyModel moveDestinationInfo = new RestNodeBodyMoveCopyModel(); + moveDestinationInfo.setTargetParentId(nodeId); + return moveDestinationInfo; + } +} From da7551dcf2e6cd84e5659a14cd8b80df5b0e9aae Mon Sep 17 00:00:00 2001 From: Ramona Popa Date: Tue, 3 Oct 2017 17:21:34 +0300 Subject: [PATCH 4/4] RM-5647 - one more integration test + some fix & refactor --- .../org_alfresco_module_rm/test/util/BaseRMTestCase.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java index 8d19bc0f33..166e87aaf3 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java @@ -70,7 +70,6 @@ import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.repository.ContentService; -import org.alfresco.service.cmr.repository.CopyService; import org.alfresco.service.cmr.repository.DocumentLinkService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; @@ -149,7 +148,6 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase protected ActionService actionService; protected OwnableService ownableService; protected VersionService versionService; - protected CopyService copyService; protected DocumentLinkService documentLinkService; /** RM Services */ @@ -392,7 +390,6 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase actionService = (ActionService)applicationContext.getBean("ActionService"); ownableService = (OwnableService)applicationContext.getBean("OwnableService"); versionService = (VersionService)applicationContext.getBean("VersionService"); - copyService = (CopyService)applicationContext.getBean("CopyService"); documentLinkService = (DocumentLinkService)applicationContext.getBean("DocumentLinkService"); // Get RM services