add tests for File Action

This commit is contained in:
Rodica Sutu
2017-01-04 16:47:28 +02:00
parent 9c8f230793
commit 889c831bda
5 changed files with 356 additions and 5 deletions

View File

@@ -110,16 +110,23 @@ public interface TestData
public static String CATEGORY_TITLE = "CATEGORY TITLE" + getRandomAlphanumeric();
/**
* The default FOLDER name used when creating categories
* The default FOLDER name used when creating folders
*/
public static String FOLDER_NAME = "FOLDER NAME" + getRandomAlphanumeric();
/**
* The default FOLDER title used when creating categories
* The default FOLDER title used when creating folders
*/
public static String FOLDER_TITLE = "FOLDER TITLE" + getRandomAlphanumeric();
/**
* The default electronic record name used when creating electronic records
*/
public static String ELECTRONIC_RECORD_NAME = "Record electronic" + getRandomAlphanumeric();
/**
* The default Non electronic record name used when creating non-electronic records
*/
public static String NONELECTRONIC_RECORD_NAME = "Record nonelectronic" + getRandomAlphanumeric();
/**
* Data Provider with:
* with the object types not allowed as children for a record category

View File

@@ -0,0 +1,223 @@
package org.alfresco.rest.rm.community.fileplancomponents;
import static org.alfresco.rest.rm.community.base.TestData.ELECTRONIC_RECORD_NAME;
import static org.alfresco.rest.rm.community.base.TestData.NONELECTRONIC_RECORD_NAME;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.FORBIDDEN;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.AssertJUnit.assertTrue;
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentContent;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
import org.alfresco.rest.rm.community.model.fileplancomponents.RecordBodyFile;
import org.testng.annotations.Test;
/**
* This class contains the tests for
* File Unfiled Record Action REST API
*
* @author Rodica Sutu
* @since 2.6
*/
public class FileRecordsTests extends BaseRMRestTest
{
private FilePlanComponent electronicRecord = FilePlanComponent.builder()
.name(ELECTRONIC_RECORD_NAME)
.nodeType(CONTENT_TYPE.toString())
.content(FilePlanComponentContent.builder().mimeType("text/plain").build())
.build();
private FilePlanComponent nonelectronicRecord = FilePlanComponent.builder()
.properties(FilePlanComponentProperties.builder()
.description(NONELECTRONIC_RECORD_NAME)
.title("Title")
.build())
.name(NONELECTRONIC_RECORD_NAME)
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
.build();
/**
* Given an unfiled record in the root unfiled record container or a unfiled record folder
* And an open record folder
* When I file the unfiled record into the record folder
* Then the record is filed
*/
@Test
public void fileRecordIntoExistingFolder() 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);
//file the record into the folder created
RecordBodyFile recordBodyFile = RecordBodyFile.builder().targetParentId(folderId).build();
FilePlanComponent recordFiled =getRestAPIFactory().getRecordsAPI().fileRecord(recordBodyFile, recordElectronic.getId());
//check the response status
assertStatusCode(CREATED);
//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(UNFILED_RECORDS_CONTAINER_ALIAS)
.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(UNFILED_RECORDS_CONTAINER_ALIAS)
.getEntries().stream()
.anyMatch(c -> c.getFilePlanComponentModel().getId()
.equals(recordNonElectId.getId())
)
);
}
/**
* Given an unfiled record in the root unfiled record container or a unfiled record folder
* And a closed record folder
* When I file the unfiled record into the record folder
* Then I get an unsupported operation exception
*
*/
@Test
public void fileRecordIntoCloseFolder() 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);
//file the record into the folder created
RecordBodyFile recordBodyFile = RecordBodyFile.builder().targetParentId(folderId).build();
getRestAPIFactory().getRecordsAPI().fileRecord(recordBodyFile, recordElectronic.getId());
//check the response status
assertStatusCode(FORBIDDEN);
//check the record is filed into the record folder
assertFalse(getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(folderId)
.getEntries().stream()
.anyMatch(c -> c.getFilePlanComponentModel().getId()
.equals(recordElectronic.getId())
)
);
//check the record doesn't exist into unfiled record container
assertTrue(getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(UNFILED_RECORDS_CONTAINER_ALIAS)
.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(FORBIDDEN);
//check the record is added into the record folder
assertFalse(getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(folderId)
.getEntries().stream()
.anyMatch(c -> c.getFilePlanComponentModel().getId()
.equals(recordNonElectId.getId())
)
);
//check the record doesn't exist into unfiled record container
assertTrue(getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(UNFILED_RECORDS_CONTAINER_ALIAS)
.getEntries().stream()
.anyMatch(c -> c.getFilePlanComponentModel().getId()
.equals(recordNonElectId.getId())
)
);
}
/**
* Given a filed record in a record folder
* And an open record folder
* When I file the filed record into the record folder
* Then the record is filed in both locations
*/
@Test
public void linkRecordInto() throws Exception
{
//create a record folder
String parentFolderId = createCategoryFolderInFilePlan().getId();
//create records
FilePlanComponent recordElectronic = getRestAPIFactory().getFilePlanComponentsAPI().createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), UNFILED_RECORDS_CONTAINER_ALIAS);
FilePlanComponent recordNonElect = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(nonelectronicRecord, UNFILED_RECORDS_CONTAINER_ALIAS);
//file the record into the folder created
RecordBodyFile recordBodyFile = RecordBodyFile.builder().targetParentId(parentFolderId).build();
FilePlanComponent recordFiled = getRestAPIFactory().getRecordsAPI().fileRecord(recordBodyFile, recordElectronic.getId());
FilePlanComponent nonElectronicFiled = getRestAPIFactory().getRecordsAPI().fileRecord(recordBodyFile, recordNonElect.getId());
//check the response status
assertStatusCode(CREATED);
//create the second folder
String folderToLink = createCategoryFolderInFilePlan().getId();
recordBodyFile = RecordBodyFile.builder().targetParentId(folderToLink).build();
//check the response status
assertStatusCode(CREATED);
//link the electronic record
FilePlanComponent recordLink = getRestAPIFactory().getRecordsAPI().fileRecord(recordBodyFile, recordElectronic.getId());
assertTrue(recordLink.getParentId().equals(parentFolderId));
//check the response status code
assertStatusCode(CREATED);
//link the nonelectronic record
FilePlanComponent nonElectronicLink = getRestAPIFactory().getRecordsAPI().fileRecord(recordBodyFile, recordNonElect.getId());
assertStatusCode(CREATED);
assertTrue(recordLink.getParentId().equals(parentFolderId));
//check the record is added into the record folder
assertTrue(getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(parentFolderId)
.getEntries().stream()
.anyMatch(c -> c.getFilePlanComponentModel().getId()
.equals(recordFiled.getId())&& c.getFilePlanComponentModel().getParentId().equals(parentFolderId)
)
);
//check the record doesn't exist into unfiled record container
assertTrue(getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(folderToLink)
.getEntries().stream()
.anyMatch(c -> c.getFilePlanComponentModel().getId()
.equals(recordFiled.getId()) && c.getFilePlanComponentModel().getParentId().equals(parentFolderId)
)
);
}
/**
* Given an unfiled or filed record
* And a container that is NOT a record folder
* When I file the unfiled or filed record to the container
* Then I get an unsupported operation exception
*/
}

View File

@@ -357,7 +357,8 @@ public class ReadRecordTests extends BaseRMRestTest
assertTrue(filePlanComponent.getName().startsWith(createdComponent.getName()));
assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType());
} catch (NoSuchElementException e)
}
catch (NoSuchElementException e)
{
fail("No child element for " + filePlanComponent.getId());
}