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 4757b508ad..af7f204e97 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 @@ -26,8 +26,6 @@ */ package org.alfresco.rest.v0; -import static java.util.stream.Collectors.toSet; - import static org.alfresco.dataprep.AlfrescoHttpClient.MIME_TYPE_JSON; import static org.apache.http.HttpStatus.SC_OK; import static org.testng.AssertJUnit.assertEquals; @@ -40,7 +38,6 @@ import java.text.MessageFormat; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.Arrays; -import java.util.Collection; import java.util.Map; import java.util.Set; @@ -99,16 +96,30 @@ public class RMRolesAndActionsAPI extends BaseAPI * * @param adminUser The RM admin user. * @param adminPassword The password of the user. - * @return The display labels of the RM roles in the system. + * @return The RM roles in the system (Note that this will be the internal names, not the display labels). */ public Set getConfiguredRoles(String adminUser, String adminPassword) { - JSONObject jsonObject = doGetRequest(adminUser, adminPassword, RM_ROLES); - Collection dataValues = jsonObject.getJSONObject("data").toMap().values(); - return dataValues.stream().filter(v -> v instanceof Map).map(v -> (String) ((Map) v).get("displayLabel")) - .collect(toSet()); + JSONObject jsonObject = doGetRequest(adminUser, adminPassword, RM_ROLES).getJSONObject("data"); + return jsonObject.toMap().keySet(); } + /** + * Get the capabilities for a given role. + * + * @param adminUser The RM admin user. + * @param adminPassword The password of the user. + * @param role The role to get capabilities for. + * @return The set of system names for the capabilities. + */ + public Set getCapabilitiesForRole(String adminUser, String adminPassword, String role) + { + JSONObject jsonObject = doGetRequest(adminUser, adminPassword, RM_ROLES).getJSONObject("data"); + assertTrue("Could not find role '" + role + "' in " + jsonObject.keySet(), jsonObject.has(role)); + return jsonObject.getJSONObject(role).getJSONObject("capabilities").keySet(); + } + + /** * create user and assign to records management role */ diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rmroles/RMRolesTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rmroles/RMRolesTests.java index cc72c61a28..d064db90ee 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rmroles/RMRolesTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rmroles/RMRolesTests.java @@ -29,6 +29,7 @@ package org.alfresco.rest.rm.community.rmroles; import static com.google.common.collect.Sets.newHashSet; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.Set; @@ -46,10 +47,11 @@ import org.testng.annotations.Test; */ public class RMRolesTests extends BaseRMRestTest { - /** The display labels of the expected default RM roles. */ - private static final Set ROLES = newHashSet("Records Management Administrator", - "Records Management Manager", "Records Management Power User", "Records Management Security Officer", - "Records Management User"); + /** The name of the RM user role. */ + private static final String RM_USER = "User"; + /** The names of the expected default RM roles. */ + private static final Set ROLES = newHashSet("Administrator", "RecordsManager", "PowerUser", + "SecurityOfficer", RM_USER); /** The API for managing RM roles and capabilities. */ @Autowired private RMRolesAndActionsAPI rmRolesAndActionsAPI; @@ -62,4 +64,14 @@ public class RMRolesTests extends BaseRMRestTest .getConfiguredRoles(getAdminUser().getUsername(), getAdminUser().getPassword()); ROLES.forEach(role -> assertTrue("Could not found role " + role, configuredRoles.contains(role))); } + + /** Check that the RM user has the capability to view and declare records. */ + @Test(description = "Check the capabilities for the RM user.") + public void checkCapabilitiesForUser() + { + Set capabilities = rmRolesAndActionsAPI + .getCapabilitiesForRole(getAdminUser().getUsername(), getAdminUser().getPassword(), RM_USER); + assertEquals("Unexpected capabilities found for RM User.", capabilities, + newHashSet("ViewRecords", "DeclareRecords")); + } }