alfrescoLogs = dockerHelper.getAlfrescoLogs();
+ assertTrue(alfrescoLogs.stream().anyMatch(logLine -> logLine.contains(expectedException)));
+ });
+
+ STEP("Check that the file is not a record");
+ assertFalse(hasRecordAspect(testFile), "File should not have record aspect");
+ }
+
+ /**
+ * Given I declare a record using the v1 API
+ * When I provide a location parameter
+ * Then the record is declared in the correct location
+ */
+ @Test
+ public void declareAndFileToValidLocationUsingFilesAPI() throws Exception
+ {
+ STEP("Declare document as record with a location parameter value");
+ Record record = getRestAPIFactory().getFilesAPI(userFillingPermission)
+ .usingParams(String.format("%s=%s", PARENT_ID_PARAM, recordFolder.getId()))
+ .declareAsRecord(testFile.getNodeRefWithoutVersion());
+ assertStatusCode(CREATED);
+
+ STEP("Verify the declared record is placed in the record folder");
+ assertEquals(record.getParentId(), recordFolder.getId(), "Record should be filed to record folder");
+
+ STEP("Verify the document in collaboration site is now a record");
+ assertTrue(hasRecordAspect(testFile), "File should have record aspect");
+ }
+
+ /**
+ * Given I declare a record using the v1 API
+ * When I provide an invalid record folder in the location parameter
+ * Then I receive an error indicating that I have attempted to declare and file a document into an invalid record folder
+ * And the document is not declared as a record
+ */
+ @Test (dataProvider = "invalidDestinationIds")
+ public void declareAndFileToInvalidLocationUsingFilesAPI(String containerID) throws Exception
+ {
+ STEP("Declare document as record with an invalid location parameter value");
+ getRestAPIFactory().getFilesAPI()
+ .usingParams(String.format("%s=%s", PARENT_ID_PARAM, containerID))
+ .declareAsRecord(testFile.getNodeRefWithoutVersion());
+ assertStatusCode(BAD_REQUEST);
+ getRestAPIFactory().getRmRestWrapper()
+ .assertLastError()
+ .containsSummary("is not valid for this endpoint. Expected nodeType is:{http://www.alfresco.org/model/recordsmanagement/1.0}recordFolder");
+
+ STEP("Check that the file is not a record");
+ assertFalse(hasRecordAspect(testFile), "File should not have record aspect");
+ }
+
+ /**
+ * Given I am an user with read only permissions on a record folder
+ * When I declare and file a record to the record folder
+ * Then I receive an error indicating that the access is denied
+ * And the document is not declared as a record
+ */
+ @Test
+ public void declareAndFileByUserWithReadOnlyPermission() throws Exception
+ {
+ STEP("Declare document as record with a record folder as location parameter");
+ getRestAPIFactory().getFilesAPI(userReadOnlyPermission)
+ .usingParams(String.format("%s=%s", PARENT_ID_PARAM, recordFolder.getId()))
+ .declareAsRecord(testFile.getNodeRefWithoutVersion());
+ assertStatusCode(FORBIDDEN);
+
+ STEP("Check that the file is not a record");
+ assertFalse(hasRecordAspect(testFile), "File should not have record aspect");
+ }
+
+ /**
+ * Given I am a non RM user
+ * When I declare and file a record to the record folder
+ * Then I receive an error indicating that the access is denied
+ * And the document is not declared as a record
+ */
+ @Test
+ public void declareAndFileByNonRMUser() throws Exception
+ {
+ STEP("Create an user with no rm rights");
+ UserModel nonRMUser = getDataUser().createRandomTestUser();
+ getDataUser().addUserToSite(nonRMUser, publicSite, UserRole.SiteCollaborator);
+
+ STEP("Declare document as record with a record folder as location parameter");
+ getRestAPIFactory().getFilesAPI(nonRMUser)
+ .usingParams(String.format("%s=%s", PARENT_ID_PARAM, recordFolder.getId()))
+ .declareAsRecord(testFile.getNodeRefWithoutVersion());
+ assertStatusCode(FORBIDDEN);
+
+ STEP("Check that the file is not a record");
+ assertFalse(hasRecordAspect(testFile), "File should not have record aspect");
+ }
+
+ /**
+ * Given I declare a record using the v1 API
+ * When I provide a nonexistent record folder in the location parameter
+ * Then I receive an error indicating that the record folder does not exist
+ * And the document is not declared as a record
+ */
+ @Test
+ public void declareAndFileToNonexistentRecordFolderUsingFilesAPI() throws Exception
+ {
+ STEP("Declare document as record with a nonexistent location parameter value");
+ getRestAPIFactory().getFilesAPI()
+ .usingParams(String.format("%s=%s", PARENT_ID_PARAM, "nonexistent"))
+ .declareAsRecord(testFile.getNodeRefWithoutVersion());
+ assertStatusCode(NOT_FOUND);
+
+ STEP("Check that the file is not a record");
+ assertFalse(hasRecordAspect(testFile), "File should not have record aspect");
+ }
+
+ /**
+ * Given I declare a record using the v1 API
+ * When I provide a closed record folder in the location parameter
+ * Then I receive an error indicating that the record folder is closed
+ * And the document is not declared as a record
+ */
+ @Test
+ public void declareAndFileToClosedRecordFolderUsingFilesAPI() throws Exception
+ {
+ STEP("Declare document as record with a closed location parameter value");
+ getRestAPIFactory().getFilesAPI()
+ .usingParams(String.format("%s=%s", PARENT_ID_PARAM, closedRecordFolder.getId()))
+ .declareAsRecord(testFile.getNodeRefWithoutVersion());
+ assertStatusCode(UNPROCESSABLE_ENTITY);
+ getRestAPIFactory().getRmRestWrapper()
+ .assertLastError()
+ .containsSummary(CLOSED_RECORD_FOLDER_EXC);
+
+ STEP("Check that the file is not a record");
+ assertFalse(hasRecordAspect(testFile), "File should not have record aspect");
+ }
+
+ /**
+ * Given I declare a record using the v1 API
+ * When I provide a held record folder in the location parameter
+ * Then I receive an error indicating that the record folder is held
+ * And the document is not declared as a record
+ */
+ @Test
+ public void declareAndFileToHeldRecordFolderUsingFilesAPI() throws Exception
+ {
+ RecordCategoryChild heldRecordFolder = createFolder(recordCategory.getId(), getRandomName("heldRecordFolder"));
+ rmRolesAndActionsAPI.createHold(getAdminUser().getUsername(), getAdminUser().getPassword(), HOLD_NAME,
+ "hold reason", "hold description");
+ rmRolesAndActionsAPI.addItemToHold(getAdminUser().getUsername(), getAdminUser().getPassword(),
+ heldRecordFolder.getId(), HOLD_NAME);
+
+ STEP("Declare document as record with a frozen location parameter value");
+ getRestAPIFactory().getFilesAPI()
+ .usingParams(String.format("%s=%s", PARENT_ID_PARAM, heldRecordFolder.getId()))
+ .declareAsRecord(testFile.getNodeRefWithoutVersion());
+ assertStatusCode(UNPROCESSABLE_ENTITY);
+
+ STEP("Check that the file is not a record");
+ assertFalse(hasRecordAspect(testFile), "File should not have record aspect");
+ }
+
+ /**
+ * Given I declare a record using the v1 API
+ * When I provide a location parameter
+ * Then the record is declared in the correct location
+ * And when I declare it again using a different location
+ * Then I get an invalid operation exception
+ */
+ @Test
+ public void declareAndFileTwiceDifferentLocations() throws Exception
+ {
+ STEP("Create a document in the collaboration site");
+ FileModel testFile = dataContent.usingSite(publicSite).usingAdmin()
+ .createContent(CMISUtil.DocumentType.TEXT_PLAIN);
+
+ STEP("Declare document as record with a record folder as location parameter");
+ getRestAPIFactory().getFilesAPI(userFillingPermission)
+ .usingParams(String.format("%s=%s", PARENT_ID_PARAM, subcategoryRecordFolder.getId()))
+ .declareAsRecord(testFile.getNodeRefWithoutVersion());
+ assertStatusCode(CREATED);
+
+ STEP("Declare it again using a different record folder as location parameter");
+ getRestAPIFactory().getFilesAPI(userFillingPermission)
+ .usingParams(String.format("%s=%s", PARENT_ID_PARAM, recordFolder.getId()))
+ .declareAsRecord(testFile.getNodeRefWithoutVersion());
+ assertStatusCode(UNPROCESSABLE_ENTITY);
+
+ STEP("Verify the declared record is placed in the first record folder");
+ assertTrue(isMatchingRecordInRecordFolder(testFile, subcategoryRecordFolder),
+ "Record should be filed to recordFolder");
+ assertFalse(isMatchingRecordInRecordFolder(testFile, recordFolder),
+ "Record should not be filed to subcategoryRecordFolder");
+ }
+
+ @AfterClass(alwaysRun = true)
+ public void declareAndFileDocumentAsRecordCleanup()
+ {
+ //delete rm items
+ deleteRecordCategory(recordCategory.getId());
+ getRestAPIFactory().getUnfiledRecordFoldersAPI().deleteUnfiledRecordFolder(unfiledContainerFolder.getId());
+
+ //delete created collaboration site
+ dataSite.deleteSite(publicSite);
+
+ //delete users
+ getDataUser().deleteUser(userFillingPermission);
+ getDataUser().deleteUser(userReadOnlyPermission);
+ }
+}
diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/DeclareDocumentAsRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/DeclareDocumentAsRecordTests.java
index 077703bca5..af871ccabe 100644
--- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/DeclareDocumentAsRecordTests.java
+++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/DeclareDocumentAsRecordTests.java
@@ -100,10 +100,16 @@ public class DeclareDocumentAsRecordTests extends BaseRMRestTest
* And it is now a record
* And it remains a secondary child of the starting location where I can still view it
*
+ *
+ * RM-6779
+ * Given I declare a record using the v1 API
+ * When I do not provide a location parameter
+ * Then the record is declared in the unfiled folder
+ *
* @throws Exception for malformed JSON API response
*/
@Test(description = "User with correct permissions can declare document as a record")
- @AlfrescoTest(jira = "RM-4429")
+ @AlfrescoTest(jira = "RM-4429, RM-6779")
public void userWithPrivilegesCanDeclareDocumentAsRecord() throws Exception
{
// create document in a folder in a collaboration site
@@ -156,8 +162,8 @@ public class DeclareDocumentAsRecordTests extends BaseRMRestTest
try
(
InputStream recordInputStream = getRestAPIFactory().getRecordsAPI().getRecordContent(record.getId()).asInputStream();
- InputStream documentInputStream = documentPostFiling.getContentStream().getStream();
- )
+ InputStream documentInputStream = documentPostFiling.getContentStream().getStream()
+ )
{
assertEquals(DigestUtils.sha1(recordInputStream), DigestUtils.sha1(documentInputStream));
}
diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/recordcategories/RecordCategoryTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/recordcategories/RecordCategoryTests.java
index 9cd8b476b6..8580839556 100644
--- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/recordcategories/RecordCategoryTests.java
+++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/recordcategories/RecordCategoryTests.java
@@ -775,7 +775,6 @@ public class RecordCategoryTests extends BaseRMRestTest
{
//is unfiled container
containerId = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(containerAlias).getId();
- ;
}
// Create a record folder
diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/CompleteRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/CompleteRecordTests.java
index d5ca79d7e3..cdd9fe2644 100644
--- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/CompleteRecordTests.java
+++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/CompleteRecordTests.java
@@ -42,8 +42,6 @@ import java.util.List;
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
import org.alfresco.rest.rm.community.model.record.Record;
-import org.alfresco.rest.rm.community.model.site.RMSite;
-import org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI;
import org.alfresco.test.AlfrescoTest;
diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/DeleteRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/DeleteRecordTests.java
index ef63360a39..bc88c6a6d6 100644
--- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/DeleteRecordTests.java
+++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/DeleteRecordTests.java
@@ -49,7 +49,6 @@ import static org.springframework.http.HttpStatus.NO_CONTENT;
import static org.springframework.http.HttpStatus.OK;
import org.alfresco.dataprep.CMISUtil;
-import org.alfresco.rest.core.JsonBodyGenerator;
import org.alfresco.rest.core.RestResponse;
import org.alfresco.rest.core.v0.BaseAPI.RM_ACTIONS;
import org.alfresco.rest.model.RestNodeBodyMoveCopyModel;
@@ -66,6 +65,7 @@ import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI;
import org.alfresco.rest.v0.RMRolesAndActionsAPI;
import org.alfresco.rest.v0.service.DispositionScheduleService;
+import org.alfresco.rest.v0.service.RoleService;
import org.alfresco.test.AlfrescoTest;
import org.alfresco.utility.data.RandomData;
import org.alfresco.utility.model.FileModel;
@@ -90,6 +90,8 @@ public class DeleteRecordTests extends BaseRMRestTest
private RMRolesAndActionsAPI rmRolesAndActionsAPI;
@Autowired
private org.alfresco.rest.v0.RecordsAPI recordsAPI;
+ @Autowired
+ private RoleService roleService;
/**
*
@@ -236,15 +238,12 @@ public class DeleteRecordTests extends BaseRMRestTest
public void userWithoutDeleteRecordsCapabilityCantDeleteRecord() throws Exception
{
// Create test user and add it with collaboration privileges
- UserModel deleteUser = getDataUser().createRandomTestUser("delnoperm");
+ // Add RM role to user, RM Power User doesn't have the "Delete Record" capabilities
+ UserModel deleteUser = roleService.createUserWithRMRole(ROLE_RM_POWER_USER.roleId);
getDataUser().addUserToSite(deleteUser, new SiteModel(getRestAPIFactory().getRMSiteAPI().getSite().getId()), SiteCollaborator);
String username = deleteUser.getUsername();
logger.info("Test user: " + username);
- // Add RM role to user, RM Power User doesn't have the "Delete Record" capabilities
- getRestAPIFactory().getRMUserAPI().assignRoleToUser(username, ROLE_RM_POWER_USER.roleId);
- assertStatusCode(OK);
-
// Create random folder
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
logger.info("Random folder:" + recordFolder.getName());
diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/FileRecordsTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/FileRecordsTests.java
index 2a90dcb5bd..98a7963406 100644
--- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/FileRecordsTests.java
+++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/FileRecordsTests.java
@@ -68,7 +68,7 @@ public class FileRecordsTests extends BaseRMRestTest
{
private UnfiledContainerChild electronicRecord = UnfiledContainerChild.builder()
.name(ELECTRONIC_RECORD_NAME)
- .nodeType(CONTENT_TYPE.toString())
+ .nodeType(CONTENT_TYPE)
.content(RecordContent.builder().mimeType("text/plain").build())
.build();
@@ -78,14 +78,14 @@ public class FileRecordsTests extends BaseRMRestTest
.title("Title")
.build())
.name(NONELECTRONIC_RECORD_NAME)
- .nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
+ .nodeType(NON_ELECTRONIC_RECORD_TYPE)
.build();
/**
* Invalid containers where electronic and non-electronic records can be filed
*/
@DataProvider (name = "invalidContainersToFile")
- public String[][] getFolderContainers() throws Exception
+ public Object[][] getFolderContainers() throws Exception
{
return new String[][] {
{ FILE_PLAN_ALIAS},
diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/ReadRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/ReadRecordTests.java
index 06b513ccac..e2c48d8695 100644
--- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/ReadRecordTests.java
+++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/ReadRecordTests.java
@@ -269,7 +269,7 @@ public class ReadRecordTests extends BaseRMRestTest
try
(
InputStream recordContentStream = recordsAPI.getRecordContent(binaryRecordId).asInputStream();
- FileInputStream localFileStream = new FileInputStream(getFile(IMAGE_FILE));
+ FileInputStream localFileStream = new FileInputStream(getFile(IMAGE_FILE))
)
{
assertEquals(DigestUtils.sha1(recordContentStream), DigestUtils.sha1(localFileStream));
diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/UpdateRecordsTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/UpdateRecordsTests.java
index 2f8f3af510..35c2eee056 100644
--- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/UpdateRecordsTests.java
+++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/UpdateRecordsTests.java
@@ -66,10 +66,12 @@ import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI;
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledRecordFolderAPI;
+import org.alfresco.rest.v0.service.RoleService;
import org.alfresco.test.AlfrescoTest;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel;
+import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.AfterClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -87,6 +89,9 @@ public class UpdateRecordsTests extends BaseRMRestTest
/* to be used to append to modifications */
private final String MODIFIED_PREFIX = "modified_";
+ @Autowired
+ private RoleService roleService;
+
/** Incomplete electronic and non electronic records created in one record folder, unfiled records container and one unfiled record folder */
@DataProvider(name = "incompleteRecords")
public Object[][] getIncompleteRecords() throws Exception
@@ -234,15 +239,12 @@ public class UpdateRecordsTests extends BaseRMRestTest
public void userWithEditMetadataCapsCanUpdateMetadata() throws Exception
{
RMUserAPI rmUserAPI = getRestAPIFactory().getRMUserAPI();
- // Create test user and add it with collab. privileges
- UserModel updateUser = getDataUser().createRandomTestUser("updateuser");
+ // Create test user and add it with collab. privileges.
+ // RM Security Officer is the lowest role with Edit Record Metadata capabilities
+ UserModel updateUser = roleService.createUserWithRMRole(ROLE_RM_SECURITY_OFFICER.roleId);
updateUser.setUserRole(UserRole.SiteCollaborator);
getDataUser().addUserToSite(updateUser, new SiteModel(getRestAPIFactory().getRMSiteAPI().getSite().getId()), UserRole.SiteCollaborator);
- // RM Security Officer is the lowest role with Edit Record Metadata capabilities
- rmUserAPI.assignRoleToUser(updateUser.getUsername(), ROLE_RM_SECURITY_OFFICER.roleId);
- assertStatusCode(OK);
-
// Create random folder
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
logger.info("random folder:" + recordFolder.getName());
diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/RMSiteUtil.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/RMSiteUtil.java
index b3574a0fcb..80062165ca 100644
--- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/RMSiteUtil.java
+++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/RMSiteUtil.java
@@ -66,7 +66,7 @@ public class RMSiteUtil
/**
* Creates an RM Site for the given compliance and default title and description
*
- * @param The RM site compliance
+ * @param compliance The RM site compliance
* @return The {@link RMSite} with the given details
*/
private static RMSite createRMSiteModel(RMSiteCompliance compliance)