RM-6129 Add test for capabilities of the RM user.

This commit is contained in:
Tom Page
2018-02-28 16:26:27 +00:00
parent 91033cdec1
commit e721781a47
2 changed files with 35 additions and 12 deletions

View File

@@ -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<String> getConfiguredRoles(String adminUser, String adminPassword)
{
JSONObject jsonObject = doGetRequest(adminUser, adminPassword, RM_ROLES);
Collection<Object> 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<String> 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
*/

View File

@@ -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<String> 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<String> 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<String> capabilities = rmRolesAndActionsAPI
.getCapabilitiesForRole(getAdminUser().getUsername(), getAdminUser().getPassword(), RM_USER);
assertEquals("Unexpected capabilities found for RM User.", capabilities,
newHashSet("ViewRecords", "DeclareRecords"));
}
}