Delete hold using RM Actions API

This commit is contained in:
cagache
2019-11-08 16:02:16 +02:00
parent 100944ac36
commit eade9c9e0f
2 changed files with 40 additions and 10 deletions

View File

@@ -38,6 +38,7 @@ import org.alfresco.rest.core.v0.APIUtils;
import org.alfresco.rest.core.v0.BaseAPI; import org.alfresco.rest.core.v0.BaseAPI;
import org.alfresco.rest.rm.community.model.hold.HoldEntry; import org.alfresco.rest.rm.community.model.hold.HoldEntry;
import org.alfresco.rest.rm.community.util.PojoUtility; import org.alfresco.rest.rm.community.util.PojoUtility;
import org.alfresco.utility.model.UserModel;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.ParseException; import org.apache.http.ParseException;
import org.json.JSONArray; 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 username user's username
* @param password its password * @param password its password

View File

@@ -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.base.TestData.HOLD_REASON;
import static org.alfresco.rest.rm.community.model.audit.AuditEvents.DELETE_HOLD; 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.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.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 static org.testng.AssertJUnit.assertTrue;
import java.util.Collections; import java.util.Collections;
@@ -100,12 +99,13 @@ public class AuditDeleteHoldTests extends BaseRMRestTest
public void deleteHoldEventIsAudited() public void deleteHoldEventIsAudited()
{ {
STEP("Create a new hold."); 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(); rmAuditService.clearAuditLog();
STEP("Delete the created hold."); 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."); STEP("Check the audit log contains the entry for the deleted hold with the hold details.");
rmAuditService.checkAuditLogForEvent(getAdminUser(), DELETE_HOLD, rmAdmin, HOLD2, rmAuditService.checkAuditLogForEvent(getAdminUser(), DELETE_HOLD, rmAdmin, HOLD2,
@@ -118,13 +118,12 @@ public class AuditDeleteHoldTests extends BaseRMRestTest
* Then the delete hold event isn't audited * Then the delete hold event isn't audited
*/ */
@Test @Test
public void unsuccessfulDeleteHoldIsNotAudited() throws Exception public void unsuccessfulDeleteHoldIsNotAudited()
{ {
rmAuditService.clearAuditLog(); rmAuditService.clearAuditLog();
STEP("Try to delete a hold by an user with no Read permissions over the hold."); STEP("Try to delete a hold by an user with no Read permissions over the hold.");
getRestAPIFactory().getNodeAPI(rmManager, toContentModel(holdNodeRef)).deleteNode(holdNodeRef); holdsAPI.deleteHold(rmManager.getUsername(), rmManager.getPassword(), holdNodeRef, SC_INTERNAL_SERVER_ERROR);
assertStatusCode(FORBIDDEN);
STEP("Check the audit log doesn't contain the entry for the unsuccessful delete hold."); 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 ", assertTrue("The list of events should not contain Delete Hold entry ",
@@ -140,12 +139,13 @@ public class AuditDeleteHoldTests extends BaseRMRestTest
public void deleteHoldAuditEntryNotVisible() public void deleteHoldAuditEntryNotVisible()
{ {
STEP("Create a new hold."); 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(); rmAuditService.clearAuditLog();
STEP("Delete the created hold."); 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."); 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 ", assertTrue("The list of events should not contain Delete Hold entry ",