From 36f5c7659961fb12a4ab7bfa2fa9d4abc909fecd Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Tue, 20 Aug 2019 08:50:58 +0300 Subject: [PATCH 1/5] Tests for Add and Remove active content to/from hold using exiting API's --- .../org/alfresco/rest/core/v0/BaseAPI.java | 2 +- .../rm/community/model/hold/HoldEntry.java | 56 +++ .../UnfiledContainerProperties.java | 2 + .../java/org/alfresco/rest/v0/HoldsAPI.java | 323 ++++++++++++++++ .../rest/v0/RMRolesAndActionsAPI.java | 76 ---- .../alfresco/rest/v0/service/RoleService.java | 40 +- .../rest/rm/community/base/TestData.java | 15 + .../DeclareAndFileDocumentAsRecordTests.java | 14 +- .../hold/AddContentToHoldsTests.java | 355 ++++++++++++++++++ .../PreventActionsOnFrozenContentTests.java | 188 ++++++++++ .../hold/RemoveContentFromHoldsTests.java | 284 ++++++++++++++ .../testdata/SampleTextFile_10kb.txt | 27 ++ 12 files changed, 1296 insertions(+), 86 deletions(-) create mode 100644 rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/hold/HoldEntry.java create mode 100644 rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/HoldsAPI.java create mode 100644 rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/AddContentToHoldsTests.java create mode 100644 rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/PreventActionsOnFrozenContentTests.java create mode 100644 rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/RemoveContentFromHoldsTests.java create mode 100644 rm-automation/rm-automation-community-rest-api/src/test/resources/shared-resources/testdata/SampleTextFile_10kb.txt diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java index 7438ee5ed6..d1b5d5f907 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java @@ -81,7 +81,7 @@ public abstract class BaseAPI protected static final String UPDATE_METADATA_API = "{0}node/{1}/formprocessor"; protected static final String ACTIONS_API = "{0}actionQueue"; protected static final String RM_ACTIONS_API = "{0}rma/actions/ExecutionQueue"; - protected static final String RM_SITE_ID = "rm"; + public static final String RM_SITE_ID = "rm"; protected static final String SHARE_ACTION_API = "{0}internal/shared/share/workspace/SpacesStore/{1}"; private static final String SLINGSHOT_PREFIX = "alfresco/s/slingshot/"; diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/hold/HoldEntry.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/hold/HoldEntry.java new file mode 100644 index 0000000000..728c877cf6 --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/hold/HoldEntry.java @@ -0,0 +1,56 @@ +/*- + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2019 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.model.hold; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.alfresco.utility.model.TestModel; + +/** + * POJO for hold entry + * + * @author Rodica Sutu + * @since 3.2 + */ +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +@JsonIgnoreProperties (ignoreUnknown = true) +public class HoldEntry extends TestModel +{ + @JsonProperty (required = true) + private String name; + + @JsonProperty (required = true) + private String nodeRef; +} diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/unfiledcontainer/UnfiledContainerProperties.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/unfiledcontainer/UnfiledContainerProperties.java index 8953d511e6..e4edfa36f3 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/unfiledcontainer/UnfiledContainerProperties.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/unfiledcontainer/UnfiledContainerProperties.java @@ -29,6 +29,7 @@ package org.alfresco.rest.rm.community.model.unfiledcontainer; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_IDENTIFIER; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_ROOT_NODE_REF; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import org.alfresco.utility.model.TestModel; @@ -50,6 +51,7 @@ import lombok.NoArgsConstructor; @EqualsAndHashCode(callSuper = true) @NoArgsConstructor @AllArgsConstructor +@JsonIgnoreProperties (ignoreUnknown = true) public class UnfiledContainerProperties extends TestModel { /*************************/ diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/HoldsAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/HoldsAPI.java new file mode 100644 index 0000000000..0906158c1e --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/HoldsAPI.java @@ -0,0 +1,323 @@ +/*- + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2019 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.v0; + +import static org.apache.http.HttpStatus.SC_OK; +import static org.testng.AssertJUnit.assertNotNull; + +import javax.json.Json; +import javax.json.JsonReader; +import java.io.IOException; +import java.io.InputStream; +import java.text.MessageFormat; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.alfresco.rest.core.v0.BaseAPI; +import org.alfresco.rest.rm.community.model.hold.HoldEntry; +import org.alfresco.rest.rm.community.util.PojoUtility; +import org.alfresco.utility.Utility; +import org.apache.chemistry.opencmis.client.api.CmisObject; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.ParseException; +import org.apache.http.util.EntityUtils; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.springframework.stereotype.Component; + +/** + * Methods to make API requests using v0 API for generalized holds + * + * @author Rodica Sutu + * @since 3.2 + */ +@Component +public class HoldsAPI extends BaseAPI +{ + public static final String HOLDS_CONTAINER = "Holds"; + private static final String CREATE_HOLDS_API = "{0}type/rma:hold/formprocessor"; + + /** The URI to add items to hold.*/ + private static final String RM_HOLDS_API = "{0}rma/holds"; + private static final String GET_RM_HOLDS = RM_HOLDS_API + "?{1}"; + + /** + * Util method to create a hold + * + * @param user the user creating the category + * @param password the user's password + * @param holdName the hold name + * @param reason hold reason + * @param description hold description + * @return The HTTP response (or null if no POST call was needed). + */ + public HttpResponse createHold(String user, String password, + String holdName, String reason, String description) + { + // if the hold already exists don't try to create it again + final String fullHoldPath = Utility.buildPath(getFilePlanPath(), HOLDS_CONTAINER) + holdName; + final CmisObject hold = getObjectByPath(user, password, fullHoldPath); + if (hold != null) + { + return null; + } + // retrieve the Holds container nodeRef + final String parentNodeRef = getItemNodeRef(user, password, "/" + HOLDS_CONTAINER); + + final JSONObject requestParams = new JSONObject(); + requestParams.put("alf_destination", getNodeRefSpacesStore() + parentNodeRef); + requestParams.put("prop_cm_name", holdName); + requestParams.put("prop_cm_description", description); + requestParams.put("prop_rma_holdReason", reason); + + // Make the POST request and throw an assertion error if it fails. + final HttpResponse httpResponse = doPostJsonRequest(user, password, SC_OK, requestParams, CREATE_HOLDS_API); + assertNotNull("Expected object to have been created at " + fullHoldPath, + getObjectByPath(user, password, fullHoldPath)); + return httpResponse; + } + + /** + * Create a hold and get the node ref of the hold from the response body + * + * @param user + * @param password + * @param holdName + * @param reason + * @param description + * @return node ref of the hold created + */ + + public String createHoldAndGetNodeRef(String user, String password, + String holdName, String reason, String description) + { + final HttpResponse httpResponse = createHold(user, password, holdName, reason, description); + + try + { + return new JSONObject(EntityUtils.toString(httpResponse.getEntity())) + .getString("persistedObject") + .replaceAll(NODE_REF_WORKSPACE_SPACES_STORE, ""); + } + catch(JSONException error) + { + LOGGER.error("Converting message body to JSON failed. Body: {}", httpResponse, error); + } + catch(ParseException | IOException error) + { + LOGGER.error("Parsing message body failed.", error); + } + + return null; + } + + + + /** + * Deletes hold + * + * @param username user's username + * @param password its password + * @param holdName the hold name + * @throws AssertionError if the deletion was unsuccessful. + */ + public void deleteHold( String username, String password, String holdName) + { + deleteItem(username, password, String.format("/%s/%s", HOLDS_CONTAINER, holdName)); + } + + /** + * Adds item (active content /record/ record folder) to the hold + * + * @param user the user who adds the item to the hold + * @param password the user's password + * @param itemNodeRef the nodeRef of the item to be added to hold + * @param holdName the hold name + * @return The HTTP response + */ + public HttpResponse addItemToHold(String user, String password, String itemNodeRef, String holdName) + { + return addItemToHold(user, password, SC_OK, itemNodeRef, holdName); + } + + /** + * Adds item (record/ record folder) to the hold + * + * @param user the user who adds the item to the hold + * @param password the user's password + * @param itemNodeRef the nodeRef of the item to be added to hold + * @param holdName the hold name + * @return The HTTP response + */ + public HttpResponse addItemToHold(String user, String password, int expectedStatus, String itemNodeRef, String + holdName) + { + final JSONObject requestParams = createHoldJsonObject(user, password, itemNodeRef, holdName); + return doPostJsonRequest(user, password, expectedStatus, requestParams, RM_HOLDS_API); + } + + /** + * Util method to add item (active content /record/ record folder) to the hold and gets the error message + * + * @param user the user who adds the item to the hold + * @param password the user's password + * @param itemNodeRef the nodeRef of the item to be added to hold + * @param holdName the hold name + * @return The error message + */ + public String addToHoldAndGetMessage(String user, String password, int expectedStatus, String itemNodeRef, String + holdName) + { + final HttpResponse httpResponse = addItemToHold(user, password, expectedStatus, itemNodeRef, holdName); + return extractErrorMessageFromHttpResponse(httpResponse); + } + + /** + * Util method to create the request body for adding an item to hold + * @param user + * @param password + * @param itemNodeRef + * @param holdName + * @return JSONObject fo + */ + private JSONObject createHoldJsonObject(String user, String password, String itemNodeRef, String holdName) + { + + final JSONArray nodeRefs = new JSONArray().put(getNodeRefSpacesStore() + itemNodeRef); + final List holdNames = Arrays.asList(holdName.split(",")); + final List holdNoderefs = holdNames.stream().map(hold -> + + getNodeRefSpacesStore() + getItemNodeRef(user, password, String.format("/%s/%s", HOLDS_CONTAINER, hold))) + .collect(Collectors.toList()); + final JSONArray holds = new JSONArray(); + holdNoderefs.forEach(holds::put); + final JSONObject requestParams = new JSONObject(); + requestParams.put("nodeRefs", nodeRefs); + requestParams.put("holds", holds); + return requestParams; + } + + /** + * Remove item (active content /record/ record folder) from the hold + * + * @param user the user who adds the item to the hold + * @param password the user's password + * @param itemNodeRef the nodeRef of the item to be added to hold + * @param holdName the hold name + * @return The HTTP response + */ + public HttpResponse removeItemFromHold(String user, String password, String itemNodeRef, String holdName) + { + return removeItemFromHold(user, password, SC_OK, itemNodeRef, holdName); + } + + /** + * Adds item (record/ record folder) to the hold + * + * @param user the user who adds the item to the hold + * @param password the user's password + * @param itemNodeRef the nodeRef of the item to be added to hold + * @param holdName the hold name + * @return The HTTP response + */ + public HttpResponse removeItemFromHold(String user, String password, int expectedStatus, String itemNodeRef, String + holdName) + { + final JSONObject requestParams = createHoldJsonObject(user, password, itemNodeRef, holdName); + return doPutJsonRequest(user, password, expectedStatus, requestParams, RM_HOLDS_API); + } + + /** + * Util method to add item (active content /record/ record folder) to the hold and gets the error message + * + * @param user the user who adds the item to the hold + * @param password the user's password + * @param itemNodeRef the nodeRef of the item to be added to hold + * @param holdName the hold name + * @return The error message + */ + public String removeFromHoldAndGetMessage(String user, String password, int expectedStatus, String itemNodeRef, String + holdName) + { + final HttpResponse httpResponse = removeItemFromHold(user, password, expectedStatus, itemNodeRef, holdName); + return extractErrorMessageFromHttpResponse(httpResponse); + } + + /** + * Util method to extract the message string from the HTTP response + * @param httpResponse + * @return + */ + private String extractErrorMessageFromHttpResponse(HttpResponse httpResponse) + { + final HttpEntity entity = httpResponse.getEntity(); + + try(InputStream responseStream = entity.getContent(); JsonReader reader = Json.createReader(responseStream)) + { + return reader.readObject().getString("message"); + } + catch (JSONException error) + { + LOGGER.error("Converting message body to JSON failed. Body: {}", httpResponse, error); + } + catch (ParseException | IOException error) + { + LOGGER.error("Parsing message body failed.", error); + } + + return null; + } + + /** + * Get the list of the available holds which have the item node reference if includedInHold parameter is true + * otherwise a list of hold node references will be retrieved which do not include the given node reference. + * + * @param user The username of the user to use. + * @param password The password of the user. + * @param itemNodeRef + * @param includedInHold + * @param fileOnly + * @return return + */ + public List getHolds(String user, String password, final String itemNodeRef, + final Boolean includedInHold, final Boolean fileOnly) + { + final String parameters = (itemNodeRef != null ? "itemNodeRef=" + NODE_REF_WORKSPACE_SPACES_STORE + itemNodeRef : "") + + (includedInHold != null ? "&includedInHold=" + includedInHold : "") + + (fileOnly != null ? "&fileOnly=" + fileOnly : ""); + + final JSONArray holdEntries = doGetRequest(user, password, + MessageFormat.format(GET_RM_HOLDS, "{0}", parameters)).getJSONObject("data").getJSONArray("holds"); + + return PojoUtility.jsonToObject(holdEntries, HoldEntry.class); + } + + +} diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java index c7fe73ccba..0a0993bd22 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java @@ -31,7 +31,6 @@ import static org.alfresco.rest.core.v0.APIUtils.ISO_INSTANT_FORMATTER; import static org.apache.http.HttpStatus.SC_OK; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertFalse; -import static org.testng.AssertJUnit.assertNotNull; import static org.testng.AssertJUnit.assertTrue; import static org.testng.AssertJUnit.fail; @@ -48,7 +47,6 @@ import org.alfresco.dataprep.AlfrescoHttpClientFactory; import org.alfresco.dataprep.UserService; import org.alfresco.rest.core.v0.BaseAPI; import org.alfresco.rest.core.v0.RMEvents; -import org.alfresco.utility.Utility; import org.apache.chemistry.opencmis.client.api.CmisObject; import org.apache.commons.httpclient.HttpStatus; import org.apache.http.HttpResponse; @@ -74,8 +72,6 @@ import org.springframework.stereotype.Component; @Component public class RMRolesAndActionsAPI extends BaseAPI { - public static final String HOLDS_CONTAINER = "Holds"; - /** The URI to view the configured roles and capabilities. */ private static final String RM_ROLES = "{0}rma/admin/rmroles"; /** The URI for REST requests about a particular configured role. */ @@ -85,9 +81,6 @@ public class RMRolesAndActionsAPI extends BaseAPI // logger private static final Logger LOGGER = LoggerFactory.getLogger(RMRolesAndActionsAPI.class); private static final String MOVE_ACTIONS_API = "action/rm-move-to/site/rm/documentLibrary/{0}"; - private static final String CREATE_HOLDS_API = "{0}type/rma:hold/formprocessor"; - /** The URI to add items to hold.*/ - private static final String RM_HOLDS_API = "{0}rma/holds"; /** http client factory */ @Autowired @@ -439,75 +432,6 @@ public class RMRolesAndActionsAPI extends BaseAPI contentService.getFolderObject(contentService.getCMISSession(username, password), siteId, containerName).getChildren().getHasMoreItems()); } - /** - * Deletes hold - * - * @param username user's username - * @param password its password - * @param holdName the hold name - * @throws AssertionError if the deletion was unsuccessful. - */ - public void deleteHold(String username, String password, String holdName) - { - deleteItem(username, password, String.format("/%s/%s", HOLDS_CONTAINER, holdName)); - } - - /** - * Util method to create a hold - * - * @param user the user creating the category - * @param password the user's password - * @param holdName the hold name - * @param reason hold reason - * @param description hold description - * @return The HTTP response (or null if no POST call was needed). - */ - public HttpResponse createHold(String user, String password, String holdName, String reason, String description) - { - // if the hold already exists don't try to create it again - final String fullHoldPath = Utility.buildPath(getFilePlanPath(), HOLDS_CONTAINER) + holdName; - final CmisObject hold = getObjectByPath(user, password, fullHoldPath); - if (hold != null) - { - return null; - } - // retrieve the Holds container nodeRef - final String parentNodeRef = getItemNodeRef(user, password, "/" + HOLDS_CONTAINER); - - final JSONObject requestParams = new JSONObject(); - requestParams.put("alf_destination", getNodeRefSpacesStore() + parentNodeRef); - requestParams.put("prop_cm_name", holdName); - requestParams.put("prop_cm_description", description); - requestParams.put("prop_rma_holdReason", reason); - - // Make the POST request and throw an assertion error if it fails. - final HttpResponse httpResponse = doPostJsonRequest(user, password, SC_OK, requestParams, CREATE_HOLDS_API); - assertNotNull("Expected object to have been created at " + fullHoldPath, - getObjectByPath(user, password, fullHoldPath)); - return httpResponse; - } - - /** - * Adds item (record/ record folder) to the hold - * - * @param user the user who adds the item to the hold - * @param password the user's password - * @param itemNodeRef the nodeRef of the item to be added to hold - * @param holdName the hold name - * @return The HTTP response - */ - public HttpResponse addItemToHold(String user, String password, String itemNodeRef, String holdName) - { - final JSONArray nodeRefs = new JSONArray().put(getNodeRefSpacesStore() + itemNodeRef); - final String holdNodeRef = getItemNodeRef(user, password, String.format("/%s/%s", HOLDS_CONTAINER, holdName)); - final JSONArray holds = new JSONArray().put(getNodeRefSpacesStore() + holdNodeRef); - final JSONObject requestParams = new JSONObject(); - requestParams.put("nodeRefs", nodeRefs); - requestParams.put("holds", holds); - - return doPostJsonRequest(user, password, SC_OK, requestParams, RM_HOLDS_API); - } - /** * Updates metadata, can be used on records, folders and categories * 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 c37dcc8541..a94719df3d 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 @@ -147,13 +147,26 @@ public class RoleService */ public UserModel createUserWithRMRoleAndCategoryPermission(String userRole, RecordCategory recordCategory, UserPermissions userPermission) + { + return createUserWithRMRoleAndRMNodePermission(userRole, recordCategory.getId(),userPermission); + } + + /** + * Helper method to create a test user with rm role and permissions on the node ref + * + * @param userRole the rm role + * @param userPermission the permissions over the record category + * @param componentId the component id to grant rm permission + * @return the created user model + */ + public UserModel createUserWithRMRoleAndRMNodePermission(String userRole, String componentId, + UserPermissions userPermission) { final UserModel rmUser = createUserWithRMRole(userRole); - getRestAPIFactory().getRMUserAPI().addUserPermission(recordCategory.getId(), rmUser, userPermission); + getRestAPIFactory().getRMUserAPI().addUserPermission(componentId, 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 @@ -167,9 +180,28 @@ public class RoleService public UserModel createCollaboratorWithRMRoleAndPermission(SiteModel siteModel, RecordCategory recordCategory, UserRoles userRole, UserPermissions userPermission) { - final UserModel rmUser = createUserWithRMRoleAndCategoryPermission(userRole.roleId, recordCategory, + return createUserWithSiteRoleRMRoleAndPermission(siteModel, UserRole.SiteCollaborator, recordCategory.getId(), userRole, userPermission); - getDataUser().addUserToSite(rmUser, siteModel, UserRole.SiteCollaborator); + } + + + /** + * Helper method to create a test user with a rm role and permissions over a rm component and a 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 + */ + public UserModel createUserWithSiteRoleRMRoleAndPermission(SiteModel siteModel, UserRole userSiteRoles, + String rmNodeId, UserRoles userRole, + UserPermissions userPermission) + { + final UserModel rmUser = createUserWithRMRoleAndRMNodePermission(userRole.roleId, rmNodeId, + userPermission); + getDataUser().addUserToSite(rmUser, siteModel, userSiteRoles); return rmUser; } } diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/TestData.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/TestData.java index 6feb052b01..38e27a327d 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/TestData.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/TestData.java @@ -97,4 +97,19 @@ public interface TestData */ public static final Set RM_ROLES = newHashSet(ROLE_RM_ADMIN.roleId, ROLE_RM_MANAGER.roleId, ROLE_RM_POWER_USER.roleId, ROLE_RM_SECURITY_OFFICER.roleId, ROLE_RM_USER.roleId); + + /** + * The default hold description + */ + String HOLD_DESCRIPTION = "Generalized hold case for tests"; + + /** + * The default hold reason + */ + String HOLD_REASON = "Active content to be reviewed for the CASE McDermott, FINRA "; + + /** + * Frozen aspect + */ + String FROZEN_ASPECT = "rma:frozen"; } 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 244132d031..e6bee2c556 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 @@ -34,7 +34,7 @@ import static org.alfresco.rest.rm.community.model.user.UserPermissions.PERMISSI import static org.alfresco.rest.rm.community.model.user.UserPermissions.PERMISSION_READ_RECORDS; import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_POWER_USER; import static org.alfresco.rest.rm.community.requests.gscore.api.FilesAPI.PARENT_ID_PARAM; -import static org.alfresco.rest.v0.RMRolesAndActionsAPI.HOLDS_CONTAINER; +import static org.alfresco.rest.v0.HoldsAPI.HOLDS_CONTAINER; 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; @@ -57,6 +57,7 @@ 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.unfiledcontainer.UnfiledContainerChild; import org.alfresco.rest.rm.community.util.DockerHelper; +import org.alfresco.rest.v0.HoldsAPI; import org.alfresco.rest.v0.RMRolesAndActionsAPI; import org.alfresco.rest.v0.service.RoleService; import org.alfresco.test.AlfrescoTest; @@ -106,6 +107,9 @@ public class DeclareAndFileDocumentAsRecordTests extends BaseRMRestTest @Autowired private RMRolesAndActionsAPI rmRolesAndActionsAPI; + @Autowired + private HoldsAPI holdsAPI; + /** * Invalid destination paths where in-place records can't be filed */ @@ -407,10 +411,10 @@ public class DeclareAndFileDocumentAsRecordTests extends BaseRMRestTest public void declareAndFileToHeldRecordFolderUsingFilesAPI() throws Exception { RecordCategoryChild heldRecordFolder = createFolder(recordCategory.getId(), getRandomName("heldRecordFolder")); - rmRolesAndActionsAPI.createHold(getAdminUser().getUsername(), getAdminUser().getPassword(), HOLD_NAME, - "hold reason", "hold description"); - rmRolesAndActionsAPI.addItemToHold(getAdminUser().getUsername(), getAdminUser().getPassword(), - heldRecordFolder.getId(), HOLD_NAME); + holdsAPI.createHold(getAdminUser().getUsername(), getAdminUser().getPassword(), HOLD_NAME, "hold reason", + "hold description"); + holdsAPI.addItemToHold(getAdminUser().getUsername(), getAdminUser().getPassword(), heldRecordFolder.getId(), + HOLD_NAME); STEP("Declare document as record with a frozen location parameter value"); getRestAPIFactory().getFilesAPI() diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/AddContentToHoldsTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/AddContentToHoldsTests.java new file mode 100644 index 0000000000..e89ff63b5c --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/AddContentToHoldsTests.java @@ -0,0 +1,355 @@ +/*- + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2019 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.hold; + +import static org.alfresco.rest.rm.community.base.TestData.FROZEN_ASPECT; +import static org.alfresco.rest.rm.community.base.TestData.HOLD_DESCRIPTION; +import static org.alfresco.rest.rm.community.base.TestData.HOLD_REASON; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS; +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; +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.rest.rm.community.utils.CoreUtil.toContentModel; +import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.IMAGE_FILE; +import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createElectronicRecordModel; +import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createNonElectronicRecordModel; +import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.getFile; +import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; +import static org.alfresco.utility.report.log.Step.STEP; +import static org.apache.commons.httpclient.HttpStatus.SC_BAD_REQUEST; +import static org.apache.commons.httpclient.HttpStatus.SC_INTERNAL_SERVER_ERROR; +import static org.springframework.http.HttpStatus.CREATED; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; +import static org.testng.AssertJUnit.assertFalse; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.model.RestNodeModel; +import org.alfresco.rest.rm.community.base.BaseRMRestTest; +import org.alfresco.rest.rm.community.model.hold.HoldEntry; +import org.alfresco.rest.rm.community.model.record.Record; +import org.alfresco.rest.rm.community.model.user.UserRoles; +import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI; +import org.alfresco.rest.v0.HoldsAPI; +import org.alfresco.rest.v0.service.RoleService; +import org.alfresco.test.AlfrescoTest; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.FileModel; +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.DataProvider; +import org.testng.annotations.Test; + +/** + * API tests for adding content to holds + * + * @author Rodica Sutu + * @since 3.2 + */ +@AlfrescoTest (jira = "RM-6874") +public class AddContentToHoldsTests extends BaseRMRestTest +{ + private static final String HOLD = "HOLD" + generateTestPrefix(AddContentToHoldsTests.class); + private static final String ACCESS_DENIED_ERROR_MESSAGE = "Access Denied. You do not have the appropriate " + + "permissions to perform this operation."; + private static final String INVALID_TYPE_ERROR_MESSAGE = "Items added to a hold must be either a record, a " + + "record folder or active content."; + + private SiteModel testSite; + private String holdNodeRef; + private FileModel document, contentToAddToHold, contentAddToHoldNoPermission; + private UserModel userAddHoldPermission; + private List users = new ArrayList<>(); + + @Autowired + private HoldsAPI holdsAPI; + @Autowired + private RoleService roleService; + + + @BeforeClass (alwaysRun = true) + public void preconditionForAddContentToHold() throws Exception + { + STEP("Create a hold."); + holdNodeRef = holdsAPI.createHoldAndGetNodeRef(getAdminUser().getUsername(), getAdminUser().getUsername(), + HOLD, HOLD_REASON, HOLD_DESCRIPTION); + + STEP("Create test files."); + testSite = dataSite.usingAdmin().createPublicRandomSite(); + document = dataContent.usingSite(testSite) + .createContent(CMISUtil.DocumentType.TEXT_PLAIN); + contentToAddToHold = dataContent.usingSite(testSite) + .createContent(CMISUtil.DocumentType.TEXT_PLAIN); + contentAddToHoldNoPermission = dataContent.usingSite(testSite) + .createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + STEP("Add the content to the hold."); + holdsAPI.addItemToHold(getAdminUser().getUsername(), getAdminUser().getPassword(), document + .getNodeRefWithoutVersion(), HOLD); + + STEP("Create users"); + userAddHoldPermission = roleService.createUserWithSiteRoleRMRoleAndPermission(testSite, + UserRole.SiteCollaborator, holdNodeRef, UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING); + users.add(userAddHoldPermission); + + } + + /** + * Given a hold that contains at least one active content + * When I use the existing REST API to retrieve the contents of the hold + * Then I should see all the active content on hold + */ + @Test + public void retrieveTheContentOfTheHoldUsingV1API() throws Exception + { + STEP("Retrieve the list of children from the hold and collect the entries that have the name of the active " + + "content held"); + List documentsHeld = restClient.authenticateUser(getAdminUser()).withCoreAPI() + .usingNode(toContentModel(holdNodeRef)) + .listChildren().getEntries().stream() + .filter(child -> child.onModel().getName().contains(document + .getName())) + .collect(Collectors.toList()); + STEP("Check the list of active content"); + assertEquals(documentsHeld.size(), 1, "The active content is not retrive when getting the children from the " + + "hold folder"); + assertEquals(documentsHeld.get(0).onModel().getName(), document.getName()); + } + + /** + * Given a hold that contains at least one active content + * When I use the existing REST API to retrieve the holds the content is added + * Then the hold where the content held is returned + */ + @Test + public void retrieveTheHoldWhereTheContentIsAdded() + { + List holdEntries = holdsAPI.getHolds(getAdminUser().getUsername(), getAdminUser().getPassword(), + document.getNodeRefWithoutVersion(), true, null); + assertTrue(holdEntries.stream().anyMatch(holdEntry -> holdEntry.getName().contains(HOLD)), "Could not find " + + "hold with name " + HOLD); + } + + /** + * Valid nodes to be added to hold + */ + @DataProvider (name = "validNodesForAddToHold") + public Object[][] getValidNodesForAddToHold() throws Exception + { + //create electronic and nonElectronic record in record folder + String recordFolderId = createCategoryFolderInFilePlan().getId(); + RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI(); + + Record electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolderId, getFile + (IMAGE_FILE)); + assertStatusCode(CREATED); + + Record nonElectronicRecord = recordFolderAPI.createRecord(createNonElectronicRecordModel(), recordFolderId); + assertStatusCode(CREATED); + getRestAPIFactory().getRMUserAPI().addUserPermission(recordFolderId, userAddHoldPermission, PERMISSION_FILING); + + String folderToHold = createCategoryFolderInFilePlan().getId(); + getRestAPIFactory().getRMUserAPI().addUserPermission(folderToHold, userAddHoldPermission, PERMISSION_FILING); + + + return new String[][] + { // record folder + { folderToHold }, + //electronic record + { electronicRecord.getId() }, + // non electronic record + { nonElectronicRecord.getId() }, + // document from collaboration site + { contentToAddToHold.getNodeRefWithoutVersion() }, + }; + } + + /** + * Given active content not on hold + * And a hold + * And file permission on the hold + * And the appropriate capability to add to hold + * When I use the existing REST API to add the active content to the hold + * Then the active content is added to the hold + * And the active content is frozen + * + * @throws Exception + */ + @Test (dataProvider = "validNodesForAddToHold") + public void addValidNodesToHoldWithAllowedUser(String nodeId) throws Exception + { + STEP("Add the content to the hold with user with permission."); + holdsAPI.addItemToHold(userAddHoldPermission.getUsername(), userAddHoldPermission.getPassword(), + nodeId, HOLD); + + STEP("Check active content is frozen."); + RestNodeModel heldActiveContent = restClient.authenticateUser(userAddHoldPermission) + .withCoreAPI().usingNode(toContentModel(nodeId)).getNode(); + assertTrue(heldActiveContent.getAspectNames().contains(FROZEN_ASPECT)); + + } + + /** + * Data provider with user without correct permission to add to hold and the node ref to be added to hold + * @return object with user model and the node ref to be added to hold + */ + @DataProvider (name = "userWithoutPermissionForAddToHold") + public Object[][] getUserWithoutPermissionForAddToHold() throws Exception + { + //create electronic and nonElectronic record in record folder + String recordFolderId = createCategoryFolderInFilePlan().getId(); + UserModel user = roleService.createUserWithRMRoleAndRMNodePermission(ROLE_RM_MANAGER.roleId, recordFolderId, + PERMISSION_READ_RECORDS); + getRestAPIFactory().getRMUserAPI().addUserPermission(holdNodeRef, user, PERMISSION_FILING); + + return new Object[][] + { // user without write permission on the content + { + roleService.createUserWithSiteRoleRMRoleAndPermission(testSite, UserRole.SiteConsumer, + holdNodeRef, UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING), + contentAddToHoldNoPermission.getNodeRefWithoutVersion() + }, + // user with write permission on the content and without filling permission on a hold + { + roleService.createUserWithSiteRoleRMRoleAndPermission(testSite, UserRole + .SiteCollaborator, + holdNodeRef, UserRoles.ROLE_RM_MANAGER, PERMISSION_READ_RECORDS), + contentAddToHoldNoPermission.getNodeRefWithoutVersion() + }, + // user with write permission on the content, filling permission on a hold without add to + // hold capability + { + roleService.createUserWithSiteRoleRMRoleAndPermission(testSite, UserRole + .SiteCollaborator, + holdNodeRef, UserRoles.ROLE_RM_POWER_USER, PERMISSION_READ_RECORDS), + contentAddToHoldNoPermission.getNodeRefWithoutVersion() + }, + //user without write permission on RM record folder + { + user, recordFolderId + }, + + }; + } + + /** + * Given active content not on hold + * And a hold + * And user without right permission to add to hold + * When I use the existing REST API to add the active content to the hold + * Then the active content is not added to the hold + * And the active content is frozen + * + * @throws Exception + */ + @Test (dataProvider = "userWithoutPermissionForAddToHold") + public void addContentToHoldWithUserWithoutHoldPermission(UserModel userModel, String nodeToBeAddedToHold) throws + Exception + { + users.add(userModel); + STEP("Add the content to the hold with user with permission."); + String response = holdsAPI.addToHoldAndGetMessage(userModel.getUsername(), + userModel.getPassword(), SC_INTERNAL_SERVER_ERROR, nodeToBeAddedToHold, HOLD); + assertTrue(response.contains(ACCESS_DENIED_ERROR_MESSAGE)); + + STEP("Check active content is not frozen."); + RestNodeModel heldActiveContent = restClient.authenticateUser(getAdminUser()) + .withCoreAPI().usingNode(toContentModel(nodeToBeAddedToHold)) + .getNode(); + assertFalse(heldActiveContent.getAspectNames().contains(FROZEN_ASPECT)); + + } + + + + /** + * Data provider withh invalid item types that can be added to a hold + */ + @DataProvider (name = "invalidNodesForAddToHold") + public Object[][] getInvalidNodesForAddToHold() throws Exception + { + + return new Object[][] + { // file plan node id + { getFilePlan(FILE_PLAN_ALIAS).getId(), SC_BAD_REQUEST, INVALID_TYPE_ERROR_MESSAGE }, + //transfer container + { getTransferContainer(TRANSFERS_ALIAS).getId(), SC_BAD_REQUEST, INVALID_TYPE_ERROR_MESSAGE }, + // an arbitrary record category + { createRootCategory(getRandomAlphanumeric()).getId(), SC_INTERNAL_SERVER_ERROR, ACCESS_DENIED_ERROR_MESSAGE }, + // unfiled records root + { getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS).getId(), SC_BAD_REQUEST, INVALID_TYPE_ERROR_MESSAGE }, + // an arbitrary unfiled records folder + { createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Folder " + + getRandomAlphanumeric(), UNFILED_RECORD_FOLDER_TYPE).getId(), SC_BAD_REQUEST, INVALID_TYPE_ERROR_MESSAGE }, + //folder, + { dataContent.usingAdmin().usingSite(testSite).createFolder().getNodeRef(), SC_BAD_REQUEST, INVALID_TYPE_ERROR_MESSAGE } + }; + } + + /** + * unfiled container + * unfiled folder + * folder + * category + * fileplan + * + * @throws Exception + */ + @Test (dataProvider = "invalidNodesForAddToHold") + public void addInvalidNodesToHold(String itemNodeRef, int responseCode, String errorMessage) throws Exception + { + STEP("Add the item to the hold "); + String responseErrorMessage = holdsAPI.addToHoldAndGetMessage(userAddHoldPermission.getUsername(), + userAddHoldPermission.getPassword(), responseCode, itemNodeRef, HOLD); + assertTrue(responseErrorMessage.contains(errorMessage), + "Actual message " + responseErrorMessage); + + STEP("Check active content is not frozen."); + RestNodeModel heldActiveContent = restClient.authenticateUser(getAdminUser()) + .withCoreAPI().usingNode(toContentModel(itemNodeRef)).getNode(); + assertFalse(heldActiveContent.getAspectNames().contains(FROZEN_ASPECT)); + } + + @AfterClass (alwaysRun = true) + public void cleanUpAddContentToHold() throws Exception + { + holdsAPI.deleteHold(getAdminUser().getUsername(), getAdminUser().getPassword(), HOLD); + dataSite.usingAdmin().deleteSite(testSite); + users.forEach(user -> getDataUser().usingAdmin().deleteUser(user)); + } +} diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/PreventActionsOnFrozenContentTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/PreventActionsOnFrozenContentTests.java new file mode 100644 index 0000000000..7d7b9b10b1 --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/PreventActionsOnFrozenContentTests.java @@ -0,0 +1,188 @@ +/*- + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2019 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.hold; + +import static org.alfresco.rest.rm.community.base.TestData.HOLD_DESCRIPTION; +import static org.alfresco.rest.rm.community.base.TestData.HOLD_REASON; +import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix; +import static org.alfresco.rest.rm.community.utils.CoreUtil.createBodyForMoveCopy; +import static org.alfresco.utility.report.log.Step.STEP; + +import javax.json.Json; +import javax.json.JsonObject; +import java.io.File; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.rm.community.base.BaseRMRestTest; +import org.alfresco.rest.v0.HoldsAPI; +import org.alfresco.utility.Utility; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FolderModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * API tests to check actions on frozen content + * + * @author Rodica Sutu + * @since 3.2 + */ +public class PreventActionsOnFrozenContentTests extends BaseRMRestTest +{ + private static final String HOLD_ONE = "HOLD" + generateTestPrefix(PreventActionsOnFrozenContentTests.class); + private static String holdNodeRef; + private static FileModel contentHeld; + private static File updatedFile; + private static FolderModel folderModel; + + @Autowired + private HoldsAPI holdsAPI; + + @BeforeClass (alwaysRun = true) + public void preconditionForRemoveContentFromHold() throws Exception + { + STEP("Create a hold."); + holdNodeRef = holdsAPI.createHoldAndGetNodeRef(getAdminUser().getUsername(), getAdminUser().getUsername(), + HOLD_ONE, HOLD_REASON, HOLD_DESCRIPTION); + + STEP("Create a test file and add to hold"); + testSite = dataSite.usingAdmin().createPublicRandomSite(); + contentHeld = dataContent.usingAdmin().usingSite(testSite) + .createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + STEP("Add the content to the hold."); + holdsAPI.addItemToHold(getAdminUser().getUsername(), getAdminUser().getPassword(), contentHeld + .getNodeRefWithoutVersion(), HOLD_ONE); + + STEP("Get a file resource."); + updatedFile = Utility.getResourceTestDataFile("SampleTextFile_10kb.txt"); + + STEP("Create a folder withing the test site ."); + folderModel = dataContent.usingAdmin().usingSite(testSite) + .createFolder(); + } + /** + * Given active content on hold + * When I try to edit the properties + * Or perform an action that edits the properties + * Then I am not successful + * + */ + @Test + public void editPropertiesForContentHeld() throws Exception + { + STEP("Update name property of the held content"); + JsonObject nameUpdated = Json.createObjectBuilder().add("name","HeldNameUpdated").build(); + restClient.authenticateUser(getAdminUser()).withCoreAPI().usingNode(contentHeld).updateNode(nameUpdated.toString()); + + STEP("Check the request failed."); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + restClient.assertLastError().containsSummary("Frozen nodes can not be updated."); + + } + + /* + * Given active content on hold + * When I try to update the content + * Then I am not successful + */ + @Test + public void updateContentForFrozenFile() throws Exception + { + STEP("Update content of the held file"); + restClient.authenticateUser(getAdminUser()).withCoreAPI().usingNode(contentHeld).updateNodeContent(updatedFile); + + STEP("Check the request failed."); + restClient.assertStatusCodeIs(HttpStatus.INTERNAL_SERVER_ERROR); + restClient.assertLastError().containsSummary("Frozen nodes can not be updated."); + + } + /* + * Given active content on hold + * When I try to delete the content + * Then I am not successful + */ + @Test + public void deleteFrozenFile() throws Exception + { + STEP("Delete frozen file"); + restClient.authenticateUser(getAdminUser()).withCoreAPI().usingNode(contentHeld).deleteNode(contentHeld.getNodeRefWithoutVersion()); + + STEP("Check the request failed."); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + restClient.assertLastError().containsSummary("Frozen nodes can not be updated."); + + } + + /** + * Given active content on hold + * When I try to copy the content + * Then I am not successful + */ + @Test + public void copyFrozenFile() throws Exception + { + STEP("Copy frozen file"); + String postBody = JsonBodyGenerator.keyValueJson("targetParentId",folderModel.getNodeRef()); + getRestAPIFactory().getNodeAPI(contentHeld).copyNode(postBody); + + STEP("Check the request failed."); + assertStatusCode(HttpStatus.FORBIDDEN); + restClient.assertLastError().containsSummary("Frozen nodes can not be copied."); + } + + /** + * Given active content on hold + * When I try to move the content + * Then I am not successful + * + */ + @Test + public void moveFrozenFile() throws Exception + { + STEP("Move frozen file"); + getRestAPIFactory().getNodeAPI(contentHeld).move(createBodyForMoveCopy(folderModel.getNodeRef())); + + STEP("Check the request failed."); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + restClient.assertLastError().containsSummary("Frozen nodes can not be copied."); + } + + + @AfterClass (alwaysRun = true) + public void cleanUpAddContentToHold() throws Exception + { + holdsAPI.deleteHold(getAdminUser().getUsername(), getAdminUser().getPassword(), HOLD_ONE); + dataSite.usingAdmin().deleteSite(testSite); + + } + +} diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/RemoveContentFromHoldsTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/RemoveContentFromHoldsTests.java new file mode 100644 index 0000000000..193dfd2de7 --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/RemoveContentFromHoldsTests.java @@ -0,0 +1,284 @@ +/*- + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2019 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.hold; + +import static org.alfresco.rest.rm.community.base.TestData.FROZEN_ASPECT; +import static org.alfresco.rest.rm.community.base.TestData.HOLD_DESCRIPTION; +import static org.alfresco.rest.rm.community.base.TestData.HOLD_REASON; +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; +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.rest.rm.community.utils.CoreUtil.toContentModel; +import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.IMAGE_FILE; +import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createElectronicRecordModel; +import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createNonElectronicRecordModel; +import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.getFile; +import static org.alfresco.utility.report.log.Step.STEP; +import static org.apache.commons.httpclient.HttpStatus.SC_INTERNAL_SERVER_ERROR; +import static org.springframework.http.HttpStatus.CREATED; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import java.util.Arrays; +import java.util.List; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.model.RestNodeModel; +import org.alfresco.rest.rm.community.base.BaseRMRestTest; +import org.alfresco.rest.rm.community.model.hold.HoldEntry; +import org.alfresco.rest.rm.community.model.record.Record; +import org.alfresco.rest.rm.community.model.user.UserRoles; +import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI; +import org.alfresco.rest.v0.HoldsAPI; +import org.alfresco.rest.v0.service.RoleService; +import org.alfresco.test.AlfrescoTest; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.FileModel; +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.DataProvider; +import org.testng.annotations.Test; + +/** + * API tests for removing content from holds + * + * @author Rodica Sutu + * @since 3.2 + */ +@AlfrescoTest (jira = "RM-6874, RM-6873") +public class RemoveContentFromHoldsTests extends BaseRMRestTest +{ + private static final String HOLD_ONE = "HOLD_ONE" + generateTestPrefix(RemoveContentFromHoldsTests.class); + private static final String HOLD_TWO = "HOLD_TWO" + generateTestPrefix(RemoveContentFromHoldsTests.class); + private static final String ACCESS_DENIED_ERROR_MESSAGE = "Access Denied. You do not have the appropriate " + + "permissions to perform this operation."; + + private SiteModel testSite; + private String holdNodeRefOne; + private FileModel contentHeld, contentAddToManyHolds; + + @Autowired + private HoldsAPI holdsAPI; + @Autowired + private RoleService roleService; + + @BeforeClass (alwaysRun = true) + public void preconditionForRemoveContentFromHold() throws Exception + { + STEP("Create two holds."); + holdNodeRefOne = holdsAPI.createHoldAndGetNodeRef(getAdminUser().getUsername(), getAdminUser().getUsername(), + HOLD_ONE, HOLD_REASON, HOLD_DESCRIPTION); + String holdNodeRefTwo = holdsAPI.createHoldAndGetNodeRef(getAdminUser().getUsername(), getAdminUser() + .getUsername(), HOLD_TWO, HOLD_REASON, HOLD_DESCRIPTION); + + STEP("Create test files and add them to hold"); + testSite = dataSite.usingAdmin().createPublicRandomSite(); + contentHeld = dataContent.usingSite(testSite) + .createContent(CMISUtil.DocumentType.TEXT_PLAIN); + contentAddToManyHolds = dataContent.usingSite(testSite) + .createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + STEP("Add the content to the hold."); + holdsAPI.addItemToHold(getAdminUser().getUsername(), getAdminUser().getPassword(), contentHeld + .getNodeRefWithoutVersion(), HOLD_ONE); + holdsAPI.addItemToHold(getAdminUser().getUsername(), getAdminUser().getPassword(), contentAddToManyHolds + .getNodeRefWithoutVersion(), String.format("%s,%s", HOLD_ONE, HOLD_TWO)); + + } + + /** + * Valid nodes to be removed from hold + */ + @DataProvider (name = "validNodesToRemoveFromHold") + public Object[][] getValidNodesToRemoveFromHold() throws Exception + { + //create electronic and nonElectronic record in record folder + String recordFolderId = createCategoryFolderInFilePlan().getId(); + RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI(); + + Record electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolderId, getFile + (IMAGE_FILE)); + assertStatusCode(CREATED); + Record nonElectronicRecord = recordFolderAPI.createRecord(createNonElectronicRecordModel(), recordFolderId); + assertStatusCode(CREATED); + + String folderToHeld = createCategoryFolderInFilePlan().getId(); + + Arrays.asList(electronicRecord.getId(), nonElectronicRecord.getId(), folderToHeld).forEach(item -> + holdsAPI.addItemToHold(getAdminUser().getUsername(), getAdminUser().getPassword(), item, HOLD_ONE)); + + return new String[][] + { // record folder + { folderToHeld }, + //electronic record + { electronicRecord.getId() }, + // non electronic record + { nonElectronicRecord.getId() }, + // document from collaboration site + { contentHeld.getNodeRefWithoutVersion() }, + }; + } + + /** + * Given active content that is held + * And the corresponding hold + * When I use the existing REST API to remove the active content from the hold + * Then the active content is removed from the hold + * And is no longer frozen + */ + @Test(dataProvider = "validNodesToRemoveFromHold") + public void removeContentFromHold(String nodeId) throws Exception + { + STEP("Remove content from hold"); + holdsAPI.removeItemFromHold(getAdminUser().getUsername(), getAdminUser().getPassword(), nodeId, HOLD_ONE); + STEP("Check the content is not held"); + RestNodeModel heldActiveContent = restClient.authenticateUser(getAdminUser()) + .withCoreAPI().usingNode(toContentModel(nodeId)).getNode(); + assertFalse(heldActiveContent.getAspectNames().contains(FROZEN_ASPECT)); + + STEP("Check node is not in any hold"); + List holdEntries = holdsAPI.getHolds(getAdminUser().getUsername(), getAdminUser().getPassword(), + nodeId, true, null); + assertTrue(holdEntries.isEmpty(), "Content held is still added to a hold."); + } + + /** + * Given active content that is held on many holds + * When I use the existing REST API to remove the active content from one hold + * Then the active content is removed from the specific hold + * And is frozen + * And in the other holds + */ + @Test + public void removeContentAddedToManyHolds() throws Exception + { + STEP("Remove content from hold"); + holdsAPI.removeItemFromHold(getAdminUser().getUsername(), getAdminUser().getPassword(), contentAddToManyHolds + .getNodeRefWithoutVersion(), HOLD_ONE); + + STEP("Check the content is held"); + RestNodeModel heldActiveContent = restClient.authenticateUser(getAdminUser()) + .withCoreAPI().usingNode(contentAddToManyHolds).getNode(); + assertTrue(heldActiveContent.getAspectNames().contains(FROZEN_ASPECT)); + + STEP("Check node is not in any hold"); + List holdEntries = holdsAPI.getHolds(getAdminUser().getUsername(), getAdminUser().getPassword(), + contentAddToManyHolds.getNodeRefWithoutVersion(), true, null); + assertFalse(holdEntries.isEmpty(), "Content held is not held after removing from one hold."); + assertTrue(holdEntries.stream().anyMatch(holdEntry -> holdEntry.getName().contains(HOLD_TWO)), "Content held is " + + "not held after removing from one hold."); + } + + /** + * + * @return + * @throws Exception + */ + @DataProvider (name = "userWithoutPermissionForRemoveFromHold") + public Object[][] getUserWithoutPermissionForAddToHold() throws Exception + { + //create electronic and nonElectronic record in record folder + String recordFolderId = createCategoryFolderInFilePlan().getId(); + UserModel user = roleService.createUserWithRMRoleAndRMNodePermission(ROLE_RM_MANAGER.roleId, recordFolderId, + PERMISSION_READ_RECORDS); + getRestAPIFactory().getRMUserAPI().addUserPermission(holdNodeRefOne, user, PERMISSION_FILING); + //create files that will be removed from hold + FileModel contentNoPermission = dataContent.usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + FileModel contentNoHoldPerm = dataContent.usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + FileModel contentNoHoldCap = dataContent.usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + //add files to hold + Arrays.asList(recordFolderId, contentNoHoldCap.getNodeRefWithoutVersion(), + contentNoHoldPerm.getNodeRefWithoutVersion(), contentNoPermission.getNodeRefWithoutVersion()).forEach( + node -> holdsAPI.addItemToHold(getAdminUser().getUsername(), getAdminUser().getPassword(), node, + HOLD_ONE) + ); + + return new Object[][] + { + // user without write permission on the content + { + roleService.createUserWithSiteRoleRMRoleAndPermission(testSite, UserRole.SiteConsumer, + holdNodeRefOne, UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING), + contentNoPermission.getNodeRefWithoutVersion() + }, + // user with write permission on the content and without filling permission on a hold + { + roleService.createUserWithSiteRoleRMRoleAndPermission(testSite, UserRole.SiteCollaborator, + holdNodeRefOne, UserRoles.ROLE_RM_MANAGER, PERMISSION_READ_RECORDS), + contentNoHoldPerm.getNodeRefWithoutVersion() + }, + // user with write permission on the content, filling permission on a hold without remove from + // hold capability + { + roleService.createUserWithSiteRoleRMRoleAndPermission(testSite, UserRole + .SiteCollaborator, + holdNodeRefOne, UserRoles.ROLE_RM_POWER_USER, PERMISSION_READ_RECORDS), + contentNoHoldCap.getNodeRefWithoutVersion() + }, + //user without write permission on RM record folder + { + user, recordFolderId + }, + + }; + } + /** + * Given active content on hold in a single hold location + * And the user does not have sufficient permissions or capabilities to remove the active content from the hold + * When the user tries to remove the active content from the hold + * Then they are unsuccessful + * @throws Exception + */ + @Test (dataProvider = "userWithoutPermissionForRemoveFromHold") + public void removeFromHoldWithUserWithoutPermission(UserModel userModel, String nodeIdToBeRemoved) throws Exception + { + STEP("Remove content from hold with user without right permission or capability"); + String responseNoHoldPermission = holdsAPI.removeFromHoldAndGetMessage(userModel.getUsername(), + userModel.getPassword(), SC_INTERNAL_SERVER_ERROR, nodeIdToBeRemoved, HOLD_ONE); + assertTrue(responseNoHoldPermission.contains(ACCESS_DENIED_ERROR_MESSAGE)); + + STEP("Check active content is frozen."); + RestNodeModel heldActiveContent = restClient.authenticateUser(getAdminUser()) + .withCoreAPI().usingNode(toContentModel(nodeIdToBeRemoved)) + .getNode(); + assertTrue(heldActiveContent.getAspectNames().contains(FROZEN_ASPECT)); + + } + + @AfterClass (alwaysRun = true) + public void cleanUpRemoveContentFromHold() throws Exception + { + holdsAPI.deleteHold(getAdminUser().getUsername(), getAdminUser().getPassword(), HOLD_ONE); + holdsAPI.deleteHold(getAdminUser().getUsername(), getAdminUser().getPassword(), HOLD_TWO); + dataSite.usingAdmin().deleteSite(testSite); + } +} diff --git a/rm-automation/rm-automation-community-rest-api/src/test/resources/shared-resources/testdata/SampleTextFile_10kb.txt b/rm-automation/rm-automation-community-rest-api/src/test/resources/shared-resources/testdata/SampleTextFile_10kb.txt new file mode 100644 index 0000000000..e0f98f53f9 --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/test/resources/shared-resources/testdata/SampleTextFile_10kb.txt @@ -0,0 +1,27 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus condimentum sagittis lacus, laoreet luctus ligula laoreet ut. Vestibulum ullamcorper accumsan velit vel vehicula. Proin tempor lacus arcu. Nunc at elit condimentum, semper nisi et, condimentum mi. In venenatis blandit nibh at sollicitudin. Vestibulum dapibus mauris at orci maximus pellentesque. Nullam id elementum ipsum. Suspendisse cursus lobortis viverra. Proin et erat at mauris tincidunt porttitor vitae ac dui. + +Donec vulputate lorem tortor, nec fermentum nibh bibendum vel. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent dictum luctus massa, non euismod lacus. Pellentesque condimentum dolor est, ut dapibus lectus luctus ac. Ut sagittis commodo arcu. Integer nisi nulla, facilisis sit amet nulla quis, eleifend suscipit purus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Aliquam euismod ultrices lorem, sit amet imperdiet est tincidunt vel. Phasellus dictum justo sit amet ligula varius aliquet auctor et metus. Fusce vitae tortor et nisi pulvinar vestibulum eget in risus. Donec ante ex, placerat a lorem eget, ultricies bibendum purus. Nam sit amet neque non ante laoreet rutrum. Nullam aliquet commodo urna, sed ullamcorper odio feugiat id. Mauris nisi sapien, porttitor in condimentum nec, venenatis eu urna. Pellentesque feugiat diam est, at rhoncus orci porttitor non. + +Nulla luctus sem sit amet nisi consequat, id ornare ipsum dignissim. Sed elementum elit nibh, eu condimentum orci viverra quis. Aenean suscipit vitae felis non suscipit. Suspendisse pharetra turpis non eros semper dictum. Etiam tincidunt venenatis venenatis. Praesent eget gravida lorem, ut congue diam. Etiam facilisis elit at porttitor egestas. Praesent consequat, velit non vulputate convallis, ligula diam sagittis urna, in venenatis nisi justo ut mauris. Vestibulum posuere sollicitudin mi, et vulputate nisl fringilla non. Nulla ornare pretium velit a euismod. Nunc sagittis venenatis vestibulum. Nunc sodales libero a est ornare ultricies. Sed sed leo sed orci pellentesque ultrices. Mauris sollicitudin, sem quis placerat ornare, velit arcu convallis ligula, pretium finibus nisl sapien vel sem. Vivamus sit amet tortor id lorem consequat hendrerit. Nullam at dui risus. + +Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed feugiat semper velit consequat facilisis. Etiam facilisis justo non iaculis dictum. Fusce turpis neque, pharetra ut odio eu, hendrerit rhoncus lacus. Nunc orci felis, imperdiet vel interdum quis, porta eu ipsum. Pellentesque dictum sem lacinia, auctor dui in, malesuada nunc. Maecenas sit amet mollis eros. Proin fringilla viverra ligula, sollicitudin viverra ante sollicitudin congue. Donec mollis felis eu libero malesuada, et lacinia risus interdum. + +Etiam vitae accumsan augue. Ut urna orci, malesuada ut nisi a, condimentum gravida magna. Nulla bibendum ex in vulputate sagittis. Nulla facilisi. Nullam faucibus et metus ac consequat. Quisque tempor eros velit, id mattis nibh aliquet a. Aenean tempor elit ut finibus auctor. Sed at imperdiet mauris. Vestibulum pharetra non lacus sed pulvinar. Sed pellentesque magna a eros volutpat ullamcorper. In hac habitasse platea dictumst. Donec ipsum mi, feugiat in eros sed, varius lacinia turpis. Donec vulputate tincidunt dui ac laoreet. Sed in eros dui. Pellentesque placerat tristique ligula eu finibus. Proin nec faucibus felis, eu commodo ipsum. + +Integer eu hendrerit diam, sed consectetur nunc. Aliquam a sem vitae leo fermentum faucibus quis at sem. Etiam blandit, quam quis fermentum varius, ante urna ultricies lectus, vel pellentesque ligula arcu nec elit. Donec placerat ante in enim scelerisque pretium. Donec et rhoncus erat. Aenean tempor nisi vitae augue tincidunt luctus. Nam condimentum dictum ante, et laoreet neque pellentesque id. Curabitur consectetur cursus neque aliquam porta. Ut interdum nunc nec nibh vestibulum, in sagittis metus facilisis. Pellentesque feugiat condimentum metus. Etiam venenatis quam at ante rhoncus vestibulum. Maecenas suscipit congue pellentesque. Vestibulum suscipit scelerisque fermentum. Nulla iaculis risus ac vulputate porttitor. + +Mauris nec metus vel dolor blandit faucibus et vel magna. Ut tincidunt ipsum non nunc dapibus, sed blandit mi condimentum. Quisque pharetra interdum quam nec feugiat. Sed pellentesque nulla et turpis blandit interdum. Curabitur at metus vitae augue elementum viverra. Sed mattis lorem non enim fermentum finibus. Sed at dui in magna dignissim accumsan. Proin tincidunt ultricies cursus. Maecenas tincidunt magna at urna faucibus lacinia. + +Quisque venenatis justo sit amet tortor condimentum, nec tincidunt tellus viverra. Morbi risus ipsum, consequat convallis malesuada non, fermentum non velit. Nulla facilisis orci eget ligula mattis fermentum. Aliquam vel velit ultricies, sollicitudin nibh eu, congue velit. Donec nulla lorem, euismod id cursus at, sollicitudin et arcu. Proin vitae tincidunt ipsum. Vivamus elementum eleifend justo, placerat interdum nulla rutrum id. + +Phasellus fringilla luctus magna, a finibus justo dapibus a. Nam risus felis, rhoncus eget diam sit amet, congue facilisis nibh. Interdum et malesuada fames ac ante ipsum primis in faucibus. Praesent consequat euismod diam, eget volutpat magna convallis at. Mauris placerat pellentesque imperdiet. Nulla porta scelerisque enim, et scelerisque neque bibendum in. Proin eget turpis nisi. Suspendisse ut est a erat egestas eleifend at euismod arcu. Donec aliquet, nisi sed faucibus condimentum, nisi metus dictum eros, nec dignissim justo odio id nulla. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Maecenas sollicitudin, justo id elementum eleifend, justo neque aliquet nibh, finibus malesuada metus erat eget neque. Suspendisse nec auctor orci. Aenean et vestibulum nulla. Nullam hendrerit augue tristique, commodo metus id, sodales lorem. Etiam feugiat dui est, vitae auctor risus convallis non. + +Maecenas turpis enim, consectetur eget lectus eu, hendrerit posuere lacus. Praesent efficitur, felis eget dapibus consectetur, nisi massa dignissim enim, nec semper dolor est eu urna. Nullam ut sodales lorem. Aliquam dapibus faucibus diam. Vestibulum vel magna et dolor gravida imperdiet ut sit amet sem. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur elementum metus tincidunt nulla euismod ultricies. Duis elementum nec neque in porttitor. Nulla sagittis lorem elit, et consectetur ante laoreet eu. Maecenas nulla tellus, scelerisque ac erat sed, fermentum dapibus metus. Donec tincidunt fermentum molestie. + +Sed consequat mi at maximus faucibus. Pellentesque aliquet tincidunt sapien vel auctor. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Praesent accumsan nunc eget leo aliquam, facilisis hendrerit turpis egestas. Morbi in ultricies mauris, a eleifend turpis. Quisque fringilla massa iaculis risus ultrices, sit amet tincidunt dui varius. Quisque maximus porta tristique. Proin tincidunt, turpis ut tempor pretium, lectus ipsum ullamcorper leo, ac tincidunt felis dui non leo. Aenean porta augue ligula, non consequat ipsum aliquet et. Suspendisse ut suscipit ex. Pellentesque vitae lacinia arcu. Curabitur eget tincidunt nulla, non bibendum metus. Nullam mi ipsum, eleifend vitae tortor pulvinar, facilisis sollicitudin ipsum. + +Vestibulum molestie risus lorem, at feugiat lorem congue sed. Phasellus ullamcorper laoreet enim, nec aliquam turpis scelerisque et. Etiam dictum metus in elit aliquam dapibus. Vivamus vel lectus velit. Nam sed purus luctus, commodo dui quis, malesuada dui. Nulla porttitor aliquet elit sit amet viverra. Proin tempor nulla urna, non aliquet metus maximus quis. Aliquam ac lectus nec mi aliquam sagittis. Quisque venenatis quam eget nisl tempor, egestas rutrum eros eleifend. Nullam venenatis commodo velit, non tempor mauris fermentum ut. In a metus quis erat cursus sagittis. Donec congue nisl in viverra egestas. + +Vestibulum facilisis ligula magna, eu ornare lectus varius et. Mauris facilisis faucibus quam, quis mollis eros convallis non. Interdum et malesuada fames ac ante ipsum primis in faucibus. Praesent sit amet rutrum erat. Suspendisse potenti. Donec lorem mi, sagittis a fringilla sit amet, sagittis bibendum mauris. In in diam et lorem rutrum eleifend a et felis. Sed ac magna quis enim faucibus dictum. Suspendisse blandit enim eu ex laoreet gravida. + +Suspendisse sed semper felis. Etiam mattis magna mi, suscipit ullamcorper tellus euismod sed. Aenean congue scelerisque ligula id sodales. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nunc sem lectus, gravida ac dui non, pharetra posuere leo. Maecenas lacus libero, facilisis et elit vitae, commodo facilisis sem. Vivamus id nisl nulla. Integer at maximus dui. Ut a tincidunt lorem. Vivamus vitae ligula vel lacus cursus condimentum. Phasellus quis mauris lobortis, finibus lorem in, vulputate ex. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed faucibus aliquam metus, quis varius elit porttitor id. Vivamus dignissim sollicitudin scelerisque. Morbi tincidunt, dolor quis vehicula consequat, dui diam condimentum nunc, vitae scelerisque odio libero nec ligula. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; From 849252b125da1dd2056380286926e4fe28c2c0b8 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Tue, 20 Aug 2019 11:33:42 +0300 Subject: [PATCH 2/5] tests updates java docs and clean up data after test run --- .../java/org/alfresco/rest/v0/HoldsAPI.java | 58 +++++++++++------- .../alfresco/rest/v0/service/RoleService.java | 15 ++--- .../hold/AddContentToHoldsTests.java | 61 +++++++++++-------- .../PreventActionsOnFrozenContentTests.java | 8 +-- 4 files changed, 81 insertions(+), 61 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/HoldsAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/HoldsAPI.java index 0906158c1e..c4d7a1264b 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/HoldsAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/HoldsAPI.java @@ -26,6 +26,7 @@ */ package org.alfresco.rest.v0; +import static org.alfresco.rest.core.v0.APIUtils.convertHTTPResponseToJSON; import static org.apache.http.HttpStatus.SC_OK; import static org.testng.AssertJUnit.assertNotNull; @@ -46,7 +47,6 @@ import org.apache.chemistry.opencmis.client.api.CmisObject; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.ParseException; -import org.apache.http.util.EntityUtils; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -62,10 +62,16 @@ import org.springframework.stereotype.Component; public class HoldsAPI extends BaseAPI { public static final String HOLDS_CONTAINER = "Holds"; + /** + * The URI to create a hold + */ private static final String CREATE_HOLDS_API = "{0}type/rma:hold/formprocessor"; - /** The URI to add items to hold.*/ + /** The URI to add items to hold.*/ private static final String RM_HOLDS_API = "{0}rma/holds"; + /** + * The URI to get holds. + */ private static final String GET_RM_HOLDS = RM_HOLDS_API + "?{1}"; /** @@ -122,15 +128,14 @@ public class HoldsAPI extends BaseAPI try { - return new JSONObject(EntityUtils.toString(httpResponse.getEntity())) - .getString("persistedObject") + return convertHTTPResponseToJSON(httpResponse).getString("persistedObject") .replaceAll(NODE_REF_WORKSPACE_SPACES_STORE, ""); } catch(JSONException error) { LOGGER.error("Converting message body to JSON failed. Body: {}", httpResponse, error); } - catch(ParseException | IOException error) + catch(ParseException error) { LOGGER.error("Parsing message body failed.", error); } @@ -176,15 +181,15 @@ public class HoldsAPI extends BaseAPI * @param holdName the hold name * @return The HTTP response */ - public HttpResponse addItemToHold(String user, String password, int expectedStatus, String itemNodeRef, String - holdName) + public HttpResponse addItemToHold(String user, String password, int expectedStatus, String itemNodeRef, + String holdName) { - final JSONObject requestParams = createHoldJsonObject(user, password, itemNodeRef, holdName); + final JSONObject requestParams = addToHoldJsonObject(user, password, itemNodeRef, holdName); return doPostJsonRequest(user, password, expectedStatus, requestParams, RM_HOLDS_API); } /** - * Util method to add item (active content /record/ record folder) to the hold and gets the error message + * Util method to add item (active content /record/ record folder) to the hold and get the error message * * @param user the user who adds the item to the hold * @param password the user's password @@ -207,7 +212,7 @@ public class HoldsAPI extends BaseAPI * @param holdName * @return JSONObject fo */ - private JSONObject createHoldJsonObject(String user, String password, String itemNodeRef, String holdName) + private JSONObject addToHoldJsonObject(String user, String password, String itemNodeRef, String holdName) { final JSONArray nodeRefs = new JSONArray().put(getNodeRefSpacesStore() + itemNodeRef); @@ -239,10 +244,11 @@ public class HoldsAPI extends BaseAPI } /** - * Adds item (record/ record folder) to the hold + * Remove item (record/ record folder) to the hold * * @param user the user who adds the item to the hold * @param password the user's password + * @param expectedStatus https status code expected * @param itemNodeRef the nodeRef of the item to be added to hold * @param holdName the hold name * @return The HTTP response @@ -250,12 +256,12 @@ public class HoldsAPI extends BaseAPI public HttpResponse removeItemFromHold(String user, String password, int expectedStatus, String itemNodeRef, String holdName) { - final JSONObject requestParams = createHoldJsonObject(user, password, itemNodeRef, holdName); + final JSONObject requestParams = addToHoldJsonObject(user, password, itemNodeRef, holdName); return doPutJsonRequest(user, password, expectedStatus, requestParams, RM_HOLDS_API); } /** - * Util method to add item (active content /record/ record folder) to the hold and gets the error message + * Util method to remove item (active content /record/ record folder) from hold and get the error message * * @param user the user who adds the item to the hold * @param password the user's password @@ -278,9 +284,11 @@ public class HoldsAPI extends BaseAPI private String extractErrorMessageFromHttpResponse(HttpResponse httpResponse) { final HttpEntity entity = httpResponse.getEntity(); - - try(InputStream responseStream = entity.getContent(); JsonReader reader = Json.createReader(responseStream)) + JsonReader reader = null; + try { + final InputStream responseStream = entity.getContent(); + reader = Json.createReader(responseStream); return reader.readObject().getString("message"); } catch (JSONException error) @@ -291,20 +299,26 @@ public class HoldsAPI extends BaseAPI { LOGGER.error("Parsing message body failed.", error); } - + finally + { + if (reader != null) + { + reader.close(); + } + } return null; } /** - * Get the list of the available holds which have the item node reference if includedInHold parameter is true + * Get the list of the available holds which have the item node reference if includedInHold parameter is true, * otherwise a list of hold node references will be retrieved which do not include the given node reference. * * @param user The username of the user to use. * @param password The password of the user. - * @param itemNodeRef - * @param includedInHold - * @param fileOnly - * @return return + * @param itemNodeRef The item node reference + * @param includedInHold True to retrieve the holds which have the item node reference + * @param fileOnly True if only files should be return + * @return return a list of hold entries */ public List getHolds(String user, String password, final String itemNodeRef, final Boolean includedInHold, final Boolean fileOnly) @@ -318,6 +332,4 @@ public class HoldsAPI extends BaseAPI return PojoUtility.jsonToObject(holdEntries, HoldEntry.class); } - - } 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 a94719df3d..91b87e8ac7 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 @@ -148,11 +148,11 @@ public class RoleService public UserModel createUserWithRMRoleAndCategoryPermission(String userRole, RecordCategory recordCategory, UserPermissions userPermission) { - return createUserWithRMRoleAndRMNodePermission(userRole, recordCategory.getId(),userPermission); + return createUserWithRMRoleAndRMNodePermission(userRole, recordCategory.getId(), userPermission); } /** - * Helper method to create a test user with rm role and permissions on the node ref + * Helper method to create a user with rm role and permissions on the node ref * * @param userRole the rm role * @param userPermission the permissions over the record category @@ -168,7 +168,7 @@ public class RoleService return rmUser; } /** - * Helper method to create a test user with rm role and permissions over the recordCategory and collaborator role + * Helper method to create a user with rm role and permissions over the recordCategory and collaborator role * in collaboration site * * @param siteModel collaboration site @@ -180,8 +180,8 @@ public class RoleService public UserModel createCollaboratorWithRMRoleAndPermission(SiteModel siteModel, RecordCategory recordCategory, UserRoles userRole, UserPermissions userPermission) { - return createUserWithSiteRoleRMRoleAndPermission(siteModel, UserRole.SiteCollaborator, recordCategory.getId(), userRole, - userPermission); + return createUserWithSiteRoleRMRoleAndPermission(siteModel, UserRole.SiteCollaborator, recordCategory.getId(), + userRole, userPermission); } @@ -190,9 +190,10 @@ public class RoleService * in collaboration site * * @param siteModel collaboration site - * @param recordCategory the category on which permission should be given + * @param userSiteRoles user role in the collaboration site + * @param rmNodeId rm node id to grant rm permission * @param userRole the rm role - * @param userPermission the permissions over the recordCategory + * @param userPermission the permissions over the rmNodeId * @return the created user model */ public UserModel createUserWithSiteRoleRMRoleAndPermission(SiteModel siteModel, UserRole userSiteRoles, diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/AddContentToHoldsTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/AddContentToHoldsTests.java index e89ff63b5c..cf159b73ea 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/AddContentToHoldsTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/AddContentToHoldsTests.java @@ -60,6 +60,8 @@ import org.alfresco.rest.model.RestNodeModel; import org.alfresco.rest.rm.community.base.BaseRMRestTest; import org.alfresco.rest.rm.community.model.hold.HoldEntry; 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.user.UserRoles; import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI; import org.alfresco.rest.v0.HoldsAPI; @@ -92,16 +94,16 @@ public class AddContentToHoldsTests extends BaseRMRestTest private SiteModel testSite; private String holdNodeRef; - private FileModel document, contentToAddToHold, contentAddToHoldNoPermission; + private FileModel documentHeld, contentToAddToHold, contentAddToHoldNoPermission; private UserModel userAddHoldPermission; private List users = new ArrayList<>(); + private List nodesToBeClean = new ArrayList<>(); @Autowired private HoldsAPI holdsAPI; @Autowired private RoleService roleService; - @BeforeClass (alwaysRun = true) public void preconditionForAddContentToHold() throws Exception { @@ -111,15 +113,15 @@ public class AddContentToHoldsTests extends BaseRMRestTest STEP("Create test files."); testSite = dataSite.usingAdmin().createPublicRandomSite(); - document = dataContent.usingSite(testSite) - .createContent(CMISUtil.DocumentType.TEXT_PLAIN); + documentHeld = dataContent.usingSite(testSite) + .createContent(CMISUtil.DocumentType.TEXT_PLAIN); contentToAddToHold = dataContent.usingSite(testSite) .createContent(CMISUtil.DocumentType.TEXT_PLAIN); contentAddToHoldNoPermission = dataContent.usingSite(testSite) .createContent(CMISUtil.DocumentType.TEXT_PLAIN); STEP("Add the content to the hold."); - holdsAPI.addItemToHold(getAdminUser().getUsername(), getAdminUser().getPassword(), document + holdsAPI.addItemToHold(getAdminUser().getUsername(), getAdminUser().getPassword(), documentHeld .getNodeRefWithoutVersion(), HOLD); STEP("Create users"); @@ -142,13 +144,13 @@ public class AddContentToHoldsTests extends BaseRMRestTest List documentsHeld = restClient.authenticateUser(getAdminUser()).withCoreAPI() .usingNode(toContentModel(holdNodeRef)) .listChildren().getEntries().stream() - .filter(child -> child.onModel().getName().contains(document + .filter(child -> child.onModel().getName().contains(documentHeld .getName())) .collect(Collectors.toList()); STEP("Check the list of active content"); assertEquals(documentsHeld.size(), 1, "The active content is not retrive when getting the children from the " + "hold folder"); - assertEquals(documentsHeld.get(0).onModel().getName(), document.getName()); + assertEquals(documentsHeld.get(0).onModel().getName(), documentHeld.getName()); } /** @@ -160,7 +162,7 @@ public class AddContentToHoldsTests extends BaseRMRestTest public void retrieveTheHoldWhereTheContentIsAdded() { List holdEntries = holdsAPI.getHolds(getAdminUser().getUsername(), getAdminUser().getPassword(), - document.getNodeRefWithoutVersion(), true, null); + documentHeld.getNodeRefWithoutVersion(), true, null); assertTrue(holdEntries.stream().anyMatch(holdEntry -> holdEntry.getName().contains(HOLD)), "Could not find " + "hold with name " + HOLD); } @@ -172,24 +174,26 @@ public class AddContentToHoldsTests extends BaseRMRestTest public Object[][] getValidNodesForAddToHold() throws Exception { //create electronic and nonElectronic record in record folder - String recordFolderId = createCategoryFolderInFilePlan().getId(); + RecordCategoryChild recordFolder = createCategoryFolderInFilePlan(); RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI(); - - Record electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolderId, getFile + nodesToBeClean.add(recordFolder.getParentId()); + Record electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolder.getId(), getFile (IMAGE_FILE)); assertStatusCode(CREATED); - Record nonElectronicRecord = recordFolderAPI.createRecord(createNonElectronicRecordModel(), recordFolderId); + Record nonElectronicRecord = recordFolderAPI.createRecord(createNonElectronicRecordModel(), recordFolder.getId()); assertStatusCode(CREATED); - getRestAPIFactory().getRMUserAPI().addUserPermission(recordFolderId, userAddHoldPermission, PERMISSION_FILING); - - String folderToHold = createCategoryFolderInFilePlan().getId(); - getRestAPIFactory().getRMUserAPI().addUserPermission(folderToHold, userAddHoldPermission, PERMISSION_FILING); + getRestAPIFactory().getRMUserAPI().addUserPermission(recordFolder.getId(), userAddHoldPermission, + PERMISSION_FILING); + RecordCategoryChild folderToHold = createCategoryFolderInFilePlan(); + getRestAPIFactory().getRMUserAPI().addUserPermission(folderToHold.getId(), userAddHoldPermission, + PERMISSION_FILING); + nodesToBeClean.add(folderToHold.getParentId()); return new String[][] { // record folder - { folderToHold }, + { folderToHold.getId() }, //electronic record { electronicRecord.getId() }, // non electronic record @@ -231,12 +235,13 @@ public class AddContentToHoldsTests extends BaseRMRestTest @DataProvider (name = "userWithoutPermissionForAddToHold") public Object[][] getUserWithoutPermissionForAddToHold() throws Exception { - //create electronic and nonElectronic record in record folder - String recordFolderId = createCategoryFolderInFilePlan().getId(); - UserModel user = roleService.createUserWithRMRoleAndRMNodePermission(ROLE_RM_MANAGER.roleId, recordFolderId, + //create record folder + RecordCategoryChild recordFolder = createCategoryFolderInFilePlan(); + //create a rm manager and grant read permission over the record folder created + UserModel user = roleService.createUserWithRMRoleAndRMNodePermission(ROLE_RM_MANAGER.roleId, recordFolder.getId(), PERMISSION_READ_RECORDS); getRestAPIFactory().getRMUserAPI().addUserPermission(holdNodeRef, user, PERMISSION_FILING); - + nodesToBeClean.add(recordFolder.getParentId()); return new Object[][] { // user without write permission on the content { @@ -261,7 +266,7 @@ public class AddContentToHoldsTests extends BaseRMRestTest }, //user without write permission on RM record folder { - user, recordFolderId + user, recordFolder.getId() }, }; @@ -298,19 +303,20 @@ public class AddContentToHoldsTests extends BaseRMRestTest /** - * Data provider withh invalid item types that can be added to a hold + * Data provider with invalid item types that can be added to a hold */ @DataProvider (name = "invalidNodesForAddToHold") public Object[][] getInvalidNodesForAddToHold() throws Exception { - + RecordCategory category = createRootCategory(getRandomAlphanumeric()); + nodesToBeClean.add(category.getId()); return new Object[][] { // file plan node id { getFilePlan(FILE_PLAN_ALIAS).getId(), SC_BAD_REQUEST, INVALID_TYPE_ERROR_MESSAGE }, //transfer container { getTransferContainer(TRANSFERS_ALIAS).getId(), SC_BAD_REQUEST, INVALID_TYPE_ERROR_MESSAGE }, - // an arbitrary record category - { createRootCategory(getRandomAlphanumeric()).getId(), SC_INTERNAL_SERVER_ERROR, ACCESS_DENIED_ERROR_MESSAGE }, + // a record category + { category.getId(), SC_INTERNAL_SERVER_ERROR, ACCESS_DENIED_ERROR_MESSAGE }, // unfiled records root { getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS).getId(), SC_BAD_REQUEST, INVALID_TYPE_ERROR_MESSAGE }, // an arbitrary unfiled records folder @@ -337,7 +343,7 @@ public class AddContentToHoldsTests extends BaseRMRestTest String responseErrorMessage = holdsAPI.addToHoldAndGetMessage(userAddHoldPermission.getUsername(), userAddHoldPermission.getPassword(), responseCode, itemNodeRef, HOLD); assertTrue(responseErrorMessage.contains(errorMessage), - "Actual message " + responseErrorMessage); + "Actual error message " + responseErrorMessage + " expected " + responseErrorMessage); STEP("Check active content is not frozen."); RestNodeModel heldActiveContent = restClient.authenticateUser(getAdminUser()) @@ -351,5 +357,6 @@ public class AddContentToHoldsTests extends BaseRMRestTest holdsAPI.deleteHold(getAdminUser().getUsername(), getAdminUser().getPassword(), HOLD); dataSite.usingAdmin().deleteSite(testSite); users.forEach(user -> getDataUser().usingAdmin().deleteUser(user)); + nodesToBeClean.forEach( category -> getRestAPIFactory().getRecordCategoryAPI().deleteRecordCategory(category)); } } diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/PreventActionsOnFrozenContentTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/PreventActionsOnFrozenContentTests.java index 7d7b9b10b1..eb64e5c0fc 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/PreventActionsOnFrozenContentTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/PreventActionsOnFrozenContentTests.java @@ -67,7 +67,7 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest private HoldsAPI holdsAPI; @BeforeClass (alwaysRun = true) - public void preconditionForRemoveContentFromHold() throws Exception + public void preconditionForPreventActionsOnFrozenContent() throws Exception { STEP("Create a hold."); holdNodeRef = holdsAPI.createHoldAndGetNodeRef(getAdminUser().getUsername(), getAdminUser().getUsername(), @@ -138,7 +138,7 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest STEP("Check the request failed."); restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); - restClient.assertLastError().containsSummary("Frozen nodes can not be updated."); + restClient.assertLastError().containsSummary("Frozen nodes can not be deleted."); } @@ -173,12 +173,12 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest STEP("Check the request failed."); restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); - restClient.assertLastError().containsSummary("Frozen nodes can not be copied."); + restClient.assertLastError().containsSummary("Frozen nodes can not be updated."); } @AfterClass (alwaysRun = true) - public void cleanUpAddContentToHold() throws Exception + public void cleanUpPreventActionsOnFrozenContent() throws Exception { holdsAPI.deleteHold(getAdminUser().getUsername(), getAdminUser().getPassword(), HOLD_ONE); dataSite.usingAdmin().deleteSite(testSite); From 0d85f2caddd21804b480466d1d6438a2535e2cbc Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Wed, 21 Aug 2019 12:03:01 +0300 Subject: [PATCH 3/5] code review changes --- .../org/alfresco/rest/core/v0/APIUtils.java | 42 ++++++++ .../java/org/alfresco/rest/v0/HoldsAPI.java | 93 ++++++------------ .../alfresco/rest/v0/service/RoleService.java | 12 +-- .../rm/community/base/BaseRMRestTest.java | 15 ++- ...ToHoldsTests.java => AddToHoldsTests.java} | 97 ++++++++++--------- .../PreventActionsOnFrozenContentTests.java | 24 +++-- ...dsTests.java => RemoveFromHoldsTests.java} | 60 +++++------- .../rest/rm/community/utils/CoreUtil.java | 45 ++++++++- 8 files changed, 225 insertions(+), 163 deletions(-) rename rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/{AddContentToHoldsTests.java => AddToHoldsTests.java} (84%) rename rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/{RemoveContentFromHoldsTests.java => RemoveFromHoldsTests.java} (85%) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/APIUtils.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/APIUtils.java index 3d3f362a41..d0b58545b2 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/APIUtils.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/APIUtils.java @@ -26,12 +26,18 @@ */ package org.alfresco.rest.core.v0; +import javax.json.Json; +import javax.json.JsonReader; import java.io.IOException; +import java.io.InputStream; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; import org.apache.commons.io.IOUtils; +import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; +import org.apache.http.ParseException; +import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -76,4 +82,40 @@ public class APIUtils LOGGER.info("Response body:\n{}", source); return new JSONObject(source); } + + /** + * Util method to extract the message string from the HTTP response + * + * @param httpResponse http response + * @return error message from the http response + */ + public static String extractErrorMessageFromHttpResponse(HttpResponse httpResponse) + { + final HttpEntity entity = httpResponse.getEntity(); + JsonReader reader = null; + try + { + final InputStream responseStream = entity.getContent(); + reader = Json.createReader(responseStream); + return reader.readObject().getString("message"); + } + catch (JSONException error) + { + + LOGGER.error("Converting message body to JSON failed. Body: {}", httpResponse, error); + } + catch (ParseException | IOException error) + { + + LOGGER.error("Parsing message body failed.", error); + } + finally + { + if (reader != null) + { + reader.close(); + } + } + return null; + } } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/HoldsAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/HoldsAPI.java index c4d7a1264b..fd038eceab 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/HoldsAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/HoldsAPI.java @@ -30,21 +30,17 @@ import static org.alfresco.rest.core.v0.APIUtils.convertHTTPResponseToJSON; import static org.apache.http.HttpStatus.SC_OK; import static org.testng.AssertJUnit.assertNotNull; -import javax.json.Json; -import javax.json.JsonReader; -import java.io.IOException; -import java.io.InputStream; import java.text.MessageFormat; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; +import org.alfresco.rest.core.v0.APIUtils; import org.alfresco.rest.core.v0.BaseAPI; import org.alfresco.rest.rm.community.model.hold.HoldEntry; import org.alfresco.rest.rm.community.util.PojoUtility; import org.alfresco.utility.Utility; import org.apache.chemistry.opencmis.client.api.CmisObject; -import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.ParseException; import org.json.JSONArray; @@ -67,7 +63,9 @@ public class HoldsAPI extends BaseAPI */ private static final String CREATE_HOLDS_API = "{0}type/rma:hold/formprocessor"; - /** The URI to add items to hold.*/ + /** + * The URI to add items to hold or to remove items from hold + */ private static final String RM_HOLDS_API = "{0}rma/holds"; /** * The URI to get holds. @@ -77,7 +75,7 @@ public class HoldsAPI extends BaseAPI /** * Util method to create a hold * - * @param user the user creating the category + * @param user the user creating the hold * @param password the user's password * @param holdName the hold name * @param reason hold reason @@ -111,13 +109,13 @@ public class HoldsAPI extends BaseAPI } /** - * Create a hold and get the node ref of the hold from the response body + * Create a hold and get the node ref of the hold from the response body * - * @param user - * @param password - * @param holdName - * @param reason - * @param description + * @param user the user creating the hold + * @param password the user's password + * @param holdName the hold name to be created + * @param reason reason of the hold to be created + * @param description hold description * @return node ref of the hold created */ @@ -159,7 +157,7 @@ public class HoldsAPI extends BaseAPI } /** - * Adds item (active content /record/ record folder) to the hold + * Adds item (content /record/ record folder) to the hold * * @param user the user who adds the item to the hold * @param password the user's password @@ -173,7 +171,7 @@ public class HoldsAPI extends BaseAPI } /** - * Adds item (record/ record folder) to the hold + * Adds item (content /record/ record folder) to the hold * * @param user the user who adds the item to the hold * @param password the user's password @@ -184,12 +182,12 @@ public class HoldsAPI extends BaseAPI public HttpResponse addItemToHold(String user, String password, int expectedStatus, String itemNodeRef, String holdName) { - final JSONObject requestParams = addToHoldJsonObject(user, password, itemNodeRef, holdName); + final JSONObject requestParams = addOrRemoveToFromHoldJsonObject(user, password, itemNodeRef, holdName); return doPostJsonRequest(user, password, expectedStatus, requestParams, RM_HOLDS_API); } /** - * Util method to add item (active content /record/ record folder) to the hold and get the error message + * Util method to add item ( content /record/ record folder) to the hold and get the error message * * @param user the user who adds the item to the hold * @param password the user's password @@ -201,18 +199,18 @@ public class HoldsAPI extends BaseAPI holdName) { final HttpResponse httpResponse = addItemToHold(user, password, expectedStatus, itemNodeRef, holdName); - return extractErrorMessageFromHttpResponse(httpResponse); + return APIUtils.extractErrorMessageFromHttpResponse(httpResponse); } /** - * Util method to create the request body for adding an item to hold - * @param user - * @param password - * @param itemNodeRef - * @param holdName + * Util method to create the request body used adding an item to hold or to remove items from hold + * @param user user to create the request body for add/remove an item to/from hold + * @param password the user's password + * @param itemNodeRef node ref to be added to hold + * @param holdName hold names for add/remove item * @return JSONObject fo */ - private JSONObject addToHoldJsonObject(String user, String password, String itemNodeRef, String holdName) + private JSONObject addOrRemoveToFromHoldJsonObject(String user, String password, String itemNodeRef, String holdName) { final JSONArray nodeRefs = new JSONArray().put(getNodeRefSpacesStore() + itemNodeRef); @@ -230,9 +228,9 @@ public class HoldsAPI extends BaseAPI } /** - * Remove item (active content /record/ record folder) from the hold + * Remove item ( content /record/ record folder) from the hold * - * @param user the user who adds the item to the hold + * @param user the user who removes the item from the hold * @param password the user's password * @param itemNodeRef the nodeRef of the item to be added to hold * @param holdName the hold name @@ -244,7 +242,7 @@ public class HoldsAPI extends BaseAPI } /** - * Remove item (record/ record folder) to the hold + * Remove item (content/ record/ record folder) to the hold * * @param user the user who adds the item to the hold * @param password the user's password @@ -256,14 +254,14 @@ public class HoldsAPI extends BaseAPI public HttpResponse removeItemFromHold(String user, String password, int expectedStatus, String itemNodeRef, String holdName) { - final JSONObject requestParams = addToHoldJsonObject(user, password, itemNodeRef, holdName); + final JSONObject requestParams = addOrRemoveToFromHoldJsonObject(user, password, itemNodeRef, holdName); return doPutJsonRequest(user, password, expectedStatus, requestParams, RM_HOLDS_API); } /** - * Util method to remove item (active content /record/ record folder) from hold and get the error message + * Util method to remove item (content /record/ record folder) from hold and get the error message * - * @param user the user who adds the item to the hold + * @param user the user who removes the item from hold * @param password the user's password * @param itemNodeRef the nodeRef of the item to be added to hold * @param holdName the hold name @@ -273,40 +271,7 @@ public class HoldsAPI extends BaseAPI holdName) { final HttpResponse httpResponse = removeItemFromHold(user, password, expectedStatus, itemNodeRef, holdName); - return extractErrorMessageFromHttpResponse(httpResponse); - } - - /** - * Util method to extract the message string from the HTTP response - * @param httpResponse - * @return - */ - private String extractErrorMessageFromHttpResponse(HttpResponse httpResponse) - { - final HttpEntity entity = httpResponse.getEntity(); - JsonReader reader = null; - try - { - final InputStream responseStream = entity.getContent(); - reader = Json.createReader(responseStream); - return reader.readObject().getString("message"); - } - catch (JSONException error) - { - LOGGER.error("Converting message body to JSON failed. Body: {}", httpResponse, error); - } - catch (ParseException | IOException error) - { - LOGGER.error("Parsing message body failed.", error); - } - finally - { - if (reader != null) - { - reader.close(); - } - } - return null; + return APIUtils.extractErrorMessageFromHttpResponse(httpResponse); } /** 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 91b87e8ac7..b167fa9fb4 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 @@ -155,8 +155,8 @@ public class RoleService * Helper method to create a user with rm role and permissions on the node ref * * @param userRole the rm role - * @param userPermission the permissions over the record category - * @param componentId the component id to grant rm permission + * @param userPermission the permissions over the rm node + * @param componentId the node id to grant rm permission * @return the created user model */ public UserModel createUserWithRMRoleAndRMNodePermission(String userRole, String componentId, @@ -167,6 +167,7 @@ public class RoleService getRestAPIFactory().getRmRestWrapper().assertStatusCodeIs(OK); return rmUser; } + /** * Helper method to create a user with rm role and permissions over the recordCategory and collaborator role * in collaboration site @@ -184,25 +185,24 @@ public class RoleService userRole, userPermission); } - /** * Helper method to create a test user with a rm role and permissions over a rm component and a role * in collaboration site * * @param siteModel collaboration site - * @param userSiteRoles user role in the collaboration site + * @param userSiteRole user role in the collaboration site * @param rmNodeId rm node id to grant rm permission * @param userRole the rm role * @param userPermission the permissions over the rmNodeId * @return the created user model */ - public UserModel createUserWithSiteRoleRMRoleAndPermission(SiteModel siteModel, UserRole userSiteRoles, + public UserModel createUserWithSiteRoleRMRoleAndPermission(SiteModel siteModel, UserRole userSiteRole, String rmNodeId, UserRoles userRole, UserPermissions userPermission) { final UserModel rmUser = createUserWithRMRoleAndRMNodePermission(userRole.roleId, rmNodeId, userPermission); - getDataUser().addUserToSite(rmUser, siteModel, userSiteRoles); + getDataUser().addUserToSite(rmUser, siteModel, userSiteRole); 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 279b37a825..96ddd592b2 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 @@ -39,6 +39,7 @@ 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.utils.CoreUtil.toFileModel; 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; @@ -823,7 +824,7 @@ public class BaseRMRestTest extends RestTest */ protected boolean hasRecordAspect(FileModel testFile) throws Exception { - return hasAspect(testFile,RECORD_TYPE); + return hasAspect(testFile, RECORD_TYPE); } /** @@ -839,6 +840,18 @@ public class BaseRMRestTest extends RestTest .getAspectNames().contains(aspectName); } + /** + * Checks if the given node has the given aspect + * + * @param nodeId the node to be checked + * @param aspectName the matching aspect + * @return true if the file has the aspect, false otherwise + */ + protected boolean hasAspect(String nodeId, String aspectName) throws Exception + { + return hasAspect(toFileModel(nodeId),aspectName); + } + /** * Helper method to verify if the declared record is in Unfiled Records location * diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/AddContentToHoldsTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/AddToHoldsTests.java similarity index 84% rename from rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/AddContentToHoldsTests.java rename to rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/AddToHoldsTests.java index cf159b73ea..5aa8ba4c45 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/AddContentToHoldsTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/AddToHoldsTests.java @@ -56,6 +56,7 @@ import java.util.List; import java.util.stream.Collectors; import org.alfresco.dataprep.CMISUtil; +import org.alfresco.dataprep.ContentActions; import org.alfresco.rest.model.RestNodeModel; import org.alfresco.rest.rm.community.base.BaseRMRestTest; import org.alfresco.rest.rm.community.model.hold.HoldEntry; @@ -78,20 +79,20 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; /** - * API tests for adding content to holds + * API tests for adding content/record folder/records to holds * * @author Rodica Sutu * @since 3.2 */ @AlfrescoTest (jira = "RM-6874") -public class AddContentToHoldsTests extends BaseRMRestTest +public class AddToHoldsTests extends BaseRMRestTest { - private static final String HOLD = "HOLD" + generateTestPrefix(AddContentToHoldsTests.class); + private static final String HOLD = "HOLD" + generateTestPrefix(AddToHoldsTests.class); private static final String ACCESS_DENIED_ERROR_MESSAGE = "Access Denied. You do not have the appropriate " + "permissions to perform this operation."; private static final String INVALID_TYPE_ERROR_MESSAGE = "Items added to a hold must be either a record, a " + "record folder or active content."; - + private static final String LOCKED_FILE_ERROR_MESSAGE = "Locked nodes can't be added to hold"; private SiteModel testSite; private String holdNodeRef; private FileModel documentHeld, contentToAddToHold, contentAddToHoldNoPermission; @@ -103,6 +104,8 @@ public class AddContentToHoldsTests extends BaseRMRestTest private HoldsAPI holdsAPI; @Autowired private RoleService roleService; + @Autowired + private ContentActions contentActions; @BeforeClass (alwaysRun = true) public void preconditionForAddContentToHold() throws Exception @@ -148,7 +151,7 @@ public class AddContentToHoldsTests extends BaseRMRestTest .getName())) .collect(Collectors.toList()); STEP("Check the list of active content"); - assertEquals(documentsHeld.size(), 1, "The active content is not retrive when getting the children from the " + + assertEquals(documentsHeld.size(), 1, "The active content is not retrieve when getting the children from the " + "hold folder"); assertEquals(documentsHeld.get(0).onModel().getName(), documentHeld.getName()); } @@ -204,27 +207,25 @@ public class AddContentToHoldsTests extends BaseRMRestTest } /** - * Given active content not on hold + * Given record folder/record/document not on hold * And a hold * And file permission on the hold * And the appropriate capability to add to hold - * When I use the existing REST API to add the active content to the hold - * Then the active content is added to the hold - * And the active content is frozen + * When I use the existing REST API to add the node to the hold + * Then the record folder/record/document is added to the hold + * And the item is frozen * * @throws Exception */ @Test (dataProvider = "validNodesForAddToHold") public void addValidNodesToHoldWithAllowedUser(String nodeId) throws Exception { - STEP("Add the content to the hold with user with permission."); + STEP("Add node to hold with user with permission."); holdsAPI.addItemToHold(userAddHoldPermission.getUsername(), userAddHoldPermission.getPassword(), nodeId, HOLD); - STEP("Check active content is frozen."); - RestNodeModel heldActiveContent = restClient.authenticateUser(userAddHoldPermission) - .withCoreAPI().usingNode(toContentModel(nodeId)).getNode(); - assertTrue(heldActiveContent.getAspectNames().contains(FROZEN_ASPECT)); + STEP("Check the node is frozen."); + assertTrue(hasAspect(nodeId, FROZEN_ASPECT)); } @@ -273,12 +274,12 @@ public class AddContentToHoldsTests extends BaseRMRestTest } /** - * Given active content not on hold + * Given a node not on hold * And a hold * And user without right permission to add to hold - * When I use the existing REST API to add the active content to the hold - * Then the active content is not added to the hold - * And the active content is frozen + * When I use the existing REST API to add the node to the hold + * Then the node is not added to the hold + * And the node is not frozen * * @throws Exception */ @@ -287,68 +288,74 @@ public class AddContentToHoldsTests extends BaseRMRestTest Exception { users.add(userModel); - STEP("Add the content to the hold with user with permission."); - String response = holdsAPI.addToHoldAndGetMessage(userModel.getUsername(), - userModel.getPassword(), SC_INTERNAL_SERVER_ERROR, nodeToBeAddedToHold, HOLD); + STEP("Add the node to the hold with user without permission."); + String response = holdsAPI.addToHoldAndGetMessage(userModel.getUsername(), userModel.getPassword(), + SC_INTERNAL_SERVER_ERROR, nodeToBeAddedToHold, HOLD); assertTrue(response.contains(ACCESS_DENIED_ERROR_MESSAGE)); - STEP("Check active content is not frozen."); - RestNodeModel heldActiveContent = restClient.authenticateUser(getAdminUser()) - .withCoreAPI().usingNode(toContentModel(nodeToBeAddedToHold)) - .getNode(); - assertFalse(heldActiveContent.getAspectNames().contains(FROZEN_ASPECT)); + STEP("Check the node is not frozen."); + assertFalse(hasAspect(nodeToBeAddedToHold,FROZEN_ASPECT)); } - /** - * Data provider with invalid item types that can be added to a hold + * Data provider with invalid node types that can be added to a hold */ @DataProvider (name = "invalidNodesForAddToHold") public Object[][] getInvalidNodesForAddToHold() throws Exception { + //create locked file + FileModel contentLocked = dataContent.usingAdmin().usingSite(testSite) + .createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + contentActions.checkOut(getAdminUser().getUsername(), getAdminUser().getPassword(), + testSite.getId(), contentLocked.getName()); RecordCategory category = createRootCategory(getRandomAlphanumeric()); nodesToBeClean.add(category.getId()); return new Object[][] { // file plan node id - { getFilePlan(FILE_PLAN_ALIAS).getId(), SC_BAD_REQUEST, INVALID_TYPE_ERROR_MESSAGE }, + { getFilePlan(FILE_PLAN_ALIAS).getId(), SC_BAD_REQUEST, INVALID_TYPE_ERROR_MESSAGE }, //transfer container { getTransferContainer(TRANSFERS_ALIAS).getId(), SC_BAD_REQUEST, INVALID_TYPE_ERROR_MESSAGE }, // a record category { category.getId(), SC_INTERNAL_SERVER_ERROR, ACCESS_DENIED_ERROR_MESSAGE }, // unfiled records root - { getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS).getId(), SC_BAD_REQUEST, INVALID_TYPE_ERROR_MESSAGE }, + { getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS).getId(), SC_BAD_REQUEST, + INVALID_TYPE_ERROR_MESSAGE }, // an arbitrary unfiled records folder { createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Folder " + - getRandomAlphanumeric(), UNFILED_RECORD_FOLDER_TYPE).getId(), SC_BAD_REQUEST, INVALID_TYPE_ERROR_MESSAGE }, + getRandomAlphanumeric(), UNFILED_RECORD_FOLDER_TYPE).getId(), SC_BAD_REQUEST, + INVALID_TYPE_ERROR_MESSAGE }, //folder, - { dataContent.usingAdmin().usingSite(testSite).createFolder().getNodeRef(), SC_BAD_REQUEST, INVALID_TYPE_ERROR_MESSAGE } + { dataContent.usingAdmin().usingSite(testSite).createFolder().getNodeRef(), SC_BAD_REQUEST, + INVALID_TYPE_ERROR_MESSAGE }, + //document locked + { contentLocked.getNodeRefWithoutVersion(), SC_INTERNAL_SERVER_ERROR, LOCKED_FILE_ERROR_MESSAGE } }; } /** - * unfiled container - * unfiled folder - * folder - * category - * fileplan + * Given a node that is not a document/record/ record folder ( a valid node type to be added to hold) + * And a hold + * And user without right permission to add to hold + * When I use the existing REST API to add the node to the hold + * Then the node is not added to the hold + * And the node is not frozen * * @throws Exception */ @Test (dataProvider = "invalidNodesForAddToHold") public void addInvalidNodesToHold(String itemNodeRef, int responseCode, String errorMessage) throws Exception { - STEP("Add the item to the hold "); - String responseErrorMessage = holdsAPI.addToHoldAndGetMessage(userAddHoldPermission.getUsername(), - userAddHoldPermission.getPassword(), responseCode, itemNodeRef, HOLD); + STEP("Add the node to the hold "); + String responseErrorMessage = holdsAPI.addToHoldAndGetMessage(getAdminUser().getUsername(), + getAdminUser().getPassword(), responseCode, itemNodeRef, HOLD); assertTrue(responseErrorMessage.contains(errorMessage), - "Actual error message " + responseErrorMessage + " expected " + responseErrorMessage); + "Actual error message " + responseErrorMessage + " expected " + errorMessage); - STEP("Check active content is not frozen."); - RestNodeModel heldActiveContent = restClient.authenticateUser(getAdminUser()) - .withCoreAPI().usingNode(toContentModel(itemNodeRef)).getNode(); - assertFalse(heldActiveContent.getAspectNames().contains(FROZEN_ASPECT)); + STEP("Check node is not frozen."); + assertFalse(hasAspect(itemNodeRef, FROZEN_ASPECT)); } @AfterClass (alwaysRun = true) diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/PreventActionsOnFrozenContentTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/PreventActionsOnFrozenContentTests.java index eb64e5c0fc..073615d483 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/PreventActionsOnFrozenContentTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/PreventActionsOnFrozenContentTests.java @@ -31,6 +31,7 @@ import static org.alfresco.rest.rm.community.base.TestData.HOLD_REASON; import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix; import static org.alfresco.rest.rm.community.utils.CoreUtil.createBodyForMoveCopy; import static org.alfresco.utility.report.log.Step.STEP; +import static org.springframework.http.HttpStatus.FORBIDDEN; import javax.json.Json; import javax.json.JsonObject; @@ -40,11 +41,11 @@ import org.alfresco.dataprep.CMISUtil; import org.alfresco.rest.core.JsonBodyGenerator; import org.alfresco.rest.rm.community.base.BaseRMRestTest; import org.alfresco.rest.v0.HoldsAPI; +import org.alfresco.test.AlfrescoTest; import org.alfresco.utility.Utility; import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FolderModel; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -55,6 +56,7 @@ import org.testng.annotations.Test; * @author Rodica Sutu * @since 3.2 */ +@AlfrescoTest (jira = "RM-6903") public class PreventActionsOnFrozenContentTests extends BaseRMRestTest { private static final String HOLD_ONE = "HOLD" + generateTestPrefix(PreventActionsOnFrozenContentTests.class); @@ -73,7 +75,7 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest holdNodeRef = holdsAPI.createHoldAndGetNodeRef(getAdminUser().getUsername(), getAdminUser().getUsername(), HOLD_ONE, HOLD_REASON, HOLD_DESCRIPTION); - STEP("Create a test file and add to hold"); + STEP("Create a test file."); testSite = dataSite.usingAdmin().createPublicRandomSite(); contentHeld = dataContent.usingAdmin().usingSite(testSite) .createContent(CMISUtil.DocumentType.TEXT_PLAIN); @@ -100,11 +102,11 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest public void editPropertiesForContentHeld() throws Exception { STEP("Update name property of the held content"); - JsonObject nameUpdated = Json.createObjectBuilder().add("name","HeldNameUpdated").build(); + JsonObject nameUpdated = Json.createObjectBuilder().add("name", "HeldNameUpdated").build(); restClient.authenticateUser(getAdminUser()).withCoreAPI().usingNode(contentHeld).updateNode(nameUpdated.toString()); STEP("Check the request failed."); - restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + restClient.assertStatusCodeIs(FORBIDDEN); restClient.assertLastError().containsSummary("Frozen nodes can not be updated."); } @@ -115,13 +117,14 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest * Then I am not successful */ @Test + @AlfrescoTest (jira = "RM-6925") public void updateContentForFrozenFile() throws Exception { STEP("Update content of the held file"); restClient.authenticateUser(getAdminUser()).withCoreAPI().usingNode(contentHeld).updateNodeContent(updatedFile); STEP("Check the request failed."); - restClient.assertStatusCodeIs(HttpStatus.INTERNAL_SERVER_ERROR); + restClient.assertStatusCodeIs(FORBIDDEN); restClient.assertLastError().containsSummary("Frozen nodes can not be updated."); } @@ -137,7 +140,7 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest restClient.authenticateUser(getAdminUser()).withCoreAPI().usingNode(contentHeld).deleteNode(contentHeld.getNodeRefWithoutVersion()); STEP("Check the request failed."); - restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + restClient.assertStatusCodeIs(FORBIDDEN); restClient.assertLastError().containsSummary("Frozen nodes can not be deleted."); } @@ -148,6 +151,7 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest * Then I am not successful */ @Test + @AlfrescoTest(jira = "RM-6924") public void copyFrozenFile() throws Exception { STEP("Copy frozen file"); @@ -155,8 +159,8 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest getRestAPIFactory().getNodeAPI(contentHeld).copyNode(postBody); STEP("Check the request failed."); - assertStatusCode(HttpStatus.FORBIDDEN); - restClient.assertLastError().containsSummary("Frozen nodes can not be copied."); + assertStatusCode(FORBIDDEN); + getRestAPIFactory().getRmRestWrapper().assertLastError().containsSummary("Frozen nodes can not be copied."); } /** @@ -172,8 +176,8 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest getRestAPIFactory().getNodeAPI(contentHeld).move(createBodyForMoveCopy(folderModel.getNodeRef())); STEP("Check the request failed."); - restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); - restClient.assertLastError().containsSummary("Frozen nodes can not be updated."); + assertStatusCode(FORBIDDEN); + getRestAPIFactory().getRmRestWrapper().assertLastError().containsSummary("Frozen nodes can not be moved."); } diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/RemoveContentFromHoldsTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/RemoveFromHoldsTests.java similarity index 85% rename from rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/RemoveContentFromHoldsTests.java rename to rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/RemoveFromHoldsTests.java index 193dfd2de7..7a13be3632 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/RemoveContentFromHoldsTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/RemoveFromHoldsTests.java @@ -33,7 +33,6 @@ import static org.alfresco.rest.rm.community.model.user.UserPermissions.PERMISSI import static org.alfresco.rest.rm.community.model.user.UserPermissions.PERMISSION_READ_RECORDS; 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.rest.rm.community.utils.CoreUtil.toContentModel; import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.IMAGE_FILE; import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createElectronicRecordModel; import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createNonElectronicRecordModel; @@ -48,7 +47,6 @@ import java.util.Arrays; import java.util.List; import org.alfresco.dataprep.CMISUtil; -import org.alfresco.rest.model.RestNodeModel; import org.alfresco.rest.rm.community.base.BaseRMRestTest; import org.alfresco.rest.rm.community.model.hold.HoldEntry; import org.alfresco.rest.rm.community.model.record.Record; @@ -68,16 +66,16 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; /** - * API tests for removing content from holds + * API tests for removing content/record folder/record from holds * * @author Rodica Sutu * @since 3.2 */ @AlfrescoTest (jira = "RM-6874, RM-6873") -public class RemoveContentFromHoldsTests extends BaseRMRestTest +public class RemoveFromHoldsTests extends BaseRMRestTest { - private static final String HOLD_ONE = "HOLD_ONE" + generateTestPrefix(RemoveContentFromHoldsTests.class); - private static final String HOLD_TWO = "HOLD_TWO" + generateTestPrefix(RemoveContentFromHoldsTests.class); + private static final String HOLD_ONE = "HOLD_ONE" + generateTestPrefix(RemoveFromHoldsTests.class); + private static final String HOLD_TWO = "HOLD_TWO" + generateTestPrefix(RemoveFromHoldsTests.class); private static final String ACCESS_DENIED_ERROR_MESSAGE = "Access Denied. You do not have the appropriate " + "permissions to perform this operation."; @@ -99,14 +97,14 @@ public class RemoveContentFromHoldsTests extends BaseRMRestTest String holdNodeRefTwo = holdsAPI.createHoldAndGetNodeRef(getAdminUser().getUsername(), getAdminUser() .getUsername(), HOLD_TWO, HOLD_REASON, HOLD_DESCRIPTION); - STEP("Create test files and add them to hold"); + STEP("Create test files."); testSite = dataSite.usingAdmin().createPublicRandomSite(); contentHeld = dataContent.usingSite(testSite) .createContent(CMISUtil.DocumentType.TEXT_PLAIN); contentAddToManyHolds = dataContent.usingSite(testSite) .createContent(CMISUtil.DocumentType.TEXT_PLAIN); - STEP("Add the content to the hold."); + STEP("Add the content to the holds."); holdsAPI.addItemToHold(getAdminUser().getUsername(), getAdminUser().getPassword(), contentHeld .getNodeRefWithoutVersion(), HOLD_ONE); holdsAPI.addItemToHold(getAdminUser().getUsername(), getAdminUser().getPassword(), contentAddToManyHolds @@ -148,21 +146,20 @@ public class RemoveContentFromHoldsTests extends BaseRMRestTest } /** - * Given active content that is held + * Given content/record folder/record that is held * And the corresponding hold - * When I use the existing REST API to remove the active content from the hold - * Then the active content is removed from the hold + * When I use the existing REST API to remove the node from the hold + * Then the node is removed from the hold * And is no longer frozen */ @Test(dataProvider = "validNodesToRemoveFromHold") public void removeContentFromHold(String nodeId) throws Exception { - STEP("Remove content from hold"); + STEP("Remove node from hold"); holdsAPI.removeItemFromHold(getAdminUser().getUsername(), getAdminUser().getPassword(), nodeId, HOLD_ONE); - STEP("Check the content is not held"); - RestNodeModel heldActiveContent = restClient.authenticateUser(getAdminUser()) - .withCoreAPI().usingNode(toContentModel(nodeId)).getNode(); - assertFalse(heldActiveContent.getAspectNames().contains(FROZEN_ASPECT)); + + STEP("Check the node is not held"); + assertFalse(hasAspect(nodeId, FROZEN_ASPECT)); STEP("Check node is not in any hold"); List holdEntries = holdsAPI.getHolds(getAdminUser().getUsername(), getAdminUser().getPassword(), @@ -180,16 +177,14 @@ public class RemoveContentFromHoldsTests extends BaseRMRestTest @Test public void removeContentAddedToManyHolds() throws Exception { - STEP("Remove content from hold"); + STEP("Remove content from hold. "); holdsAPI.removeItemFromHold(getAdminUser().getUsername(), getAdminUser().getPassword(), contentAddToManyHolds .getNodeRefWithoutVersion(), HOLD_ONE); - STEP("Check the content is held"); - RestNodeModel heldActiveContent = restClient.authenticateUser(getAdminUser()) - .withCoreAPI().usingNode(contentAddToManyHolds).getNode(); - assertTrue(heldActiveContent.getAspectNames().contains(FROZEN_ASPECT)); + STEP("Check the content is held. "); + assertTrue(hasAspect(contentAddToManyHolds.getNodeRefWithoutVersion(), FROZEN_ASPECT)); - STEP("Check node is not in any hold"); + STEP("Check node is in hold HOLD_TWO. "); List holdEntries = holdsAPI.getHolds(getAdminUser().getUsername(), getAdminUser().getPassword(), contentAddToManyHolds.getNodeRefWithoutVersion(), true, null); assertFalse(holdEntries.isEmpty(), "Content held is not held after removing from one hold."); @@ -198,7 +193,7 @@ public class RemoveContentFromHoldsTests extends BaseRMRestTest } /** - * + * Data provider with user without right permission or capability to remove from hold a specific node * @return * @throws Exception */ @@ -241,7 +236,7 @@ public class RemoveContentFromHoldsTests extends BaseRMRestTest { roleService.createUserWithSiteRoleRMRoleAndPermission(testSite, UserRole .SiteCollaborator, - holdNodeRefOne, UserRoles.ROLE_RM_POWER_USER, PERMISSION_READ_RECORDS), + holdNodeRefOne, UserRoles.ROLE_RM_POWER_USER, PERMISSION_FILING), contentNoHoldCap.getNodeRefWithoutVersion() }, //user without write permission on RM record folder @@ -252,25 +247,22 @@ public class RemoveContentFromHoldsTests extends BaseRMRestTest }; } /** - * Given active content on hold in a single hold location - * And the user does not have sufficient permissions or capabilities to remove the active content from the hold - * When the user tries to remove the active content from the hold - * Then they are unsuccessful + * Given node on hold in a single hold location + * And the user does not have sufficient permissions or capabilities to remove the node from the hold + * When the user tries to remove the node from the hold + * Then it's unsuccessful * @throws Exception */ @Test (dataProvider = "userWithoutPermissionForRemoveFromHold") public void removeFromHoldWithUserWithoutPermission(UserModel userModel, String nodeIdToBeRemoved) throws Exception { - STEP("Remove content from hold with user without right permission or capability"); + STEP("Remove node from hold with user without right permission or capability"); String responseNoHoldPermission = holdsAPI.removeFromHoldAndGetMessage(userModel.getUsername(), userModel.getPassword(), SC_INTERNAL_SERVER_ERROR, nodeIdToBeRemoved, HOLD_ONE); assertTrue(responseNoHoldPermission.contains(ACCESS_DENIED_ERROR_MESSAGE)); - STEP("Check active content is frozen."); - RestNodeModel heldActiveContent = restClient.authenticateUser(getAdminUser()) - .withCoreAPI().usingNode(toContentModel(nodeIdToBeRemoved)) - .getNode(); - assertTrue(heldActiveContent.getAspectNames().contains(FROZEN_ASPECT)); + STEP("Check node is frozen."); + assertTrue(hasAspect(nodeIdToBeRemoved, FROZEN_ASPECT)); } 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 index cc0c7c5bfd..f7ae9e7ae2 100644 --- 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 @@ -26,8 +26,12 @@ */ package org.alfresco.rest.rm.community.utils; +import java.lang.reflect.InvocationTargetException; + import org.alfresco.rest.model.RestNodeBodyMoveCopyModel; import org.alfresco.utility.model.ContentModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.RepoTestModel; /** * Utility class for core components models @@ -63,8 +67,43 @@ public class CoreUtil */ public static ContentModel toContentModel(String nodeId) { - ContentModel node = new ContentModel(); - node.setNodeRef(nodeId); - return node; + return toModel(nodeId, ContentModel.class); } + + /** + * Helper method to create a File Model + * + * @return ContentModel + * @throws Exception + */ + public static FileModel toFileModel(String nodeId) + { + return toModel(nodeId,FileModel.class); + } + + /** + * Helper method to create a RepoTestModel using the node id + * + * @param nodeId node ref of the test model + * @param classOf repo test model class + * @return + */ + private static T toModel(String nodeId, Class classOf) + { + T target = null; + try + { + target = (T) classOf.getDeclaredConstructor().newInstance(); + } + catch (InvocationTargetException| NoSuchMethodException| IllegalAccessException | InstantiationException e) + { + e.printStackTrace(); + } + + target.setNodeRef(nodeId); + return target; + + } + + } From 0e4501d27acb2252ab96d317f267a5f0fc21dbab Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Wed, 21 Aug 2019 14:41:05 +0300 Subject: [PATCH 4/5] minor updates of the java doc and code style --- .../java/org/alfresco/rest/v0/HoldsAPI.java | 19 +++++++++---------- .../rm/community/hold/AddToHoldsTests.java | 11 +++-------- .../PreventActionsOnFrozenContentTests.java | 8 +++----- .../community/hold/RemoveFromHoldsTests.java | 5 ++--- 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/HoldsAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/HoldsAPI.java index fd038eceab..1c0a17dd1f 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/HoldsAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/HoldsAPI.java @@ -67,6 +67,7 @@ public class HoldsAPI extends BaseAPI * The URI to add items to hold or to remove items from hold */ private static final String RM_HOLDS_API = "{0}rma/holds"; + /** * The URI to get holds. */ @@ -118,7 +119,6 @@ public class HoldsAPI extends BaseAPI * @param description hold description * @return node ref of the hold created */ - public String createHoldAndGetNodeRef(String user, String password, String holdName, String reason, String description) { @@ -141,8 +141,6 @@ public class HoldsAPI extends BaseAPI return null; } - - /** * Deletes hold * @@ -157,7 +155,7 @@ public class HoldsAPI extends BaseAPI } /** - * Adds item (content /record/ record folder) to the hold + * Adds item(content/record/record folder) to the hold * * @param user the user who adds the item to the hold * @param password the user's password @@ -171,7 +169,7 @@ public class HoldsAPI extends BaseAPI } /** - * Adds item (content /record/ record folder) to the hold + * Adds item(content/record/record folder) to the hold * * @param user the user who adds the item to the hold * @param password the user's password @@ -187,7 +185,7 @@ public class HoldsAPI extends BaseAPI } /** - * Util method to add item ( content /record/ record folder) to the hold and get the error message + * Util method to add item(content/record/record folder) to the hold and get the error message * * @param user the user who adds the item to the hold * @param password the user's password @@ -203,7 +201,8 @@ public class HoldsAPI extends BaseAPI } /** - * Util method to create the request body used adding an item to hold or to remove items from hold + * Util method to create the request body used when adding an item to holds or when removing an item from holds + * * @param user user to create the request body for add/remove an item to/from hold * @param password the user's password * @param itemNodeRef node ref to be added to hold @@ -228,7 +227,7 @@ public class HoldsAPI extends BaseAPI } /** - * Remove item ( content /record/ record folder) from the hold + * Remove item(content/record/record folder) from the hold * * @param user the user who removes the item from the hold * @param password the user's password @@ -242,7 +241,7 @@ public class HoldsAPI extends BaseAPI } /** - * Remove item (content/ record/ record folder) to the hold + * Remove item(content/record/record folder) to the hold * * @param user the user who adds the item to the hold * @param password the user's password @@ -259,7 +258,7 @@ public class HoldsAPI extends BaseAPI } /** - * Util method to remove item (content /record/ record folder) from hold and get the error message + * Util method to remove item(content/record/record folder) from hold and get the error message * * @param user the user who removes the item from hold * @param password the user's password diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/AddToHoldsTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/AddToHoldsTests.java index 5aa8ba4c45..c8f7d6c3ac 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/AddToHoldsTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/AddToHoldsTests.java @@ -221,12 +221,10 @@ public class AddToHoldsTests extends BaseRMRestTest public void addValidNodesToHoldWithAllowedUser(String nodeId) throws Exception { STEP("Add node to hold with user with permission."); - holdsAPI.addItemToHold(userAddHoldPermission.getUsername(), userAddHoldPermission.getPassword(), - nodeId, HOLD); + holdsAPI.addItemToHold(userAddHoldPermission.getUsername(), userAddHoldPermission.getPassword(), nodeId, HOLD); STEP("Check the node is frozen."); assertTrue(hasAspect(nodeId, FROZEN_ASPECT)); - } /** @@ -284,8 +282,7 @@ public class AddToHoldsTests extends BaseRMRestTest * @throws Exception */ @Test (dataProvider = "userWithoutPermissionForAddToHold") - public void addContentToHoldWithUserWithoutHoldPermission(UserModel userModel, String nodeToBeAddedToHold) throws - Exception + public void addContentToHoldWithUserWithoutHoldPermission(UserModel userModel, String nodeToBeAddedToHold) throws Exception { users.add(userModel); STEP("Add the node to the hold with user without permission."); @@ -295,10 +292,8 @@ public class AddToHoldsTests extends BaseRMRestTest STEP("Check the node is not frozen."); assertFalse(hasAspect(nodeToBeAddedToHold,FROZEN_ASPECT)); - } - /** * Data provider with invalid node types that can be added to a hold */ @@ -319,7 +314,7 @@ public class AddToHoldsTests extends BaseRMRestTest //transfer container { getTransferContainer(TRANSFERS_ALIAS).getId(), SC_BAD_REQUEST, INVALID_TYPE_ERROR_MESSAGE }, // a record category - { category.getId(), SC_INTERNAL_SERVER_ERROR, ACCESS_DENIED_ERROR_MESSAGE }, + { category.getId(), SC_BAD_REQUEST, INVALID_TYPE_ERROR_MESSAGE }, // unfiled records root { getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS).getId(), SC_BAD_REQUEST, INVALID_TYPE_ERROR_MESSAGE }, diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/PreventActionsOnFrozenContentTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/PreventActionsOnFrozenContentTests.java index 073615d483..71ea17ecd7 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/PreventActionsOnFrozenContentTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/PreventActionsOnFrozenContentTests.java @@ -80,7 +80,7 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest contentHeld = dataContent.usingAdmin().usingSite(testSite) .createContent(CMISUtil.DocumentType.TEXT_PLAIN); - STEP("Add the content to the hold."); + STEP("Add the file to the hold."); holdsAPI.addItemToHold(getAdminUser().getUsername(), getAdminUser().getPassword(), contentHeld .getNodeRefWithoutVersion(), HOLD_ONE); @@ -91,6 +91,7 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest folderModel = dataContent.usingAdmin().usingSite(testSite) .createFolder(); } + /** * Given active content on hold * When I try to edit the properties @@ -108,7 +109,6 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest STEP("Check the request failed."); restClient.assertStatusCodeIs(FORBIDDEN); restClient.assertLastError().containsSummary("Frozen nodes can not be updated."); - } /* @@ -126,8 +126,8 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest STEP("Check the request failed."); restClient.assertStatusCodeIs(FORBIDDEN); restClient.assertLastError().containsSummary("Frozen nodes can not be updated."); - } + /* * Given active content on hold * When I try to delete the content @@ -142,7 +142,6 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest STEP("Check the request failed."); restClient.assertStatusCodeIs(FORBIDDEN); restClient.assertLastError().containsSummary("Frozen nodes can not be deleted."); - } /** @@ -186,7 +185,6 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest { holdsAPI.deleteHold(getAdminUser().getUsername(), getAdminUser().getPassword(), HOLD_ONE); dataSite.usingAdmin().deleteSite(testSite); - } } diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/RemoveFromHoldsTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/RemoveFromHoldsTests.java index 7a13be3632..5c7bb07ff7 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/RemoveFromHoldsTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/RemoveFromHoldsTests.java @@ -104,7 +104,7 @@ public class RemoveFromHoldsTests extends BaseRMRestTest contentAddToManyHolds = dataContent.usingSite(testSite) .createContent(CMISUtil.DocumentType.TEXT_PLAIN); - STEP("Add the content to the holds."); + STEP("Add content to the holds."); holdsAPI.addItemToHold(getAdminUser().getUsername(), getAdminUser().getPassword(), contentHeld .getNodeRefWithoutVersion(), HOLD_ONE); holdsAPI.addItemToHold(getAdminUser().getUsername(), getAdminUser().getPassword(), contentAddToManyHolds @@ -194,7 +194,7 @@ public class RemoveFromHoldsTests extends BaseRMRestTest /** * Data provider with user without right permission or capability to remove from hold a specific node - * @return + * @return user model and the node ref to be removed from hold * @throws Exception */ @DataProvider (name = "userWithoutPermissionForRemoveFromHold") @@ -263,7 +263,6 @@ public class RemoveFromHoldsTests extends BaseRMRestTest STEP("Check node is frozen."); assertTrue(hasAspect(nodeIdToBeRemoved, FROZEN_ASPECT)); - } @AfterClass (alwaysRun = true) From 0a26da478bb7efd6006d0c5cb17f6da58f1e0ee0 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Thu, 22 Aug 2019 14:51:33 +0300 Subject: [PATCH 5/5] update the tests to allow remove from hold with a user with read permission, filling permission over the hold and remove from hold capabilities --- .../community/hold/RemoveFromHoldsTests.java | 121 +++++++++++++----- 1 file changed, 92 insertions(+), 29 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/RemoveFromHoldsTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/RemoveFromHoldsTests.java index 5c7bb07ff7..f0bacf4f6e 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/RemoveFromHoldsTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/hold/RemoveFromHoldsTests.java @@ -44,12 +44,15 @@ import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; import java.util.Arrays; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.alfresco.dataprep.CMISUtil; import org.alfresco.rest.rm.community.base.BaseRMRestTest; import org.alfresco.rest.rm.community.model.hold.HoldEntry; import org.alfresco.rest.rm.community.model.record.Record; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild; import org.alfresco.rest.rm.community.model.user.UserRoles; import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI; import org.alfresco.rest.v0.HoldsAPI; @@ -79,10 +82,11 @@ public class RemoveFromHoldsTests extends BaseRMRestTest private static final String ACCESS_DENIED_ERROR_MESSAGE = "Access Denied. You do not have the appropriate " + "permissions to perform this operation."; - private SiteModel testSite; + private SiteModel testSite, privateSite; private String holdNodeRefOne; private FileModel contentHeld, contentAddToManyHolds; - + private Set usersToBeClean = new HashSet<>(); + private Set nodesToBeClean = new HashSet<>(); @Autowired private HoldsAPI holdsAPI; @Autowired @@ -99,6 +103,7 @@ public class RemoveFromHoldsTests extends BaseRMRestTest STEP("Create test files."); testSite = dataSite.usingAdmin().createPublicRandomSite(); + privateSite = dataSite.usingAdmin().createPrivateRandomSite(); contentHeld = dataContent.usingSite(testSite) .createContent(CMISUtil.DocumentType.TEXT_PLAIN); contentAddToManyHolds = dataContent.usingSite(testSite) @@ -119,23 +124,23 @@ public class RemoveFromHoldsTests extends BaseRMRestTest public Object[][] getValidNodesToRemoveFromHold() throws Exception { //create electronic and nonElectronic record in record folder - String recordFolderId = createCategoryFolderInFilePlan().getId(); + RecordCategoryChild recordFolder = createCategoryFolderInFilePlan(); RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI(); - - Record electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolderId, getFile + nodesToBeClean.add(recordFolder.getParentId()); + Record electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolder.getId(), getFile (IMAGE_FILE)); assertStatusCode(CREATED); - Record nonElectronicRecord = recordFolderAPI.createRecord(createNonElectronicRecordModel(), recordFolderId); + Record nonElectronicRecord = recordFolderAPI.createRecord(createNonElectronicRecordModel(), recordFolder.getId()); assertStatusCode(CREATED); - String folderToHeld = createCategoryFolderInFilePlan().getId(); - - Arrays.asList(electronicRecord.getId(), nonElectronicRecord.getId(), folderToHeld).forEach(item -> + RecordCategoryChild folderToHeld = createCategoryFolderInFilePlan(); + nodesToBeClean.add(folderToHeld.getParentId()); + Arrays.asList(electronicRecord.getId(), nonElectronicRecord.getId(), folderToHeld.getId()).forEach(item -> holdsAPI.addItemToHold(getAdminUser().getUsername(), getAdminUser().getPassword(), item, HOLD_ONE)); return new String[][] { // record folder - { folderToHeld }, + { folderToHeld.getId() }, //electronic record { electronicRecord.getId() }, // non electronic record @@ -200,32 +205,25 @@ public class RemoveFromHoldsTests extends BaseRMRestTest @DataProvider (name = "userWithoutPermissionForRemoveFromHold") public Object[][] getUserWithoutPermissionForAddToHold() throws Exception { - //create electronic and nonElectronic record in record folder - String recordFolderId = createCategoryFolderInFilePlan().getId(); - UserModel user = roleService.createUserWithRMRoleAndRMNodePermission(ROLE_RM_MANAGER.roleId, recordFolderId, - PERMISSION_READ_RECORDS); + //create record folder + RecordCategoryChild recordFolder = createCategoryFolderInFilePlan(); + nodesToBeClean.add(recordFolder.getParentId()); + UserModel user = roleService.createUserWithRMRole(ROLE_RM_MANAGER.roleId); getRestAPIFactory().getRMUserAPI().addUserPermission(holdNodeRefOne, user, PERMISSION_FILING); //create files that will be removed from hold - FileModel contentNoPermission = dataContent.usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); FileModel contentNoHoldPerm = dataContent.usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); FileModel contentNoHoldCap = dataContent.usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); - + FileModel privateFile = dataContent.usingSite(privateSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); //add files to hold - Arrays.asList(recordFolderId, contentNoHoldCap.getNodeRefWithoutVersion(), - contentNoHoldPerm.getNodeRefWithoutVersion(), contentNoPermission.getNodeRefWithoutVersion()).forEach( + Arrays.asList(recordFolder.getId(), contentNoHoldCap.getNodeRefWithoutVersion(), + contentNoHoldPerm.getNodeRefWithoutVersion(), privateFile.getNodeRefWithoutVersion()).forEach( node -> holdsAPI.addItemToHold(getAdminUser().getUsername(), getAdminUser().getPassword(), node, HOLD_ONE) - ); - + ); return new Object[][] { - // user without write permission on the content - { - roleService.createUserWithSiteRoleRMRoleAndPermission(testSite, UserRole.SiteConsumer, - holdNodeRefOne, UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING), - contentNoPermission.getNodeRefWithoutVersion() - }, - // user with write permission on the content and without filling permission on a hold + // user with read permission on the content, with remove from hold capability and without + // filling permission on a hold { roleService.createUserWithSiteRoleRMRoleAndPermission(testSite, UserRole.SiteCollaborator, holdNodeRefOne, UserRoles.ROLE_RM_MANAGER, PERMISSION_READ_RECORDS), @@ -239,10 +237,15 @@ public class RemoveFromHoldsTests extends BaseRMRestTest holdNodeRefOne, UserRoles.ROLE_RM_POWER_USER, PERMISSION_FILING), contentNoHoldCap.getNodeRefWithoutVersion() }, - //user without write permission on RM record folder + //user without read permission on RM record folder { - user, recordFolderId + user, recordFolder.getId() }, + //user without read permission over the content from the private site + { + user, privateFile.getNodeRefWithoutVersion() + } + }; } @@ -256,6 +259,9 @@ public class RemoveFromHoldsTests extends BaseRMRestTest @Test (dataProvider = "userWithoutPermissionForRemoveFromHold") public void removeFromHoldWithUserWithoutPermission(UserModel userModel, String nodeIdToBeRemoved) throws Exception { + STEP("Update the list of users to be deleted after running the tests"); + usersToBeClean.add(userModel); + STEP("Remove node from hold with user without right permission or capability"); String responseNoHoldPermission = holdsAPI.removeFromHoldAndGetMessage(userModel.getUsername(), userModel.getPassword(), SC_INTERNAL_SERVER_ERROR, nodeIdToBeRemoved, HOLD_ONE); @@ -265,11 +271,68 @@ public class RemoveFromHoldsTests extends BaseRMRestTest assertTrue(hasAspect(nodeIdToBeRemoved, FROZEN_ASPECT)); } + /** + * Data provider with user with right permission or capability to remove from hold a specific node + * + * @return user model and the node ref to be removed from hold + * @throws Exception + */ + @DataProvider (name = "userWithPermissionForRemoveFromHold") + public Object[][] getUserWithPermissionForAddToHold() throws Exception + { + //create record folder + RecordCategoryChild recordFolder = createCategoryFolderInFilePlan(); + nodesToBeClean.add(recordFolder.getParentId()); + UserModel user = roleService.createUserWithRMRoleAndRMNodePermission(ROLE_RM_MANAGER.roleId, recordFolder.getId(), + PERMISSION_READ_RECORDS); + getRestAPIFactory().getRMUserAPI().addUserPermission(holdNodeRefOne, user, PERMISSION_FILING); + //create file that will be removed from hold + FileModel contentPermission = dataContent.usingSite(testSite).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + //add files to hold + Arrays.asList(recordFolder.getId(), contentPermission.getNodeRefWithoutVersion()).forEach( + node -> holdsAPI.addItemToHold(getAdminUser().getUsername(), getAdminUser().getPassword(), node, + HOLD_ONE) + ); + + return new Object[][] + { + // user with write permission on the content + { + roleService.createUserWithSiteRoleRMRoleAndPermission(testSite, UserRole.SiteConsumer, + holdNodeRefOne, UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING), + contentPermission.getNodeRefWithoutVersion() + }, + //user with read permission on RM record folder + { + user, recordFolder.getId() + }, + + }; + } + @Test (dataProvider = "userWithPermissionForRemoveFromHold") + public void removeFromHoldWithUserWithPermission(UserModel userModel, String nodeIdToBeRemoved) throws Exception + { + STEP("Update the list of users to be deleted after running the tests"); + usersToBeClean.add(userModel); + + STEP("Remove node from hold with user with right permission and capability"); + holdsAPI.removeItemFromHold(userModel.getUsername(), + userModel.getPassword(), nodeIdToBeRemoved, HOLD_ONE); + + STEP("Check node is not frozen."); + assertFalse(hasAspect(nodeIdToBeRemoved, FROZEN_ASPECT)); + } + @AfterClass (alwaysRun = true) public void cleanUpRemoveContentFromHold() throws Exception { holdsAPI.deleteHold(getAdminUser().getUsername(), getAdminUser().getPassword(), HOLD_ONE); holdsAPI.deleteHold(getAdminUser().getUsername(), getAdminUser().getPassword(), HOLD_TWO); dataSite.usingAdmin().deleteSite(testSite); + dataSite.usingAdmin().deleteSite(privateSite); + usersToBeClean.forEach(user -> getDataUser().usingAdmin().deleteUser(user)); + nodesToBeClean.forEach(category -> getRestAPIFactory().getRecordCategoryAPI().deleteRecordCategory(category)); + } }