mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-4361: fixes further to code inspection.
This commit is contained in:
@@ -48,6 +48,7 @@ import static org.testng.AssertJUnit.assertTrue;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
@@ -60,6 +61,7 @@ import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent
|
|||||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
|
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
|
||||||
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection;
|
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection;
|
||||||
import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
|
import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
|
||||||
|
import org.alfresco.rest.rm.community.requests.igCoreAPI.RecordsAPI;
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
import org.testng.annotations.DataProvider;
|
import org.testng.annotations.DataProvider;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
@@ -119,7 +121,7 @@ public class ReadRecordTests extends BaseRMRestTest
|
|||||||
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||||
FilePlanComponent electronicRecord = FilePlanComponent.builder()
|
FilePlanComponent electronicRecord = FilePlanComponent.builder()
|
||||||
.name(ELECTRONIC_RECORD_NAME)
|
.name(ELECTRONIC_RECORD_NAME)
|
||||||
.nodeType(CONTENT_TYPE.toString())
|
.nodeType(CONTENT_TYPE)
|
||||||
.content(FilePlanComponentContent.builder().mimeType("text/plain").build())
|
.content(FilePlanComponentContent.builder().mimeType("text/plain").build())
|
||||||
.build();
|
.build();
|
||||||
FilePlanComponent nonelectronicRecord = FilePlanComponent.builder()
|
FilePlanComponent nonelectronicRecord = FilePlanComponent.builder()
|
||||||
@@ -128,7 +130,7 @@ public class ReadRecordTests extends BaseRMRestTest
|
|||||||
.title("Title")
|
.title("Title")
|
||||||
.build())
|
.build())
|
||||||
.name(NONELECTRONIC_RECORD_NAME)
|
.name(NONELECTRONIC_RECORD_NAME)
|
||||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
|
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||||
.build();
|
.build();
|
||||||
//create records
|
//create records
|
||||||
filePlanComponentAPI.createFilePlanComponent(electronicRecord, container);
|
filePlanComponentAPI.createFilePlanComponent(electronicRecord, container);
|
||||||
@@ -157,10 +159,10 @@ public class ReadRecordTests extends BaseRMRestTest
|
|||||||
//create the containers from the relativePath
|
//create the containers from the relativePath
|
||||||
FilePlanComponent recordFolder = FilePlanComponent.builder()
|
FilePlanComponent recordFolder = FilePlanComponent.builder()
|
||||||
.name(FOLDER_NAME)
|
.name(FOLDER_NAME)
|
||||||
.nodeType(RECORD_FOLDER_TYPE.toString())
|
.nodeType(RECORD_FOLDER_TYPE)
|
||||||
.relativePath(RELATIVE_PATH)
|
.relativePath(RELATIVE_PATH)
|
||||||
.build();
|
.build();
|
||||||
String folderId = filePlanComponentAPI.createFilePlanComponent(recordFolder, FILE_PLAN_ALIAS.toString()).getId();
|
String folderId = filePlanComponentAPI.createFilePlanComponent(recordFolder, FILE_PLAN_ALIAS).getId();
|
||||||
//create electronic record
|
//create electronic record
|
||||||
|
|
||||||
String recordWithContentId = filePlanComponentAPI.createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), folderId).getId();
|
String recordWithContentId = filePlanComponentAPI.createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), folderId).getId();
|
||||||
@@ -172,7 +174,7 @@ public class ReadRecordTests extends BaseRMRestTest
|
|||||||
assertFalse(recordWithContent.getIsCategory());
|
assertFalse(recordWithContent.getIsCategory());
|
||||||
assertFalse(recordWithContent.getIsRecordFolder());
|
assertFalse(recordWithContent.getIsRecordFolder());
|
||||||
assertNotNull(recordWithContent.getContent().getEncoding());
|
assertNotNull(recordWithContent.getContent().getEncoding());
|
||||||
assertEquals(recordWithContent.getNodeType(),CONTENT_TYPE.toString());
|
assertEquals(recordWithContent.getNodeType(),CONTENT_TYPE);
|
||||||
assertNotNull(recordWithContent.getContent().getEncoding());
|
assertNotNull(recordWithContent.getContent().getEncoding());
|
||||||
assertNotNull(recordWithContent.getContent().getMimeType());
|
assertNotNull(recordWithContent.getContent().getMimeType());
|
||||||
assertNotNull(recordWithContent.getAspectNames());
|
assertNotNull(recordWithContent.getAspectNames());
|
||||||
@@ -189,7 +191,7 @@ public class ReadRecordTests extends BaseRMRestTest
|
|||||||
assertFalse(nonElectronicRecord.getIsCategory());
|
assertFalse(nonElectronicRecord.getIsCategory());
|
||||||
assertFalse(nonElectronicRecord.getIsRecordFolder());
|
assertFalse(nonElectronicRecord.getIsRecordFolder());
|
||||||
assertNotNull(nonElectronicRecord.getContent().getEncoding());
|
assertNotNull(nonElectronicRecord.getContent().getEncoding());
|
||||||
assertEquals(nonElectronicRecord.getNodeType(), NON_ELECTRONIC_RECORD_TYPE.toString());
|
assertEquals(nonElectronicRecord.getNodeType(), NON_ELECTRONIC_RECORD_TYPE);
|
||||||
assertNotNull(nonElectronicRecord.getContent().getEncoding());
|
assertNotNull(nonElectronicRecord.getContent().getEncoding());
|
||||||
assertNotNull(nonElectronicRecord.getContent().getMimeType());
|
assertNotNull(nonElectronicRecord.getContent().getMimeType());
|
||||||
assertNotNull(nonElectronicRecord.getAspectNames());
|
assertNotNull(nonElectronicRecord.getAspectNames());
|
||||||
@@ -205,49 +207,56 @@ public class ReadRecordTests extends BaseRMRestTest
|
|||||||
@Test
|
@Test
|
||||||
public void readRecordContent() throws Exception
|
public void readRecordContent() throws Exception
|
||||||
{
|
{
|
||||||
|
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||||
|
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
|
||||||
|
|
||||||
String RECORD_ELECTRONIC = "Record " + getRandomAlphanumeric();
|
String RECORD_ELECTRONIC = "Record " + getRandomAlphanumeric();
|
||||||
String RECORD_ELECTRONIC_BINARY = "Binary Record" + getRandomAlphanumeric();
|
String RECORD_ELECTRONIC_BINARY = "Binary Record" + getRandomAlphanumeric();
|
||||||
String RELATIVE_PATH = "/" + CATEGORY_NAME + getRandomAlphanumeric() + "/folder";
|
String RELATIVE_PATH = "/" + CATEGORY_NAME + getRandomAlphanumeric() + "/folder";
|
||||||
|
|
||||||
// create the containers from the relativePath
|
// create the containers from the relativePath
|
||||||
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
|
||||||
FilePlanComponent recordFolder = FilePlanComponent.builder()
|
FilePlanComponent recordFolder = FilePlanComponent.builder()
|
||||||
.name(FOLDER_NAME)
|
.name(FOLDER_NAME)
|
||||||
.nodeType(RECORD_FOLDER_TYPE.toString())
|
.nodeType(RECORD_FOLDER_TYPE)
|
||||||
.relativePath(RELATIVE_PATH)
|
.relativePath(RELATIVE_PATH)
|
||||||
.build();
|
.build();
|
||||||
String folderId = filePlanComponentAPI.createFilePlanComponent(recordFolder, FILE_PLAN_ALIAS.toString()).getId();
|
String folderId = filePlanComponentAPI.createFilePlanComponent(recordFolder, FILE_PLAN_ALIAS).getId();
|
||||||
|
|
||||||
// text file as an electronic record
|
// text file as an electronic record
|
||||||
FilePlanComponent recordText = FilePlanComponent.builder()
|
FilePlanComponent recordText = FilePlanComponent.builder()
|
||||||
.name(RECORD_ELECTRONIC)
|
.name(RECORD_ELECTRONIC)
|
||||||
.nodeType(CONTENT_TYPE.toString())
|
.nodeType(CONTENT_TYPE)
|
||||||
.build();
|
.build();
|
||||||
String recordId = filePlanComponentAPI.createElectronicRecord(recordText, createTempFile(RECORD_ELECTRONIC, RECORD_ELECTRONIC), folderId).getId();
|
String recordId = filePlanComponentAPI.createElectronicRecord(recordText, createTempFile(RECORD_ELECTRONIC, RECORD_ELECTRONIC), folderId).getId();
|
||||||
assertEquals(getRestAPIFactory().getRecordsAPI().getRecordContent(recordId).asString(), RECORD_ELECTRONIC);
|
assertEquals(recordsAPI.getRecordContent(recordId).asString(), RECORD_ELECTRONIC);
|
||||||
// Check status code
|
// Check status code
|
||||||
assertStatusCode(OK);
|
assertStatusCode(OK);
|
||||||
|
|
||||||
// binary file as an electronic record
|
// binary file as an electronic record
|
||||||
FilePlanComponent recordBinary = FilePlanComponent.builder()
|
FilePlanComponent recordBinary = FilePlanComponent.builder()
|
||||||
.name(RECORD_ELECTRONIC_BINARY)
|
.name(RECORD_ELECTRONIC_BINARY)
|
||||||
.nodeType(CONTENT_TYPE.toString())
|
.nodeType(CONTENT_TYPE)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
String binaryRecordId = filePlanComponentAPI.createElectronicRecord(recordBinary, IMAGE_FILE, folderId).getId();
|
String binaryRecordId = filePlanComponentAPI.createElectronicRecord(recordBinary, IMAGE_FILE, folderId).getId();
|
||||||
// binary content, therefore compare respective SHA1 checksums in order to verify this is identical content
|
// binary content, therefore compare respective SHA1 checksums in order to verify this is identical content
|
||||||
assertEquals(
|
try
|
||||||
DigestUtils.sha1(getRestAPIFactory().getRecordsAPI().getRecordContent(binaryRecordId).asInputStream()),
|
(
|
||||||
DigestUtils.sha1(new FileInputStream(new File(Resources.getResource(IMAGE_FILE).getFile()))));
|
InputStream recordContentStream = recordsAPI.getRecordContent(binaryRecordId).asInputStream();
|
||||||
|
FileInputStream localFileStream = new FileInputStream(new File(Resources.getResource(IMAGE_FILE).getFile()));
|
||||||
|
)
|
||||||
|
{
|
||||||
|
assertEquals(DigestUtils.sha1(recordContentStream), DigestUtils.sha1(localFileStream));
|
||||||
|
}
|
||||||
assertStatusCode(OK);
|
assertStatusCode(OK);
|
||||||
|
|
||||||
// electronic record with no content
|
// electronic record with no content
|
||||||
FilePlanComponent recordNoContent = FilePlanComponent.builder()
|
FilePlanComponent recordNoContent = FilePlanComponent.builder()
|
||||||
.name(RECORD_ELECTRONIC)
|
.name(RECORD_ELECTRONIC)
|
||||||
.nodeType(CONTENT_TYPE.toString())
|
.nodeType(CONTENT_TYPE)
|
||||||
.build();
|
.build();
|
||||||
String recordNoContentId = filePlanComponentAPI.createFilePlanComponent(recordNoContent,folderId).getId();
|
String recordNoContentId = filePlanComponentAPI.createFilePlanComponent(recordNoContent,folderId).getId();
|
||||||
assertTrue(getRestAPIFactory().getRecordsAPI().getRecordContent(recordNoContentId).asString().isEmpty());
|
assertTrue(recordsAPI.getRecordContent(recordNoContentId).asString().isEmpty());
|
||||||
assertStatusCode(OK);
|
assertStatusCode(OK);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -263,11 +272,11 @@ public class ReadRecordTests extends BaseRMRestTest
|
|||||||
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||||
FilePlanComponent record = FilePlanComponent.builder()
|
FilePlanComponent record = FilePlanComponent.builder()
|
||||||
.name(NONELECTRONIC_RECORD_NAME)
|
.name(NONELECTRONIC_RECORD_NAME)
|
||||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
|
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||||
.relativePath("/"+CATEGORY_NAME+getRandomAlphanumeric()+"/"+FOLDER_NAME)
|
.relativePath("/" + CATEGORY_NAME + getRandomAlphanumeric() + "/" + FOLDER_NAME)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
String nonElectronicRecord = filePlanComponentAPI.createFilePlanComponent(record,FILE_PLAN_ALIAS.toString()).getId();
|
String nonElectronicRecord = filePlanComponentAPI.createFilePlanComponent(record, FILE_PLAN_ALIAS).getId();
|
||||||
|
|
||||||
|
|
||||||
assertTrue(getRestAPIFactory().getRecordsAPI().getRecordContent(nonElectronicRecord).asString().isEmpty());
|
assertTrue(getRestAPIFactory().getRecordsAPI().getRecordContent(nonElectronicRecord).asString().isEmpty());
|
||||||
@@ -325,7 +334,7 @@ public class ReadRecordTests extends BaseRMRestTest
|
|||||||
//build the electronic record
|
//build the electronic record
|
||||||
FilePlanComponent record = FilePlanComponent.builder()
|
FilePlanComponent record = FilePlanComponent.builder()
|
||||||
.name(ELECTRONIC_RECORD_NAME +i)
|
.name(ELECTRONIC_RECORD_NAME +i)
|
||||||
.nodeType(CONTENT_TYPE.toString())
|
.nodeType(CONTENT_TYPE)
|
||||||
.build();
|
.build();
|
||||||
//create a child
|
//create a child
|
||||||
FilePlanComponent child = filePlanComponentAPI.createElectronicRecord(record, createTempFile(ELECTRONIC_RECORD_NAME + i, ELECTRONIC_RECORD_NAME + i ), containerId);
|
FilePlanComponent child = filePlanComponentAPI.createElectronicRecord(record, createTempFile(ELECTRONIC_RECORD_NAME + i, ELECTRONIC_RECORD_NAME + i ), containerId);
|
||||||
@@ -340,7 +349,7 @@ public class ReadRecordTests extends BaseRMRestTest
|
|||||||
.title("Title")
|
.title("Title")
|
||||||
.build())
|
.build())
|
||||||
.name(NONELECTRONIC_RECORD_NAME+i)
|
.name(NONELECTRONIC_RECORD_NAME+i)
|
||||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
|
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||||
.build();
|
.build();
|
||||||
//create records
|
//create records
|
||||||
FilePlanComponent child = filePlanComponentAPI.createFilePlanComponent(nonelectronicRecord, containerId);
|
FilePlanComponent child = filePlanComponentAPI.createFilePlanComponent(nonelectronicRecord, containerId);
|
||||||
@@ -406,7 +415,7 @@ public class ReadRecordTests extends BaseRMRestTest
|
|||||||
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
|
||||||
FilePlanComponent electRecord = FilePlanComponent.builder()
|
FilePlanComponent electRecord = FilePlanComponent.builder()
|
||||||
.name(ELECTRONIC_RECORD_NAME)
|
.name(ELECTRONIC_RECORD_NAME)
|
||||||
.nodeType(CONTENT_TYPE.toString())
|
.nodeType(CONTENT_TYPE)
|
||||||
.content(FilePlanComponentContent.builder().mimeType("text/plain").build())
|
.content(FilePlanComponentContent.builder().mimeType("text/plain").build())
|
||||||
.build();
|
.build();
|
||||||
FilePlanComponent nonElectronic = FilePlanComponent.builder()
|
FilePlanComponent nonElectronic = FilePlanComponent.builder()
|
||||||
@@ -415,12 +424,12 @@ public class ReadRecordTests extends BaseRMRestTest
|
|||||||
.title("Title")
|
.title("Title")
|
||||||
.build())
|
.build())
|
||||||
.name(NONELECTRONIC_RECORD_NAME)
|
.name(NONELECTRONIC_RECORD_NAME)
|
||||||
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
|
.nodeType(NON_ELECTRONIC_RECORD_TYPE)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
//create records in Unfiled Container
|
//create records in Unfiled Container
|
||||||
FilePlanComponent recordElecInUnfiled = filePlanComponentAPI.createFilePlanComponent(electRecord, UNFILED_RECORDS_CONTAINER_ALIAS.toString());
|
FilePlanComponent recordElecInUnfiled = filePlanComponentAPI.createFilePlanComponent(electRecord, UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||||
FilePlanComponent recordNonElecInUnfiled = filePlanComponentAPI.createFilePlanComponent(nonElectronic, UNFILED_RECORDS_CONTAINER_ALIAS.toString());
|
FilePlanComponent recordNonElecInUnfiled = filePlanComponentAPI.createFilePlanComponent(nonElectronic, UNFILED_RECORDS_CONTAINER_ALIAS);
|
||||||
|
|
||||||
// List children for the electronic Record
|
// List children for the electronic Record
|
||||||
filePlanComponentAPI.listChildComponents(recordElecInUnfiled.getId(), "where=(isFile=true)")
|
filePlanComponentAPI.listChildComponents(recordElecInUnfiled.getId(), "where=(isFile=true)")
|
||||||
@@ -441,8 +450,8 @@ public class ReadRecordTests extends BaseRMRestTest
|
|||||||
nonElectronic.setRelativePath(RELATIVE_PATH);
|
nonElectronic.setRelativePath(RELATIVE_PATH);
|
||||||
|
|
||||||
//create records in Unfiled Container
|
//create records in Unfiled Container
|
||||||
FilePlanComponent recordElecFromRecordFolder = filePlanComponentAPI.createFilePlanComponent(electRecord, FILE_PLAN_ALIAS.toString());
|
FilePlanComponent recordElecFromRecordFolder = filePlanComponentAPI.createFilePlanComponent(electRecord, FILE_PLAN_ALIAS);
|
||||||
FilePlanComponent recordNonElecFromRecordFolder = filePlanComponentAPI.createFilePlanComponent(nonElectronic, FILE_PLAN_ALIAS.toString());
|
FilePlanComponent recordNonElecFromRecordFolder = filePlanComponentAPI.createFilePlanComponent(nonElectronic, FILE_PLAN_ALIAS);
|
||||||
|
|
||||||
// List children for the electronic Record
|
// List children for the electronic Record
|
||||||
filePlanComponentAPI.listChildComponents(recordElecFromRecordFolder.getId(), "where=(isFile=true)")
|
filePlanComponentAPI.listChildComponents(recordElecFromRecordFolder.getId(), "where=(isFile=true)")
|
||||||
|
Reference in New Issue
Block a user