From 48b26d6b224869e29e9a0260ff0f32b3c9c532f8 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Wed, 28 Feb 2018 15:52:53 +0000 Subject: [PATCH 1/4] RM-6129 Add test for pre-configured RM roles. --- .../rest/v0/RMRolesAndActionsAPI.java | 21 ++++++ .../rm/community/rmroles/RMRolesTests.java | 65 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rmroles/RMRolesTests.java 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 d2f664e73c..4757b508ad 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,6 +26,8 @@ */ 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; @@ -38,7 +40,9 @@ 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; import org.alfresco.dataprep.AlfrescoHttpClient; import org.alfresco.dataprep.AlfrescoHttpClientFactory; @@ -70,6 +74,8 @@ import org.springframework.stereotype.Component; @Component public class RMRolesAndActionsAPI extends BaseAPI { + /** The URI to view the configured roles and capabilities. Using is=true includes the in-place readers and writers. */ + private static final String RM_ROLES = "{0}rma/admin/rmroles?is=true"; private static final String RM_ROLES_AUTHORITIES = "{0}rm/roles/{1}/authorities/{2}?alf_ticket={3}"; // logger @@ -88,6 +94,21 @@ public class RMRolesAndActionsAPI extends BaseAPI @Autowired private ContentService contentService; + /** + * Get all the configured RM roles. + * + * @param adminUser The RM admin user. + * @param adminPassword The password of the user. + * @return The display labels of the RM roles in the system. + */ + 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()); + } + /** * 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 new file mode 100644 index 0000000000..cc72c61a28 --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/rmroles/RMRolesTests.java @@ -0,0 +1,65 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2018 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.rest.rm.community.rmroles; + +import static com.google.common.collect.Sets.newHashSet; + +import static org.junit.Assert.assertTrue; + +import java.util.Set; + +import org.alfresco.rest.rm.community.base.BaseRMRestTest; +import org.alfresco.rest.v0.RMRolesAndActionsAPI; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.Test; + +/** + * API tests of RM roles. + * + * @author Tom Page + * @since 2.7 + */ +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 API for managing RM roles and capabilities. */ + @Autowired + private RMRolesAndActionsAPI rmRolesAndActionsAPI; + + /** Check that the roles API returns the default RM roles. */ + @Test(description = "Check the default RM roles exist.") + public void checkRMRolesExist() + { + Set configuredRoles = rmRolesAndActionsAPI + .getConfiguredRoles(getAdminUser().getUsername(), getAdminUser().getPassword()); + ROLES.forEach(role -> assertTrue("Could not found role " + role, configuredRoles.contains(role))); + } +} From d22362e3c3755f3d6831620ba26beef03ea2b877 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Wed, 28 Feb 2018 16:26:27 +0000 Subject: [PATCH 2/4] RM-6129 Add test for capabilities of the RM user. --- .../rest/v0/RMRolesAndActionsAPI.java | 27 +++++++++++++------ .../rm/community/rmroles/RMRolesTests.java | 20 +++++++++++--- 2 files changed, 35 insertions(+), 12 deletions(-) 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")); + } } From 16fafb426234daaf193a88a024d6bb498540e195 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Fri, 2 Mar 2018 09:13:00 +0000 Subject: [PATCH 3/4] RM-6129 Add API tests for creating and editing RM roles. --- .../org/alfresco/rest/core/v0/BaseAPI.java | 79 +++++++++++++++++-- .../rest/v0/RMRolesAndActionsAPI.java | 48 ++++++++++- .../rm/community/rmroles/RMRolesTests.java | 44 ++++++++++- 3 files changed, 161 insertions(+), 10 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java index 4feb2dac87..1b71e49e80 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java @@ -310,6 +310,78 @@ public abstract class BaseAPI } } + /** + * Helper method for PUT requests + * + * @param adminUser user with administrative privileges + * @param adminPassword password for adminUser + * @param expectedStatusCode The expected return status code. + * @param requestParams zero or more endpoint specific request parameters + * @param urlTemplate request URL template + * @param urlTemplateParams zero or more parameters used with urlTemplate + */ + protected HttpResponse doPutJsonRequest(String adminUser, + String adminPassword, + int expectedStatusCode, + JSONObject requestParams, + String urlTemplate, + String... urlTemplateParams) + { + AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); + return doPutJsonRequest(adminUser, adminPassword, expectedStatusCode, client.getApiUrl(), requestParams, urlTemplate, urlTemplateParams); + } + + /** + * Helper method for PUT requests + * + * @param adminUser user with administrative privileges + * @param adminPassword password for adminUser + * @param expectedStatusCode The expected return status code. + * @param urlStart the start of the URL (for example "alfresco/s/slingshot"). + * @param requestParams zero or more endpoint specific request parameters + * @param urlTemplate request URL template + * @param urlTemplateParams zero or more parameters used with urlTemplate + * @throws AssertionError if the returned status code is not as expected. + */ + private HttpResponse doPutJsonRequest(String adminUser, + String adminPassword, + int expectedStatusCode, + String urlStart, + JSONObject requestParams, + String urlTemplate, + String... urlTemplateParams) + { + String requestUrl = formatRequestUrl(urlStart, urlTemplate, urlTemplateParams); + try + { + HttpResponse httpResponse = doRequestJson(HttpPut.class, requestUrl, adminUser, adminPassword, requestParams); + assertEquals("PUT request to " + requestUrl + " was not successful.", httpResponse.getStatusLine().getStatusCode(), expectedStatusCode); + return httpResponse; + } + catch (InstantiationException | IllegalAccessException error) + { + throw new IllegalArgumentException("doPutRequest failed", error); + } + } + + /** + * Fill in the parameters for a URL template. + * + * @param urlStart The start of the URL. + * @param urlTemplate The template. + * @param urlTemplateParams Any parameters that need to be filled into the URL template. + * @return The resultant URL. + */ + private String formatRequestUrl(String urlStart, String urlTemplate, String[] urlTemplateParams) + { + if (urlTemplateParams.length == 1) + { + // The format method needs some help to know not to use the whole array object. + return MessageFormat.format(urlTemplate, urlStart, urlTemplateParams[0]); + } + return MessageFormat.format(urlTemplate, urlStart, urlTemplateParams); + } + /** * Helper method for POST requests * @param adminUser user with administrative privileges @@ -403,11 +475,8 @@ public abstract class BaseAPI String urlTemplate, String... urlTemplateParams) { - // Ensure the host is part of the request URL. - String requestUrl = MessageFormat.format( - urlTemplate, - urlStart, - urlTemplateParams); + String requestUrl; + requestUrl = formatRequestUrl(urlStart, urlTemplate, urlTemplateParams); try { HttpResponse httpResponse = doRequestJson(HttpPost.class, requestUrl, adminUser, adminPassword, requestParams); 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 af7f204e97..5a389e0656 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 @@ -71,8 +71,10 @@ import org.springframework.stereotype.Component; @Component public class RMRolesAndActionsAPI extends BaseAPI { - /** The URI to view the configured roles and capabilities. Using is=true includes the in-place readers and writers. */ - private static final String RM_ROLES = "{0}rma/admin/rmroles?is=true"; + /** 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. */ + private static final String RM_ROLES_ROLE = RM_ROLES + "/{1}"; private static final String RM_ROLES_AUTHORITIES = "{0}rm/roles/{1}/authorities/{2}?alf_ticket={3}"; // logger @@ -100,7 +102,8 @@ public class RMRolesAndActionsAPI extends BaseAPI */ public Set getConfiguredRoles(String adminUser, String adminPassword) { - JSONObject jsonObject = doGetRequest(adminUser, adminPassword, RM_ROLES).getJSONObject("data"); + // Using "is=true" includes the in-place readers and writers. + JSONObject jsonObject = doGetRequest(adminUser, adminPassword, RM_ROLES + "?is=true").getJSONObject("data"); return jsonObject.toMap().keySet(); } @@ -119,6 +122,45 @@ public class RMRolesAndActionsAPI extends BaseAPI return jsonObject.getJSONObject(role).getJSONObject("capabilities").keySet(); } + /** + * Create a new RM role. + * + * @param adminUser The username of the admin user. + * @param adminPassword The password for the admin user. + * @param roleName The name of the new role. + * @param roleDisplayLabel A human-readable label for the role. + * @param capabilities A list of capabilities for the role. + */ + public void createRole(String adminUser, String adminPassword, String roleName, String roleDisplayLabel, Set capabilities) + { + JSONObject requestBody = new JSONObject(); + requestBody.put("name", roleName); + requestBody.put("displayLabel", roleDisplayLabel); + JSONArray capabilitiesArray = new JSONArray(); + capabilities.forEach(capabilitiesArray::put); + requestBody.put("capabilities", capabilitiesArray); + doPostJsonRequest(adminUser, adminPassword, HttpStatus.SC_OK, requestBody, RM_ROLES); + } + + /** + * Update an existing RM role. + * + * @param adminUser The username of the admin user. + * @param adminPassword The password for the admin user. + * @param roleName The name of the new role. + * @param roleDisplayLabel A human-readable label for the role. + * @param capabilities A list of capabilities for the role. + */ + public void updateRole(String adminUser, String adminPassword, String roleName, String roleDisplayLabel, Set capabilities) + { + JSONObject requestBody = new JSONObject(); + requestBody.put("name", roleName); + requestBody.put("displayLabel", roleDisplayLabel); + JSONArray capabilitiesArray = new JSONArray(); + capabilities.forEach(capabilitiesArray::put); + requestBody.put("capabilities", capabilitiesArray); + doPutJsonRequest(adminUser, adminPassword, HttpStatus.SC_OK, requestBody, RM_ROLES_ROLE, roleName); + } /** * 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 d064db90ee..f7773f95ee 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 @@ -27,8 +27,11 @@ package org.alfresco.rest.rm.community.rmroles; +import static java.util.Collections.singleton; + import static com.google.common.collect.Sets.newHashSet; +import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -49,6 +52,12 @@ public class RMRolesTests extends BaseRMRestTest { /** The name of the RM user role. */ private static final String RM_USER = "User"; + /** The id of the view records capability. */ + public static final String VIEW_RECORDS_CAP = "ViewRecords"; + /** The id of the declare records capability. */ + public static final String DECLARE_RECORDS_CAP = "DeclareRecords"; + /** A list of capabilities. */ + private static final java.util.HashSet CAPABILITIES = newHashSet(VIEW_RECORDS_CAP, DECLARE_RECORDS_CAP); /** The names of the expected default RM roles. */ private static final Set ROLES = newHashSet("Administrator", "RecordsManager", "PowerUser", "SecurityOfficer", RM_USER); @@ -71,7 +80,38 @@ public class RMRolesTests extends BaseRMRestTest { Set capabilities = rmRolesAndActionsAPI .getCapabilitiesForRole(getAdminUser().getUsername(), getAdminUser().getPassword(), RM_USER); - assertEquals("Unexpected capabilities found for RM User.", capabilities, - newHashSet("ViewRecords", "DeclareRecords")); + assertEquals("Unexpected capabilities found for RM User.", capabilities, CAPABILITIES); + } + + /** Check that a new role can be created and retrieved. */ + @Test(description = "Create a new role.") + public void createNewRole() + { + String roleName = generateTestPrefix(RMRolesTests.class) + "newName"; + + // Call the endpoint under test. + rmRolesAndActionsAPI.createRole(getAdminUser().getUsername(), getAdminUser().getPassword(), roleName, + "New Role Label", CAPABILITIES); + + Set actualCapabilities = rmRolesAndActionsAPI + .getCapabilitiesForRole(getAdminUser().getUsername(), getAdminUser().getPassword(), roleName); + assertEquals("Unexpected capabilities found for RM User.", actualCapabilities, CAPABILITIES); + } + + /** Check that a role can be edited. */ + @Test(description = "Update a role.") + public void updateRole() + { + String roleName = generateTestPrefix(RMRolesTests.class) + "Name"; + rmRolesAndActionsAPI.createRole(getAdminUser().getUsername(), getAdminUser().getPassword(), roleName, "Label", + singleton(VIEW_RECORDS_CAP)); + + // Call the endpoint under test. + rmRolesAndActionsAPI.updateRole(getAdminUser().getUsername(), getAdminUser().getPassword(), roleName, + "Updated Label", singleton(DECLARE_RECORDS_CAP)); + + Set actualCapabilities = rmRolesAndActionsAPI + .getCapabilitiesForRole(getAdminUser().getUsername(), getAdminUser().getPassword(), roleName); + assertEquals("Unexpected capabilities for edited RM User.", actualCapabilities, singleton(DECLARE_RECORDS_CAP)); } } From d35ca27ab85cb3ab57c984342779e3c23160ab1d Mon Sep 17 00:00:00 2001 From: Tom Page Date: Fri, 2 Mar 2018 15:58:49 +0000 Subject: [PATCH 4/4] RM-6129 Use roles from UserRoles. --- .../rest/rm/community/model/user/UserRoles.java | 11 ++++++++++- .../rest/rm/community/rmroles/RMRolesTests.java | 11 ++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/user/UserRoles.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/user/UserRoles.java index 3fc30071cd..a20eb8fc79 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/user/UserRoles.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/user/UserRoles.java @@ -24,11 +24,16 @@ * along with Alfresco. If not, see . * #L% */ + package org.alfresco.rest.rm.community.model.user; +import static com.google.common.collect.Sets.newHashSet; + +import java.util.Set; + /** * Constants for RM user roles - * + * * @author Kristijan Conkas * @since 2.6 */ @@ -39,4 +44,8 @@ public class UserRoles public static final String ROLE_RM_POWER_USER = "PowerUser"; public static final String ROLE_RM_SECURITY_OFFICER = "SecurityOfficer"; public static final String ROLE_RM_USER = "User"; + + /** The ids of the default RM roles. */ + public static final Set RM_ROLES = newHashSet(ROLE_RM_ADMIN, ROLE_RM_MANAGER, ROLE_RM_POWER_USER, + ROLE_RM_SECURITY_OFFICER, ROLE_RM_USER); } 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 f7773f95ee..daef946a79 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 @@ -31,6 +31,8 @@ import static java.util.Collections.singleton; import static com.google.common.collect.Sets.newHashSet; +import static org.alfresco.rest.rm.community.model.user.UserRoles.RM_ROLES; +import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_USER; import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -50,17 +52,12 @@ import org.testng.annotations.Test; */ public class RMRolesTests extends BaseRMRestTest { - /** The name of the RM user role. */ - private static final String RM_USER = "User"; /** The id of the view records capability. */ public static final String VIEW_RECORDS_CAP = "ViewRecords"; /** The id of the declare records capability. */ public static final String DECLARE_RECORDS_CAP = "DeclareRecords"; /** A list of capabilities. */ private static final java.util.HashSet CAPABILITIES = newHashSet(VIEW_RECORDS_CAP, DECLARE_RECORDS_CAP); - /** 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; @@ -71,7 +68,7 @@ public class RMRolesTests extends BaseRMRestTest { Set configuredRoles = rmRolesAndActionsAPI .getConfiguredRoles(getAdminUser().getUsername(), getAdminUser().getPassword()); - ROLES.forEach(role -> assertTrue("Could not found role " + role, configuredRoles.contains(role))); + RM_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. */ @@ -79,7 +76,7 @@ public class RMRolesTests extends BaseRMRestTest public void checkCapabilitiesForUser() { Set capabilities = rmRolesAndActionsAPI - .getCapabilitiesForRole(getAdminUser().getUsername(), getAdminUser().getPassword(), RM_USER); + .getCapabilitiesForRole(getAdminUser().getUsername(), getAdminUser().getPassword(), ROLE_RM_USER); assertEquals("Unexpected capabilities found for RM User.", capabilities, CAPABILITIES); }