RM-4488 (Refactor REST API Automation test code according to the latest changes)

This commit is contained in:
Tuna Aksoy
2016-12-24 20:48:23 +00:00
parent 0599aa5d30
commit c91bf852d9
35 changed files with 1041 additions and 1550 deletions

View File

@@ -26,8 +26,6 @@
*/
package org.alfresco.rest.rm.community.base;
import static java.lang.Integer.parseInt;
import static com.jayway.restassured.RestAssured.given;
import static org.alfresco.rest.rm.community.base.TestData.CATEGORY_TITLE;
@@ -44,7 +42,6 @@ import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.OK;
import com.google.gson.JsonObject;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.http.ContentType;
import com.jayway.restassured.response.Response;
@@ -53,19 +50,17 @@ import com.jayway.restassured.specification.RequestSpecification;
import org.alfresco.dataprep.AlfrescoHttpClient;
import org.alfresco.dataprep.AlfrescoHttpClientFactory;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.core.RMRestWrapper;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentModel;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType;
import org.alfresco.rest.rm.community.model.site.RMSite;
import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI;
import org.alfresco.rest.rm.community.requests.RMSiteAPI;
import org.alfresco.rest.rm.community.model.site.RMSiteModel;
import org.alfresco.rest.rm.community.model.user.UserPermissions;
import org.alfresco.rest.rm.community.requests.FilePlanComponents;
import org.alfresco.rest.rm.community.requests.RMSite;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.model.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
@@ -76,39 +71,49 @@ import org.testng.annotations.DataProvider;
* @author Tuna Aksoy
* @since 2.6
*/
@Configuration
@PropertySource(value = {"classpath:default.properties", "classpath:config.properties"})
@PropertySource(value = "classpath:module.properties", ignoreResourceNotFound = true)
@PropertySource(value = "classpath:local.properties", ignoreResourceNotFound = true)
public class BaseRestTest extends RestTest
{
@Value ("${alfresco.scheme}")
private String scheme;
@Value ("${alfresco.server}")
private String server;
@Value ("${alfresco.port}")
private String port;
@Value ("${rest.rmPath}")
private String restRmPath;
@Value ("${rest.basePath}")
private String restCorePath;
@Autowired
private RMSiteAPI rmSiteAPI;
private RMRestWrapper rmRestWrapper;
@Autowired
private DataUser dataUser;
@Autowired
public FilePlanComponentAPI filePlanComponentAPI;
@Autowired
private AlfrescoHttpClientFactory alfrescoHttpClientFactory;
private RMSite rmSite;
private FilePlanComponents filePlanComponents;
protected RMSite getRMSiteAPI()
{
if (rmSite == null)
{
rmSite = getRmRestWrapper().withIGCoreAPI().usingRMSite();
}
return rmSite;
}
protected FilePlanComponents getFilePlanComponentsAPI()
{
if (filePlanComponents == null)
{
filePlanComponents = getRmRestWrapper().withIGCoreAPI().usingFilePlanComponents();
}
return filePlanComponents;
}
/**
* @return the rmRestWrapper
*/
protected RMRestWrapper getRmRestWrapper()
{
return this.rmRestWrapper;
}
// Constants
public static final String RM_ID = "rm";
public static final String RM_TITLE = "Records Management";
@@ -116,14 +121,16 @@ public class BaseRestTest extends RestTest
/** Valid root containers where electronic and non-electronic records can be created */
@DataProvider(name = "validRootContainers")
public Object[][] getValidRootContainers() throws Exception {
return new Object[][] {
public Object[][] getValidRootContainers() throws Exception
{
return new Object[][]
{
// an arbitrary record folder
{ createCategoryFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString()) },
{ createCategoryFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS) },
// unfiled records root
{ getFilePlanComponentAsUser(dataUser.getAdminUser(), UNFILED_RECORDS_CONTAINER_ALIAS.toString()) },
{ getFilePlanComponentAsUser(dataUser.getAdminUser(), UNFILED_RECORDS_CONTAINER_ALIAS) },
// an arbitrary unfiled records folder
{ createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), "Unfiled Folder " + getRandomAlphanumeric()) }
{ createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Folder " + getRandomAlphanumeric()) }
};
}
@@ -134,14 +141,30 @@ public class BaseRestTest extends RestTest
@BeforeClass (alwaysRun = true)
public void checkServerHealth() throws Exception
{
RestAssured.baseURI = scheme + "://" + server;
RestAssured.port = parseInt(port);
RestAssured.basePath = restRmPath;
// Create RM Site if not exist
createRMSiteIfNotExists();
}
/**
* FIXME!!!
*
* @param userModel FIXME!!!
*/
protected void authenticateUser(UserModel userModel)
{
getRmRestWrapper().authenticateUser(userModel);
}
protected void assertStatusCodeIs(HttpStatus httpStatus)
{
getRmRestWrapper().assertStatusCodeIs(httpStatus);
}
protected void disconnect()
{
getRmRestWrapper().disconnect();
}
/**
* Helper method to create the RM Site via the POST request
* if the site doesn't exist
@@ -149,18 +172,18 @@ public class BaseRestTest extends RestTest
public void createRMSiteIfNotExists() throws Exception
{
// Check RM site doesn't exist
if (!rmSiteAPI.existsRMSite())
if (!rmSite.existsRMSite())
{
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// Create the RM site
RMSite rmSite = RMSite.builder().compliance(STANDARD).build();
rmSite.setTitle(RM_TITLE);
rmSite.setDescription(RM_DESCRIPTION);
rmSiteAPI.createRMSite(rmSite);
RMSiteModel rmSiteModel = RMSiteModel.builder().compliance(STANDARD).build();
rmSiteModel.setTitle(RM_TITLE);
rmSiteModel.setDescription(RM_DESCRIPTION);
rmSite.createRMSite(rmSiteModel);
// Verify the status code
rmSiteAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
assertStatusCodeIs(CREATED);
}
}
@@ -172,7 +195,7 @@ public class BaseRestTest extends RestTest
* @return The created category
* @throws Exception on unsuccessful component creation
*/
public FilePlanComponent createCategory(String parentCategoryId, String categoryName) throws Exception
public FilePlanComponentModel createCategory(String parentCategoryId, String categoryName) throws Exception
{
return createComponent(parentCategoryId, categoryName, RECORD_CATEGORY_TYPE, CATEGORY_TITLE);
}
@@ -185,7 +208,7 @@ public class BaseRestTest extends RestTest
* @return The created category
* @throws Exception on unsuccessful component creation
*/
public FilePlanComponent createFolder(String parentCategoryId, String folderName) throws Exception
public FilePlanComponentModel createFolder(String parentCategoryId, String folderName) throws Exception
{
return createComponent(parentCategoryId, folderName, RECORD_FOLDER_TYPE, FOLDER_TITLE);
}
@@ -198,7 +221,7 @@ public class BaseRestTest extends RestTest
* @return The created folder
* @throws Exception on unsuccessful component creation
*/
public FilePlanComponent createUnfiledRecordsFolder(String parentId, String folderName) throws Exception
public FilePlanComponentModel createUnfiledRecordsFolder(String parentId, String folderName) throws Exception
{
return createComponent(parentId, folderName, UNFILED_RECORD_FOLDER_TYPE, FOLDER_TITLE);
}
@@ -213,20 +236,21 @@ public class BaseRestTest extends RestTest
* @return The created file plan component
* @throws Exception
*/
private FilePlanComponent createComponent(String parentComponentId, String componentName, FilePlanComponentType componentType, String componentTitle) throws Exception
private FilePlanComponentModel createComponent(String parentComponentId, String componentName, String componentType, String componentTitle) throws Exception
{
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
FilePlanComponent filePlanComponent = FilePlanComponent.builder()
FilePlanComponentModel filePlanComponent = FilePlanComponentModel.builder()
.name(componentName)
.nodeType(componentType.toString())
.nodeType(componentType)
.properties(FilePlanComponentProperties.builder()
.title(componentTitle)
.build())
.build();
FilePlanComponent fpc = filePlanComponentAPI.createFilePlanComponent(filePlanComponent, parentComponentId);
restWrapper.assertStatusCodeIs(CREATED);
FilePlanComponentModel fpc = getFilePlanComponentsAPI().createFilePlanComponent(filePlanComponent, parentComponentId);
assertStatusCodeIs(CREATED);
return fpc;
}
@@ -236,21 +260,21 @@ public class BaseRestTest extends RestTest
* @return
* @throws Exception
*/
public FilePlanComponent closeFolder(String folderId) throws Exception
public FilePlanComponentModel closeFolder(String folderId) throws Exception
{
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// build fileplan component + properties for update request
FilePlanComponentProperties properties = new FilePlanComponentProperties();
properties.setIsClosed(true);
FilePlanComponent filePlanComponent = new FilePlanComponent();
FilePlanComponentModel filePlanComponent = new FilePlanComponentModel();
filePlanComponent.setProperties(properties);
FilePlanComponent updatedComponent = filePlanComponentAPI.updateFilePlanComponent(filePlanComponent, folderId);
restWrapper.assertStatusCodeIs(OK);
FilePlanComponentModel updatedComponent = getFilePlanComponentsAPI().updateFilePlanComponent(filePlanComponent, folderId);
assertStatusCodeIs(OK);
return updatedComponent;
}
/**
* Helper method to create a randomly-named <category>/<folder> structure in fileplan
* @param user user under whose privileges this structure is going to be created
@@ -258,17 +282,17 @@ public class BaseRestTest extends RestTest
* @return record folder
* @throws Exception on failed creation
*/
public FilePlanComponent createCategoryFolderInFilePlan(UserModel user, String parentId) throws Exception
public FilePlanComponentModel createCategoryFolderInFilePlan(UserModel user, String parentId) throws Exception
{
filePlanComponentAPI.usingRestWrapper().authenticateUser(user);
authenticateUser(user);
// create root category
FilePlanComponent recordCategory = createCategory(parentId, "Category " + getRandomAlphanumeric());
FilePlanComponentModel recordCategory = createCategory(parentId, "Category " + getRandomAlphanumeric());
// and return a folder underneath
return createFolder(recordCategory.getId(), "Folder " + getRandomAlphanumeric());
}
/**
* Helper method to retieve a fileplan component with user's privilege
* @param user user under whose privileges a component is to be read
@@ -276,12 +300,12 @@ public class BaseRestTest extends RestTest
* @return {@link FilePlanComponent} for given componentId
* @throws Exception if user doesn't have sufficient privileges
*/
public FilePlanComponent getFilePlanComponentAsUser(UserModel user, String componentId) throws Exception
public FilePlanComponentModel getFilePlanComponentAsUser(UserModel user, String componentId) throws Exception
{
filePlanComponentAPI.usingRestWrapper().authenticateUser(user);
return filePlanComponentAPI.getFilePlanComponent(componentId);
authenticateUser(user);
return getFilePlanComponentsAPI().getFilePlanComponent(componentId);
}
/**
* Helper method to add permission on a component to user
* @param component {@link FilePlanComponent} on which permission should be given
@@ -291,11 +315,11 @@ public class BaseRestTest extends RestTest
// FIXME: As of December 2016 there is no v1-style API for managing RM permissions.
// Until such APIs have become available, this method is just a proxy to an "old-style"
// API call.
public void addUserPermission(FilePlanComponent component, UserModel user, String permission)
public void addUserPermission(FilePlanComponentModel component, UserModel user, String permission)
{
// get an "old-style" REST API client
AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
JsonObject bodyJson = buildObject()
.addArray("permissions")
.addObject()
@@ -309,7 +333,7 @@ public class BaseRestTest extends RestTest
.setBaseUri(client.getApiUrl())
.setBasePath("/")
.build();
// execute an "old-style" API call
Response response = given()
.spec(spec)
@@ -322,6 +346,6 @@ public class BaseRestTest extends RestTest
.post("/node/workspace/SpacesStore/{nodeId}/rmpermissions")
.prettyPeek()
.andReturn();
filePlanComponentAPI.usingRestWrapper().setStatusCode(Integer.toString(response.getStatusCode()));
rmRestWrapper.setStatusCode(Integer.toString(response.getStatusCode()));
}
}

View File

@@ -50,7 +50,7 @@ import org.testng.annotations.DataProvider;
* @since 2.6
*/
public interface TestData
{
{
/**
* A user with ALFRESCO_ADMINISTRATORS role.
* <p>"GROUP_ANOTHER_ADMIN_EXISTS" The ANOTHER_ADMIN user has been created.
@@ -75,10 +75,10 @@ public interface TestData
public static Object[][] getContainers()
{
return new Object[][] {
{ FILE_PLAN_ALIAS.toString() },
{ TRANSFERS_ALIAS.toString() },
{ HOLDS_ALIAS.toString() },
{ UNFILED_RECORDS_CONTAINER_ALIAS.toString() },
{ FILE_PLAN_ALIAS },
{ TRANSFERS_ALIAS },
{ HOLDS_ALIAS },
{ UNFILED_RECORDS_CONTAINER_ALIAS },
};
}
@@ -130,15 +130,15 @@ public interface TestData
public static Object[][] childrenNotAllowedForCategory()
{
return new Object[][] {
{ FILE_PLAN_TYPE.toString() },
{ TRANSFER_CONTAINER_TYPE.toString() },
{ HOLD_CONTAINER_TYPE.toString() },
{ UNFILED_CONTAINER_TYPE.toString() },
{ UNFILED_RECORD_FOLDER_TYPE.toString()},
{ HOLD_TYPE.toString()},
{ TRANSFER_TYPE.toString()},
{ FOLDER_TYPE.toString()},
{ CONTENT_TYPE.toString()}
{ FILE_PLAN_TYPE },
{ TRANSFER_CONTAINER_TYPE },
{ HOLD_CONTAINER_TYPE },
{ UNFILED_CONTAINER_TYPE },
{ UNFILED_RECORD_FOLDER_TYPE },
{ HOLD_TYPE },
{ TRANSFER_TYPE },
{ FOLDER_TYPE },
{ CONTENT_TYPE }
};
}
}

View File

@@ -38,11 +38,9 @@ import static org.springframework.http.HttpStatus.NO_CONTENT;
import static org.springframework.http.HttpStatus.OK;
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.FilePlanComponentModel;
import org.alfresco.rest.rm.community.model.user.UserPermissions;
import org.alfresco.rest.rm.community.model.user.UserRoles;
import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI;
import org.alfresco.rest.rm.community.requests.RMSiteAPI;
import org.alfresco.rest.rm.community.requests.RMUserAPI;
import org.alfresco.test.AlfrescoTest;
import org.alfresco.utility.constants.UserRole;
@@ -64,16 +62,10 @@ import org.testng.annotations.Test;
public class DeleteRecordTests extends BaseRestTest
{
@Autowired
private FilePlanComponentAPI filePlanComponentAPI;
private RMUserAPI rmUserAPI;
@Autowired
private RMUserAPI rmUserAPI;
@Autowired
private DataUser dataUser;
@Autowired
private RMSiteAPI rmSiteAPI;
/** image resource file to be used for records body */
private static final String IMAGE_FILE = "money.JPG";
@@ -86,7 +78,7 @@ public class DeleteRecordTests extends BaseRestTest
* When I delete the record
* Then it is deleted from the file plan
* </pre>
*
*
* @param container
* @throws Exception
*/
@@ -96,21 +88,21 @@ public class DeleteRecordTests extends BaseRestTest
description = "Admin user can delete an electronic record"
)
@AlfrescoTest(jira="RM-4363")
public void adminCanDeleteElectronicRecord(FilePlanComponent container) throws Exception
public void adminCanDeleteElectronicRecord(FilePlanComponentModel container) throws Exception
{
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// create an electronic record
FilePlanComponent record = FilePlanComponent.builder()
FilePlanComponentModel record = FilePlanComponentModel.builder()
.name("Record " + getRandomAlphanumeric())
.nodeType(CONTENT_TYPE.toString())
.nodeType(CONTENT_TYPE)
.build();
FilePlanComponent newRecord = filePlanComponentAPI.createElectronicRecord(record, IMAGE_FILE, container.getId());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
FilePlanComponentModel newRecord = getFilePlanComponentsAPI().createElectronicRecord(record, IMAGE_FILE, container.getId());
assertStatusCodeIs(CREATED);
deleteAndVerify(newRecord);
}
/**
* <pre>
* Given a record
@@ -119,7 +111,7 @@ public class DeleteRecordTests extends BaseRestTest
* When I delete the record
* Then it is deleted from the file plan
* </pre>
*
*
* @param container
* @throws Exception
*/
@@ -129,23 +121,23 @@ public class DeleteRecordTests extends BaseRestTest
description = "Admin user can delete a non-electronic record"
)
@AlfrescoTest(jira="RM-4363")
public void adminCanDeleteNonElectronicRecord(FilePlanComponent container) throws Exception
public void adminCanDeleteNonElectronicRecord(FilePlanComponentModel container) throws Exception
{
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// create a non-electronic record
FilePlanComponent record = FilePlanComponent.builder()
FilePlanComponentModel record = FilePlanComponentModel.builder()
.name("Record " + getRandomAlphanumeric())
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
.build();
FilePlanComponent newRecord = filePlanComponentAPI.createFilePlanComponent(
FilePlanComponentModel newRecord = getFilePlanComponentsAPI().createFilePlanComponent(
record,
container.getId());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
assertStatusCodeIs(CREATED);
deleteAndVerify(newRecord);
}
/**
* <pre>
* Given a record
@@ -154,7 +146,7 @@ public class DeleteRecordTests extends BaseRestTest
* Then nothing happens
* And error gets reported
* </pre>
*
*
* @param container
* @throws Exception
*/
@@ -165,37 +157,37 @@ public class DeleteRecordTests extends BaseRestTest
@AlfrescoTest(jira="RM-4363")
public void userWithoutWritePermissionsCantDeleteRecord() throws Exception
{
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// create a non-electronic record in unfiled records
FilePlanComponent record = FilePlanComponent.builder()
FilePlanComponentModel record = FilePlanComponentModel.builder()
.name("Record " + getRandomAlphanumeric())
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
.build();
FilePlanComponent newRecord = filePlanComponentAPI.createFilePlanComponent(
FilePlanComponentModel newRecord = getFilePlanComponentsAPI().createFilePlanComponent(
record,
UNFILED_RECORDS_CONTAINER_ALIAS.toString());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
UNFILED_RECORDS_CONTAINER_ALIAS);
assertStatusCodeIs(CREATED);
// create test user and add it with collab. privileges
UserModel deleteUser = dataUser.createRandomTestUser("delnoperm");
deleteUser.setUserRole(UserRole.SiteCollaborator);
logger.info("test user: " + deleteUser.getUsername());
dataUser.addUserToSite(deleteUser, new SiteModel(rmSiteAPI.getSite().getId()), UserRole.SiteCollaborator);
dataUser.addUserToSite(deleteUser, new SiteModel(getRMSiteAPI().getSite().getId()), UserRole.SiteCollaborator);
// add RM role to user
rmUserAPI.assignRoleToUser(deleteUser.getUsername(), UserRoles.ROLE_RM_POWER_USER);
rmUserAPI.usingRestWrapper().assertStatusCodeIs(OK);
// log in as deleteUser
filePlanComponentAPI.usingRestWrapper().authenticateUser(deleteUser);
authenticateUser(deleteUser);
// try to delete newRecord
filePlanComponentAPI.deleteFilePlanComponent(newRecord.getId());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN);
getFilePlanComponentsAPI().deleteFilePlanComponent(newRecord.getId());
assertStatusCodeIs(FORBIDDEN);
}
/**
* <pre>
* Given a record
@@ -204,7 +196,7 @@ public class DeleteRecordTests extends BaseRestTest
* Then nothing happens
* And error gets reported
* </pre>
*
*
* @param container
* @throws Exception
*/
@@ -215,66 +207,65 @@ public class DeleteRecordTests extends BaseRestTest
@AlfrescoTest(jira="RM-4363")
public void userWithoutDeleteRecordsCapabilityCantDeleteRecord() throws Exception
{
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// create test user and add it with collab. privileges
UserModel deleteUser = dataUser.createRandomTestUser("delnoperm");
deleteUser.setUserRole(UserRole.SiteCollaborator);
dataUser.addUserToSite(deleteUser, new SiteModel(rmSiteAPI.getSite().getId()), UserRole.SiteCollaborator);
dataUser.addUserToSite(deleteUser, new SiteModel(getRMSiteAPI().getSite().getId()), UserRole.SiteCollaborator);
logger.info("test user: " + deleteUser.getUsername());
// add RM role to user, RM Power User doesn't have the Delete Record capabilities
rmUserAPI.assignRoleToUser(deleteUser.getUsername(), UserRoles.ROLE_RM_POWER_USER);
rmUserAPI.usingRestWrapper().assertStatusCodeIs(OK);
// create random folder
FilePlanComponent randomFolder = createCategoryFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString());
FilePlanComponentModel randomFolder = createCategoryFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS);
logger.info("random folder:" + randomFolder.getName());
// grant deleteUser Filing privileges on randomFolder category, this will be
// inherited to randomFolder
addUserPermission(filePlanComponentAPI.getFilePlanComponent(randomFolder.getParentId()),
addUserPermission(getFilePlanComponentsAPI().getFilePlanComponent(randomFolder.getParentId()),
deleteUser, UserPermissions.PERMISSION_FILING);
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK);
assertStatusCodeIs(OK);
// create a non-electronic record in randomFolder
FilePlanComponent record = FilePlanComponent.builder()
FilePlanComponentModel record = FilePlanComponentModel.builder()
.name("Record " + getRandomAlphanumeric())
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
.build();
FilePlanComponent newRecord = filePlanComponentAPI.createFilePlanComponent(
FilePlanComponentModel newRecord = getFilePlanComponentsAPI().createFilePlanComponent(
record,
randomFolder.getId());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
assertStatusCodeIs(CREATED);
// log in as deleteUser
filePlanComponentAPI.usingRestWrapper().authenticateUser(deleteUser);
authenticateUser(deleteUser);
// verify the user can see the newRecord
filePlanComponentAPI.getFilePlanComponent(newRecord.getId());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK);
getFilePlanComponentsAPI().getFilePlanComponent(newRecord.getId());
assertStatusCodeIs(OK);
// try to delete newRecord
filePlanComponentAPI.deleteFilePlanComponent(newRecord.getId());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN);
getFilePlanComponentsAPI().deleteFilePlanComponent(newRecord.getId());
assertStatusCodeIs(FORBIDDEN);
}
/**
* Utility method to delete a record and verify successful deletion
* @param record
* @throws Exception
*/
private void deleteAndVerify(FilePlanComponent record) throws Exception
private void deleteAndVerify(FilePlanComponentModel record) throws Exception
{
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// delete it and verify status
filePlanComponentAPI.deleteFilePlanComponent(record.getId());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(NO_CONTENT);
getFilePlanComponentsAPI().deleteFilePlanComponent(record.getId());
assertStatusCodeIs(NO_CONTENT);
// try to get deleted file plan component
filePlanComponentAPI.getFilePlanComponent(record.getId());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(NOT_FOUND);
getFilePlanComponentsAPI().getFilePlanComponent(record.getId());
assertStatusCodeIs(NOT_FOUND);
}
}

View File

@@ -40,8 +40,7 @@ import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import org.alfresco.rest.rm.community.base.BaseRestTest;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentModel;
import org.alfresco.utility.data.DataUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.DataProvider;
@@ -58,9 +57,6 @@ import org.testng.annotations.Test;
*/
public class ElectronicRecordTests extends BaseRestTest
{
@Autowired
private FilePlanComponentAPI filePlanComponentAPI;
@Autowired
private DataUser dataUser;
@@ -73,13 +69,13 @@ public class ElectronicRecordTests extends BaseRestTest
return new Object[][] {
// record category
{ getFilePlanComponentAsUser(dataUser.getAdminUser(),
createCategoryFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString()).getParentId()) },
createCategoryFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS).getParentId()) },
// file plan root
{ getFilePlanComponentAsUser(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString()) },
{ getFilePlanComponentAsUser(dataUser.getAdminUser(), FILE_PLAN_ALIAS) },
// transfers
{ getFilePlanComponentAsUser(dataUser.getAdminUser(), TRANSFERS_ALIAS.toString()) },
{ getFilePlanComponentAsUser(dataUser.getAdminUser(), TRANSFERS_ALIAS) },
// holds
{ getFilePlanComponentAsUser(dataUser.getAdminUser(), HOLDS_ALIAS.toString()) },
{ getFilePlanComponentAsUser(dataUser.getAdminUser(), HOLDS_ALIAS) },
};
}
@@ -98,19 +94,19 @@ public class ElectronicRecordTests extends BaseRestTest
dataProvider = "invalidParentContainers",
description = "Electronic records can't be created in invalid parent containers"
)
public void cantCreateElectronicRecordsInInvalidContainers(FilePlanComponent container) throws Exception
public void cantCreateElectronicRecordsInInvalidContainers(FilePlanComponentModel container) throws Exception
{
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// Build object the filePlan
FilePlanComponent record = FilePlanComponent.builder()
FilePlanComponentModel record = FilePlanComponentModel.builder()
.name("Record " + getRandomAlphanumeric())
.nodeType(CONTENT_TYPE.toString())
.nodeType(CONTENT_TYPE)
.build();
filePlanComponentAPI.createElectronicRecord(record, IMAGE_FILE, container.getId());
getFilePlanComponentsAPI().createElectronicRecord(record, IMAGE_FILE, container.getId());
// verify the create request status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
assertStatusCodeIs(UNPROCESSABLE_ENTITY);
}
/**
@@ -126,8 +122,8 @@ public class ElectronicRecordTests extends BaseRestTest
@Test(description = "Electronic record can't be created in closed record folder")
public void cantCreateElectronicRecordInClosedFolder() throws Exception
{
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
FilePlanComponent recordFolder = createCategoryFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString());
authenticateUser(dataUser.getAdminUser());
FilePlanComponentModel recordFolder = createCategoryFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS);
// the folder should be open
assertFalse(recordFolder.getProperties().getIsClosed());
@@ -136,14 +132,14 @@ public class ElectronicRecordTests extends BaseRestTest
closeFolder(recordFolder.getId());
// try to create it, this should fail
FilePlanComponent record = FilePlanComponent.builder()
FilePlanComponentModel record = FilePlanComponentModel.builder()
.name("Record " + getRandomAlphanumeric())
.nodeType(CONTENT_TYPE.toString())
.nodeType(CONTENT_TYPE)
.build();
filePlanComponentAPI.createElectronicRecord(record, IMAGE_FILE, recordFolder.getId());
getFilePlanComponentsAPI().createElectronicRecord(record, IMAGE_FILE, recordFolder.getId());
// verify the status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
assertStatusCodeIs(UNPROCESSABLE_ENTITY);
}
/**
@@ -171,27 +167,27 @@ public class ElectronicRecordTests extends BaseRestTest
dataProvider = "validRootContainers",
description = "Electronic record can only be created if all mandatory properties are given"
)
public void canCreateElectronicRecordOnlyWithMandatoryProperties(FilePlanComponent container) throws Exception
public void canCreateElectronicRecordOnlyWithMandatoryProperties(FilePlanComponentModel container) throws Exception
{
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
logger.info("Root container:\n" + toJson(container));
if (container.getNodeType().equals(RECORD_FOLDER_TYPE.toString()))
if (container.getNodeType().equals(RECORD_FOLDER_TYPE))
{
// only record folders can be open or closed
assertFalse(container.getProperties().getIsClosed());
}
// component without name
FilePlanComponent record = FilePlanComponent.builder()
.nodeType(CONTENT_TYPE.toString())
FilePlanComponentModel record = FilePlanComponentModel.builder()
.nodeType(CONTENT_TYPE)
.build();
// try to create it
filePlanComponentAPI.createFilePlanComponent(record, container.getId());
getFilePlanComponentsAPI().createFilePlanComponent(record, container.getId());
// verify the status code is BAD_REQUEST
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(BAD_REQUEST);
assertStatusCodeIs(BAD_REQUEST);
}
/**
@@ -216,21 +212,21 @@ public class ElectronicRecordTests extends BaseRestTest
dataProvider = "validRootContainers",
description = "Electronic records can be created in unfiled record folder or unfiled record root"
)
public void canCreateElectronicRecordsInValidContainers(FilePlanComponent container) throws Exception
public void canCreateElectronicRecordsInValidContainers(FilePlanComponentModel container) throws Exception
{
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
FilePlanComponent record = FilePlanComponent.builder()
FilePlanComponentModel record = FilePlanComponentModel.builder()
.name("Record " + getRandomAlphanumeric())
.nodeType(CONTENT_TYPE.toString())
.nodeType(CONTENT_TYPE)
.build();
String newRecordId = filePlanComponentAPI.createElectronicRecord(record, IMAGE_FILE, container.getId()).getId();
String newRecordId = getFilePlanComponentsAPI().createElectronicRecord(record, IMAGE_FILE, container.getId()).getId();
// verify the create request status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
assertStatusCodeIs(CREATED);
// get newly created electonic record and verify its properties
FilePlanComponent electronicRecord = filePlanComponentAPI.getFilePlanComponent(newRecordId);
FilePlanComponentModel electronicRecord = getFilePlanComponentsAPI().getFilePlanComponent(newRecordId);
// created record will have record identifier inserted in its name but will be prefixed with
// the name it was created as
assertTrue(electronicRecord.getName().startsWith(record.getName()));
@@ -247,22 +243,22 @@ public class ElectronicRecordTests extends BaseRestTest
dataProvider = "validRootContainers",
description = "Electronic records can be created in unfiled record folder or unfiled record root"
)
public void recordNameDerivedFromFileName(FilePlanComponent container) throws Exception
public void recordNameDerivedFromFileName(FilePlanComponentModel container) throws Exception
{
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// record object without name set
FilePlanComponent record = FilePlanComponent.builder()
.nodeType(CONTENT_TYPE.toString())
FilePlanComponentModel record = FilePlanComponentModel.builder()
.nodeType(CONTENT_TYPE)
.build();
String newRecordId = filePlanComponentAPI.createElectronicRecord(record, IMAGE_FILE, container.getId()).getId();
String newRecordId = getFilePlanComponentsAPI().createElectronicRecord(record, IMAGE_FILE, container.getId()).getId();
// verify the create request status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
assertStatusCodeIs(CREATED);
// get newly created electonic record and verify its properties
FilePlanComponent electronicRecord = filePlanComponentAPI.getFilePlanComponent(newRecordId);
FilePlanComponentModel electronicRecord = getFilePlanComponentsAPI().getFilePlanComponent(newRecordId);
// record will have record identifier inserted in its name but will for sure start with file name
// and end with its extension
assertTrue(electronicRecord.getName().startsWith(IMAGE_FILE.substring(0, IMAGE_FILE.indexOf("."))));

View File

@@ -43,15 +43,10 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.rm.community.base.BaseRestTest;
import org.alfresco.rest.rm.community.base.TestData;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentModel;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType;
import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI;
import org.alfresco.rest.rm.community.requests.RMSiteAPI;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.model.UserModel;
import org.alfresco.utility.report.Bug;
@@ -67,15 +62,6 @@ import org.testng.annotations.Test;
*/
public class FilePlanTests extends BaseRestTest
{
@Autowired
private FilePlanComponentAPI filePlanComponentAPI;
@Autowired
protected RestWrapper restWrapper;
@Autowired
private RMSiteAPI rmSiteAPI;
@Autowired
private DataUser dataUser;
@@ -90,23 +76,23 @@ public class FilePlanTests extends BaseRestTest
dataProviderClass = TestData.class,
dataProvider = "getContainers"
)
public void getFilePlanComponentWhenRMIsNotCreated(String filePlanAlias) throws Exception
public void getFilePlanComponentWhenRMIsNotCreated(String filePlanComponentAlias) throws Exception
{
// Check RM Site Exist
if (rmSiteAPI.existsRMSite())
if (getRMSiteAPI().existsRMSite())
{
// Delete RM Site
rmSiteAPI.deleteRMSite();
getRMSiteAPI().deleteRMSite();
}
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// Get the file plan component
filePlanComponentAPI.getFilePlanComponent(filePlanAlias.toString());
getFilePlanComponentsAPI().getFilePlanComponent(filePlanComponentAlias);
//check the response code is NOT_FOUND
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(NOT_FOUND);
assertStatusCodeIs(NOT_FOUND);
}
@@ -122,22 +108,22 @@ public class FilePlanTests extends BaseRestTest
dataProviderClass = TestData.class,
dataProvider = "getContainersAndTypes"
)
public void getFilePlanComponentWhenRMIsCreated(FilePlanComponentAlias filePlanAlias, FilePlanComponentType rmType) throws Exception
public void getFilePlanComponentWhenRMIsCreated(String filePlanComponentAlias, String filePlanComponentType) throws Exception
{
// Create RM Site if doesn't exist
createRMSiteIfNotExists();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// Get the file plan special container
FilePlanComponent filePlanComponent = filePlanComponentAPI.getFilePlanComponent(filePlanAlias.toString());
FilePlanComponentModel filePlanComponent = getFilePlanComponentsAPI().getFilePlanComponent(filePlanComponentAlias);
// Check the response code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK);
assertStatusCodeIs(OK);
// Check the response contains the right node type
assertEquals(filePlanComponent.getNodeType(), rmType.toString());
assertEquals(filePlanComponent.getNodeType(), filePlanComponentType);
}
/**
@@ -157,13 +143,13 @@ public class FilePlanTests extends BaseRestTest
createRMSiteIfNotExists();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// Get the file plan special containers with the optional parameter allowableOperations
FilePlanComponent filePlanComponent = filePlanComponentAPI.withParams("include="+ ALLOWABLE_OPERATIONS).getFilePlanComponent(specialContainerAlias);
FilePlanComponentModel filePlanComponent = getFilePlanComponentsAPI().getFilePlanComponent(specialContainerAlias, "include=" + ALLOWABLE_OPERATIONS);
// Check the list of allowableOperations returned
if(specialContainerAlias.equals(TRANSFERS_ALIAS.toString()))
if(specialContainerAlias.equals(TRANSFERS_ALIAS))
{
assertTrue(filePlanComponent.getAllowableOperations().containsAll(asList(UPDATE)),
"Wrong list of the allowable operations is return" + filePlanComponent.getAllowableOperations().toString());
@@ -196,10 +182,10 @@ public class FilePlanTests extends BaseRestTest
createRMSiteIfNotExists();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// Build object for updating the filePlan
FilePlanComponent filePlanComponent = FilePlanComponent.builder()
FilePlanComponentModel filePlanComponent = FilePlanComponentModel.builder()
.properties(FilePlanComponentProperties.builder()
.title(FILE_PLAN_TITLE)
.description(FILE_PLAN_DESCRIPTION)
@@ -207,10 +193,10 @@ public class FilePlanTests extends BaseRestTest
.build();
// Update the record category
FilePlanComponent renamedFilePlanComponent = filePlanComponentAPI.updateFilePlanComponent(filePlanComponent,FILE_PLAN_ALIAS.toString());
FilePlanComponentModel renamedFilePlanComponent = getFilePlanComponentsAPI().updateFilePlanComponent(filePlanComponent, FILE_PLAN_ALIAS);
// Verify the response status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK);
assertStatusCodeIs(OK);
// Verify the returned description field for the file plan component
assertEquals(renamedFilePlanComponent.getProperties().getDescription(), FILE_PLAN_DESCRIPTION);
@@ -230,19 +216,19 @@ public class FilePlanTests extends BaseRestTest
dataProviderClass = TestData.class,
dataProvider = "getContainers"
)
public void deleteFilePlanSpecialComponents(String filePlanAlias) throws Exception
public void deleteFilePlanSpecialComponents(String filePlanComponentAlias) throws Exception
{
// Create RM Site if doesn't exist
createRMSiteIfNotExists();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// Delete the file plan component
filePlanComponentAPI.deleteFilePlanComponent(filePlanAlias.toString());
getFilePlanComponentsAPI().deleteFilePlanComponent(filePlanComponentAlias);
// Check the DELETE response status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
assertStatusCodeIs(UNPROCESSABLE_ENTITY);
}
/**
@@ -256,27 +242,27 @@ public class FilePlanTests extends BaseRestTest
dataProviderClass = TestData.class,
dataProvider = "getContainers"
)
public void deleteFilePlanSpecialComponentsNonRMUser(String filePlanAlias) throws Exception
public void deleteFilePlanSpecialComponentsNonRMUser(String filePlanComponentAlias) throws Exception
{
// Create RM Site if doesn't exist
createRMSiteIfNotExists();
// Disconnect the current user from the API session
rmSiteAPI.usingRestWrapper().disconnect();
disconnect();
// Authenticate admin user to Alfresco REST API
restClient.authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// Create a random user
UserModel nonRMuser = dataUser.createRandomTestUser("testUser");
// Authenticate using the random user
filePlanComponentAPI.usingRestWrapper().authenticateUser(nonRMuser);
authenticateUser(nonRMuser);
// Delete the file plan component
filePlanComponentAPI.deleteFilePlanComponent(filePlanAlias.toString());
getFilePlanComponentsAPI().deleteFilePlanComponent(filePlanComponentAlias);
// Check the DELETE response status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN);
assertStatusCodeIs(FORBIDDEN);
}
/**
@@ -291,40 +277,40 @@ public class FilePlanTests extends BaseRestTest
dataProvider = "getContainersAndTypes"
)
@Bug(id = "RM-4296")
public void createFilePlanSpecialContainerWhenExists(FilePlanComponentAlias filePlanAlias, FilePlanComponentType rmType) throws Exception
public void createFilePlanSpecialContainerWhenExists(String filePlanComponentAlias, String filePlanComponentType) throws Exception
{
// Create RM Site if doesn't exist
createRMSiteIfNotExists();
// Authenticate with admin user
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// Get the RM site ID
String rmSiteId = rmSiteAPI.getSite().getGuid();
String name = filePlanAlias + getRandomAlphanumeric();
String rmSiteId = getRMSiteAPI().getSite().getGuid();
String name = filePlanComponentAlias + getRandomAlphanumeric();
// Build the file plan root properties
FilePlanComponent filePlanComponent = FilePlanComponent.builder()
FilePlanComponentModel filePlanComponent = FilePlanComponentModel.builder()
.name(name)
.nodeType(rmType.toString())
.nodeType(filePlanComponentType)
.properties(FilePlanComponentProperties.builder()
.build())
.build();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// Create the special containers into RM site - parent folder
filePlanComponentAPI.createFilePlanComponent(filePlanComponent, rmSiteId);
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
getFilePlanComponentsAPI().createFilePlanComponent(filePlanComponent, rmSiteId);
assertStatusCodeIs(UNPROCESSABLE_ENTITY);
// Create the special containers into RM site - parent folder
filePlanComponentAPI.createFilePlanComponent(filePlanComponent, FILE_PLAN_ALIAS.toString());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
getFilePlanComponentsAPI().createFilePlanComponent(filePlanComponent, FILE_PLAN_ALIAS);
assertStatusCodeIs(UNPROCESSABLE_ENTITY);
// Create the special containers into the root of special containers containers
filePlanComponentAPI.createFilePlanComponent(filePlanComponent, filePlanAlias.toString());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
getFilePlanComponentsAPI().createFilePlanComponent(filePlanComponent, filePlanComponentAlias);
assertStatusCodeIs(UNPROCESSABLE_ENTITY);
}
/**
@@ -338,13 +324,13 @@ public class FilePlanTests extends BaseRestTest
dataProviderClass = TestData.class,
dataProvider = "getContainers"
)
public void getSpecialFilePlanComponentsWithNonRMuser(String filePlanAlias) throws Exception
public void getSpecialFilePlanComponentsWithNonRMuser(String filePlanComponentAlias) throws Exception
{
// Create RM Site if doesn't exist
createRMSiteIfNotExists();
// Disconnect user from REST API session
rmSiteAPI.usingRestWrapper().disconnect();
disconnect();
// Authenticate admin user to Alfresco REST API
restClient.authenticateUser(dataUser.getAdminUser());
@@ -353,12 +339,12 @@ public class FilePlanTests extends BaseRestTest
UserModel nonRMuser = dataUser.createRandomTestUser("testUser");
// Authenticate using the random user
filePlanComponentAPI.usingRestWrapper().authenticateUser(nonRMuser);
authenticateUser(nonRMuser);
// Get the special file plan components
filePlanComponentAPI.getFilePlanComponent(filePlanAlias.toString());
getFilePlanComponentsAPI().getFilePlanComponent(filePlanComponentAlias);
// Check the response status code is FORBIDDEN
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN);
assertStatusCodeIs(FORBIDDEN);
}
}

View File

@@ -46,10 +46,8 @@ import static org.testng.Assert.assertFalse;
import java.util.Random;
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.FilePlanComponentModel;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
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.data.DataUser;
import org.alfresco.utility.model.SiteModel;
@@ -65,15 +63,9 @@ import org.testng.annotations.Test;
*/
public class NonElectronicRecordTests extends BaseRestTest
{
@Autowired
private FilePlanComponentAPI filePlanComponentAPI;
@Autowired
private DataUser dataUser;
@Autowired
private RMSiteAPI rmSiteAPI;
/**
* <pre>
* Given a parent container that is NOT a record folder or an unfiled record folder
@@ -86,37 +78,37 @@ public class NonElectronicRecordTests extends BaseRestTest
@Test(description = "Non-electronic record can't be created as a child of invalid parent Id")
public void cantCreateForInvalidParentIds() throws Exception
{
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// non-electronic record object to be used for create tests
FilePlanComponent nonElectronicRecord = FilePlanComponent.builder()
FilePlanComponentModel nonElectronicRecord = FilePlanComponentModel.builder()
.name("Record " + getRandomAlphanumeric())
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
.build();
// create record category, non-electronic records can't be its children
FilePlanComponent recordCategoryModel = FilePlanComponent.builder()
FilePlanComponentModel recordCategoryModel = FilePlanComponentModel.builder()
.name("Category " + getRandomAlphanumeric())
.nodeType(RECORD_CATEGORY_TYPE.toString())
.nodeType(RECORD_CATEGORY_TYPE)
.build();
FilePlanComponent recordCategory = filePlanComponentAPI.createFilePlanComponent(recordCategoryModel, FILE_PLAN_ALIAS.toString());
FilePlanComponentModel recordCategory = getFilePlanComponentsAPI().createFilePlanComponent(recordCategoryModel, FILE_PLAN_ALIAS);
// iterate through all invalid parent containers and try to create/file an electronic record
asList(FILE_PLAN_ALIAS.toString(), TRANSFERS_ALIAS.toString(), HOLDS_ALIAS.toString(), recordCategory.getId())
asList(FILE_PLAN_ALIAS, TRANSFERS_ALIAS, HOLDS_ALIAS, recordCategory.getId())
.stream()
.forEach(id ->
{
try
{
filePlanComponentAPI.createFilePlanComponent(nonElectronicRecord, id);
getFilePlanComponentsAPI().createFilePlanComponent(nonElectronicRecord, id);
}
catch (Exception error)
{
}
// Verify the status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
assertStatusCodeIs(UNPROCESSABLE_ENTITY);
});
}
@@ -142,12 +134,12 @@ public class NonElectronicRecordTests extends BaseRestTest
dataProvider = "validRootContainers",
description = "Non-electronic records can be created in valid containers"
)
public void canCreateInValidContainers(FilePlanComponent container) throws Exception
public void canCreateInValidContainers(FilePlanComponentModel container) throws Exception
{
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
logger.info("Root container:\n" + toJson(container));
if (container.getNodeType().equals(RECORD_FOLDER_TYPE.toString()))
if (container.getNodeType().equals(RECORD_FOLDER_TYPE))
{
// only record folders can be open or closed
assertFalse(container.getProperties().getIsClosed());
@@ -166,9 +158,9 @@ public class NonElectronicRecordTests extends BaseRestTest
Integer size = random.nextInt(Integer.MAX_VALUE);
// set values of all available properties for the non electronic records
FilePlanComponent filePlanComponent = FilePlanComponent.builder()
FilePlanComponentModel filePlanComponent = FilePlanComponentModel.builder()
.name("Record " + getRandomAlphanumeric())
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
.properties(FilePlanComponentProperties.builder()
.title(title)
.description(description)
@@ -182,15 +174,15 @@ public class NonElectronicRecordTests extends BaseRestTest
.build();
// create non-electronic record
String nonElectronicId = filePlanComponentAPI.createFilePlanComponent(
String nonElectronicId = getFilePlanComponentsAPI().createFilePlanComponent(
filePlanComponent,
container.getId()).getId();
// verify the create request status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
assertStatusCodeIs(CREATED);
// get newly created non-electonic record and verify its properties
FilePlanComponent nonElectronicRecord = filePlanComponentAPI.getFilePlanComponent(nonElectronicId);
FilePlanComponentModel nonElectronicRecord = getFilePlanComponentsAPI().getFilePlanComponent(nonElectronicId);
assertEquals(title, nonElectronicRecord.getProperties().getTitle());
assertEquals(description, nonElectronicRecord.getProperties().getDescription());
@@ -215,8 +207,8 @@ public class NonElectronicRecordTests extends BaseRestTest
@Test(description = "Non-electronic record can't be created in closed record folder")
public void cantCreateInClosedFolder() throws Exception
{
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
FilePlanComponent recordFolder = createCategoryFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString());
authenticateUser(dataUser.getAdminUser());
FilePlanComponentModel recordFolder = createCategoryFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS);
// the folder should be open
assertFalse(recordFolder.getProperties().getIsClosed());
@@ -226,15 +218,15 @@ public class NonElectronicRecordTests extends BaseRestTest
// try to create it, this should fail and throw an exception
filePlanComponentAPI.createFilePlanComponent(FilePlanComponent.builder()
getFilePlanComponentsAPI().createFilePlanComponent(FilePlanComponentModel.builder()
.name("Record " + getRandomAlphanumeric())
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
.build(),
recordFolder.getId())
.getId();
// verify the status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
assertStatusCodeIs(UNPROCESSABLE_ENTITY);
}
/**
@@ -261,22 +253,22 @@ public class NonElectronicRecordTests extends BaseRestTest
dataProvider = "validRootContainers",
description = "Non-electronic record can only be created if all mandatory properties are given"
)
public void allMandatoryPropertiesRequired(FilePlanComponent container) throws Exception
public void allMandatoryPropertiesRequired(FilePlanComponentModel container) throws Exception
{
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
logger.info("Root container:\n" + toJson(container));
if (container.getNodeType().equals(RECORD_FOLDER_TYPE.toString()))
if (container.getNodeType().equals(RECORD_FOLDER_TYPE))
{
// only record folders can be open or closed
assertFalse(container.getProperties().getIsClosed());
}
// component without name and title
FilePlanComponent noNameOrTitle = getDummyNonElectronicRecord();
FilePlanComponentModel noNameOrTitle = getDummyNonElectronicRecord();
// component with title only
FilePlanComponent titleOnly = getDummyNonElectronicRecord();
FilePlanComponentModel titleOnly = getDummyNonElectronicRecord();
FilePlanComponentProperties properties = FilePlanComponentProperties.builder()
.title("Title " + getRandomAlphanumeric())
.build();
@@ -296,14 +288,14 @@ public class NonElectronicRecordTests extends BaseRestTest
// this should fail and throw an exception
try
{
filePlanComponentAPI.createFilePlanComponent(c, container.getId());
getFilePlanComponentsAPI().createFilePlanComponent(c, container.getId());
}
catch (Exception e)
{
}
// verify the status code is BAD_REQUEST
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(BAD_REQUEST);
assertStatusCodeIs(BAD_REQUEST);
});
}
@@ -321,45 +313,45 @@ public class NonElectronicRecordTests extends BaseRestTest
dataProvider = "validRootContainers",
description = "Non-electronic record can't be created if user doesn't have RM privileges"
)
public void cantCreateIfNoRmPrivileges(FilePlanComponent container) throws Exception
public void cantCreateIfNoRmPrivileges(FilePlanComponentModel container) throws Exception
{
String username = "zzzuser";
UserModel user = createUserWithRole(username, UserRole.SiteManager);
filePlanComponentAPI.usingRestWrapper().authenticateUser(user);
authenticateUser(user);
// try to create a fileplan component
FilePlanComponent record=FilePlanComponent.builder()
FilePlanComponentModel record = FilePlanComponentModel.builder()
.properties(FilePlanComponentProperties.builder()
.description("Description")
.title("Title")
.build())
.name("Record Name")
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
.build();
// this should fail and throw an exception
try
{
filePlanComponentAPI.createFilePlanComponent(record, container.getId());
getFilePlanComponentsAPI().createFilePlanComponent(record, container.getId());
}
catch (Exception e)
{
}
// user who isn't an RM site member can't access the container path
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN);
assertStatusCodeIs(FORBIDDEN);
}
/**
* Helper function to return an empty FilePlanComponent for non-electronic record
* @return
*/
private FilePlanComponent getDummyNonElectronicRecord()
private FilePlanComponentModel getDummyNonElectronicRecord()
{
FilePlanComponent component=FilePlanComponent.builder()
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
FilePlanComponentModel component = FilePlanComponentModel.builder()
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
.build();
return component;
}
@@ -378,8 +370,8 @@ public class NonElectronicRecordTests extends BaseRestTest
*/
private UserModel createUserWithRole(String userName, UserRole userRole) throws Exception
{
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
String siteId = rmSiteAPI.getSite().getId();
authenticateUser(dataUser.getAdminUser());
String siteId = getRMSiteAPI().getSite().getId();
// check if user exists
UserModel user = new UserModel();

View File

@@ -44,14 +44,11 @@ import static org.testng.Assert.fail;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.rm.community.base.BaseRestTest;
import org.alfresco.rest.rm.community.base.TestData;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentModel;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection;
import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.report.Bug;
import org.springframework.beans.factory.annotation.Autowired;
@@ -66,9 +63,6 @@ import org.testng.annotations.Test;
*/
public class RecordCategoryTest extends BaseRestTest
{
@Autowired
private FilePlanComponentAPI filePlanComponentAPI;
@Autowired
private DataUser dataUser;
@@ -88,15 +82,15 @@ public class RecordCategoryTest extends BaseRestTest
public void createCategoryTest() throws Exception
{
// Authenticate with admin user
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
String categoryName = "Category name " + getRandomAlphanumeric();
String categoryTitle = "Category title " + getRandomAlphanumeric();
// Build the record category properties
FilePlanComponent recordCategory = FilePlanComponent.builder()
FilePlanComponentModel recordCategory = FilePlanComponentModel.builder()
.name(categoryName)
.nodeType(RECORD_CATEGORY_TYPE.toString())
.nodeType(RECORD_CATEGORY_TYPE)
.properties(
FilePlanComponentProperties.builder()
.title(categoryTitle)
@@ -104,10 +98,10 @@ public class RecordCategoryTest extends BaseRestTest
.build();
// Create the record category
FilePlanComponent filePlanComponent = filePlanComponentAPI.createFilePlanComponent(recordCategory, FILE_PLAN_ALIAS.toString());
FilePlanComponentModel filePlanComponent = getFilePlanComponentsAPI().createFilePlanComponent(recordCategory, FILE_PLAN_ALIAS);
// Verify the status code
restWrapper.assertStatusCodeIs(CREATED);
assertStatusCodeIs(CREATED);
// Verify the returned file plan component
assertTrue(filePlanComponent.getIsCategory());
@@ -115,7 +109,7 @@ public class RecordCategoryTest extends BaseRestTest
assertFalse(filePlanComponent.getIsRecordFolder());
assertEquals(filePlanComponent.getName(), categoryName);
assertEquals(filePlanComponent.getNodeType(), RECORD_CATEGORY_TYPE.toString());
assertEquals(filePlanComponent.getNodeType(), RECORD_CATEGORY_TYPE);
assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername());
@@ -139,16 +133,16 @@ public class RecordCategoryTest extends BaseRestTest
public void renameCategory() throws Exception
{
// Authenticate with admin user
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// Create record category first
String categoryName = "Category name " + getRandomAlphanumeric();
String categoryTitle = "Category title " + getRandomAlphanumeric();
// Build the record category properties
FilePlanComponent recordCategory = FilePlanComponent.builder()
FilePlanComponentModel recordCategory = FilePlanComponentModel.builder()
.name(categoryName)
.nodeType(RECORD_CATEGORY_TYPE.toString())
.nodeType(RECORD_CATEGORY_TYPE)
.properties(
FilePlanComponentProperties.builder()
.title(categoryTitle)
@@ -156,24 +150,24 @@ public class RecordCategoryTest extends BaseRestTest
.build();
// Create the record category
FilePlanComponent filePlanComponent = filePlanComponentAPI.createFilePlanComponent(recordCategory, FILE_PLAN_ALIAS.toString());
FilePlanComponentModel filePlanComponent = getFilePlanComponentsAPI().createFilePlanComponent(recordCategory, FILE_PLAN_ALIAS);
String newCategoryName = "Rename " + categoryName;
// Build the properties which will be updated
FilePlanComponent recordCategoryUpdated = FilePlanComponent.builder().name(newCategoryName).build();
FilePlanComponentModel recordCategoryUpdated = FilePlanComponentModel.builder().name(newCategoryName).build();
// Update the record category
FilePlanComponent renamedFilePlanComponent = filePlanComponentAPI.updateFilePlanComponent(recordCategoryUpdated, filePlanComponent.getId());
FilePlanComponentModel renamedFilePlanComponent = getFilePlanComponentsAPI().updateFilePlanComponent(recordCategoryUpdated, filePlanComponent.getId());
// Verify the status code
restWrapper.assertStatusCodeIs(OK);
assertStatusCodeIs(OK);
// Verify the returned file plan component
assertEquals(renamedFilePlanComponent.getName(), newCategoryName);
// Get actual FILE_PLAN_ALIAS id
FilePlanComponent parentComponent = filePlanComponentAPI.getFilePlanComponent(FILE_PLAN_ALIAS.toString());
FilePlanComponentModel parentComponent = getFilePlanComponentsAPI().getFilePlanComponent(FILE_PLAN_ALIAS);
// verify renamed component still has this parent
assertEquals(renamedFilePlanComponent.getParentId(), parentComponent.getId());
@@ -192,16 +186,16 @@ public class RecordCategoryTest extends BaseRestTest
public void deleteCategory() throws Exception
{
// Authenticate with admin user
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// Create record category first
String categoryName = "Category name " + getRandomAlphanumeric();
String categoryTitle = "Category title " + getRandomAlphanumeric();
// Build the record category properties
FilePlanComponent recordCategory = FilePlanComponent.builder()
FilePlanComponentModel recordCategory = FilePlanComponentModel.builder()
.name(categoryName)
.nodeType(RECORD_CATEGORY_TYPE.toString())
.nodeType(RECORD_CATEGORY_TYPE)
.properties(
FilePlanComponentProperties.builder()
.title(categoryTitle)
@@ -209,17 +203,17 @@ public class RecordCategoryTest extends BaseRestTest
.build();
// Create the record category
FilePlanComponent filePlanComponent = filePlanComponentAPI.createFilePlanComponent(recordCategory, FILE_PLAN_ALIAS.toString());
FilePlanComponentModel filePlanComponent = getFilePlanComponentsAPI().createFilePlanComponent(recordCategory, FILE_PLAN_ALIAS);
// Delete the record category
filePlanComponentAPI.deleteFilePlanComponent(filePlanComponent.getId());
getFilePlanComponentsAPI().deleteFilePlanComponent(filePlanComponent.getId());
// Verify the status code
restWrapper.assertStatusCodeIs(NO_CONTENT);
assertStatusCodeIs(NO_CONTENT);
// Deleted component should no longer be retrievable
filePlanComponentAPI.getFilePlanComponent(filePlanComponent.getId());
restWrapper.assertStatusCodeIs(NOT_FOUND);
getFilePlanComponentsAPI().getFilePlanComponent(filePlanComponent.getId());
assertStatusCodeIs(NOT_FOUND);
}
/**
@@ -235,11 +229,11 @@ public class RecordCategoryTest extends BaseRestTest
public void createSubcategory() throws Exception
{
// Create root level category
FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), getRandomAlphanumeric());
FilePlanComponentModel rootCategory = createCategory(FILE_PLAN_ALIAS, getRandomAlphanumeric());
assertNotNull(rootCategory.getId());
// Create subcategory as a child of rootCategory
FilePlanComponent childCategory = createCategory(rootCategory.getId(), getRandomAlphanumeric());
FilePlanComponentModel childCategory = createCategory(rootCategory.getId(), getRandomAlphanumeric());
// Child category created?
assertNotNull(childCategory.getId());
@@ -249,7 +243,7 @@ public class RecordCategoryTest extends BaseRestTest
assertTrue(childCategory.getIsCategory());
assertFalse(childCategory.getIsFile());
assertFalse(childCategory.getIsRecordFolder());
assertEquals(childCategory.getNodeType(), RECORD_CATEGORY_TYPE.toString());
assertEquals(childCategory.getNodeType(), RECORD_CATEGORY_TYPE);
}
/**
@@ -267,15 +261,15 @@ public class RecordCategoryTest extends BaseRestTest
public void listChildren() throws Exception
{
// Create root level category
FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), getRandomAlphanumeric());
FilePlanComponentModel rootCategory = createCategory(FILE_PLAN_ALIAS, getRandomAlphanumeric());
assertNotNull(rootCategory.getId());
// Add child categories/folders
ArrayList<FilePlanComponent> children = new ArrayList<FilePlanComponent>();
ArrayList<FilePlanComponentModel> children = new ArrayList<FilePlanComponentModel>();
for (int i=0; i < NUMBER_OF_CHILDREN; i++)
{
// Create a child
FilePlanComponent child = createComponent(rootCategory.getId(),
FilePlanComponentModel child = createComponent(rootCategory.getId(),
getRandomAlphanumeric(),
// half of the children should be subcategories, the other subfolders
(i <= NUMBER_OF_CHILDREN / 2) ? RECORD_CATEGORY_TYPE : RECORD_FOLDER_TYPE);
@@ -284,26 +278,26 @@ public class RecordCategoryTest extends BaseRestTest
}
// Authenticate with admin user
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// List children from API
FilePlanComponentsCollection apiChildren = filePlanComponentAPI.listChildComponents(rootCategory.getId());
FilePlanComponentsCollection apiChildren = getFilePlanComponentsAPI().listChildComponents(rootCategory.getId());
// Check status code
restWrapper.assertStatusCodeIs(OK);
assertStatusCodeIs(OK);
logger.info("parent: " + rootCategory.getId());
// Check listed children against created list
apiChildren.getEntries().forEach(c ->
{
FilePlanComponent filePlanComponent = c.getFilePlanComponent();
FilePlanComponentModel filePlanComponent = c.getFilePlanComponentModel();
assertNotNull(filePlanComponent.getId());
logger.info("Checking child " + filePlanComponent.getId());
try
{
// Find this child in created children list
FilePlanComponent createdComponent = children.stream()
FilePlanComponentModel createdComponent = children.stream()
.filter(child -> child.getId().equals(filePlanComponent.getId()))
.findFirst()
.get();
@@ -319,7 +313,7 @@ public class RecordCategoryTest extends BaseRestTest
// Boolean properties related to node type
// Only RECORD_CATEGORY_TYPE and RECORD_FOLDER_TYPE have been created
if (filePlanComponent.getNodeType().equals(RECORD_CATEGORY_TYPE.toString()))
if (filePlanComponent.getNodeType().equals(RECORD_CATEGORY_TYPE))
{
assertTrue(filePlanComponent.getIsCategory());
assertFalse(filePlanComponent.getIsRecordFolder());
@@ -362,13 +356,13 @@ public class RecordCategoryTest extends BaseRestTest
String COMPONENT_NAME = "Component"+getRandomAlphanumeric();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
//Create the category
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), COMPONENT_NAME);
FilePlanComponentModel category = createCategory(FILE_PLAN_ALIAS, COMPONENT_NAME);
//Build node properties
FilePlanComponent recordCategory = FilePlanComponent.builder()
FilePlanComponentModel recordCategory = FilePlanComponentModel.builder()
.name(COMPONENT_NAME)
.nodeType(nodeType)
.properties(
@@ -378,8 +372,8 @@ public class RecordCategoryTest extends BaseRestTest
.build();
//create the invalid node type
filePlanComponentAPI.createFilePlanComponent(recordCategory, category.getId());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
getFilePlanComponentsAPI().createFilePlanComponent(recordCategory, category.getId());
assertStatusCodeIs(UNPROCESSABLE_ENTITY);
}
@@ -391,7 +385,7 @@ public class RecordCategoryTest extends BaseRestTest
* @return The created category
* @throws Exception on unsuccessful component creation
*/
public FilePlanComponent createCategory(String parentCategoryId, String categoryName) throws Exception
public FilePlanComponentModel createCategory(String parentCategoryId, String categoryName) throws Exception
{
return createComponent(parentCategoryId, categoryName, RECORD_CATEGORY_TYPE);
}
@@ -405,20 +399,22 @@ public class RecordCategoryTest extends BaseRestTest
* @return The created file plan component
* @throws Exception
*/
private FilePlanComponent createComponent(String parentComponentId, String componentName, FilePlanComponentType componentType) throws Exception
private FilePlanComponentModel createComponent(String parentComponentId, String componentName, String componentType) throws Exception
{
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
//Build node properties
FilePlanComponent component = FilePlanComponent.builder()
FilePlanComponentModel component = FilePlanComponentModel.builder()
.name(componentName)
.nodeType(componentType.toString())
.nodeType(componentType)
.properties(FilePlanComponentProperties.builder()
.title("Title for " + componentName)
.build())
.build();
FilePlanComponent fpc = filePlanComponentAPI.createFilePlanComponent(component, parentComponentId);
restWrapper.assertStatusCodeIs(CREATED);
FilePlanComponentModel fpc = getFilePlanComponentsAPI().createFilePlanComponent(component, parentComponentId);
assertStatusCodeIs(CREATED);
return fpc;
}
}

View File

@@ -49,14 +49,12 @@ import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.rm.community.base.BaseRestTest;
import org.alfresco.rest.rm.community.base.TestData;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentModel;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection;
import org.alfresco.rest.rm.community.model.fileplancomponents.ReviewPeriod;
import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.report.Bug;
import org.springframework.beans.factory.annotation.Autowired;
@@ -72,9 +70,6 @@ import org.testng.annotations.Test;
*/
public class RecordFolderTests extends BaseRestTest
{
@Autowired
public FilePlanComponentAPI filePlanComponentAPI;
@Autowired
public DataUser dataUser;
@@ -92,22 +87,21 @@ public class RecordFolderTests extends BaseRestTest
{
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
FilePlanComponent filePlanComponent = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY);
authenticateUser(dataUser.getAdminUser());
FilePlanComponentModel filePlanComponent = createCategory(FILE_PLAN_ALIAS, CATEGORY);
FilePlanComponent recordFolder = FilePlanComponent.builder()
FilePlanComponentModel recordFolder = FilePlanComponentModel.builder()
.name(FOLDER_NAME)
.nodeType(RECORD_FOLDER_TYPE.toString())
.nodeType(RECORD_FOLDER_TYPE)
.properties(FilePlanComponentProperties.builder()
.title(FOLDER_TITLE)
.build())
.build();
// Create the record folder
FilePlanComponent folder = filePlanComponentAPI.createFilePlanComponent(recordFolder, filePlanComponent.getId());
FilePlanComponentModel folder = getFilePlanComponentsAPI().createFilePlanComponent(recordFolder, filePlanComponent.getId());
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
assertStatusCodeIs(CREATED);
// Check folder has been created within the category created
assertEquals(filePlanComponent.getId(),folder.getParentId());
@@ -117,7 +111,7 @@ public class RecordFolderTests extends BaseRestTest
assertTrue(folder.getIsRecordFolder());
assertEquals(folder.getName(), FOLDER_NAME);
assertEquals(folder.getNodeType(), RECORD_FOLDER_TYPE.toString());
assertEquals(folder.getNodeType(), RECORD_FOLDER_TYPE);
assertEquals(folder.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername());
// Verify the returned file plan component properties
@@ -140,24 +134,24 @@ public class RecordFolderTests extends BaseRestTest
public void createFolderIntoSpecialContainers(String filePlanComponent) throws Exception
{
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
String componentID = filePlanComponentAPI.getFilePlanComponent(filePlanComponent).getId();
String componentID = getFilePlanComponentsAPI().getFilePlanComponent(filePlanComponent).getId();
// Build the record category properties
FilePlanComponent recordFolder = FilePlanComponent.builder()
FilePlanComponentModel recordFolder = FilePlanComponentModel.builder()
.name(FOLDER_NAME)
.nodeType(RECORD_FOLDER_TYPE.toString())
.nodeType(RECORD_FOLDER_TYPE)
.properties(FilePlanComponentProperties.builder()
.title(FOLDER_TITLE)
.build())
.build();
// Create a record folder
filePlanComponentAPI.createFilePlanComponent(recordFolder, componentID);
getFilePlanComponentsAPI().createFilePlanComponent(recordFolder, componentID);
// Check the API Response code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
assertStatusCodeIs(UNPROCESSABLE_ENTITY);
}
/**
@@ -173,14 +167,14 @@ public class RecordFolderTests extends BaseRestTest
{
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY);
FilePlanComponent folder = createFolder(category.getId(),FOLDER_NAME);
authenticateUser(dataUser.getAdminUser());
FilePlanComponentModel category = createCategory(FILE_PLAN_ALIAS, CATEGORY);
FilePlanComponentModel folder = createFolder(category.getId(),FOLDER_NAME);
FilePlanComponent folderDetails = filePlanComponentAPI.withParams("include="+IS_CLOSED).getFilePlanComponent(folder.getId());
FilePlanComponentModel folderDetails = getFilePlanComponentsAPI().getFilePlanComponent(folder.getId(), "include=" + IS_CLOSED);
// Verify the returned properties for the file plan component - record folder
assertEquals(RECORD_FOLDER_TYPE.toString(),folderDetails.getNodeType());
assertEquals(RECORD_FOLDER_TYPE, folderDetails.getNodeType());
assertTrue(folderDetails.getIsRecordFolder());
assertFalse(folderDetails.getIsCategory());
assertFalse(folderDetails.getIsFile());
@@ -190,7 +184,6 @@ public class RecordFolderTests extends BaseRestTest
assertEquals(dataUser.getAdminUser().getUsername(),folderDetails.getCreatedByUser().getId());
assertEquals(dataUser.getAdminUser().getUsername(), folderDetails.getModifiedByUser().getId());
assertEquals(FOLDER_TITLE,folderDetails.getProperties().getTitle());
}
@@ -208,13 +201,15 @@ public class RecordFolderTests extends BaseRestTest
public void updateTheRecordFolderProperties() throws Exception
{
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
//Create a record category
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY);
FilePlanComponentModel category = createCategory(FILE_PLAN_ALIAS, CATEGORY);
//Create a record folder
FilePlanComponent folder = createFolder(category.getId(), FOLDER_NAME);
FilePlanComponentModel folder = createFolder(category.getId(), FOLDER_NAME);
// Create record category first
String folderDescription = "The folder description is updated" + getRandomAlphanumeric();
@@ -223,7 +218,7 @@ public class RecordFolderTests extends BaseRestTest
String location = "Location"+getRandomAlphanumeric();
//Create the file plan component properties to update
FilePlanComponent recordFolder = FilePlanComponent.builder()
FilePlanComponentModel recordFolder = FilePlanComponentModel.builder()
.name(folderName)
.properties(FilePlanComponentProperties.builder()
.title(folderTitle)
@@ -235,10 +230,10 @@ public class RecordFolderTests extends BaseRestTest
.build();
// Update the record category
FilePlanComponent folderUpdated = filePlanComponentAPI.updateFilePlanComponent(recordFolder, folder.getId());
FilePlanComponentModel folderUpdated = getFilePlanComponentsAPI().updateFilePlanComponent(recordFolder, folder.getId());
// Check the Response Status Code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK);
assertStatusCodeIs(OK);
// Verify the returned properties for the file plan component - record folder
assertEquals(folderName, folderUpdated.getName());
@@ -265,21 +260,23 @@ public class RecordFolderTests extends BaseRestTest
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// Create the record category
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY);
FilePlanComponentModel category = createCategory(FILE_PLAN_ALIAS, CATEGORY);
// Create the record folder
FilePlanComponent folder = createFolder(category.getId(), FOLDER_NAME);
FilePlanComponentModel folder = createFolder(category.getId(), FOLDER_NAME);
// Delete the Record folder
filePlanComponentAPI.deleteFilePlanComponent(folder.getId());
getFilePlanComponentsAPI().deleteFilePlanComponent(folder.getId());
// Check the Response Status Code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(NO_CONTENT);
assertStatusCodeIs(NO_CONTENT);
// Check the File Plan Component is not found
filePlanComponentAPI.getFilePlanComponent(folder.getId());
getFilePlanComponentsAPI().getFilePlanComponent(folder.getId());
// Check the Response Status Code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(NOT_FOUND);
assertStatusCodeIs(NOT_FOUND);
}
/**
@@ -299,40 +296,40 @@ public class RecordFolderTests extends BaseRestTest
String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY);
authenticateUser(dataUser.getAdminUser());
FilePlanComponentModel category = createCategory(FILE_PLAN_ALIAS, CATEGORY);
// Add child olders
ArrayList<FilePlanComponent> children = new ArrayList<FilePlanComponent>();
ArrayList<FilePlanComponentModel> children = new ArrayList<FilePlanComponentModel>();
for (int i = 0; i < NUMBER_OF_FOLDERS; i++)
{
// Create a child
FilePlanComponent child = createFolder(category.getId(),
FilePlanComponentModel child = createFolder(category.getId(),
getRandomAlphanumeric());
assertNotNull(child.getId());
children.add(child);
}
// Authenticate with admin user
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// List children from API
FilePlanComponentsCollection apiChildren = filePlanComponentAPI.listChildComponents(category.getId());
FilePlanComponentsCollection apiChildren = getFilePlanComponentsAPI().listChildComponents(category.getId());
// Check status code
restWrapper.assertStatusCodeIs(OK);
assertStatusCodeIs(OK);
// Check listed children against created list
apiChildren.getEntries().forEach(c ->
{
FilePlanComponent filePlanComponent = c.getFilePlanComponent();
FilePlanComponentModel filePlanComponent = c.getFilePlanComponentModel();
assertNotNull(filePlanComponent.getId());
logger.info("Checking child " + filePlanComponent.getId());
try
{
// Find this child in created children list
FilePlanComponent createdComponent = children.stream()
FilePlanComponentModel createdComponent = children.stream()
.filter(child -> child.getId().equals(filePlanComponent.getId()))
.findFirst()
.get();
@@ -379,18 +376,18 @@ public class RecordFolderTests extends BaseRestTest
String RELATIVE_PATH = LocalDateTime.now().getYear()+"/"+ LocalDateTime.now().getMonth()+"/"+ LocalDateTime.now().getDayOfMonth();
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
//The record folder to be created
FilePlanComponent recordFolder = FilePlanComponent.builder()
FilePlanComponentModel recordFolder = FilePlanComponentModel.builder()
.name(FOLDER_NAME)
.nodeType(RECORD_FOLDER_TYPE.toString())
.nodeType(RECORD_FOLDER_TYPE)
.relativePath(RELATIVE_PATH)
.build();
// Create the record folder
FilePlanComponent folder = filePlanComponentAPI.withParams("include="+ PATH).createFilePlanComponent(recordFolder,FILE_PLAN_ALIAS.toString());
FilePlanComponentModel folder = getFilePlanComponentsAPI().createFilePlanComponent(recordFolder, FILE_PLAN_ALIAS, "include=" + PATH);
//Check the API response code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
assertStatusCodeIs(CREATED);
// Verify the returned properties for the file plan component - record folder
assertFalse(folder.getIsCategory());
@@ -400,12 +397,12 @@ public class RecordFolderTests extends BaseRestTest
//Check the path return contains the RELATIVE_PATH
assertTrue(folder.getPath().getName().contains(RELATIVE_PATH));
//check the parent is a category
assertTrue(filePlanComponentAPI.getFilePlanComponent(folder.getParentId()).getIsCategory());
assertTrue(getFilePlanComponentsAPI().getFilePlanComponent(folder.getParentId()).getIsCategory());
//check the created folder from the server
folder=filePlanComponentAPI.withParams("include=" + PATH).getFilePlanComponent(folder.getId());
folder = getFilePlanComponentsAPI().getFilePlanComponent(folder.getId(), "include=" + PATH);
//Check the API response code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK);
assertStatusCodeIs(OK);
// Verify the returned properties for the file plan component - record folder
assertFalse(folder.getIsCategory());
assertFalse(folder.getIsFile());
@@ -417,16 +414,16 @@ public class RecordFolderTests extends BaseRestTest
//New Relative Path only a part of containers need to be created before the record folder
String NEW_RELATIVE_PATH = LocalDateTime.now().getYear() + "/" + LocalDateTime.now().getMonth() + "/" +( LocalDateTime.now().getDayOfMonth()+1);
//The record folder to be created
FilePlanComponent recordFolder2 = FilePlanComponent.builder()
FilePlanComponentModel recordFolder2 = FilePlanComponentModel.builder()
.name(FOLDER_NAME)
.nodeType(RECORD_FOLDER_TYPE.toString())
.nodeType(RECORD_FOLDER_TYPE)
.relativePath(NEW_RELATIVE_PATH)
.build();
// Create the record folder
FilePlanComponent folder2 = filePlanComponentAPI.withParams("include=" + PATH).createFilePlanComponent(recordFolder2, FILE_PLAN_ALIAS.toString());
FilePlanComponentModel folder2 = getFilePlanComponentsAPI().createFilePlanComponent(recordFolder2, FILE_PLAN_ALIAS, "include=" + PATH);
//Check the API response code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
assertStatusCodeIs(CREATED);
// Verify the returned properties for the file plan component - record folder
assertFalse(folder2.getIsCategory());
@@ -436,12 +433,12 @@ public class RecordFolderTests extends BaseRestTest
assertTrue(folder2.getPath().getName().contains(NEW_RELATIVE_PATH));
//check the parent is a category
assertTrue(filePlanComponentAPI.getFilePlanComponent(folder.getParentId()).getIsCategory());
assertTrue(getFilePlanComponentsAPI().getFilePlanComponent(folder.getParentId()).getIsCategory());
// Check the folder created on the server
folder2 = filePlanComponentAPI.withParams("include=" + PATH).getFilePlanComponent(folder2.getId());
folder2 = getFilePlanComponentsAPI().getFilePlanComponent(folder2.getId(), "include=" + PATH);
//Check the API response code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK);
assertStatusCodeIs(OK);
// Verify the returned properties for the file plan component - record folder
assertFalse(folder2.getIsCategory());
@@ -454,12 +451,12 @@ public class RecordFolderTests extends BaseRestTest
@AfterClass (alwaysRun = true)
public void tearDown() throws Exception
{
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
filePlanComponentAPI.listChildComponents(FILE_PLAN_ALIAS.toString()).getEntries().forEach(filePlanComponentEntry ->
authenticateUser(dataUser.getAdminUser());
getFilePlanComponentsAPI().listChildComponents(FILE_PLAN_ALIAS).getEntries().forEach(filePlanComponentEntry ->
{
try
{
filePlanComponentAPI.deleteFilePlanComponent(filePlanComponentEntry.getFilePlanComponent().getId());
getFilePlanComponentsAPI().deleteFilePlanComponent(filePlanComponentEntry.getFilePlanComponentModel().getId());
}
catch (Exception e)
{
@@ -467,7 +464,4 @@ public class RecordFolderTests extends BaseRestTest
}
});
}
}

View File

@@ -48,13 +48,10 @@ import static org.testng.Assert.assertTrue;
import java.util.List;
import java.util.stream.Collectors;
import org.alfresco.rest.core.RestWrapper;
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.FilePlanComponentModel;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection;
import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI;
import org.alfresco.utility.data.DataUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.DataProvider;
@@ -68,9 +65,6 @@ import org.testng.annotations.Test;
*/
public class UnfiledRecordsFolderTests extends BaseRestTest
{
@Autowired
private FilePlanComponentAPI filePlanComponentAPI;
@Autowired
private DataUser dataUser;
@@ -100,27 +94,26 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
public void createRootUnfiledRecordsFolder() throws Exception
{
// Authenticate with admin user
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
String folderName = "Folder " + getRandomAlphanumeric();
String folderTitle = folderName + " Title";
String folderDescription = folderName + " Description";
// Build unfiled records folder properties
FilePlanComponent unfiledFolder = FilePlanComponent.builder()
FilePlanComponentModel unfiledFolder = FilePlanComponentModel.builder()
.name(folderName)
.nodeType(UNFILED_RECORD_FOLDER_TYPE.toString())
.nodeType(UNFILED_RECORD_FOLDER_TYPE)
.properties(FilePlanComponentProperties.builder()
.title(folderTitle)
.description(folderDescription)
.build())
.build();
FilePlanComponent filePlanComponent = filePlanComponentAPI.createFilePlanComponent(unfiledFolder,
UNFILED_RECORDS_CONTAINER_ALIAS.toString());
FilePlanComponentModel filePlanComponent = getFilePlanComponentsAPI().createFilePlanComponent(unfiledFolder, UNFILED_RECORDS_CONTAINER_ALIAS);
// Verify the status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
assertStatusCodeIs(CREATED);
// Verify the returned file plan component
assertFalse(filePlanComponent.getIsCategory());
@@ -128,7 +121,7 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
assertFalse(filePlanComponent.getIsRecordFolder()); // it is not a _normal_ record folder!
assertEquals(filePlanComponent.getName(), folderName);
assertEquals(filePlanComponent.getNodeType(), UNFILED_RECORD_FOLDER_TYPE.toString());
assertEquals(filePlanComponent.getNodeType(), UNFILED_RECORD_FOLDER_TYPE);
assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername());
@@ -146,20 +139,20 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
dataProvider = "invalidRootTypes",
description = "Only unfiled records folders can be created at unfiled records root level"
)
public void onlyRecordFoldersCanBeCreatedAtUnfiledRecordsRoot(FilePlanComponentType componentType)
public void onlyRecordFoldersCanBeCreatedAtUnfiledRecordsRoot(String filePlanComponentType)
{
filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
String folderName = "Folder " + getRandomAlphanumeric();
String folderTitle = folderName + " Title";
String folderDescription = folderName + " Description";
logger.info("creating " + componentType.toString());
logger.info("creating " + filePlanComponentType);
// Build unfiled records folder properties
FilePlanComponent unfiledFolder = FilePlanComponent.builder()
FilePlanComponentModel unfiledFolder = FilePlanComponentModel.builder()
.name(folderName)
.nodeType(componentType.toString())
.nodeType(filePlanComponentType)
.properties(FilePlanComponentProperties.builder()
.title(folderTitle)
.description(folderDescription)
@@ -168,15 +161,14 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
try
{
filePlanComponentAPI.createFilePlanComponent(unfiledFolder,
UNFILED_RECORDS_CONTAINER_ALIAS.toString());
getFilePlanComponentsAPI().createFilePlanComponent(unfiledFolder, UNFILED_RECORDS_CONTAINER_ALIAS);
}
catch (Exception error)
{
}
// Verify the status code
filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY);
assertStatusCodeIs(UNPROCESSABLE_ENTITY);
}
/**
@@ -189,7 +181,7 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
@Test(description = "Child unfiled records folder can be created in a parent unfiled records folder")
public void childUnfiledRecordsFolderCanBeCreated() throws Exception
{
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
String parentFolderName = "Parent Folder " + getRandomAlphanumeric();
String childFolderName = "Child Folder " + getRandomAlphanumeric();
@@ -197,13 +189,13 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
String childFolderDescription = childFolderName + " Description";
// No need for fine control, create it using utility function
FilePlanComponent parentFolder = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), parentFolderName);
FilePlanComponentModel parentFolder = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS, parentFolderName);
assertEquals(parentFolderName, parentFolder.getName());
// Build the unfiled records folder properties
FilePlanComponent unfiledFolder = FilePlanComponent.builder()
FilePlanComponentModel unfiledFolder = FilePlanComponentModel.builder()
.name(childFolderName)
.nodeType(UNFILED_RECORD_FOLDER_TYPE.toString())
.nodeType(UNFILED_RECORD_FOLDER_TYPE)
.properties(FilePlanComponentProperties.builder()
.title(childFolderTitle)
.description(childFolderDescription)
@@ -211,11 +203,10 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
.build();
// Create it as a child of parentFolder
FilePlanComponent childFolder = filePlanComponentAPI.createFilePlanComponent(unfiledFolder,
parentFolder.getId());
FilePlanComponentModel childFolder = getFilePlanComponentsAPI().createFilePlanComponent(unfiledFolder, parentFolder.getId());
// Verify the status code
restWrapper.assertStatusCodeIs(CREATED);
assertStatusCodeIs(CREATED);
// Verify the returned file plan component
assertFalse(childFolder.getIsCategory());
@@ -223,7 +214,7 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
assertFalse(childFolder.getIsRecordFolder()); // it is not a _normal_ record folder!
assertEquals(childFolder.getName(), childFolderName);
assertEquals(childFolder.getNodeType(), UNFILED_RECORD_FOLDER_TYPE.toString());
assertEquals(childFolder.getNodeType(), UNFILED_RECORD_FOLDER_TYPE);
assertEquals(childFolder.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername());
// Verify the returned file plan component properties
@@ -236,11 +227,11 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
// Does child's parent point to it?
// Perform another call as our parentFolder had been executed before childFolder existed
FilePlanComponentsCollection parentsChildren = filePlanComponentAPI.listChildComponents(parentFolder.getId());
restWrapper.assertStatusCodeIs(OK);
FilePlanComponentsCollection parentsChildren = getFilePlanComponentsAPI().listChildComponents(parentFolder.getId());
assertStatusCodeIs(OK);
List<String> childIds = parentsChildren.getEntries()
.stream()
.map(c -> c.getFilePlanComponent().getId())
.map(c -> c.getFilePlanComponentModel().getId())
.collect(Collectors.toList());
// Child folder is listed in parent
@@ -260,16 +251,16 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
@Test(description = "Unfiled record folder")
public void editUnfiledRecordsFolder() throws Exception
{
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
String modified = "Modified ";
String folderName = "Folder To Modify" + getRandomAlphanumeric();
// No need for fine control, create it using utility function
FilePlanComponent folderToModify = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), folderName);
FilePlanComponentModel folderToModify = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS, folderName);
assertEquals(folderName, folderToModify.getName());
// Build the properties which will be updated
FilePlanComponent folderToUpdate = FilePlanComponent.builder()
FilePlanComponentModel folderToUpdate = FilePlanComponentModel.builder()
.name(modified + folderToModify.getName())
.properties(FilePlanComponentProperties.builder().
title(modified + folderToModify.getProperties().getTitle()).
@@ -278,12 +269,12 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
.build();
// Update the unfiled records folder
filePlanComponentAPI.updateFilePlanComponent(folderToUpdate, folderToModify.getId());
getFilePlanComponentsAPI().updateFilePlanComponent(folderToUpdate, folderToModify.getId());
// Verify the status code
restWrapper.assertStatusCodeIs(OK);
assertStatusCodeIs(OK);
// This is to ensure the change was actually applied, rather than simply trusting the object returned by PUT
FilePlanComponent renamedFolder = filePlanComponentAPI.getFilePlanComponent(folderToModify.getId());
FilePlanComponentModel renamedFolder = getFilePlanComponentsAPI().getFilePlanComponent(folderToModify.getId());
// Verify the returned file plan component
assertEquals(modified + folderToModify.getName(), renamedFolder.getName());
@@ -301,21 +292,21 @@ public class UnfiledRecordsFolderTests extends BaseRestTest
@Test(description = "Delete unfiled record folder")
public void deleteUnfiledRecordsFolder() throws Exception
{
RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
String folderName = "Folder To Delete" + getRandomAlphanumeric();
// Create folderToDelete
FilePlanComponent folderToDelete = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), folderName);
FilePlanComponentModel folderToDelete = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS, folderName);
assertEquals(folderName, folderToDelete.getName());
// Delete folderToDelete
filePlanComponentAPI.deleteFilePlanComponent(folderToDelete.getId());
getFilePlanComponentsAPI().deleteFilePlanComponent(folderToDelete.getId());
// Verify the status code
restWrapper.assertStatusCodeIs(NO_CONTENT);
assertStatusCodeIs(NO_CONTENT);
// Deleted component should no longer be retrievable
filePlanComponentAPI.getFilePlanComponent(folderToDelete.getId());
restWrapper.assertStatusCodeIs(NOT_FOUND);
getFilePlanComponentsAPI().getFilePlanComponent(folderToDelete.getId());
assertStatusCodeIs(NOT_FOUND);
}
}

View File

@@ -43,10 +43,8 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import org.alfresco.dataprep.UserService;
import org.alfresco.rest.core.RestWrapper;
import org.alfresco.rest.rm.community.base.BaseRestTest;
import org.alfresco.rest.rm.community.model.site.RMSite;
import org.alfresco.rest.rm.community.requests.RMSiteAPI;
import org.alfresco.rest.rm.community.model.site.RMSiteModel;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.data.RandomData;
@@ -67,9 +65,6 @@ public class RMSiteTests extends BaseRestTest
@Autowired
private UserService userService;
@Autowired
private RMSiteAPI rmSiteAPI;
@Autowired
private DataUser dataUser;
@@ -85,24 +80,24 @@ public class RMSiteTests extends BaseRestTest
public void createRMSiteAsAdminUser() throws Exception
{
// Authenticate with admin user
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// Check if the RM site exists
if (rmSiteAPI.existsRMSite())
if (getRMSiteAPI().existsRMSite())
{
// Delete the RM site
rmSiteAPI.deleteRMSite();
getRMSiteAPI().deleteRMSite();
}
// Create the RM site
RMSite rmSite =RMSite.builder().compliance(STANDARD).build();
rmSite.setTitle(RM_TITLE);
rmSite.setDescription(RM_DESCRIPTION);
RMSiteModel rmSiteModel = RMSiteModel.builder().compliance(STANDARD).build();
rmSiteModel.setTitle(RM_TITLE);
rmSiteModel.setDescription(RM_DESCRIPTION);
RMSite rmSiteResponse = rmSiteAPI.createRMSite(rmSite);
RMSiteModel rmSiteResponse = getRMSiteAPI().createRMSite(rmSiteModel);
// Verify the status code
rmSiteAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
assertStatusCodeIs(CREATED);
// Verify the returned file plan component
assertEquals(rmSiteResponse.getId(), RM_ID);
@@ -128,21 +123,21 @@ public class RMSiteTests extends BaseRestTest
createRMSiteIfNotExists();
// Authenticate with admin user
RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// Construct new properties
String newTitle = RM_TITLE + "createRMSiteWhenSiteExists";
String newDescription = RM_DESCRIPTION + "createRMSiteWhenSiteExists";
// Create the RM site
RMSite rmSite = RMSite.builder().compliance(STANDARD).build();
rmSite.setTitle(newTitle);
rmSite.setDescription(newDescription);
RMSiteModel rmSiteModel = RMSiteModel.builder().compliance(STANDARD).build();
rmSiteModel.setTitle(newTitle);
rmSiteModel.setDescription(newDescription);
rmSiteAPI.createRMSite(rmSite);
getRMSiteAPI().createRMSite(rmSiteModel);
// Verify the status code
restWrapper.assertStatusCodeIs(CONFLICT);
assertStatusCodeIs(CONFLICT);
}
/**
@@ -157,13 +152,13 @@ public class RMSiteTests extends BaseRestTest
public void deleteRMSite() throws Exception
{
// Authenticate with admin user
RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// Delete the RM site
rmSiteAPI.deleteRMSite();
getRMSiteAPI().deleteRMSite();
// Verify the status code
restWrapper.assertStatusCodeIs(NO_CONTENT);
assertStatusCodeIs(NO_CONTENT);
}
/**
@@ -178,26 +173,26 @@ public class RMSiteTests extends BaseRestTest
public void getRMSite() throws Exception
{
// Authenticate with admin user
RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// Check if RM site exists
if (!rmSiteAPI.existsRMSite())
if (!getRMSiteAPI().existsRMSite())
{
// Verify the status code when RM site doesn't exist
restWrapper.assertStatusCodeIs(NOT_FOUND);
assertStatusCodeIs(NOT_FOUND);
createRMSiteIfNotExists();
}
else
{
// Get the RM site
RMSite rmSite = rmSiteAPI.getSite();
RMSiteModel rmSiteModel = getRMSiteAPI().getSite();
// Verify the status code
restWrapper.assertStatusCodeIs(OK);
assertEquals(rmSite.getId(), RM_ID);
assertEquals(rmSite.getDescription(), RM_DESCRIPTION);
assertEquals(rmSite.getCompliance(), STANDARD);
assertEquals(rmSite.getVisibility(), PUBLIC);
assertStatusCodeIs(OK);
assertEquals(rmSiteModel.getId(), RM_ID);
assertEquals(rmSiteModel.getDescription(), RM_DESCRIPTION);
assertEquals(rmSiteModel.getCompliance(), STANDARD);
assertEquals(rmSiteModel.getVisibility(), PUBLIC);
}
}
@@ -214,17 +209,17 @@ public class RMSiteTests extends BaseRestTest
public void createRMSiteAsAnotherAdminUser() throws Exception
{
// Authenticate with admin user
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// Check if the RM site exists
if (rmSiteAPI.existsRMSite())
if (getRMSiteAPI().existsRMSite())
{
// Delete the RM site
rmSiteAPI.deleteRMSite();
getRMSiteAPI().deleteRMSite();
}
// Disconnect the current user from the API session
rmSiteAPI.usingRestWrapper().disconnect();
disconnect();
// Create user
userService.create(dataUser.getAdminUser().getUsername(),
@@ -239,24 +234,24 @@ public class RMSiteTests extends BaseRestTest
UserModel userModel = new UserModel(ANOTHER_ADMIN,DEFAULT_PASSWORD);
// Authenticate as that new user
rmSiteAPI.usingRestWrapper().authenticateUser(userModel);
authenticateUser(userModel);
// Create the RM site
RMSite rmSite = RMSite.builder().compliance(DOD5015).build();
rmSite.setTitle(RM_TITLE);
rmSite.setDescription(RM_DESCRIPTION);
rmSite=rmSiteAPI.createRMSite(rmSite);
RMSiteModel rmSiteModel = RMSiteModel.builder().compliance(DOD5015).build();
rmSiteModel.setTitle(RM_TITLE);
rmSiteModel.setDescription(RM_DESCRIPTION);
rmSiteModel = getRMSiteAPI().createRMSite(rmSiteModel);
// Verify the status code
rmSiteAPI.usingRestWrapper().assertStatusCodeIs(CREATED);
assertStatusCodeIs(CREATED);
// Verify the returned file plan component
assertEquals(rmSite.getId(), RM_ID);
assertEquals(rmSite.getTitle(), RM_TITLE);
assertEquals(rmSite.getDescription(), RM_DESCRIPTION);
assertEquals(rmSite.getCompliance(), DOD5015);
assertEquals(rmSite.getVisibility(), PUBLIC);
assertEquals(rmSite.getRole(), UserRole.SiteManager.toString());
assertEquals(rmSiteModel.getId(), RM_ID);
assertEquals(rmSiteModel.getTitle(), RM_TITLE);
assertEquals(rmSiteModel.getDescription(), RM_DESCRIPTION);
assertEquals(rmSiteModel.getCompliance(), DOD5015);
assertEquals(rmSiteModel.getVisibility(), PUBLIC);
assertEquals(rmSiteModel.getRole(), UserRole.SiteManager.toString());
}
/**
@@ -270,52 +265,52 @@ public class RMSiteTests extends BaseRestTest
public void updateRMSiteDetails()throws Exception
{
String NEW_TITLE = RM_TITLE + RandomData.getRandomAlphanumeric();
String NEW_DESCRIPTION = RM_DESCRIPTION+ RandomData.getRandomAlphanumeric();
String NEW_DESCRIPTION = RM_DESCRIPTION + RandomData.getRandomAlphanumeric();
// Authenticate with admin user
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// Create the site if it does not exist
createRMSiteIfNotExists();
//Create RM site model
RMSite rmSiteToUpdate = new RMSite();
// Create RM site model
RMSiteModel rmSiteToUpdate = RMSiteModel.builder().build();
rmSiteToUpdate.setTitle(NEW_TITLE);
rmSiteToUpdate.setDescription(NEW_DESCRIPTION);
// Disconnect the user from the API session
rmSiteAPI.usingRestWrapper().disconnect();
disconnect();
// Create a random user
UserModel nonRMuser = dataUser.createRandomTestUser("testUser");
// Authenticate as that random user
rmSiteAPI.usingRestWrapper().authenticateUser(nonRMuser);
authenticateUser(nonRMuser);
// Create the RM site
rmSiteAPI.updateRMSite(rmSiteToUpdate);
getRMSiteAPI().updateRMSite(rmSiteToUpdate);
// Verify the status code
rmSiteAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN);
assertStatusCodeIs(FORBIDDEN);
// Disconnect the user from the API session
rmSiteAPI.usingRestWrapper().disconnect();
disconnect();
// Authenticate with admin user
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// Update the RM Site
RMSite rmSite = rmSiteAPI.updateRMSite(rmSiteToUpdate);
RMSiteModel rmSiteModel = getRMSiteAPI().updateRMSite(rmSiteToUpdate);
// Verify the response status code
rmSiteAPI.usingRestWrapper().assertStatusCodeIs(OK);
assertStatusCodeIs(OK);
// Verify the returned file plan component
assertEquals(rmSite.getId(), RM_ID);
assertEquals(rmSite.getTitle(), NEW_TITLE);
assertEquals(rmSite.getDescription(), NEW_DESCRIPTION);
assertNotNull(rmSite.getCompliance());
assertEquals(rmSite.getVisibility(), PUBLIC);
assertEquals(rmSiteModel.getId(), RM_ID);
assertEquals(rmSiteModel.getTitle(), NEW_TITLE);
assertEquals(rmSiteModel.getDescription(), NEW_DESCRIPTION);
assertNotNull(rmSiteModel.getCompliance());
assertEquals(rmSiteModel.getVisibility(), PUBLIC);
}
/**
@@ -327,18 +322,18 @@ public class RMSiteTests extends BaseRestTest
public void updateRMSiteComplianceAsAdmin() throws Exception
{
// Authenticate with admin user
rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
authenticateUser(dataUser.getAdminUser());
// Create the RM site if it does not exist
createRMSiteIfNotExists();
// Build the RM site properties
RMSite rmSiteToUpdate = RMSite.builder().compliance(DOD5015).build();
RMSiteModel rmSiteToUpdate = RMSiteModel.builder().compliance(DOD5015).build();
// Update the RM site
rmSiteAPI.updateRMSite(rmSiteToUpdate);
getRMSiteAPI().updateRMSite(rmSiteToUpdate);
// Verify the response status code
rmSiteAPI.usingRestWrapper().assertStatusCodeIs(BAD_REQUEST);
assertStatusCodeIs(BAD_REQUEST);
}
}

View File

@@ -1,2 +0,0 @@
alfresco.server=localhost
rest.rmPath=alfresco/api/-default-/public/ig/versions/1