From bebca649fe8335bc07bb33d9376f7639b73c7629 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Tue, 3 Jan 2017 08:16:12 +0200 Subject: [PATCH 1/8] -Add tests for Read Records (1) --- .../rm-automation-community-rest-api/pom.xml | 27 ++ .../fileplancomponents/FilePlanComponent.java | 2 +- .../FilePlanComponentContent.java | 9 + .../requests/FilePlanComponentAPI.java | 6 +- .../rm/community/requests/RecordsAPI.java | 70 ++++ .../rest/rm/community/base/BaseRestTest.java | 50 ++- .../fileplancomponents/ReadRecordTests.java | 305 ++++++++++++++++++ 7 files changed, 458 insertions(+), 11 deletions(-) create mode 100644 rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/RecordsAPI.java create mode 100644 rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/ReadRecordTests.java diff --git a/rm-automation/rm-automation-community-rest-api/pom.xml b/rm-automation/rm-automation-community-rest-api/pom.xml index 0579d444e2..24280df4be 100644 --- a/rm-automation/rm-automation-community-rest-api/pom.xml +++ b/rm-automation/rm-automation-community-rest-api/pom.xml @@ -19,6 +19,16 @@ + + + + org.projectlombok + lombok-maven-plugin + 1.16.10 + + + + org.codehaus.mojo @@ -29,6 +39,23 @@ ${project.parent.parent.basedir}/license/description.ftl + + org.projectlombok + lombok-maven-plugin + 1.16.8.0 + + UTF-8 + + + + generate-sources + + testDelombok + delombok + + + + 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 4b3c0274df..5fbf4cb383 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 @@ -90,7 +90,7 @@ public class FilePlanComponent @JsonProperty (required = true) private FilePlanComponentUserInfo createdByUser; - @JsonProperty(value = PROPERTIES, required = true) + @JsonProperty(value = PROPERTIES) private FilePlanComponentProperties properties; @JsonProperty (value = ALLOWABLE_OPERATIONS) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentContent.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentContent.java index 9a7a23bbde..36eada3bb5 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentContent.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentContent.java @@ -28,11 +28,20 @@ package org.alfresco.rest.rm.community.model.fileplancomponents; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + /** * POJO for FilePlanComponent content field * @author Kristijan Conkas * @since 2.6 */ +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor public class FilePlanComponentContent { @JsonProperty (required = true) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/FilePlanComponentAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/FilePlanComponentAPI.java index 5279bdf67f..5a2a269fbd 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/FilePlanComponentAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/FilePlanComponentAPI.java @@ -110,8 +110,8 @@ public class FilePlanComponentAPI extends RestAPI return usingRestWrapper().processModels(FilePlanComponentsCollection.class, simpleRequest( GET, - "fileplan-components/{fileplanComponentId}/children", - filePlanComponentId + "fileplan-components/{fileplanComponentId}/children?{parameters}", + filePlanComponentId, getParameters() )); } @@ -203,7 +203,7 @@ public class FilePlanComponentAPI extends RestAPI builder.addMultiPart("filedata", recordContent, ContentType.BINARY.name()); /* - * RestWrapper adds some headers which break multipart/form-data uploads and also assumes json POST requests. + * RestWrapper adds some headers which break multipart/form-data uploads and also assumes json POST requests. * Upload the file using RestAssured library. */ Response response = given() 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 new file mode 100644 index 0000000000..b0423791ba --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/RecordsAPI.java @@ -0,0 +1,70 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2017 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.rest.rm.community.requests; + +import static com.jayway.restassured.RestAssured.given; + +import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryString; + +import com.jayway.restassured.response.Response; + +import org.alfresco.rest.core.RestAPI; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestHtmlResponse; +import org.springframework.context.annotation.Scope; +import org.springframework.http.HttpMethod; +import org.springframework.stereotype.Component; + +/** + *Records REST API Wrapper + * + *@author Rodica Sutu + *@since 2.6 + */ +@Component +@Scope (value = "prototype") +public class RecordsAPI extends RestAPI +{ + 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(); + usingRestWrapper().setStatusCode(Integer.toString(response.getStatusCode())); + LOG.info("The record content is " + response.getBody().prettyPrint()); + return (T) response.getBody().prettyPrint(); + } + + public RestHtmlResponse getRecordContent(String recordId) throws Exception + { + mandatoryString("recordId", recordId); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "records/{recordId}/content?{parameters}", recordId, getParameters()); + return usingRestWrapper().processHtmlResponse(request); + } +} 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 d888ab2692..407942452f 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 @@ -44,6 +44,11 @@ import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.OK; import com.google.gson.JsonObject; +import java.io.File; +import java.io.FileOutputStream; +import java.io.OutputStreamWriter; +import java.nio.charset.Charset; + import com.jayway.restassured.RestAssured; import com.jayway.restassured.builder.RequestSpecBuilder; import com.jayway.restassured.http.ContentType; @@ -99,7 +104,7 @@ public class BaseRestTest extends RestTest @Autowired private RMSiteAPI rmSiteAPI; - + @Autowired private DataUser dataUser; @@ -239,18 +244,18 @@ public class BaseRestTest extends RestTest public FilePlanComponent closeFolder(String folderId) throws Exception { RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - + // build fileplan component + properties for update request FilePlanComponentProperties properties = new FilePlanComponentProperties(); properties.setIsClosed(true); FilePlanComponent filePlanComponent = new FilePlanComponent(); filePlanComponent.setProperties(properties); - + FilePlanComponent updatedComponent = filePlanComponentAPI.updateFilePlanComponent(filePlanComponent, folderId); restWrapper.assertStatusCodeIs(OK); return updatedComponent; } - + /** * Helper method to create a randomly-named / structure in fileplan * @param user user under whose privileges this structure is going to be created @@ -261,14 +266,14 @@ public class BaseRestTest extends RestTest public FilePlanComponent createCategoryFolderInFilePlan(UserModel user, String parentId) throws Exception { filePlanComponentAPI.usingRestWrapper().authenticateUser(user); - + // create root category FilePlanComponent recordCategory = createCategory(parentId, "Category " + getRandomAlphanumeric()); - + // and return a folder underneath return createFolder(recordCategory.getId(), "Folder " + getRandomAlphanumeric()); } - + /** * Helper method to retieve a fileplan component with user's privilege * @param user user under whose privileges a component is to be read @@ -281,6 +286,7 @@ public class BaseRestTest extends RestTest filePlanComponentAPI.usingRestWrapper().authenticateUser(user); return filePlanComponentAPI.getFilePlanComponent(componentId); } + /** * Helper method to add permission on a component to user @@ -325,3 +331,33 @@ public class BaseRestTest extends RestTest filePlanComponentAPI.usingRestWrapper().setStatusCode(Integer.toString(response.getStatusCode())); } } + + /** + * Create temp file + * real size content + * + * @param name file name + * @return {@link File} file + */ + public static File createTempFile(final String name,String content) + { + try + { + // create file + final File file = File.createTempFile(name, ".txt"); + + // create writer + try (FileOutputStream fos = new FileOutputStream(file); + OutputStreamWriter writer = new OutputStreamWriter(fos, Charset.forName("UTF-8").newEncoder())) + { + // place content in file + writer.write(content); + } + + return file; + } catch (Exception exception) + { + throw new RuntimeException("Unable to create test file.", exception); + } + } +} 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 new file mode 100644 index 0000000000..45f8f5c90b --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/ReadRecordTests.java @@ -0,0 +1,305 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2017 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.rest.rm.community.fileplancomponents; + +import static org.alfresco.rest.rm.community.base.TestData.FOLDER_NAME; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; +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.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.utility.data.RandomData.getRandomAlphanumeric; +import static org.springframework.http.HttpStatus.BAD_REQUEST; +import static org.springframework.http.HttpStatus.OK; +import static org.testng.Assert.assertEquals; +import static org.testng.AssertJUnit.assertTrue; + +import org.alfresco.rest.rm.community.base.BaseRestTest; +import org.alfresco.rest.rm.community.base.TestData; +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.requests.FilePlanComponentAPI; +import org.alfresco.rest.rm.community.requests.RecordsAPI; +import org.alfresco.utility.data.DataUser; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * This class contains the tests for + * read records API + * + * @author Rodica Sutu + * @since 2.6 + */ +public class ReadRecordTests extends BaseRestTest +{ + + @Autowired + private FilePlanComponentAPI filePlanComponentAPI; + @Autowired + private RecordsAPI recordsAPI; + + @Autowired + private DataUser dataUser; + + private String CATEGORY_NAME=TestData.CATEGORY_NAME +getRandomAlphanumeric(); + + String ELECTRONIC_RECORD_NAME = "Record electronic" + getRandomAlphanumeric(); + String NONELECTRONIC_RECORD_NAME = "Record nonelectronic" + getRandomAlphanumeric(); + + FilePlanComponent electronicRecord = FilePlanComponent.builder() + .name(ELECTRONIC_RECORD_NAME) + .nodeType(CONTENT_TYPE.toString()) + .content(FilePlanComponentContent.builder().mimeType("text/plain").build()) + .build(); + FilePlanComponent nonelectronicRecord = FilePlanComponent.builder() + .properties(FilePlanComponentProperties.builder() + .description("Description") + .title("Title") + .build()) + .name(NONELECTRONIC_RECORD_NAME) + .nodeType(NON_ELECTRONIC_RECORD_TYPE.toString()) + .build(); + + /** + * Given a record category or a container which can't contain records + * When I try to read the children filtering the results to records + * Then I receive an empty list + */ + @DataProvider(name="invalidContainersForRecords") + public Object[][] getContainers() throws Exception + { + return new Object[][] { + { FILE_PLAN_ALIAS.toString() }, + { TRANSFERS_ALIAS.toString() }, + { HOLDS_ALIAS.toString() }, + { createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY_NAME).getId()} + }; + } + @Test + ( + dataProvider ="invalidContainersForRecords", + description ="Reading records from invalid containers" + ) + public void readRecordsFromInvalidContainers(String container) throws Exception + { + + + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + FilePlanComponent electronicRecord = FilePlanComponent.builder() + .name(ELECTRONIC_RECORD_NAME) + .nodeType(CONTENT_TYPE.toString()) + .content(FilePlanComponentContent.builder().mimeType("text/plain").build()) + .build(); + FilePlanComponent nonelectronicRecord= FilePlanComponent.builder() + .properties(FilePlanComponentProperties.builder() + .description("Description") + .title("Title") + .build()) + .name(NONELECTRONIC_RECORD_NAME) + .nodeType(NON_ELECTRONIC_RECORD_TYPE.toString()) + .build(); + //create records + filePlanComponentAPI.createFilePlanComponent(electronicRecord,container); + filePlanComponentAPI.createFilePlanComponent(nonelectronicRecord, container); + + // List children from API + filePlanComponentAPI.withParams("where=(isFile=true)").listChildComponents(container) + //check the list returned is empty + .assertThat().entriesListIsEmpty().assertThat().paginationExist(); + // Check status code + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); + } + //TODO MAYBE Update AC ?? + /** + * Given a record + * When I try to read the children + * Then I receive error + */ + @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()); + + // List children for the electronic Record + filePlanComponentAPI.withParams("where=(isFile=true)").listChildComponents(recordElecInUnfiled.getId()) + //check the list returned is empty + .assertThat().entriesListIsEmpty().assertThat().paginationExist(); + // Check status code + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); + + // List children for the nonElectronic Record + filePlanComponentAPI.withParams("where=(isFile=true)").listChildComponents(recordNonElecInUnfiled.getId()) + //check the list returned is empty + .assertThat().entriesListIsEmpty().assertThat().paginationExist(); + // Check status code + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); + + //Update the Records objects + electronicRecord.setRelativePath(RELATIVE_PATH); + nonelectronicRecord.setRelativePath(RELATIVE_PATH); + + //create records in Unfiled Container + FilePlanComponent recordElecFromRecordFolder = filePlanComponentAPI.createFilePlanComponent(electronicRecord, FILE_PLAN_ALIAS.toString()); + FilePlanComponent recordNonElecFromRecordFolder = filePlanComponentAPI.createFilePlanComponent(nonelectronicRecord, FILE_PLAN_ALIAS.toString()); + + // List children for the electronic Record + filePlanComponentAPI.withParams("where=(isFile=true)").listChildComponents(recordElecFromRecordFolder.getId()) + //check the list returned is empty + .assertThat().entriesListIsEmpty().assertThat().paginationExist(); + // Check status code + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); + + // List children for the nonElectronic Record + filePlanComponentAPI.withParams("where=(isFile=true)").listChildComponents(recordNonElecFromRecordFolder.getId()) + //check the list returned is empty + .assertThat().entriesListIsEmpty().assertThat().paginationExist(); + // Check status code + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); + } + + /** + * Given a record + * When I try to read the meta-data + * Then I successfully receive the meta-data values for that record + */ + @Test + public void readRecordMetadata() throws Exception + { + recordsAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + logger.info("NEW TEST" + recordsAPI.getRecordContentText("05978b97-bc84-4693-9f3f-f1b0502cfa7b").toString()); + + } + + /** + * Given an electronic record + * When I try to read the content + * Then I successfully receive the content of the record + */ + @Test + public void readRecordContent() throws Exception + { + String RECORD_ELECTRONIC= "Record " + getRandomAlphanumeric(); + 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(); + // + FilePlanComponent record = FilePlanComponent.builder() + .name(RECORD_ELECTRONIC) + .nodeType(CONTENT_TYPE.toString()) + .build(); + String recordId =filePlanComponentAPI.createElectronicRecord(record, createTempFile(RECORD_ELECTRONIC, RECORD_ELECTRONIC), folderId).getId(); + + recordsAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + assertEquals(recordsAPI.getRecordContentText(recordId),RECORD_ELECTRONIC); + // Check status code + recordsAPI.usingRestWrapper().assertStatusCodeIs(OK); + + FilePlanComponent recordNoContent = FilePlanComponent.builder() + .name(RECORD_ELECTRONIC) + .nodeType(CONTENT_TYPE.toString()) + .build(); + String recordNoContentId=filePlanComponentAPI.createFilePlanComponent(recordNoContent,folderId).getId(); + assertTrue(recordsAPI.getRecordContentText(recordNoContentId).toString().isEmpty()); + recordsAPI.usingRestWrapper().assertStatusCodeIs(OK); + } + /** + * Given a non-electronic record + * When I try to read the content + * Then I am informed that the record has no content + */ + @Test + public void readRecordNonElectronicContent() throws Exception + { + + String NONELECTRONIC_RECORD_NAME = "Record nonelectronic" + getRandomAlphanumeric(); + FilePlanComponent record = FilePlanComponent.builder() + .name(NONELECTRONIC_RECORD_NAME) + .nodeType(NON_ELECTRONIC_RECORD_TYPE.toString()) + .relativePath("/"+CATEGORY_NAME+"/"+FOLDER_NAME) + .build(); + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + String nonElectronicRecord=filePlanComponentAPI.createFilePlanComponent(record,FILE_PLAN_ALIAS.toString()).getId(); + recordsAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + assertTrue(recordsAPI.getRecordContentText(nonElectronicRecord).toString().isEmpty()); + recordsAPI.usingRestWrapper().assertStatusCodeIs(OK); + } + + /** + * Given a container (eg record folder, record category, etc) + * When I try to read the content + * Then I receive an error + */ + @Test + ( + dataProvider = "getContainers", + dataProviderClass = TestData.class, + description = "Reading records from invalid containers" + ) + public void readContainFromInvalidContainers(String container) throws Exception + { + recordsAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + recordsAPI.getRecordContentText(container).toString(); + recordsAPI.usingRestWrapper().assertStatusCodeIs(BAD_REQUEST); + } + + /** + * Given a container that is a record folder + * When I try to record the containers records + * Then I receive a list of all the records contained within the record folder + */ + + /** + * Given a container this an unfiled record folder or the unfiled record container root + * When I try to record the containers records + * Then I receive a list of all the records contained within the unfiled record folder or the unfiled record container root + */ + + + +} From f0f896668b1231ee22d661e35433ba9b9a640c6a Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Tue, 3 Jan 2017 10:20:27 +0200 Subject: [PATCH 2/8] add tests for list the records --- .../fileplancomponents/ReadRecordTests.java | 118 ++++++++++++++++-- 1 file changed, 109 insertions(+), 9 deletions(-) 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 45f8f5c90b..2f716962df 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 @@ -38,13 +38,21 @@ import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.OK; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.fail; import static org.testng.AssertJUnit.assertTrue; +import java.util.ArrayList; +import java.util.NoSuchElementException; + +import org.alfresco.rest.core.RestWrapper; import org.alfresco.rest.rm.community.base.BaseRestTest; import org.alfresco.rest.rm.community.base.TestData; 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.FilePlanComponentsCollection; import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI; import org.alfresco.rest.rm.community.requests.RecordsAPI; import org.alfresco.utility.data.DataUser; @@ -70,7 +78,7 @@ public class ReadRecordTests extends BaseRestTest @Autowired private DataUser dataUser; - private String CATEGORY_NAME=TestData.CATEGORY_NAME +getRandomAlphanumeric(); + String CATEGORY_NAME=TestData.CATEGORY_NAME +getRandomAlphanumeric(); String ELECTRONIC_RECORD_NAME = "Record electronic" + getRandomAlphanumeric(); String NONELECTRONIC_RECORD_NAME = "Record nonelectronic" + getRandomAlphanumeric(); @@ -95,7 +103,7 @@ public class ReadRecordTests extends BaseRestTest * Then I receive an empty list */ @DataProvider(name="invalidContainersForRecords") - public Object[][] getContainers() throws Exception + public Object[][] getInvalidContainersForRecords() throws Exception { return new Object[][] { { FILE_PLAN_ALIAS.toString() }, @@ -112,7 +120,6 @@ public class ReadRecordTests extends BaseRestTest public void readRecordsFromInvalidContainers(String container) throws Exception { - filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); FilePlanComponent electronicRecord = FilePlanComponent.builder() @@ -261,10 +268,11 @@ public class ReadRecordTests extends BaseRestTest FilePlanComponent record = FilePlanComponent.builder() .name(NONELECTRONIC_RECORD_NAME) .nodeType(NON_ELECTRONIC_RECORD_TYPE.toString()) - .relativePath("/"+CATEGORY_NAME+"/"+FOLDER_NAME) + .relativePath("/"+CATEGORY_NAME+getRandomAlphanumeric()+"/"+FOLDER_NAME) .build(); filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); String nonElectronicRecord=filePlanComponentAPI.createFilePlanComponent(record,FILE_PLAN_ALIAS.toString()).getId(); + recordsAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); assertTrue(recordsAPI.getRecordContentText(nonElectronicRecord).toString().isEmpty()); recordsAPI.usingRestWrapper().assertStatusCodeIs(OK); @@ -294,12 +302,104 @@ public class ReadRecordTests extends BaseRestTest * Then I receive a list of all the records contained within the record folder */ - /** - * Given a container this an unfiled record folder or the unfiled record container root - * When I try to record the containers records - * Then I receive a list of all the records contained within the unfiled record folder or the unfiled record container root - */ + /** Valid root containers where electronic and non-electronic records can be created */ + @DataProvider (name = "folderContainers") + public Object[][] getFolderContainers() throws Exception + { + return new Object[][] { + // an arbitrary record folder + { createCategoryFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString()).getId() }, + // an arbitrary unfiled records folder + { createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), "Unfiled Folder " + getRandomAlphanumeric()).getId() } + }; + } + + @Test + ( + dataProvider ="folderContainers", + description ="List the records from record folder/unfiled record folder" + ) + public void readRecordsFromFolders(String containerId) throws Exception + { + final int NUMBER_OF_RECORDS = 5; + //String RELATIVE_PATH = "/" + CATEGORY_NAME + getRandomAlphanumeric(); + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + // Create Electronic Records + ArrayList children = new ArrayList(); + for (int i = 0; i < NUMBER_OF_RECORDS; i++) + { + //build de electronic record + FilePlanComponent record = FilePlanComponent.builder() + .name(ELECTRONIC_RECORD_NAME +i) + .nodeType(CONTENT_TYPE.toString()) + .build(); + //create a child + FilePlanComponent child = filePlanComponentAPI.createElectronicRecord(record, createTempFile(ELECTRONIC_RECORD_NAME + i, ELECTRONIC_RECORD_NAME + i ), containerId); + children.add(child); + } + //Create NonElectronicRecords + for (int i = 0; i < NUMBER_OF_RECORDS; i++) + { + FilePlanComponent nonelectronicRecord = FilePlanComponent.builder() + .properties(FilePlanComponentProperties.builder() + .description("Description") + .title("Title") + .build()) + .name(NONELECTRONIC_RECORD_NAME+i) + .nodeType(NON_ELECTRONIC_RECORD_TYPE.toString()) + .build(); + //create records + FilePlanComponent child=filePlanComponentAPI.createFilePlanComponent(nonelectronicRecord, containerId); + children.add(child); + } + // Authenticate with admin user + RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + // List children from API + FilePlanComponentsCollection apiChildren = + (FilePlanComponentsCollection) filePlanComponentAPI.listChildComponents(containerId).assertThat().entriesListIsNotEmpty(); + + // Check status code + restWrapper.assertStatusCodeIs(OK); + // Check listed children against created list + apiChildren.getEntries().forEach(c -> + { + FilePlanComponent filePlanComponent = c.getFilePlanComponent(); + assertNotNull(filePlanComponent.getId()); + logger.info("Checking child " + filePlanComponent.getId()); + + try + { + // Find this child in created children list + FilePlanComponent createdComponent = children.stream() + .filter(child -> child.getId().equals(filePlanComponent.getId())) + .findFirst() + .get(); + + // Created by + assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername()); + + // Is parent Id set correctly + assertEquals(filePlanComponent.getParentId(), containerId); + assertTrue(filePlanComponent.getIsFile()); + + // Boolean properties related to node type + assertFalse(filePlanComponent.getIsRecordFolder()); + assertFalse(filePlanComponent.getIsCategory()); + + //assertEquals(createdComponent.getName(), filePlanComponent.getName()); + assertTrue(filePlanComponent.getName().startsWith(createdComponent.getName())); + assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType()); + + } catch (NoSuchElementException e) + { + fail("No child element for " + filePlanComponent.getId()); + } + } + ); + } } From 9892d88c5b4c5261e213b86232a098de31b40eda Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Tue, 3 Jan 2017 14:20:55 +0200 Subject: [PATCH 3/8] 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: + *
    + *
  • {@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 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 */ From 3bfd00c7a46eeef41654205a05215fc832378b04 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Tue, 3 Jan 2017 15:03:35 +0200 Subject: [PATCH 4/8] revert pom changes --- .../rm-automation-community-rest-api/pom.xml | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/pom.xml b/rm-automation/rm-automation-community-rest-api/pom.xml index 24280df4be..0579d444e2 100644 --- a/rm-automation/rm-automation-community-rest-api/pom.xml +++ b/rm-automation/rm-automation-community-rest-api/pom.xml @@ -19,16 +19,6 @@ - - - - org.projectlombok - lombok-maven-plugin - 1.16.10 - - - - org.codehaus.mojo @@ -39,23 +29,6 @@ ${project.parent.parent.basedir}/license/description.ftl - - org.projectlombok - lombok-maven-plugin - 1.16.8.0 - - UTF-8 - - - - generate-sources - - testDelombok - delombok - - - - From a69d85ff531688574b02a97d0e08e320029e4b55 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Tue, 3 Jan 2017 15:58:02 +0200 Subject: [PATCH 5/8] fix failing test --- .../fileplancomponents/ReadRecordTests.java | 131 ++++++++++-------- 1 file changed, 70 insertions(+), 61 deletions(-) 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 e6cf21a140..29787ef498 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 @@ -70,7 +70,6 @@ import org.testng.annotations.Test; */ public class ReadRecordTests extends BaseRestTest { - @Autowired private FilePlanComponentAPI filePlanComponentAPI; @Autowired @@ -84,13 +83,13 @@ public class ReadRecordTests extends BaseRestTest String ELECTRONIC_RECORD_NAME = "Record electronic" + getRandomAlphanumeric(); String NONELECTRONIC_RECORD_NAME = "Record nonelectronic" + getRandomAlphanumeric(); - FilePlanComponent electronicRecord = FilePlanComponent.builder() + private FilePlanComponent electronicRecord = FilePlanComponent.builder() .name(ELECTRONIC_RECORD_NAME) .nodeType(CONTENT_TYPE.toString()) .content(FilePlanComponentContent.builder().mimeType("text/plain").build()) .build(); - - FilePlanComponent nonelectronicRecord = FilePlanComponent.builder() + + private FilePlanComponent nonelectronicRecord = FilePlanComponent.builder() .properties(FilePlanComponentProperties.builder() .description(NONELECTRONIC_RECORD_NAME) .title("Title") @@ -148,59 +147,6 @@ public class ReadRecordTests extends BaseRestTest // Check status code filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); } - //TODO MAYBE Update AC ?? - /** - * Given a record - * When I try to read the children - * Then I receive error - */ - @Test - public void readChildrenOnRecordsString() throws Exception - { - 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()); - - // List children for the electronic Record - filePlanComponentAPI.withParams("where=(isFile=true)").listChildComponents(recordElecInUnfiled.getId()) - //check the list returned is empty - .assertThat().entriesListIsEmpty().assertThat().paginationExist(); - // Check status code - filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); - - // List children for the nonElectronic Record - filePlanComponentAPI.withParams("where=(isFile=true)").listChildComponents(recordNonElecInUnfiled.getId()) - //check the list returned is empty - .assertThat().entriesListIsEmpty().assertThat().paginationExist(); - // Check status code - filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); - - //Update the Records objects - electronicRecord.setRelativePath(RELATIVE_PATH); - nonelectronicRecord.setRelativePath(RELATIVE_PATH); - - //create records in Unfiled Container - FilePlanComponent recordElecFromRecordFolder = filePlanComponentAPI.createFilePlanComponent(electronicRecord, FILE_PLAN_ALIAS.toString()); - FilePlanComponent recordNonElecFromRecordFolder = filePlanComponentAPI.createFilePlanComponent(nonelectronicRecord, FILE_PLAN_ALIAS.toString()); - - // List children for the electronic Record - filePlanComponentAPI.withParams("where=(isFile=true)").listChildComponents(recordElecFromRecordFolder.getId()) - //check the list returned is empty - .assertThat().entriesListIsEmpty().assertThat().paginationExist(); - // Check status code - filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); - - // List children for the nonElectronic Record - filePlanComponentAPI.withParams("where=(isFile=true)").listChildComponents(recordNonElecFromRecordFolder.getId()) - //check the list returned is empty - .assertThat().entriesListIsEmpty().assertThat().paginationExist(); - // Check status code - filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); - } /** * Given a record @@ -220,10 +166,9 @@ public class ReadRecordTests extends BaseRestTest .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(); + String recordWithContentId = 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()); + FilePlanComponent recordWithContent=filePlanComponentAPI.withParams("include = "+ IS_COMPLETED).getFilePlanComponent(recordWithContentId); //Check the metadata returned assertTrue(recordWithContent.getName().startsWith(ELECTRONIC_RECORD_NAME)); assertTrue(recordWithContent.getIsFile()); @@ -234,7 +179,6 @@ public class ReadRecordTests extends BaseRestTest 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 @@ -442,5 +386,70 @@ public class ReadRecordTests extends BaseRestTest } ); } + + /** + * Given a record + * When I try to read the children + * Then I receive error + */ + @Test + public void readChildrenOnRecordsString() throws Exception + { + String RELATIVE_PATH = "CATEGORY" + getRandomAlphanumeric() + "/FOLDER"; + FilePlanComponent electRecord = FilePlanComponent.builder() + .name(ELECTRONIC_RECORD_NAME) + .nodeType(CONTENT_TYPE.toString()) + .content(FilePlanComponentContent.builder().mimeType("text/plain").build()) + .build(); + FilePlanComponent nonElectronic = FilePlanComponent.builder() + .properties(FilePlanComponentProperties.builder() + .description(NONELECTRONIC_RECORD_NAME) + .title("Title") + .build()) + .name(NONELECTRONIC_RECORD_NAME) + .nodeType(NON_ELECTRONIC_RECORD_TYPE.toString()) + .build(); + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + //create records in Unfiled Container + FilePlanComponent recordElecInUnfiled = filePlanComponentAPI.createFilePlanComponent(electRecord, UNFILED_RECORDS_CONTAINER_ALIAS.toString()); + FilePlanComponent recordNonElecInUnfiled = filePlanComponentAPI.createFilePlanComponent(nonElectronic, UNFILED_RECORDS_CONTAINER_ALIAS.toString()); + + // List children for the electronic Record + filePlanComponentAPI.withParams("where=(isFile=true)").listChildComponents(recordElecInUnfiled.getId()) + //check the list returned is empty + .assertThat().entriesListIsEmpty().assertThat().paginationExist(); + // Check status code + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); + + // List children for the nonElectronic Record + filePlanComponentAPI.withParams("where=(isFile=true)").listChildComponents(recordNonElecInUnfiled.getId()) + //check the list returned is empty + .assertThat().entriesListIsEmpty().assertThat().paginationExist(); + // Check status code + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); + + //Update the Records objects + electRecord.setRelativePath(RELATIVE_PATH); + nonElectronic.setRelativePath(RELATIVE_PATH); + + //create records in Unfiled Container + FilePlanComponent recordElecFromRecordFolder = filePlanComponentAPI.createFilePlanComponent(electRecord, FILE_PLAN_ALIAS.toString()); + FilePlanComponent recordNonElecFromRecordFolder = filePlanComponentAPI.createFilePlanComponent(nonElectronic, FILE_PLAN_ALIAS.toString()); + + // List children for the electronic Record + filePlanComponentAPI.withParams("where=(isFile=true)").listChildComponents(recordElecFromRecordFolder.getId()) + //check the list returned is empty + .assertThat().entriesListIsEmpty().assertThat().paginationExist(); + // Check status code + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); + + // List children for the nonElectronic Record + filePlanComponentAPI.withParams("where=(isFile=true)").listChildComponents(recordNonElecFromRecordFolder.getId()) + //check the list returned is empty + .assertThat().entriesListIsEmpty().assertThat().paginationExist(); + // Check status code + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); + } } From ea95a02baa29abc3d271429415abdea202fcda56 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Tue, 3 Jan 2017 20:35:48 +0200 Subject: [PATCH 6/8] update tests according to the latest changes --- .../alfresco/rest/core/RestAPIFactory.java | 11 ++ .../igCoreAPI/FilePlanComponentAPI.java | 30 +++- .../requests/{ => igCoreAPI}/RecordsAPI.java | 26 ++- .../requests/igCoreAPI/RestIGCoreAPI.java | 10 ++ .../rm/community/base/BaseRMRestTest.java | 7 +- .../fileplancomponents/ReadRecordTests.java | 155 ++++++++---------- 6 files changed, 137 insertions(+), 102 deletions(-) rename rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/{ => igCoreAPI}/RecordsAPI.java (82%) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java index 99ff7b30ab..b899a1306a 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java @@ -28,6 +28,7 @@ package org.alfresco.rest.core; import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.RMSiteAPI; +import org.alfresco.rest.rm.community.requests.igCoreAPI.RecordsAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.RestIGCoreAPI; import org.alfresco.utility.data.DataUser; import org.alfresco.utility.model.UserModel; @@ -84,4 +85,14 @@ public class RestAPIFactory { return getRestIGCoreAPI(userModel).usingFilePlanComponents(); } + + public RecordsAPI getRecordsAPI() + { + return getRestIGCoreAPI(null).usingRecords(); + } + + public RecordsAPI getRecordsAPI(UserModel userModel) + { + return getRestIGCoreAPI(userModel).usingRecords(); + } } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/FilePlanComponentAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/FilePlanComponentAPI.java index 2bc7350088..e0ee81edfd 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/FilePlanComponentAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/FilePlanComponentAPI.java @@ -138,8 +138,31 @@ public class FilePlanComponentAPI extends RMModelRequest return getRMRestWrapper().processModels(FilePlanComponentsCollection.class, simpleRequest( GET, - "fileplan-components/{fileplanComponentId}/children?{parameters}", - filePlanComponentId, getParameters() + "fileplan-components/{fileplanComponentId}/children", + filePlanComponentId + )); + } + + /** + * List child components of a file plan component + * @param parameters The URL parameters to add + * @param filePlanComponentId The id of the file plan component of which to get child components + * @return The {@link FilePlanComponent} for the given file plan component id + * @throws Exception for the following cases: + *
    + *
  • {@code fileplanComponentId} is not a valid format
  • + *
  • authentication fails
  • + *
  • {@code fileplanComponentId} does not exist
  • + *
+ */ + public FilePlanComponentsCollection listChildComponents(String filePlanComponentId, String parameters) throws Exception + { + mandatoryString("filePlanComponentId", filePlanComponentId); + + return getRMRestWrapper().processModels(FilePlanComponentsCollection.class, simpleRequest( + GET, + "fileplan-components/{fileplanComponentId}/children?{parameters}", + filePlanComponentId,parameters )); } @@ -248,6 +271,7 @@ public class FilePlanComponentAPI extends RMModelRequest } builder.addMultiPart("filedata", recordContent, ContentType.BINARY.name()); + /* * Upload the file using RestAssured library. */ Response response = given() @@ -288,7 +312,7 @@ public class FilePlanComponentAPI extends RMModelRequest /** * Updates a file plan component * - * @param filePlanComponentModel The properties to be updated + * @param filePlanComponent The properties to be updated * @param parameters The URL parameters to add * @param filePlanComponentId The id of the file plan component which will be updated * @param returns The updated {@link FilePlanComponent} 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/igCoreAPI/RecordsAPI.java similarity index 82% rename from rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/RecordsAPI.java rename to rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/RecordsAPI.java index 6843494674..07d2b5a099 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/igCoreAPI/RecordsAPI.java @@ -24,7 +24,7 @@ * along with Alfresco. If not, see . * #L% */ -package org.alfresco.rest.rm.community.requests; +package org.alfresco.rest.rm.community.requests.igCoreAPI; import static com.jayway.restassured.RestAssured.given; @@ -32,9 +32,10 @@ import static org.alfresco.rest.rm.community.util.ParameterCheck.mandatoryString import com.jayway.restassured.response.Response; -import org.alfresco.rest.core.RestAPI; +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; @@ -47,8 +48,16 @@ import org.springframework.stereotype.Component; */ @Component @Scope (value = "prototype") -public class RecordsAPI extends RestAPI +public class RecordsAPI extends RMModelRequest { + /** + * @param rmRestWrapper + */ + public RecordsAPI(RMRestWrapper rmRestWrapper) + { + super(rmRestWrapper); + } + /** * Get the content for the electronic record * @@ -65,13 +74,12 @@ public class RecordsAPI extends RestAPI public T getRecordContentText(String recordId) throws Exception { mandatoryString("recordId", recordId); - Response response = given().auth().basic(usingRestWrapper().getTestUser().getUsername(), usingRestWrapper().getTestUser().getPassword()) - .get("records/{recordId}/content?{parameters}", recordId, getParameters()) + Response response = given().auth().basic(getRMRestWrapper().getTestUser().getUsername(), getRMRestWrapper().getTestUser().getPassword()) + .get("records/{recordId}/content", recordId) .andReturn(); - usingRestWrapper().setStatusCode(Integer.toString(response.getStatusCode())); + getRMRestWrapper().setStatusCode(Integer.toString(response.getStatusCode())); - LOG.info("The record content is " + response.getBody().prettyPrint()); return (T) response.getBody().prettyPrint(); } @@ -91,7 +99,7 @@ public class RecordsAPI extends RestAPI public RestHtmlResponse getRecordContent(String recordId) throws Exception { mandatoryString("recordId", recordId); - RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "records/{recordId}/content?{parameters}", recordId, getParameters()); - return usingRestWrapper().processHtmlResponse(request); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "records/{recordId}/content", recordId); + return getRMRestWrapper().processHtmlResponse(request); } } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/RestIGCoreAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/RestIGCoreAPI.java index 336933e39a..e582d9a8a0 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/RestIGCoreAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/RestIGCoreAPI.java @@ -77,4 +77,14 @@ public class RestIGCoreAPI extends RMModelRequest { return new FilePlanComponentAPI(getRMRestWrapper()); } + + /** + * Provides DSL on all REST calls under records/... API path + * + * @return {@link FilePlanComponentAPI} + */ + public RecordsAPI usingRecords() + { + return new RecordsAPI(getRMRestWrapper()); + } } 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 a5e4b1825d..efa0586622 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 @@ -39,6 +39,11 @@ import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.OK; +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; @@ -332,7 +337,7 @@ public class BaseRMRestTest extends RestTest * @param name file name * @return {@link File} file */ - public static File createTempFile(final String name,String content) + public static File createTempFile(final String name, String content) { try { 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 f9882804e1..ac53d2b4cb 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 @@ -47,17 +47,12 @@ import static org.testng.AssertJUnit.assertTrue; import java.util.ArrayList; import java.util.NoSuchElementException; -import org.alfresco.rest.core.RestWrapper; -import org.alfresco.rest.rm.community.base.BaseRestTest; +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; 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.FilePlanComponentsCollection; -import org.alfresco.rest.rm.community.requests.FilePlanComponentAPI; -import org.alfresco.rest.rm.community.requests.RecordsAPI; -import org.alfresco.utility.data.DataUser; -import org.springframework.beans.factory.annotation.Autowired; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -68,16 +63,8 @@ import org.testng.annotations.Test; * @author Rodica Sutu * @since 2.6 */ -public class ReadRecordTests extends BaseRestTest +public class ReadRecordTests extends BaseRMRestTest { - @Autowired - private FilePlanComponentAPI filePlanComponentAPI; - @Autowired - private RecordsAPI recordsAPI; - - @Autowired - private DataUser dataUser; - String CATEGORY_NAME=TestData.CATEGORY_NAME +getRandomAlphanumeric(); String ELECTRONIC_RECORD_NAME = "Record electronic" + getRandomAlphanumeric(); @@ -107,10 +94,10 @@ public class ReadRecordTests extends BaseRestTest public Object[][] getInvalidContainersForRecords() throws Exception { return new Object[][] { - { FILE_PLAN_ALIAS.toString() }, - { TRANSFERS_ALIAS.toString() }, - { HOLDS_ALIAS.toString() }, - { createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY_NAME).getId()} + { FILE_PLAN_ALIAS }, + { TRANSFERS_ALIAS }, + { HOLDS_ALIAS }, + { createCategoryFolderInFilePlan().getParentId()} }; } @Test @@ -121,33 +108,33 @@ public class ReadRecordTests extends BaseRestTest public void readRecordsFromInvalidContainers(String container) throws Exception { - filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - FilePlanComponent electronicRecord = FilePlanComponent.builder() .name(ELECTRONIC_RECORD_NAME) .nodeType(CONTENT_TYPE.toString()) .content(FilePlanComponentContent.builder().mimeType("text/plain").build()) .build(); - FilePlanComponent nonelectronicRecord= FilePlanComponent.builder() - .properties(FilePlanComponentProperties.builder() - .description("Description") - .title("Title") - .build()) - .name(NONELECTRONIC_RECORD_NAME) - .nodeType(NON_ELECTRONIC_RECORD_TYPE.toString()) - .build(); + FilePlanComponent nonelectronicRecord = FilePlanComponent.builder() + .properties(FilePlanComponentProperties.builder() + .description("Description") + .title("Title") + .build()) + .name(NONELECTRONIC_RECORD_NAME) + .nodeType(NON_ELECTRONIC_RECORD_TYPE.toString()) + .build(); //create records - filePlanComponentAPI.createFilePlanComponent(electronicRecord,container); - filePlanComponentAPI.createFilePlanComponent(nonelectronicRecord, container); + getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(electronicRecord, container); + getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(nonelectronicRecord, container); + // List children from API - filePlanComponentAPI.withParams("where=(isFile=true)").listChildComponents(container) - //check the list returned is empty - .assertThat().entriesListIsEmpty().assertThat().paginationExist(); - // Check status code - filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); + getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(container, "where=(isFile=true)") + .assertThat()//check the list returned is empty + .entriesListIsEmpty().assertThat().paginationExist(); + //check response status code + assertStatusCode(OK); } + /** * Given a record * When I try to read the meta-data @@ -157,18 +144,17 @@ public class ReadRecordTests extends BaseRestTest public void readRecordMetadata() throws Exception { String RELATIVE_PATH = "/" + CATEGORY_NAME + getRandomAlphanumeric() + "/folder"; - filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - //create the containers from the relativePath + //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(); + String folderId = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(recordFolder, FILE_PLAN_ALIAS.toString()).getId(); //create electronic record - String recordWithContentId = filePlanComponentAPI.createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), folderId).getId(); + String recordWithContentId = getRestAPIFactory().getFilePlanComponentsAPI().createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), folderId).getId(); //Get the record created - FilePlanComponent recordWithContent=filePlanComponentAPI.withParams("include = "+ IS_COMPLETED).getFilePlanComponent(recordWithContentId); + FilePlanComponent recordWithContent=getRestAPIFactory().getFilePlanComponentsAPI().getFilePlanComponent(recordWithContentId, "include = "+IS_COMPLETED); //Check the metadata returned assertTrue(recordWithContent.getName().startsWith(ELECTRONIC_RECORD_NAME)); assertTrue(recordWithContent.getIsFile()); @@ -179,12 +165,12 @@ public class ReadRecordTests extends BaseRestTest assertNotNull(recordWithContent.getContent().getEncoding()); assertNotNull(recordWithContent.getContent().getMimeType()); assertNotNull(recordWithContent.getAspectNames()); - filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); + assertStatusCode(OK); //create non-electronic record - String nonElectronicRecordId = filePlanComponentAPI.createFilePlanComponent(nonelectronicRecord, folderId).getId(); + String nonElectronicRecordId = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(nonelectronicRecord, folderId).getId(); //Get the record created - FilePlanComponent nonElectronicRecord = filePlanComponentAPI.withParams("include = " + IS_COMPLETED).getFilePlanComponent(nonElectronicRecordId); + FilePlanComponent nonElectronicRecord = getRestAPIFactory().getFilePlanComponentsAPI().getFilePlanComponent(nonElectronicRecordId, "include = " + IS_COMPLETED); //Check the metadata returned assertTrue(nonElectronicRecord.getName().startsWith(NONELECTRONIC_RECORD_NAME)); @@ -197,7 +183,7 @@ public class ReadRecordTests extends BaseRestTest assertNotNull(nonElectronicRecord.getContent().getMimeType()); assertNotNull(nonElectronicRecord.getAspectNames()); assertEquals(nonElectronicRecord.getProperties().getDescription(), NONELECTRONIC_RECORD_NAME); - filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); + assertStatusCode(OK); } /** @@ -208,36 +194,33 @@ public class ReadRecordTests extends BaseRestTest @Test public void readRecordContent() throws Exception { - String RECORD_ELECTRONIC= "Record " + getRandomAlphanumeric(); - String RELATIVE_PATH="/"+CATEGORY_NAME+ getRandomAlphanumeric()+"/folder"; - filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + String RECORD_ELECTRONIC = "Record " + getRandomAlphanumeric(); + String RELATIVE_PATH = "/"+CATEGORY_NAME+ getRandomAlphanumeric()+"/folder"; //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(); + String folderId = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(recordFolder,FILE_PLAN_ALIAS.toString()).getId(); // FilePlanComponent record = FilePlanComponent.builder() .name(RECORD_ELECTRONIC) .nodeType(CONTENT_TYPE.toString()) .build(); - String recordId =filePlanComponentAPI.createElectronicRecord(record, createTempFile(RECORD_ELECTRONIC, RECORD_ELECTRONIC), folderId).getId(); + String recordId = getRestAPIFactory().getFilePlanComponentsAPI().createElectronicRecord(record, createTempFile(RECORD_ELECTRONIC, RECORD_ELECTRONIC), folderId).getId(); - recordsAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - - assertEquals(recordsAPI.getRecordContentText(recordId),RECORD_ELECTRONIC); + assertEquals(getRestAPIFactory().getRecordsAPI().getRecordContentText(recordId),RECORD_ELECTRONIC); // Check status code - recordsAPI.usingRestWrapper().assertStatusCodeIs(OK); + assertStatusCode(OK); FilePlanComponent recordNoContent = FilePlanComponent.builder() .name(RECORD_ELECTRONIC) .nodeType(CONTENT_TYPE.toString()) .build(); - String recordNoContentId=filePlanComponentAPI.createFilePlanComponent(recordNoContent,folderId).getId(); - assertTrue(recordsAPI.getRecordContentText(recordNoContentId).toString().isEmpty()); - recordsAPI.usingRestWrapper().assertStatusCodeIs(OK); + String recordNoContentId = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(recordNoContent,folderId).getId(); + assertTrue(getRestAPIFactory().getRecordsAPI().getRecordContentText(recordNoContentId).toString().isEmpty()); + assertStatusCode(OK); } /** * Given a non-electronic record @@ -254,12 +237,12 @@ public class ReadRecordTests extends BaseRestTest .nodeType(NON_ELECTRONIC_RECORD_TYPE.toString()) .relativePath("/"+CATEGORY_NAME+getRandomAlphanumeric()+"/"+FOLDER_NAME) .build(); - filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - String nonElectronicRecord=filePlanComponentAPI.createFilePlanComponent(record,FILE_PLAN_ALIAS.toString()).getId(); - recordsAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - assertTrue(recordsAPI.getRecordContentText(nonElectronicRecord).toString().isEmpty()); - recordsAPI.usingRestWrapper().assertStatusCodeIs(OK); + String nonElectronicRecord= getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(record,FILE_PLAN_ALIAS.toString()).getId(); + + + assertTrue(getRestAPIFactory().getRecordsAPI().getRecordContentText(nonElectronicRecord).toString().isEmpty()); + assertStatusCode(OK); } @@ -276,9 +259,8 @@ public class ReadRecordTests extends BaseRestTest ) public void readContentFromInvalidContainers(String container) throws Exception { - recordsAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - recordsAPI.getRecordContentText(container).toString(); - recordsAPI.usingRestWrapper().assertStatusCodeIs(BAD_REQUEST); + getRestAPIFactory().getRecordsAPI().getRecordContentText(container).toString(); + assertStatusCode(BAD_REQUEST); } /** @@ -293,7 +275,7 @@ public class ReadRecordTests extends BaseRestTest { return new Object[][] { // an arbitrary record folder - { createCategoryFolderInFilePlan(dataUser.getAdminUser(), FILE_PLAN_ALIAS.toString()).getId() }, + { createCategoryFolderInFilePlan().getId()}, // an arbitrary unfiled records folder { createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), "Unfiled Folder " + getRandomAlphanumeric()).getId() } }; @@ -308,7 +290,6 @@ public class ReadRecordTests extends BaseRestTest { final int NUMBER_OF_RECORDS = 5; //String RELATIVE_PATH = "/" + CATEGORY_NAME + getRandomAlphanumeric(); - filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); // Create Electronic Records ArrayList children = new ArrayList(); @@ -320,7 +301,7 @@ public class ReadRecordTests extends BaseRestTest .nodeType(CONTENT_TYPE.toString()) .build(); //create a child - FilePlanComponent child = filePlanComponentAPI.createElectronicRecord(record, createTempFile(ELECTRONIC_RECORD_NAME + i, ELECTRONIC_RECORD_NAME + i ), containerId); + FilePlanComponent child = getRestAPIFactory().getFilePlanComponentsAPI().createElectronicRecord(record, createTempFile(ELECTRONIC_RECORD_NAME + i, ELECTRONIC_RECORD_NAME + i ), containerId); children.add(child); } //Create NonElectronicRecords @@ -335,24 +316,22 @@ public class ReadRecordTests extends BaseRestTest .nodeType(NON_ELECTRONIC_RECORD_TYPE.toString()) .build(); //create records - FilePlanComponent child=filePlanComponentAPI.createFilePlanComponent(nonelectronicRecord, containerId); + FilePlanComponent child= getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(nonelectronicRecord, containerId); children.add(child); } - // Authenticate with admin user - RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); // List children from API FilePlanComponentsCollection apiChildren = - (FilePlanComponentsCollection) filePlanComponentAPI.listChildComponents(containerId).assertThat().entriesListIsNotEmpty(); + (FilePlanComponentsCollection) getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(containerId).assertThat().entriesListIsNotEmpty(); // Check status code - restWrapper.assertStatusCodeIs(OK); + assertStatusCode(OK); // Check listed children against created list apiChildren.getEntries().forEach(c -> { - FilePlanComponent filePlanComponent = c.getFilePlanComponent(); + FilePlanComponent filePlanComponent = c.getFilePlanComponentModel(); assertNotNull(filePlanComponent.getId()); logger.info("Checking child " + filePlanComponent.getId()); @@ -365,7 +344,7 @@ public class ReadRecordTests extends BaseRestTest .get(); // Created by - assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername()); + assertEquals(filePlanComponent.getCreatedByUser().getId(), getAdminUser().getUsername()); // Is parent Id set correctly assertEquals(filePlanComponent.getParentId(), containerId); @@ -409,47 +388,45 @@ public class ReadRecordTests extends BaseRestTest .name(NONELECTRONIC_RECORD_NAME) .nodeType(NON_ELECTRONIC_RECORD_TYPE.toString()) .build(); - filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); //create records in Unfiled Container - FilePlanComponent recordElecInUnfiled = filePlanComponentAPI.createFilePlanComponent(electRecord, UNFILED_RECORDS_CONTAINER_ALIAS.toString()); - FilePlanComponent recordNonElecInUnfiled = filePlanComponentAPI.createFilePlanComponent(nonElectronic, UNFILED_RECORDS_CONTAINER_ALIAS.toString()); + FilePlanComponent recordElecInUnfiled = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(electRecord, UNFILED_RECORDS_CONTAINER_ALIAS.toString()); + FilePlanComponent recordNonElecInUnfiled = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(nonElectronic, UNFILED_RECORDS_CONTAINER_ALIAS.toString()); // List children for the electronic Record - filePlanComponentAPI.withParams("where=(isFile=true)").listChildComponents(recordElecInUnfiled.getId()) + getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(recordElecInUnfiled.getId(), "where=(isFile=true)") //check the list returned is empty .assertThat().entriesListIsEmpty().assertThat().paginationExist(); // Check status code - filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); + assertStatusCode(OK); // List children for the nonElectronic Record - filePlanComponentAPI.withParams("where=(isFile=true)").listChildComponents(recordNonElecInUnfiled.getId()) + getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(recordNonElecInUnfiled.getId(), "where=(isFile=true)") //check the list returned is empty .assertThat().entriesListIsEmpty().assertThat().paginationExist(); // Check status code - filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); + assertStatusCode(OK); //Update the Records objects electRecord.setRelativePath(RELATIVE_PATH); nonElectronic.setRelativePath(RELATIVE_PATH); //create records in Unfiled Container - FilePlanComponent recordElecFromRecordFolder = filePlanComponentAPI.createFilePlanComponent(electRecord, FILE_PLAN_ALIAS.toString()); - FilePlanComponent recordNonElecFromRecordFolder = filePlanComponentAPI.createFilePlanComponent(nonElectronic, FILE_PLAN_ALIAS.toString()); + FilePlanComponent recordElecFromRecordFolder = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(electRecord, FILE_PLAN_ALIAS.toString()); + FilePlanComponent recordNonElecFromRecordFolder = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(nonElectronic, FILE_PLAN_ALIAS.toString()); // List children for the electronic Record - filePlanComponentAPI.withParams("where=(isFile=true)").listChildComponents(recordElecFromRecordFolder.getId()) + getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(recordElecFromRecordFolder.getId(), "where=(isFile=true)") //check the list returned is empty .assertThat().entriesListIsEmpty().assertThat().paginationExist(); // Check status code - filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); + assertStatusCode(OK); // List children for the nonElectronic Record - filePlanComponentAPI.withParams("where=(isFile=true)").listChildComponents(recordNonElecFromRecordFolder.getId()) + getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(recordNonElecFromRecordFolder.getId(), "where=(isFile=true)") //check the list returned is empty .assertThat().entriesListIsEmpty().assertThat().paginationExist(); // Check status code - filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); + assertStatusCode(OK); } - } From f46e98160c16c7a9320a7dfc12e6289731415916 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Wed, 4 Jan 2017 08:40:49 +0200 Subject: [PATCH 7/8] minor updates --- .../rm/community/fileplancomponents/ReadRecordTests.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 ac53d2b4cb..f1dba007c5 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 @@ -289,7 +289,6 @@ public class ReadRecordTests extends BaseRMRestTest public void readRecordsFromFolders(String containerId) throws Exception { final int NUMBER_OF_RECORDS = 5; - //String RELATIVE_PATH = "/" + CATEGORY_NAME + getRandomAlphanumeric(); // Create Electronic Records ArrayList children = new ArrayList(); @@ -316,7 +315,7 @@ public class ReadRecordTests extends BaseRMRestTest .nodeType(NON_ELECTRONIC_RECORD_TYPE.toString()) .build(); //create records - FilePlanComponent child= getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(nonelectronicRecord, containerId); + FilePlanComponent child = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(nonelectronicRecord, containerId); children.add(child); } @@ -372,7 +371,7 @@ public class ReadRecordTests extends BaseRMRestTest * Then I receive error */ @Test - public void readChildrenOnRecordsString() throws Exception + public void readChildrenOnRecords() throws Exception { String RELATIVE_PATH = "CATEGORY" + getRandomAlphanumeric() + "/FOLDER"; FilePlanComponent electRecord = FilePlanComponent.builder() From 9c8f230793b1d5355c471d8e33a5b202b5307b27 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Wed, 4 Jan 2017 09:21:59 +0200 Subject: [PATCH 8/8] revert some unintended changes --- .../rm/community/requests/igCoreAPI/FilePlanComponentAPI.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/FilePlanComponentAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/FilePlanComponentAPI.java index e0ee81edfd..cdd8530dc1 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/FilePlanComponentAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/igCoreAPI/FilePlanComponentAPI.java @@ -271,7 +271,9 @@ public class FilePlanComponentAPI extends RMModelRequest } builder.addMultiPart("filedata", recordContent, ContentType.BINARY.name()); + /* + * RestWrapper adds some headers which break multipart/form-data uploads and also assumes json POST requests. * Upload the file using RestAssured library. */ Response response = given()