From eade9c9e0fec1f8df7554b1feb32d00f7002e79c Mon Sep 17 00:00:00 2001 From: cagache Date: Fri, 8 Nov 2019 16:02:16 +0200 Subject: [PATCH] Delete hold using RM Actions API --- .../java/org/alfresco/rest/v0/HoldsAPI.java | 32 ++++++++++++++++++- .../community/audit/AuditDeleteHoldTests.java | 18 +++++------ 2 files changed, 40 insertions(+), 10 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 b5ef69b038..c16fd352c2 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 @@ -38,6 +38,7 @@ 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.model.UserModel; import org.apache.http.HttpResponse; import org.apache.http.ParseException; import org.json.JSONArray; @@ -144,7 +145,36 @@ public class HoldsAPI extends BaseAPI } /** - * Deletes hold + * Deletes hold using RM Actions API and expect action to be successful + * + * @param user the user who does the request + * @param holdNodeRef the hold node ref + * @return The HTTP Response or throws AssertionError if the request is not successful. + */ + public HttpResponse deleteHold(UserModel user, String holdNodeRef) + { + return deleteHold(user.getUsername(), user.getPassword(), holdNodeRef, SC_OK); + } + + /** + * Deletes hold using RM Actions API and expect a specific status code + * + * @param username user's username + * @param password its password + * @param holdNodeRef the hold node ref + * @return The HTTP Response or throws AssertionError if the returned status code is not as expected. + */ + public HttpResponse deleteHold(String username, String password, String holdNodeRef, int expectedStatusCode) + { + JSONObject requestParams = new JSONObject(); + requestParams.put("name", "deleteHold"); + requestParams.put("nodeRef", getNodeRefSpacesStore() + holdNodeRef); + + return doPostJsonRequest(username, password, expectedStatusCode, requestParams, RM_ACTIONS_API); + } + + /** + * Deletes hold using cmis * * @param username user's username * @param password its password diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/audit/AuditDeleteHoldTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/audit/AuditDeleteHoldTests.java index bcc535410e..b22a71b215 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/audit/AuditDeleteHoldTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/audit/AuditDeleteHoldTests.java @@ -32,9 +32,8 @@ 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.audit.AuditEvents.DELETE_HOLD; import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix; -import static org.alfresco.rest.rm.community.utils.CoreUtil.toContentModel; import static org.alfresco.utility.report.log.Step.STEP; -import static org.springframework.http.HttpStatus.FORBIDDEN; +import static org.apache.commons.httpclient.HttpStatus.SC_INTERNAL_SERVER_ERROR; import static org.testng.AssertJUnit.assertTrue; import java.util.Collections; @@ -100,12 +99,13 @@ public class AuditDeleteHoldTests extends BaseRMRestTest public void deleteHoldEventIsAudited() { STEP("Create a new hold."); - holdsAPI.createHold(rmAdmin.getUsername(), rmAdmin.getPassword(), HOLD2, HOLD_REASON, HOLD_DESCRIPTION); + String holdRef = holdsAPI.createHoldAndGetNodeRef(rmAdmin.getUsername(), rmAdmin.getPassword(), HOLD2, + HOLD_REASON, HOLD_DESCRIPTION); rmAuditService.clearAuditLog(); STEP("Delete the created hold."); - holdsAPI.deleteHold(rmAdmin.getUsername(), rmAdmin.getPassword(), HOLD2); + holdsAPI.deleteHold(rmAdmin, holdRef); STEP("Check the audit log contains the entry for the deleted hold with the hold details."); rmAuditService.checkAuditLogForEvent(getAdminUser(), DELETE_HOLD, rmAdmin, HOLD2, @@ -118,13 +118,12 @@ public class AuditDeleteHoldTests extends BaseRMRestTest * Then the delete hold event isn't audited */ @Test - public void unsuccessfulDeleteHoldIsNotAudited() throws Exception + public void unsuccessfulDeleteHoldIsNotAudited() { rmAuditService.clearAuditLog(); STEP("Try to delete a hold by an user with no Read permissions over the hold."); - getRestAPIFactory().getNodeAPI(rmManager, toContentModel(holdNodeRef)).deleteNode(holdNodeRef); - assertStatusCode(FORBIDDEN); + holdsAPI.deleteHold(rmManager.getUsername(), rmManager.getPassword(), holdNodeRef, SC_INTERNAL_SERVER_ERROR); STEP("Check the audit log doesn't contain the entry for the unsuccessful delete hold."); assertTrue("The list of events should not contain Delete Hold entry ", @@ -140,12 +139,13 @@ public class AuditDeleteHoldTests extends BaseRMRestTest public void deleteHoldAuditEntryNotVisible() { STEP("Create a new hold."); - holdsAPI.createHold(rmAdmin.getUsername(), rmAdmin.getPassword(), HOLD2, HOLD_REASON, HOLD_DESCRIPTION); + String holdRef = holdsAPI.createHoldAndGetNodeRef(rmAdmin.getUsername(), rmAdmin.getPassword(), HOLD2, HOLD_REASON, + HOLD_DESCRIPTION); rmAuditService.clearAuditLog(); STEP("Delete the created hold."); - holdsAPI.deleteHold(rmAdmin.getUsername(), rmAdmin.getPassword(), HOLD2); + holdsAPI.deleteHold(rmAdmin, holdRef); STEP("Check that an user with no Read permissions over the hold can't see the entry for the delete hold event."); assertTrue("The list of events should not contain Delete Hold entry ",