mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-4391: CI remediation
This commit is contained in:
@@ -47,15 +47,11 @@ import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent
|
|||||||
import org.alfresco.rest.rm.community.model.site.RMSite;
|
import org.alfresco.rest.rm.community.model.site.RMSite;
|
||||||
import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI;
|
import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI;
|
||||||
import org.alfresco.rest.rm.community.requests.RMSiteAPI;
|
import org.alfresco.rest.rm.community.requests.RMSiteAPI;
|
||||||
import org.alfresco.utility.constants.UserRole;
|
|
||||||
import org.alfresco.utility.data.DataUser;
|
import org.alfresco.utility.data.DataUser;
|
||||||
import org.alfresco.utility.model.SiteModel;
|
|
||||||
import org.alfresco.utility.model.UserModel;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.PropertySource;
|
import org.springframework.context.annotation.PropertySource;
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -216,37 +212,4 @@ public class BaseRestTest extends RestTest
|
|||||||
return updatedComponent;
|
return updatedComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create RM user with given role
|
|
||||||
* <br>
|
|
||||||
* Checks whether the user exists in RM site and creates it if required, with password identical
|
|
||||||
* to username. Note the role is a Core API role, not an RM role.
|
|
||||||
* <br>
|
|
||||||
* For already existing users, no site membership or role verification is performed.
|
|
||||||
* <p>
|
|
||||||
* @param userName username to add
|
|
||||||
* @param userRole user's role
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public UserModel createRMUserWithRole(String userName, UserRole userRole) throws Exception
|
|
||||||
{
|
|
||||||
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
|
|
||||||
String siteId = rmSiteAPI.getSite().getId();
|
|
||||||
|
|
||||||
// check if user exists
|
|
||||||
UserModel user = new UserModel();
|
|
||||||
user.setUsername(userName);
|
|
||||||
user.setPassword(userName);
|
|
||||||
|
|
||||||
if (!dataUser.isUserInRepo(userName))
|
|
||||||
{
|
|
||||||
// user doesn't exist, create it
|
|
||||||
user = dataUser.createUser(userName, userName);
|
|
||||||
user.setUserRole(userRole);
|
|
||||||
|
|
||||||
dataUser.addUserToSite(user, new SiteModel(siteId), userRole);
|
|
||||||
}
|
|
||||||
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
}
|
}
|
@@ -40,7 +40,6 @@ import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
|
|||||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||||
import static org.springframework.http.HttpStatus.CREATED;
|
import static org.springframework.http.HttpStatus.CREATED;
|
||||||
import static org.springframework.http.HttpStatus.FORBIDDEN;
|
import static org.springframework.http.HttpStatus.FORBIDDEN;
|
||||||
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
|
||||||
import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
|
import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertFalse;
|
import static org.testng.Assert.assertFalse;
|
||||||
@@ -51,8 +50,10 @@ import org.alfresco.rest.rm.community.base.BaseRestTest;
|
|||||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
|
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
|
||||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
|
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
|
||||||
import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI;
|
import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI;
|
||||||
|
import org.alfresco.rest.rm.community.requests.RMSiteAPI;
|
||||||
import org.alfresco.utility.constants.UserRole;
|
import org.alfresco.utility.constants.UserRole;
|
||||||
import org.alfresco.utility.data.DataUser;
|
import org.alfresco.utility.data.DataUser;
|
||||||
|
import org.alfresco.utility.model.SiteModel;
|
||||||
import org.alfresco.utility.model.UserModel;
|
import org.alfresco.utility.model.UserModel;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.testng.annotations.DataProvider;
|
import org.testng.annotations.DataProvider;
|
||||||
@@ -72,6 +73,9 @@ public class NonElectronicRecordTests extends BaseRestTest
|
|||||||
@Autowired
|
@Autowired
|
||||||
private DataUser dataUser;
|
private DataUser dataUser;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RMSiteAPI rmSiteAPI;
|
||||||
|
|
||||||
/** Valid root containers where non-electronic records can be created */
|
/** Valid root containers where non-electronic records can be created */
|
||||||
@DataProvider(name = "validContainers")
|
@DataProvider(name = "validContainers")
|
||||||
public Object[][] rootContainers() throws Exception {
|
public Object[][] rootContainers() throws Exception {
|
||||||
@@ -230,17 +234,12 @@ public class NonElectronicRecordTests extends BaseRestTest
|
|||||||
closeFolder(recordFolder.getId());
|
closeFolder(recordFolder.getId());
|
||||||
|
|
||||||
// try to create it, this should fail and throw an exception
|
// try to create it, this should fail and throw an exception
|
||||||
try
|
|
||||||
{
|
|
||||||
filePlanComponentAPI.createFilePlanComponent(
|
filePlanComponentAPI.createFilePlanComponent(
|
||||||
new FilePlanComponent("Record " + getRandomAlphanumeric(),
|
new FilePlanComponent("Record " + getRandomAlphanumeric(),
|
||||||
NON_ELECTRONIC_RECORD_TYPE.toString(),
|
NON_ELECTRONIC_RECORD_TYPE.toString(),
|
||||||
new FilePlanComponentProperties()),
|
new FilePlanComponentProperties()),
|
||||||
recordFolder.getId()).getId();
|
recordFolder.getId()).getId();
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// verify the status code
|
// verify the status code
|
||||||
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
|
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
|
||||||
@@ -332,7 +331,7 @@ public class NonElectronicRecordTests extends BaseRestTest
|
|||||||
public void cantCreateIfNoRmPrivileges(FilePlanComponent container) throws Exception
|
public void cantCreateIfNoRmPrivileges(FilePlanComponent container) throws Exception
|
||||||
{
|
{
|
||||||
String username = "zzzuser";
|
String username = "zzzuser";
|
||||||
UserModel user = createRMUserWithRole(username, UserRole.SiteConsumer);
|
UserModel user = createUserWithRole(username, UserRole.SiteManager);
|
||||||
|
|
||||||
filePlanComponentAPI.usingRestWrapper().authenticateUser(user);
|
filePlanComponentAPI.usingRestWrapper().authenticateUser(user);
|
||||||
|
|
||||||
@@ -379,4 +378,38 @@ public class NonElectronicRecordTests extends BaseRestTest
|
|||||||
// and return a folder underneath
|
// and return a folder underneath
|
||||||
return createFolder(recordCategory.getId(), "Folder " + getRandomAlphanumeric());
|
return createFolder(recordCategory.getId(), "Folder " + getRandomAlphanumeric());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create user with given role and add it to RM site
|
||||||
|
* <br>
|
||||||
|
* Checks whether the user exists in RM site and creates it if required, with password identical
|
||||||
|
* to username. Note the role is a Core API role, not an RM role.
|
||||||
|
* <br>
|
||||||
|
* For already existing users, no site membership or role verification is performed.
|
||||||
|
* <p>
|
||||||
|
* @param userName username to add
|
||||||
|
* @param userRole user's role
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private UserModel createUserWithRole(String userName, UserRole userRole) throws Exception
|
||||||
|
{
|
||||||
|
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
|
||||||
|
String siteId = rmSiteAPI.getSite().getId();
|
||||||
|
|
||||||
|
// check if user exists
|
||||||
|
UserModel user = new UserModel();
|
||||||
|
user.setUsername(userName);
|
||||||
|
user.setPassword(userName);
|
||||||
|
|
||||||
|
if (!dataUser.isUserInRepo(userName))
|
||||||
|
{
|
||||||
|
// user doesn't exist, create it
|
||||||
|
user = dataUser.createUser(userName, userName);
|
||||||
|
user.setUserRole(userRole);
|
||||||
|
|
||||||
|
dataUser.addUserToSite(user, new SiteModel(siteId), userRole);
|
||||||
|
}
|
||||||
|
|
||||||
|
return user;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user