From 91033cdec1c3e808769d67704f2c915d45aecb4c Mon Sep 17 00:00:00 2001 From: Tom Page Date: Wed, 28 Feb 2018 15:52:53 +0000 Subject: [PATCH] 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))); + } +}