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 85c781b51c..8a83c591c5 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
@@ -31,20 +31,18 @@ import static com.jayway.restassured.RestAssured.given;
import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryString;
import com.jayway.restassured.response.Response;
+import com.jayway.restassured.response.ResponseBody;
import org.alfresco.rest.core.RMRestWrapper;
-import org.alfresco.rest.core.RestRequest;
-import org.alfresco.rest.model.RestHtmlResponse;
import org.alfresco.rest.rm.community.requests.RMModelRequest;
import org.springframework.context.annotation.Scope;
-import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
/**
- *Records REST API Wrapper
+ * Records REST API Wrapper
*
- *@author Rodica Sutu
- *@since 2.6
+ * @author Rodica Sutu
+ * @since 2.6
*/
@Component
@Scope (value = "prototype")
@@ -62,7 +60,7 @@ public class RecordsAPI extends RMModelRequest
* Get the content for the electronic record
*
* @param recordId The id of the electronic record
- * @return The content for the given record id
+ * @return {@link ResponseBody} representing content for the given record id
* @throws Exception for the following cases:
*
* - {@code recordId} has no content
@@ -71,40 +69,16 @@ public class RecordsAPI extends RMModelRequest
* - {@code recordId} does not exist
*
*/
- //FIXME Add a generic method to support retrieving binary content
- public T getRecordContentText(String recordId) throws Exception
+ public ResponseBody> getRecordContent(String recordId) throws Exception
{
mandatoryString("recordId", recordId);
- Response response = given().auth().basic(getRMRestWrapper().getTestUser().getUsername(),
- getRMRestWrapper().getTestUser().getPassword()
- )
+ Response response = given()
+ .auth().basic(getRMRestWrapper().getTestUser().getUsername(),
+ getRMRestWrapper().getTestUser().getPassword())
+ .when()
.get("records/{recordId}/content", recordId)
.andReturn();
-
getRMRestWrapper().setStatusCode(Integer.toString(response.getStatusCode()));
-
- return (T) response.getBody().prettyPrint();
- }
-
- /**
- * Get the content RestHtmlResponse(Response header and body) for the electronic record
- *
- * @param recordId The id of the electronic record
- * @return The body and the header for the record
- * @throws Exception for the following cases:
- *
- * - {@code recordId} has no content
- * - {@code recordId} is not a valid format, or is not a record
- * - authentication fails
- * - {@code recordId} does not exist
- *
- */
- //FIXME Add a generic method to support retrieving binary content as we might end up
- //FIXME with too many methods for differents content types
- public RestHtmlResponse getRecordContent(String recordId) throws Exception
- {
- mandatoryString("recordId", recordId);
- RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "records/{recordId}/content", recordId);
- return getRMRestWrapper().processHtmlResponse(request);
+ return response.getBody();
}
}
diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java
index 05185ce1d3..ebef9ce32c 100644
--- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java
+++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java
@@ -33,8 +33,8 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAspects.ASPECTS_CLOSED_RECORD;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
-import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_TYPE;
+import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE;
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createFilePlanComponentModel;
import static org.alfresco.rest.rm.community.utils.RMSiteUtil.createStandardRMSiteModel;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
@@ -45,11 +45,6 @@ import static org.testng.Assert.assertTrue;
import java.util.List;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.OutputStreamWriter;
-import java.nio.charset.Charset;
-
import org.alfresco.rest.RestTest;
import org.alfresco.rest.core.RestAPIFactory;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/ReadRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/ReadRecordTests.java
index a1a96649c6..b86c6b1328 100644
--- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/ReadRecordTests.java
+++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/ReadRecordTests.java
@@ -35,6 +35,7 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo
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.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
+import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.IMAGE_FILE;
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createTempFile;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
@@ -45,9 +46,13 @@ import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.fail;
import static org.testng.AssertJUnit.assertTrue;
+import java.io.File;
+import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.NoSuchElementException;
+import com.google.common.io.Resources;
+
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
import org.alfresco.rest.rm.community.base.TestData;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
@@ -55,6 +60,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.FilePlanComponentsCollection;
import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
+import org.apache.commons.codec.digest.DigestUtils;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -77,7 +83,7 @@ public class ReadRecordTests extends BaseRMRestTest
.nodeType(CONTENT_TYPE.toString())
.content(FilePlanComponentContent.builder().mimeType("text/plain").build())
.build();
-
+
private FilePlanComponent nonelectronicRecord = FilePlanComponent.builder()
.properties(FilePlanComponentProperties.builder()
.description(NONELECTRONIC_RECORD_NAME)
@@ -200,32 +206,48 @@ public class ReadRecordTests extends BaseRMRestTest
public void readRecordContent() throws Exception
{
String RECORD_ELECTRONIC = "Record " + getRandomAlphanumeric();
- String RELATIVE_PATH = "/"+CATEGORY_NAME+ getRandomAlphanumeric()+"/folder";
+ String RECORD_ELECTRONIC_BINARY = "Binary Record" + getRandomAlphanumeric();
+ String RELATIVE_PATH = "/" + CATEGORY_NAME + getRandomAlphanumeric() + "/folder";
+
+ // create the containers from the relativePath
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
- //create the containers from the relativePath
FilePlanComponent recordFolder = FilePlanComponent.builder()
.name(FOLDER_NAME)
.nodeType(RECORD_FOLDER_TYPE.toString())
.relativePath(RELATIVE_PATH)
.build();
- String folderId = filePlanComponentAPI.createFilePlanComponent(recordFolder,FILE_PLAN_ALIAS.toString()).getId();
- //
- FilePlanComponent record = FilePlanComponent.builder()
+ String folderId = filePlanComponentAPI.createFilePlanComponent(recordFolder, FILE_PLAN_ALIAS.toString()).getId();
+
+ // text file as an electronic record
+ FilePlanComponent recordText = FilePlanComponent.builder()
.name(RECORD_ELECTRONIC)
.nodeType(CONTENT_TYPE.toString())
.build();
- String recordId = filePlanComponentAPI.createElectronicRecord(record, createTempFile(RECORD_ELECTRONIC, RECORD_ELECTRONIC), folderId).getId();
-
- assertEquals(getRestAPIFactory().getRecordsAPI().getRecordContentText(recordId),RECORD_ELECTRONIC);
+ String recordId = filePlanComponentAPI.createElectronicRecord(recordText, createTempFile(RECORD_ELECTRONIC, RECORD_ELECTRONIC), folderId).getId();
+ assertEquals(getRestAPIFactory().getRecordsAPI().getRecordContent(recordId).asString(), RECORD_ELECTRONIC);
// Check status code
assertStatusCode(OK);
+ // binary file as an electronic record
+ FilePlanComponent recordBinary = FilePlanComponent.builder()
+ .name(RECORD_ELECTRONIC_BINARY)
+ .nodeType(CONTENT_TYPE.toString())
+ .build();
+
+ String binaryRecordId = filePlanComponentAPI.createElectronicRecord(recordBinary, IMAGE_FILE, folderId).getId();
+ // binary content, therefore compare respective SHA1 checksums in order to verify this is identical content
+ assertEquals(
+ DigestUtils.sha1(getRestAPIFactory().getRecordsAPI().getRecordContent(binaryRecordId).asInputStream()),
+ DigestUtils.sha1(new FileInputStream(new File(Resources.getResource(IMAGE_FILE).getFile()))));
+ assertStatusCode(OK);
+
+ // electronic record with no content
FilePlanComponent recordNoContent = FilePlanComponent.builder()
.name(RECORD_ELECTRONIC)
.nodeType(CONTENT_TYPE.toString())
.build();
String recordNoContentId = filePlanComponentAPI.createFilePlanComponent(recordNoContent,folderId).getId();
- assertTrue(getRestAPIFactory().getRecordsAPI().getRecordContentText(recordNoContentId).toString().isEmpty());
+ assertTrue(getRestAPIFactory().getRecordsAPI().getRecordContent(recordNoContentId).asString().isEmpty());
assertStatusCode(OK);
}
/**
@@ -245,12 +267,11 @@ public class ReadRecordTests extends BaseRMRestTest
.relativePath("/"+CATEGORY_NAME+getRandomAlphanumeric()+"/"+FOLDER_NAME)
.build();
- String nonElectronicRecord= filePlanComponentAPI.createFilePlanComponent(record,FILE_PLAN_ALIAS.toString()).getId();
+ String nonElectronicRecord = filePlanComponentAPI.createFilePlanComponent(record,FILE_PLAN_ALIAS.toString()).getId();
- assertTrue(getRestAPIFactory().getRecordsAPI().getRecordContentText(nonElectronicRecord).toString().isEmpty());
+ assertTrue(getRestAPIFactory().getRecordsAPI().getRecordContent(nonElectronicRecord).asString().isEmpty());
assertStatusCode(OK);
-
}
/**
@@ -266,7 +287,7 @@ public class ReadRecordTests extends BaseRMRestTest
)
public void readContentFromInvalidContainers(String container) throws Exception
{
- getRestAPIFactory().getRecordsAPI().getRecordContentText(container).toString();
+ getRestAPIFactory().getRecordsAPI().getRecordContent(container).asString();
assertStatusCode(BAD_REQUEST);
}