From f6dd63519f3da057e4636c88aa529420d7e3abeb Mon Sep 17 00:00:00 2001 From: cagache Date: Wed, 4 Sep 2019 16:20:43 +0300 Subject: [PATCH 1/3] RM-6918 View legal holds content UI tests --- .../java/org/alfresco/rest/v0/HoldsAPI.java | 76 ++++++++++--------- 1 file changed, 39 insertions(+), 37 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 1c0a17dd1f..4dec2955a6 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 @@ -31,7 +31,7 @@ import static org.apache.http.HttpStatus.SC_OK; import static org.testng.AssertJUnit.assertNotNull; import java.text.MessageFormat; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -165,22 +165,23 @@ public class HoldsAPI extends BaseAPI */ public HttpResponse addItemToHold(String user, String password, String itemNodeRef, String holdName) { - return addItemToHold(user, password, SC_OK, itemNodeRef, holdName); + return addItemsToHolds(user, password, SC_OK, Collections.singletonList(itemNodeRef), + Collections.singletonList(holdName)); } /** - * Adds item(content/record/record folder) to the hold + * Adds a list of items (content/record/record folder) to a list of holds * - * @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 + * @param user the user who adds the item to the hold + * @param password the user's password + * @param itemNodeRefs the list of items nodeRefs to be added to holds + * @param holdNames the list of holds * @return The HTTP response */ - public HttpResponse addItemToHold(String user, String password, int expectedStatus, String itemNodeRef, - String holdName) + public HttpResponse addItemsToHolds(String user, String password, int expectedStatus, List itemNodeRefs, + List holdNames) { - final JSONObject requestParams = addOrRemoveToFromHoldJsonObject(user, password, itemNodeRef, holdName); + final JSONObject requestParams = addOrRemoveToFromHoldJsonObject(user, password, itemNodeRefs, holdNames); return doPostJsonRequest(user, password, expectedStatus, requestParams, RM_HOLDS_API); } @@ -196,30 +197,29 @@ public class HoldsAPI extends BaseAPI public String addToHoldAndGetMessage(String user, String password, int expectedStatus, String itemNodeRef, String holdName) { - final HttpResponse httpResponse = addItemToHold(user, password, expectedStatus, itemNodeRef, holdName); + final HttpResponse httpResponse = addItemsToHolds(user, password, expectedStatus, Collections.singletonList(itemNodeRef), + Collections.singletonList(holdName)); return APIUtils.extractErrorMessageFromHttpResponse(httpResponse); } /** - * Util method to create the request body used when adding an item to holds or when removing an item from holds + * Util method to create the request body used when adding items to holds or when removing items from holds * - * @param user user to create the request body for add/remove an item to/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 + * @param items list of items node refs to be added to holds + * @param holdNames list of hold names for add/remove items * @return JSONObject fo */ - private JSONObject addOrRemoveToFromHoldJsonObject(String user, String password, String itemNodeRef, String holdName) + private JSONObject addOrRemoveToFromHoldJsonObject(String user, String password, List items, List holdNames) { - - final JSONArray nodeRefs = new JSONArray().put(getNodeRefSpacesStore() + itemNodeRef); - final List holdNames = Arrays.asList(holdName.split(",")); - final List holdNoderefs = holdNames.stream().map(hold -> - + final JSONArray nodeRefs = new JSONArray(); + items.forEach(itemNodeRef -> nodeRefs.put(getNodeRefSpacesStore() + itemNodeRef)); + final List holdNodeRefs = holdNames.stream().map(hold -> getNodeRefSpacesStore() + getItemNodeRef(user, password, String.format("/%s/%s", HOLDS_CONTAINER, hold))) - .collect(Collectors.toList()); + .collect(Collectors.toList()); final JSONArray holds = new JSONArray(); - holdNoderefs.forEach(holds::put); + holdNodeRefs.forEach(holds::put); final JSONObject requestParams = new JSONObject(); requestParams.put("nodeRefs", nodeRefs); requestParams.put("holds", holds); @@ -227,33 +227,34 @@ public class HoldsAPI extends BaseAPI } /** - * Remove item(content/record/record folder) from the hold + * Remove item(content/record/record folder) from 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 itemNodeRef the nodeRef of the item to be removed from 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); + return removeItemsFromHolds(user, password, SC_OK, Collections.singletonList(itemNodeRef), + Collections.singletonList(holdName)); } /** - * Remove item(content/record/record folder) to the hold + * Remove a list of items (content/record/record folder) from a list of holds * - * @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 + * @param user the user who removes the item from the hold + * @param password the user's password + * @param expectedStatus https status code expected + * @param itemNodeRefs the list of items nodeRefs to be removed from hold + * @param holdNames the list of hold names * @return The HTTP response */ - public HttpResponse removeItemFromHold(String user, String password, int expectedStatus, String itemNodeRef, String - holdName) + public HttpResponse removeItemsFromHolds(String user, String password, int expectedStatus, List itemNodeRefs, + List holdNames) { - final JSONObject requestParams = addOrRemoveToFromHoldJsonObject(user, password, itemNodeRef, holdName); + final JSONObject requestParams = addOrRemoveToFromHoldJsonObject(user, password, itemNodeRefs, holdNames); return doPutJsonRequest(user, password, expectedStatus, requestParams, RM_HOLDS_API); } @@ -262,14 +263,15 @@ public class HoldsAPI extends BaseAPI * * @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 itemNodeRef the nodeRef of the item to be removed from 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); + final HttpResponse httpResponse = removeItemsFromHolds(user, password, expectedStatus, Collections.singletonList(itemNodeRef), + Collections.singletonList(holdName)); return APIUtils.extractErrorMessageFromHttpResponse(httpResponse); } From d9300606ec96fe3c303852a72f5f32cdd2800139 Mon Sep 17 00:00:00 2001 From: cagache Date: Thu, 5 Sep 2019 10:26:58 +0300 Subject: [PATCH 2/3] RM-6918 View legal holds content UI tests --- .../java/org/alfresco/rest/v0/HoldsAPI.java | 34 +++++++++++++++++-- .../community/hold/RemoveFromHoldsTests.java | 33 +++++++++--------- 2 files changed, 48 insertions(+), 19 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 4dec2955a6..ae4cf38213 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 @@ -127,7 +127,7 @@ public class HoldsAPI extends BaseAPI try { return convertHTTPResponseToJSON(httpResponse).getString("persistedObject") - .replaceAll(NODE_REF_WORKSPACE_SPACES_STORE, ""); + .replace(NODE_REF_WORKSPACE_SPACES_STORE, ""); } catch(JSONException error) { @@ -172,7 +172,22 @@ public class HoldsAPI extends BaseAPI /** * Adds a list of items (content/record/record folder) to a list of holds * - * @param user the user who adds the item to the hold + * @param user the user who adds the items to the holds + * @param password the user's password + * @param itemNodeRefs the list of items nodeRefs to be added to holds + * @param holdNames the list of holds + * @return The HTTP response + */ + public HttpResponse addItemsToHolds(String user, String password, List itemNodeRefs, + List holdNames) + { + return addItemsToHolds(user, password, SC_OK, itemNodeRefs, holdNames); + } + + /** + * Adds a list of items (content/record/record folder) to a list of holds + * + * @param user the user who adds the items to the holds * @param password the user's password * @param itemNodeRefs the list of items nodeRefs to be added to holds * @param holdNames the list of holds @@ -241,6 +256,21 @@ public class HoldsAPI extends BaseAPI Collections.singletonList(holdName)); } + /** + * Remove a list of items (content/record/record folder) from a list of holds + * + * @param user the user who removes the item from the hold + * @param password the user's password + * @param itemNodeRefs the list of items nodeRefs to be removed from hold + * @param holdNames the list of hold names + * @return The HTTP response + */ + public HttpResponse removeItemsFromHolds(String user, String password, List itemNodeRefs, + List holdNames) + { + return removeItemsFromHolds(user, password, SC_OK, itemNodeRefs, holdNames); + } + /** * Remove a list of items (content/record/record folder) from a list of holds * 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 f0bacf4f6e..6021842bc2 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 @@ -26,6 +26,8 @@ */ package org.alfresco.rest.rm.community.hold; +import static java.util.Arrays.asList; + 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; @@ -43,7 +45,7 @@ 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.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -112,16 +114,15 @@ public class RemoveFromHoldsTests extends BaseRMRestTest STEP("Add content to the holds."); 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)); - + holdsAPI.addItemsToHolds(getAdminUser().getUsername(), getAdminUser().getPassword(), + Collections.singletonList(contentAddToManyHolds.getNodeRefWithoutVersion()), asList(HOLD_ONE, HOLD_TWO)); } /** * Valid nodes to be removed from hold */ @DataProvider (name = "validNodesToRemoveFromHold") - public Object[][] getValidNodesToRemoveFromHold() throws Exception + public Object[][] getValidNodesToRemoveFromHold() { //create electronic and nonElectronic record in record folder RecordCategoryChild recordFolder = createCategoryFolderInFilePlan(); @@ -135,8 +136,8 @@ public class RemoveFromHoldsTests extends BaseRMRestTest 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)); + holdsAPI.addItemsToHolds(getAdminUser().getUsername(), getAdminUser().getPassword(), + asList(electronicRecord.getId(), nonElectronicRecord.getId(), folderToHeld.getId()), Collections.singletonList(HOLD_ONE)); return new String[][] { // record folder @@ -215,11 +216,11 @@ public class RemoveFromHoldsTests extends BaseRMRestTest 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(recordFolder.getId(), contentNoHoldCap.getNodeRefWithoutVersion(), - contentNoHoldPerm.getNodeRefWithoutVersion(), privateFile.getNodeRefWithoutVersion()).forEach( - node -> holdsAPI.addItemToHold(getAdminUser().getUsername(), getAdminUser().getPassword(), node, - HOLD_ONE) - ); + holdsAPI.addItemsToHolds(getAdminUser().getUsername(), getAdminUser().getPassword(), + asList(recordFolder.getId(), contentNoHoldCap.getNodeRefWithoutVersion(), + contentNoHoldPerm.getNodeRefWithoutVersion(), privateFile.getNodeRefWithoutVersion()), + Collections.singletonList(HOLD_ONE)); + return new Object[][] { // user with read permission on the content, with remove from hold capability and without @@ -290,10 +291,8 @@ public class RemoveFromHoldsTests extends BaseRMRestTest 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) - ); + holdsAPI.addItemsToHolds(getAdminUser().getUsername(), getAdminUser().getPassword(), + asList(recordFolder.getId(), contentPermission.getNodeRefWithoutVersion()), Collections.singletonList(HOLD_ONE)); return new Object[][] { @@ -325,7 +324,7 @@ public class RemoveFromHoldsTests extends BaseRMRestTest } @AfterClass (alwaysRun = true) - public void cleanUpRemoveContentFromHold() throws Exception + public void cleanUpRemoveContentFromHold() { holdsAPI.deleteHold(getAdminUser().getUsername(), getAdminUser().getPassword(), HOLD_ONE); holdsAPI.deleteHold(getAdminUser().getUsername(), getAdminUser().getPassword(), HOLD_TWO); From 2ea8180a79b7eed3c67dfc6ff4e7f9ff1a81bddf Mon Sep 17 00:00:00 2001 From: cagache Date: Fri, 6 Sep 2019 08:50:49 +0300 Subject: [PATCH 3/3] Code review comments --- .../src/main/java/org/alfresco/rest/v0/HoldsAPI.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 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 ae4cf38213..113eb01cb5 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 @@ -165,8 +165,7 @@ public class HoldsAPI extends BaseAPI */ public HttpResponse addItemToHold(String user, String password, String itemNodeRef, String holdName) { - return addItemsToHolds(user, password, SC_OK, Collections.singletonList(itemNodeRef), - Collections.singletonList(holdName)); + return addItemsToHolds(user, password, Collections.singletonList(itemNodeRef), Collections.singletonList(holdName)); } /** @@ -178,8 +177,7 @@ public class HoldsAPI extends BaseAPI * @param holdNames the list of holds * @return The HTTP response */ - public HttpResponse addItemsToHolds(String user, String password, List itemNodeRefs, - List holdNames) + public HttpResponse addItemsToHolds(String user, String password, List itemNodeRefs, List holdNames) { return addItemsToHolds(user, password, SC_OK, itemNodeRefs, holdNames); } @@ -252,8 +250,7 @@ public class HoldsAPI extends BaseAPI */ public HttpResponse removeItemFromHold(String user, String password, String itemNodeRef, String holdName) { - return removeItemsFromHolds(user, password, SC_OK, Collections.singletonList(itemNodeRef), - Collections.singletonList(holdName)); + return removeItemsFromHolds(user, password, Collections.singletonList(itemNodeRef), Collections.singletonList(holdName)); } /** @@ -265,8 +262,7 @@ public class HoldsAPI extends BaseAPI * @param holdNames the list of hold names * @return The HTTP response */ - public HttpResponse removeItemsFromHolds(String user, String password, List itemNodeRefs, - List holdNames) + public HttpResponse removeItemsFromHolds(String user, String password, List itemNodeRefs, List holdNames) { return removeItemsFromHolds(user, password, SC_OK, itemNodeRefs, holdNames); }