From 11a638c827e781838229b2b26aadb265557be772 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Tue, 2 Jul 2019 10:29:21 +0300 Subject: [PATCH] refactoring of the added rest api tests for SQL queries new tests added for sql queries for: record categories, record folders and records --- .../requests/gscore/api/RMUserAPI.java | 111 ++++++++++++------ .../rest/v0/RMRolesAndActionsAPI.java | 37 +++++- .../src/test/resources/log4j.properties | 7 ++ 3 files changed, 116 insertions(+), 39 deletions(-) create mode 100644 rm-automation/rm-automation-community-rest-api/src/test/resources/log4j.properties diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java index d24c53c614..2466211a55 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java @@ -84,6 +84,7 @@ public class RMUserAPI extends RMModelRequest /** * Assign RM role to user + * * @param userName User's username * @param userRole User's RM role, one of {@link UserRoles} roles * @throws Exception for failed requests @@ -97,29 +98,30 @@ public class RMUserAPI extends RMModelRequest // override v1 baseURI and basePath RequestSpecification spec = new RequestSpecBuilder() - .setBaseUri(client.getApiUrl()) - .setBasePath("/") - .build(); + .setBaseUri(client.getApiUrl()) + .setBasePath("/") + .build(); Response response = given() - .spec(spec) - .log().all() - .pathParam("role", userRole) - .pathParam("authority", userName) - .param("alf_ticket", client.getAlfTicket(adminUser.getUsername(), - adminUser.getPassword())) - .when() - .post("/rm/roles/{role}/authorities/{authority}") - .prettyPeek() - .andReturn(); + .spec(spec) + .log().all() + .pathParam("role", userRole) + .pathParam("authority", userName) + .param("alf_ticket", client.getAlfTicket(adminUser.getUsername(), + adminUser.getPassword())) + .when() + .post("/rm/roles/{role}/authorities/{authority}") + .prettyPeek() + .andReturn(); getRmRestWrapper().setStatusCode(Integer.toString(response.getStatusCode())); } /** * Helper method to add permission on a component to user - * @param component The id of the file plan component on which permission should be given - * @param user {@link UserModel} for a user to be granted permission - * @param permission {@link UserPermissions} to be granted + * + * @param filePlanComponentId The id of the file plan component on which permission should be given + * @param user {@link UserModel} for a user to be granted permission + * @param permission {@link UserPermissions} to be granted */ public void addUserPermission(String filePlanComponentId, UserModel user, String permission) { @@ -129,34 +131,75 @@ public class RMUserAPI extends RMModelRequest AlfrescoHttpClient client = getAlfrescoHttpClient(); JsonObject bodyJson = buildObject() - .addArray("permissions") + .addArray("permissions") .addObject() - .add("authority", user.getUsername()) - .add("role", permission) - .end() - .getJson(); + .add("authority", (user != null ? user.getUsername() : null)) + .add("role", permission) + .end() + .getJson(); // override v1 baseURI and basePath RequestSpecification spec = new RequestSpecBuilder() - .setBaseUri(client.getApiUrl()) - .setBasePath("/") - .build(); + .setBaseUri(client.getApiUrl()) + .setBasePath("/") + .build(); // execute an "old-style" API call Response response = given() - .spec(spec) - .auth().basic(adminUser.getUsername(), adminUser.getPassword()) - .contentType(ContentType.JSON) - .body(bodyJson.toString()) - .pathParam("nodeId", filePlanComponentId) - .log().all() - .when() - .post("/node/workspace/SpacesStore/{nodeId}/rmpermissions") - .prettyPeek() - .andReturn(); + .spec(spec) + .auth().basic(adminUser.getUsername(), adminUser.getPassword()) + .contentType(ContentType.JSON) + .body(bodyJson.toString()) + .pathParam("nodeId", filePlanComponentId) + .log().all() + .when() + .post("/node/workspace/SpacesStore/{nodeId}/rmpermissions") + .prettyPeek() + .andReturn(); getRmRestWrapper().setStatusCode(Integer.toString(response.getStatusCode())); } + /** + * Helper method to add permission on a component to user + * + * @param filePlanComponentId The id of the file plan component on which permission should be given + * @param permission {@link UserPermissions} to be granted + */ + public void setUserPermissionInheritance(String filePlanComponentId, Boolean isInherited) + { + UserModel adminUser = getRmRestWrapper().getTestUser(); + + // get an "old-style" REST API client + AlfrescoHttpClient client = getAlfrescoHttpClient(); + + JsonObject bodyJson = buildObject() + .addArray("permissions") + .end() + .add("isInherited", isInherited) + .getJson(); + + // override v1 baseURI and basePath + RequestSpecification spec = new RequestSpecBuilder() + .setBaseUri(client.getApiUrl()) + .setBasePath("/") + .build(); + + // execute an "old-style" API call + Response response = given() + .spec(spec) + .auth().basic(adminUser.getUsername(), adminUser.getPassword()) + .contentType(ContentType.JSON) + .body(bodyJson.toString()) + .pathParam("nodeId", filePlanComponentId) + .log().all() + .when() + .post("/node/workspace/SpacesStore/{nodeId}/rmpermissions") + .prettyPeek() + .andReturn(); + getRmRestWrapper().setStatusCode(Integer.toString(response.getStatusCode())); + } + + /** * Creates a user with the given name using the old APIs * 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 6f07fcf3ab..3be051a3d2 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 @@ -48,6 +48,7 @@ import org.alfresco.dataprep.ContentService; 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; @@ -73,6 +74,8 @@ 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. */ @@ -83,6 +86,8 @@ public class RMRolesAndActionsAPI extends BaseAPI 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 @@ -447,9 +452,9 @@ public class RMRolesAndActionsAPI extends BaseAPI 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 - String holdsContainerPath = getFilePlanPath() + "/Holds"; - String fullHoldPath = holdsContainerPath + "/" + holdName; - CmisObject hold = getObjectByPath(user, password, fullHoldPath); + final String holdsContainerPath = Utility.buildPath(getFilePlanPath(), HOLDS_CONTAINER); + final String fullHoldPath = holdsContainerPath + holdName; + final CmisObject hold = getObjectByPath(user, password, fullHoldPath); if (hold != null) { return null; @@ -457,19 +462,41 @@ public class RMRolesAndActionsAPI extends BaseAPI // retrieve the Holds container nodeRef String parentNodeRef = getItemNodeRef(user, password, "/Holds"); - JSONObject requestParams = new JSONObject(); + 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. - HttpResponse httpResponse = doPostJsonRequest(user, password, SC_OK, requestParams, CREATE_HOLDS_API); + 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/test/resources/log4j.properties b/rm-automation/rm-automation-community-rest-api/src/test/resources/log4j.properties new file mode 100644 index 0000000000..93c931c03c --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/test/resources/log4j.properties @@ -0,0 +1,7 @@ +log4j.rootLogger=info, console + +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n + +log4j.logger.com.example=debug \ No newline at end of file