From 9892d88c5b4c5261e213b86232a098de31b40eda Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Tue, 3 Jan 2017 14:20:55 +0200 Subject: [PATCH] updates on Read Records API tests --- .../fileplancomponents/FilePlanComponent.java | 3 +- .../FilePlanComponentFields.java | 3 +- .../rm/community/requests/RecordsAPI.java | 33 ++++++++- .../rest/rm/community/base/BaseRestTest.java | 13 ++-- .../fileplancomponents/ReadRecordTests.java | 69 +++++++++++++++---- 5 files changed, 95 insertions(+), 26 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponent.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponent.java index 5fbf4cb383..6957ed908b 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponent.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponent.java @@ -28,6 +28,7 @@ package org.alfresco.rest.rm.community.model.fileplancomponents; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.ALLOWABLE_OPERATIONS; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.IS_CLOSED; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.IS_COMPLETED; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PATH; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.RELATIVE_PATH; @@ -81,7 +82,7 @@ public class FilePlanComponent @JsonProperty(value = IS_CLOSED) private Boolean isClosed; - @JsonProperty + @JsonProperty(value = IS_COMPLETED) private Boolean isCompleted; @JsonProperty (required = true) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentFields.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentFields.java index 743db8cf6c..68b8a3def0 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentFields.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentFields.java @@ -49,6 +49,7 @@ public class FilePlanComponentFields public static final String PROPERTIES_REVIEW_PERIOD = "rma:reviewPeriod"; public static final String PROPERTIES_LOCATION = "rma:location"; public static final String PROPERTIES_IS_CLOSED = "rma:isClosed"; // not to be confused with IS_CLOSED! + public static final String IS_COMPLETED = "isCompleted"; // for non-electronic records public static final String PROPERTIES_BOX = "rma:box"; @@ -58,7 +59,7 @@ public class FilePlanComponentFields public static final String PROPERTIES_SHELF = "rma:shelf"; public static final String PROPERTIES_STORAGE_LOCATION = "rma:storageLocation"; - //RelativePath specifies the container structure to create relative to the node nodeId. + //RelativePath specifies the container structure to create relative to the nodeId. public static final String RELATIVE_PATH = "relativePath"; public static final String PATH = "path"; } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/RecordsAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/RecordsAPI.java index b0423791ba..6843494674 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/RecordsAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/RecordsAPI.java @@ -49,18 +49,45 @@ import org.springframework.stereotype.Component; @Scope (value = "prototype") public class RecordsAPI extends RestAPI { + /** + * Get the content for the electronic record + * + * @param recordId The id of the electronic record + * @return The content for the given record id + * @throws Exception for the following cases: + * + */ public T getRecordContentText(String recordId) throws Exception { mandatoryString("recordId", recordId); - //RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "records/{recordId}/content?{parameters}", recordId, getParameters()); Response response = given().auth().basic(usingRestWrapper().getTestUser().getUsername(), usingRestWrapper().getTestUser().getPassword()) - .get("records/{recordId}/content?{parameters}", recordId, getParameters()) - .andReturn(); + .get("records/{recordId}/content?{parameters}", recordId, getParameters()) + .andReturn(); + usingRestWrapper().setStatusCode(Integer.toString(response.getStatusCode())); + LOG.info("The record content is " + response.getBody().prettyPrint()); return (T) response.getBody().prettyPrint(); } + /** + * Get the html content for the electronic record + * + * @param recordId The id of the electronic record + * @return The content for the given record id + * @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
  • + *
+ */ public RestHtmlResponse getRecordContent(String recordId) throws Exception { mandatoryString("recordId", recordId); diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java index 407942452f..23aa715f04 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java @@ -113,7 +113,7 @@ public class BaseRestTest extends RestTest @Autowired private AlfrescoHttpClientFactory alfrescoHttpClientFactory; - + // Constants public static final String RM_ID = "rm"; public static final String RM_TITLE = "Records Management"; @@ -287,7 +287,7 @@ public class BaseRestTest extends RestTest return filePlanComponentAPI.getFilePlanComponent(componentId); } - + /** * Helper method to add permission on a component to user * @param component {@link FilePlanComponent} on which permission should be given @@ -301,7 +301,7 @@ public class BaseRestTest extends RestTest { // get an "old-style" REST API client AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); - + JsonObject bodyJson = buildObject() .addArray("permissions") .addObject() @@ -315,7 +315,7 @@ public class BaseRestTest extends RestTest .setBaseUri(client.getApiUrl()) .setBasePath("/") .build(); - + // execute an "old-style" API call Response response = given() .spec(spec) @@ -330,11 +330,10 @@ public class BaseRestTest extends RestTest .andReturn(); filePlanComponentAPI.usingRestWrapper().setStatusCode(Integer.toString(response.getStatusCode())); } -} + /** - * Create temp file - * real size content + * Create temp file with content * * @param name file name * @return {@link File} file 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 2f716962df..e6cf21a140 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 @@ -31,6 +31,7 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.HOLDS_ALIAS; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.IS_COMPLETED; 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; @@ -62,7 +63,7 @@ import org.testng.annotations.Test; /** * This class contains the tests for - * read records API + * Read Records API * * @author Rodica Sutu * @since 2.6 @@ -88,9 +89,10 @@ public class ReadRecordTests extends BaseRestTest .nodeType(CONTENT_TYPE.toString()) .content(FilePlanComponentContent.builder().mimeType("text/plain").build()) .build(); + FilePlanComponent nonelectronicRecord = FilePlanComponent.builder() .properties(FilePlanComponentProperties.builder() - .description("Description") + .description(NONELECTRONIC_RECORD_NAME) .title("Title") .build()) .name(NONELECTRONIC_RECORD_NAME) @@ -124,9 +126,9 @@ public class ReadRecordTests extends BaseRestTest FilePlanComponent electronicRecord = FilePlanComponent.builder() .name(ELECTRONIC_RECORD_NAME) - .nodeType(CONTENT_TYPE.toString()) - .content(FilePlanComponentContent.builder().mimeType("text/plain").build()) - .build(); + .nodeType(CONTENT_TYPE.toString()) + .content(FilePlanComponentContent.builder().mimeType("text/plain").build()) + .build(); FilePlanComponent nonelectronicRecord= FilePlanComponent.builder() .properties(FilePlanComponentProperties.builder() .description("Description") @@ -155,13 +157,10 @@ public class ReadRecordTests extends BaseRestTest @Test public void readChildrenOnRecordsString() throws Exception { - String ELECTRONIC_RECORD_NAME = "Record electronic" + getRandomAlphanumeric(); - String NONELECTRONIC_RECORD_NAME = "Record nonelectronic" + getRandomAlphanumeric(); String RELATIVE_PATH="CATEGORY"+ getRandomAlphanumeric()+"/FOLDER"; filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - //create records in Unfiled Container FilePlanComponent recordElecInUnfiled = filePlanComponentAPI.createFilePlanComponent(electronicRecord, UNFILED_RECORDS_CONTAINER_ALIAS.toString()); FilePlanComponent recordNonElecInUnfiled = filePlanComponentAPI.createFilePlanComponent(nonelectronicRecord, UNFILED_RECORDS_CONTAINER_ALIAS.toString()); @@ -211,9 +210,50 @@ public class ReadRecordTests extends BaseRestTest @Test public void readRecordMetadata() throws Exception { - recordsAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - logger.info("NEW TEST" + recordsAPI.getRecordContentText("05978b97-bc84-4693-9f3f-f1b0502cfa7b").toString()); + String RELATIVE_PATH = "/" + CATEGORY_NAME + getRandomAlphanumeric() + "/folder"; + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + //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(); + //create electronic record + //String recordWithContentId = + FilePlanComponent fpc = filePlanComponentAPI.createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), folderId);//.getId(); + //Get the record created + FilePlanComponent recordWithContent=filePlanComponentAPI.withParams("include = "+ IS_COMPLETED).getFilePlanComponent(fpc.getId()); + //Check the metadata returned + assertTrue(recordWithContent.getName().startsWith(ELECTRONIC_RECORD_NAME)); + assertTrue(recordWithContent.getIsFile()); + assertFalse(recordWithContent.getIsCategory()); + assertFalse(recordWithContent.getIsRecordFolder()); + assertNotNull(recordWithContent.getContent().getEncoding()); + assertEquals(recordWithContent.getNodeType(),CONTENT_TYPE.toString()); + assertNotNull(recordWithContent.getContent().getEncoding()); + assertNotNull(recordWithContent.getContent().getMimeType()); + assertNotNull(recordWithContent.getAspectNames()); + assertEquals(recordWithContent.getProperties().getDescription(),ELECTRONIC_RECORD_NAME); + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); + //create non-electronic record + String nonElectronicRecordId = filePlanComponentAPI.createFilePlanComponent(nonelectronicRecord, folderId).getId(); + //Get the record created + FilePlanComponent nonElectronicRecord = filePlanComponentAPI.withParams("include = " + IS_COMPLETED).getFilePlanComponent(nonElectronicRecordId); + + //Check the metadata returned + assertTrue(nonElectronicRecord.getName().startsWith(NONELECTRONIC_RECORD_NAME)); + assertTrue(nonElectronicRecord.getIsFile()); + assertFalse(nonElectronicRecord.getIsCategory()); + assertFalse(nonElectronicRecord.getIsRecordFolder()); + assertNotNull(nonElectronicRecord.getContent().getEncoding()); + assertEquals(nonElectronicRecord.getNodeType(), NON_ELECTRONIC_RECORD_TYPE.toString()); + assertNotNull(nonElectronicRecord.getContent().getEncoding()); + assertNotNull(nonElectronicRecord.getContent().getMimeType()); + assertNotNull(nonElectronicRecord.getAspectNames()); + assertEquals(nonElectronicRecord.getProperties().getDescription(), NONELECTRONIC_RECORD_NAME); + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); } /** @@ -261,7 +301,7 @@ public class ReadRecordTests extends BaseRestTest * Then I am informed that the record has no content */ @Test - public void readRecordNonElectronicContent() throws Exception + public void readNonElectronicRecordContent() throws Exception { String NONELECTRONIC_RECORD_NAME = "Record nonelectronic" + getRandomAlphanumeric(); @@ -276,6 +316,7 @@ public class ReadRecordTests extends BaseRestTest recordsAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); assertTrue(recordsAPI.getRecordContentText(nonElectronicRecord).toString().isEmpty()); recordsAPI.usingRestWrapper().assertStatusCodeIs(OK); + } /** @@ -289,7 +330,7 @@ public class ReadRecordTests extends BaseRestTest dataProviderClass = TestData.class, description = "Reading records from invalid containers" ) - public void readContainFromInvalidContainers(String container) throws Exception + public void readContentFromInvalidContainers(String container) throws Exception { recordsAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); recordsAPI.getRecordContentText(container).toString(); @@ -297,9 +338,9 @@ public class ReadRecordTests extends BaseRestTest } /** - * Given a container that is a record folder + * Given a container that is a record/unfiled folder * When I try to record the containers records - * Then I receive a list of all the records contained within the record folder + * Then I receive a list of all the records contained within the record/unfiled folder */ /** Valid root containers where electronic and non-electronic records can be created */