mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-6129 Add test for pre-configured RM roles.
This commit is contained in:
@@ -26,6 +26,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.rest.v0;
|
package org.alfresco.rest.v0;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.toSet;
|
||||||
|
|
||||||
import static org.alfresco.dataprep.AlfrescoHttpClient.MIME_TYPE_JSON;
|
import static org.alfresco.dataprep.AlfrescoHttpClient.MIME_TYPE_JSON;
|
||||||
import static org.apache.http.HttpStatus.SC_OK;
|
import static org.apache.http.HttpStatus.SC_OK;
|
||||||
import static org.testng.AssertJUnit.assertEquals;
|
import static org.testng.AssertJUnit.assertEquals;
|
||||||
@@ -38,7 +40,9 @@ import java.text.MessageFormat;
|
|||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.dataprep.AlfrescoHttpClient;
|
import org.alfresco.dataprep.AlfrescoHttpClient;
|
||||||
import org.alfresco.dataprep.AlfrescoHttpClientFactory;
|
import org.alfresco.dataprep.AlfrescoHttpClientFactory;
|
||||||
@@ -70,6 +74,8 @@ import org.springframework.stereotype.Component;
|
|||||||
@Component
|
@Component
|
||||||
public class RMRolesAndActionsAPI extends BaseAPI
|
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}";
|
private static final String RM_ROLES_AUTHORITIES = "{0}rm/roles/{1}/authorities/{2}?alf_ticket={3}";
|
||||||
|
|
||||||
// logger
|
// logger
|
||||||
@@ -88,6 +94,21 @@ public class RMRolesAndActionsAPI extends BaseAPI
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ContentService contentService;
|
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<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());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create user and assign to records management role
|
* create user and assign to records management role
|
||||||
*/
|
*/
|
||||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
* #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<String> 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<String> configuredRoles = rmRolesAndActionsAPI
|
||||||
|
.getConfiguredRoles(getAdminUser().getUsername(), getAdminUser().getPassword());
|
||||||
|
ROLES.forEach(role -> assertTrue("Could not found role " + role, configuredRoles.contains(role)));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user