From 443c980ee2bc23b52b40d1ac200a00371dab8709 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Wed, 4 Jan 2017 20:31:23 +0200 Subject: [PATCH] - updates and add tests --- .../requests/igCoreAPI/RecordsAPI.java | 41 +++---- .../fileplancomponents/FileRecordsTests.java | 109 ++++++++++++++++-- 2 files changed, 119 insertions(+), 31 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/RecordsAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/RecordsAPI.java index be6d8f8321..292ed2da97 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/RecordsAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/RecordsAPI.java @@ -119,14 +119,15 @@ public class RecordsAPI extends RMModelRequest * @param recordId The id of the record to file * @return The {@link FilePlanComponent} with the given properties * @throws Exception for the following cases: - * + * + * */ public FilePlanComponent fileRecord(RecordBodyFile recordBodyFile, String recordId) throws Exception { @@ -137,21 +138,21 @@ public class RecordsAPI extends RMModelRequest } /** - * Creates a file plan component with the given properties under the parent node with the given id + * File the record recordId into file plan structure based on the location sent via the request body * - * @param filePlanComponentModel The properties of the file plan component to be created - * @param parameters The URL parameters to add - * @param parentId The id of the parent where the new file plan component should be created + * @param recordBodyFile The properties where to file the record + * @param recordId The id of the record to file * @return The {@link FilePlanComponent} with the given properties * @throws Exception for the following cases: - * + * + * */ public FilePlanComponent fileRecord(RecordBodyFile recordBodyFile, String recordId, String parameters) throws Exception { diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/FileRecordsTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/FileRecordsTests.java index d0f47c029c..5bc9b4e68e 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/FileRecordsTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/FileRecordsTests.java @@ -55,15 +55,32 @@ public class FileRecordsTests extends BaseRMRestTest * When I file the unfiled record into the record folder * Then the record is filed */ + /** + * Unfiled containers from where record can be filed + */ + @DataProvider (name = "unfiledContainer") + public Object[][] getUnfiledContainer() throws Exception + { + return new Object[][] { + //unfiled container + { getFilePlanComponent(UNFILED_RECORDS_CONTAINER_ALIAS).getId() }, + // an arbitrary unfiled records folder + { createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), "Unfiled Folder " + getRandomAlphanumeric()).getId() } + }; + } @Test - public void fileRecordIntoExistingFolder() throws Exception + ( + dataProvider = "unfiledContainer", + description = "File record from unfiled containers " + ) + public void fileRecordIntoExistingFolder(String unfiledContainerId) throws Exception { //create a record folder String folderId = createCategoryFolderInFilePlan().getId(); //create records - FilePlanComponent recordElectronic = getRestAPIFactory().getFilePlanComponentsAPI().createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), UNFILED_RECORDS_CONTAINER_ALIAS); - FilePlanComponent recordNonElectId = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(nonelectronicRecord, UNFILED_RECORDS_CONTAINER_ALIAS); + FilePlanComponent recordElectronic = getRestAPIFactory().getFilePlanComponentsAPI().createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), unfiledContainerId); + FilePlanComponent recordNonElectId = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(nonelectronicRecord, unfiledContainerId); //file the record into the folder created RecordBodyFile recordBodyFile = RecordBodyFile.builder().targetParentId(folderId).build(); @@ -80,7 +97,7 @@ public class FileRecordsTests extends BaseRMRestTest ) ); //check the record doesn't exist into unfiled record container - assertFalse(getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(UNFILED_RECORDS_CONTAINER_ALIAS) + assertFalse(getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(unfiledContainerId) .getEntries().stream() .anyMatch(c -> c.getFilePlanComponentModel().getId() .equals(recordElectronic.getId()) @@ -100,7 +117,7 @@ public class FileRecordsTests extends BaseRMRestTest ) ); //check the record doesn't exist into unfiled record container - assertFalse(getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(UNFILED_RECORDS_CONTAINER_ALIAS) + assertFalse(getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(unfiledContainerId) .getEntries().stream() .anyMatch(c -> c.getFilePlanComponentModel().getId() .equals(recordNonElectId.getId()) @@ -116,14 +133,18 @@ public class FileRecordsTests extends BaseRMRestTest * */ @Test - public void fileRecordIntoCloseFolder() throws Exception + ( + dataProvider = "unfiledContainer", + description = "File record from unfiled containers into a closed folder " + ) + public void fileRecordIntoCloseFolder(String unfiledContainerId) throws Exception { //create a record folder String folderId = createCategoryFolderInFilePlan().getId(); closeFolder(folderId); //create records - FilePlanComponent recordElectronic = getRestAPIFactory().getFilePlanComponentsAPI().createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), UNFILED_RECORDS_CONTAINER_ALIAS); - FilePlanComponent recordNonElectId = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(nonelectronicRecord, UNFILED_RECORDS_CONTAINER_ALIAS); + FilePlanComponent recordElectronic = getRestAPIFactory().getFilePlanComponentsAPI().createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), unfiledContainerId); + FilePlanComponent recordNonElectId = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(nonelectronicRecord, unfiledContainerId); //file the record into the folder created RecordBodyFile recordBodyFile = RecordBodyFile.builder().targetParentId(folderId).build(); @@ -139,7 +160,7 @@ public class FileRecordsTests extends BaseRMRestTest ) ); //check the record doesn't exist into unfiled record container - assertTrue(getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(UNFILED_RECORDS_CONTAINER_ALIAS) + assertTrue(getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(unfiledContainerId) .getEntries().stream() .anyMatch(c -> c.getFilePlanComponentModel().getId() .equals(recordElectronic.getId()) @@ -157,7 +178,7 @@ public class FileRecordsTests extends BaseRMRestTest ) ); //check the record doesn't exist into unfiled record container - assertTrue(getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(UNFILED_RECORDS_CONTAINER_ALIAS) + assertTrue(getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(unfiledContainerId) .getEntries().stream() .anyMatch(c -> c.getFilePlanComponentModel().getId() .equals(recordNonElectId.getId()) @@ -245,7 +266,7 @@ public class FileRecordsTests extends BaseRMRestTest * Then I get an unsupported operation exception */ /** - * Valid root containers where electronic and non-electronic records can be created + * Invalid containers where electronic and non-electronic records can be filed */ @DataProvider (name = "invalidContainersForFile") public Object[][] getFolderContainers() throws Exception @@ -283,4 +304,70 @@ public class FileRecordsTests extends BaseRMRestTest assertStatusCode(BAD_REQUEST); } + /** + * Given an unfiled record in the root unfiled record container or a unfiled record folder + * When I file the unfiled record into the record folder using the relativePath + * Then the filePlan structure from relativePath is created and the record is filed into the specified path + */ + @Test + ( + dataProvider = "unfiledContainer", + description = "File record from unfiled containers " + ) + public void fileRecordIntoRelativePath(String unfiledContainerId) throws Exception + { + //create a record folder + String RELATIVE_PATH = "CATEGORY" + getRandomAlphanumeric() + "/FOLDER"; + + //create records + FilePlanComponent recordElectronic = getRestAPIFactory().getFilePlanComponentsAPI().createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), unfiledContainerId); + FilePlanComponent recordNonElectId = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(nonelectronicRecord, unfiledContainerId); + + //file the record into the folder created + RecordBodyFile recordBodyFile = RecordBodyFile.builder().relativePath(RELATIVE_PATH).build(); + FilePlanComponent recordFiled = getRestAPIFactory().getRecordsAPI().fileRecord(recordBodyFile, recordElectronic.getId()); + + //check the response status + assertStatusCode(CREATED); + + //Get the folder ID created + String folderId= getRestAPIFactory().getFilePlanComponentsAPI().getFilePlanComponent(FILE_PLAN_ALIAS, "relativePath="+RELATIVE_PATH).getId(); + //check the parent id for the record returned + assertEquals(recordFiled.getParentId(), folderId); + //check the record is filed into the record folder + assertTrue(getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(folderId) + .getEntries().stream() + .anyMatch(c -> c.getFilePlanComponentModel().getId() + .equals(recordElectronic.getId()) + ) + ); + //check the record doesn't exist into unfiled record container + assertFalse(getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(unfiledContainerId) + .getEntries().stream() + .anyMatch(c -> c.getFilePlanComponentModel().getId() + .equals(recordElectronic.getId()) + ) + ); + //file the non-electronic record into the folder created + FilePlanComponent nonElectRecordFiled = getRestAPIFactory().getRecordsAPI().fileRecord(recordBodyFile, recordNonElectId.getId()); + //check the response status code + assertStatusCode(CREATED); + //check the parent id for the record returned + assertEquals(nonElectRecordFiled.getParentId(), folderId); + //check the record is added into the record folder + assertTrue(getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(folderId) + .getEntries().stream() + .anyMatch(c -> c.getFilePlanComponentModel().getId() + .equals(recordNonElectId.getId()) + ) + ); + //check the record doesn't exist into unfiled record container + assertFalse(getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(unfiledContainerId) + .getEntries().stream() + .anyMatch(c -> c.getFilePlanComponentModel().getId() + .equals(recordNonElectId.getId()) + ) + ); + } + }