From 65dd4787c2103ca20488d1a313bb5cbb0deb5943 Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Tue, 18 Oct 2016 09:58:41 +0100 Subject: [PATCH 01/49] first commit --- README | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000000..e69de29bb2 From 182ab80190fbcec6b0abc4ba48a14931fb92c1f5 Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Tue, 18 Oct 2016 10:02:00 +0100 Subject: [PATCH 02/49] Added some tests to compare TAS with RestAssured used directly. --- .gitignore | 4 + pom.xml | 61 +++++++ .../model/RestFilePlanComponentModel.java | 161 ++++++++++++++++++ .../requests/RestFilePlanComponentApi.java | 38 +++++ .../FilePlanComponentsTest.java | 155 +++++++++++++++++ .../FilePlanComponentsTest.java | 65 +++++++ 6 files changed, 484 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/org/alfresco/rest/model/RestFilePlanComponentModel.java create mode 100644 src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java create mode 100644 src/test/java/org/alfresco/rest/api/fileplancomponents/FilePlanComponentsTest.java create mode 100644 src/test/java/org/alfresco/rest/fileplancomponents/FilePlanComponentsTest.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..a05b0a82e1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/target/ +/.settings/ +.classpath +.project \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000000..b232aa797a --- /dev/null +++ b/pom.xml @@ -0,0 +1,61 @@ + + + + 4.0.0 + org.alfresco + alfresco-rm-rest-automation + 1.0.0-SNAPSHOT + Alfresco Records Management REST Automation + + + 1.8 + 1.8 + + + + + junit + junit + 4.12 + test + + + io.rest-assured + rest-assured + 3.0.1 + test + + + org.hamcrest + hamcrest-all + 1.3 + test + + + com.google.code.gson + gson + 2.7 + test + + + com.google.guava + guava + 19.0 + test + + + + + org.alfresco.tas + restapi-test + 1.0-SNAPSHOT + + + org.alfresco.tas + restapi-test + 1.0-SNAPSHOT + test-jar + test + + + diff --git a/src/main/java/org/alfresco/rest/model/RestFilePlanComponentModel.java b/src/main/java/org/alfresco/rest/model/RestFilePlanComponentModel.java new file mode 100644 index 0000000000..c15bf8116b --- /dev/null +++ b/src/main/java/org/alfresco/rest/model/RestFilePlanComponentModel.java @@ -0,0 +1,161 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.rest.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +/** + * FIXME: Document me :) + * + * @author Tuna Aksoy + * @since 1.0 + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class RestFilePlanComponentModel +{ + private String id; + private String parentId; + private String name; + private String nodeType; + private boolean isCategory; + private boolean isRecordFolder; + private boolean isFile; + private boolean hasRetentionSchedule; + + /** + * @return the id + */ + public String getId() + { + return this.id; + } + + /** + * @param id the id to set + */ + public void setId(String id) + { + this.id = id; + } + + /** + * @return the parentId + */ + public String getParentId() + { + return this.parentId; + } + + /** + * @param parentId the parentId to set + */ + public void setParentId(String parentId) + { + this.parentId = parentId; + } + + /** + * @return the name + */ + public String getName() + { + return this.name; + } + + /** + * @param name the name to set + */ + public void setName(String name) + { + this.name = name; + } + + /** + * @return the nodeType + */ + public String getNodeType() + { + return this.nodeType; + } + + /** + * @param nodeType the nodeType to set + */ + public void setNodeType(String nodeType) + { + this.nodeType = nodeType; + } + + /** + * @return the isCategory + */ + public boolean isIsCategory() + { + return this.isCategory; + } + + /** + * @param isCategory the isCategory to set + */ + public void setCategory(boolean isCategory) + { + this.isCategory = isCategory; + } + + /** + * @return the isRecordFolder + */ + public boolean isIsRecordFolder() + { + return this.isRecordFolder; + } + + /** + * @param isRecordFolder the isRecordFolder to set + */ + public void setRecordFolder(boolean isRecordFolder) + { + this.isRecordFolder = isRecordFolder; + } + + /** + * @return the isFile + */ + public boolean isIsFile() + { + return this.isFile; + } + + /** + * @param isFile the isFile to set + */ + public void setFile(boolean isFile) + { + this.isFile = isFile; + } + + /** + * @return the hasRetentionSchedule + */ + public boolean isHasRetentionSchedule() + { + return this.hasRetentionSchedule; + } + + /** + * @param hasRetentionSchedule the hasRetentionSchedule to set + */ + public void setHasRetentionSchedule(boolean hasRetentionSchedule) + { + this.hasRetentionSchedule = hasRetentionSchedule; + } +} diff --git a/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java b/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java new file mode 100644 index 0000000000..a5eaccea61 --- /dev/null +++ b/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java @@ -0,0 +1,38 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.rest.requests; + +import static org.alfresco.rest.core.RestRequest.simpleRequest; +import static org.springframework.http.HttpMethod.GET; + +import org.alfresco.rest.core.RestAPI; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestFilePlanComponentModel; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +/** + * FIXME: Document me :) + * + * @author Tuna Aksoy + * @since 1.0 + */ +@Component +@Scope(value = "prototype") +public class RestFilePlanComponentApi extends RestAPI +{ + public RestFilePlanComponentModel getFilePlanComponent(String filePlanComponentId) throws Exception + { + RestRequest request = simpleRequest(GET, "fileplan-components/{fileplanComponentId}", filePlanComponentId); + return usingRestWrapper().processModel(RestFilePlanComponentModel.class, request); + } +} diff --git a/src/test/java/org/alfresco/rest/api/fileplancomponents/FilePlanComponentsTest.java b/src/test/java/org/alfresco/rest/api/fileplancomponents/FilePlanComponentsTest.java new file mode 100644 index 0000000000..4de6262bc5 --- /dev/null +++ b/src/test/java/org/alfresco/rest/api/fileplancomponents/FilePlanComponentsTest.java @@ -0,0 +1,155 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.rest.api.fileplancomponents; + +import static io.restassured.RestAssured.authentication; +import static io.restassured.RestAssured.basePath; +import static io.restassured.RestAssured.baseURI; +import static io.restassured.RestAssured.basic; +import static io.restassured.RestAssured.enableLoggingOfRequestAndResponseIfValidationFails; +import static io.restassured.RestAssured.given; +import static io.restassured.RestAssured.port; + +import static java.util.UUID.randomUUID; + +import static com.google.common.collect.ImmutableMap.builder; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.is; + +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * FIXME: Document me :) + * + * @author Tuna Aksoy + * @since 1.0 + */ +public class FilePlanComponentsTest +{ + private static final String CONTENT_TYPE_KEY = "content-type"; + private static final String CONTENT_TYPE_VALUE = "application/json;charset=UTF-8"; + + /** + * FIXME: Document me :) + * FIXME: Create a base class and move this method, extract to properties to a file, etc. etc. + * + * @throws java.lang.Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception + { + baseURI = "http://localhost"; + port = 8090; + basePath = "/alfresco/api/-default-/public/ig/versions/1"; + authentication = basic("admin", "admin"); + enableLoggingOfRequestAndResponseIfValidationFails(); + } + + @Test + public void testfilePlanComponentsGet() + { + given(). + when(). + get("/fileplan-components/-filePlan-"). + then(). + statusCode(200). + header(CONTENT_TYPE_KEY, CONTENT_TYPE_VALUE). + root("entry"). + body("isFile", is(false)). + body("nodeType", equalTo("rma:filePlan")). + body("aspectNames", hasItems("rma:recordComponentIdentifier", "rma:filePlanComponent", "rma:recordsManagementRoot")). + body("properties.\"st:componentId\"", equalTo("documentLibrary")); + + /* + given(). + expect(). + body("entry.isFile", is(false)). + body("entry.nodeType", equalTo("rma:filePlan")). + body("entry.aspectNames", hasItems("rma:recordComponentIdentifier", "rma:filePlanComponent", "rma:recordsManagementRoot")). + body("entry.properties.\"st:componentId\"", equalTo("documentLibrary")). + statusCode(200). + header(CONTENT_TYPE_KEY, CONTENT_TYPE_VALUE). + when(). + get("/fileplan-components/-filePlan-"); + + + + get("/fileplan-components/-filePlan-"). + then(). + assertThat(). + statusCode(200). + header(CONTENT_TYPE_KEY, CONTENT_TYPE_VALUE). + body("entry.isFile", is(false)). + body("entry.nodeType", equalTo("rma:filePlan")). + body("entry.aspectNames", hasItems("rma:recordComponentIdentifier", "rma:filePlanComponent", "rma:recordsManagementRoot")). + body("entry.properties.\"st:componentId\"", equalTo("documentLibrary")); + + + + given(). + when(). + get("/fileplan-components/-filePlan-"). + then(). + statusCode(200). + header(CONTENT_TYPE_KEY, CONTENT_TYPE_VALUE). + body("entry.isFile", is(false)). + body("entry.nodeType", equalTo("rma:filePlan")). + body("entry.aspectNames", hasItems("rma:recordComponentIdentifier", "rma:filePlanComponent", "rma:recordsManagementRoot")). + body("entry.properties.\"st:componentId\"", equalTo("documentLibrary")); + */ + + + given(). + contentType("application/json"). + body( + builder(). + put("name", randomUUID().toString()). + put("nodeType", "rma:recordCategory"). + build()). + when(). + post("/fileplan-components/-filePlan-/children"). + then(). + statusCode(201). + header(CONTENT_TYPE_KEY, CONTENT_TYPE_VALUE); + + + /* + given(). + contentType("application/json"). + body("{\"name\":\"" + randomUUID().toString() + "\",\"nodeType\":\"rma:recordCategory\"}"). + when(). + post("/fileplan-components/-filePlan-/children"). + then(). + statusCode(201). + header(CONTENT_TYPE_KEY, CONTENT_TYPE_VALUE); + + + + Map category = new HashMap<>(); + category.put("name", randomUUID().toString()); + category.put("nodeType", "rma:recordCategory"); + + given(). + contentType("application/json"). + body(category). + when(). + post("/fileplan-components/-filePlan-/children"). + then(). + //log().ifValidationFails(). + statusCode(201). + header(CONTENT_TYPE_KEY, CONTENT_TYPE_VALUE); + */ + } +} diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanComponentsTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanComponentsTest.java new file mode 100644 index 0000000000..79227e59f9 --- /dev/null +++ b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanComponentsTest.java @@ -0,0 +1,65 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.rest.fileplancomponents; + +import static com.jayway.restassured.RestAssured.basePath; +import static com.jayway.restassured.RestAssured.baseURI; +import static com.jayway.restassured.RestAssured.port; + +import static org.springframework.http.HttpStatus.OK; +import static org.testng.Assert.assertEquals; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.RestFilePlanComponentModel; +import org.alfresco.rest.requests.RestFilePlanComponentApi; +import org.alfresco.utility.data.DataUser; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * FIXME: Document me :) + * + * @author Tuna Aksoy + * @since 1.0 + */ +public class FilePlanComponentsTest extends RestTest +{ + @Autowired + private RestFilePlanComponentApi filePlanComponentApi; + + @Autowired + private DataUser dataUser; + + /** + * @see org.alfresco.rest.RestTest#checkServerHealth() + */ + @Override + @BeforeClass(alwaysRun = true) + public void checkServerHealth() throws Exception + { + baseURI = "http://localhost"; + port = 8090; + basePath = "alfresco/api/-default-/public/ig/versions/1"; + } + + @Test + public void testfilePlanComponentsGet() throws Exception + { + RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper(); + restWrapper.authenticateUser(dataUser.getAdminUser()); + RestFilePlanComponentModel filePlanComponent = filePlanComponentApi.getFilePlanComponent("-filePlan-"); + restWrapper.assertStatusCodeIs(OK); + assertEquals(filePlanComponent.getNodeType(), "rma:filePlan"); + } +} From 073ae6f73af7643865b587787a709a099c53494b Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Thu, 20 Oct 2016 14:53:39 +0100 Subject: [PATCH 03/49] RM-4013: Skeleton Record Category model. --- .../rest/model/FileplanComponentTypes.java | 37 ++++++++++++++ .../requests/RestFilePlanComponentApi.java | 43 +++++++++++++++- .../RecordCategoryComponentsTest.java | 51 +++++++++++++++++++ .../java/org/alfresco/rest/ig/IgTest.java | 40 +++++++++++++++ 4 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/alfresco/rest/model/FileplanComponentTypes.java create mode 100644 src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryComponentsTest.java create mode 100644 src/test/java/org/alfresco/rest/ig/IgTest.java diff --git a/src/main/java/org/alfresco/rest/model/FileplanComponentTypes.java b/src/main/java/org/alfresco/rest/model/FileplanComponentTypes.java new file mode 100644 index 0000000000..f3d59c04a0 --- /dev/null +++ b/src/main/java/org/alfresco/rest/model/FileplanComponentTypes.java @@ -0,0 +1,37 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.rest.model; + +/** + * Fileplan Component Types enum + * @author Kristijan Conkas + * @since 2.6 + */ +public enum FileplanComponentTypes +{ + CATEGORY("rma:recordCategory"), + FOLDER("rma:recordFolder"), + HOLD("rma:hold"), + UNFILED_RECORD_FOLDER("rma:unfiledRecordFolder"); + + private String value; + + FileplanComponentTypes (String value) + { + this.value = value; + } + + public String toString() + { + return this.value; + } +} diff --git a/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java b/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java index a5eaccea61..cc6fa31824 100644 --- a/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java +++ b/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java @@ -12,27 +12,68 @@ package org.alfresco.rest.requests; import static org.alfresco.rest.core.RestRequest.simpleRequest; +import static org.alfresco.rest.core.RestRequest.requestWithBody; import static org.springframework.http.HttpMethod.GET; +import static org.springframework.http.HttpMethod.POST; + +import java.util.Map; import org.alfresco.rest.core.RestAPI; import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.FileplanComponentTypes; import org.alfresco.rest.model.RestFilePlanComponentModel; +import org.json.JSONObject; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; /** - * FIXME: Document me :) + * ReST wrapper for IG APIs * * @author Tuna Aksoy + * @author kconkas * @since 1.0 */ @Component @Scope(value = "prototype") public class RestFilePlanComponentApi extends RestAPI { + + /** + * Get file plan component + * @param filePlanComponentId + * @return {@link RestFilePlanComponentModel} for filePlanComponentId + * @throws Exception for non-existent components + */ public RestFilePlanComponentModel getFilePlanComponent(String filePlanComponentId) throws Exception { RestRequest request = simpleRequest(GET, "fileplan-components/{fileplanComponentId}", filePlanComponentId); return usingRestWrapper().processModel(RestFilePlanComponentModel.class, request); } + + /** + * Create child file plan component + * @param parentFilePlanComponentId + * @param componentName + * @param type + * @param properties + * @return + * @throws Exception + */ + public RestFilePlanComponentModel createFilePlanComponent(String parentFilePlanComponentId, String componentName, + FileplanComponentTypes componentType, Map properties) throws Exception + { + if (componentName == null) + throw new IllegalArgumentException("Child component name missing"); + + JSONObject body = new JSONObject(); + body.put("name", componentName); + body.put("nodeType", componentType.toString()); + if (properties != null) + { + body.put("properties", properties); + } + + RestRequest request = requestWithBody(POST, body.toString(), "fileplan-components/{fileplanComponentId}/children", parentFilePlanComponentId); + return usingRestWrapper().processModel(RestFilePlanComponentModel.class, request); + } } diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryComponentsTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryComponentsTest.java new file mode 100644 index 0000000000..47e6976d54 --- /dev/null +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryComponentsTest.java @@ -0,0 +1,51 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.rest.fileplancomponents; + +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.ig.IgTest; +import org.alfresco.rest.model.FileplanComponentTypes; +import org.alfresco.rest.model.RestFilePlanComponentModel; +import org.alfresco.rest.requests.RestFilePlanComponentApi; +import org.alfresco.utility.data.DataUser; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertTrue; +import static org.springframework.http.HttpStatus.CREATED; + +/** + * + * @author Kristijan Conkas + * @since + */ +public class RecordCategoryComponentsTest extends IgTest +{ + @Autowired + private RestFilePlanComponentApi filePlanComponentApi; + + @Autowired + private DataUser dataUser; + + @Test + public void createCategory() throws Exception + { + RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper(); + restWrapper.authenticateUser(dataUser.getAdminUser()); + RestFilePlanComponentModel filePlanComponent = + filePlanComponentApi.createFilePlanComponent("-filePlan-", "category 123", FileplanComponentTypes.CATEGORY, null); + + restWrapper.assertStatusCodeIs(CREATED); + assertTrue(filePlanComponent.isIsCategory()); + // TODO: add more verification here + } +} diff --git a/src/test/java/org/alfresco/rest/ig/IgTest.java b/src/test/java/org/alfresco/rest/ig/IgTest.java new file mode 100644 index 0000000000..c9e254a021 --- /dev/null +++ b/src/test/java/org/alfresco/rest/ig/IgTest.java @@ -0,0 +1,40 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.rest.ig; + +import static com.jayway.restassured.RestAssured.basePath; +import static com.jayway.restassured.RestAssured.baseURI; +import static com.jayway.restassured.RestAssured.port; + +import org.alfresco.rest.RestTest; +import org.testng.annotations.BeforeClass; + +/** + * Information Governance specific RestTest + * @author Kristijan Conkas + * @since 2.6 + */ +public class IgTest extends RestTest +{ + /** + * @see org.alfresco.rest.RestTest#checkServerHealth() + */ + @Override + @BeforeClass(alwaysRun = true) + public void checkServerHealth() throws Exception + { + // TODO: obtain these from property files + baseURI = "http://192.168.33.10"; + port = 8080; + basePath = "alfresco/api/-default-/public/ig/versions/1"; + } +} From 544938a9b801bd9ad69fac58f5377a2a37d7ccc7 Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Thu, 20 Oct 2016 17:02:18 +0100 Subject: [PATCH 04/49] RM-3964: CRUD happy path tests. --- ...tTypes.java => FileplanComponentType.java} | 4 +- .../requests/RestFilePlanComponentApi.java | 67 ++++++++++++++---- .../FilePlanComponentsTest.java | 21 +----- .../RecordCategoryComponentsTest.java | 69 +++++++++++++++++-- .../rest/ig/{IgTest.java => IgRestTest.java} | 6 +- 5 files changed, 125 insertions(+), 42 deletions(-) rename src/main/java/org/alfresco/rest/model/{FileplanComponentTypes.java => FileplanComponentType.java} (90%) rename src/test/java/org/alfresco/rest/ig/{IgTest.java => IgRestTest.java} (88%) diff --git a/src/main/java/org/alfresco/rest/model/FileplanComponentTypes.java b/src/main/java/org/alfresco/rest/model/FileplanComponentType.java similarity index 90% rename from src/main/java/org/alfresco/rest/model/FileplanComponentTypes.java rename to src/main/java/org/alfresco/rest/model/FileplanComponentType.java index f3d59c04a0..4428e0b5a0 100644 --- a/src/main/java/org/alfresco/rest/model/FileplanComponentTypes.java +++ b/src/main/java/org/alfresco/rest/model/FileplanComponentType.java @@ -16,7 +16,7 @@ package org.alfresco.rest.model; * @author Kristijan Conkas * @since 2.6 */ -public enum FileplanComponentTypes +public enum FileplanComponentType { CATEGORY("rma:recordCategory"), FOLDER("rma:recordFolder"), @@ -25,7 +25,7 @@ public enum FileplanComponentTypes private String value; - FileplanComponentTypes (String value) + FileplanComponentType (String value) { this.value = value; } diff --git a/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java b/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java index cc6fa31824..33737cadcb 100644 --- a/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java +++ b/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java @@ -11,16 +11,18 @@ */ package org.alfresco.rest.requests; -import static org.alfresco.rest.core.RestRequest.simpleRequest; import static org.alfresco.rest.core.RestRequest.requestWithBody; +import static org.alfresco.rest.core.RestRequest.simpleRequest; +import static org.springframework.http.HttpMethod.DELETE; import static org.springframework.http.HttpMethod.GET; import static org.springframework.http.HttpMethod.POST; +import static org.springframework.http.HttpMethod.PUT; import java.util.Map; import org.alfresco.rest.core.RestAPI; import org.alfresco.rest.core.RestRequest; -import org.alfresco.rest.model.FileplanComponentTypes; +import org.alfresco.rest.model.FileplanComponentType; import org.alfresco.rest.model.RestFilePlanComponentModel; import org.json.JSONObject; import org.springframework.context.annotation.Scope; @@ -52,15 +54,15 @@ public class RestFilePlanComponentApi extends RestAPI /** * Create child file plan component - * @param parentFilePlanComponentId - * @param componentName - * @param type - * @param properties - * @return + * @param parentFilePlanComponentId parent file plan component id + * @param componentName component name + * @param type one of {@link FilePlanComponentType} + * @param properties component type specific, refer to API reference for details + * @return {@link RestFilePlanComponentModel} for componentName * @throws Exception */ public RestFilePlanComponentModel createFilePlanComponent(String parentFilePlanComponentId, String componentName, - FileplanComponentTypes componentType, Map properties) throws Exception + FileplanComponentType componentType, Map properties) throws Exception { if (componentName == null) throw new IllegalArgumentException("Child component name missing"); @@ -68,12 +70,53 @@ public class RestFilePlanComponentApi extends RestAPI JSONObject body = new JSONObject(); body.put("name", componentName); body.put("nodeType", componentType.toString()); - if (properties != null) - { - body.put("properties", properties); - } + if (properties != null) body.put("properties", properties); RestRequest request = requestWithBody(POST, body.toString(), "fileplan-components/{fileplanComponentId}/children", parentFilePlanComponentId); return usingRestWrapper().processModel(RestFilePlanComponentModel.class, request); } + + /** + * Update file plan component + * @param filePlanComponentId + * @param requestBody update body, refer to API reference for details + * @return {@link RestFilePlanComponentModel} for filePlanComponentId + * @throws Exception + */ + public RestFilePlanComponentModel updateFilePlanComponent(String filePlanComponentId, JSONObject requestBody) throws Exception + { + RestRequest request = requestWithBody(PUT, requestBody.toString(), "fileplan-components/{fileplanComponentId}", filePlanComponentId); + return usingRestWrapper().processModel(RestFilePlanComponentModel.class, request); + } + + /** + * Rename file plan component + * @param filePlanComponentId + * @param newName + * @return + * @throws Exception + */ + public RestFilePlanComponentModel renameFilePlanComponent(String filePlanComponentId, String newName) throws Exception + { + JSONObject body = new JSONObject(); + body.put("name", newName); + + return updateFilePlanComponent(filePlanComponentId, body); + } + + /** + * Delete file plan component + * @param filePlanComponentId + * @param deletePermanently if set to true delete without moving to the trashcan + * @throws Exception + */ + public RestRequest deleteFilePlanComponent(String filePlanComponentId, boolean deletePermanently) throws Exception + { + JSONObject body = new JSONObject(); + if (deletePermanently) body.put("permanent", deletePermanently); + + RestRequest request = requestWithBody(DELETE, body.toString(), "fileplan-components/{fileplanComponentId}", filePlanComponentId); + usingRestWrapper().processEmptyModel(request); + return request; + } } diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanComponentsTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanComponentsTest.java index 79227e59f9..2a0e69a4ee 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanComponentsTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanComponentsTest.java @@ -11,20 +11,15 @@ */ package org.alfresco.rest.fileplancomponents; -import static com.jayway.restassured.RestAssured.basePath; -import static com.jayway.restassured.RestAssured.baseURI; -import static com.jayway.restassured.RestAssured.port; - import static org.springframework.http.HttpStatus.OK; import static org.testng.Assert.assertEquals; -import org.alfresco.rest.RestTest; import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.ig.IgRestTest; import org.alfresco.rest.model.RestFilePlanComponentModel; import org.alfresco.rest.requests.RestFilePlanComponentApi; import org.alfresco.utility.data.DataUser; import org.springframework.beans.factory.annotation.Autowired; -import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; /** @@ -33,7 +28,7 @@ import org.testng.annotations.Test; * @author Tuna Aksoy * @since 1.0 */ -public class FilePlanComponentsTest extends RestTest +public class FilePlanComponentsTest extends IgRestTest { @Autowired private RestFilePlanComponentApi filePlanComponentApi; @@ -41,18 +36,6 @@ public class FilePlanComponentsTest extends RestTest @Autowired private DataUser dataUser; - /** - * @see org.alfresco.rest.RestTest#checkServerHealth() - */ - @Override - @BeforeClass(alwaysRun = true) - public void checkServerHealth() throws Exception - { - baseURI = "http://localhost"; - port = 8090; - basePath = "alfresco/api/-default-/public/ig/versions/1"; - } - @Test public void testfilePlanComponentsGet() throws Exception { diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryComponentsTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryComponentsTest.java index 47e6976d54..4df726bb47 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryComponentsTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryComponentsTest.java @@ -11,24 +11,31 @@ */ package org.alfresco.rest.fileplancomponents; +import java.util.UUID; + import org.alfresco.rest.core.RestWrapper; -import org.alfresco.rest.ig.IgTest; -import org.alfresco.rest.model.FileplanComponentTypes; +import org.alfresco.rest.ig.IgRestTest; import org.alfresco.rest.model.RestFilePlanComponentModel; import org.alfresco.rest.requests.RestFilePlanComponentApi; import org.alfresco.utility.data.DataUser; import org.springframework.beans.factory.annotation.Autowired; import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; +import static org.testng.Assert.assertNotNull; +import static org.alfresco.rest.model.FileplanComponentType.CATEGORY; import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.OK; +import static org.springframework.http.HttpStatus.NO_CONTENT; + /** * * @author Kristijan Conkas * @since */ -public class RecordCategoryComponentsTest extends IgTest +public class RecordCategoryComponentsTest extends IgRestTest { @Autowired private RestFilePlanComponentApi filePlanComponentApi; @@ -36,16 +43,66 @@ public class RecordCategoryComponentsTest extends IgTest @Autowired private DataUser dataUser; + /** new category name */ + private String categoryName = "cat " + UUID.randomUUID().toString().substring(0, 8); + + private String newCategoryId = null; + @Test - public void createCategory() throws Exception + ( + description = "Create category as authorised user" + ) + public void createCategoryAsAuthorisedUser() throws Exception { + // create category RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper(); restWrapper.authenticateUser(dataUser.getAdminUser()); RestFilePlanComponentModel filePlanComponent = - filePlanComponentApi.createFilePlanComponent("-filePlan-", "category 123", FileplanComponentTypes.CATEGORY, null); + filePlanComponentApi.createFilePlanComponent("-filePlan-", categoryName, CATEGORY, null); + // verify returned object restWrapper.assertStatusCodeIs(CREATED); assertTrue(filePlanComponent.isIsCategory()); - // TODO: add more verification here + assertEquals(filePlanComponent.getName(), categoryName); + assertEquals(filePlanComponent.getNodeType(), CATEGORY.toString()); + newCategoryId = filePlanComponent.getId(); + } + + @Test + ( + description = "Rename category as authorised user", + dependsOnMethods= { "createCategoryAsAuthorisedUser" } + ) + public void renameCategoryAsAuthorisedUser() throws Exception + { + assertNotNull(newCategoryId); + String newName = "renamed " + categoryName; + + // rename + RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper(); + restWrapper.authenticateUser(dataUser.getAdminUser()); + RestFilePlanComponentModel filePlanComponent = filePlanComponentApi.renameFilePlanComponent(newCategoryId, newName); + + // verify returned object + restWrapper.assertStatusCodeIs(OK); + assertEquals(filePlanComponent.getName(), newName); + } + + @Test + ( + description = "Rename category as authorised user", + dependsOnMethods= { "renameCategoryAsAuthorisedUser" } + ) + public void deleteCategoryAsAuthorisedUser() throws Exception + { + // delete + RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper(); + restWrapper.authenticateUser(dataUser.getAdminUser()); + filePlanComponentApi.deleteFilePlanComponent(newCategoryId, true); + + // verify deletion + restWrapper.assertStatusCodeIs(NO_CONTENT); + // TODO: verify we can't get an object with this ID again + // TODO: can we verify that deletion with deletePermanently=false indeed ended up in trashcan? } } diff --git a/src/test/java/org/alfresco/rest/ig/IgTest.java b/src/test/java/org/alfresco/rest/ig/IgRestTest.java similarity index 88% rename from src/test/java/org/alfresco/rest/ig/IgTest.java rename to src/test/java/org/alfresco/rest/ig/IgRestTest.java index c9e254a021..dedba57b10 100644 --- a/src/test/java/org/alfresco/rest/ig/IgTest.java +++ b/src/test/java/org/alfresco/rest/ig/IgRestTest.java @@ -19,11 +19,11 @@ import org.alfresco.rest.RestTest; import org.testng.annotations.BeforeClass; /** - * Information Governance specific RestTest + * Information Governance RestTest implementation * @author Kristijan Conkas * @since 2.6 */ -public class IgTest extends RestTest +public class IgRestTest extends RestTest { /** * @see org.alfresco.rest.RestTest#checkServerHealth() @@ -33,7 +33,7 @@ public class IgTest extends RestTest public void checkServerHealth() throws Exception { // TODO: obtain these from property files - baseURI = "http://192.168.33.10"; + baseURI = "http://localhost"; port = 8080; basePath = "alfresco/api/-default-/public/ig/versions/1"; } From 0a228eeb4c9b0493aa53297c0ee6b9f3496a3f1a Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Thu, 20 Oct 2016 22:50:56 +0100 Subject: [PATCH 05/49] Extracted properties from code into properties file, tidied up the code. --- .gitignore | 3 +- pom.xml | 32 ---- .../rest/model/FileplanComponentType.java | 11 +- .../model/RestFilePlanComponentModel.java | 1 + .../requests/RestFilePlanComponentApi.java | 21 ++- .../org/alfresco/rest/BaseIgRestTest.java | 58 +++++++ .../FilePlanComponentsTest.java | 155 ------------------ .../FilePlanComponentsTest.java | 4 +- .../RecordCategoryComponentsTest.java | 10 +- .../java/org/alfresco/rest/ig/IgRestTest.java | 40 ----- src/test/resources/config.properties | 4 + src/test/resources/local.properties | 0 12 files changed, 88 insertions(+), 251 deletions(-) create mode 100644 src/test/java/org/alfresco/rest/BaseIgRestTest.java delete mode 100644 src/test/java/org/alfresco/rest/api/fileplancomponents/FilePlanComponentsTest.java delete mode 100644 src/test/java/org/alfresco/rest/ig/IgRestTest.java create mode 100644 src/test/resources/config.properties create mode 100644 src/test/resources/local.properties diff --git a/.gitignore b/.gitignore index a05b0a82e1..dfce60785c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /target/ /.settings/ .classpath -.project \ No newline at end of file +.project +/src/test/resources/local.properties \ No newline at end of file diff --git a/pom.xml b/pom.xml index b232aa797a..9aa1699457 100644 --- a/pom.xml +++ b/pom.xml @@ -13,38 +13,6 @@ - - junit - junit - 4.12 - test - - - io.rest-assured - rest-assured - 3.0.1 - test - - - org.hamcrest - hamcrest-all - 1.3 - test - - - com.google.code.gson - gson - 2.7 - test - - - com.google.guava - guava - 19.0 - test - - - org.alfresco.tas restapi-test diff --git a/src/main/java/org/alfresco/rest/model/FileplanComponentType.java b/src/main/java/org/alfresco/rest/model/FileplanComponentType.java index 4428e0b5a0..8572c4bc8a 100644 --- a/src/main/java/org/alfresco/rest/model/FileplanComponentType.java +++ b/src/main/java/org/alfresco/rest/model/FileplanComponentType.java @@ -13,23 +13,24 @@ package org.alfresco.rest.model; /** * Fileplan Component Types enum + * * @author Kristijan Conkas * @since 2.6 */ public enum FileplanComponentType { - CATEGORY("rma:recordCategory"), - FOLDER("rma:recordFolder"), + RECORD_CATEGORY("rma:recordCategory"), + RECORD_FOLDER("rma:recordFolder"), HOLD("rma:hold"), UNFILED_RECORD_FOLDER("rma:unfiledRecordFolder"); - + private String value; - + FileplanComponentType (String value) { this.value = value; } - + public String toString() { return this.value; diff --git a/src/main/java/org/alfresco/rest/model/RestFilePlanComponentModel.java b/src/main/java/org/alfresco/rest/model/RestFilePlanComponentModel.java index c15bf8116b..4a65d390a9 100644 --- a/src/main/java/org/alfresco/rest/model/RestFilePlanComponentModel.java +++ b/src/main/java/org/alfresco/rest/model/RestFilePlanComponentModel.java @@ -19,6 +19,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; * @author Tuna Aksoy * @since 1.0 */ +// FIXME: Once the fields have been added this annotation should be removed @JsonIgnoreProperties(ignoreUnknown = true) public class RestFilePlanComponentModel { diff --git a/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java b/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java index 33737cadcb..de3ef604b9 100644 --- a/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java +++ b/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java @@ -29,7 +29,7 @@ import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; /** - * ReST wrapper for IG APIs + * REST wrapper for IG APIs * * @author Tuna Aksoy * @author kconkas @@ -39,7 +39,6 @@ import org.springframework.stereotype.Component; @Scope(value = "prototype") public class RestFilePlanComponentApi extends RestAPI { - /** * Get file plan component * @param filePlanComponentId @@ -51,7 +50,7 @@ public class RestFilePlanComponentApi extends RestAPI RestRequest request = simpleRequest(GET, "fileplan-components/{fileplanComponentId}", filePlanComponentId); return usingRestWrapper().processModel(RestFilePlanComponentModel.class, request); } - + /** * Create child file plan component * @param parentFilePlanComponentId parent file plan component id @@ -61,21 +60,21 @@ public class RestFilePlanComponentApi extends RestAPI * @return {@link RestFilePlanComponentModel} for componentName * @throws Exception */ - public RestFilePlanComponentModel createFilePlanComponent(String parentFilePlanComponentId, String componentName, + public RestFilePlanComponentModel createFilePlanComponent(String parentFilePlanComponentId, String componentName, FileplanComponentType componentType, Map properties) throws Exception { if (componentName == null) throw new IllegalArgumentException("Child component name missing"); - + JSONObject body = new JSONObject(); body.put("name", componentName); body.put("nodeType", componentType.toString()); if (properties != null) body.put("properties", properties); - + RestRequest request = requestWithBody(POST, body.toString(), "fileplan-components/{fileplanComponentId}/children", parentFilePlanComponentId); return usingRestWrapper().processModel(RestFilePlanComponentModel.class, request); } - + /** * Update file plan component * @param filePlanComponentId @@ -88,7 +87,7 @@ public class RestFilePlanComponentApi extends RestAPI RestRequest request = requestWithBody(PUT, requestBody.toString(), "fileplan-components/{fileplanComponentId}", filePlanComponentId); return usingRestWrapper().processModel(RestFilePlanComponentModel.class, request); } - + /** * Rename file plan component * @param filePlanComponentId @@ -103,18 +102,18 @@ public class RestFilePlanComponentApi extends RestAPI return updateFilePlanComponent(filePlanComponentId, body); } - + /** * Delete file plan component * @param filePlanComponentId * @param deletePermanently if set to true delete without moving to the trashcan - * @throws Exception + * @throws Exception */ public RestRequest deleteFilePlanComponent(String filePlanComponentId, boolean deletePermanently) throws Exception { JSONObject body = new JSONObject(); if (deletePermanently) body.put("permanent", deletePermanently); - + RestRequest request = requestWithBody(DELETE, body.toString(), "fileplan-components/{fileplanComponentId}", filePlanComponentId); usingRestWrapper().processEmptyModel(request); return request; diff --git a/src/test/java/org/alfresco/rest/BaseIgRestTest.java b/src/test/java/org/alfresco/rest/BaseIgRestTest.java new file mode 100644 index 0000000000..0fa4ca5ff0 --- /dev/null +++ b/src/test/java/org/alfresco/rest/BaseIgRestTest.java @@ -0,0 +1,58 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.rest; + +import static java.lang.Integer.parseInt; + +import com.jayway.restassured.RestAssured; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.testng.annotations.BeforeClass; + +/** + * Base class for all IG REST API Tests + * + * @author Kristijan Conkas + * @author Tuna Aksoy + * @since 2.6 + */ +@Configuration +@PropertySource("classpath:config.properties") +@PropertySource(value = "classpath:local.properties", ignoreResourceNotFound = true) +public class BaseIgRestTest extends RestTest +{ + @Value("${alfresco.rm.scheme}") + private String scheme; + + @Value("${alfresco.rm.host}") + private String host; + + @Value("${alfresco.rm.port}") + private String port; + + @Value("${alfresco.rm.basePath}") + private String basePath; + + /** + * @see org.alfresco.rest.RestTest#checkServerHealth() + */ + @Override + @BeforeClass(alwaysRun = true) + public void checkServerHealth() throws Exception + { + RestAssured.baseURI = scheme + "://" + host; + RestAssured.port = parseInt(port); + RestAssured.basePath = basePath; + } +} diff --git a/src/test/java/org/alfresco/rest/api/fileplancomponents/FilePlanComponentsTest.java b/src/test/java/org/alfresco/rest/api/fileplancomponents/FilePlanComponentsTest.java deleted file mode 100644 index 4de6262bc5..0000000000 --- a/src/test/java/org/alfresco/rest/api/fileplancomponents/FilePlanComponentsTest.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * License rights for this program may be obtained from Alfresco Software, Ltd. - * pursuant to a written agreement and any use of this program without such an - * agreement is prohibited. - * #L% - */ -package org.alfresco.rest.api.fileplancomponents; - -import static io.restassured.RestAssured.authentication; -import static io.restassured.RestAssured.basePath; -import static io.restassured.RestAssured.baseURI; -import static io.restassured.RestAssured.basic; -import static io.restassured.RestAssured.enableLoggingOfRequestAndResponseIfValidationFails; -import static io.restassured.RestAssured.given; -import static io.restassured.RestAssured.port; - -import static java.util.UUID.randomUUID; - -import static com.google.common.collect.ImmutableMap.builder; - -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasItems; -import static org.hamcrest.Matchers.is; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * FIXME: Document me :) - * - * @author Tuna Aksoy - * @since 1.0 - */ -public class FilePlanComponentsTest -{ - private static final String CONTENT_TYPE_KEY = "content-type"; - private static final String CONTENT_TYPE_VALUE = "application/json;charset=UTF-8"; - - /** - * FIXME: Document me :) - * FIXME: Create a base class and move this method, extract to properties to a file, etc. etc. - * - * @throws java.lang.Exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception - { - baseURI = "http://localhost"; - port = 8090; - basePath = "/alfresco/api/-default-/public/ig/versions/1"; - authentication = basic("admin", "admin"); - enableLoggingOfRequestAndResponseIfValidationFails(); - } - - @Test - public void testfilePlanComponentsGet() - { - given(). - when(). - get("/fileplan-components/-filePlan-"). - then(). - statusCode(200). - header(CONTENT_TYPE_KEY, CONTENT_TYPE_VALUE). - root("entry"). - body("isFile", is(false)). - body("nodeType", equalTo("rma:filePlan")). - body("aspectNames", hasItems("rma:recordComponentIdentifier", "rma:filePlanComponent", "rma:recordsManagementRoot")). - body("properties.\"st:componentId\"", equalTo("documentLibrary")); - - /* - given(). - expect(). - body("entry.isFile", is(false)). - body("entry.nodeType", equalTo("rma:filePlan")). - body("entry.aspectNames", hasItems("rma:recordComponentIdentifier", "rma:filePlanComponent", "rma:recordsManagementRoot")). - body("entry.properties.\"st:componentId\"", equalTo("documentLibrary")). - statusCode(200). - header(CONTENT_TYPE_KEY, CONTENT_TYPE_VALUE). - when(). - get("/fileplan-components/-filePlan-"); - - - - get("/fileplan-components/-filePlan-"). - then(). - assertThat(). - statusCode(200). - header(CONTENT_TYPE_KEY, CONTENT_TYPE_VALUE). - body("entry.isFile", is(false)). - body("entry.nodeType", equalTo("rma:filePlan")). - body("entry.aspectNames", hasItems("rma:recordComponentIdentifier", "rma:filePlanComponent", "rma:recordsManagementRoot")). - body("entry.properties.\"st:componentId\"", equalTo("documentLibrary")); - - - - given(). - when(). - get("/fileplan-components/-filePlan-"). - then(). - statusCode(200). - header(CONTENT_TYPE_KEY, CONTENT_TYPE_VALUE). - body("entry.isFile", is(false)). - body("entry.nodeType", equalTo("rma:filePlan")). - body("entry.aspectNames", hasItems("rma:recordComponentIdentifier", "rma:filePlanComponent", "rma:recordsManagementRoot")). - body("entry.properties.\"st:componentId\"", equalTo("documentLibrary")); - */ - - - given(). - contentType("application/json"). - body( - builder(). - put("name", randomUUID().toString()). - put("nodeType", "rma:recordCategory"). - build()). - when(). - post("/fileplan-components/-filePlan-/children"). - then(). - statusCode(201). - header(CONTENT_TYPE_KEY, CONTENT_TYPE_VALUE); - - - /* - given(). - contentType("application/json"). - body("{\"name\":\"" + randomUUID().toString() + "\",\"nodeType\":\"rma:recordCategory\"}"). - when(). - post("/fileplan-components/-filePlan-/children"). - then(). - statusCode(201). - header(CONTENT_TYPE_KEY, CONTENT_TYPE_VALUE); - - - - Map category = new HashMap<>(); - category.put("name", randomUUID().toString()); - category.put("nodeType", "rma:recordCategory"); - - given(). - contentType("application/json"). - body(category). - when(). - post("/fileplan-components/-filePlan-/children"). - then(). - //log().ifValidationFails(). - statusCode(201). - header(CONTENT_TYPE_KEY, CONTENT_TYPE_VALUE); - */ - } -} diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanComponentsTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanComponentsTest.java index 2a0e69a4ee..d1c412965f 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanComponentsTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanComponentsTest.java @@ -14,8 +14,8 @@ package org.alfresco.rest.fileplancomponents; import static org.springframework.http.HttpStatus.OK; import static org.testng.Assert.assertEquals; +import org.alfresco.rest.BaseIgRestTest; import org.alfresco.rest.core.RestWrapper; -import org.alfresco.rest.ig.IgRestTest; import org.alfresco.rest.model.RestFilePlanComponentModel; import org.alfresco.rest.requests.RestFilePlanComponentApi; import org.alfresco.utility.data.DataUser; @@ -28,7 +28,7 @@ import org.testng.annotations.Test; * @author Tuna Aksoy * @since 1.0 */ -public class FilePlanComponentsTest extends IgRestTest +public class FilePlanComponentsTest extends BaseIgRestTest { @Autowired private RestFilePlanComponentApi filePlanComponentApi; diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryComponentsTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryComponentsTest.java index 4df726bb47..7bec99137a 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryComponentsTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryComponentsTest.java @@ -13,8 +13,8 @@ package org.alfresco.rest.fileplancomponents; import java.util.UUID; +import org.alfresco.rest.BaseIgRestTest; import org.alfresco.rest.core.RestWrapper; -import org.alfresco.rest.ig.IgRestTest; import org.alfresco.rest.model.RestFilePlanComponentModel; import org.alfresco.rest.requests.RestFilePlanComponentApi; import org.alfresco.utility.data.DataUser; @@ -24,7 +24,7 @@ import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertNotNull; -import static org.alfresco.rest.model.FileplanComponentType.CATEGORY; +import static org.alfresco.rest.model.FileplanComponentType.RECORD_CATEGORY; import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.HttpStatus.NO_CONTENT; @@ -35,7 +35,7 @@ import static org.springframework.http.HttpStatus.NO_CONTENT; * @author Kristijan Conkas * @since */ -public class RecordCategoryComponentsTest extends IgRestTest +public class RecordCategoryComponentsTest extends BaseIgRestTest { @Autowired private RestFilePlanComponentApi filePlanComponentApi; @@ -58,13 +58,13 @@ public class RecordCategoryComponentsTest extends IgRestTest RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper(); restWrapper.authenticateUser(dataUser.getAdminUser()); RestFilePlanComponentModel filePlanComponent = - filePlanComponentApi.createFilePlanComponent("-filePlan-", categoryName, CATEGORY, null); + filePlanComponentApi.createFilePlanComponent("-filePlan-", categoryName, RECORD_CATEGORY, null); // verify returned object restWrapper.assertStatusCodeIs(CREATED); assertTrue(filePlanComponent.isIsCategory()); assertEquals(filePlanComponent.getName(), categoryName); - assertEquals(filePlanComponent.getNodeType(), CATEGORY.toString()); + assertEquals(filePlanComponent.getNodeType(), RECORD_CATEGORY.toString()); newCategoryId = filePlanComponent.getId(); } diff --git a/src/test/java/org/alfresco/rest/ig/IgRestTest.java b/src/test/java/org/alfresco/rest/ig/IgRestTest.java deleted file mode 100644 index dedba57b10..0000000000 --- a/src/test/java/org/alfresco/rest/ig/IgRestTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * License rights for this program may be obtained from Alfresco Software, Ltd. - * pursuant to a written agreement and any use of this program without such an - * agreement is prohibited. - * #L% - */ -package org.alfresco.rest.ig; - -import static com.jayway.restassured.RestAssured.basePath; -import static com.jayway.restassured.RestAssured.baseURI; -import static com.jayway.restassured.RestAssured.port; - -import org.alfresco.rest.RestTest; -import org.testng.annotations.BeforeClass; - -/** - * Information Governance RestTest implementation - * @author Kristijan Conkas - * @since 2.6 - */ -public class IgRestTest extends RestTest -{ - /** - * @see org.alfresco.rest.RestTest#checkServerHealth() - */ - @Override - @BeforeClass(alwaysRun = true) - public void checkServerHealth() throws Exception - { - // TODO: obtain these from property files - baseURI = "http://localhost"; - port = 8080; - basePath = "alfresco/api/-default-/public/ig/versions/1"; - } -} diff --git a/src/test/resources/config.properties b/src/test/resources/config.properties new file mode 100644 index 0000000000..899f737db2 --- /dev/null +++ b/src/test/resources/config.properties @@ -0,0 +1,4 @@ +alfresco.rm.scheme=http +alfresco.rm.host=localhost +alfresco.rm.port=8080 +alfresco.rm.basePath=alfresco/api/-default-/public/ig/versions/1 \ No newline at end of file diff --git a/src/test/resources/local.properties b/src/test/resources/local.properties new file mode 100644 index 0000000000..e69de29bb2 From 95888e178b6da98e0bfff44d6d2f642a7410fbea Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Thu, 20 Oct 2016 23:02:59 +0100 Subject: [PATCH 06/49] Removed local.properties from versioning --- src/test/resources/local.properties | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/test/resources/local.properties diff --git a/src/test/resources/local.properties b/src/test/resources/local.properties deleted file mode 100644 index e69de29bb2..0000000000 From d8f9f2bc3ed7e81c0e8dbe135de7e1d1b5ea0ee8 Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Thu, 20 Oct 2016 23:26:29 +0100 Subject: [PATCH 07/49] Updated the README file, made some minor changes. --- README | 1 + .../java/org/alfresco/rest/model/FileplanComponentType.java | 1 + src/test/java/org/alfresco/rest/BaseIgRestTest.java | 6 ++++++ .../rest/fileplancomponents/FilePlanComponentsTest.java | 5 +++-- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README b/README index e69de29bb2..3aa3496e19 100644 --- a/README +++ b/README @@ -0,0 +1 @@ +In order to change the value of a property in "config.properties" create a file called "local.properties" under src/test/resources and redefine the property with the new value. \ No newline at end of file diff --git a/src/main/java/org/alfresco/rest/model/FileplanComponentType.java b/src/main/java/org/alfresco/rest/model/FileplanComponentType.java index 8572c4bc8a..5811a3f2bf 100644 --- a/src/main/java/org/alfresco/rest/model/FileplanComponentType.java +++ b/src/main/java/org/alfresco/rest/model/FileplanComponentType.java @@ -19,6 +19,7 @@ package org.alfresco.rest.model; */ public enum FileplanComponentType { + FILE_PLAN("rma:filePlan"), RECORD_CATEGORY("rma:recordCategory"), RECORD_FOLDER("rma:recordFolder"), HOLD("rma:hold"), diff --git a/src/test/java/org/alfresco/rest/BaseIgRestTest.java b/src/test/java/org/alfresco/rest/BaseIgRestTest.java index 0fa4ca5ff0..c814ab1196 100644 --- a/src/test/java/org/alfresco/rest/BaseIgRestTest.java +++ b/src/test/java/org/alfresco/rest/BaseIgRestTest.java @@ -32,6 +32,12 @@ import org.testng.annotations.BeforeClass; @PropertySource(value = "classpath:local.properties", ignoreResourceNotFound = true) public class BaseIgRestTest extends RestTest { + /** Alias which can be used instead of the identifier of a node. */ + public static final String ALIAS_FILE_PLAN = "-filePlan-"; + public static final String ALIAS_TRANSFERS = "-transfers-"; + public static final String ALIAS_UNFILED_RECORDS_CONTAINER = "-unfiled-"; + public static final String ALIAS_HOLDS = "-holds-"; + @Value("${alfresco.rm.scheme}") private String scheme; diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanComponentsTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanComponentsTest.java index d1c412965f..39ff68f34e 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanComponentsTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanComponentsTest.java @@ -11,6 +11,7 @@ */ package org.alfresco.rest.fileplancomponents; +import static org.alfresco.rest.model.FileplanComponentType.FILE_PLAN; import static org.springframework.http.HttpStatus.OK; import static org.testng.Assert.assertEquals; @@ -41,8 +42,8 @@ public class FilePlanComponentsTest extends BaseIgRestTest { RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper(); restWrapper.authenticateUser(dataUser.getAdminUser()); - RestFilePlanComponentModel filePlanComponent = filePlanComponentApi.getFilePlanComponent("-filePlan-"); + RestFilePlanComponentModel filePlanComponent = filePlanComponentApi.getFilePlanComponent(ALIAS_FILE_PLAN); restWrapper.assertStatusCodeIs(OK); - assertEquals(filePlanComponent.getNodeType(), "rma:filePlan"); + assertEquals(filePlanComponent.getNodeType(), FILE_PLAN.toString()); } } From bcf76ab21093a4b0754d5a1636907fe01f70743d Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Fri, 21 Oct 2016 11:51:47 +0300 Subject: [PATCH 08/49] update .gitignore --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index dfce60785c..69fd5a71f4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ /.settings/ .classpath .project -/src/test/resources/local.properties \ No newline at end of file +/src/test/resources/local.properties +/.idea/ +*.iml From 9618b2a0a6f4af618dfaf43b59c1f5763d92c01c Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Fri, 21 Oct 2016 11:20:32 +0100 Subject: [PATCH 09/49] RM-3964: enum to const --- .../rest/model/FileplanComponentType.java | 39 ------------------- .../requests/RestFilePlanComponentApi.java | 5 +-- .../org/alfresco/rest/BaseIgRestTest.java | 7 ++++ ...nComponentsTest.java => FilePlanTest.java} | 5 +-- ...nentsTest.java => RecordCategoryTest.java} | 3 +- 5 files changed, 12 insertions(+), 47 deletions(-) delete mode 100644 src/main/java/org/alfresco/rest/model/FileplanComponentType.java rename src/test/java/org/alfresco/rest/fileplancomponents/{FilePlanComponentsTest.java => FilePlanTest.java} (86%) rename src/test/java/org/alfresco/rest/fileplancomponents/{RecordCategoryComponentsTest.java => RecordCategoryTest.java} (96%) diff --git a/src/main/java/org/alfresco/rest/model/FileplanComponentType.java b/src/main/java/org/alfresco/rest/model/FileplanComponentType.java deleted file mode 100644 index 5811a3f2bf..0000000000 --- a/src/main/java/org/alfresco/rest/model/FileplanComponentType.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * License rights for this program may be obtained from Alfresco Software, Ltd. - * pursuant to a written agreement and any use of this program without such an - * agreement is prohibited. - * #L% - */ -package org.alfresco.rest.model; - -/** - * Fileplan Component Types enum - * - * @author Kristijan Conkas - * @since 2.6 - */ -public enum FileplanComponentType -{ - FILE_PLAN("rma:filePlan"), - RECORD_CATEGORY("rma:recordCategory"), - RECORD_FOLDER("rma:recordFolder"), - HOLD("rma:hold"), - UNFILED_RECORD_FOLDER("rma:unfiledRecordFolder"); - - private String value; - - FileplanComponentType (String value) - { - this.value = value; - } - - public String toString() - { - return this.value; - } -} diff --git a/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java b/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java index de3ef604b9..61a629e70e 100644 --- a/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java +++ b/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java @@ -22,7 +22,6 @@ import java.util.Map; import org.alfresco.rest.core.RestAPI; import org.alfresco.rest.core.RestRequest; -import org.alfresco.rest.model.FileplanComponentType; import org.alfresco.rest.model.RestFilePlanComponentModel; import org.json.JSONObject; import org.springframework.context.annotation.Scope; @@ -61,14 +60,14 @@ public class RestFilePlanComponentApi extends RestAPI * @throws Exception */ public RestFilePlanComponentModel createFilePlanComponent(String parentFilePlanComponentId, String componentName, - FileplanComponentType componentType, Map properties) throws Exception + String componentType, Map properties) throws Exception { if (componentName == null) throw new IllegalArgumentException("Child component name missing"); JSONObject body = new JSONObject(); body.put("name", componentName); - body.put("nodeType", componentType.toString()); + body.put("nodeType", componentType); if (properties != null) body.put("properties", properties); RestRequest request = requestWithBody(POST, body.toString(), "fileplan-components/{fileplanComponentId}/children", parentFilePlanComponentId); diff --git a/src/test/java/org/alfresco/rest/BaseIgRestTest.java b/src/test/java/org/alfresco/rest/BaseIgRestTest.java index c814ab1196..8dee75f3ff 100644 --- a/src/test/java/org/alfresco/rest/BaseIgRestTest.java +++ b/src/test/java/org/alfresco/rest/BaseIgRestTest.java @@ -38,6 +38,13 @@ public class BaseIgRestTest extends RestTest public static final String ALIAS_UNFILED_RECORDS_CONTAINER = "-unfiled-"; public static final String ALIAS_HOLDS = "-holds-"; + /** Component types. */ + public static final String FILE_PLAN = "rma:filePlan"; + public static final String RECORD_CATEGORY = "rma:recordCategory"; + public static final String RECORD_FOLDER = "rma:recordFolder"; + public static final String HOLD = "rma:hold"; + public static final String UNFILED_RECORD_FOLDER = "rma:unfiledRecordFolder"; + @Value("${alfresco.rm.scheme}") private String scheme; diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanComponentsTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTest.java similarity index 86% rename from src/test/java/org/alfresco/rest/fileplancomponents/FilePlanComponentsTest.java rename to src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTest.java index 39ff68f34e..bb85121136 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanComponentsTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTest.java @@ -11,7 +11,6 @@ */ package org.alfresco.rest.fileplancomponents; -import static org.alfresco.rest.model.FileplanComponentType.FILE_PLAN; import static org.springframework.http.HttpStatus.OK; import static org.testng.Assert.assertEquals; @@ -29,7 +28,7 @@ import org.testng.annotations.Test; * @author Tuna Aksoy * @since 1.0 */ -public class FilePlanComponentsTest extends BaseIgRestTest +public class FilePlanTest extends BaseIgRestTest { @Autowired private RestFilePlanComponentApi filePlanComponentApi; @@ -44,6 +43,6 @@ public class FilePlanComponentsTest extends BaseIgRestTest restWrapper.authenticateUser(dataUser.getAdminUser()); RestFilePlanComponentModel filePlanComponent = filePlanComponentApi.getFilePlanComponent(ALIAS_FILE_PLAN); restWrapper.assertStatusCodeIs(OK); - assertEquals(filePlanComponent.getNodeType(), FILE_PLAN.toString()); + assertEquals(filePlanComponent.getNodeType(), FILE_PLAN); } } diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryComponentsTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java similarity index 96% rename from src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryComponentsTest.java rename to src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java index 7bec99137a..98f8204908 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryComponentsTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java @@ -24,7 +24,6 @@ import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertNotNull; -import static org.alfresco.rest.model.FileplanComponentType.RECORD_CATEGORY; import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.HttpStatus.NO_CONTENT; @@ -35,7 +34,7 @@ import static org.springframework.http.HttpStatus.NO_CONTENT; * @author Kristijan Conkas * @since */ -public class RecordCategoryComponentsTest extends BaseIgRestTest +public class RecordCategoryTest extends BaseIgRestTest { @Autowired private RestFilePlanComponentApi filePlanComponentApi; From 26ea6127e1def5d91b9c52446eb4405f7a6b5eef Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Fri, 21 Oct 2016 12:19:38 +0100 Subject: [PATCH 10/49] RM-3964: Refactoring utility methods (WIP) --- .../rest/body/IgJsonBodyGenerator.java | 52 ++++++++++++ .../alfresco/rest/model/PropertiesModel.java | 22 +++++ .../model/RestFilePlanComponentModel.java | 5 ++ .../requests/RestFilePlanComponentApi.java | 31 +++---- .../RecordCategoryTest.java | 85 ++++++++++--------- 5 files changed, 137 insertions(+), 58 deletions(-) create mode 100644 src/main/java/org/alfresco/rest/body/IgJsonBodyGenerator.java create mode 100644 src/main/java/org/alfresco/rest/model/PropertiesModel.java diff --git a/src/main/java/org/alfresco/rest/body/IgJsonBodyGenerator.java b/src/main/java/org/alfresco/rest/body/IgJsonBodyGenerator.java new file mode 100644 index 0000000000..263a4ad994 --- /dev/null +++ b/src/main/java/org/alfresco/rest/body/IgJsonBodyGenerator.java @@ -0,0 +1,52 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.rest.body; + +import javax.json.Json; +import javax.json.JsonBuilderFactory; +import javax.json.JsonObject; + +import org.alfresco.rest.model.RestFilePlanComponentModel; + +/** + * Helper for building JSON objects + * @author Kristijan Conkas + * @since 2.6 + */ +public class IgJsonBodyGenerator +{ + private static JsonBuilderFactory jsonBuilderFactory; + + /** + * @return the initialized JSON builder factory + */ + private static JsonBuilderFactory getJsonBuilder() + { + if (jsonBuilderFactory == null) + return Json.createBuilderFactory(null); + else + { + return jsonBuilderFactory; + } + } + + public static String filePlanComponentCreate(RestFilePlanComponentModel model) + { + JsonObject value = getJsonBuilder() + .createObjectBuilder() + .add("name", model.getName()) + .add("nodeType", model.getNodeType()) + // TODO: handle properties for holds and unfiled record folders + .build(); + return value.toString(); + } +} diff --git a/src/main/java/org/alfresco/rest/model/PropertiesModel.java b/src/main/java/org/alfresco/rest/model/PropertiesModel.java new file mode 100644 index 0000000000..de096ce3c5 --- /dev/null +++ b/src/main/java/org/alfresco/rest/model/PropertiesModel.java @@ -0,0 +1,22 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.rest.model; + +/** + * Fileplan component properties + * @author Kristijan Conkas + * @since 2.6 + */ +public class PropertiesModel +{ + // TODO: implement me +} diff --git a/src/main/java/org/alfresco/rest/model/RestFilePlanComponentModel.java b/src/main/java/org/alfresco/rest/model/RestFilePlanComponentModel.java index 4a65d390a9..d1e606f168 100644 --- a/src/main/java/org/alfresco/rest/model/RestFilePlanComponentModel.java +++ b/src/main/java/org/alfresco/rest/model/RestFilePlanComponentModel.java @@ -13,6 +13,9 @@ package org.alfresco.rest.model; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + /** * FIXME: Document me :) * @@ -20,6 +23,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; * @since 1.0 */ // FIXME: Once the fields have been added this annotation should be removed +@Component +@Scope(value="prototype") @JsonIgnoreProperties(ignoreUnknown = true) public class RestFilePlanComponentModel { diff --git a/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java b/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java index 61a629e70e..934c9dcc8b 100644 --- a/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java +++ b/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java @@ -20,6 +20,7 @@ import static org.springframework.http.HttpMethod.PUT; import java.util.Map; +import org.alfresco.rest.body.IgJsonBodyGenerator; import org.alfresco.rest.core.RestAPI; import org.alfresco.rest.core.RestRequest; import org.alfresco.rest.model.RestFilePlanComponentModel; @@ -50,27 +51,19 @@ public class RestFilePlanComponentApi extends RestAPI return usingRestWrapper().processModel(RestFilePlanComponentModel.class, request); } + /** - * Create child file plan component - * @param parentFilePlanComponentId parent file plan component id - * @param componentName component name - * @param type one of {@link FilePlanComponentType} - * @param properties component type specific, refer to API reference for details - * @return {@link RestFilePlanComponentModel} for componentName + * Post file plan component + * @param model + * @return * @throws Exception */ - public RestFilePlanComponentModel createFilePlanComponent(String parentFilePlanComponentId, String componentName, - String componentType, Map properties) throws Exception + public RestFilePlanComponentModel postFilePlanComponent(RestFilePlanComponentModel model) throws Exception { - if (componentName == null) - throw new IllegalArgumentException("Child component name missing"); - - JSONObject body = new JSONObject(); - body.put("name", componentName); - body.put("nodeType", componentType); - if (properties != null) body.put("properties", properties); - - RestRequest request = requestWithBody(POST, body.toString(), "fileplan-components/{fileplanComponentId}/children", parentFilePlanComponentId); + RestRequest request = requestWithBody(POST, + IgJsonBodyGenerator.filePlanComponentCreate(model).toString(), + "fileplan-components/{fileplanComponentId}/children", + model.getId()); return usingRestWrapper().processModel(RestFilePlanComponentModel.class, request); } @@ -81,7 +74,7 @@ public class RestFilePlanComponentApi extends RestAPI * @return {@link RestFilePlanComponentModel} for filePlanComponentId * @throws Exception */ - public RestFilePlanComponentModel updateFilePlanComponent(String filePlanComponentId, JSONObject requestBody) throws Exception + public RestFilePlanComponentModel putFilePlanComponent(String filePlanComponentId, JSONObject requestBody) throws Exception { RestRequest request = requestWithBody(PUT, requestBody.toString(), "fileplan-components/{fileplanComponentId}", filePlanComponentId); return usingRestWrapper().processModel(RestFilePlanComponentModel.class, request); @@ -99,7 +92,7 @@ public class RestFilePlanComponentApi extends RestAPI JSONObject body = new JSONObject(); body.put("name", newName); - return updateFilePlanComponent(filePlanComponentId, body); + return putFilePlanComponent(filePlanComponentId, body); } /** diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java index 98f8204908..1769413089 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java @@ -42,6 +42,9 @@ public class RecordCategoryTest extends BaseIgRestTest @Autowired private DataUser dataUser; + @Autowired + private RestFilePlanComponentModel componentModel; + /** new category name */ private String categoryName = "cat " + UUID.randomUUID().toString().substring(0, 8); @@ -56,8 +59,12 @@ public class RecordCategoryTest extends BaseIgRestTest // create category RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper(); restWrapper.authenticateUser(dataUser.getAdminUser()); - RestFilePlanComponentModel filePlanComponent = - filePlanComponentApi.createFilePlanComponent("-filePlan-", categoryName, RECORD_CATEGORY, null); + + componentModel.setId(ALIAS_FILE_PLAN ); + componentModel.setName(categoryName); + componentModel.setNodeType(RECORD_CATEGORY); + + RestFilePlanComponentModel filePlanComponent = filePlanComponentApi.postFilePlanComponent(componentModel); // verify returned object restWrapper.assertStatusCodeIs(CREATED); @@ -67,41 +74,41 @@ public class RecordCategoryTest extends BaseIgRestTest newCategoryId = filePlanComponent.getId(); } - @Test - ( - description = "Rename category as authorised user", - dependsOnMethods= { "createCategoryAsAuthorisedUser" } - ) - public void renameCategoryAsAuthorisedUser() throws Exception - { - assertNotNull(newCategoryId); - String newName = "renamed " + categoryName; - - // rename - RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper(); - restWrapper.authenticateUser(dataUser.getAdminUser()); - RestFilePlanComponentModel filePlanComponent = filePlanComponentApi.renameFilePlanComponent(newCategoryId, newName); - - // verify returned object - restWrapper.assertStatusCodeIs(OK); - assertEquals(filePlanComponent.getName(), newName); - } - - @Test - ( - description = "Rename category as authorised user", - dependsOnMethods= { "renameCategoryAsAuthorisedUser" } - ) - public void deleteCategoryAsAuthorisedUser() throws Exception - { - // delete - RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper(); - restWrapper.authenticateUser(dataUser.getAdminUser()); - filePlanComponentApi.deleteFilePlanComponent(newCategoryId, true); - - // verify deletion - restWrapper.assertStatusCodeIs(NO_CONTENT); - // TODO: verify we can't get an object with this ID again - // TODO: can we verify that deletion with deletePermanently=false indeed ended up in trashcan? - } +// @Test +// ( +// description = "Rename category as authorised user", +// dependsOnMethods= { "createCategoryAsAuthorisedUser" } +// ) +// public void renameCategoryAsAuthorisedUser() throws Exception +// { +// assertNotNull(newCategoryId); +// String newName = "renamed " + categoryName; +// +// // rename +// RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper(); +// restWrapper.authenticateUser(dataUser.getAdminUser()); +// RestFilePlanComponentModel filePlanComponent = filePlanComponentApi.renameFilePlanComponent(newCategoryId, newName); +// +// // verify returned object +// restWrapper.assertStatusCodeIs(OK); +// assertEquals(filePlanComponent.getName(), newName); +// } +// +// @Test +// ( +// description = "Rename category as authorised user", +// dependsOnMethods= { "renameCategoryAsAuthorisedUser" } +// ) +// public void deleteCategoryAsAuthorisedUser() throws Exception +// { +// // delete +// RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper(); +// restWrapper.authenticateUser(dataUser.getAdminUser()); +// filePlanComponentApi.deleteFilePlanComponent(newCategoryId, true); +// +// // verify deletion +// restWrapper.assertStatusCodeIs(NO_CONTENT); +// // TODO: verify we can't get an object with this ID again +// // TODO: can we verify that deletion with deletePermanently=false indeed ended up in trashcan? +// } } From 918638e8a5db812c3f935a6c607db0f5cf561fb0 Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Fri, 21 Oct 2016 17:17:11 +0100 Subject: [PATCH 11/49] RM-3964: Update method + tests (WIP) --- .../rest/body/IgJsonBodyGenerator.java | 24 +++++-- .../alfresco/rest/model/PropertiesModel.java | 68 ++++++++++++++++++- .../model/RestFilePlanComponentModel.java | 26 ++++++- .../requests/RestFilePlanComponentApi.java | 36 +++------- .../org/alfresco/rest/BaseIgRestTest.java | 10 +-- .../rest/fileplancomponents/FilePlanTest.java | 2 +- .../RecordCategoryTest.java | 62 ++++++++++------- 7 files changed, 161 insertions(+), 67 deletions(-) diff --git a/src/main/java/org/alfresco/rest/body/IgJsonBodyGenerator.java b/src/main/java/org/alfresco/rest/body/IgJsonBodyGenerator.java index 263a4ad994..5ef5519640 100644 --- a/src/main/java/org/alfresco/rest/body/IgJsonBodyGenerator.java +++ b/src/main/java/org/alfresco/rest/body/IgJsonBodyGenerator.java @@ -13,8 +13,9 @@ package org.alfresco.rest.body; import javax.json.Json; import javax.json.JsonBuilderFactory; -import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; +import org.alfresco.rest.model.PropertiesModel; import org.alfresco.rest.model.RestFilePlanComponentModel; /** @@ -32,7 +33,9 @@ public class IgJsonBodyGenerator private static JsonBuilderFactory getJsonBuilder() { if (jsonBuilderFactory == null) + { return Json.createBuilderFactory(null); + } else { return jsonBuilderFactory; @@ -41,12 +44,21 @@ public class IgJsonBodyGenerator public static String filePlanComponentCreate(RestFilePlanComponentModel model) { - JsonObject value = getJsonBuilder() + PropertiesModel properties = model.getProperties(); + JsonObjectBuilder valueBuilder = getJsonBuilder() .createObjectBuilder() .add("name", model.getName()) - .add("nodeType", model.getNodeType()) - // TODO: handle properties for holds and unfiled record folders - .build(); - return value.toString(); + .add("nodeType", model.getNodeType()); + if (properties != null) + { + // handle properties + JsonObjectBuilder propertiesBuilder = getJsonBuilder().createObjectBuilder(); + if (properties.getTitle() != null) + { + propertiesBuilder.add("cm:title", properties.getTitle()); + } + valueBuilder.add("properties", propertiesBuilder.build()); + } + return valueBuilder.build().toString(); } } diff --git a/src/main/java/org/alfresco/rest/model/PropertiesModel.java b/src/main/java/org/alfresco/rest/model/PropertiesModel.java index de096ce3c5..03afc0cf3c 100644 --- a/src/main/java/org/alfresco/rest/model/PropertiesModel.java +++ b/src/main/java/org/alfresco/rest/model/PropertiesModel.java @@ -11,12 +11,78 @@ */ package org.alfresco.rest.model; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + /** * Fileplan component properties * @author Kristijan Conkas * @since 2.6 */ +@Component +@Scope(value = "prototype") +@JsonIgnoreProperties(ignoreUnknown = true) public class PropertiesModel { - // TODO: implement me + // TODO: handling individual properties is tedious and error prone, how about @JsonGetter + @JsonSetter? + + @JsonProperty("rma:vitalRecordIndicator") + private boolean vitalRecord; + + @JsonProperty("cm:title") + private String title; + + @JsonProperty("rma:holdReason") + private String holdReason; + + /** + * @return the vitalRecord + */ + public boolean isVitalRecord() + { + return this.vitalRecord; + } + + /** + * @param vitalRecord the vitalRecord to set + */ + public void setVitalRecord(boolean vitalRecord) + { + this.vitalRecord = vitalRecord; + } + + /** + * @return the title + */ + public String getTitle() + { + return this.title; + } + + /** + * @param title the title to set + */ + public void setTitle(String title) + { + this.title = title; + } + + /** + * @return the holdReason + */ + public String getHoldReason() + { + return this.holdReason; + } + + /** + * @param holdReason the holdReason to set + */ + public void setHoldReason(String holdReason) + { + this.holdReason = holdReason; + } } diff --git a/src/main/java/org/alfresco/rest/model/RestFilePlanComponentModel.java b/src/main/java/org/alfresco/rest/model/RestFilePlanComponentModel.java index d1e606f168..96c6d7a374 100644 --- a/src/main/java/org/alfresco/rest/model/RestFilePlanComponentModel.java +++ b/src/main/java/org/alfresco/rest/model/RestFilePlanComponentModel.java @@ -12,6 +12,7 @@ package org.alfresco.rest.model; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @@ -22,9 +23,9 @@ import org.springframework.stereotype.Component; * @author Tuna Aksoy * @since 1.0 */ -// FIXME: Once the fields have been added this annotation should be removed @Component -@Scope(value="prototype") +@Scope(value = "prototype") +//FIXME: Once the fields have been added this annotation should be removed @JsonIgnoreProperties(ignoreUnknown = true) public class RestFilePlanComponentModel { @@ -36,7 +37,10 @@ public class RestFilePlanComponentModel private boolean isRecordFolder; private boolean isFile; private boolean hasRetentionSchedule; - + + @JsonProperty(value = "properties") + private PropertiesModel properties; + /** * @return the id */ @@ -164,4 +168,20 @@ public class RestFilePlanComponentModel { this.hasRetentionSchedule = hasRetentionSchedule; } + + /** + * @return the properties + */ + public PropertiesModel getProperties() + { + return properties; + } + + /** + * @param properties the properties to set + */ + public void setProperties(PropertiesModel properties) + { + this.properties = properties; + } } diff --git a/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java b/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java index 934c9dcc8b..48fe117c90 100644 --- a/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java +++ b/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java @@ -11,16 +11,15 @@ */ package org.alfresco.rest.requests; +import static org.alfresco.rest.body.IgJsonBodyGenerator.filePlanComponentCreate; import static org.alfresco.rest.core.RestRequest.requestWithBody; import static org.alfresco.rest.core.RestRequest.simpleRequest; + import static org.springframework.http.HttpMethod.DELETE; import static org.springframework.http.HttpMethod.GET; import static org.springframework.http.HttpMethod.POST; import static org.springframework.http.HttpMethod.PUT; -import java.util.Map; - -import org.alfresco.rest.body.IgJsonBodyGenerator; import org.alfresco.rest.core.RestAPI; import org.alfresco.rest.core.RestRequest; import org.alfresco.rest.model.RestFilePlanComponentModel; @@ -50,18 +49,17 @@ public class RestFilePlanComponentApi extends RestAPI RestRequest request = simpleRequest(GET, "fileplan-components/{fileplanComponentId}", filePlanComponentId); return usingRestWrapper().processModel(RestFilePlanComponentModel.class, request); } - /** - * Post file plan component + * Create file plan component * @param model * @return * @throws Exception */ - public RestFilePlanComponentModel postFilePlanComponent(RestFilePlanComponentModel model) throws Exception + public RestFilePlanComponentModel createFilePlanComponent(RestFilePlanComponentModel model) throws Exception { RestRequest request = requestWithBody(POST, - IgJsonBodyGenerator.filePlanComponentCreate(model).toString(), + filePlanComponentCreate(model).toString(), "fileplan-components/{fileplanComponentId}/children", model.getId()); return usingRestWrapper().processModel(RestFilePlanComponentModel.class, request); @@ -74,27 +72,15 @@ public class RestFilePlanComponentApi extends RestAPI * @return {@link RestFilePlanComponentModel} for filePlanComponentId * @throws Exception */ - public RestFilePlanComponentModel putFilePlanComponent(String filePlanComponentId, JSONObject requestBody) throws Exception + public RestFilePlanComponentModel updateFilePlanComponent(String filePlanComponentId, RestFilePlanComponentModel update) throws Exception { - RestRequest request = requestWithBody(PUT, requestBody.toString(), "fileplan-components/{fileplanComponentId}", filePlanComponentId); + RestRequest request = requestWithBody(PUT, + filePlanComponentCreate(update).toString(), + "fileplan-components/{fileplanComponentId}", + filePlanComponentId); return usingRestWrapper().processModel(RestFilePlanComponentModel.class, request); } - - /** - * Rename file plan component - * @param filePlanComponentId - * @param newName - * @return - * @throws Exception - */ - public RestFilePlanComponentModel renameFilePlanComponent(String filePlanComponentId, String newName) throws Exception - { - JSONObject body = new JSONObject(); - body.put("name", newName); - - return putFilePlanComponent(filePlanComponentId, body); - } - + /** * Delete file plan component * @param filePlanComponentId diff --git a/src/test/java/org/alfresco/rest/BaseIgRestTest.java b/src/test/java/org/alfresco/rest/BaseIgRestTest.java index 8dee75f3ff..9471f9393c 100644 --- a/src/test/java/org/alfresco/rest/BaseIgRestTest.java +++ b/src/test/java/org/alfresco/rest/BaseIgRestTest.java @@ -39,11 +39,11 @@ public class BaseIgRestTest extends RestTest public static final String ALIAS_HOLDS = "-holds-"; /** Component types. */ - public static final String FILE_PLAN = "rma:filePlan"; - public static final String RECORD_CATEGORY = "rma:recordCategory"; - public static final String RECORD_FOLDER = "rma:recordFolder"; - public static final String HOLD = "rma:hold"; - public static final String UNFILED_RECORD_FOLDER = "rma:unfiledRecordFolder"; + public static final String COMPONENT_FILE_PLAN = "rma:filePlan"; + public static final String COMPONENT_RECORD_CATEGORY = "rma:recordCategory"; + public static final String COMPONENT_RECORD_FOLDER = "rma:recordFolder"; + public static final String COMPONENT_HOLD = "rma:hold"; + public static final String COMPONENT_UNFILED_RECORD_FOLDER = "rma:unfiledRecordFolder"; @Value("${alfresco.rm.scheme}") private String scheme; diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTest.java index bb85121136..c55698e0ce 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTest.java @@ -43,6 +43,6 @@ public class FilePlanTest extends BaseIgRestTest restWrapper.authenticateUser(dataUser.getAdminUser()); RestFilePlanComponentModel filePlanComponent = filePlanComponentApi.getFilePlanComponent(ALIAS_FILE_PLAN); restWrapper.assertStatusCodeIs(OK); - assertEquals(filePlanComponent.getNodeType(), FILE_PLAN); + assertEquals(filePlanComponent.getNodeType(), COMPONENT_FILE_PLAN); } } diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java index 1769413089..642076bdf8 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java @@ -15,6 +15,7 @@ import java.util.UUID; import org.alfresco.rest.BaseIgRestTest; import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.PropertiesModel; import org.alfresco.rest.model.RestFilePlanComponentModel; import org.alfresco.rest.requests.RestFilePlanComponentApi; import org.alfresco.utility.data.DataUser; @@ -22,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertNotNull; import static org.springframework.http.HttpStatus.CREATED; @@ -45,6 +47,9 @@ public class RecordCategoryTest extends BaseIgRestTest @Autowired private RestFilePlanComponentModel componentModel; + @Autowired + private PropertiesModel propertiesModel; + /** new category name */ private String categoryName = "cat " + UUID.randomUUID().toString().substring(0, 8); @@ -57,43 +62,48 @@ public class RecordCategoryTest extends BaseIgRestTest public void createCategoryAsAuthorisedUser() throws Exception { // create category - RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper(); - restWrapper.authenticateUser(dataUser.getAdminUser()); - + propertiesModel.setTitle("New Test File Plan"); componentModel.setId(ALIAS_FILE_PLAN ); componentModel.setName(categoryName); - componentModel.setNodeType(RECORD_CATEGORY); + componentModel.setNodeType(COMPONENT_RECORD_CATEGORY); + componentModel.setProperties(propertiesModel); - RestFilePlanComponentModel filePlanComponent = filePlanComponentApi.postFilePlanComponent(componentModel); + RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + RestFilePlanComponentModel filePlanComponent = filePlanComponentApi.createFilePlanComponent(componentModel); // verify returned object restWrapper.assertStatusCodeIs(CREATED); assertTrue(filePlanComponent.isIsCategory()); assertEquals(filePlanComponent.getName(), categoryName); - assertEquals(filePlanComponent.getNodeType(), RECORD_CATEGORY.toString()); + assertEquals(filePlanComponent.getNodeType(), COMPONENT_RECORD_CATEGORY.toString()); + assertFalse(filePlanComponent.getProperties().isVitalRecord()); + newCategoryId = filePlanComponent.getId(); } -// @Test -// ( -// description = "Rename category as authorised user", -// dependsOnMethods= { "createCategoryAsAuthorisedUser" } -// ) -// public void renameCategoryAsAuthorisedUser() throws Exception -// { -// assertNotNull(newCategoryId); -// String newName = "renamed " + categoryName; -// -// // rename -// RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper(); -// restWrapper.authenticateUser(dataUser.getAdminUser()); -// RestFilePlanComponentModel filePlanComponent = filePlanComponentApi.renameFilePlanComponent(newCategoryId, newName); -// -// // verify returned object -// restWrapper.assertStatusCodeIs(OK); -// assertEquals(filePlanComponent.getName(), newName); -// } -// + @Test + ( + description = "Rename category as authorised user", + dependsOnMethods= { "createCategoryAsAuthorisedUser" } + ) + public void renameCategoryAsAuthorisedUser() throws Exception + { + assertNotNull(newCategoryId); + String newName = "renamed " + categoryName; + + RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper(); + restWrapper.authenticateUser(dataUser.getAdminUser()); + + RestFilePlanComponentModel filePlanComponent = filePlanComponentApi.getFilePlanComponent(newCategoryId); + filePlanComponent.setName(newName); + + RestFilePlanComponentModel renamedFilePlanComponent = filePlanComponentApi.updateFilePlanComponent(newCategoryId, filePlanComponent); + + // verify returned object + restWrapper.assertStatusCodeIs(OK); + assertEquals(renamedFilePlanComponent.getName(), newName); + } + // @Test // ( // description = "Rename category as authorised user", From 0d83c1fa18b5f555bef5d72078829d5acc15a3c8 Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Mon, 24 Oct 2016 10:06:20 +0100 Subject: [PATCH 12/49] RM-3964: Utility methods updated to take models as parameters. --- .../rest/body/IgJsonBodyGenerator.java | 29 +++++++++++++++ .../requests/RestFilePlanComponentApi.java | 18 +++++----- .../RecordCategoryTest.java | 36 +++++++++---------- 3 files changed, 56 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/alfresco/rest/body/IgJsonBodyGenerator.java b/src/main/java/org/alfresco/rest/body/IgJsonBodyGenerator.java index 5ef5519640..69e7665db7 100644 --- a/src/main/java/org/alfresco/rest/body/IgJsonBodyGenerator.java +++ b/src/main/java/org/alfresco/rest/body/IgJsonBodyGenerator.java @@ -42,6 +42,11 @@ public class IgJsonBodyGenerator } } + /** + * Generate request body for create API calls + * @param model + * @return request body JSON string + */ public static String filePlanComponentCreate(RestFilePlanComponentModel model) { PropertiesModel properties = model.getProperties(); @@ -61,4 +66,28 @@ public class IgJsonBodyGenerator } return valueBuilder.build().toString(); } + + /** + * Generate request body for update API calls + * @param model + * @return request body JSON string + */ + public static String filePlanComponentUpdate(RestFilePlanComponentModel model) + { + PropertiesModel properties = model.getProperties(); + JsonObjectBuilder valueBuilder = getJsonBuilder() + .createObjectBuilder() + .add("name", model.getName()); + if (properties != null) + { + // handle properties + JsonObjectBuilder propertiesBuilder = getJsonBuilder().createObjectBuilder(); + if (properties.getTitle() != null) + { + propertiesBuilder.add("cm:title", properties.getTitle()); + } + valueBuilder.add("properties", propertiesBuilder.build()); + } + return valueBuilder.build().toString(); + } } diff --git a/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java b/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java index 48fe117c90..ca52c13f30 100644 --- a/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java +++ b/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java @@ -12,6 +12,7 @@ package org.alfresco.rest.requests; import static org.alfresco.rest.body.IgJsonBodyGenerator.filePlanComponentCreate; +import static org.alfresco.rest.body.IgJsonBodyGenerator.filePlanComponentUpdate; import static org.alfresco.rest.core.RestRequest.requestWithBody; import static org.alfresco.rest.core.RestRequest.simpleRequest; @@ -67,32 +68,31 @@ public class RestFilePlanComponentApi extends RestAPI /** * Update file plan component - * @param filePlanComponentId - * @param requestBody update body, refer to API reference for details - * @return {@link RestFilePlanComponentModel} for filePlanComponentId + * @param update {@link RestFilePlanComponentModel} to update + * @param returns updated {@link RestFilePlanComponentModel} * @throws Exception */ - public RestFilePlanComponentModel updateFilePlanComponent(String filePlanComponentId, RestFilePlanComponentModel update) throws Exception + public RestFilePlanComponentModel updateFilePlanComponent(RestFilePlanComponentModel update) throws Exception { RestRequest request = requestWithBody(PUT, - filePlanComponentCreate(update).toString(), + filePlanComponentUpdate(update).toString(), "fileplan-components/{fileplanComponentId}", - filePlanComponentId); + update.getId()); return usingRestWrapper().processModel(RestFilePlanComponentModel.class, request); } /** * Delete file plan component - * @param filePlanComponentId + * @param delete {@link RestFilePlanComponentModel} to delete * @param deletePermanently if set to true delete without moving to the trashcan * @throws Exception */ - public RestRequest deleteFilePlanComponent(String filePlanComponentId, boolean deletePermanently) throws Exception + public RestRequest deleteFilePlanComponent(RestFilePlanComponentModel delete, boolean deletePermanently) throws Exception { JSONObject body = new JSONObject(); if (deletePermanently) body.put("permanent", deletePermanently); - RestRequest request = requestWithBody(DELETE, body.toString(), "fileplan-components/{fileplanComponentId}", filePlanComponentId); + RestRequest request = requestWithBody(DELETE, body.toString(), "fileplan-components/{fileplanComponentId}", delete.getId()); usingRestWrapper().processEmptyModel(request); return request; } diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java index 642076bdf8..2c216d3cdc 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java @@ -97,28 +97,28 @@ public class RecordCategoryTest extends BaseIgRestTest RestFilePlanComponentModel filePlanComponent = filePlanComponentApi.getFilePlanComponent(newCategoryId); filePlanComponent.setName(newName); - RestFilePlanComponentModel renamedFilePlanComponent = filePlanComponentApi.updateFilePlanComponent(newCategoryId, filePlanComponent); + RestFilePlanComponentModel renamedFilePlanComponent = filePlanComponentApi.updateFilePlanComponent(filePlanComponent); // verify returned object restWrapper.assertStatusCodeIs(OK); assertEquals(renamedFilePlanComponent.getName(), newName); } -// @Test -// ( -// description = "Rename category as authorised user", -// dependsOnMethods= { "renameCategoryAsAuthorisedUser" } -// ) -// public void deleteCategoryAsAuthorisedUser() throws Exception -// { -// // delete -// RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper(); -// restWrapper.authenticateUser(dataUser.getAdminUser()); -// filePlanComponentApi.deleteFilePlanComponent(newCategoryId, true); -// -// // verify deletion -// restWrapper.assertStatusCodeIs(NO_CONTENT); -// // TODO: verify we can't get an object with this ID again -// // TODO: can we verify that deletion with deletePermanently=false indeed ended up in trashcan? -// } + @Test + ( + description = "Rename category as authorised user", + dependsOnMethods= { "renameCategoryAsAuthorisedUser" } + ) + public void deleteCategoryAsAuthorisedUser() throws Exception + { + // delete + RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper(); + restWrapper.authenticateUser(dataUser.getAdminUser()); + filePlanComponentApi.deleteFilePlanComponent(filePlanComponentApi.getFilePlanComponent(newCategoryId), true); + + // verify deletion + restWrapper.assertStatusCodeIs(NO_CONTENT); + // TODO: verify we can't get an object with this ID again + // TODO: can we verify that deletion with deletePermanently=false indeed ended up in trashcan? + } } From a892c63d77bc4e07d0039cc9921a7cff75818154 Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Tue, 25 Oct 2016 10:05:32 +0100 Subject: [PATCH 13/49] Refactored test code --- README | 2 + pom.xml | 5 + .../alfresco/com/FilePlanComponentAlias.java | 59 ++++++ .../alfresco/com/FilePlanComponentFields.java | 28 +++ .../alfresco/com/FilePlanComponentType.java | 62 ++++++ .../org/alfresco/com/util/ParameterCheck.java | 57 ++++++ .../rest/body/IgJsonBodyGenerator.java | 93 --------- ...onentModel.java => FilePlanComponent.java} | 27 ++- ....java => FilePlanComponentProperties.java} | 26 ++- .../rest/requests/FilePlanComponentApi.java | 145 ++++++++++++++ .../requests/RestFilePlanComponentApi.java | 99 ---------- ...{BaseIgRestTest.java => BaseRestTest.java} | 17 +- .../rest/fileplancomponents/FilePlanTest.java | 48 ----- .../RecordCategoryTest.java | 177 +++++++++++------- 14 files changed, 503 insertions(+), 342 deletions(-) create mode 100644 src/main/java/org/alfresco/com/FilePlanComponentAlias.java create mode 100644 src/main/java/org/alfresco/com/FilePlanComponentFields.java create mode 100644 src/main/java/org/alfresco/com/FilePlanComponentType.java create mode 100644 src/main/java/org/alfresco/com/util/ParameterCheck.java delete mode 100644 src/main/java/org/alfresco/rest/body/IgJsonBodyGenerator.java rename src/main/java/org/alfresco/rest/model/{RestFilePlanComponentModel.java => FilePlanComponent.java} (88%) rename src/main/java/org/alfresco/rest/model/{PropertiesModel.java => FilePlanComponentProperties.java} (74%) create mode 100644 src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java delete mode 100644 src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java rename src/test/java/org/alfresco/rest/{BaseIgRestTest.java => BaseRestTest.java} (64%) delete mode 100644 src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTest.java diff --git a/README b/README index 3aa3496e19..da2b8cbd31 100644 --- a/README +++ b/README @@ -1 +1,3 @@ +FIXME: DOCUMENT ME BETTER :) + In order to change the value of a property in "config.properties" create a file called "local.properties" under src/test/resources and redefine the property with the new value. \ No newline at end of file diff --git a/pom.xml b/pom.xml index 9aa1699457..b1c0b95331 100644 --- a/pom.xml +++ b/pom.xml @@ -25,5 +25,10 @@ test-jar test + + org.jglue.fluent-json + fluent-json + 2.0.0 + diff --git a/src/main/java/org/alfresco/com/FilePlanComponentAlias.java b/src/main/java/org/alfresco/com/FilePlanComponentAlias.java new file mode 100644 index 0000000000..13dc3dbd68 --- /dev/null +++ b/src/main/java/org/alfresco/com/FilePlanComponentAlias.java @@ -0,0 +1,59 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.com; + +/** + * File plan component alias enumeration + * + * @author Tuna Aksoy + * @since 1.0 + */ +public enum FilePlanComponentAlias +{ + FILE_PLAN_ALIAS("-filePlan-"), + TRANSFERS_ALIAS("-transfers-"), + UNFILED_RECORDS_CONTAINER_ALIAS("-unfiled-"), + HOLDS_ALIAS("-holds-"); + + private String alias; + + private FilePlanComponentAlias(String alias) + { + this.alias = alias; + } + + public static final FilePlanComponentAlias getFilePlanComponentAlias(String alias) + { + switch (alias) + { + case "-filePlan-": + return FILE_PLAN_ALIAS; + case "-transfers-": + return TRANSFERS_ALIAS; + case "-unfiled-": + return UNFILED_RECORDS_CONTAINER_ALIAS; + case "-holds-": + return HOLDS_ALIAS; + } + + throw new IllegalArgumentException("Invalid file plan component alias enum value: '" + alias + "'."); + } + + /** + * @see java.lang.Enum#toString() + */ + @Override + public String toString() + { + return this.alias; + } +} diff --git a/src/main/java/org/alfresco/com/FilePlanComponentFields.java b/src/main/java/org/alfresco/com/FilePlanComponentFields.java new file mode 100644 index 0000000000..76b91035c4 --- /dev/null +++ b/src/main/java/org/alfresco/com/FilePlanComponentFields.java @@ -0,0 +1,28 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.com; + +/** + * FIXME: Document me :) + * + * @author Tuna Aksoy + * @since 1.0 + */ +public class FilePlanComponentFields +{ + public static final String NAME = "name"; + public static final String NODE_TYPE = "nodeType"; + public static final String PROPERTIES = "properties"; + public static final String PROPERTIES_TITLE = "cm:title"; + public static final String PROPERTIES_VITAL_RECORD_INDICATOR = "rma:vitalRecordIndicator"; + public static final String PROPERTIES_HOLD_REASON = "rma:holdReason"; +} diff --git a/src/main/java/org/alfresco/com/FilePlanComponentType.java b/src/main/java/org/alfresco/com/FilePlanComponentType.java new file mode 100644 index 0000000000..432178c75e --- /dev/null +++ b/src/main/java/org/alfresco/com/FilePlanComponentType.java @@ -0,0 +1,62 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.com; + +/** + * File plan component type enumeration + * + * @author Tuna Aksoy + * @since 1.0 + */ +public enum FilePlanComponentType +{ + FILE_PLAN_TYPE("rma:filePlan"), + RECORD_CATEGORY_TYPE("rma:recordCategory"), + RECORD_FOLDER_TYPE("rma:recordFolder"), + HOLD_TYPE("rma:hold"), + UNFILED_RECORD_FOLDER_TYPE("rma:unfiledRecordFolder"); + + private String type; + + private FilePlanComponentType(String type) + { + this.type = type; + } + + public static final FilePlanComponentType getFilePlanComponentType(String type) + { + switch (type) + { + case "rma:filePlan": + return FILE_PLAN_TYPE; + case "rma:recordCategory": + return RECORD_CATEGORY_TYPE; + case "rma:recordFolder": + return RECORD_FOLDER_TYPE; + case "rma:hold": + return HOLD_TYPE; + case "rma:unfiledRecordFolder": + return UNFILED_RECORD_FOLDER_TYPE; + } + + throw new IllegalArgumentException("Invalid file plan component type enum value: '" + type + "'."); + } + + /** + * @see java.lang.Enum#toString() + */ + @Override + public String toString() + { + return this.type; + } +} diff --git a/src/main/java/org/alfresco/com/util/ParameterCheck.java b/src/main/java/org/alfresco/com/util/ParameterCheck.java new file mode 100644 index 0000000000..533fbe6573 --- /dev/null +++ b/src/main/java/org/alfresco/com/util/ParameterCheck.java @@ -0,0 +1,57 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.com.util; + +import static org.apache.commons.lang3.StringUtils.isBlank; + +/** + * Utility class for checking parameters + * + * @author Tuna Aksoy + * @since 1.0 + */ +public class ParameterCheck +{ + private ParameterCheck() + { + // Intentionally blank + } + + /** + * FIXME: Document me :) + * + * @param paramName FIXME: Document me :) + * @param paramValue FIXME: Document me :) + * @throws IllegalArgumentException FIXME: Document me :) + */ + public static void mandatoryString(final String paramName, final String paramValue) throws IllegalArgumentException + { + if (isBlank(paramValue)) + { + throw new IllegalArgumentException("'" + paramName + "' is a mandatory parameter."); + } + } + + /** + * FIXME: Document me :) + * + * @param paramName FIXME: Document me :) + * @param object FIXME: Document me :) + */ + public static void mandatoryObject(final String paramName, final Object object) + { + if (object == null) + { + throw new IllegalArgumentException("'" + paramName + "' is a mandatory parameter."); + } + } +} diff --git a/src/main/java/org/alfresco/rest/body/IgJsonBodyGenerator.java b/src/main/java/org/alfresco/rest/body/IgJsonBodyGenerator.java deleted file mode 100644 index 69e7665db7..0000000000 --- a/src/main/java/org/alfresco/rest/body/IgJsonBodyGenerator.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * License rights for this program may be obtained from Alfresco Software, Ltd. - * pursuant to a written agreement and any use of this program without such an - * agreement is prohibited. - * #L% - */ -package org.alfresco.rest.body; - -import javax.json.Json; -import javax.json.JsonBuilderFactory; -import javax.json.JsonObjectBuilder; - -import org.alfresco.rest.model.PropertiesModel; -import org.alfresco.rest.model.RestFilePlanComponentModel; - -/** - * Helper for building JSON objects - * @author Kristijan Conkas - * @since 2.6 - */ -public class IgJsonBodyGenerator -{ - private static JsonBuilderFactory jsonBuilderFactory; - - /** - * @return the initialized JSON builder factory - */ - private static JsonBuilderFactory getJsonBuilder() - { - if (jsonBuilderFactory == null) - { - return Json.createBuilderFactory(null); - } - else - { - return jsonBuilderFactory; - } - } - - /** - * Generate request body for create API calls - * @param model - * @return request body JSON string - */ - public static String filePlanComponentCreate(RestFilePlanComponentModel model) - { - PropertiesModel properties = model.getProperties(); - JsonObjectBuilder valueBuilder = getJsonBuilder() - .createObjectBuilder() - .add("name", model.getName()) - .add("nodeType", model.getNodeType()); - if (properties != null) - { - // handle properties - JsonObjectBuilder propertiesBuilder = getJsonBuilder().createObjectBuilder(); - if (properties.getTitle() != null) - { - propertiesBuilder.add("cm:title", properties.getTitle()); - } - valueBuilder.add("properties", propertiesBuilder.build()); - } - return valueBuilder.build().toString(); - } - - /** - * Generate request body for update API calls - * @param model - * @return request body JSON string - */ - public static String filePlanComponentUpdate(RestFilePlanComponentModel model) - { - PropertiesModel properties = model.getProperties(); - JsonObjectBuilder valueBuilder = getJsonBuilder() - .createObjectBuilder() - .add("name", model.getName()); - if (properties != null) - { - // handle properties - JsonObjectBuilder propertiesBuilder = getJsonBuilder().createObjectBuilder(); - if (properties.getTitle() != null) - { - propertiesBuilder.add("cm:title", properties.getTitle()); - } - valueBuilder.add("properties", propertiesBuilder.build()); - } - return valueBuilder.build().toString(); - } -} diff --git a/src/main/java/org/alfresco/rest/model/RestFilePlanComponentModel.java b/src/main/java/org/alfresco/rest/model/FilePlanComponent.java similarity index 88% rename from src/main/java/org/alfresco/rest/model/RestFilePlanComponentModel.java rename to src/main/java/org/alfresco/rest/model/FilePlanComponent.java index 96c6d7a374..9403411bed 100644 --- a/src/main/java/org/alfresco/rest/model/RestFilePlanComponentModel.java +++ b/src/main/java/org/alfresco/rest/model/FilePlanComponent.java @@ -11,6 +11,8 @@ */ package org.alfresco.rest.model; +import static org.alfresco.com.FilePlanComponentFields.PROPERTIES; + import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; @@ -18,29 +20,36 @@ import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; /** - * FIXME: Document me :) + * POJO for file plan component * * @author Tuna Aksoy * @since 1.0 */ @Component @Scope(value = "prototype") -//FIXME: Once the fields have been added this annotation should be removed +//FIXME: Once the fields have been added the JsonIgnoreProperties annotation should be removed @JsonIgnoreProperties(ignoreUnknown = true) -public class RestFilePlanComponentModel +public class FilePlanComponent { private String id; + private String parentId; + private String name; + private String nodeType; + private boolean isCategory; + private boolean isRecordFolder; + private boolean isFile; + private boolean hasRetentionSchedule; - - @JsonProperty(value = "properties") - private PropertiesModel properties; - + + @JsonProperty(PROPERTIES) + private FilePlanComponentProperties properties; + /** * @return the id */ @@ -172,7 +181,7 @@ public class RestFilePlanComponentModel /** * @return the properties */ - public PropertiesModel getProperties() + public FilePlanComponentProperties getProperties() { return properties; } @@ -180,7 +189,7 @@ public class RestFilePlanComponentModel /** * @param properties the properties to set */ - public void setProperties(PropertiesModel properties) + public void setProperties(FilePlanComponentProperties properties) { this.properties = properties; } diff --git a/src/main/java/org/alfresco/rest/model/PropertiesModel.java b/src/main/java/org/alfresco/rest/model/FilePlanComponentProperties.java similarity index 74% rename from src/main/java/org/alfresco/rest/model/PropertiesModel.java rename to src/main/java/org/alfresco/rest/model/FilePlanComponentProperties.java index 03afc0cf3c..311779450e 100644 --- a/src/main/java/org/alfresco/rest/model/PropertiesModel.java +++ b/src/main/java/org/alfresco/rest/model/FilePlanComponentProperties.java @@ -11,6 +11,10 @@ */ package org.alfresco.rest.model; +import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_HOLD_REASON; +import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_TITLE; +import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR; + import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; @@ -18,26 +22,28 @@ import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; /** - * Fileplan component properties + * POJO for file plan component properties + * * @author Kristijan Conkas - * @since 2.6 + * @since 1.0 */ @Component @Scope(value = "prototype") +//FIXME: Once the fields have been added the JsonIgnoreProperties annotation should be removed @JsonIgnoreProperties(ignoreUnknown = true) -public class PropertiesModel +public class FilePlanComponentProperties { // TODO: handling individual properties is tedious and error prone, how about @JsonGetter + @JsonSetter? - - @JsonProperty("rma:vitalRecordIndicator") + + @JsonProperty(PROPERTIES_VITAL_RECORD_INDICATOR) private boolean vitalRecord; - - @JsonProperty("cm:title") + + @JsonProperty(PROPERTIES_TITLE) private String title; - - @JsonProperty("rma:holdReason") + + @JsonProperty(PROPERTIES_HOLD_REASON) private String holdReason; - + /** * @return the vitalRecord */ diff --git a/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java b/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java new file mode 100644 index 0000000000..460e4eb23c --- /dev/null +++ b/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java @@ -0,0 +1,145 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.rest.requests; + +import static org.alfresco.com.util.ParameterCheck.mandatoryObject; +import static org.alfresco.com.util.ParameterCheck.mandatoryString; +import static org.alfresco.rest.core.RestRequest.requestWithBody; +import static org.alfresco.rest.core.RestRequest.simpleRequest; +import static org.springframework.http.HttpMethod.DELETE; +import static org.springframework.http.HttpMethod.GET; +import static org.springframework.http.HttpMethod.POST; +import static org.springframework.http.HttpMethod.PUT; + +import com.google.gson.JsonObject; + +import org.alfresco.rest.core.RestAPI; +import org.alfresco.rest.model.FilePlanComponent; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +/** + * File plan component REST API Wrapper + * + * @author Tuna Aksoy + * @author Kristijan Conkas + * @since 1.0 + */ +@Component +@Scope(value = "prototype") +public class FilePlanComponentApi extends RestAPI +{ + /** + * Get a file plan component + * + * @param filePlanComponentId The id of the file plan component to get + * @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 FilePlanComponent getFilePlanComponent(String filePlanComponentId) throws Exception + { + mandatoryString("filePlanComponentId", filePlanComponentId); + + return usingRestWrapper().processModel(FilePlanComponent.class, simpleRequest( + GET, + "fileplan-components/{fileplanComponentId}", + filePlanComponentId + )); + } + + /** + * Creates a file plan component with the given properties under the parent node with the given id + * + * @param filePlanComponentProperties The properties of the file plan component to be created + * @param parentId The id of the parent where the new file plan component should be created + * @return The {@link FilePlanComponent} with the given properties + * @throws Exception for the following cases: + *
    + *
  • {@code fileplanComponentId} is not a valid format
  • + *
  • authentication fails
  • + *
  • current user does not have permission to add children to {@code fileplanComponentId}
  • + *
  • {@code fileplanComponentId} does not exist
  • + *
  • new name clashes with an existing node in the current parent container
  • + *
  • model integrity exception, including node name with invalid characters
  • + *
+ */ + public FilePlanComponent createFilePlanComponent(JsonObject filePlanComponentProperties, String parentId) throws Exception + { + mandatoryObject("filePlanComponentProperties", filePlanComponentProperties); + mandatoryString("parentId", parentId); + + return usingRestWrapper().processModel(FilePlanComponent.class, requestWithBody( + POST, + filePlanComponentProperties.toString(), + "fileplan-components/{fileplanComponentId}/children", + parentId + )); + } + + /** + * Updates a file plan component + * + * @param filePlanComponentProperties The properties to be updated + * @param filePlanComponentId The id of the file plan component which will be updated + * @param returns The updated {@link FilePlanComponent} + * @throws Exception for the following cases: + *
    + *
  • the update request is invalid or {@code fileplanComponentId} is not a valid format or {@code filePlanComponentProperties} is invalid
  • + *
  • authentication fails
  • + *
  • current user does not have permission to update {@code fileplanComponentId}
  • + *
  • {@code fileplanComponentId} does not exist
  • + *
  • the updated name clashes with an existing node in the current parent folder
  • + *
  • model integrity exception, including node name with invalid characters
  • + *
+ */ + public FilePlanComponent updateFilePlanComponent(JsonObject filePlanComponentProperties, String filePlanComponentId) throws Exception + { + mandatoryObject("filePlanComponentProperties", filePlanComponentProperties); + mandatoryString("filePlanComponentId", filePlanComponentId); + + return usingRestWrapper().processModel(FilePlanComponent.class, requestWithBody( + PUT, + filePlanComponentProperties.toString(), + "fileplan-components/{fileplanComponentId}", + filePlanComponentId + )); + } + + /** + * Delete file plan component + * + * @param filePlanComponentId The id of the file plan component to be deleted + * @throws Exception for the following cases: + *
    + *
  • {@code fileplanComponentId} is not a valid format
  • + *
  • authentication fails
  • + *
  • current user does not have permission to delete {@code fileplanComponentId}
  • + *
  • {@code fileplanComponentId} does not exist
  • + *
  • {@code fileplanComponentId} is locked and cannot be deleted
  • + *
+ */ + public void deleteFilePlanComponent(String filePlanComponentId) throws Exception + { + mandatoryString("filePlanComponentId", filePlanComponentId); + + usingRestWrapper().processEmptyModel(simpleRequest( + DELETE, + "fileplan-components/{fileplanComponentId}", + filePlanComponentId + )); + } +} diff --git a/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java b/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java deleted file mode 100644 index ca52c13f30..0000000000 --- a/src/main/java/org/alfresco/rest/requests/RestFilePlanComponentApi.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * License rights for this program may be obtained from Alfresco Software, Ltd. - * pursuant to a written agreement and any use of this program without such an - * agreement is prohibited. - * #L% - */ -package org.alfresco.rest.requests; - -import static org.alfresco.rest.body.IgJsonBodyGenerator.filePlanComponentCreate; -import static org.alfresco.rest.body.IgJsonBodyGenerator.filePlanComponentUpdate; -import static org.alfresco.rest.core.RestRequest.requestWithBody; -import static org.alfresco.rest.core.RestRequest.simpleRequest; - -import static org.springframework.http.HttpMethod.DELETE; -import static org.springframework.http.HttpMethod.GET; -import static org.springframework.http.HttpMethod.POST; -import static org.springframework.http.HttpMethod.PUT; - -import org.alfresco.rest.core.RestAPI; -import org.alfresco.rest.core.RestRequest; -import org.alfresco.rest.model.RestFilePlanComponentModel; -import org.json.JSONObject; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; - -/** - * REST wrapper for IG APIs - * - * @author Tuna Aksoy - * @author kconkas - * @since 1.0 - */ -@Component -@Scope(value = "prototype") -public class RestFilePlanComponentApi extends RestAPI -{ - /** - * Get file plan component - * @param filePlanComponentId - * @return {@link RestFilePlanComponentModel} for filePlanComponentId - * @throws Exception for non-existent components - */ - public RestFilePlanComponentModel getFilePlanComponent(String filePlanComponentId) throws Exception - { - RestRequest request = simpleRequest(GET, "fileplan-components/{fileplanComponentId}", filePlanComponentId); - return usingRestWrapper().processModel(RestFilePlanComponentModel.class, request); - } - - /** - * Create file plan component - * @param model - * @return - * @throws Exception - */ - public RestFilePlanComponentModel createFilePlanComponent(RestFilePlanComponentModel model) throws Exception - { - RestRequest request = requestWithBody(POST, - filePlanComponentCreate(model).toString(), - "fileplan-components/{fileplanComponentId}/children", - model.getId()); - return usingRestWrapper().processModel(RestFilePlanComponentModel.class, request); - } - - /** - * Update file plan component - * @param update {@link RestFilePlanComponentModel} to update - * @param returns updated {@link RestFilePlanComponentModel} - * @throws Exception - */ - public RestFilePlanComponentModel updateFilePlanComponent(RestFilePlanComponentModel update) throws Exception - { - RestRequest request = requestWithBody(PUT, - filePlanComponentUpdate(update).toString(), - "fileplan-components/{fileplanComponentId}", - update.getId()); - return usingRestWrapper().processModel(RestFilePlanComponentModel.class, request); - } - - /** - * Delete file plan component - * @param delete {@link RestFilePlanComponentModel} to delete - * @param deletePermanently if set to true delete without moving to the trashcan - * @throws Exception - */ - public RestRequest deleteFilePlanComponent(RestFilePlanComponentModel delete, boolean deletePermanently) throws Exception - { - JSONObject body = new JSONObject(); - if (deletePermanently) body.put("permanent", deletePermanently); - - RestRequest request = requestWithBody(DELETE, body.toString(), "fileplan-components/{fileplanComponentId}", delete.getId()); - usingRestWrapper().processEmptyModel(request); - return request; - } -} diff --git a/src/test/java/org/alfresco/rest/BaseIgRestTest.java b/src/test/java/org/alfresco/rest/BaseRestTest.java similarity index 64% rename from src/test/java/org/alfresco/rest/BaseIgRestTest.java rename to src/test/java/org/alfresco/rest/BaseRestTest.java index 9471f9393c..7ff9a538e6 100644 --- a/src/test/java/org/alfresco/rest/BaseIgRestTest.java +++ b/src/test/java/org/alfresco/rest/BaseRestTest.java @@ -25,26 +25,13 @@ import org.testng.annotations.BeforeClass; * * @author Kristijan Conkas * @author Tuna Aksoy - * @since 2.6 + * @since 1.0 */ @Configuration @PropertySource("classpath:config.properties") @PropertySource(value = "classpath:local.properties", ignoreResourceNotFound = true) -public class BaseIgRestTest extends RestTest +public class BaseRestTest extends RestTest { - /** Alias which can be used instead of the identifier of a node. */ - public static final String ALIAS_FILE_PLAN = "-filePlan-"; - public static final String ALIAS_TRANSFERS = "-transfers-"; - public static final String ALIAS_UNFILED_RECORDS_CONTAINER = "-unfiled-"; - public static final String ALIAS_HOLDS = "-holds-"; - - /** Component types. */ - public static final String COMPONENT_FILE_PLAN = "rma:filePlan"; - public static final String COMPONENT_RECORD_CATEGORY = "rma:recordCategory"; - public static final String COMPONENT_RECORD_FOLDER = "rma:recordFolder"; - public static final String COMPONENT_HOLD = "rma:hold"; - public static final String COMPONENT_UNFILED_RECORD_FOLDER = "rma:unfiledRecordFolder"; - @Value("${alfresco.rm.scheme}") private String scheme; diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTest.java deleted file mode 100644 index c55698e0ce..0000000000 --- a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * License rights for this program may be obtained from Alfresco Software, Ltd. - * pursuant to a written agreement and any use of this program without such an - * agreement is prohibited. - * #L% - */ -package org.alfresco.rest.fileplancomponents; - -import static org.springframework.http.HttpStatus.OK; -import static org.testng.Assert.assertEquals; - -import org.alfresco.rest.BaseIgRestTest; -import org.alfresco.rest.core.RestWrapper; -import org.alfresco.rest.model.RestFilePlanComponentModel; -import org.alfresco.rest.requests.RestFilePlanComponentApi; -import org.alfresco.utility.data.DataUser; -import org.springframework.beans.factory.annotation.Autowired; -import org.testng.annotations.Test; - -/** - * FIXME: Document me :) - * - * @author Tuna Aksoy - * @since 1.0 - */ -public class FilePlanTest extends BaseIgRestTest -{ - @Autowired - private RestFilePlanComponentApi filePlanComponentApi; - - @Autowired - private DataUser dataUser; - - @Test - public void testfilePlanComponentsGet() throws Exception - { - RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper(); - restWrapper.authenticateUser(dataUser.getAdminUser()); - RestFilePlanComponentModel filePlanComponent = filePlanComponentApi.getFilePlanComponent(ALIAS_FILE_PLAN); - restWrapper.assertStatusCodeIs(OK); - assertEquals(filePlanComponent.getNodeType(), COMPONENT_FILE_PLAN); - } -} diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java index 2c216d3cdc..54dce68633 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java @@ -11,114 +11,155 @@ */ package org.alfresco.rest.fileplancomponents; -import java.util.UUID; +import static java.util.UUID.randomUUID; -import org.alfresco.rest.BaseIgRestTest; +import static org.alfresco.com.FilePlanComponentAlias.FILE_PLAN_ALIAS; +import static org.alfresco.com.FilePlanComponentFields.NAME; +import static org.alfresco.com.FilePlanComponentFields.NODE_TYPE; +import static org.alfresco.com.FilePlanComponentFields.PROPERTIES; +import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_TITLE; +import static org.alfresco.com.FilePlanComponentType.RECORD_CATEGORY_TYPE; +import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; +import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.NO_CONTENT; +import static org.springframework.http.HttpStatus.OK; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import com.google.gson.JsonObject; + +import org.alfresco.rest.BaseRestTest; import org.alfresco.rest.core.RestWrapper; -import org.alfresco.rest.model.PropertiesModel; -import org.alfresco.rest.model.RestFilePlanComponentModel; -import org.alfresco.rest.requests.RestFilePlanComponentApi; +import org.alfresco.rest.model.FilePlanComponent; +import org.alfresco.rest.model.FilePlanComponentProperties; +import org.alfresco.rest.requests.FilePlanComponentApi; import org.alfresco.utility.data.DataUser; import org.springframework.beans.factory.annotation.Autowired; import org.testng.annotations.Test; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.assertNotNull; -import static org.springframework.http.HttpStatus.CREATED; -import static org.springframework.http.HttpStatus.OK; -import static org.springframework.http.HttpStatus.NO_CONTENT; - - /** + * FIXME: Document me :) * * @author Kristijan Conkas - * @since + * @author Tuna Aksoy + * @since 1.0 */ -public class RecordCategoryTest extends BaseIgRestTest +public class RecordCategoryTest extends BaseRestTest { @Autowired - private RestFilePlanComponentApi filePlanComponentApi; + private FilePlanComponentApi filePlanComponentApi; @Autowired private DataUser dataUser; - - @Autowired - private RestFilePlanComponentModel componentModel; - - @Autowired - private PropertiesModel propertiesModel; - - /** new category name */ - private String categoryName = "cat " + UUID.randomUUID().toString().substring(0, 8); - - private String newCategoryId = null; - + @Test ( description = "Create category as authorised user" ) public void createCategoryAsAuthorisedUser() throws Exception { - // create category - propertiesModel.setTitle("New Test File Plan"); - componentModel.setId(ALIAS_FILE_PLAN ); - componentModel.setName(categoryName); - componentModel.setNodeType(COMPONENT_RECORD_CATEGORY); - componentModel.setProperties(propertiesModel); - RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - RestFilePlanComponentModel filePlanComponent = filePlanComponentApi.createFilePlanComponent(componentModel); - - // verify returned object + + String categoryName = "Category name " + randomUUID().toString().substring(0, 8); + String categoryTitle = "Category title " + randomUUID().toString().substring(0, 8); + + // Build the record category properties + JsonObject recordCategoryProperties = buildObject(). + add(NAME, categoryName). + add(NODE_TYPE, RECORD_CATEGORY_TYPE.toString()). + addObject(PROPERTIES). + add(PROPERTIES_TITLE, categoryTitle). + end(). + getJson(); + + // Create the record category + FilePlanComponent filePlanComponent = filePlanComponentApi.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString()); + + // Verify the status code restWrapper.assertStatusCodeIs(CREATED); + + // Verify the returned file plan component assertTrue(filePlanComponent.isIsCategory()); assertEquals(filePlanComponent.getName(), categoryName); - assertEquals(filePlanComponent.getNodeType(), COMPONENT_RECORD_CATEGORY.toString()); - assertFalse(filePlanComponent.getProperties().isVitalRecord()); - - newCategoryId = filePlanComponent.getId(); + assertEquals(filePlanComponent.getNodeType(), RECORD_CATEGORY_TYPE.toString()); + + // Verify the returned file plan component properties + FilePlanComponentProperties filePlanComponentProperties = filePlanComponent.getProperties(); + assertEquals(filePlanComponentProperties.getTitle(), categoryTitle); } - + @Test ( - description = "Rename category as authorised user", - dependsOnMethods= { "createCategoryAsAuthorisedUser" } - ) + description = "Rename category as authorised user" + ) public void renameCategoryAsAuthorisedUser() throws Exception { - assertNotNull(newCategoryId); - String newName = "renamed " + categoryName; - - RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper(); - restWrapper.authenticateUser(dataUser.getAdminUser()); - - RestFilePlanComponentModel filePlanComponent = filePlanComponentApi.getFilePlanComponent(newCategoryId); - filePlanComponent.setName(newName); - - RestFilePlanComponentModel renamedFilePlanComponent = filePlanComponentApi.updateFilePlanComponent(filePlanComponent); + RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - // verify returned object + // Create record category first + + String categoryName = "Category name " + randomUUID().toString().substring(0, 8); + String categoryTitle = "Category title " + randomUUID().toString().substring(0, 8); + + // Build the record category properties + JsonObject recordCategoryProperties = buildObject(). + add(NAME, categoryName). + add(NODE_TYPE, RECORD_CATEGORY_TYPE.toString()). + addObject(PROPERTIES). + add(PROPERTIES_TITLE, categoryTitle). + end(). + getJson(); + + // Create the record category + FilePlanComponent filePlanComponent = filePlanComponentApi.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString()); + + + String newCategoryName = "Rename " + categoryName; + + // Build the properties which will be updated + JsonObject updateRecordCategoryProperties = buildObject(). + add(NAME, newCategoryName). + getJson(); + + // Update the record category + FilePlanComponent renamedFilePlanComponent = filePlanComponentApi.updateFilePlanComponent(updateRecordCategoryProperties, filePlanComponent.getId()); + + // Verify the status code restWrapper.assertStatusCodeIs(OK); - assertEquals(renamedFilePlanComponent.getName(), newName); + + // Verify the returned file plan component + assertEquals(renamedFilePlanComponent.getName(), newCategoryName); } @Test ( - description = "Rename category as authorised user", - dependsOnMethods= { "renameCategoryAsAuthorisedUser" } + description = "Rename category as authorised user" ) public void deleteCategoryAsAuthorisedUser() throws Exception { - // delete - RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper(); - restWrapper.authenticateUser(dataUser.getAdminUser()); - filePlanComponentApi.deleteFilePlanComponent(filePlanComponentApi.getFilePlanComponent(newCategoryId), true); + RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - // verify deletion + // Create record category first + + String categoryName = "Category name " + randomUUID().toString().substring(0, 8); + String categoryTitle = "Category title " + randomUUID().toString().substring(0, 8); + + // Build the record category properties + JsonObject recordCategoryProperties = buildObject(). + add(NAME, categoryName). + add(NODE_TYPE, RECORD_CATEGORY_TYPE.toString()). + addObject(PROPERTIES). + add(PROPERTIES_TITLE, categoryTitle). + end(). + getJson(); + + // Create the record category + FilePlanComponent filePlanComponent = filePlanComponentApi.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString()); + + // Delete the record category + filePlanComponentApi.deleteFilePlanComponent(filePlanComponent.getId()); + + // Verify the status code restWrapper.assertStatusCodeIs(NO_CONTENT); - // TODO: verify we can't get an object with this ID again - // TODO: can we verify that deletion with deletePermanently=false indeed ended up in trashcan? } } From fefee35dac8436d91839b5bd86aa9bc282581d36 Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Tue, 25 Oct 2016 16:45:47 +0100 Subject: [PATCH 14/49] RM-3964: Refactoring further to API implementation discussion. --- .../rest/model/FilePlanComponent.java | 7 +- .../model/FilePlanComponentsCollection.java | 24 +++ .../rest/requests/FilePlanComponentApi.java | 24 +++ .../RecordCategoryTest.java | 145 +++++++++++++++++- 4 files changed, 192 insertions(+), 8 deletions(-) create mode 100644 src/main/java/org/alfresco/rest/model/FilePlanComponentsCollection.java diff --git a/src/main/java/org/alfresco/rest/model/FilePlanComponent.java b/src/main/java/org/alfresco/rest/model/FilePlanComponent.java index 9403411bed..efe28755fc 100644 --- a/src/main/java/org/alfresco/rest/model/FilePlanComponent.java +++ b/src/main/java/org/alfresco/rest/model/FilePlanComponent.java @@ -16,21 +16,16 @@ import static org.alfresco.com.FilePlanComponentFields.PROPERTIES; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; - /** * POJO for file plan component * * @author Tuna Aksoy * @since 1.0 */ -@Component -@Scope(value = "prototype") //FIXME: Once the fields have been added the JsonIgnoreProperties annotation should be removed @JsonIgnoreProperties(ignoreUnknown = true) public class FilePlanComponent -{ +{ private String id; private String parentId; diff --git a/src/main/java/org/alfresco/rest/model/FilePlanComponentsCollection.java b/src/main/java/org/alfresco/rest/model/FilePlanComponentsCollection.java new file mode 100644 index 0000000000..8f8f9e1eba --- /dev/null +++ b/src/main/java/org/alfresco/rest/model/FilePlanComponentsCollection.java @@ -0,0 +1,24 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.rest.model; + +import org.alfresco.rest.core.RestModels; + +/** + * Handle collection of FilePlanComponents + * @author Kristijan Conkas + * @since 1.0 + */ +public class FilePlanComponentsCollection extends RestModels +{ + +} diff --git a/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java b/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java index 460e4eb23c..f2764539c6 100644 --- a/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java +++ b/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java @@ -24,6 +24,7 @@ import com.google.gson.JsonObject; import org.alfresco.rest.core.RestAPI; import org.alfresco.rest.model.FilePlanComponent; +import org.alfresco.rest.model.FilePlanComponentsCollection; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @@ -61,6 +62,29 @@ public class FilePlanComponentApi extends RestAPI )); } + /** + * List child components of a file plan component + * + * @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) throws Exception + { + mandatoryString("filePlanComponentId", filePlanComponentId); + + return usingRestWrapper().processModels(FilePlanComponentsCollection.class, simpleRequest( + GET, + "fileplan-components/{fileplanComponentId}/children", + filePlanComponentId + )); + } + /** * Creates a file plan component with the given properties under the parent node with the given id * diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java index 54dce68633..3fe829770c 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java @@ -19,21 +19,29 @@ import static org.alfresco.com.FilePlanComponentFields.NODE_TYPE; import static org.alfresco.com.FilePlanComponentFields.PROPERTIES; import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_TITLE; import static org.alfresco.com.FilePlanComponentType.RECORD_CATEGORY_TYPE; +import static org.alfresco.com.FilePlanComponentType.RECORD_FOLDER_TYPE; import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.NO_CONTENT; import static org.springframework.http.HttpStatus.OK; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; +import java.util.ArrayList; +import java.util.List; + import com.google.gson.JsonObject; +import org.alfresco.com.FilePlanComponentType; import org.alfresco.rest.BaseRestTest; import org.alfresco.rest.core.RestWrapper; import org.alfresco.rest.model.FilePlanComponent; import org.alfresco.rest.model.FilePlanComponentProperties; +import org.alfresco.rest.model.FilePlanComponentsCollection; import org.alfresco.rest.requests.FilePlanComponentApi; import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.data.RandomData; import org.springframework.beans.factory.annotation.Autowired; import org.testng.annotations.Test; @@ -51,7 +59,16 @@ public class RecordCategoryTest extends BaseRestTest @Autowired private DataUser dataUser; + + // for children creation test + private static final int NUMBER_OF_CHILDREN = 10; + /** + *
+     * Given that a file plan exists
+     * When I ask the API to create a root record category
+     * Then it is created as a root record category
+     */
     @Test
     (
         description = "Create category as authorised user"
@@ -88,6 +105,12 @@ public class RecordCategoryTest extends BaseRestTest
         assertEquals(filePlanComponentProperties.getTitle(), categoryTitle);
     }
 
+    /**
+     * 
+     * Given that a record category exists
+     * When I ask the API to update the details of the record category
+     * Then the details of the record category are updated
+     */
     @Test
     (
         description = "Rename category as authorised user"
@@ -113,7 +136,6 @@ public class RecordCategoryTest extends BaseRestTest
         // Create the record category
         FilePlanComponent filePlanComponent = filePlanComponentApi.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString());
 
-
         String newCategoryName = "Rename " + categoryName;
 
         // Build the properties which will be updated
@@ -131,9 +153,15 @@ public class RecordCategoryTest extends BaseRestTest
         assertEquals(renamedFilePlanComponent.getName(), newCategoryName);
     }
 
+    /**
+     * 
+     * Given that a record category exists
+     * When I ask the API to delete the record category
+     * Then the record category and all its contents is deleted
+     */
     @Test
     (
-        description = "Rename category as authorised user"
+        description = "Delete category as authorised user"
     )
     public void deleteCategoryAsAuthorisedUser() throws Exception
     {
@@ -162,4 +190,117 @@ public class RecordCategoryTest extends BaseRestTest
         // Verify the status code
         restWrapper.assertStatusCodeIs(NO_CONTENT);
     }
+    
+    /**
+     * 
+     * Given that a record category exists
+     * When I ask the API to create a record category
+     * Then it is created within the record category
+     */
+    @Test
+    (
+        description = "Create child category"
+    )
+    public void createSubcategory() throws Exception
+    {
+        // create root level category
+        FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), RandomData.getRandomAlphanumeric());
+        assertNotNull(rootCategory.getId());
+        
+        // create subcategory as a child of rootCategory
+        FilePlanComponent childCategory = createCategory(rootCategory.getId(), RandomData.getRandomAlphanumeric());
+        // child category created?
+        assertNotNull(childCategory.getId());
+    }
+    
+    /**
+     * 
+     * Given that a record category exists
+     * And contains a number of record categories and record folders
+     * When I ask the APi to get me the children of the record category
+     * Then I am returned the contained record categories and record folders
+     * And their details
+     */
+    @Test
+    (
+        description = "List children of a category"
+    )
+    public void listChildren() throws Exception
+    {
+        // create root level category
+        FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), RandomData.getRandomAlphanumeric());
+        assertNotNull(rootCategory.getId());
+        
+        // add child categories/folders
+        ArrayList children = new ArrayList();
+        for(int i=0; i < NUMBER_OF_CHILDREN; i++)
+        {
+            // create a child
+            FilePlanComponent child = createComponent(rootCategory.getId(), 
+                RandomData.getRandomAlphanumeric(),
+                // half of the children should be subcategories, the other subfolders
+                (i <= NUMBER_OF_CHILDREN / 2) ? RECORD_CATEGORY_TYPE : RECORD_FOLDER_TYPE);
+            assertNotNull(child.getId());
+            children.add(child);
+        }
+        
+        // list children from API
+        RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
+        FilePlanComponentsCollection apiChildren = filePlanComponentApi.listChildComponents(rootCategory.getId());
+        restWrapper.assertStatusCodeIs(OK);
+        
+        List childrenApi = apiChildren.getEntries();
+        childrenApi.forEach(c -> {
+            //assertNotNull(c.getId());
+            
+            logger.info(c + " id=" + c.getId() + " name=" + c.getName() + " properties=" + c.getProperties());
+        });
+    }
+    
+    /**
+     * Helper method to create child category
+     * @param parentCategoryId
+     * @param categoryName
+     * @throws Exception on unsuccessful component creation
+     */
+    private FilePlanComponent createCategory(String parentCategoryId, String categoryName) throws Exception
+    {
+        return createComponent(parentCategoryId, categoryName, RECORD_CATEGORY_TYPE);
+    }
+    
+    /**
+     * Helper method to create child folder
+     * @param parentComponentId parent category or folder id
+     * @param folderName new folder name
+     * @throws Exception on unsuccessful folder creation
+     */
+    private FilePlanComponent createFolder(String parentComponentId, String folderName) throws Exception
+    {
+        return createComponent(parentComponentId, folderName, RECORD_FOLDER_TYPE);
+    }
+    
+    /**
+     * Helper method to create generic child component
+     * @param parentComponentId
+     * @param componentName
+     * @param componentType
+     * @return
+     * @throws Exception
+     */
+    private FilePlanComponent createComponent(String parentComponentId, String componentName, FilePlanComponentType componentType) throws Exception
+    {
+        RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
+
+        JsonObject componentProperties = buildObject().
+            add(NAME, componentName).
+            add(NODE_TYPE, componentType.toString()).
+            addObject(PROPERTIES).
+                add(PROPERTIES_TITLE, "Title for " + componentName).
+                end().
+            getJson();
+
+        FilePlanComponent fpc = filePlanComponentApi.createFilePlanComponent(componentProperties, parentComponentId);
+        restWrapper.assertStatusCodeIs(CREATED);
+        return fpc;
+    }
 }

From de55e85ec4733976aeaafd4d3e2b79625938cba0 Mon Sep 17 00:00:00 2001
From: Tuna Aksoy 
Date: Tue, 25 Oct 2016 20:14:47 +0100
Subject: [PATCH 15/49] Refactored RM site creation related code

---
 .../FilePlanComponentAlias.java               |   2 +-
 .../FilePlanComponentFields.java              |   2 +-
 .../FilePlanComponentType.java                |   2 +-
 .../alfresco/com/site/RMSiteCompliance.java   |  24 ++++
 .../org/alfresco/com/site/RMSiteFields.java   |  26 ++++
 .../FilePlanComponent.java                    |   4 +-
 .../FilePlanComponentProperties.java          |   8 +-
 .../org/alfresco/rest/model/site/RMSite.java  |  49 +++++++
 .../rest/requests/FilePlanComponentApi.java   |   2 +-
 .../org/alfresco/rest/requests/RMSiteAPI.java |  93 +++++++++++++
 .../rest/fileplancomponents/RMSiteTests.java  | 127 ++++++++++++++++++
 .../RecordCategoryTest.java                   |  16 +--
 12 files changed, 337 insertions(+), 18 deletions(-)
 rename src/main/java/org/alfresco/com/{ => fileplancomponents}/FilePlanComponentAlias.java (96%)
 rename src/main/java/org/alfresco/com/{ => fileplancomponents}/FilePlanComponentFields.java (94%)
 rename src/main/java/org/alfresco/com/{ => fileplancomponents}/FilePlanComponentType.java (97%)
 create mode 100644 src/main/java/org/alfresco/com/site/RMSiteCompliance.java
 create mode 100644 src/main/java/org/alfresco/com/site/RMSiteFields.java
 rename src/main/java/org/alfresco/rest/model/{ => fileplancomponents}/FilePlanComponent.java (96%)
 rename src/main/java/org/alfresco/rest/model/{ => fileplancomponents}/FilePlanComponentProperties.java (85%)
 create mode 100644 src/main/java/org/alfresco/rest/model/site/RMSite.java
 create mode 100644 src/main/java/org/alfresco/rest/requests/RMSiteAPI.java
 create mode 100644 src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java

diff --git a/src/main/java/org/alfresco/com/FilePlanComponentAlias.java b/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentAlias.java
similarity index 96%
rename from src/main/java/org/alfresco/com/FilePlanComponentAlias.java
rename to src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentAlias.java
index 13dc3dbd68..45ada4d9ec 100644
--- a/src/main/java/org/alfresco/com/FilePlanComponentAlias.java
+++ b/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentAlias.java
@@ -9,7 +9,7 @@
  * agreement is prohibited.
  * #L%
  */
-package org.alfresco.com;
+package org.alfresco.com.fileplancomponents;
 
 /**
  * File plan component alias enumeration
diff --git a/src/main/java/org/alfresco/com/FilePlanComponentFields.java b/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentFields.java
similarity index 94%
rename from src/main/java/org/alfresco/com/FilePlanComponentFields.java
rename to src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentFields.java
index 76b91035c4..0f9b959462 100644
--- a/src/main/java/org/alfresco/com/FilePlanComponentFields.java
+++ b/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentFields.java
@@ -9,7 +9,7 @@
  * agreement is prohibited.
  * #L%
  */
-package org.alfresco.com;
+package org.alfresco.com.fileplancomponents;
 
 /**
  * FIXME: Document me :)
diff --git a/src/main/java/org/alfresco/com/FilePlanComponentType.java b/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentType.java
similarity index 97%
rename from src/main/java/org/alfresco/com/FilePlanComponentType.java
rename to src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentType.java
index 432178c75e..ebf8cc070d 100644
--- a/src/main/java/org/alfresco/com/FilePlanComponentType.java
+++ b/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentType.java
@@ -9,7 +9,7 @@
  * agreement is prohibited.
  * #L%
  */
-package org.alfresco.com;
+package org.alfresco.com.fileplancomponents;
 
 /**
  * File plan component type enumeration
diff --git a/src/main/java/org/alfresco/com/site/RMSiteCompliance.java b/src/main/java/org/alfresco/com/site/RMSiteCompliance.java
new file mode 100644
index 0000000000..84dd6b00f6
--- /dev/null
+++ b/src/main/java/org/alfresco/com/site/RMSiteCompliance.java
@@ -0,0 +1,24 @@
+/*
+ * #%L
+ * Alfresco Records Management Module
+ * %%
+ * Copyright (C) 2005 - 2016 Alfresco Software Limited
+ * %%
+ * License rights for this program may be obtained from Alfresco Software, Ltd.
+ * pursuant to a written agreement and any use of this program without such an
+ * agreement is prohibited.
+ * #L%
+ */
+package org.alfresco.com.site;
+
+/**
+ * FIXME: Document me :)
+ *
+ * @author Tuna Aksoy
+ * @since 1.0
+ */
+public enum RMSiteCompliance
+{
+    STANDARD,
+    DOD5015;
+}
diff --git a/src/main/java/org/alfresco/com/site/RMSiteFields.java b/src/main/java/org/alfresco/com/site/RMSiteFields.java
new file mode 100644
index 0000000000..d0ce8303b6
--- /dev/null
+++ b/src/main/java/org/alfresco/com/site/RMSiteFields.java
@@ -0,0 +1,26 @@
+/*
+ * #%L
+ * Alfresco Records Management Module
+ * %%
+ * Copyright (C) 2005 - 2016 Alfresco Software Limited
+ * %%
+ * License rights for this program may be obtained from Alfresco Software, Ltd.
+ * pursuant to a written agreement and any use of this program without such an
+ * agreement is prohibited.
+ * #L%
+ */
+package org.alfresco.com.site;
+
+/**
+ * FIXME: Document me :)
+ *
+ * @author Tuna Aksoy
+ * @since 1.0
+ */
+public class RMSiteFields
+{
+    public static final String ID = "id";
+    public static final String COMPLIANCE = "compliance";
+    public static final String TITLE = "title";
+    public static final String DESCRIPTION = "description";
+}
diff --git a/src/main/java/org/alfresco/rest/model/FilePlanComponent.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java
similarity index 96%
rename from src/main/java/org/alfresco/rest/model/FilePlanComponent.java
rename to src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java
index 9403411bed..420233847c 100644
--- a/src/main/java/org/alfresco/rest/model/FilePlanComponent.java
+++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java
@@ -9,9 +9,9 @@
  * agreement is prohibited.
  * #L%
  */
-package org.alfresco.rest.model;
+package org.alfresco.rest.model.fileplancomponents;
 
-import static org.alfresco.com.FilePlanComponentFields.PROPERTIES;
+import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES;
 
 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonProperty;
diff --git a/src/main/java/org/alfresco/rest/model/FilePlanComponentProperties.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java
similarity index 85%
rename from src/main/java/org/alfresco/rest/model/FilePlanComponentProperties.java
rename to src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java
index 311779450e..d51c86e52c 100644
--- a/src/main/java/org/alfresco/rest/model/FilePlanComponentProperties.java
+++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java
@@ -9,11 +9,11 @@
  * agreement is prohibited.
  * #L%
  */
-package org.alfresco.rest.model;
+package org.alfresco.rest.model.fileplancomponents;
 
-import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_HOLD_REASON;
-import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_TITLE;
-import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR;
+import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_HOLD_REASON;
+import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE;
+import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR;
 
 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonProperty;
diff --git a/src/main/java/org/alfresco/rest/model/site/RMSite.java b/src/main/java/org/alfresco/rest/model/site/RMSite.java
new file mode 100644
index 0000000000..680777f96f
--- /dev/null
+++ b/src/main/java/org/alfresco/rest/model/site/RMSite.java
@@ -0,0 +1,49 @@
+/*
+ * #%L
+ * Alfresco Records Management Module
+ * %%
+ * Copyright (C) 2005 - 2016 Alfresco Software Limited
+ * %%
+ * License rights for this program may be obtained from Alfresco Software, Ltd.
+ * pursuant to a written agreement and any use of this program without such an
+ * agreement is prohibited.
+ * #L%
+ */
+package org.alfresco.rest.model.site;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import org.alfresco.com.site.RMSiteCompliance;
+import org.alfresco.rest.model.RestSiteModel;
+
+/**
+ * FIXME: Document me :)
+ *
+ * @author Rodica Sutu
+ * @since 1.0
+ */
+public class RMSite extends RestSiteModel
+{
+    @JsonProperty (required = true)
+    protected RMSiteCompliance compliance;
+
+    /**
+     * FIXME: Document me :)
+     *
+     * @param compliance the compliance to set
+     */
+    public void setCompliance(RMSiteCompliance compliance)
+    {
+        this.compliance = compliance;
+    }
+
+    /**
+     * FIXME: Document me :)
+     *
+     * @return FIXME: Document me :)
+     */
+    public RMSiteCompliance getCompliance()
+    {
+        return compliance;
+    }
+}
diff --git a/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java b/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java
index 460e4eb23c..6da4b4ab49 100644
--- a/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java
+++ b/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java
@@ -23,7 +23,7 @@ import static org.springframework.http.HttpMethod.PUT;
 import com.google.gson.JsonObject;
 
 import org.alfresco.rest.core.RestAPI;
-import org.alfresco.rest.model.FilePlanComponent;
+import org.alfresco.rest.model.fileplancomponents.FilePlanComponent;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Component;
 
diff --git a/src/main/java/org/alfresco/rest/requests/RMSiteAPI.java b/src/main/java/org/alfresco/rest/requests/RMSiteAPI.java
new file mode 100644
index 0000000000..9b5a6b78d7
--- /dev/null
+++ b/src/main/java/org/alfresco/rest/requests/RMSiteAPI.java
@@ -0,0 +1,93 @@
+/*
+ * #%L
+ * Alfresco Records Management Module
+ * %%
+ * Copyright (C) 2005 - 2016 Alfresco Software Limited
+ * %%
+ * License rights for this program may be obtained from Alfresco Software, Ltd.
+ * pursuant to a written agreement and any use of this program without such an
+ * agreement is prohibited.
+ * #L%
+ */
+package org.alfresco.rest.requests;
+
+import static org.alfresco.rest.core.RestRequest.requestWithBody;
+import static org.alfresco.rest.core.RestRequest.simpleRequest;
+import static org.springframework.http.HttpMethod.DELETE;
+import static org.springframework.http.HttpMethod.GET;
+import static org.springframework.http.HttpMethod.POST;
+import static org.springframework.http.HttpMethod.PUT;
+
+import com.google.gson.JsonObject;
+
+import org.alfresco.rest.core.RestAPI;
+import org.alfresco.rest.model.site.RMSite;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+/**
+ * FIXME: Document me :)
+ */
+@Component
+@Scope (value = "prototype")
+public class RMSiteAPI extends RestAPI
+{
+    /**
+     * Get the RM site
+     *
+     * @return FIXME: Document me :)
+     * @throws FIXME: Document me :)
+     */
+    public RMSite getSite() throws Exception
+    {
+        return usingRestWrapper().processModel(RMSite.class, simpleRequest(
+                GET,
+                "sites/rm"
+        ));
+    }
+
+    /**
+     * Create the RM site
+     *
+     * @param rmSiteProperties FIXME: Document me :)
+     * @return FIXME: Document me :)
+     * @throws Exception FIXME: Document me :)
+     */
+    public RMSite createRMSite(JsonObject rmSiteProperties) throws Exception
+    {
+        return usingRestWrapper().processModel(RMSite.class, requestWithBody(
+                POST,
+                rmSiteProperties.toString(),
+                "sites"
+        ));
+    }
+
+    /**
+     * Delete RM site
+     *
+     * @throws Exception FIXME: Document me :)
+     */
+    public void deleteRMSite() throws Exception
+    {
+        usingRestWrapper().processEmptyModel(simpleRequest(
+                DELETE,
+                "sites/rm"
+        ));
+    }
+
+    /**
+     * Update RM site
+     *
+     * @param rmSiteProperties FIXME: Document me :)
+     * @return FIXME: Document me :)
+     * @throws Exception FIXME: Document me :)
+     */
+    public RMSite updateRMSite(JsonObject rmSiteProperties) throws Exception
+    {
+        return usingRestWrapper().processModel(RMSite.class, requestWithBody(
+                PUT,
+                rmSiteProperties.toString(),
+                "sites/rm"
+        ));
+    }
+}
diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java b/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java
new file mode 100644
index 0000000000..a6de974fb1
--- /dev/null
+++ b/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java
@@ -0,0 +1,127 @@
+/*
+ * #%L
+ * Alfresco Records Management Module
+ * %%
+ * Copyright (C) 2005 - 2016 Alfresco Software Limited
+ * %%
+ * License rights for this program may be obtained from Alfresco Software, Ltd.
+ * pursuant to a written agreement and any use of this program without such an
+ * agreement is prohibited.
+ * #L%
+ */
+package org.alfresco.rest.fileplancomponents;
+
+import static org.alfresco.com.site.RMSiteCompliance.STANDARD;
+import static org.alfresco.com.site.RMSiteFields.COMPLIANCE;
+import static org.alfresco.com.site.RMSiteFields.DESCRIPTION;
+import static org.alfresco.com.site.RMSiteFields.TITLE;
+import static org.jglue.fluentjson.JsonBuilderFactory.buildObject;
+import static org.springframework.http.HttpStatus.CONFLICT;
+import static org.springframework.http.HttpStatus.CREATED;
+import static org.springframework.http.HttpStatus.NO_CONTENT;
+import static org.springframework.social.alfresco.api.entities.Site.Visibility.PUBLIC;
+import static org.testng.Assert.assertEquals;
+
+import com.google.gson.JsonObject;
+
+import org.alfresco.rest.BaseRestTest;
+import org.alfresco.rest.core.RestWrapper;
+import org.alfresco.rest.model.site.RMSite;
+import org.alfresco.rest.requests.RMSiteAPI;
+import org.alfresco.utility.data.DataUser;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.testng.annotations.Test;
+
+/**
+ * FIXME: Document me :)
+ * FIXME: Should we use dependent tests or not?
+ * They were removed here but there is no guarantee for the test execution order.
+ * In {@link RecordCategoryTest} we create a record category first to delete it.
+ * Probbaly something to think about again.
+ *
+ * @author Rodica Sutu
+ * @since 1.0
+ */
+public class RMSiteTests extends BaseRestTest
+{
+    @Autowired
+    private RMSiteAPI rmSiteAPI;
+
+    @Autowired
+    private DataUser dataUser;
+
+    // Constants
+    private static final String RM_ID = "rm";
+    private static final String RM_TITLE = "Records Management";
+    private static final String RM_DESCRIPTION = "Records Management Site";
+
+    @Test
+    (
+            description = "Create RM site as admin user"
+    )
+    public void createRMSiteAsAdminUser() throws Exception
+    {
+        RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
+
+        // Build the RM site properties
+        JsonObject rmSiteProperties = buildObject().
+                add(TITLE, RM_TITLE).
+                add(DESCRIPTION, RM_DESCRIPTION).
+                add(COMPLIANCE, STANDARD.toString()).
+                getJson();
+
+        // Create the RM site
+        RMSite rmSite = rmSiteAPI.createRMSite(rmSiteProperties);
+
+        // Verify the status code
+        restWrapper.assertStatusCodeIs(CREATED);
+
+        // Verify the returned file plan component
+        assertEquals(rmSite.getId(), RM_ID);
+        assertEquals(rmSite.getTitle(), RM_TITLE);
+        assertEquals(rmSite.getDescription(), RM_DESCRIPTION);
+        assertEquals(rmSite.getCompliance(), STANDARD);
+        assertEquals(rmSite.getVisibility(), PUBLIC);
+    }
+
+    @Test
+    (
+            description = "Create RM site when site already exist admin user"
+    )
+    public void createRMSiteWhenSiteExists() throws Exception
+    {
+        RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
+
+        // Construct new properties
+        String newTitle = RM_TITLE + "createRMSiteWhenSiteExists";
+        String newDescription = RM_DESCRIPTION + "createRMSiteWhenSiteExists";
+
+        // Build the RM site properties
+        JsonObject rmSiteProperties = buildObject().
+                add(TITLE, newTitle).
+                add(DESCRIPTION, newDescription).
+                add(COMPLIANCE, STANDARD.toString()).
+                getJson();
+
+        // Create the RM site
+        rmSiteAPI.createRMSite(rmSiteProperties);
+
+        // Verify the status code
+        restWrapper.assertStatusCodeIs(CONFLICT);
+    }
+
+    @Test
+    (
+            description = "Delete RM site as admin user"
+    )
+    public void deleteRMSite() throws Exception
+    {
+        RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
+
+        // Delete the RM site
+        rmSiteAPI.deleteRMSite();
+
+        // Verify the status code
+        restWrapper.assertStatusCodeIs(NO_CONTENT);
+    }
+}
diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java
index 54dce68633..75e243716d 100644
--- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java
+++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java
@@ -13,12 +13,12 @@ package org.alfresco.rest.fileplancomponents;
 
 import static java.util.UUID.randomUUID;
 
-import static org.alfresco.com.FilePlanComponentAlias.FILE_PLAN_ALIAS;
-import static org.alfresco.com.FilePlanComponentFields.NAME;
-import static org.alfresco.com.FilePlanComponentFields.NODE_TYPE;
-import static org.alfresco.com.FilePlanComponentFields.PROPERTIES;
-import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_TITLE;
-import static org.alfresco.com.FilePlanComponentType.RECORD_CATEGORY_TYPE;
+import static org.alfresco.com.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
+import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.NAME;
+import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.NODE_TYPE;
+import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES;
+import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE;
+import static org.alfresco.com.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE;
 import static org.jglue.fluentjson.JsonBuilderFactory.buildObject;
 import static org.springframework.http.HttpStatus.CREATED;
 import static org.springframework.http.HttpStatus.NO_CONTENT;
@@ -30,8 +30,8 @@ import com.google.gson.JsonObject;
 
 import org.alfresco.rest.BaseRestTest;
 import org.alfresco.rest.core.RestWrapper;
-import org.alfresco.rest.model.FilePlanComponent;
-import org.alfresco.rest.model.FilePlanComponentProperties;
+import org.alfresco.rest.model.fileplancomponents.FilePlanComponent;
+import org.alfresco.rest.model.fileplancomponents.FilePlanComponentProperties;
 import org.alfresco.rest.requests.FilePlanComponentApi;
 import org.alfresco.utility.data.DataUser;
 import org.springframework.beans.factory.annotation.Autowired;

From 9efdc2834a0f031df0d43710dc69585e690dffcb Mon Sep 17 00:00:00 2001
From: Tuna Aksoy 
Date: Tue, 25 Oct 2016 22:28:17 +0100
Subject: [PATCH 16/49] Fixed the issue with getting file plan component
 children

---
 .../rest/model/FilePlanComponentEntry.java    | 33 +++++++++++++++++++
 .../model/FilePlanComponentsCollection.java   |  2 +-
 .../RecordCategoryTest.java                   |  8 +++--
 3 files changed, 39 insertions(+), 4 deletions(-)
 create mode 100644 src/main/java/org/alfresco/rest/model/FilePlanComponentEntry.java

diff --git a/src/main/java/org/alfresco/rest/model/FilePlanComponentEntry.java b/src/main/java/org/alfresco/rest/model/FilePlanComponentEntry.java
new file mode 100644
index 0000000000..c0c0d385f2
--- /dev/null
+++ b/src/main/java/org/alfresco/rest/model/FilePlanComponentEntry.java
@@ -0,0 +1,33 @@
+/*
+ * #%L
+ * Alfresco Records Management Module
+ * %%
+ * Copyright (C) 2005 - 2016 Alfresco Software Limited
+ * %%
+ * License rights for this program may be obtained from Alfresco Software, Ltd.
+ * pursuant to a written agreement and any use of this program without such an
+ * agreement is prohibited.
+ * #L%
+ */
+package org.alfresco.rest.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import org.alfresco.rest.core.RestModels;
+
+/**
+ * POJO for file plan component entry
+ *
+ * @author Tuna Aksoy
+ * @since 1.0
+ */
+public class FilePlanComponentEntry extends RestModels
+{
+    @JsonProperty(value = "entry")
+    FilePlanComponent filePlanComponent;
+
+    public FilePlanComponent getFilePlanComponent()
+    {
+        return filePlanComponent;
+    }
+}
diff --git a/src/main/java/org/alfresco/rest/model/FilePlanComponentsCollection.java b/src/main/java/org/alfresco/rest/model/FilePlanComponentsCollection.java
index 8f8f9e1eba..ca6bb84659 100644
--- a/src/main/java/org/alfresco/rest/model/FilePlanComponentsCollection.java
+++ b/src/main/java/org/alfresco/rest/model/FilePlanComponentsCollection.java
@@ -18,7 +18,7 @@ import org.alfresco.rest.core.RestModels;
  * @author Kristijan Conkas
  * @since 1.0
  */
-public class FilePlanComponentsCollection extends RestModels
+public class FilePlanComponentsCollection extends RestModels
 {
 
 }
diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java
index 3fe829770c..c891226235 100644
--- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java
+++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java
@@ -36,6 +36,7 @@ import com.google.gson.JsonObject;
 import org.alfresco.com.FilePlanComponentType;
 import org.alfresco.rest.BaseRestTest;
 import org.alfresco.rest.core.RestWrapper;
+import org.alfresco.rest.model.FilePlanComponentEntry;
 import org.alfresco.rest.model.FilePlanComponent;
 import org.alfresco.rest.model.FilePlanComponentProperties;
 import org.alfresco.rest.model.FilePlanComponentsCollection;
@@ -249,11 +250,12 @@ public class RecordCategoryTest extends BaseRestTest
         FilePlanComponentsCollection apiChildren = filePlanComponentApi.listChildComponents(rootCategory.getId());
         restWrapper.assertStatusCodeIs(OK);
         
-        List childrenApi = apiChildren.getEntries();
+        List childrenApi = apiChildren.getEntries();
         childrenApi.forEach(c -> {
             //assertNotNull(c.getId());
-            
-            logger.info(c + " id=" + c.getId() + " name=" + c.getName() + " properties=" + c.getProperties());
+
+            FilePlanComponent filePlanComponent = c.getFilePlanComponent();
+            logger.info(c + " id=" + filePlanComponent.getId() + " name=" + filePlanComponent.getName() + " properties=" + filePlanComponent.getProperties());
         });
     }
     

From d9a6e04b6eb196fe5d3d3aeca637538f4254b3f3 Mon Sep 17 00:00:00 2001
From: Kristijan Conkas 
Date: Wed, 26 Oct 2016 16:54:31 +0100
Subject: [PATCH 17/49] RM-3964: Component children test.

---
 .../model/FilePlanComponentProperties.java    |  4 ---
 .../RecordCategoryTest.java                   | 28 +++++++++++++++++--
 2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/alfresco/rest/model/FilePlanComponentProperties.java b/src/main/java/org/alfresco/rest/model/FilePlanComponentProperties.java
index 311779450e..dbb1cbb82f 100644
--- a/src/main/java/org/alfresco/rest/model/FilePlanComponentProperties.java
+++ b/src/main/java/org/alfresco/rest/model/FilePlanComponentProperties.java
@@ -27,14 +27,10 @@ import org.springframework.stereotype.Component;
  * @author Kristijan Conkas
  * @since 1.0
  */
-@Component
-@Scope(value = "prototype")
 //FIXME: Once the fields have been added the JsonIgnoreProperties annotation should be removed
 @JsonIgnoreProperties(ignoreUnknown = true)
 public class FilePlanComponentProperties
 {
-    // TODO: handling individual properties is tedious and error prone, how about @JsonGetter + @JsonSetter?
-
     @JsonProperty(PROPERTIES_VITAL_RECORD_INDICATOR)
     private boolean vitalRecord;
 
diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java
index c891226235..8b74076d36 100644
--- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java
+++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java
@@ -27,9 +27,11 @@ import static org.springframework.http.HttpStatus.OK;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.NoSuchElementException;
 
 import com.google.gson.JsonObject;
 
@@ -210,6 +212,7 @@ public class RecordCategoryTest extends BaseRestTest
         
         // create subcategory as a child of rootCategory
         FilePlanComponent childCategory = createCategory(rootCategory.getId(), RandomData.getRandomAlphanumeric());
+        
         // child category created?
         assertNotNull(childCategory.getId());
     }
@@ -250,12 +253,31 @@ public class RecordCategoryTest extends BaseRestTest
         FilePlanComponentsCollection apiChildren = filePlanComponentApi.listChildComponents(rootCategory.getId());
         restWrapper.assertStatusCodeIs(OK);
         
+        // check listed children against created list
         List childrenApi = apiChildren.getEntries();
-        childrenApi.forEach(c -> {
-            //assertNotNull(c.getId());
-
+        childrenApi.forEach(c -> 
+        {
             FilePlanComponent filePlanComponent = c.getFilePlanComponent();
+            assertNotNull(filePlanComponent.getId());
+            
             logger.info(c + " id=" + filePlanComponent.getId() + " name=" + filePlanComponent.getName() + " properties=" + filePlanComponent.getProperties());
+            
+            try 
+            {
+                FilePlanComponent createdComponent = children.stream()
+                    .filter(child -> child.getId().compareTo(filePlanComponent.getId()) == 0)
+                    .findFirst()
+                    .get();
+                
+                // does returned object have the same contents as the created one?
+                assertEquals(createdComponent.getName(), filePlanComponent.getName());
+                assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType());
+                assertEquals(createdComponent.getProperties().getTitle(), filePlanComponent.getProperties().getTitle());
+            } 
+            catch (NoSuchElementException e)
+            {
+                fail("No child element for " + filePlanComponent.getId());
+            }
         });
     }
     

From 62a6f1edd378cd87c611556f475113b82ab1d0c5 Mon Sep 17 00:00:00 2001
From: Kristijan Conkas 
Date: Thu, 27 Oct 2016 12:04:03 +0100
Subject: [PATCH 18/49] RM-3964: more verification for positive tests.

---
 .../alfresco/com/FilePlanComponentFields.java |  1 +
 .../rest/model/FilePlanComponent.java         | 38 ++++++++++
 .../model/FilePlanComponentCreatedByUser.java | 51 ++++++++++++++
 .../model/FilePlanComponentProperties.java    |  3 -
 .../RecordCategoryTest.java                   | 69 +++++++++++++++----
 5 files changed, 147 insertions(+), 15 deletions(-)
 create mode 100644 src/main/java/org/alfresco/rest/model/FilePlanComponentCreatedByUser.java

diff --git a/src/main/java/org/alfresco/com/FilePlanComponentFields.java b/src/main/java/org/alfresco/com/FilePlanComponentFields.java
index 76b91035c4..473fd396ed 100644
--- a/src/main/java/org/alfresco/com/FilePlanComponentFields.java
+++ b/src/main/java/org/alfresco/com/FilePlanComponentFields.java
@@ -21,6 +21,7 @@ public class FilePlanComponentFields
 {
     public static final String NAME = "name";
     public static final String NODE_TYPE = "nodeType";
+    public static final String NODE_PARENT_ID = "parentId";
     public static final String PROPERTIES = "properties";
     public static final String PROPERTIES_TITLE = "cm:title";
     public static final String PROPERTIES_VITAL_RECORD_INDICATOR = "rma:vitalRecordIndicator";
diff --git a/src/main/java/org/alfresco/rest/model/FilePlanComponent.java b/src/main/java/org/alfresco/rest/model/FilePlanComponent.java
index efe28755fc..36b48489f9 100644
--- a/src/main/java/org/alfresco/rest/model/FilePlanComponent.java
+++ b/src/main/java/org/alfresco/rest/model/FilePlanComponent.java
@@ -13,6 +13,8 @@ package org.alfresco.rest.model;
 
 import static org.alfresco.com.FilePlanComponentFields.PROPERTIES;
 
+import java.util.List;
+
 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonProperty;
 
@@ -42,8 +44,12 @@ public class FilePlanComponent
 
     private boolean hasRetentionSchedule;
 
+    private List aspectNames;
+    
     @JsonProperty(PROPERTIES)
     private FilePlanComponentProperties properties;
+    
+    private FilePlanComponentCreatedByUser createdByUser;
 
     /**
      * @return the id
@@ -188,4 +194,36 @@ public class FilePlanComponent
     {
         this.properties = properties;
     }
+
+    /**
+     * @return the aspectNames
+     */
+    public List getAspectNames()
+    {
+        return this.aspectNames;
+    }
+
+    /**
+     * @param aspectNames the aspectNames to set
+     */
+    public void setAspectNames(List aspectNames)
+    {
+        this.aspectNames = aspectNames;
+    }
+
+    /**
+     * @return the createdByUser
+     */
+    public FilePlanComponentCreatedByUser getCreatedByUser()
+    {
+        return this.createdByUser;
+    }
+
+    /**
+     * @param createdByUser the createdByUser to set
+     */
+    public void setCreatedByUser(FilePlanComponentCreatedByUser createdByUser)
+    {
+        this.createdByUser = createdByUser;
+    }
 }
diff --git a/src/main/java/org/alfresco/rest/model/FilePlanComponentCreatedByUser.java b/src/main/java/org/alfresco/rest/model/FilePlanComponentCreatedByUser.java
new file mode 100644
index 0000000000..37994c350e
--- /dev/null
+++ b/src/main/java/org/alfresco/rest/model/FilePlanComponentCreatedByUser.java
@@ -0,0 +1,51 @@
+/*
+ * #%L
+ * Alfresco Records Management Module
+ * %%
+ * Copyright (C) 2005 - 2016 Alfresco Software Limited
+ * %%
+ * License rights for this program may be obtained from Alfresco Software, Ltd.
+ * pursuant to a written agreement and any use of this program without such an
+ * agreement is prohibited.
+ * #L%
+ */
+package org.alfresco.rest.model;
+
+/**
+ * POJO for file plan component created by object
+ * @author Kristijan Conkas
+ * @since 1.0
+ */
+public class FilePlanComponentCreatedByUser
+{
+    private String id;
+    private String displayName;
+    /**
+     * @return the id
+     */
+    public String getId()
+    {
+        return this.id;
+    }
+    /**
+     * @param id the id to set
+     */
+    public void setId(String id)
+    {
+        this.id = id;
+    }
+    /**
+     * @return the displayName
+     */
+    public String getDisplayName()
+    {
+        return this.displayName;
+    }
+    /**
+     * @param displayName the displayName to set
+     */
+    public void setDisplayName(String displayName)
+    {
+        this.displayName = displayName;
+    }
+}
diff --git a/src/main/java/org/alfresco/rest/model/FilePlanComponentProperties.java b/src/main/java/org/alfresco/rest/model/FilePlanComponentProperties.java
index dbb1cbb82f..89357f51a8 100644
--- a/src/main/java/org/alfresco/rest/model/FilePlanComponentProperties.java
+++ b/src/main/java/org/alfresco/rest/model/FilePlanComponentProperties.java
@@ -18,9 +18,6 @@ import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_I
 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonProperty;
 
-import org.springframework.context.annotation.Scope;
-import org.springframework.stereotype.Component;
-
 /**
  * POJO for file plan component properties
  *
diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java
index 8b74076d36..b27353a3d4 100644
--- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java
+++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java
@@ -23,8 +23,10 @@ import static org.alfresco.com.FilePlanComponentType.RECORD_FOLDER_TYPE;
 import static org.jglue.fluentjson.JsonBuilderFactory.buildObject;
 import static org.springframework.http.HttpStatus.CREATED;
 import static org.springframework.http.HttpStatus.NO_CONTENT;
+import static org.springframework.http.HttpStatus.NOT_FOUND;
 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.assertTrue;
 import static org.testng.Assert.fail;
@@ -46,6 +48,7 @@ import org.alfresco.rest.requests.FilePlanComponentApi;
 import org.alfresco.utility.data.DataUser;
 import org.alfresco.utility.data.RandomData;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
 import org.testng.annotations.Test;
 
 /**
@@ -76,7 +79,7 @@ public class RecordCategoryTest extends BaseRestTest
     (
         description = "Create category as authorised user"
     )
-    public void createCategoryAsAuthorisedUser() throws Exception
+    public void createCategoryTest() throws Exception
     {
         RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
 
@@ -102,10 +105,13 @@ public class RecordCategoryTest extends BaseRestTest
         assertTrue(filePlanComponent.isIsCategory());
         assertEquals(filePlanComponent.getName(), categoryName);
         assertEquals(filePlanComponent.getNodeType(), RECORD_CATEGORY_TYPE.toString());
-
+        assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername());
+            
         // Verify the returned file plan component properties
         FilePlanComponentProperties filePlanComponentProperties = filePlanComponent.getProperties();
         assertEquals(filePlanComponentProperties.getTitle(), categoryTitle);
+        
+        logger.info("aspects: " + filePlanComponent.getAspectNames());
     }
 
     /**
@@ -118,12 +124,11 @@ public class RecordCategoryTest extends BaseRestTest
     (
         description = "Rename category as authorised user"
     )
-    public void renameCategoryAsAuthorisedUser() throws Exception
+    public void renameCategory() throws Exception
     {
         RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
 
         // Create record category first
-
         String categoryName = "Category name " + randomUUID().toString().substring(0, 8);
         String categoryTitle = "Category title " + randomUUID().toString().substring(0, 8);
 
@@ -154,6 +159,11 @@ public class RecordCategoryTest extends BaseRestTest
 
         // Verify the returned file plan component
         assertEquals(renamedFilePlanComponent.getName(), newCategoryName);
+        
+        // get actual FILE_PLAN_ALIAS id
+        FilePlanComponent parentComponent = filePlanComponentApi.getFilePlanComponent(FILE_PLAN_ALIAS.toString());
+        // verify renamed component still has this parent
+        assertEquals(renamedFilePlanComponent.getParentId(), parentComponent.getId());
     }
 
     /**
@@ -166,12 +176,11 @@ public class RecordCategoryTest extends BaseRestTest
     (
         description = "Delete category as authorised user"
     )
-    public void deleteCategoryAsAuthorisedUser() throws Exception
+    public void deleteCategory() throws Exception
     {
         RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
 
         // Create record category first
-
         String categoryName = "Category name " + randomUUID().toString().substring(0, 8);
         String categoryTitle = "Category title " + randomUUID().toString().substring(0, 8);
 
@@ -192,6 +201,10 @@ public class RecordCategoryTest extends BaseRestTest
 
         // Verify the status code
         restWrapper.assertStatusCodeIs(NO_CONTENT);
+        
+        // deleted component should no longer be retrievable
+        filePlanComponentApi.getFilePlanComponent(filePlanComponent.getId());
+        restWrapper.assertStatusCodeIs(NOT_FOUND);
     }
     
     /**
@@ -215,6 +228,13 @@ public class RecordCategoryTest extends BaseRestTest
         
         // child category created?
         assertNotNull(childCategory.getId());
+        
+        // verify child category
+        assertEquals(childCategory.getParentId(), rootCategory.getId());
+        assertTrue(childCategory.isIsCategory());
+        assertFalse(childCategory.isIsFile());
+        assertFalse(childCategory.isIsRecordFolder());
+        assertEquals(childCategory.getNodeType(), RECORD_CATEGORY_TYPE.toString());
     }
     
     /**
@@ -233,7 +253,7 @@ public class RecordCategoryTest extends BaseRestTest
     {
         // create root level category
         FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), RandomData.getRandomAlphanumeric());
-        assertNotNull(rootCategory.getId());
+        assertNotNull(rootCategory.getId());   
         
         // add child categories/folders
         ArrayList children = new ArrayList();
@@ -253,25 +273,50 @@ public class RecordCategoryTest extends BaseRestTest
         FilePlanComponentsCollection apiChildren = filePlanComponentApi.listChildComponents(rootCategory.getId());
         restWrapper.assertStatusCodeIs(OK);
         
+        logger.info("parent: " + rootCategory.getId());
+        
         // check listed children against created list
-        List childrenApi = apiChildren.getEntries();
-        childrenApi.forEach(c -> 
+        apiChildren.getEntries().forEach(c -> 
         {
             FilePlanComponent filePlanComponent = c.getFilePlanComponent();
             assertNotNull(filePlanComponent.getId());
-            
-            logger.info(c + " id=" + filePlanComponent.getId() + " name=" + filePlanComponent.getName() + " properties=" + filePlanComponent.getProperties());
+            logger.info("checking child " + filePlanComponent.getId());
             
             try 
             {
+                // find this child in created children list
                 FilePlanComponent createdComponent = children.stream()
-                    .filter(child -> child.getId().compareTo(filePlanComponent.getId()) == 0)
+                    .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(), rootCategory.getId());
+                
+                // only categories or folders have been created
+                assertFalse(filePlanComponent.isIsFile());
+     
+                // boolean properties related to node type
+                // only RECORD_CATEGORY_TYPE and RECORD_FOLDER_TYPE have been created
+                if (filePlanComponent.getNodeType().equals(RECORD_CATEGORY_TYPE.toString()))
+                {   
+                    assertTrue(filePlanComponent.isIsCategory());
+                    assertFalse(filePlanComponent.isIsRecordFolder());
+                }
+                else
+                {
+                    assertTrue(filePlanComponent.isIsRecordFolder());
+                    assertFalse(filePlanComponent.isIsCategory());
+                }
+
                 // does returned object have the same contents as the created one?
                 assertEquals(createdComponent.getName(), filePlanComponent.getName());
                 assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType());
+                
+                // verify properties
                 assertEquals(createdComponent.getProperties().getTitle(), filePlanComponent.getProperties().getTitle());
             } 
             catch (NoSuchElementException e)

From eacdd243101f17fb5e2cdfb69eebf5760b8ee251 Mon Sep 17 00:00:00 2001
From: Rodica Sutu 
Date: Thu, 27 Oct 2016 15:08:49 +0300
Subject: [PATCH 19/49] tidy up the code, creating the RM Site on BaseRestTests

---
 .../alfresco/com/site/RMSiteCompliance.java   |  2 +-
 .../org/alfresco/com/site/RMSiteFields.java   | 15 +++-
 .../org/alfresco/rest/model/site/RMSite.java  | 12 ++-
 .../org/alfresco/rest/requests/RMSiteAPI.java | 52 ++++++++---
 .../java/org/alfresco/rest/BaseRestTest.java  | 86 +++++++++++++++++--
 .../rest/fileplancomponents/RMSiteTests.java  | 52 ++++++++---
 6 files changed, 180 insertions(+), 39 deletions(-)

diff --git a/src/main/java/org/alfresco/com/site/RMSiteCompliance.java b/src/main/java/org/alfresco/com/site/RMSiteCompliance.java
index 84dd6b00f6..0d5f731967 100644
--- a/src/main/java/org/alfresco/com/site/RMSiteCompliance.java
+++ b/src/main/java/org/alfresco/com/site/RMSiteCompliance.java
@@ -12,7 +12,7 @@
 package org.alfresco.com.site;
 
 /**
- * FIXME: Document me :)
+ * RM Site compliance
  *
  * @author Tuna Aksoy
  * @since 1.0
diff --git a/src/main/java/org/alfresco/com/site/RMSiteFields.java b/src/main/java/org/alfresco/com/site/RMSiteFields.java
index d0ce8303b6..c7c65f0d06 100644
--- a/src/main/java/org/alfresco/com/site/RMSiteFields.java
+++ b/src/main/java/org/alfresco/com/site/RMSiteFields.java
@@ -12,9 +12,18 @@
 package org.alfresco.com.site;
 
 /**
- * FIXME: Document me :)
- *
+ *RM Site properties from the RM Model Schema
+ *"entry": {
+ *      "id": "string",
+ *      "guid": "string",
+ *      "title": "string",
+ *      "description": "string",
+ *      "visibility": "{@link org.springframework.social.alfresco.api.entities.Site.Visibility}",
+ *      "compliance": "{@link RMSiteCompliance}",
+ *      "role": "{@link org.alfresco.utility.constants.UserRole}"
+ *}
  * @author Tuna Aksoy
+ * @author Rodica Sutu
  * @since 1.0
  */
 public class RMSiteFields
@@ -23,4 +32,6 @@ public class RMSiteFields
     public static final String COMPLIANCE = "compliance";
     public static final String TITLE = "title";
     public static final String DESCRIPTION = "description";
+    public static final String VISIBILITY ="visibility";
+    public static final String ROLE = "role";
 }
diff --git a/src/main/java/org/alfresco/rest/model/site/RMSite.java b/src/main/java/org/alfresco/rest/model/site/RMSite.java
index 680777f96f..47a636b031 100644
--- a/src/main/java/org/alfresco/rest/model/site/RMSite.java
+++ b/src/main/java/org/alfresco/rest/model/site/RMSite.java
@@ -17,7 +17,7 @@ import org.alfresco.com.site.RMSiteCompliance;
 import org.alfresco.rest.model.RestSiteModel;
 
 /**
- * FIXME: Document me :)
+ * POJO for RM Site component
  *
  * @author Rodica Sutu
  * @since 1.0
@@ -28,9 +28,8 @@ public class RMSite extends RestSiteModel
     protected RMSiteCompliance compliance;
 
     /**
-     * FIXME: Document me :)
-     *
-     * @param compliance the compliance to set
+     * Helper method to set RM site compliance
+     * @param compliance {@link RMSiteCompliance} the compliance to set
      */
     public void setCompliance(RMSiteCompliance compliance)
     {
@@ -38,9 +37,8 @@ public class RMSite extends RestSiteModel
     }
 
     /**
-     * FIXME: Document me :)
-     *
-     * @return FIXME: Document me :)
+     * Helper method to get RM site compliance
+     * @return compliance the RM Site compliance to get
      */
     public RMSiteCompliance getCompliance()
     {
diff --git a/src/main/java/org/alfresco/rest/requests/RMSiteAPI.java b/src/main/java/org/alfresco/rest/requests/RMSiteAPI.java
index 9b5a6b78d7..3be78bb4fb 100644
--- a/src/main/java/org/alfresco/rest/requests/RMSiteAPI.java
+++ b/src/main/java/org/alfresco/rest/requests/RMSiteAPI.java
@@ -26,7 +26,11 @@ import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Component;
 
 /**
- * FIXME: Document me :)
+ *  File plan component REST API Wrapper
+ *
+ * @author Tuna Aksoy
+ * @author Rodica Sutu
+ * @since 1.0
  */
 @Component
 @Scope (value = "prototype")
@@ -35,8 +39,14 @@ public class RMSiteAPI extends RestAPI
     /**
      * Get the RM site
      *
-     * @return FIXME: Document me :)
-     * @throws FIXME: Document me :)
+     * @return The {@link RMSite} for the given file plan component id
+     * @throws Exception for the following cases:
+     * 
    + *
  • Api Response code 400 Invalid parameter: GET request is suported only for the RM site
  • + *
  • Api Response code 401 If authentication failed
  • + *
  • Api Response code 409 If RM Site does not exist
  • + *
  • Api Response code default Unexpected error
  • + *
*/ public RMSite getSite() throws Exception { @@ -49,9 +59,15 @@ public class RMSiteAPI extends RestAPI /** * Create the RM site * - * @param rmSiteProperties FIXME: Document me :) - * @return FIXME: Document me :) - * @throws Exception FIXME: Document me :) + * @param rmSiteProperties The properties of the rm site to be created + * @return The {@link RMSite} with the given properties + * @throws Exception for the following cases: + *
    + *
  • Api Response code 400 Invalid parameter: title, or description exceed the maximum length; or siteBodyCreate invalid
  • + *
  • Api Response code 401 If authentication failedApi Response code 409 RM Site already exists
  • + *
  • Api Response code default Unexpected error
  • + *
*/ public RMSite createRMSite(JsonObject rmSiteProperties) throws Exception { @@ -64,8 +80,14 @@ public class RMSiteAPI extends RestAPI /** * Delete RM site - * - * @throws Exception FIXME: Document me :) + * @throws Exception for the following cases: + *
    + *
  • Api Response code 400 Invalid parameter: DELETE request is suported only for the RM site
  • + *
  • Api Response code 401 If authentication failedApi Response code 403 Current user does not have permission to delete the site that is visible to them.
  • + *
  • Api Response code 404 RM site does not exist
  • + *
  • Api Response code default Unexpected error
  • + *
*/ public void deleteRMSite() throws Exception { @@ -78,9 +100,16 @@ public class RMSiteAPI extends RestAPI /** * Update RM site * - * @param rmSiteProperties FIXME: Document me :) - * @return FIXME: Document me :) - * @throws Exception FIXME: Document me :) + * @param rmSiteProperties The properties to be updated + * @return The updated {@link RMSite} + * @throws Exception for the following cases: + *
    + *
  • Api Response code 400 the update request is invalid {@code rmSiteProperties} is invalid
  • + *
  • Api Response code 401 If authentication fails
  • + *
  • Api Response code 403 does not have permission to update {@code RMSite}
  • + *
  • Api Response code 404 {@code RMSite} does not exist
  • + *
  • Api Response code default Unexpected error,model integrity exception
  • + *
*/ public RMSite updateRMSite(JsonObject rmSiteProperties) throws Exception { @@ -90,4 +119,5 @@ public class RMSiteAPI extends RestAPI "sites/rm" )); } + } diff --git a/src/test/java/org/alfresco/rest/BaseRestTest.java b/src/test/java/org/alfresco/rest/BaseRestTest.java index 7ff9a538e6..7d35effb57 100644 --- a/src/test/java/org/alfresco/rest/BaseRestTest.java +++ b/src/test/java/org/alfresco/rest/BaseRestTest.java @@ -13,11 +13,25 @@ package org.alfresco.rest; import static java.lang.Integer.parseInt; +import static org.alfresco.com.site.RMSiteCompliance.STANDARD; +import static org.alfresco.com.site.RMSiteFields.COMPLIANCE; +import static org.alfresco.com.site.RMSiteFields.DESCRIPTION; +import static org.alfresco.com.site.RMSiteFields.TITLE; +import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; +import static org.springframework.http.HttpStatus.CREATED; + +import com.google.gson.JsonObject; import com.jayway.restassured.RestAssured; +import org.alfresco.dataprep.SiteService; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.requests.RMSiteAPI; +import org.alfresco.utility.data.DataUser; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; +import org.springframework.http.HttpStatus; import org.testng.annotations.BeforeClass; /** @@ -32,27 +46,87 @@ import org.testng.annotations.BeforeClass; @PropertySource(value = "classpath:local.properties", ignoreResourceNotFound = true) public class BaseRestTest extends RestTest { - @Value("${alfresco.rm.scheme}") + @Value ("${alfresco.rm.scheme}") private String scheme; - @Value("${alfresco.rm.host}") + @Value ("${alfresco.rm.host}") private String host; - @Value("${alfresco.rm.port}") + @Value ("${alfresco.rm.port}") private String port; - @Value("${alfresco.rm.basePath}") + @Value ("${alfresco.rm.basePath}") private String basePath; + @Autowired + public RMSiteAPI rmSiteAPI; + + @Autowired + public DataUser dataUser; + + private static final String RM_ID = "rm"; + + @Autowired + private SiteService siteService; + /** * @see org.alfresco.rest.RestTest#checkServerHealth() */ @Override - @BeforeClass(alwaysRun = true) + @BeforeClass (alwaysRun = true) public void checkServerHealth() throws Exception { RestAssured.baseURI = scheme + "://" + host; RestAssured.port = parseInt(port); RestAssured.basePath = basePath; + //create RM Site if not exist + createRMSiteIfNotExists(); } -} + /* + * Helper method to create the RM Site via the POST request + * if the site doesn't exist + */ + + public void createRMSiteIfNotExists() throws Exception + { + final String RM_TITLE = "Records Management"; + final String RM_DESCRIPTION = "Records Management Site"; + //check RM site doesn't exist + if (!siteRMExist()) + { + rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + // Build the RM site properties + JsonObject rmSiteProperties = buildObject(). + add(TITLE, RM_TITLE). + add(DESCRIPTION, RM_DESCRIPTION). + add(COMPLIANCE, STANDARD.toString()). + getJson(); + // Create the RM site + rmSiteAPI.createRMSite(rmSiteProperties); + + // Verify the status code + rmSiteAPI.usingRestWrapper().assertStatusCodeIs(CREATED); + } + } + + + /* + * Check the RM site exist via the GET request + * + */ + public boolean siteRMExist() throws Exception + { /* + return siteService.exists(RM_ID, dataUser.getAdminUser().getUsername(), + dataUser.getAdminUser().getPassword()); + */ + RestWrapper restWrapper=rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + rmSiteAPI.getSite(); + if (restWrapper.getStatusCode().equals(HttpStatus.OK.toString())) + { + return true; + } else + { + return false; + } + } +} \ No newline at end of file diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java b/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java index a6de974fb1..8b22ace9ef 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java @@ -18,7 +18,9 @@ import static org.alfresco.com.site.RMSiteFields.TITLE; import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; import static org.springframework.http.HttpStatus.CONFLICT; import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.NOT_FOUND; import static org.springframework.http.HttpStatus.NO_CONTENT; +import static org.springframework.http.HttpStatus.OK; import static org.springframework.social.alfresco.api.entities.Site.Visibility.PUBLIC; import static org.testng.Assert.assertEquals; @@ -27,9 +29,6 @@ import com.google.gson.JsonObject; import org.alfresco.rest.BaseRestTest; import org.alfresco.rest.core.RestWrapper; import org.alfresco.rest.model.site.RMSite; -import org.alfresco.rest.requests.RMSiteAPI; -import org.alfresco.utility.data.DataUser; -import org.springframework.beans.factory.annotation.Autowired; import org.testng.annotations.Test; /** @@ -44,11 +43,6 @@ import org.testng.annotations.Test; */ public class RMSiteTests extends BaseRestTest { - @Autowired - private RMSiteAPI rmSiteAPI; - - @Autowired - private DataUser dataUser; // Constants private static final String RM_ID = "rm"; @@ -57,12 +51,16 @@ public class RMSiteTests extends BaseRestTest @Test ( - description = "Create RM site as admin user" + description = "Create RM site as admin user with standard Compliance" ) public void createRMSiteAsAdminUser() throws Exception { RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - + if (siteRMExist()) + { + //Delete the RM site + rmSiteAPI.deleteRMSite(); + } // Build the RM site properties JsonObject rmSiteProperties = buildObject(). add(TITLE, RM_TITLE). @@ -74,7 +72,7 @@ public class RMSiteTests extends BaseRestTest RMSite rmSite = rmSiteAPI.createRMSite(rmSiteProperties); // Verify the status code - restWrapper.assertStatusCodeIs(CREATED); + rmSiteAPI.usingRestWrapper().assertStatusCodeIs(CREATED); // Verify the returned file plan component assertEquals(rmSite.getId(), RM_ID); @@ -86,10 +84,12 @@ public class RMSiteTests extends BaseRestTest @Test ( - description = "Create RM site when site already exist admin user" + description = "Create RM site when site already exist with admin user" ) public void createRMSiteWhenSiteExists() throws Exception { + rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + createRMSiteIfNotExists(); RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); // Construct new properties @@ -124,4 +124,32 @@ public class RMSiteTests extends BaseRestTest // Verify the status code restWrapper.assertStatusCodeIs(NO_CONTENT); } + + @Test + ( + description = "GET RM site as admin user" + ) + public void getRMSite() throws Exception + { + RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + // Get the RM site + RMSite rmSite=rmSiteAPI.getSite(); + + if (!siteRMExist()) + { + // Verify the status code + restWrapper.assertStatusCodeIs(NOT_FOUND); + } + else + { + // Verify the status code + restWrapper.assertStatusCodeIs(OK); + assertEquals(rmSite.getId(), RM_ID); + assertEquals(rmSite.getDescription(), RM_DESCRIPTION); + assertEquals(rmSite.getCompliance(), STANDARD); + assertEquals(rmSite.getVisibility(), PUBLIC); + } + + } } From 1f2b869ba874147f5b61a4dcc683f87ae2c6e693 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Thu, 27 Oct 2016 16:07:53 +0300 Subject: [PATCH 20/49] remove unnecessary comment + correct java docs --- .../alfresco/com/site/RMSiteCompliance.java | 2 +- .../org/alfresco/rest/model/site/RMSite.java | 2 +- .../org/alfresco/rest/requests/RMSiteAPI.java | 4 ++-- .../java/org/alfresco/rest/BaseRestTest.java | 22 +++++-------------- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/alfresco/com/site/RMSiteCompliance.java b/src/main/java/org/alfresco/com/site/RMSiteCompliance.java index 0d5f731967..76f0bf4926 100644 --- a/src/main/java/org/alfresco/com/site/RMSiteCompliance.java +++ b/src/main/java/org/alfresco/com/site/RMSiteCompliance.java @@ -20,5 +20,5 @@ package org.alfresco.com.site; public enum RMSiteCompliance { STANDARD, - DOD5015; + DOD5015 } diff --git a/src/main/java/org/alfresco/rest/model/site/RMSite.java b/src/main/java/org/alfresco/rest/model/site/RMSite.java index 47a636b031..960f518488 100644 --- a/src/main/java/org/alfresco/rest/model/site/RMSite.java +++ b/src/main/java/org/alfresco/rest/model/site/RMSite.java @@ -25,7 +25,7 @@ import org.alfresco.rest.model.RestSiteModel; public class RMSite extends RestSiteModel { @JsonProperty (required = true) - protected RMSiteCompliance compliance; + private RMSiteCompliance compliance; /** * Helper method to set RM site compliance diff --git a/src/main/java/org/alfresco/rest/requests/RMSiteAPI.java b/src/main/java/org/alfresco/rest/requests/RMSiteAPI.java index 3be78bb4fb..7cb99889cc 100644 --- a/src/main/java/org/alfresco/rest/requests/RMSiteAPI.java +++ b/src/main/java/org/alfresco/rest/requests/RMSiteAPI.java @@ -42,7 +42,7 @@ public class RMSiteAPI extends RestAPI * @return The {@link RMSite} for the given file plan component id * @throws Exception for the following cases: *
    - *
  • Api Response code 400 Invalid parameter: GET request is suported only for the RM site
  • + *
  • Api Response code 400 Invalid parameter: GET request is supported only for the RM site
  • *
  • Api Response code 401 If authentication failed
  • *
  • Api Response code 409 If RM Site does not exist
  • *
  • Api Response code default Unexpected error
  • @@ -82,7 +82,7 @@ public class RMSiteAPI extends RestAPI * Delete RM site * @throws Exception for the following cases: *
      - *
    • Api Response code 400 Invalid parameter: DELETE request is suported only for the RM site
    • + *
    • Api Response code 400 Invalid parameter: DELETE request is supported only for the RM site
    • *
    • Api Response code 401 If authentication failedApi Response code 403 Current user does not have permission to delete the site that is visible to them.
    • *
    • Api Response code 404 RM site does not exist
    • diff --git a/src/test/java/org/alfresco/rest/BaseRestTest.java b/src/test/java/org/alfresco/rest/BaseRestTest.java index 7d35effb57..ae97287230 100644 --- a/src/test/java/org/alfresco/rest/BaseRestTest.java +++ b/src/test/java/org/alfresco/rest/BaseRestTest.java @@ -73,7 +73,7 @@ public class BaseRestTest extends RestTest * @see org.alfresco.rest.RestTest#checkServerHealth() */ @Override - @BeforeClass (alwaysRun = true) + @BeforeClass(alwaysRun = true) public void checkServerHealth() throws Exception { RestAssured.baseURI = scheme + "://" + host; @@ -82,10 +82,10 @@ public class BaseRestTest extends RestTest //create RM Site if not exist createRMSiteIfNotExists(); } - /* + /** * Helper method to create the RM Site via the POST request * if the site doesn't exist - */ + */ public void createRMSiteIfNotExists() throws Exception { @@ -110,23 +110,13 @@ public class BaseRestTest extends RestTest } - /* + /** * Check the RM site exist via the GET request - * */ public boolean siteRMExist() throws Exception - { /* - return siteService.exists(RM_ID, dataUser.getAdminUser().getUsername(), - dataUser.getAdminUser().getPassword()); - */ + { RestWrapper restWrapper=rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); rmSiteAPI.getSite(); - if (restWrapper.getStatusCode().equals(HttpStatus.OK.toString())) - { - return true; - } else - { - return false; - } + return restWrapper.getStatusCode().equals(HttpStatus.OK.toString()); } } \ No newline at end of file From c2a4ecd2c6c58b43af049b936b505babddb826bc Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Thu, 27 Oct 2016 16:12:39 +0300 Subject: [PATCH 21/49] java doc indentation --- .../rest/fileplancomponents/RMSiteTests.java | 45 +++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java b/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java index 8b22ace9ef..7b09d1433d 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java @@ -11,10 +11,12 @@ */ package org.alfresco.rest.fileplancomponents; +import static org.alfresco.com.site.RMSiteCompliance.DOD5015; import static org.alfresco.com.site.RMSiteCompliance.STANDARD; import static org.alfresco.com.site.RMSiteFields.COMPLIANCE; import static org.alfresco.com.site.RMSiteFields.DESCRIPTION; import static org.alfresco.com.site.RMSiteFields.TITLE; +import static org.alfresco.rest.TestData.ANOTHER_ADMIN; import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; import static org.springframework.http.HttpStatus.CONFLICT; import static org.springframework.http.HttpStatus.CREATED; @@ -51,11 +53,11 @@ public class RMSiteTests extends BaseRestTest @Test ( - description = "Create RM site as admin user with standard Compliance" + description = "Create RM site as admin user with Standard Compliance" ) public void createRMSiteAsAdminUser() throws Exception { - RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); if (siteRMExist()) { //Delete the RM site @@ -135,7 +137,6 @@ public class RMSiteTests extends BaseRestTest // Get the RM site RMSite rmSite=rmSiteAPI.getSite(); - if (!siteRMExist()) { // Verify the status code @@ -150,6 +151,42 @@ public class RMSiteTests extends BaseRestTest assertEquals(rmSite.getCompliance(), STANDARD); assertEquals(rmSite.getVisibility(), PUBLIC); } - } + + @Test + ( + description = "Create RM site as an admin user created with DOD compliance" + ) + public void createRMSiteAsAnotherAdminUser() throws Exception + { + rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + if (siteRMExist()) + { + //Delete the RM site + rmSiteAPI.deleteRMSite(); + } + + rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.createRandomTestUser(ANOTHER_ADMIN)); + // Build the RM site properties + JsonObject rmSiteProperties = buildObject(). + add(TITLE, RM_TITLE). + add(DESCRIPTION, RM_DESCRIPTION). + add(COMPLIANCE, DOD5015.toString()). + getJson(); + + // Create the RM site + RMSite rmSite = rmSiteAPI.createRMSite(rmSiteProperties); + + // Verify the status code + rmSiteAPI.usingRestWrapper().assertStatusCodeIs(CREATED); + + // Verify the returned file plan component + assertEquals(rmSite.getId(), RM_ID); + assertEquals(rmSite.getTitle(), RM_TITLE); + assertEquals(rmSite.getDescription(), RM_DESCRIPTION); + assertEquals(rmSite.getCompliance(), DOD5015); + assertEquals(rmSite.getVisibility(), PUBLIC); + } + + } From ce3c514967485580c3cb83144ae618ab02384d0c Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Thu, 27 Oct 2016 16:38:40 +0300 Subject: [PATCH 22/49] Revert "java doc indentation" This reverts commit c2a4ecd2c6c58b43af049b936b505babddb826bc. --- .../rest/fileplancomponents/RMSiteTests.java | 45 ++----------------- 1 file changed, 4 insertions(+), 41 deletions(-) diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java b/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java index 7b09d1433d..8b22ace9ef 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java @@ -11,12 +11,10 @@ */ package org.alfresco.rest.fileplancomponents; -import static org.alfresco.com.site.RMSiteCompliance.DOD5015; import static org.alfresco.com.site.RMSiteCompliance.STANDARD; import static org.alfresco.com.site.RMSiteFields.COMPLIANCE; import static org.alfresco.com.site.RMSiteFields.DESCRIPTION; import static org.alfresco.com.site.RMSiteFields.TITLE; -import static org.alfresco.rest.TestData.ANOTHER_ADMIN; import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; import static org.springframework.http.HttpStatus.CONFLICT; import static org.springframework.http.HttpStatus.CREATED; @@ -53,11 +51,11 @@ public class RMSiteTests extends BaseRestTest @Test ( - description = "Create RM site as admin user with Standard Compliance" + description = "Create RM site as admin user with standard Compliance" ) public void createRMSiteAsAdminUser() throws Exception { - rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); if (siteRMExist()) { //Delete the RM site @@ -137,6 +135,7 @@ public class RMSiteTests extends BaseRestTest // Get the RM site RMSite rmSite=rmSiteAPI.getSite(); + if (!siteRMExist()) { // Verify the status code @@ -151,42 +150,6 @@ public class RMSiteTests extends BaseRestTest assertEquals(rmSite.getCompliance(), STANDARD); assertEquals(rmSite.getVisibility(), PUBLIC); } + } - - @Test - ( - description = "Create RM site as an admin user created with DOD compliance" - ) - public void createRMSiteAsAnotherAdminUser() throws Exception - { - rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - if (siteRMExist()) - { - //Delete the RM site - rmSiteAPI.deleteRMSite(); - } - - rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.createRandomTestUser(ANOTHER_ADMIN)); - // Build the RM site properties - JsonObject rmSiteProperties = buildObject(). - add(TITLE, RM_TITLE). - add(DESCRIPTION, RM_DESCRIPTION). - add(COMPLIANCE, DOD5015.toString()). - getJson(); - - // Create the RM site - RMSite rmSite = rmSiteAPI.createRMSite(rmSiteProperties); - - // Verify the status code - rmSiteAPI.usingRestWrapper().assertStatusCodeIs(CREATED); - - // Verify the returned file plan component - assertEquals(rmSite.getId(), RM_ID); - assertEquals(rmSite.getTitle(), RM_TITLE); - assertEquals(rmSite.getDescription(), RM_DESCRIPTION); - assertEquals(rmSite.getCompliance(), DOD5015); - assertEquals(rmSite.getVisibility(), PUBLIC); - } - - } From 5c5236c01c8fd229ef54c8e887f9c34d1e9233ff Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Thu, 27 Oct 2016 16:41:43 +0300 Subject: [PATCH 23/49] java doc indentation --- .../java/org/alfresco/rest/BaseRestTest.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/test/java/org/alfresco/rest/BaseRestTest.java b/src/test/java/org/alfresco/rest/BaseRestTest.java index ae97287230..522ef3f240 100644 --- a/src/test/java/org/alfresco/rest/BaseRestTest.java +++ b/src/test/java/org/alfresco/rest/BaseRestTest.java @@ -83,10 +83,9 @@ public class BaseRestTest extends RestTest createRMSiteIfNotExists(); } /** - * Helper method to create the RM Site via the POST request - * if the site doesn't exist - */ - + * Helper method to create the RM Site via the POST request + * if the site doesn't exist + */ public void createRMSiteIfNotExists() throws Exception { final String RM_TITLE = "Records Management"; @@ -96,11 +95,11 @@ public class BaseRestTest extends RestTest { rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); // Build the RM site properties - JsonObject rmSiteProperties = buildObject(). - add(TITLE, RM_TITLE). - add(DESCRIPTION, RM_DESCRIPTION). - add(COMPLIANCE, STANDARD.toString()). - getJson(); + JsonObject rmSiteProperties = buildObject() + .add(TITLE, RM_TITLE) + .add(DESCRIPTION, RM_DESCRIPTION) + .add(COMPLIANCE, STANDARD.toString()) + .getJson(); // Create the RM site rmSiteAPI.createRMSite(rmSiteProperties); @@ -111,8 +110,8 @@ public class BaseRestTest extends RestTest /** - * Check the RM site exist via the GET request - */ + * Check the RM site exist via the GET request + */ public boolean siteRMExist() throws Exception { RestWrapper restWrapper=rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); From 2289696e0fe083281c3de04144a93d0a8f8da7d9 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Thu, 27 Oct 2016 17:04:11 +0300 Subject: [PATCH 24/49] fix the merge --- .../FilePlanComponentEntry.java | 2 +- .../FilePlanComponentsCollection.java | 2 +- .../rest/requests/FilePlanComponentApi.java | 4 ++-- .../RecordCategoryTest.java | 24 +++++++++---------- 4 files changed, 16 insertions(+), 16 deletions(-) rename src/main/java/org/alfresco/rest/model/{ => fileplancomponents}/FilePlanComponentEntry.java (93%) rename src/main/java/org/alfresco/rest/model/{ => fileplancomponents}/FilePlanComponentsCollection.java (91%) diff --git a/src/main/java/org/alfresco/rest/model/FilePlanComponentEntry.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentEntry.java similarity index 93% rename from src/main/java/org/alfresco/rest/model/FilePlanComponentEntry.java rename to src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentEntry.java index c0c0d385f2..4669779447 100644 --- a/src/main/java/org/alfresco/rest/model/FilePlanComponentEntry.java +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentEntry.java @@ -9,7 +9,7 @@ * agreement is prohibited. * #L% */ -package org.alfresco.rest.model; +package org.alfresco.rest.model.fileplancomponents; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/main/java/org/alfresco/rest/model/FilePlanComponentsCollection.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentsCollection.java similarity index 91% rename from src/main/java/org/alfresco/rest/model/FilePlanComponentsCollection.java rename to src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentsCollection.java index ca6bb84659..24d3f395f2 100644 --- a/src/main/java/org/alfresco/rest/model/FilePlanComponentsCollection.java +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentsCollection.java @@ -9,7 +9,7 @@ * agreement is prohibited. * #L% */ -package org.alfresco.rest.model; +package org.alfresco.rest.model.fileplancomponents; import org.alfresco.rest.core.RestModels; diff --git a/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java b/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java index f2764539c6..d934382d74 100644 --- a/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java +++ b/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java @@ -23,8 +23,8 @@ import static org.springframework.http.HttpMethod.PUT; import com.google.gson.JsonObject; import org.alfresco.rest.core.RestAPI; -import org.alfresco.rest.model.FilePlanComponent; -import org.alfresco.rest.model.FilePlanComponentsCollection; +import org.alfresco.rest.model.fileplancomponents.FilePlanComponent; +import org.alfresco.rest.model.fileplancomponents.FilePlanComponentsCollection; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java index 8b74076d36..1b01d55c78 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java @@ -13,13 +13,13 @@ package org.alfresco.rest.fileplancomponents; import static java.util.UUID.randomUUID; -import static org.alfresco.com.FilePlanComponentAlias.FILE_PLAN_ALIAS; -import static org.alfresco.com.FilePlanComponentFields.NAME; -import static org.alfresco.com.FilePlanComponentFields.NODE_TYPE; -import static org.alfresco.com.FilePlanComponentFields.PROPERTIES; -import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_TITLE; -import static org.alfresco.com.FilePlanComponentType.RECORD_CATEGORY_TYPE; -import static org.alfresco.com.FilePlanComponentType.RECORD_FOLDER_TYPE; +import static org.alfresco.com.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; +import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.NAME; +import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.NODE_TYPE; +import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES; +import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; +import static org.alfresco.com.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE; +import static org.alfresco.com.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE; import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.NO_CONTENT; @@ -35,13 +35,13 @@ import java.util.NoSuchElementException; import com.google.gson.JsonObject; -import org.alfresco.com.FilePlanComponentType; +import org.alfresco.com.fileplancomponents.FilePlanComponentType; import org.alfresco.rest.BaseRestTest; import org.alfresco.rest.core.RestWrapper; -import org.alfresco.rest.model.FilePlanComponentEntry; -import org.alfresco.rest.model.FilePlanComponent; -import org.alfresco.rest.model.FilePlanComponentProperties; -import org.alfresco.rest.model.FilePlanComponentsCollection; +import org.alfresco.rest.model.fileplancomponents.FilePlanComponent; +import org.alfresco.rest.model.fileplancomponents.FilePlanComponentEntry; +import org.alfresco.rest.model.fileplancomponents.FilePlanComponentProperties; +import org.alfresco.rest.model.fileplancomponents.FilePlanComponentsCollection; import org.alfresco.rest.requests.FilePlanComponentApi; import org.alfresco.utility.data.DataUser; import org.alfresco.utility.data.RandomData; From 524b771342553d0c5ec977246a3766fe4fb78ca6 Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Thu, 27 Oct 2016 15:27:35 +0100 Subject: [PATCH 25/49] RM-3964: test updates. --- .../RecordCategoryTest.java | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java index b27353a3d4..e2f31ef8e3 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java @@ -22,8 +22,8 @@ import static org.alfresco.com.FilePlanComponentType.RECORD_CATEGORY_TYPE; import static org.alfresco.com.FilePlanComponentType.RECORD_FOLDER_TYPE; import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; import static org.springframework.http.HttpStatus.CREATED; -import static org.springframework.http.HttpStatus.NO_CONTENT; import static org.springframework.http.HttpStatus.NOT_FOUND; +import static org.springframework.http.HttpStatus.NO_CONTENT; import static org.springframework.http.HttpStatus.OK; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; @@ -32,7 +32,6 @@ import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; import java.util.ArrayList; -import java.util.List; import java.util.NoSuchElementException; import com.google.gson.JsonObject; @@ -40,7 +39,6 @@ import com.google.gson.JsonObject; import org.alfresco.com.FilePlanComponentType; import org.alfresco.rest.BaseRestTest; import org.alfresco.rest.core.RestWrapper; -import org.alfresco.rest.model.FilePlanComponentEntry; import org.alfresco.rest.model.FilePlanComponent; import org.alfresco.rest.model.FilePlanComponentProperties; import org.alfresco.rest.model.FilePlanComponentsCollection; @@ -48,7 +46,6 @@ import org.alfresco.rest.requests.FilePlanComponentApi; import org.alfresco.utility.data.DataUser; import org.alfresco.utility.data.RandomData; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; import org.testng.annotations.Test; /** @@ -103,8 +100,13 @@ public class RecordCategoryTest extends BaseRestTest // Verify the returned file plan component assertTrue(filePlanComponent.isIsCategory()); + assertFalse(filePlanComponent.isIsFile()); + assertFalse(filePlanComponent.isIsRecordFolder()); + assertEquals(filePlanComponent.getName(), categoryName); assertEquals(filePlanComponent.getNodeType(), RECORD_CATEGORY_TYPE.toString()); + assertFalse(filePlanComponent.isHasRetentionSchedule()); + assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername()); // Verify the returned file plan component properties @@ -317,7 +319,7 @@ public class RecordCategoryTest extends BaseRestTest assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType()); // verify properties - assertEquals(createdComponent.getProperties().getTitle(), filePlanComponent.getProperties().getTitle()); + //assertEquals(createdComponent.getProperties().getTitle(), filePlanComponent.getProperties().getTitle()); } catch (NoSuchElementException e) { @@ -337,17 +339,6 @@ public class RecordCategoryTest extends BaseRestTest return createComponent(parentCategoryId, categoryName, RECORD_CATEGORY_TYPE); } - /** - * Helper method to create child folder - * @param parentComponentId parent category or folder id - * @param folderName new folder name - * @throws Exception on unsuccessful folder creation - */ - private FilePlanComponent createFolder(String parentComponentId, String folderName) throws Exception - { - return createComponent(parentComponentId, folderName, RECORD_FOLDER_TYPE); - } - /** * Helper method to create generic child component * @param parentComponentId From 667ba1a656ea8542e98c656c1a3392ce1a6ee9f5 Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Thu, 27 Oct 2016 15:29:04 +0100 Subject: [PATCH 26/49] Fixed compilation issues. --- .../rest/model/FilePlanComponentEntry.java | 1 + .../FilePlanComponentProperties.java | 3 - .../rest/requests/FilePlanComponentApi.java | 4 +- .../java/org/alfresco/rest/BaseRestTest.java | 21 +++--- .../rest/fileplancomponents/RMSiteTests.java | 21 ++---- .../RecordCategoryTest.java | 68 +++++++++---------- 6 files changed, 54 insertions(+), 64 deletions(-) diff --git a/src/main/java/org/alfresco/rest/model/FilePlanComponentEntry.java b/src/main/java/org/alfresco/rest/model/FilePlanComponentEntry.java index c0c0d385f2..82ee037347 100644 --- a/src/main/java/org/alfresco/rest/model/FilePlanComponentEntry.java +++ b/src/main/java/org/alfresco/rest/model/FilePlanComponentEntry.java @@ -14,6 +14,7 @@ package org.alfresco.rest.model; import com.fasterxml.jackson.annotation.JsonProperty; import org.alfresco.rest.core.RestModels; +import org.alfresco.rest.model.fileplancomponents.FilePlanComponent; /** * POJO for file plan component entry diff --git a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java index e3a25084ce..805b6dd68d 100644 --- a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java @@ -18,9 +18,6 @@ import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPER import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; - /** * POJO for file plan component properties * diff --git a/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java b/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java index f2764539c6..bb3d82329d 100644 --- a/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java +++ b/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java @@ -23,8 +23,8 @@ import static org.springframework.http.HttpMethod.PUT; import com.google.gson.JsonObject; import org.alfresco.rest.core.RestAPI; -import org.alfresco.rest.model.FilePlanComponent; import org.alfresco.rest.model.FilePlanComponentsCollection; +import org.alfresco.rest.model.fileplancomponents.FilePlanComponent; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @@ -84,7 +84,7 @@ public class FilePlanComponentApi extends RestAPI filePlanComponentId )); } - + /** * Creates a file plan component with the given properties under the parent node with the given id * diff --git a/src/test/java/org/alfresco/rest/BaseRestTest.java b/src/test/java/org/alfresco/rest/BaseRestTest.java index 522ef3f240..af6669d371 100644 --- a/src/test/java/org/alfresco/rest/BaseRestTest.java +++ b/src/test/java/org/alfresco/rest/BaseRestTest.java @@ -19,11 +19,11 @@ import static org.alfresco.com.site.RMSiteFields.DESCRIPTION; import static org.alfresco.com.site.RMSiteFields.TITLE; import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.OK; import com.google.gson.JsonObject; import com.jayway.restassured.RestAssured; -import org.alfresco.dataprep.SiteService; import org.alfresco.rest.core.RestWrapper; import org.alfresco.rest.requests.RMSiteAPI; import org.alfresco.utility.data.DataUser; @@ -31,7 +31,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; -import org.springframework.http.HttpStatus; import org.testng.annotations.BeforeClass; /** @@ -64,10 +63,10 @@ public class BaseRestTest extends RestTest @Autowired public DataUser dataUser; - private static final String RM_ID = "rm"; - - @Autowired - private SiteService siteService; + // Constants + public static final String RM_ID = "rm"; + public static final String RM_TITLE = "Records Management"; + public static final String RM_DESCRIPTION = "Records Management Site"; /** * @see org.alfresco.rest.RestTest#checkServerHealth() @@ -79,6 +78,7 @@ public class BaseRestTest extends RestTest RestAssured.baseURI = scheme + "://" + host; RestAssured.port = parseInt(port); RestAssured.basePath = basePath; + //create RM Site if not exist createRMSiteIfNotExists(); } @@ -88,18 +88,18 @@ public class BaseRestTest extends RestTest */ public void createRMSiteIfNotExists() throws Exception { - final String RM_TITLE = "Records Management"; - final String RM_DESCRIPTION = "Records Management Site"; //check RM site doesn't exist if (!siteRMExist()) { rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + // Build the RM site properties JsonObject rmSiteProperties = buildObject() .add(TITLE, RM_TITLE) .add(DESCRIPTION, RM_DESCRIPTION) .add(COMPLIANCE, STANDARD.toString()) .getJson(); + // Create the RM site rmSiteAPI.createRMSite(rmSiteProperties); @@ -108,14 +108,13 @@ public class BaseRestTest extends RestTest } } - /** * Check the RM site exist via the GET request */ public boolean siteRMExist() throws Exception { - RestWrapper restWrapper=rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); rmSiteAPI.getSite(); - return restWrapper.getStatusCode().equals(HttpStatus.OK.toString()); + return restWrapper.getStatusCode().equals(OK.toString()); } } \ No newline at end of file diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java b/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java index 8b22ace9ef..0a575c81a5 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java @@ -36,19 +36,13 @@ import org.testng.annotations.Test; * FIXME: Should we use dependent tests or not? * They were removed here but there is no guarantee for the test execution order. * In {@link RecordCategoryTest} we create a record category first to delete it. - * Probbaly something to think about again. + * Probably something to think about again. * * @author Rodica Sutu * @since 1.0 */ public class RMSiteTests extends BaseRestTest { - - // Constants - private static final String RM_ID = "rm"; - private static final String RM_TITLE = "Records Management"; - private static final String RM_DESCRIPTION = "Records Management Site"; - @Test ( description = "Create RM site as admin user with standard Compliance" @@ -58,7 +52,7 @@ public class RMSiteTests extends BaseRestTest RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); if (siteRMExist()) { - //Delete the RM site + // Delete the RM site rmSiteAPI.deleteRMSite(); } // Build the RM site properties @@ -72,7 +66,7 @@ public class RMSiteTests extends BaseRestTest RMSite rmSite = rmSiteAPI.createRMSite(rmSiteProperties); // Verify the status code - rmSiteAPI.usingRestWrapper().assertStatusCodeIs(CREATED); + restWrapper.assertStatusCodeIs(CREATED); // Verify the returned file plan component assertEquals(rmSite.getId(), RM_ID); @@ -126,15 +120,15 @@ public class RMSiteTests extends BaseRestTest } @Test - ( - description = "GET RM site as admin user" - ) + ( + description = "GET RM site as admin user" + ) public void getRMSite() throws Exception { RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); // Get the RM site - RMSite rmSite=rmSiteAPI.getSite(); + RMSite rmSite = rmSiteAPI.getSite(); if (!siteRMExist()) { @@ -150,6 +144,5 @@ public class RMSiteTests extends BaseRestTest assertEquals(rmSite.getCompliance(), STANDARD); assertEquals(rmSite.getVisibility(), PUBLIC); } - } } diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java index 8b74076d36..db380ab373 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java @@ -13,13 +13,13 @@ package org.alfresco.rest.fileplancomponents; import static java.util.UUID.randomUUID; -import static org.alfresco.com.FilePlanComponentAlias.FILE_PLAN_ALIAS; -import static org.alfresco.com.FilePlanComponentFields.NAME; -import static org.alfresco.com.FilePlanComponentFields.NODE_TYPE; -import static org.alfresco.com.FilePlanComponentFields.PROPERTIES; -import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_TITLE; -import static org.alfresco.com.FilePlanComponentType.RECORD_CATEGORY_TYPE; -import static org.alfresco.com.FilePlanComponentType.RECORD_FOLDER_TYPE; +import static org.alfresco.com.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; +import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.NAME; +import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.NODE_TYPE; +import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES; +import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; +import static org.alfresco.com.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE; +import static org.alfresco.com.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE; import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.NO_CONTENT; @@ -35,13 +35,13 @@ import java.util.NoSuchElementException; import com.google.gson.JsonObject; -import org.alfresco.com.FilePlanComponentType; +import org.alfresco.com.fileplancomponents.FilePlanComponentType; import org.alfresco.rest.BaseRestTest; import org.alfresco.rest.core.RestWrapper; import org.alfresco.rest.model.FilePlanComponentEntry; -import org.alfresco.rest.model.FilePlanComponent; -import org.alfresco.rest.model.FilePlanComponentProperties; import org.alfresco.rest.model.FilePlanComponentsCollection; +import org.alfresco.rest.model.fileplancomponents.FilePlanComponent; +import org.alfresco.rest.model.fileplancomponents.FilePlanComponentProperties; import org.alfresco.rest.requests.FilePlanComponentApi; import org.alfresco.utility.data.DataUser; import org.alfresco.utility.data.RandomData; @@ -62,7 +62,7 @@ public class RecordCategoryTest extends BaseRestTest @Autowired private DataUser dataUser; - + // for children creation test private static final int NUMBER_OF_CHILDREN = 10; @@ -193,7 +193,7 @@ public class RecordCategoryTest extends BaseRestTest // Verify the status code restWrapper.assertStatusCodeIs(NO_CONTENT); } - + /** *
            * Given that a record category exists
      @@ -209,14 +209,14 @@ public class RecordCategoryTest extends BaseRestTest
               // create root level category
               FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), RandomData.getRandomAlphanumeric());
               assertNotNull(rootCategory.getId());
      -        
      +
               // create subcategory as a child of rootCategory
               FilePlanComponent childCategory = createCategory(rootCategory.getId(), RandomData.getRandomAlphanumeric());
      -        
      +
               // child category created?
               assertNotNull(childCategory.getId());
           }
      -    
      +
           /**
            * 
            * Given that a record category exists
      @@ -234,53 +234,53 @@ public class RecordCategoryTest extends BaseRestTest
               // create root level category
               FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), RandomData.getRandomAlphanumeric());
               assertNotNull(rootCategory.getId());
      -        
      +
               // add child categories/folders
               ArrayList children = new ArrayList();
      -        for(int i=0; i < NUMBER_OF_CHILDREN; i++)
      +        for (int i=0; i < NUMBER_OF_CHILDREN; i++)
               {
                   // create a child
      -            FilePlanComponent child = createComponent(rootCategory.getId(), 
      +            FilePlanComponent child = createComponent(rootCategory.getId(),
                       RandomData.getRandomAlphanumeric(),
                       // half of the children should be subcategories, the other subfolders
                       (i <= NUMBER_OF_CHILDREN / 2) ? RECORD_CATEGORY_TYPE : RECORD_FOLDER_TYPE);
                   assertNotNull(child.getId());
                   children.add(child);
               }
      -        
      +
               // list children from API
               RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser());
               FilePlanComponentsCollection apiChildren = filePlanComponentApi.listChildComponents(rootCategory.getId());
               restWrapper.assertStatusCodeIs(OK);
      -        
      +
               // check listed children against created list
               List childrenApi = apiChildren.getEntries();
      -        childrenApi.forEach(c -> 
      +        childrenApi.forEach(c ->
               {
                   FilePlanComponent filePlanComponent = c.getFilePlanComponent();
                   assertNotNull(filePlanComponent.getId());
      -            
      +
                   logger.info(c + " id=" + filePlanComponent.getId() + " name=" + filePlanComponent.getName() + " properties=" + filePlanComponent.getProperties());
      -            
      -            try 
      +
      +            try
                   {
                       FilePlanComponent createdComponent = children.stream()
                           .filter(child -> child.getId().compareTo(filePlanComponent.getId()) == 0)
                           .findFirst()
                           .get();
      -                
      +
                       // does returned object have the same contents as the created one?
                       assertEquals(createdComponent.getName(), filePlanComponent.getName());
                       assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType());
      -                assertEquals(createdComponent.getProperties().getTitle(), filePlanComponent.getProperties().getTitle());
      -            } 
      +                //assertEquals(createdComponent.getProperties().getTitle(), filePlanComponent.getProperties().getTitle());
      +            }
                   catch (NoSuchElementException e)
                   {
                       fail("No child element for " + filePlanComponent.getId());
                   }
               });
           }
      -    
      +
           /**
            * Helper method to create child category
            * @param parentCategoryId
      @@ -291,18 +291,18 @@ public class RecordCategoryTest extends BaseRestTest
           {
               return createComponent(parentCategoryId, categoryName, RECORD_CATEGORY_TYPE);
           }
      -    
      +
           /**
            * Helper method to create child folder
            * @param parentComponentId parent category or folder id
            * @param folderName new folder name
            * @throws Exception on unsuccessful folder creation
            */
      -    private FilePlanComponent createFolder(String parentComponentId, String folderName) throws Exception
      -    {
      -        return createComponent(parentComponentId, folderName, RECORD_FOLDER_TYPE);
      -    }
      -    
      +//    private FilePlanComponent createFolder(String parentComponentId, String folderName) throws Exception
      +//    {
      +//        return createComponent(parentComponentId, folderName, RECORD_FOLDER_TYPE);
      +//    }
      +
           /**
            * Helper method to create generic child component
            * @param parentComponentId
      
      From f896963188692b8b7718abcb35d6f8e6a1993cdc Mon Sep 17 00:00:00 2001
      From: Rodica Sutu 
      Date: Thu, 27 Oct 2016 19:03:33 +0300
      Subject: [PATCH 27/49] new tests for RM Site
      
      ---
       src/test/java/org/alfresco/rest/TestData.java | 21 +++++
       .../rest/fileplancomponents/RMSiteTests.java  | 86 +++++++++++++++----
       2 files changed, 89 insertions(+), 18 deletions(-)
       create mode 100644 src/test/java/org/alfresco/rest/TestData.java
      
      diff --git a/src/test/java/org/alfresco/rest/TestData.java b/src/test/java/org/alfresco/rest/TestData.java
      new file mode 100644
      index 0000000000..df52bdce2d
      --- /dev/null
      +++ b/src/test/java/org/alfresco/rest/TestData.java
      @@ -0,0 +1,21 @@
      +package org.alfresco.rest;
      +
      +/**
      + * Test data used in tests
      + *
      + * @author Rodica Sutu
      + */
      +public interface TestData
      +{
      +    /**
      +     * A user with ALFRESCO_ADMINISTRATORS role.
      +     * 

      "GROUP_ANOTHER_ADMIN_EXISTS" The ANOTHER_ADMIN user has been created. + */ + public static final String ANOTHER_ADMIN = "another_admin"; + + /** + * The default password used when creating test users. + */ + public static final String DEFAULT_PASSWORD = "password"; + public static final String DEFAULT_EMAIL = "default@alfresco.com"; +} diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java b/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java index 8b22ace9ef..98fd5dcb1f 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java @@ -11,10 +11,14 @@ */ package org.alfresco.rest.fileplancomponents; +import static org.alfresco.com.site.RMSiteCompliance.DOD5015; import static org.alfresco.com.site.RMSiteCompliance.STANDARD; import static org.alfresco.com.site.RMSiteFields.COMPLIANCE; import static org.alfresco.com.site.RMSiteFields.DESCRIPTION; import static org.alfresco.com.site.RMSiteFields.TITLE; +import static org.alfresco.rest.TestData.ANOTHER_ADMIN; +import static org.alfresco.rest.TestData.DEFAULT_EMAIL; +import static org.alfresco.rest.TestData.DEFAULT_PASSWORD; import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; import static org.springframework.http.HttpStatus.CONFLICT; import static org.springframework.http.HttpStatus.CREATED; @@ -26,9 +30,12 @@ import static org.testng.Assert.assertEquals; import com.google.gson.JsonObject; +import org.alfresco.dataprep.UserService; import org.alfresco.rest.BaseRestTest; import org.alfresco.rest.core.RestWrapper; import org.alfresco.rest.model.site.RMSite; +import org.alfresco.utility.model.UserModel; +import org.springframework.beans.factory.annotation.Autowired; import org.testng.annotations.Test; /** @@ -48,25 +55,27 @@ public class RMSiteTests extends BaseRestTest private static final String RM_ID = "rm"; private static final String RM_TITLE = "Records Management"; private static final String RM_DESCRIPTION = "Records Management Site"; + @Autowired + private UserService userService; @Test ( - description = "Create RM site as admin user with standard Compliance" + description = "Create RM site as admin user with Standard Compliance" ) public void createRMSiteAsAdminUser() throws Exception { - RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); if (siteRMExist()) { //Delete the RM site rmSiteAPI.deleteRMSite(); } // Build the RM site properties - JsonObject rmSiteProperties = buildObject(). - add(TITLE, RM_TITLE). - add(DESCRIPTION, RM_DESCRIPTION). - add(COMPLIANCE, STANDARD.toString()). - getJson(); + JsonObject rmSiteProperties = buildObject() + .add(TITLE, RM_TITLE) + .add(DESCRIPTION, RM_DESCRIPTION) + .add(COMPLIANCE, STANDARD.toString()) + .getJson(); // Create the RM site RMSite rmSite = rmSiteAPI.createRMSite(rmSiteProperties); @@ -97,11 +106,11 @@ public class RMSiteTests extends BaseRestTest String newDescription = RM_DESCRIPTION + "createRMSiteWhenSiteExists"; // Build the RM site properties - JsonObject rmSiteProperties = buildObject(). - add(TITLE, newTitle). - add(DESCRIPTION, newDescription). - add(COMPLIANCE, STANDARD.toString()). - getJson(); + JsonObject rmSiteProperties = buildObject() + .add(TITLE, newTitle) + .add(DESCRIPTION, newDescription) + .add(COMPLIANCE, STANDARD.toString()) + .getJson(); // Create the RM site rmSiteAPI.createRMSite(rmSiteProperties); @@ -126,16 +135,15 @@ public class RMSiteTests extends BaseRestTest } @Test - ( - description = "GET RM site as admin user" - ) + ( + description = "GET RM site as admin user" + ) public void getRMSite() throws Exception { RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); // Get the RM site RMSite rmSite=rmSiteAPI.getSite(); - if (!siteRMExist()) { // Verify the status code @@ -150,6 +158,48 @@ public class RMSiteTests extends BaseRestTest assertEquals(rmSite.getCompliance(), STANDARD); assertEquals(rmSite.getVisibility(), PUBLIC); } - } -} + + @Test + ( + description = "Create RM site as an admin user created with DOD compliance" + ) + public void createRMSiteAsAnotherAdminUser() throws Exception + { + rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + if (siteRMExist()) + { + //Delete the RM site + rmSiteAPI.deleteRMSite(); + } + rmSiteAPI.usingRestWrapper().disconnect(); + userService.create(dataUser.getAdminUser().getUsername(), + dataUser.getAdminUser().getPassword(), + ANOTHER_ADMIN, + DEFAULT_PASSWORD, + DEFAULT_EMAIL, + ANOTHER_ADMIN, + ANOTHER_ADMIN); + UserModel userModel=new UserModel(ANOTHER_ADMIN,DEFAULT_PASSWORD); + rmSiteAPI.usingRestWrapper().authenticateUser(userModel); + // Build the RM site properties + JsonObject rmSiteProperties = buildObject() + .add(TITLE, RM_TITLE) + .add(DESCRIPTION, RM_DESCRIPTION) + .add(COMPLIANCE, DOD5015.toString()) + .getJson(); + + // Create the RM site + RMSite rmSite = rmSiteAPI.createRMSite(rmSiteProperties); + + // Verify the status code + rmSiteAPI.usingRestWrapper().assertStatusCodeIs(CREATED); + + // Verify the returned file plan component + assertEquals(rmSite.getId(), RM_ID); + assertEquals(rmSite.getTitle(), RM_TITLE); + assertEquals(rmSite.getDescription(), RM_DESCRIPTION); + assertEquals(rmSite.getCompliance(), DOD5015); + assertEquals(rmSite.getVisibility(), PUBLIC); + } + } From dc0a6ed1a59bdb4eb2a0474832fb3410e663715c Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Thu, 27 Oct 2016 19:13:11 +0300 Subject: [PATCH 28/49] fix compilation error --- .../java/org/alfresco/rest/fileplancomponents/RMSiteTests.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java b/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java index b4378dcca9..858e82efab 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java @@ -50,6 +50,8 @@ import org.testng.annotations.Test; */ public class RMSiteTests extends BaseRestTest { + @Autowired + private UserService userService; @Test ( description = "Create RM site as admin user with Standard Compliance" From ca65f0a5a9cf864d2ef9566d6f8a321e4ce190b9 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Thu, 27 Oct 2016 19:22:11 +0300 Subject: [PATCH 29/49] fix compilation errors --- .../java/org/alfresco/rest/requests/FilePlanComponentApi.java | 2 +- .../alfresco/rest/fileplancomponents/RecordCategoryTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java b/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java index bb3d82329d..6c4c7463dc 100644 --- a/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java +++ b/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java @@ -23,8 +23,8 @@ import static org.springframework.http.HttpMethod.PUT; import com.google.gson.JsonObject; import org.alfresco.rest.core.RestAPI; -import org.alfresco.rest.model.FilePlanComponentsCollection; import org.alfresco.rest.model.fileplancomponents.FilePlanComponent; +import org.alfresco.rest.model.fileplancomponents.FilePlanComponentsCollection; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java index db380ab373..4741b32c63 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java @@ -38,10 +38,10 @@ import com.google.gson.JsonObject; import org.alfresco.com.fileplancomponents.FilePlanComponentType; import org.alfresco.rest.BaseRestTest; import org.alfresco.rest.core.RestWrapper; -import org.alfresco.rest.model.FilePlanComponentEntry; -import org.alfresco.rest.model.FilePlanComponentsCollection; import org.alfresco.rest.model.fileplancomponents.FilePlanComponent; +import org.alfresco.rest.model.fileplancomponents.FilePlanComponentEntry; import org.alfresco.rest.model.fileplancomponents.FilePlanComponentProperties; +import org.alfresco.rest.model.fileplancomponents.FilePlanComponentsCollection; import org.alfresco.rest.requests.FilePlanComponentApi; import org.alfresco.utility.data.DataUser; import org.alfresco.utility.data.RandomData; From 65472ca6c1d3d7fe61cd7636396a347b1feb5f18 Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Thu, 27 Oct 2016 21:06:55 +0100 Subject: [PATCH 30/49] Fixed dataprep issue --- .../java/org/alfresco/rest/BaseRestTest.java | 18 ++++++++--------- .../RMSiteTests.java | 3 ++- src/test/resources/config.properties | 4 ---- src/test/resources/default.properties | 20 +++++++++++++++++++ 4 files changed, 31 insertions(+), 14 deletions(-) rename src/test/java/org/alfresco/rest/{fileplancomponents => site}/RMSiteTests.java (98%) delete mode 100644 src/test/resources/config.properties create mode 100644 src/test/resources/default.properties diff --git a/src/test/java/org/alfresco/rest/BaseRestTest.java b/src/test/java/org/alfresco/rest/BaseRestTest.java index af6669d371..64fccd8a31 100644 --- a/src/test/java/org/alfresco/rest/BaseRestTest.java +++ b/src/test/java/org/alfresco/rest/BaseRestTest.java @@ -41,21 +41,21 @@ import org.testng.annotations.BeforeClass; * @since 1.0 */ @Configuration -@PropertySource("classpath:config.properties") +@PropertySource("classpath:default.properties") @PropertySource(value = "classpath:local.properties", ignoreResourceNotFound = true) public class BaseRestTest extends RestTest { - @Value ("${alfresco.rm.scheme}") + @Value ("${alfresco.scheme}") private String scheme; - @Value ("${alfresco.rm.host}") - private String host; + @Value ("${alfresco.server}") + private String server; - @Value ("${alfresco.rm.port}") + @Value ("${alfresco.port}") private String port; - @Value ("${alfresco.rm.basePath}") - private String basePath; + @Value ("${rest.rmPath}") + private String restRmPath; @Autowired public RMSiteAPI rmSiteAPI; @@ -75,9 +75,9 @@ public class BaseRestTest extends RestTest @BeforeClass(alwaysRun = true) public void checkServerHealth() throws Exception { - RestAssured.baseURI = scheme + "://" + host; + RestAssured.baseURI = scheme + "://" + server; RestAssured.port = parseInt(port); - RestAssured.basePath = basePath; + RestAssured.basePath = restRmPath; //create RM Site if not exist createRMSiteIfNotExists(); diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java b/src/test/java/org/alfresco/rest/site/RMSiteTests.java similarity index 98% rename from src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java rename to src/test/java/org/alfresco/rest/site/RMSiteTests.java index 858e82efab..4ebd4a9589 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RMSiteTests.java +++ b/src/test/java/org/alfresco/rest/site/RMSiteTests.java @@ -9,7 +9,7 @@ * agreement is prohibited. * #L% */ -package org.alfresco.rest.fileplancomponents; +package org.alfresco.rest.site; import static org.alfresco.com.site.RMSiteCompliance.DOD5015; import static org.alfresco.com.site.RMSiteCompliance.STANDARD; @@ -33,6 +33,7 @@ import com.google.gson.JsonObject; import org.alfresco.dataprep.UserService; import org.alfresco.rest.BaseRestTest; import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.fileplancomponents.RecordCategoryTest; import org.alfresco.rest.model.site.RMSite; import org.alfresco.utility.model.UserModel; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/test/resources/config.properties b/src/test/resources/config.properties deleted file mode 100644 index 899f737db2..0000000000 --- a/src/test/resources/config.properties +++ /dev/null @@ -1,4 +0,0 @@ -alfresco.rm.scheme=http -alfresco.rm.host=localhost -alfresco.rm.port=8080 -alfresco.rm.basePath=alfresco/api/-default-/public/ig/versions/1 \ No newline at end of file diff --git a/src/test/resources/default.properties b/src/test/resources/default.properties new file mode 100644 index 0000000000..47fa27dcf0 --- /dev/null +++ b/src/test/resources/default.properties @@ -0,0 +1,20 @@ +######################################################################### +# Original property values from default.properties # +######################################################################### + +# dataprep related +alfresco.scheme=http +alfresco.server=localhost +alfresco.port=8080 + +# credentials +admin.user=admin +admin.password=admin + +# rest related +rest.basePath=alfresco/api/-default-/public/alfresco/versions/1 +rest.workflowPath=alfresco/api/-default-/public/workflow/versions/1 + +######################################################################### + +rest.rmPath=alfresco/api/-default-/public/ig/versions/1 \ No newline at end of file From c611f6ff87fb3ea40b87cd9609109269ca20217a Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Fri, 28 Oct 2016 09:20:51 +0100 Subject: [PATCH 31/49] RM-3964: fixed a FIXME. --- .../com/fileplancomponents/FilePlanComponentFields.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentFields.java b/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentFields.java index 71495ca033..0981bcfc2a 100644 --- a/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentFields.java +++ b/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentFields.java @@ -12,7 +12,7 @@ package org.alfresco.com.fileplancomponents; /** - * FIXME: Document me :) + * File plan component field names constants * * @author Tuna Aksoy * @since 1.0 From d50590c5f0375c10843419c5835eb0d7ee2d4e3f Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Fri, 28 Oct 2016 11:53:04 +0100 Subject: [PATCH 32/49] RM-3964: Update further to code inspection comments. --- .../rest/fileplancomponents/RecordCategoryTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java index c969906e79..9744ac702e 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java @@ -74,7 +74,7 @@ public class RecordCategoryTest extends BaseRestTest */ @Test ( - description = "Create category as authorised user" + description = "Create root category" ) public void createCategoryTest() throws Exception { @@ -124,7 +124,7 @@ public class RecordCategoryTest extends BaseRestTest */ @Test ( - description = "Rename category as authorised user" + description = "Rename root category" ) public void renameCategory() throws Exception { @@ -176,7 +176,7 @@ public class RecordCategoryTest extends BaseRestTest */ @Test ( - description = "Delete category as authorised user" + description = "Delete category" ) public void deleteCategory() throws Exception { From 4b2c76b6d331be8ca559437ca92c78e3fff9006c Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Sat, 29 Oct 2016 23:02:55 +0100 Subject: [PATCH 33/49] Fixed config issue. --- src/test/resources/default.properties | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/test/resources/default.properties b/src/test/resources/default.properties index 47fa27dcf0..82d19c77d6 100644 --- a/src/test/resources/default.properties +++ b/src/test/resources/default.properties @@ -15,6 +15,11 @@ admin.password=admin rest.basePath=alfresco/api/-default-/public/alfresco/versions/1 rest.workflowPath=alfresco/api/-default-/public/workflow/versions/1 +# Database Section +db.url = jdbc:mysql://${alfresco.server}:3306/alfresco +db.username = alfresco +db.password = alfresco + ######################################################################### rest.rmPath=alfresco/api/-default-/public/ig/versions/1 \ No newline at end of file From 7d39b799d8ec4ceafab43ee72ac696970dccbe56 Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Sun, 30 Oct 2016 22:58:17 +0000 Subject: [PATCH 34/49] Removed test scope from restapi-test dependency in order to use it in the benchmark project directly --- pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/pom.xml b/pom.xml index b1c0b95331..a707968ca9 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,6 @@ restapi-test 1.0-SNAPSHOT test-jar - test org.jglue.fluent-json From d146c4454b0ce856261c30d12b925f74a1bebc0b Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Mon, 31 Oct 2016 08:33:41 +0200 Subject: [PATCH 35/49] File Plan CRUD API tests --- .../FilePlanComponentFields.java | 2 + .../FilePlanComponentType.java | 11 +- .../fileplancomponents/FilePlanComponent.java | 11 + .../FilePlanComponentProperties.java | 20 ++ .../rest/requests/FilePlanComponentApi.java | 6 +- src/test/java/org/alfresco/rest/TestData.java | 54 ++++ .../fileplancomponents/FilePlanTests.java | 259 ++++++++++++++++++ 7 files changed, 359 insertions(+), 4 deletions(-) create mode 100644 src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java diff --git a/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentFields.java b/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentFields.java index 0981bcfc2a..8a3c158085 100644 --- a/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentFields.java +++ b/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentFields.java @@ -26,4 +26,6 @@ public class FilePlanComponentFields public static final String PROPERTIES_TITLE = "cm:title"; public static final String PROPERTIES_VITAL_RECORD_INDICATOR = "rma:vitalRecordIndicator"; public static final String PROPERTIES_HOLD_REASON = "rma:holdReason"; + public static final String PROPERTIES_DESCRIPTION = "cm:description"; + public static final String ALLOWABLE_OPERATIONS = "allowableOperations"; } diff --git a/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentType.java b/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentType.java index ebf8cc070d..2af558be18 100644 --- a/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentType.java +++ b/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentType.java @@ -23,7 +23,10 @@ public enum FilePlanComponentType RECORD_CATEGORY_TYPE("rma:recordCategory"), RECORD_FOLDER_TYPE("rma:recordFolder"), HOLD_TYPE("rma:hold"), - UNFILED_RECORD_FOLDER_TYPE("rma:unfiledRecordFolder"); + UNFILED_RECORD_FOLDER_TYPE("rma:unfiledRecordFolder"), + HOLD_CONTAINER_TYPE("rma:holdContainer"), + TRANSFER_CONTAINER_TYPE("rma:transferContainer"), + UNFILED_CONTAINER_TYPE("rma:unfiledRecordContainer"); private String type; @@ -46,6 +49,12 @@ public enum FilePlanComponentType return HOLD_TYPE; case "rma:unfiledRecordFolder": return UNFILED_RECORD_FOLDER_TYPE; + case "rma:holdContainer": + return HOLD_CONTAINER_TYPE; + case "rma:transferContainer": + return TRANSFER_CONTAINER_TYPE; + case "rma:unfiledRecordContainer": + return UNFILED_CONTAINER_TYPE; } throw new IllegalArgumentException("Invalid file plan component type enum value: '" + type + "'."); diff --git a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java index 14f33de343..22a09c27bd 100644 --- a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java @@ -11,6 +11,7 @@ */ package org.alfresco.rest.model.fileplancomponents; +import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.ALLOWABLE_OPERATIONS; import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES; import java.util.List; @@ -51,6 +52,8 @@ public class FilePlanComponent private FilePlanComponentCreatedByUser createdByUser; + @JsonProperty (ALLOWABLE_OPERATIONS) + private List allowableOperations; /** * @return the id */ @@ -226,4 +229,12 @@ public class FilePlanComponent { this.createdByUser = createdByUser; } + + /** + * @return the allowableOperations + */ + public List getAllowableOperations() + { + return this.allowableOperations; + } } diff --git a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java index 805b6dd68d..34e069be03 100644 --- a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java @@ -11,6 +11,7 @@ */ package org.alfresco.rest.model.fileplancomponents; +import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_DESCRIPTION; import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_HOLD_REASON; import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR; @@ -37,6 +38,8 @@ public class FilePlanComponentProperties @JsonProperty(PROPERTIES_HOLD_REASON) private String holdReason; + @JsonProperty (PROPERTIES_DESCRIPTION) + private String description; /** * @return the vitalRecord */ @@ -84,4 +87,21 @@ public class FilePlanComponentProperties { this.holdReason = holdReason; } + + /** + * @param description the description to set + */ + public void setDescription(String description) + { + this.description = description; + } + + /** + * @return the description + */ + public String getDescription() + { + return this.description; + } + } diff --git a/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java b/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java index 6c4c7463dc..11c892d24d 100644 --- a/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java +++ b/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java @@ -37,7 +37,7 @@ import org.springframework.stereotype.Component; */ @Component @Scope(value = "prototype") -public class FilePlanComponentApi extends RestAPI +public class FilePlanComponentApi extends RestAPI { /** * Get a file plan component @@ -57,8 +57,8 @@ public class FilePlanComponentApi extends RestAPI return usingRestWrapper().processModel(FilePlanComponent.class, simpleRequest( GET, - "fileplan-components/{fileplanComponentId}", - filePlanComponentId + "fileplan-components/{fileplanComponentId}?{parameters}", + filePlanComponentId, getParameters() )); } diff --git a/src/test/java/org/alfresco/rest/TestData.java b/src/test/java/org/alfresco/rest/TestData.java index df52bdce2d..a9fb20daea 100644 --- a/src/test/java/org/alfresco/rest/TestData.java +++ b/src/test/java/org/alfresco/rest/TestData.java @@ -1,5 +1,27 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ package org.alfresco.rest; +import static org.alfresco.com.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; +import static org.alfresco.com.fileplancomponents.FilePlanComponentAlias.HOLDS_ALIAS; +import static org.alfresco.com.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS; +import static org.alfresco.com.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS; +import static org.alfresco.com.fileplancomponents.FilePlanComponentType.FILE_PLAN_TYPE; +import static org.alfresco.com.fileplancomponents.FilePlanComponentType.HOLD_CONTAINER_TYPE; +import static org.alfresco.com.fileplancomponents.FilePlanComponentType.TRANSFER_CONTAINER_TYPE; +import static org.alfresco.com.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE; + +import org.testng.annotations.DataProvider; + /** * Test data used in tests * @@ -18,4 +40,36 @@ public interface TestData */ public static final String DEFAULT_PASSWORD = "password"; public static final String DEFAULT_EMAIL = "default@alfresco.com"; + + /** + * Data Provider with the special file plan components alias + * @return file plan component alias + */ + @DataProvider + public static Object[][] getContainers() + { + return new Object[][] { + { FILE_PLAN_ALIAS.toString() }, + { TRANSFERS_ALIAS.toString() }, + { HOLDS_ALIAS.toString() }, + { UNFILED_RECORDS_CONTAINER_ALIAS.toString() }, + }; + } + + /** + * Data Provider with: + * the special file plan components alias + * file plan component node type + * @return file plan component alias + */ + @DataProvider + public static Object[][] getContainersAndTypes() + { + return new Object[][] { + { FILE_PLAN_ALIAS, FILE_PLAN_TYPE }, + { TRANSFERS_ALIAS, TRANSFER_CONTAINER_TYPE }, + { HOLDS_ALIAS, HOLD_CONTAINER_TYPE }, + { UNFILED_RECORDS_CONTAINER_ALIAS, UNFILED_CONTAINER_TYPE }, + }; + } } diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java new file mode 100644 index 0000000000..a2966251fd --- /dev/null +++ b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java @@ -0,0 +1,259 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.rest.fileplancomponents; + +import static java.util.UUID.randomUUID; + +import static org.alfresco.com.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; +import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.NAME; +import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.NODE_TYPE; +import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES; +import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_DESCRIPTION; +import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; +import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; +import static org.springframework.http.HttpStatus.FORBIDDEN; +import static org.springframework.http.HttpStatus.NOT_FOUND; +import static org.springframework.http.HttpStatus.OK; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import java.util.Arrays; + +import com.google.gson.JsonObject; + +import org.alfresco.com.fileplancomponents.FilePlanComponentAlias; +import org.alfresco.com.fileplancomponents.FilePlanComponentType; +import org.alfresco.rest.BaseRestTest; +import org.alfresco.rest.TestData; +import org.alfresco.rest.model.fileplancomponents.FilePlanComponent; +import org.alfresco.rest.requests.FilePlanComponentApi; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.Test; + +/** + * This class contains the test for testing + * the File Plan CRUD API + * + * @author Rodica Sutu + * @since 1.0 + */ +public class FilePlanTests extends BaseRestTest +{ + @Autowired + private FilePlanComponentApi filePlanComponentApi; + + @Autowired + private DataUser dataUser; + + /** + * Given that the RM site doesn't exist + * When I use the API to get the File Plan/holds/unfiled/transfers + * Then I get the 404 response code + */ + @Test + ( + description = "Check the GET response code when the RM site doesn't exist", + dataProviderClass = TestData.class, + dataProvider = "getContainers" + ) + public void getFilePlanComponentWhenRMIsNotCreated(String filePlanAlias) throws Exception + { + //check RM Site Exist + if (siteRMExist()) + { + //delete RM Site + rmSiteAPI.deleteRMSite(); + } + filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + //get the file plan component + filePlanComponentApi.getFilePlanComponent(filePlanAlias.toString()); + //check the response code is NOT_FOUND + filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(NOT_FOUND); + } + + /** + * Given that a file plan exists + * When I ask the API for the details of the file plan + * Then I am given the details of the file plan + */ + @Test + ( + description = "Check the GET response for special file plan components when the RM site exit", + dataProviderClass = TestData.class, + dataProvider = "getContainersAndTypes" + ) + public void getFilePlanComponentWhenRMIsCreated(FilePlanComponentAlias filePlanAlias, FilePlanComponentType rmType) throws Exception + { + //create RM Site if doesn't exist + createRMSiteIfNotExists(); + //authenticate with admin user + filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + //get the file plan special container + FilePlanComponent filePlanComponent=filePlanComponentApi.getFilePlanComponent(filePlanAlias.toString()); + //check the response code + filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(OK); + //check the response contains the right node type + assertEquals(filePlanComponent.getNodeType(), rmType.toString()); + } + + /** + * Given that a file plan exists + * When I ask the API for the details of the file plan to include the allowableOperations property + * Then I am given the allowableOperations property with the update and create operations. + */ + @Test + ( + description = "Check the allowableOperations list returned ", + dataProviderClass = TestData.class, + dataProvider = "getContainers" + ) + public void includeAllowableOperations(FilePlanComponentAlias filePlanAlias) throws Exception + { + //create RM Site if doesn't exist + createRMSiteIfNotExists(); + filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + //GET the file plan special containers with the optional parameter allowableOperations + FilePlanComponent filePlanComponent = filePlanComponentApi.withParams("include=allowableOperations").getFilePlanComponent(filePlanAlias.toString()); + //Check the list of allowableOperations returned + assertTrue(filePlanComponent.getAllowableOperations().containsAll(Arrays.asList("update", "create")), + "Wrong list of the allowable operations is return" + filePlanComponent.getAllowableOperations().toString()); + //check the list of allowableOperations doesn't contains DELETE operation + assertFalse(filePlanComponent.getAllowableOperations().contains("delete"), + "The list of allowable operations contains delete option"+ filePlanComponent.getAllowableOperations().toString()); + } + + /** + * Given that a file plan exists + * When I ask the API to modify the details of the file plan + * Then the details of the file are modified + * Note: the details of the file plan are limited to title and description. + */ + @Test + @Bug (id = "RM-4295") + public void updateFilePlan() throws Exception + { + String FILE_PLAN_DESCRIPTION="Description updated " +randomUUID().toString().substring(0, 4); + String FILE_PLAN_TITLE = "Title updated " + randomUUID().toString().substring(0, 4); + //create RM Site if doesn't exist + createRMSiteIfNotExists(); + filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + //Build the file plan root properties + JsonObject filePlanProperties = buildObject() + .addObject(PROPERTIES) + .add(PROPERTIES_TITLE, FILE_PLAN_TITLE) + .add(PROPERTIES_DESCRIPTION, FILE_PLAN_DESCRIPTION) + .end() + .getJson(); + + + // Update the record category + FilePlanComponent renamedFilePlanComponent = filePlanComponentApi.updateFilePlanComponent(filePlanProperties,FILE_PLAN_ALIAS.toString()); + + // Verify the response status code + filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(OK); + + // Verify the returned description field for the file plan component + assertEquals(renamedFilePlanComponent.getProperties().getDescription(), FILE_PLAN_DESCRIPTION); + // Verify the returned title field for the file plan component + assertEquals(renamedFilePlanComponent.getProperties().getTitle(), FILE_PLAN_TITLE); + } + + /** + * Given that a file plan exists + * When I ask the API to delete the file plan + * Then the 405 response code is returned. (see https://docs.google.com/document/d/1l4tcAnZotJR6qTHI4LFi62dy_i5Zuk-9ImDXDHpD_rA/edit?ts=578f7b64# page 20 and36) + */ + @Test + ( + description = "Check the response code when deleting the special file plan components", + dataProviderClass = TestData.class, + dataProvider = "getContainers" + ) + public void deleteFilePlanSpecialComponents(String filePlanAlias) throws Exception + { + createRMSiteIfNotExists(); + filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + //get the file plan component + filePlanComponentApi.deleteFilePlanComponent(filePlanAlias.toString()); + //check the DELETE response status code + filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); + } + + /** + * Given that RM site exists + * When I ask to create the file plan + * Then the 405 response code is returned. (see https://docs.google.com/document/d/1l4tcAnZotJR6qTHI4LFi62dy_i5Zuk-9ImDXDHpD_rA/edit?ts=578f7b64# page 20) + */ + @Test + ( + description = "Check the response code when creating the special file plan components", + dataProviderClass = TestData.class, + dataProvider = "getContainersAndTypes" + ) + @Bug(id="RM-4296") + public void createFilePlanSpecialContainerWhenExists(FilePlanComponentAlias filePlanAlias, FilePlanComponentType rmType) throws Exception + { + String rmSiteId=rmSiteAPI.getSite().getGuid(); + + //create RM Site if doesn't exist + createRMSiteIfNotExists(); + filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + String COMPONENT_TITLE = filePlanAlias + randomUUID().toString().substring(0, 4); + //Build the file plan root properties + JsonObject componentProperties = buildObject() + .add(NAME, COMPONENT_TITLE) + .add(NODE_TYPE, rmType.toString()) + .getJson(); + //create the special containers into RM site - parent folder + filePlanComponentApi.createFilePlanComponent(componentProperties, rmSiteId); + filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); + + //create the special containers into RM site - parent folder + filePlanComponentApi.createFilePlanComponent(componentProperties, FILE_PLAN_ALIAS.toString()); + filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); + + //create the special containers into the root of special containers containers + filePlanComponentApi.createFilePlanComponent(componentProperties, filePlanAlias.toString()); + filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); + } + + /** + * Given that RM exists + * When a non-RM user ask the API for the details of the file plan + * Then the status code 403 (Permission denied) is return + */ + @Test + ( + description = "Check the response code when the RM site containers are get with non rm users", + dataProviderClass = TestData.class, + dataProvider = "getContainers" + ) + public void getSpecialFilePlanComponentsWithNonRMuser(String filePlanAlias) throws Exception + { + //create RM Site if doesn't exist + createRMSiteIfNotExists(); + rmSiteAPI.usingRestWrapper().disconnect(); + restClient.authenticateUser(dataUser.getAdminUser()); + //create a random user + UserModel nonRMuser = dataUser.createRandomTestUser("testUser"); + //authenticate using the random user + filePlanComponentApi.usingRestWrapper().authenticateUser(nonRMuser); + //get the special file plan components + filePlanComponentApi.getFilePlanComponent(filePlanAlias.toString()); + //check the response status code -FORBIDDEN + filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); + } +} From 6ed52b60cb5654ec3b4b7c7b27efe296df937f25 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Mon, 31 Oct 2016 10:40:03 +0200 Subject: [PATCH 36/49] remove some indentation,update AC as per review comment --- .../rest/fileplancomponents/FilePlanTests.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java index a2966251fd..608e430d53 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java @@ -199,9 +199,9 @@ public class FilePlanTests extends BaseRestTest */ @Test ( - description = "Check the response code when creating the special file plan components", - dataProviderClass = TestData.class, - dataProvider = "getContainersAndTypes" + description = "Check the response code when creating the special file plan components", + dataProviderClass = TestData.class, + dataProvider = "getContainersAndTypes" ) @Bug(id="RM-4296") public void createFilePlanSpecialContainerWhenExists(FilePlanComponentAlias filePlanAlias, FilePlanComponentType rmType) throws Exception @@ -231,15 +231,15 @@ public class FilePlanTests extends BaseRestTest } /** - * Given that RM exists + * Given that RM site exists * When a non-RM user ask the API for the details of the file plan * Then the status code 403 (Permission denied) is return */ @Test ( - description = "Check the response code when the RM site containers are get with non rm users", - dataProviderClass = TestData.class, - dataProvider = "getContainers" + description = "Check the response code when the RM site containers are get with non rm users", + dataProviderClass = TestData.class, + dataProvider = "getContainers" ) public void getSpecialFilePlanComponentsWithNonRMuser(String filePlanAlias) throws Exception { From d5cebb2757bed519f2e882e416388eb3612c5239 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Mon, 31 Oct 2016 14:56:09 +0200 Subject: [PATCH 37/49] Fix the mismatch argument type --- .../org/alfresco/rest/fileplancomponents/FilePlanTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java index 608e430d53..4969e5ebcd 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java @@ -120,13 +120,13 @@ public class FilePlanTests extends BaseRestTest dataProviderClass = TestData.class, dataProvider = "getContainers" ) - public void includeAllowableOperations(FilePlanComponentAlias filePlanAlias) throws Exception + public void includeAllowableOperations(String specialContainerAlias) throws Exception { //create RM Site if doesn't exist createRMSiteIfNotExists(); filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); //GET the file plan special containers with the optional parameter allowableOperations - FilePlanComponent filePlanComponent = filePlanComponentApi.withParams("include=allowableOperations").getFilePlanComponent(filePlanAlias.toString()); + FilePlanComponent filePlanComponent = filePlanComponentApi.withParams("include=allowableOperations").getFilePlanComponent(specialContainerAlias); //Check the list of allowableOperations returned assertTrue(filePlanComponent.getAllowableOperations().containsAll(Arrays.asList("update", "create")), "Wrong list of the allowable operations is return" + filePlanComponent.getAllowableOperations().toString()); From 4eb968f0573420167b5afdb53b3e24084535f7e9 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Mon, 31 Oct 2016 18:30:02 +0200 Subject: [PATCH 38/49] updates on RM Site API tests --- .../fileplancomponents/FilePlanTests.java | 4 +- .../org/alfresco/rest/site/RMSiteTests.java | 128 +++++++++++++++++- 2 files changed, 124 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java index 4969e5ebcd..45bbc41c5b 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java @@ -174,7 +174,7 @@ public class FilePlanTests extends BaseRestTest /** * Given that a file plan exists * When I ask the API to delete the file plan - * Then the 405 response code is returned. (see https://docs.google.com/document/d/1l4tcAnZotJR6qTHI4LFi62dy_i5Zuk-9ImDXDHpD_rA/edit?ts=578f7b64# page 20 and36) + * Then the 403 response code is returned. */ @Test ( @@ -195,7 +195,7 @@ public class FilePlanTests extends BaseRestTest /** * Given that RM site exists * When I ask to create the file plan - * Then the 405 response code is returned. (see https://docs.google.com/document/d/1l4tcAnZotJR6qTHI4LFi62dy_i5Zuk-9ImDXDHpD_rA/edit?ts=578f7b64# page 20) + * Then the 403 response code is returned. */ @Test ( diff --git a/src/test/java/org/alfresco/rest/site/RMSiteTests.java b/src/test/java/org/alfresco/rest/site/RMSiteTests.java index 4ebd4a9589..c503a96758 100644 --- a/src/test/java/org/alfresco/rest/site/RMSiteTests.java +++ b/src/test/java/org/alfresco/rest/site/RMSiteTests.java @@ -20,13 +20,16 @@ import static org.alfresco.rest.TestData.ANOTHER_ADMIN; import static org.alfresco.rest.TestData.DEFAULT_EMAIL; import static org.alfresco.rest.TestData.DEFAULT_PASSWORD; import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; +import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.CONFLICT; import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.FORBIDDEN; import static org.springframework.http.HttpStatus.NOT_FOUND; import static org.springframework.http.HttpStatus.NO_CONTENT; import static org.springframework.http.HttpStatus.OK; import static org.springframework.social.alfresco.api.entities.Site.Visibility.PUBLIC; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; import com.google.gson.JsonObject; @@ -35,7 +38,10 @@ import org.alfresco.rest.BaseRestTest; import org.alfresco.rest.core.RestWrapper; import org.alfresco.rest.fileplancomponents.RecordCategoryTest; import org.alfresco.rest.model.site.RMSite; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.RandomData; import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; import org.springframework.beans.factory.annotation.Autowired; import org.testng.annotations.Test; @@ -53,9 +59,17 @@ public class RMSiteTests extends BaseRestTest { @Autowired private UserService userService; + + + /** + * Given that RM module is installed + * When I want to create the rm site with specific title, description and compliance + * Then the RM site is created + * + */ @Test ( - description = "Create RM site as admin user with Standard Compliance" + description = "Create RM site as admin user with Standard Compliance" ) public void createRMSiteAsAdminUser() throws Exception { @@ -84,11 +98,17 @@ public class RMSiteTests extends BaseRestTest assertEquals(rmSite.getDescription(), RM_DESCRIPTION); assertEquals(rmSite.getCompliance(), STANDARD); assertEquals(rmSite.getVisibility(), PUBLIC); + assertEquals(rmSite.getRole(), UserRole.SiteManager.toString()); } + /** + * Given that RM site exists + * When I want to create the RM site + * Then the response code 409 (Site with the given identifier already exists) is return + */ @Test ( - description = "Create RM site when site already exist with admin user" + description = "Create RM site when site already exist with admin user" ) public void createRMSiteWhenSiteExists() throws Exception { @@ -114,9 +134,14 @@ public class RMSiteTests extends BaseRestTest restWrapper.assertStatusCodeIs(CONFLICT); } + /** + * Given that RM site exists + * When I want to delete the RM site + * Then RM site is successfully deleted + */ @Test ( - description = "Delete RM site as admin user" + description = "Delete RM site as admin user" ) public void deleteRMSite() throws Exception { @@ -129,9 +154,14 @@ public class RMSiteTests extends BaseRestTest restWrapper.assertStatusCodeIs(NO_CONTENT); } + /** + * Given that RM site exists + * When I GET the retrieve the RM site details + * Then RM site details are returned + */ @Test ( - description = "GET RM site as admin user" + description = "GET the RM site as admin user" ) public void getRMSite() throws Exception { @@ -141,8 +171,9 @@ public class RMSiteTests extends BaseRestTest RMSite rmSite = rmSiteAPI.getSite(); if (!siteRMExist()) { - // Verify the status code + // Verify the status code when rm site doesn't exist restWrapper.assertStatusCodeIs(NOT_FOUND); + createRMSiteIfNotExists(); } else { @@ -155,10 +186,16 @@ public class RMSiteTests extends BaseRestTest } } + /** + * Given that an user is created and RM site doesn't exist + * When the user wants to create a RM site with DOD compliance + * Then RM site is created + */ @Test ( - description = "Create RM site as an admin user created with DOD compliance" + description = "Create RM site with DOD compliance as an another admin user" ) + @Bug (id="RM-4289") public void createRMSiteAsAnotherAdminUser() throws Exception { rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); @@ -196,5 +233,84 @@ public class RMSiteTests extends BaseRestTest assertEquals(rmSite.getDescription(), RM_DESCRIPTION); assertEquals(rmSite.getCompliance(), DOD5015); assertEquals(rmSite.getVisibility(), PUBLIC); + assertEquals(rmSite.getRole(), UserRole.SiteManager.toString()); + } + + /** + * Given that RM site exist + * When a new created user want to update the RM site details (title or description) + * Then 403 response status code is return + * When the admin user wants to update the RM site details (title or description) + * Then RM site details are updated + */ + @Test + public void updateRMSiteDetailsAsAdmin()throws Exception + { + String NEW_TITLE = RM_TITLE + RandomData.getRandomAlphanumeric(); + String NEW_DESCRIPTION=RM_DESCRIPTION+ RandomData.getRandomAlphanumeric(); + + // Build the RM site properties + JsonObject rmSiteToUpdate = buildObject() + .add(TITLE, NEW_TITLE) + .add(DESCRIPTION, NEW_DESCRIPTION) + .getJson(); + + rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + if (!siteRMExist()) + { + createRMSiteIfNotExists(); + } + + rmSiteAPI.usingRestWrapper().disconnect(); + UserModel nonRMuser = dataUser.createRandomTestUser("testUser"); + rmSiteAPI.usingRestWrapper().authenticateUser(nonRMuser); + + // Create the RM site + RMSite rmSite = rmSiteAPI.updateRMSite(rmSiteToUpdate); + + // Verify the status code + rmSiteAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); + + rmSiteAPI.usingRestWrapper().disconnect(); + rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + // Update the RM Site + rmSite = rmSiteAPI.updateRMSite(rmSiteToUpdate); + + // Verify the response status code + rmSiteAPI.usingRestWrapper().assertStatusCodeIs(OK); + + // Verify the returned file plan component + assertEquals(rmSite.getId(), RM_ID); + assertEquals(rmSite.getTitle(), NEW_TITLE); + assertEquals(rmSite.getDescription(), NEW_DESCRIPTION); + assertNotNull(rmSite.getCompliance()); + assertEquals(rmSite.getVisibility(), PUBLIC); + + } + + + /** + * Given that RM site exist + * When the admin user wants to update the RM site compliance + * Then RM site compliance is not updated + */ + @Test + public void updateRMSiteComplianceAsAdmin() throws Exception + { + rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + if (!siteRMExist()) + { + createRMSiteIfNotExists(); + } + // Build the RM site properties + JsonObject rmSiteToUpdate = buildObject() + .add(COMPLIANCE, DOD5015.toString()) + .getJson(); + // Update the RM site + RMSite rmSite = rmSiteAPI.updateRMSite(rmSiteToUpdate); + + // Verify the response status code + rmSiteAPI.usingRestWrapper().assertStatusCodeIs(BAD_REQUEST); } } From 4330ae08c7d8df06e6020f42f8c3b9524c3bc78b Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Tue, 1 Nov 2016 08:39:49 +0200 Subject: [PATCH 39/49] minor updates --- .../java/org/alfresco/rest/site/RMSiteTests.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/test/java/org/alfresco/rest/site/RMSiteTests.java b/src/test/java/org/alfresco/rest/site/RMSiteTests.java index c503a96758..01748a13d2 100644 --- a/src/test/java/org/alfresco/rest/site/RMSiteTests.java +++ b/src/test/java/org/alfresco/rest/site/RMSiteTests.java @@ -36,7 +36,6 @@ import com.google.gson.JsonObject; import org.alfresco.dataprep.UserService; import org.alfresco.rest.BaseRestTest; import org.alfresco.rest.core.RestWrapper; -import org.alfresco.rest.fileplancomponents.RecordCategoryTest; import org.alfresco.rest.model.site.RMSite; import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.data.RandomData; @@ -46,11 +45,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.testng.annotations.Test; /** - * FIXME: Document me :) - * FIXME: Should we use dependent tests or not? - * They were removed here but there is no guarantee for the test execution order. - * In {@link RecordCategoryTest} we create a record category first to delete it. - * Probbaly something to think about again. + * This class contains the test for testing + * the RM site CRUD API * * @author Rodica Sutu * @since 1.0 @@ -69,7 +65,7 @@ public class RMSiteTests extends BaseRestTest */ @Test ( - description = "Create RM site as admin user with Standard Compliance" + description = "Create RM site with Standard Compliance as admin user" ) public void createRMSiteAsAdminUser() throws Exception { @@ -238,13 +234,13 @@ public class RMSiteTests extends BaseRestTest /** * Given that RM site exist - * When a new created user want to update the RM site details (title or description) + * When a non-RM user wants to update the RM site details (title or description) * Then 403 response status code is return * When the admin user wants to update the RM site details (title or description) * Then RM site details are updated */ @Test - public void updateRMSiteDetailsAsAdmin()throws Exception + public void updateRMSiteDetails()throws Exception { String NEW_TITLE = RM_TITLE + RandomData.getRandomAlphanumeric(); String NEW_DESCRIPTION=RM_DESCRIPTION+ RandomData.getRandomAlphanumeric(); @@ -286,7 +282,6 @@ public class RMSiteTests extends BaseRestTest assertEquals(rmSite.getDescription(), NEW_DESCRIPTION); assertNotNull(rmSite.getCompliance()); assertEquals(rmSite.getVisibility(), PUBLIC); - } From bec85dc308dce9979ee5c55a542875895a75ac83 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Tue, 1 Nov 2016 09:21:57 +0200 Subject: [PATCH 40/49] minor update --- .../org/alfresco/rest/fileplancomponents/FilePlanTests.java | 2 +- src/test/java/org/alfresco/rest/site/RMSiteTests.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java index 45bbc41c5b..cc7888575f 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java @@ -44,7 +44,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.testng.annotations.Test; /** - * This class contains the test for testing + * This class contains the tests for * the File Plan CRUD API * * @author Rodica Sutu diff --git a/src/test/java/org/alfresco/rest/site/RMSiteTests.java b/src/test/java/org/alfresco/rest/site/RMSiteTests.java index 01748a13d2..813ecf52c0 100644 --- a/src/test/java/org/alfresco/rest/site/RMSiteTests.java +++ b/src/test/java/org/alfresco/rest/site/RMSiteTests.java @@ -45,7 +45,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.testng.annotations.Test; /** - * This class contains the test for testing + * This class contains the tests for * the RM site CRUD API * * @author Rodica Sutu From 43e483d0bc1d667b54d9f9ea934a690d67d980c9 Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Tue, 1 Nov 2016 19:42:39 +0000 Subject: [PATCH 41/49] Refactored code --- README | 2 +- .../fileplancomponents/FilePlanComponent.java | 20 +- .../FilePlanComponentAlias.java | 31 ++- .../FilePlanComponentCreatedByUser.java | 5 + .../FilePlanComponentEntry.java | 5 +- .../FilePlanComponentFields.java | 3 +- .../FilePlanComponentProperties.java | 12 +- .../FilePlanComponentType.java | 39 ++-- .../FilePlanComponentsCollection.java | 1 + .../org/alfresco/rest/model/site/RMSite.java | 3 +- .../model}/site/RMSiteCompliance.java | 2 +- .../model}/site/RMSiteFields.java | 2 +- ...nentApi.java => FilePlanComponentAPI.java} | 6 +- .../org/alfresco/rest/requests/RMSiteAPI.java | 8 +- .../{com => rest}/util/ParameterCheck.java | 19 +- .../rest/base/AllowableOperations.java | 25 +++ .../rest/{ => base}/BaseRestTest.java | 26 +-- .../alfresco/rest/{ => base}/TestData.java | 23 ++- .../fileplancomponents/FilePlanTests.java | 191 +++++++++++------- .../RecordCategoryTest.java | 180 +++++++++-------- .../org/alfresco/rest/site/RMSiteTests.java | 93 ++++++--- src/test/resources/default.properties | 6 +- 22 files changed, 417 insertions(+), 285 deletions(-) rename src/main/java/org/alfresco/{com => rest/model}/fileplancomponents/FilePlanComponentAlias.java (58%) rename src/main/java/org/alfresco/{com => rest/model}/fileplancomponents/FilePlanComponentFields.java (91%) rename src/main/java/org/alfresco/{com => rest/model}/fileplancomponents/FilePlanComponentType.java (58%) rename src/main/java/org/alfresco/{com => rest/model}/site/RMSiteCompliance.java (92%) rename src/main/java/org/alfresco/{com => rest/model}/site/RMSiteFields.java (96%) rename src/main/java/org/alfresco/rest/requests/{FilePlanComponentApi.java => FilePlanComponentAPI.java} (97%) rename src/main/java/org/alfresco/{com => rest}/util/ParameterCheck.java (63%) create mode 100644 src/test/java/org/alfresco/rest/base/AllowableOperations.java rename src/test/java/org/alfresco/rest/{ => base}/BaseRestTest.java (83%) rename src/test/java/org/alfresco/rest/{ => base}/TestData.java (66%) diff --git a/README b/README index da2b8cbd31..907f41ab0a 100644 --- a/README +++ b/README @@ -1,3 +1,3 @@ -FIXME: DOCUMENT ME BETTER :) +FIXME: Add more info to the README file In order to change the value of a property in "config.properties" create a file called "local.properties" under src/test/resources and redefine the property with the new value. \ No newline at end of file diff --git a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java index 22a09c27bd..2090616ac9 100644 --- a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java @@ -11,8 +11,8 @@ */ package org.alfresco.rest.model.fileplancomponents; -import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.ALLOWABLE_OPERATIONS; -import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.ALLOWABLE_OPERATIONS; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES; import java.util.List; @@ -28,32 +28,22 @@ import com.fasterxml.jackson.annotation.JsonProperty; //FIXME: Once the fields have been added the JsonIgnoreProperties annotation should be removed @JsonIgnoreProperties(ignoreUnknown = true) public class FilePlanComponent -{ +{ private String id; - private String parentId; - private String name; - private String nodeType; - private boolean isCategory; - private boolean isRecordFolder; - private boolean isFile; - private boolean hasRetentionSchedule; - private List aspectNames; - + private FilePlanComponentCreatedByUser createdByUser; @JsonProperty(PROPERTIES) private FilePlanComponentProperties properties; - - private FilePlanComponentCreatedByUser createdByUser; - @JsonProperty (ALLOWABLE_OPERATIONS) private List allowableOperations; + /** * @return the id */ diff --git a/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentAlias.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentAlias.java similarity index 58% rename from src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentAlias.java rename to src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentAlias.java index 45ada4d9ec..975324531a 100644 --- a/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentAlias.java +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentAlias.java @@ -9,7 +9,9 @@ * agreement is prohibited. * #L% */ -package org.alfresco.com.fileplancomponents; +package org.alfresco.rest.model.fileplancomponents; + +import static org.alfresco.rest.util.ParameterCheck.mandatoryString; /** * File plan component alias enumeration @@ -33,19 +35,26 @@ public enum FilePlanComponentAlias public static final FilePlanComponentAlias getFilePlanComponentAlias(String alias) { - switch (alias) + mandatoryString("alias", alias); + + FilePlanComponentAlias result = null; + FilePlanComponentAlias[] values = values(); + + for (FilePlanComponentAlias filePlanComponentAlias : values) { - case "-filePlan-": - return FILE_PLAN_ALIAS; - case "-transfers-": - return TRANSFERS_ALIAS; - case "-unfiled-": - return UNFILED_RECORDS_CONTAINER_ALIAS; - case "-holds-": - return HOLDS_ALIAS; + if (filePlanComponentAlias.toString().equals(alias)) + { + result = filePlanComponentAlias; + break; + } } - throw new IllegalArgumentException("Invalid file plan component alias enum value: '" + alias + "'."); + if (result == null) + { + throw new IllegalArgumentException("Invalid file plan component alias enum value: '" + alias + "'."); + } + + return result; } /** diff --git a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentCreatedByUser.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentCreatedByUser.java index a9a993b7f7..c7abc2f920 100644 --- a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentCreatedByUser.java +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentCreatedByUser.java @@ -13,6 +13,7 @@ package org.alfresco.rest.model.fileplancomponents; /** * POJO for file plan component created by object + * * @author Kristijan Conkas * @since 1.0 */ @@ -20,6 +21,7 @@ public class FilePlanComponentCreatedByUser { private String id; private String displayName; + /** * @return the id */ @@ -27,6 +29,7 @@ public class FilePlanComponentCreatedByUser { return this.id; } + /** * @param id the id to set */ @@ -34,6 +37,7 @@ public class FilePlanComponentCreatedByUser { this.id = id; } + /** * @return the displayName */ @@ -41,6 +45,7 @@ public class FilePlanComponentCreatedByUser { return this.displayName; } + /** * @param displayName the displayName to set */ diff --git a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentEntry.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentEntry.java index 02f28c2a32..134ea684ba 100644 --- a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentEntry.java +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentEntry.java @@ -11,10 +11,11 @@ */ package org.alfresco.rest.model.fileplancomponents; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.ENTRY; + import com.fasterxml.jackson.annotation.JsonProperty; import org.alfresco.rest.core.RestModels; -import org.alfresco.rest.model.fileplancomponents.FilePlanComponent; /** * POJO for file plan component entry @@ -24,7 +25,7 @@ import org.alfresco.rest.model.fileplancomponents.FilePlanComponent; */ public class FilePlanComponentEntry extends RestModels { - @JsonProperty(value = "entry") + @JsonProperty(ENTRY) FilePlanComponent filePlanComponent; public FilePlanComponent getFilePlanComponent() diff --git a/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentFields.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentFields.java similarity index 91% rename from src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentFields.java rename to src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentFields.java index 8a3c158085..fe59991f0e 100644 --- a/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentFields.java +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentFields.java @@ -9,7 +9,7 @@ * agreement is prohibited. * #L% */ -package org.alfresco.com.fileplancomponents; +package org.alfresco.rest.model.fileplancomponents; /** * File plan component field names constants @@ -22,6 +22,7 @@ public class FilePlanComponentFields public static final String NAME = "name"; public static final String NODE_TYPE = "nodeType"; public static final String NODE_PARENT_ID = "parentId"; + public static final String ENTRY = "entry"; public static final String PROPERTIES = "properties"; public static final String PROPERTIES_TITLE = "cm:title"; public static final String PROPERTIES_VITAL_RECORD_INDICATOR = "rma:vitalRecordIndicator"; diff --git a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java index 34e069be03..729c444eb5 100644 --- a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java @@ -11,10 +11,10 @@ */ package org.alfresco.rest.model.fileplancomponents; -import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_DESCRIPTION; -import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_HOLD_REASON; -import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; -import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_DESCRIPTION; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_HOLD_REASON; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; @@ -38,8 +38,9 @@ public class FilePlanComponentProperties @JsonProperty(PROPERTIES_HOLD_REASON) private String holdReason; - @JsonProperty (PROPERTIES_DESCRIPTION) + @JsonProperty(PROPERTIES_DESCRIPTION) private String description; + /** * @return the vitalRecord */ @@ -103,5 +104,4 @@ public class FilePlanComponentProperties { return this.description; } - } diff --git a/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentType.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentType.java similarity index 58% rename from src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentType.java rename to src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentType.java index 2af558be18..26173d3a8a 100644 --- a/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentType.java +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentType.java @@ -9,7 +9,9 @@ * agreement is prohibited. * #L% */ -package org.alfresco.com.fileplancomponents; +package org.alfresco.rest.model.fileplancomponents; + +import static org.alfresco.rest.util.ParameterCheck.mandatoryString; /** * File plan component type enumeration @@ -37,27 +39,26 @@ public enum FilePlanComponentType public static final FilePlanComponentType getFilePlanComponentType(String type) { - switch (type) + mandatoryString("type", type); + + FilePlanComponentType result = null; + FilePlanComponentType[] values = values(); + + for (FilePlanComponentType filePlanComponentType : values) { - case "rma:filePlan": - return FILE_PLAN_TYPE; - case "rma:recordCategory": - return RECORD_CATEGORY_TYPE; - case "rma:recordFolder": - return RECORD_FOLDER_TYPE; - case "rma:hold": - return HOLD_TYPE; - case "rma:unfiledRecordFolder": - return UNFILED_RECORD_FOLDER_TYPE; - case "rma:holdContainer": - return HOLD_CONTAINER_TYPE; - case "rma:transferContainer": - return TRANSFER_CONTAINER_TYPE; - case "rma:unfiledRecordContainer": - return UNFILED_CONTAINER_TYPE; + if (filePlanComponentType.toString().equals(filePlanComponentType)) + { + result = filePlanComponentType; + break; + } } - throw new IllegalArgumentException("Invalid file plan component type enum value: '" + type + "'."); + if (result == null) + { + throw new IllegalArgumentException("Invalid file plan component type enum value: '" + type + "'."); + } + + return result; } /** diff --git a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentsCollection.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentsCollection.java index 24d3f395f2..14a40d6d9e 100644 --- a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentsCollection.java +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentsCollection.java @@ -15,6 +15,7 @@ import org.alfresco.rest.core.RestModels; /** * Handle collection of FilePlanComponents + * * @author Kristijan Conkas * @since 1.0 */ diff --git a/src/main/java/org/alfresco/rest/model/site/RMSite.java b/src/main/java/org/alfresco/rest/model/site/RMSite.java index 960f518488..296afaa9a1 100644 --- a/src/main/java/org/alfresco/rest/model/site/RMSite.java +++ b/src/main/java/org/alfresco/rest/model/site/RMSite.java @@ -13,7 +13,6 @@ package org.alfresco.rest.model.site; import com.fasterxml.jackson.annotation.JsonProperty; -import org.alfresco.com.site.RMSiteCompliance; import org.alfresco.rest.model.RestSiteModel; /** @@ -29,6 +28,7 @@ public class RMSite extends RestSiteModel /** * Helper method to set RM site compliance + * * @param compliance {@link RMSiteCompliance} the compliance to set */ public void setCompliance(RMSiteCompliance compliance) @@ -38,6 +38,7 @@ public class RMSite extends RestSiteModel /** * Helper method to get RM site compliance + * * @return compliance the RM Site compliance to get */ public RMSiteCompliance getCompliance() diff --git a/src/main/java/org/alfresco/com/site/RMSiteCompliance.java b/src/main/java/org/alfresco/rest/model/site/RMSiteCompliance.java similarity index 92% rename from src/main/java/org/alfresco/com/site/RMSiteCompliance.java rename to src/main/java/org/alfresco/rest/model/site/RMSiteCompliance.java index 76f0bf4926..ceb010694e 100644 --- a/src/main/java/org/alfresco/com/site/RMSiteCompliance.java +++ b/src/main/java/org/alfresco/rest/model/site/RMSiteCompliance.java @@ -9,7 +9,7 @@ * agreement is prohibited. * #L% */ -package org.alfresco.com.site; +package org.alfresco.rest.model.site; /** * RM Site compliance diff --git a/src/main/java/org/alfresco/com/site/RMSiteFields.java b/src/main/java/org/alfresco/rest/model/site/RMSiteFields.java similarity index 96% rename from src/main/java/org/alfresco/com/site/RMSiteFields.java rename to src/main/java/org/alfresco/rest/model/site/RMSiteFields.java index c7c65f0d06..2f4804e78d 100644 --- a/src/main/java/org/alfresco/com/site/RMSiteFields.java +++ b/src/main/java/org/alfresco/rest/model/site/RMSiteFields.java @@ -9,7 +9,7 @@ * agreement is prohibited. * #L% */ -package org.alfresco.com.site; +package org.alfresco.rest.model.site; /** *RM Site properties from the RM Model Schema diff --git a/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java b/src/main/java/org/alfresco/rest/requests/FilePlanComponentAPI.java similarity index 97% rename from src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java rename to src/main/java/org/alfresco/rest/requests/FilePlanComponentAPI.java index 11c892d24d..72c2375325 100644 --- a/src/main/java/org/alfresco/rest/requests/FilePlanComponentApi.java +++ b/src/main/java/org/alfresco/rest/requests/FilePlanComponentAPI.java @@ -11,10 +11,10 @@ */ package org.alfresco.rest.requests; -import static org.alfresco.com.util.ParameterCheck.mandatoryObject; -import static org.alfresco.com.util.ParameterCheck.mandatoryString; import static org.alfresco.rest.core.RestRequest.requestWithBody; import static org.alfresco.rest.core.RestRequest.simpleRequest; +import static org.alfresco.rest.util.ParameterCheck.mandatoryObject; +import static org.alfresco.rest.util.ParameterCheck.mandatoryString; import static org.springframework.http.HttpMethod.DELETE; import static org.springframework.http.HttpMethod.GET; import static org.springframework.http.HttpMethod.POST; @@ -37,7 +37,7 @@ import org.springframework.stereotype.Component; */ @Component @Scope(value = "prototype") -public class FilePlanComponentApi extends RestAPI +public class FilePlanComponentAPI extends RestAPI { /** * Get a file plan component diff --git a/src/main/java/org/alfresco/rest/requests/RMSiteAPI.java b/src/main/java/org/alfresco/rest/requests/RMSiteAPI.java index 7cb99889cc..580d7703ea 100644 --- a/src/main/java/org/alfresco/rest/requests/RMSiteAPI.java +++ b/src/main/java/org/alfresco/rest/requests/RMSiteAPI.java @@ -13,6 +13,7 @@ package org.alfresco.rest.requests; import static org.alfresco.rest.core.RestRequest.requestWithBody; import static org.alfresco.rest.core.RestRequest.simpleRequest; +import static org.alfresco.rest.util.ParameterCheck.mandatoryObject; import static org.springframework.http.HttpMethod.DELETE; import static org.springframework.http.HttpMethod.GET; import static org.springframework.http.HttpMethod.POST; @@ -34,7 +35,7 @@ import org.springframework.stereotype.Component; */ @Component @Scope (value = "prototype") -public class RMSiteAPI extends RestAPI +public class RMSiteAPI extends RestAPI { /** * Get the RM site @@ -71,6 +72,8 @@ public class RMSiteAPI extends RestAPI */ public RMSite createRMSite(JsonObject rmSiteProperties) throws Exception { + mandatoryObject("rmSiteProperties", rmSiteProperties); + return usingRestWrapper().processModel(RMSite.class, requestWithBody( POST, rmSiteProperties.toString(), @@ -113,11 +116,12 @@ public class RMSiteAPI extends RestAPI */ public RMSite updateRMSite(JsonObject rmSiteProperties) throws Exception { + mandatoryObject("rmSiteProperties", rmSiteProperties); + return usingRestWrapper().processModel(RMSite.class, requestWithBody( PUT, rmSiteProperties.toString(), "sites/rm" )); } - } diff --git a/src/main/java/org/alfresco/com/util/ParameterCheck.java b/src/main/java/org/alfresco/rest/util/ParameterCheck.java similarity index 63% rename from src/main/java/org/alfresco/com/util/ParameterCheck.java rename to src/main/java/org/alfresco/rest/util/ParameterCheck.java index 533fbe6573..2895d538b6 100644 --- a/src/main/java/org/alfresco/com/util/ParameterCheck.java +++ b/src/main/java/org/alfresco/rest/util/ParameterCheck.java @@ -9,7 +9,7 @@ * agreement is prohibited. * #L% */ -package org.alfresco.com.util; +package org.alfresco.rest.util; import static org.apache.commons.lang3.StringUtils.isBlank; @@ -27,11 +27,11 @@ public class ParameterCheck } /** - * FIXME: Document me :) + * Checks if a given {@link String} is blank or not, i.e. not null, "" or " ". * - * @param paramName FIXME: Document me :) - * @param paramValue FIXME: Document me :) - * @throws IllegalArgumentException FIXME: Document me :) + * @param paramName The name of the parameter to check + * @param paramValue The value of the parameter to check + * @throws IllegalArgumentException Throws an exception if the given value is blank */ public static void mandatoryString(final String paramName, final String paramValue) throws IllegalArgumentException { @@ -42,12 +42,13 @@ public class ParameterCheck } /** - * FIXME: Document me :) + * Checks if a given {@link Object} is null or not * - * @param paramName FIXME: Document me :) - * @param object FIXME: Document me :) + * @param paramName The name of the parameter to check + * @param object The value of the parameter to check + * @throws IllegalArgumentException Throws an exception if the given value is null */ - public static void mandatoryObject(final String paramName, final Object object) + public static void mandatoryObject(final String paramName, final Object object) throws IllegalArgumentException { if (object == null) { diff --git a/src/test/java/org/alfresco/rest/base/AllowableOperations.java b/src/test/java/org/alfresco/rest/base/AllowableOperations.java new file mode 100644 index 0000000000..e48322595c --- /dev/null +++ b/src/test/java/org/alfresco/rest/base/AllowableOperations.java @@ -0,0 +1,25 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.rest.base; + +/** + * List of allowable operations + * + * @author Tuna Aksoy + * @since 1.0 + */ +public class AllowableOperations +{ + public static final String CREATE = "create"; + public static final String UPDATE = "update"; + public static final String DELETE = "delete"; +} diff --git a/src/test/java/org/alfresco/rest/BaseRestTest.java b/src/test/java/org/alfresco/rest/base/BaseRestTest.java similarity index 83% rename from src/test/java/org/alfresco/rest/BaseRestTest.java rename to src/test/java/org/alfresco/rest/base/BaseRestTest.java index 64fccd8a31..6151551afa 100644 --- a/src/test/java/org/alfresco/rest/BaseRestTest.java +++ b/src/test/java/org/alfresco/rest/base/BaseRestTest.java @@ -9,14 +9,14 @@ * agreement is prohibited. * #L% */ -package org.alfresco.rest; +package org.alfresco.rest.base; import static java.lang.Integer.parseInt; -import static org.alfresco.com.site.RMSiteCompliance.STANDARD; -import static org.alfresco.com.site.RMSiteFields.COMPLIANCE; -import static org.alfresco.com.site.RMSiteFields.DESCRIPTION; -import static org.alfresco.com.site.RMSiteFields.TITLE; +import static org.alfresco.rest.model.site.RMSiteCompliance.STANDARD; +import static org.alfresco.rest.model.site.RMSiteFields.COMPLIANCE; +import static org.alfresco.rest.model.site.RMSiteFields.DESCRIPTION; +import static org.alfresco.rest.model.site.RMSiteFields.TITLE; import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.OK; @@ -24,6 +24,7 @@ import static org.springframework.http.HttpStatus.OK; import com.google.gson.JsonObject; import com.jayway.restassured.RestAssured; +import org.alfresco.rest.RestTest; import org.alfresco.rest.core.RestWrapper; import org.alfresco.rest.requests.RMSiteAPI; import org.alfresco.utility.data.DataUser; @@ -58,10 +59,10 @@ public class BaseRestTest extends RestTest private String restRmPath; @Autowired - public RMSiteAPI rmSiteAPI; + private RMSiteAPI rmSiteAPI; @Autowired - public DataUser dataUser; + private DataUser dataUser; // Constants public static final String RM_ID = "rm"; @@ -79,17 +80,18 @@ public class BaseRestTest extends RestTest RestAssured.port = parseInt(port); RestAssured.basePath = restRmPath; - //create RM Site if not exist + // Create RM Site if not exist createRMSiteIfNotExists(); } + /** * Helper method to create the RM Site via the POST request * if the site doesn't exist */ public void createRMSiteIfNotExists() throws Exception { - //check RM site doesn't exist - if (!siteRMExist()) + // Check RM site doesn't exist + if (!siteRMExists()) { rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); @@ -109,9 +111,9 @@ public class BaseRestTest extends RestTest } /** - * Check the RM site exist via the GET request + * Check if the RM site exists via the GET request */ - public boolean siteRMExist() throws Exception + public boolean siteRMExists() throws Exception { RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); rmSiteAPI.getSite(); diff --git a/src/test/java/org/alfresco/rest/TestData.java b/src/test/java/org/alfresco/rest/base/TestData.java similarity index 66% rename from src/test/java/org/alfresco/rest/TestData.java rename to src/test/java/org/alfresco/rest/base/TestData.java index a9fb20daea..fb71b4f37c 100644 --- a/src/test/java/org/alfresco/rest/TestData.java +++ b/src/test/java/org/alfresco/rest/base/TestData.java @@ -9,16 +9,16 @@ * agreement is prohibited. * #L% */ -package org.alfresco.rest; +package org.alfresco.rest.base; -import static org.alfresco.com.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; -import static org.alfresco.com.fileplancomponents.FilePlanComponentAlias.HOLDS_ALIAS; -import static org.alfresco.com.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS; -import static org.alfresco.com.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS; -import static org.alfresco.com.fileplancomponents.FilePlanComponentType.FILE_PLAN_TYPE; -import static org.alfresco.com.fileplancomponents.FilePlanComponentType.HOLD_CONTAINER_TYPE; -import static org.alfresco.com.fileplancomponents.FilePlanComponentType.TRANSFER_CONTAINER_TYPE; -import static org.alfresco.com.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentAlias.HOLDS_ALIAS; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentType.FILE_PLAN_TYPE; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentType.HOLD_CONTAINER_TYPE; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentType.TRANSFER_CONTAINER_TYPE; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE; import org.testng.annotations.DataProvider; @@ -26,6 +26,7 @@ import org.testng.annotations.DataProvider; * Test data used in tests * * @author Rodica Sutu + * @since 1.0 */ public interface TestData { @@ -39,6 +40,10 @@ public interface TestData * The default password used when creating test users. */ public static final String DEFAULT_PASSWORD = "password"; + + /** + * The default email address used when creating test users. + */ public static final String DEFAULT_EMAIL = "default@alfresco.com"; /** diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java index cc7888575f..913f7c63fe 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java @@ -11,14 +11,18 @@ */ package org.alfresco.rest.fileplancomponents; -import static java.util.UUID.randomUUID; +import static java.util.Arrays.asList; -import static org.alfresco.com.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; -import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.NAME; -import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.NODE_TYPE; -import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES; -import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_DESCRIPTION; -import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; +import static org.alfresco.rest.base.AllowableOperations.CREATE; +import static org.alfresco.rest.base.AllowableOperations.DELETE; +import static org.alfresco.rest.base.AllowableOperations.UPDATE; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.NAME; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.NODE_TYPE; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_DESCRIPTION; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; +import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; import static org.springframework.http.HttpStatus.FORBIDDEN; import static org.springframework.http.HttpStatus.NOT_FOUND; @@ -27,16 +31,15 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; -import java.util.Arrays; - import com.google.gson.JsonObject; -import org.alfresco.com.fileplancomponents.FilePlanComponentAlias; -import org.alfresco.com.fileplancomponents.FilePlanComponentType; -import org.alfresco.rest.BaseRestTest; -import org.alfresco.rest.TestData; +import org.alfresco.rest.base.BaseRestTest; +import org.alfresco.rest.base.TestData; import org.alfresco.rest.model.fileplancomponents.FilePlanComponent; -import org.alfresco.rest.requests.FilePlanComponentApi; +import org.alfresco.rest.model.fileplancomponents.FilePlanComponentAlias; +import org.alfresco.rest.model.fileplancomponents.FilePlanComponentType; +import org.alfresco.rest.requests.FilePlanComponentAPI; +import org.alfresco.rest.requests.RMSiteAPI; import org.alfresco.utility.data.DataUser; import org.alfresco.utility.model.UserModel; import org.alfresco.utility.report.Bug; @@ -53,14 +56,17 @@ import org.testng.annotations.Test; public class FilePlanTests extends BaseRestTest { @Autowired - private FilePlanComponentApi filePlanComponentApi; + private FilePlanComponentAPI filePlanComponentAPI; + + @Autowired + private RMSiteAPI rmSiteAPI; @Autowired private DataUser dataUser; /** * Given that the RM site doesn't exist - * When I use the API to get the File Plan/holds/unfiled/transfers + * When I use the API to get the File Plan/Holds/Unfiled Records Container/Transfers * Then I get the 404 response code */ @Test @@ -71,17 +77,21 @@ public class FilePlanTests extends BaseRestTest ) public void getFilePlanComponentWhenRMIsNotCreated(String filePlanAlias) throws Exception { - //check RM Site Exist - if (siteRMExist()) + // Check RM Site Exist + if (siteRMExists()) { - //delete RM Site + // Delete RM Site rmSiteAPI.deleteRMSite(); } - filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - //get the file plan component - filePlanComponentApi.getFilePlanComponent(filePlanAlias.toString()); + + // Authenticate with admin user + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + // Get the file plan component + filePlanComponentAPI.getFilePlanComponent(filePlanAlias.toString()); + //check the response code is NOT_FOUND - filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(NOT_FOUND); + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(NOT_FOUND); } /** @@ -97,15 +107,19 @@ public class FilePlanTests extends BaseRestTest ) public void getFilePlanComponentWhenRMIsCreated(FilePlanComponentAlias filePlanAlias, FilePlanComponentType rmType) throws Exception { - //create RM Site if doesn't exist + // Create RM Site if doesn't exist createRMSiteIfNotExists(); - //authenticate with admin user - filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - //get the file plan special container - FilePlanComponent filePlanComponent=filePlanComponentApi.getFilePlanComponent(filePlanAlias.toString()); - //check the response code - filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(OK); - //check the response contains the right node type + + // Authenticate with admin user + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + // Get the file plan special container + FilePlanComponent filePlanComponent = filePlanComponentAPI.getFilePlanComponent(filePlanAlias.toString()); + + // Check the response code + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); + + // Check the response contains the right node type assertEquals(filePlanComponent.getNodeType(), rmType.toString()); } @@ -122,17 +136,22 @@ public class FilePlanTests extends BaseRestTest ) public void includeAllowableOperations(String specialContainerAlias) throws Exception { - //create RM Site if doesn't exist + // Create RM Site if doesn't exist createRMSiteIfNotExists(); - filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - //GET the file plan special containers with the optional parameter allowableOperations - FilePlanComponent filePlanComponent = filePlanComponentApi.withParams("include=allowableOperations").getFilePlanComponent(specialContainerAlias); - //Check the list of allowableOperations returned - assertTrue(filePlanComponent.getAllowableOperations().containsAll(Arrays.asList("update", "create")), + + // Authenticate with admin user + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + // Get the file plan special containers with the optional parameter allowableOperations + FilePlanComponent filePlanComponent = filePlanComponentAPI.withParams("include=allowableOperations").getFilePlanComponent(specialContainerAlias); + + // Check the list of allowableOperations returned + assertTrue(filePlanComponent.getAllowableOperations().containsAll(asList(UPDATE, CREATE)), "Wrong list of the allowable operations is return" + filePlanComponent.getAllowableOperations().toString()); - //check the list of allowableOperations doesn't contains DELETE operation - assertFalse(filePlanComponent.getAllowableOperations().contains("delete"), - "The list of allowable operations contains delete option"+ filePlanComponent.getAllowableOperations().toString()); + + // Check the list of allowableOperations doesn't contains DELETE operation + assertFalse(filePlanComponent.getAllowableOperations().contains(DELETE), + "The list of allowable operations contains delete option" + filePlanComponent.getAllowableOperations().toString()); } /** @@ -145,12 +164,16 @@ public class FilePlanTests extends BaseRestTest @Bug (id = "RM-4295") public void updateFilePlan() throws Exception { - String FILE_PLAN_DESCRIPTION="Description updated " +randomUUID().toString().substring(0, 4); - String FILE_PLAN_TITLE = "Title updated " + randomUUID().toString().substring(0, 4); - //create RM Site if doesn't exist + String FILE_PLAN_DESCRIPTION = "Description updated " + getRandomAlphanumeric(); + String FILE_PLAN_TITLE = "Title updated " + getRandomAlphanumeric(); + + // Create RM Site if doesn't exist createRMSiteIfNotExists(); - filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - //Build the file plan root properties + + // Authenticate with admin user + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + // Build the file plan root properties JsonObject filePlanProperties = buildObject() .addObject(PROPERTIES) .add(PROPERTIES_TITLE, FILE_PLAN_TITLE) @@ -158,15 +181,15 @@ public class FilePlanTests extends BaseRestTest .end() .getJson(); - // Update the record category - FilePlanComponent renamedFilePlanComponent = filePlanComponentApi.updateFilePlanComponent(filePlanProperties,FILE_PLAN_ALIAS.toString()); + FilePlanComponent renamedFilePlanComponent = filePlanComponentAPI.updateFilePlanComponent(filePlanProperties,FILE_PLAN_ALIAS.toString()); // Verify the response status code - filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(OK); + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); // Verify the returned description field for the file plan component assertEquals(renamedFilePlanComponent.getProperties().getDescription(), FILE_PLAN_DESCRIPTION); + // Verify the returned title field for the file plan component assertEquals(renamedFilePlanComponent.getProperties().getTitle(), FILE_PLAN_TITLE); } @@ -184,12 +207,17 @@ public class FilePlanTests extends BaseRestTest ) public void deleteFilePlanSpecialComponents(String filePlanAlias) throws Exception { + // Create RM Site if doesn't exist createRMSiteIfNotExists(); - filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - //get the file plan component - filePlanComponentApi.deleteFilePlanComponent(filePlanAlias.toString()); - //check the DELETE response status code - filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); + + // Authenticate with admin user + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + // Delete the file plan component + filePlanComponentAPI.deleteFilePlanComponent(filePlanAlias.toString()); + + // Check the DELETE response status code + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); } /** @@ -206,28 +234,33 @@ public class FilePlanTests extends BaseRestTest @Bug(id="RM-4296") public void createFilePlanSpecialContainerWhenExists(FilePlanComponentAlias filePlanAlias, FilePlanComponentType rmType) throws Exception { - String rmSiteId=rmSiteAPI.getSite().getGuid(); + String rmSiteId = rmSiteAPI.getSite().getGuid(); - //create RM Site if doesn't exist + // Create RM Site if doesn't exist createRMSiteIfNotExists(); - filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - String COMPONENT_TITLE = filePlanAlias + randomUUID().toString().substring(0, 4); + + // Authenticate with admin user + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + String name = filePlanAlias + getRandomAlphanumeric(); + //Build the file plan root properties JsonObject componentProperties = buildObject() - .add(NAME, COMPONENT_TITLE) + .add(NAME, name) .add(NODE_TYPE, rmType.toString()) .getJson(); - //create the special containers into RM site - parent folder - filePlanComponentApi.createFilePlanComponent(componentProperties, rmSiteId); - filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); - //create the special containers into RM site - parent folder - filePlanComponentApi.createFilePlanComponent(componentProperties, FILE_PLAN_ALIAS.toString()); - filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); + // Create the special containers into RM site - parent folder + filePlanComponentAPI.createFilePlanComponent(componentProperties, rmSiteId); + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); - //create the special containers into the root of special containers containers - filePlanComponentApi.createFilePlanComponent(componentProperties, filePlanAlias.toString()); - filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); + // Create the special containers into RM site - parent folder + filePlanComponentAPI.createFilePlanComponent(componentProperties, FILE_PLAN_ALIAS.toString()); + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); + + // Create the special containers into the root of special containers containers + filePlanComponentAPI.createFilePlanComponent(componentProperties, filePlanAlias.toString()); + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); } /** @@ -243,17 +276,25 @@ public class FilePlanTests extends BaseRestTest ) public void getSpecialFilePlanComponentsWithNonRMuser(String filePlanAlias) throws Exception { - //create RM Site if doesn't exist + // Create RM Site if doesn't exist createRMSiteIfNotExists(); + + // Disconnect user from REST API session rmSiteAPI.usingRestWrapper().disconnect(); + + // Authenticate admin user to Alfresco REST API restClient.authenticateUser(dataUser.getAdminUser()); - //create a random user + + // Create a random user UserModel nonRMuser = dataUser.createRandomTestUser("testUser"); - //authenticate using the random user - filePlanComponentApi.usingRestWrapper().authenticateUser(nonRMuser); - //get the special file plan components - filePlanComponentApi.getFilePlanComponent(filePlanAlias.toString()); - //check the response status code -FORBIDDEN - filePlanComponentApi.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); + + // Authenticate using the random user + filePlanComponentAPI.usingRestWrapper().authenticateUser(nonRMuser); + + // Get the special file plan components + filePlanComponentAPI.getFilePlanComponent(filePlanAlias.toString()); + + // Check the response status code is FORBIDDEN + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); } } diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java index fbd2d03527..67d73d42c6 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java @@ -11,15 +11,14 @@ */ package org.alfresco.rest.fileplancomponents; -import static java.util.UUID.randomUUID; - -import static org.alfresco.com.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; -import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.NAME; -import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.NODE_TYPE; -import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES; -import static org.alfresco.com.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; -import static org.alfresco.com.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE; -import static org.alfresco.com.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.NAME; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.NODE_TYPE; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE; +import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.NOT_FOUND; @@ -36,20 +35,19 @@ import java.util.NoSuchElementException; import com.google.gson.JsonObject; -import org.alfresco.com.fileplancomponents.FilePlanComponentType; -import org.alfresco.rest.BaseRestTest; +import org.alfresco.rest.base.BaseRestTest; import org.alfresco.rest.core.RestWrapper; import org.alfresco.rest.model.fileplancomponents.FilePlanComponent; import org.alfresco.rest.model.fileplancomponents.FilePlanComponentProperties; +import org.alfresco.rest.model.fileplancomponents.FilePlanComponentType; import org.alfresco.rest.model.fileplancomponents.FilePlanComponentsCollection; -import org.alfresco.rest.requests.FilePlanComponentApi; +import org.alfresco.rest.requests.FilePlanComponentAPI; import org.alfresco.utility.data.DataUser; -import org.alfresco.utility.data.RandomData; import org.springframework.beans.factory.annotation.Autowired; import org.testng.annotations.Test; /** - * FIXME: Document me :) + * Record category related API tests * * @author Kristijan Conkas * @author Tuna Aksoy @@ -58,12 +56,12 @@ import org.testng.annotations.Test; public class RecordCategoryTest extends BaseRestTest { @Autowired - private FilePlanComponentApi filePlanComponentApi; + private FilePlanComponentAPI filePlanComponentAPI; @Autowired private DataUser dataUser; - // for children creation test + // Number of children (for children creation test) private static final int NUMBER_OF_CHILDREN = 10; /** @@ -78,10 +76,11 @@ public class RecordCategoryTest extends BaseRestTest ) public void createCategoryTest() throws Exception { - RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + // Authenticate with admin user + RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - String categoryName = "Category name " + randomUUID().toString().substring(0, 8); - String categoryTitle = "Category title " + randomUUID().toString().substring(0, 8); + String categoryName = "Category name " + getRandomAlphanumeric(); + String categoryTitle = "Category title " + getRandomAlphanumeric(); // Build the record category properties JsonObject recordCategoryProperties = buildObject(). @@ -93,7 +92,7 @@ public class RecordCategoryTest extends BaseRestTest getJson(); // Create the record category - FilePlanComponent filePlanComponent = filePlanComponentApi.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString()); + FilePlanComponent filePlanComponent = filePlanComponentAPI.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString()); // Verify the status code restWrapper.assertStatusCodeIs(CREATED); @@ -102,18 +101,18 @@ public class RecordCategoryTest extends BaseRestTest assertTrue(filePlanComponent.isIsCategory()); assertFalse(filePlanComponent.isIsFile()); assertFalse(filePlanComponent.isIsRecordFolder()); - + assertEquals(filePlanComponent.getName(), categoryName); assertEquals(filePlanComponent.getNodeType(), RECORD_CATEGORY_TYPE.toString()); assertFalse(filePlanComponent.isHasRetentionSchedule()); - + assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername()); - + // Verify the returned file plan component properties FilePlanComponentProperties filePlanComponentProperties = filePlanComponent.getProperties(); assertEquals(filePlanComponentProperties.getTitle(), categoryTitle); - - logger.info("aspects: " + filePlanComponent.getAspectNames()); + + logger.info("Aspects: " + filePlanComponent.getAspectNames()); } /** @@ -128,11 +127,12 @@ public class RecordCategoryTest extends BaseRestTest ) public void renameCategory() throws Exception { - RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + // Authenticate with admin user + RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); // Create record category first - String categoryName = "Category name " + randomUUID().toString().substring(0, 8); - String categoryTitle = "Category title " + randomUUID().toString().substring(0, 8); + String categoryName = "Category name " + getRandomAlphanumeric(); + String categoryTitle = "Category title " + getRandomAlphanumeric(); // Build the record category properties JsonObject recordCategoryProperties = buildObject(). @@ -144,7 +144,7 @@ public class RecordCategoryTest extends BaseRestTest getJson(); // Create the record category - FilePlanComponent filePlanComponent = filePlanComponentApi.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString()); + FilePlanComponent filePlanComponent = filePlanComponentAPI.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString()); String newCategoryName = "Rename " + categoryName; @@ -154,16 +154,17 @@ public class RecordCategoryTest extends BaseRestTest getJson(); // Update the record category - FilePlanComponent renamedFilePlanComponent = filePlanComponentApi.updateFilePlanComponent(updateRecordCategoryProperties, filePlanComponent.getId()); + FilePlanComponent renamedFilePlanComponent = filePlanComponentAPI.updateFilePlanComponent(updateRecordCategoryProperties, filePlanComponent.getId()); // Verify the status code restWrapper.assertStatusCodeIs(OK); // Verify the returned file plan component assertEquals(renamedFilePlanComponent.getName(), newCategoryName); - - // get actual FILE_PLAN_ALIAS id - FilePlanComponent parentComponent = filePlanComponentApi.getFilePlanComponent(FILE_PLAN_ALIAS.toString()); + + // Get actual FILE_PLAN_ALIAS id + FilePlanComponent parentComponent = filePlanComponentAPI.getFilePlanComponent(FILE_PLAN_ALIAS.toString()); + // verify renamed component still has this parent assertEquals(renamedFilePlanComponent.getParentId(), parentComponent.getId()); } @@ -180,11 +181,12 @@ public class RecordCategoryTest extends BaseRestTest ) public void deleteCategory() throws Exception { - RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + // Authenticate with admin user + RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); // Create record category first - String categoryName = "Category name " + randomUUID().toString().substring(0, 8); - String categoryTitle = "Category title " + randomUUID().toString().substring(0, 8); + String categoryName = "Category name " + getRandomAlphanumeric(); + String categoryTitle = "Category title " + getRandomAlphanumeric(); // Build the record category properties JsonObject recordCategoryProperties = buildObject(). @@ -196,16 +198,16 @@ public class RecordCategoryTest extends BaseRestTest getJson(); // Create the record category - FilePlanComponent filePlanComponent = filePlanComponentApi.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString()); + FilePlanComponent filePlanComponent = filePlanComponentAPI.createFilePlanComponent(recordCategoryProperties, FILE_PLAN_ALIAS.toString()); // Delete the record category - filePlanComponentApi.deleteFilePlanComponent(filePlanComponent.getId()); + filePlanComponentAPI.deleteFilePlanComponent(filePlanComponent.getId()); // Verify the status code restWrapper.assertStatusCodeIs(NO_CONTENT); - - // deleted component should no longer be retrievable - filePlanComponentApi.getFilePlanComponent(filePlanComponent.getId()); + + // Deleted component should no longer be retrievable + filePlanComponentAPI.getFilePlanComponent(filePlanComponent.getId()); restWrapper.assertStatusCodeIs(NOT_FOUND); } @@ -221,17 +223,17 @@ public class RecordCategoryTest extends BaseRestTest ) public void createSubcategory() throws Exception { - // create root level category - FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), RandomData.getRandomAlphanumeric()); + // Create root level category + FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), getRandomAlphanumeric()); assertNotNull(rootCategory.getId()); - // create subcategory as a child of rootCategory - FilePlanComponent childCategory = createCategory(rootCategory.getId(), RandomData.getRandomAlphanumeric()); + // Create subcategory as a child of rootCategory + FilePlanComponent childCategory = createCategory(rootCategory.getId(), getRandomAlphanumeric()); - // child category created? + // Child category created? assertNotNull(childCategory.getId()); - - // verify child category + + // Verify child category assertEquals(childCategory.getParentId(), rootCategory.getId()); assertTrue(childCategory.isIsCategory()); assertFalse(childCategory.isIsFile()); @@ -253,57 +255,61 @@ public class RecordCategoryTest extends BaseRestTest ) public void listChildren() throws Exception { - // create root level category - FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), RandomData.getRandomAlphanumeric()); - assertNotNull(rootCategory.getId()); + // Create root level category + FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), getRandomAlphanumeric()); + assertNotNull(rootCategory.getId()); - // add child categories/folders + // Add child categories/folders ArrayList children = new ArrayList(); for (int i=0; i < NUMBER_OF_CHILDREN; i++) { - // create a child + // Create a child FilePlanComponent child = createComponent(rootCategory.getId(), - RandomData.getRandomAlphanumeric(), + getRandomAlphanumeric(), // half of the children should be subcategories, the other subfolders (i <= NUMBER_OF_CHILDREN / 2) ? RECORD_CATEGORY_TYPE : RECORD_FOLDER_TYPE); assertNotNull(child.getId()); children.add(child); } - // list children from API - RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - FilePlanComponentsCollection apiChildren = filePlanComponentApi.listChildComponents(rootCategory.getId()); + // Authenticate with admin user + RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + // List children from API + FilePlanComponentsCollection apiChildren = filePlanComponentAPI.listChildComponents(rootCategory.getId()); + + // Check status code restWrapper.assertStatusCodeIs(OK); logger.info("parent: " + rootCategory.getId()); - - // check listed children against created list - apiChildren.getEntries().forEach(c -> + + // Check listed children against created list + apiChildren.getEntries().forEach(c -> { FilePlanComponent filePlanComponent = c.getFilePlanComponent(); assertNotNull(filePlanComponent.getId()); - logger.info("checking child " + filePlanComponent.getId()); - - try + logger.info("Checking child " + filePlanComponent.getId()); + + try { - // find this child in created children list + // Find this child in created children list FilePlanComponent createdComponent = children.stream() .filter(child -> child.getId().equals(filePlanComponent.getId())) .findFirst() .get(); - // created by + // Created by assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername()); - - // is parent Id set correctly? + + // Is parent Id set correctly? assertEquals(filePlanComponent.getParentId(), rootCategory.getId()); - - // only categories or folders have been created + + // Only categories or folders have been created assertFalse(filePlanComponent.isIsFile()); - - // boolean properties related to node type - // only RECORD_CATEGORY_TYPE and RECORD_FOLDER_TYPE have been created + + // Boolean properties related to node type + // Only RECORD_CATEGORY_TYPE and RECORD_FOLDER_TYPE have been created if (filePlanComponent.getNodeType().equals(RECORD_CATEGORY_TYPE.toString())) - { + { assertTrue(filePlanComponent.isIsCategory()); assertFalse(filePlanComponent.isIsRecordFolder()); } @@ -313,12 +319,13 @@ public class RecordCategoryTest extends BaseRestTest assertFalse(filePlanComponent.isIsCategory()); } - // does returned object have the same contents as the created one? + // Does returned object have the same contents as the created one? assertEquals(createdComponent.getName(), filePlanComponent.getName()); assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType()); - - // verify properties - } + + // Verify properties + // FIXME: Verify properties + } catch (NoSuchElementException e) { fail("No child element for " + filePlanComponent.getId()); @@ -328,8 +335,10 @@ public class RecordCategoryTest extends BaseRestTest /** * Helper method to create child category - * @param parentCategoryId - * @param categoryName + * + * @param parentCategoryId The id of the parent category + * @param categoryName The name of the category + * @return The created category * @throws Exception on unsuccessful component creation */ private FilePlanComponent createCategory(String parentCategoryId, String categoryName) throws Exception @@ -339,15 +348,16 @@ public class RecordCategoryTest extends BaseRestTest /** * Helper method to create generic child component - * @param parentComponentId - * @param componentName - * @param componentType - * @return + * + * @param parentComponentId The id of the parent file plan component + * @param componentName The name of the file plan component + * @param componentType The name of the file plan component + * @return The created file plan component * @throws Exception */ private FilePlanComponent createComponent(String parentComponentId, String componentName, FilePlanComponentType componentType) throws Exception { - RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); JsonObject componentProperties = buildObject(). add(NAME, componentName). @@ -357,7 +367,7 @@ public class RecordCategoryTest extends BaseRestTest end(). getJson(); - FilePlanComponent fpc = filePlanComponentApi.createFilePlanComponent(componentProperties, parentComponentId); + FilePlanComponent fpc = filePlanComponentAPI.createFilePlanComponent(componentProperties, parentComponentId); restWrapper.assertStatusCodeIs(CREATED); return fpc; } diff --git a/src/test/java/org/alfresco/rest/site/RMSiteTests.java b/src/test/java/org/alfresco/rest/site/RMSiteTests.java index 813ecf52c0..14b480cd1e 100644 --- a/src/test/java/org/alfresco/rest/site/RMSiteTests.java +++ b/src/test/java/org/alfresco/rest/site/RMSiteTests.java @@ -11,14 +11,14 @@ */ package org.alfresco.rest.site; -import static org.alfresco.com.site.RMSiteCompliance.DOD5015; -import static org.alfresco.com.site.RMSiteCompliance.STANDARD; -import static org.alfresco.com.site.RMSiteFields.COMPLIANCE; -import static org.alfresco.com.site.RMSiteFields.DESCRIPTION; -import static org.alfresco.com.site.RMSiteFields.TITLE; -import static org.alfresco.rest.TestData.ANOTHER_ADMIN; -import static org.alfresco.rest.TestData.DEFAULT_EMAIL; -import static org.alfresco.rest.TestData.DEFAULT_PASSWORD; +import static org.alfresco.rest.base.TestData.ANOTHER_ADMIN; +import static org.alfresco.rest.base.TestData.DEFAULT_EMAIL; +import static org.alfresco.rest.base.TestData.DEFAULT_PASSWORD; +import static org.alfresco.rest.model.site.RMSiteCompliance.DOD5015; +import static org.alfresco.rest.model.site.RMSiteCompliance.STANDARD; +import static org.alfresco.rest.model.site.RMSiteFields.COMPLIANCE; +import static org.alfresco.rest.model.site.RMSiteFields.DESCRIPTION; +import static org.alfresco.rest.model.site.RMSiteFields.TITLE; import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.CONFLICT; @@ -34,10 +34,12 @@ import static org.testng.Assert.assertNotNull; import com.google.gson.JsonObject; import org.alfresco.dataprep.UserService; -import org.alfresco.rest.BaseRestTest; +import org.alfresco.rest.base.BaseRestTest; import org.alfresco.rest.core.RestWrapper; import org.alfresco.rest.model.site.RMSite; +import org.alfresco.rest.requests.RMSiteAPI; import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; import org.alfresco.utility.data.RandomData; import org.alfresco.utility.model.UserModel; import org.alfresco.utility.report.Bug; @@ -56,12 +58,16 @@ public class RMSiteTests extends BaseRestTest @Autowired private UserService userService; + @Autowired + private RMSiteAPI rmSiteAPI; + + @Autowired + private DataUser dataUser; /** * Given that RM module is installed - * When I want to create the rm site with specific title, description and compliance + * When I want to create the RM site with specific title, description and compliance * Then the RM site is created - * */ @Test ( @@ -69,12 +75,16 @@ public class RMSiteTests extends BaseRestTest ) public void createRMSiteAsAdminUser() throws Exception { + // Authenticate with admin user rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - if (siteRMExist()) + + // Check if the RM site exists + if (siteRMExists()) { // Delete the RM site rmSiteAPI.deleteRMSite(); } + // Build the RM site properties JsonObject rmSiteProperties = buildObject() .add(TITLE, RM_TITLE) @@ -108,8 +118,10 @@ public class RMSiteTests extends BaseRestTest ) public void createRMSiteWhenSiteExists() throws Exception { - rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + // Create the RM site if it does not exist createRMSiteIfNotExists(); + + // Authenticate with admin user RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); // Construct new properties @@ -141,6 +153,7 @@ public class RMSiteTests extends BaseRestTest ) public void deleteRMSite() throws Exception { + // Authenticate with admin user RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); // Delete the RM site @@ -161,13 +174,14 @@ public class RMSiteTests extends BaseRestTest ) public void getRMSite() throws Exception { + // Authenticate with admin user RestWrapper restWrapper = rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); // Get the RM site RMSite rmSite = rmSiteAPI.getSite(); - if (!siteRMExist()) + if (!siteRMExists()) { - // Verify the status code when rm site doesn't exist + // Verify the status code when RM site doesn't exist restWrapper.assertStatusCodeIs(NOT_FOUND); createRMSiteIfNotExists(); } @@ -194,13 +208,20 @@ public class RMSiteTests extends BaseRestTest @Bug (id="RM-4289") public void createRMSiteAsAnotherAdminUser() throws Exception { + // Authenticate with admin user rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - if (siteRMExist()) + + // Check if the RM site exists + if (siteRMExists()) { - //Delete the RM site + // Delete the RM site rmSiteAPI.deleteRMSite(); } + + // Disconnect the current user from the API session rmSiteAPI.usingRestWrapper().disconnect(); + + // Create user userService.create(dataUser.getAdminUser().getUsername(), dataUser.getAdminUser().getPassword(), ANOTHER_ADMIN, @@ -208,8 +229,13 @@ public class RMSiteTests extends BaseRestTest DEFAULT_EMAIL, ANOTHER_ADMIN, ANOTHER_ADMIN); - UserModel userModel=new UserModel(ANOTHER_ADMIN,DEFAULT_PASSWORD); + + // Build the user model + UserModel userModel = new UserModel(ANOTHER_ADMIN,DEFAULT_PASSWORD); + + // Authenticate as that new user rmSiteAPI.usingRestWrapper().authenticateUser(userModel); + // Build the RM site properties JsonObject rmSiteProperties = buildObject() .add(TITLE, RM_TITLE) @@ -251,14 +277,19 @@ public class RMSiteTests extends BaseRestTest .add(DESCRIPTION, NEW_DESCRIPTION) .getJson(); + // Authenticate with admin user rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - if (!siteRMExist()) - { - createRMSiteIfNotExists(); - } + // Create the site if it does not exist + createRMSiteIfNotExists(); + + // Disconnect the user from the API session rmSiteAPI.usingRestWrapper().disconnect(); + + // Create a random user UserModel nonRMuser = dataUser.createRandomTestUser("testUser"); + + // Authenticate as that random user rmSiteAPI.usingRestWrapper().authenticateUser(nonRMuser); // Create the RM site @@ -267,7 +298,10 @@ public class RMSiteTests extends BaseRestTest // Verify the status code rmSiteAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); + // Disconnect the user from the API session rmSiteAPI.usingRestWrapper().disconnect(); + + // Authenticate with admin user rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); // Update the RM Site @@ -284,7 +318,6 @@ public class RMSiteTests extends BaseRestTest assertEquals(rmSite.getVisibility(), PUBLIC); } - /** * Given that RM site exist * When the admin user wants to update the RM site compliance @@ -293,19 +326,21 @@ public class RMSiteTests extends BaseRestTest @Test public void updateRMSiteComplianceAsAdmin() throws Exception { + // Authenticate with admin user rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - if (!siteRMExist()) - { - createRMSiteIfNotExists(); - } + + // Create the RM site if it does not exist + createRMSiteIfNotExists(); + // Build the RM site properties JsonObject rmSiteToUpdate = buildObject() .add(COMPLIANCE, DOD5015.toString()) .getJson(); + // Update the RM site - RMSite rmSite = rmSiteAPI.updateRMSite(rmSiteToUpdate); + rmSiteAPI.updateRMSite(rmSiteToUpdate); // Verify the response status code rmSiteAPI.usingRestWrapper().assertStatusCodeIs(BAD_REQUEST); } - } +} diff --git a/src/test/resources/default.properties b/src/test/resources/default.properties index 82d19c77d6..911f2a44fc 100644 --- a/src/test/resources/default.properties +++ b/src/test/resources/default.properties @@ -2,16 +2,16 @@ # Original property values from default.properties # ######################################################################### -# dataprep related +# Dataprep related alfresco.scheme=http alfresco.server=localhost alfresco.port=8080 -# credentials +# Credentials admin.user=admin admin.password=admin -# rest related +# Rest related rest.basePath=alfresco/api/-default-/public/alfresco/versions/1 rest.workflowPath=alfresco/api/-default-/public/workflow/versions/1 From 026e956df37a928f0162ce6749ecd6816c8afca4 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Wed, 2 Nov 2016 10:37:15 +0200 Subject: [PATCH 42/49] fix the test createFilePlanSpecialContainerWhenExists() --- .../rest/fileplancomponents/FilePlanTests.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java index 913f7c63fe..427e080cde 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java @@ -234,22 +234,24 @@ public class FilePlanTests extends BaseRestTest @Bug(id="RM-4296") public void createFilePlanSpecialContainerWhenExists(FilePlanComponentAlias filePlanAlias, FilePlanComponentType rmType) throws Exception { - String rmSiteId = rmSiteAPI.getSite().getGuid(); - // Create RM Site if doesn't exist createRMSiteIfNotExists(); // Authenticate with admin user - filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + rmSiteAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + // Get the RM site ID + String rmSiteId = rmSiteAPI.getSite().getGuid(); String name = filePlanAlias + getRandomAlphanumeric(); - //Build the file plan root properties + // Build the file plan root properties JsonObject componentProperties = buildObject() .add(NAME, name) .add(NODE_TYPE, rmType.toString()) .getJson(); + // Authenticate with admin user + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); // Create the special containers into RM site - parent folder filePlanComponentAPI.createFilePlanComponent(componentProperties, rmSiteId); filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); From 138319917ed28be1a714dfa3fbee114f9d6c12e0 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Mon, 7 Nov 2016 14:51:17 +0200 Subject: [PATCH 43/49] Update gitignore to ignore test-output folder --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 69fd5a71f4..d1a4acb433 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /src/test/resources/local.properties /.idea/ *.iml +/test-output/ From e4feb0d48448c9d8409f7dbdb7fe28b214386575 Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Fri, 11 Nov 2016 11:11:45 +0000 Subject: [PATCH 44/49] RM-4366: added path field --- .../fileplancomponents/FilePlanComponent.java | 19 ++++- .../FilePlanComponentIdNamePair.java | 56 +++++++++++++ .../FilePlanComponentPath.java | 78 +++++++++++++++++++ 3 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentIdNamePair.java create mode 100644 src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentPath.java diff --git a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java index 2090616ac9..9843d19104 100644 --- a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java @@ -43,7 +43,8 @@ public class FilePlanComponent private FilePlanComponentProperties properties; @JsonProperty (ALLOWABLE_OPERATIONS) private List allowableOperations; - + private FilePlanComponentPath path; + /** * @return the id */ @@ -227,4 +228,20 @@ public class FilePlanComponent { return this.allowableOperations; } + + /** + * @return the path + */ + public FilePlanComponentPath getPath() + { + return this.path; + } + + /** + * @param path the path to set + */ + public void setPath(FilePlanComponentPath path) + { + this.path = path; + } } diff --git a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentIdNamePair.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentIdNamePair.java new file mode 100644 index 0000000000..b5dc837df4 --- /dev/null +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentIdNamePair.java @@ -0,0 +1,56 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.rest.model.fileplancomponents; + +/** + * POJO for id/name pair + * + * @author Kristijan Conkas + * @since 1.0 + */ +public class FilePlanComponentIdNamePair +{ + public String id; + public String name; + + /** + * @return the id + */ + public String getId() + { + return this.id; + } + + /** + * @param id the id to set + */ + public void setId(String id) + { + this.id = id; + } + + /** + * @return the name + */ + public String getName() + { + return this.name; + } + + /** + * @param name the name to set + */ + public void setName(String name) + { + this.name = name; + } +} diff --git a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentPath.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentPath.java new file mode 100644 index 0000000000..dd94868794 --- /dev/null +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentPath.java @@ -0,0 +1,78 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.rest.model.fileplancomponents; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +/** + * POJO for FilePlanComponent path parameter + *
      + * @author Kristijan Conkas + * @since 1.0 + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class FilePlanComponentPath +{ + private String name; + private boolean isComplete; + private List elements; + + /** + * @return the name + */ + public String getName() + { + return this.name; + } + + /** + * @param name the name to set + */ + public void setName(String name) + { + this.name = name; + } + + /** + * @return the isComplete + */ + public boolean isComplete() + { + return this.isComplete; + } + + /** + * @param isComplete the isComplete to set + */ + public void setComplete(boolean isComplete) + { + this.isComplete = isComplete; + } + + /** + * @return the elements + */ + public List getElements() + { + return this.elements; + } + + /** + * @param elements the elements to set + */ + public void setElements(List elements) + { + this.elements = elements; + } +} From 7aacdaa1d973144765a40d4c53f6bfd400ef11bb Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Fri, 11 Nov 2016 16:18:51 +0200 Subject: [PATCH 45/49] -updates on Record Folder CRUD API's tests --- .../fileplancomponents/FilePlanComponent.java | 117 +++++- .../FilePlanComponentFields.java | 4 + .../FilePlanComponentProperties.java | 48 ++- ...er.java => FilePlanComponentUserInfo.java} | 2 +- .../fileplancomponents/ReviewPeriod.java | 33 ++ .../org/alfresco/rest/base/BaseRestTest.java | 72 +++- .../java/org/alfresco/rest/base/TestData.java | 21 ++ .../RecordCategoryTest.java | 2 +- .../fileplancomponents/RecordFolderTests.java | 350 ++++++++++++++++++ 9 files changed, 638 insertions(+), 11 deletions(-) rename src/main/java/org/alfresco/rest/model/fileplancomponents/{FilePlanComponentCreatedByUser.java => FilePlanComponentUserInfo.java} (95%) create mode 100644 src/main/java/org/alfresco/rest/model/fileplancomponents/ReviewPeriod.java create mode 100644 src/test/java/org/alfresco/rest/fileplancomponents/RecordFolderTests.java diff --git a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java index 2090616ac9..438fcf03f8 100644 --- a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java @@ -12,11 +12,11 @@ package org.alfresco.rest.model.fileplancomponents; import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.ALLOWABLE_OPERATIONS; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.IS_CLOSED; import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES; import java.util.List; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -26,24 +26,62 @@ import com.fasterxml.jackson.annotation.JsonProperty; * @since 1.0 */ //FIXME: Once the fields have been added the JsonIgnoreProperties annotation should be removed -@JsonIgnoreProperties(ignoreUnknown = true) + public class FilePlanComponent { + @JsonProperty (required = true) private String id; + + @JsonProperty (required = true) private String parentId; + + @JsonProperty (required = true) private String name; + + @JsonProperty (required = true) private String nodeType; + + @JsonProperty (required = true) private boolean isCategory; + + @JsonProperty (required = true) private boolean isRecordFolder; + + @JsonProperty (required = true) private boolean isFile; + + @JsonProperty private boolean hasRetentionSchedule; + + @JsonProperty(value = IS_CLOSED) + private boolean isClosed; + + @JsonProperty + private boolean isCompleted; + + @JsonProperty (required = true) private List aspectNames; - private FilePlanComponentCreatedByUser createdByUser; - @JsonProperty(PROPERTIES) + + @JsonProperty (required = true) + private FilePlanComponentUserInfo createdByUser; + + @JsonProperty(value = PROPERTIES, required = true) private FilePlanComponentProperties properties; - @JsonProperty (ALLOWABLE_OPERATIONS) + + @JsonProperty (value = ALLOWABLE_OPERATIONS) private List allowableOperations; + @JsonProperty (required = true) + private String modifiedAt; + + + @JsonProperty (required = true) + private String createdAt; + + @JsonProperty (required = true) + private FilePlanComponentUserInfo modifiedByUser; + + /** * @return the id */ @@ -207,7 +245,7 @@ public class FilePlanComponent /** * @return the createdByUser */ - public FilePlanComponentCreatedByUser getCreatedByUser() + public FilePlanComponentUserInfo getCreatedByUser() { return this.createdByUser; } @@ -215,7 +253,7 @@ public class FilePlanComponent /** * @param createdByUser the createdByUser to set */ - public void setCreatedByUser(FilePlanComponentCreatedByUser createdByUser) + public void setCreatedByUser(FilePlanComponentUserInfo createdByUser) { this.createdByUser = createdByUser; } @@ -227,4 +265,69 @@ public class FilePlanComponent { return this.allowableOperations; } + + public void setModifiedAt(String modifiedAt) + { + this.modifiedAt = modifiedAt; + } + + public void setCreatedAt(String createdAt) + { + this.createdAt = createdAt; + } + + public void setModifiedByUser(FilePlanComponentUserInfo modifiedByUser) + { + this.modifiedByUser = modifiedByUser; + } + + public boolean isCategory() + { + return this.isCategory; + } + + public boolean isRecordFolder() + { + return this.isRecordFolder; + } + + public boolean isFile() + { + return this.isFile; + } + + public String getModifiedAt() + { + return this.modifiedAt; + } + + public String getCreatedAt() + { + return this.createdAt; + } + + public FilePlanComponentUserInfo getModifiedByUser() + { + return this.modifiedByUser; + } + + public boolean isClosed() + { + return this.isClosed; + } + + public void setClosed(boolean closed) + { + this.isClosed = closed; + } + + public boolean isCompleted() + { + return this.isCompleted; + } + + public void setCompleted(boolean completed) + { + this.isCompleted = completed; + } } diff --git a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentFields.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentFields.java index fe59991f0e..0ef87cc62d 100644 --- a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentFields.java +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentFields.java @@ -28,5 +28,9 @@ public class FilePlanComponentFields public static final String PROPERTIES_VITAL_RECORD_INDICATOR = "rma:vitalRecordIndicator"; public static final String PROPERTIES_HOLD_REASON = "rma:holdReason"; public static final String PROPERTIES_DESCRIPTION = "cm:description"; + public static final String PROPERTIES_SUPPLEMENTAL_MARKING_LIST = "rmc:supplementalMarkingList"; public static final String ALLOWABLE_OPERATIONS = "allowableOperations"; + public static final String IS_CLOSED="isclosed"; + public static final String PROPERTIES_REVIEW_PERIOD="rma:reviewPeriod"; + public static final String PROPERTIES_LOCATION="rma:location"; } diff --git a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java index 729c444eb5..e3bbd4458b 100644 --- a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java @@ -13,9 +13,14 @@ package org.alfresco.rest.model.fileplancomponents; import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_DESCRIPTION; import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_HOLD_REASON; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_LOCATION; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_REVIEW_PERIOD; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_SUPPLEMENTAL_MARKING_LIST; import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR; +import java.util.List; + import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; @@ -26,9 +31,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; * @since 1.0 */ //FIXME: Once the fields have been added the JsonIgnoreProperties annotation should be removed -@JsonIgnoreProperties(ignoreUnknown = true) +@JsonIgnoreProperties (ignoreUnknown = true) public class FilePlanComponentProperties { + @JsonProperty(PROPERTIES_VITAL_RECORD_INDICATOR) private boolean vitalRecord; @@ -41,6 +47,16 @@ public class FilePlanComponentProperties @JsonProperty(PROPERTIES_DESCRIPTION) private String description; + @JsonProperty(PROPERTIES_SUPPLEMENTAL_MARKING_LIST) + private List supplementalMarkingList; + + @JsonProperty(PROPERTIES_REVIEW_PERIOD) + private ReviewPeriod reviewPeriod; + + @JsonProperty(PROPERTIES_LOCATION) + private String location; + + /** * @return the vitalRecord */ @@ -104,4 +120,34 @@ public class FilePlanComponentProperties { return this.description; } + + public List getSupplementalMarkingList() + { + return this.supplementalMarkingList; + } + + public void setSupplementalMarkingList(List supplementalMarkingList) + { + this.supplementalMarkingList = supplementalMarkingList; + } + + public ReviewPeriod getReviewPeriod() + { + return reviewPeriod; + } + + public void setReviewPeriod(ReviewPeriod reviewPeriod) + { + this.reviewPeriod = reviewPeriod; + } + + public String getLocation() + { + return location; + } + + public void setLocation(String location) + { + this.location = location; + } } diff --git a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentCreatedByUser.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentUserInfo.java similarity index 95% rename from src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentCreatedByUser.java rename to src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentUserInfo.java index c7abc2f920..76912ae486 100644 --- a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentCreatedByUser.java +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentUserInfo.java @@ -17,7 +17,7 @@ package org.alfresco.rest.model.fileplancomponents; * @author Kristijan Conkas * @since 1.0 */ -public class FilePlanComponentCreatedByUser +public class FilePlanComponentUserInfo { private String id; private String displayName; diff --git a/src/main/java/org/alfresco/rest/model/fileplancomponents/ReviewPeriod.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/ReviewPeriod.java new file mode 100644 index 0000000000..475b761ab9 --- /dev/null +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/ReviewPeriod.java @@ -0,0 +1,33 @@ +package org.alfresco.rest.model.fileplancomponents; + +/** + * POJO for file plan component review period + * + * @author Rodica Sutu + * @since 1.0 + */ +public class ReviewPeriod +{ + private String periodType; + private String expression; + + public String getPeriodType() + { + return periodType; + } + + public void setPeriodType(String periodType) + { + this.periodType = periodType; + } + + public String getExpression() + { + return expression; + } + + public void setExpression(String expression) + { + this.expression = expression; + } +} diff --git a/src/test/java/org/alfresco/rest/base/BaseRestTest.java b/src/test/java/org/alfresco/rest/base/BaseRestTest.java index 6151551afa..8f7f0cb222 100644 --- a/src/test/java/org/alfresco/rest/base/BaseRestTest.java +++ b/src/test/java/org/alfresco/rest/base/BaseRestTest.java @@ -13,6 +13,14 @@ package org.alfresco.rest.base; import static java.lang.Integer.parseInt; +import static org.alfresco.rest.base.TestData.CATEGORY_TITLE; +import static org.alfresco.rest.base.TestData.FOLDER_TITLE; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.NAME; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.NODE_TYPE; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE; import static org.alfresco.rest.model.site.RMSiteCompliance.STANDARD; import static org.alfresco.rest.model.site.RMSiteFields.COMPLIANCE; import static org.alfresco.rest.model.site.RMSiteFields.DESCRIPTION; @@ -26,6 +34,9 @@ import com.jayway.restassured.RestAssured; import org.alfresco.rest.RestTest; import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.fileplancomponents.FilePlanComponent; +import org.alfresco.rest.model.fileplancomponents.FilePlanComponentType; +import org.alfresco.rest.requests.FilePlanComponentAPI; import org.alfresco.rest.requests.RMSiteAPI; import org.alfresco.utility.data.DataUser; import org.springframework.beans.factory.annotation.Autowired; @@ -58,12 +69,18 @@ public class BaseRestTest extends RestTest @Value ("${rest.rmPath}") private String restRmPath; + @Value ("${rest.basePath}") + private String restCorePath; + @Autowired private RMSiteAPI rmSiteAPI; @Autowired private DataUser dataUser; + @Autowired + public FilePlanComponentAPI filePlanComponentAPI; + // Constants public static final String RM_ID = "rm"; public static final String RM_TITLE = "Records Management"; @@ -73,7 +90,7 @@ public class BaseRestTest extends RestTest * @see org.alfresco.rest.RestTest#checkServerHealth() */ @Override - @BeforeClass(alwaysRun = true) + @BeforeClass (alwaysRun = true) public void checkServerHealth() throws Exception { RestAssured.baseURI = scheme + "://" + server; @@ -119,4 +136,57 @@ public class BaseRestTest extends RestTest rmSiteAPI.getSite(); return restWrapper.getStatusCode().equals(OK.toString()); } + + /** + * Helper method to create child category + * + * @param parentCategoryId The id of the parent category + * @param categoryName The name of the category + * @return The created category + * @throws Exception on unsuccessful component creation + */ + public FilePlanComponent createCategory(String parentCategoryId, String categoryName) throws Exception + { + return createComponent(parentCategoryId, categoryName, RECORD_CATEGORY_TYPE, CATEGORY_TITLE); + } + + /** + * Helper method to create child folder + * + * @param parentCategoryId The id of the parent category + * @param folderName The name of the category + * @return The created category + * @throws Exception on unsuccessful component creation + */ + public FilePlanComponent createFolder(String parentCategoryId, String folderName) throws Exception + { + return createComponent(parentCategoryId, folderName, RECORD_FOLDER_TYPE, FOLDER_TITLE); + } + + /** + * Helper method to create generic child component + * + * @param parentComponentId The id of the parent file plan component + * @param componentName The name of the file plan component + * @param componentType The name of the file plan component + * @param componentTitle + * @return The created file plan component + * @throws Exception + */ + private FilePlanComponent createComponent(String parentComponentId, String componentName, FilePlanComponentType componentType, String componentTitle) throws Exception + { + RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + JsonObject componentProperties = buildObject().add(NAME, componentName) + .add(NODE_TYPE, componentType.toString()) + .addObject(PROPERTIES) + .add(PROPERTIES_TITLE, componentTitle) + .end() + .getJson(); + + FilePlanComponent fpc = filePlanComponentAPI.createFilePlanComponent(componentProperties, parentComponentId); + restWrapper.assertStatusCodeIs(CREATED); + return fpc; + } + } \ No newline at end of file diff --git a/src/test/java/org/alfresco/rest/base/TestData.java b/src/test/java/org/alfresco/rest/base/TestData.java index fb71b4f37c..dc8e23ee16 100644 --- a/src/test/java/org/alfresco/rest/base/TestData.java +++ b/src/test/java/org/alfresco/rest/base/TestData.java @@ -19,6 +19,7 @@ import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentType.F import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentType.HOLD_CONTAINER_TYPE; import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentType.TRANSFER_CONTAINER_TYPE; import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE; +import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; import org.testng.annotations.DataProvider; @@ -77,4 +78,24 @@ public interface TestData { UNFILED_RECORDS_CONTAINER_ALIAS, UNFILED_CONTAINER_TYPE }, }; } + + /** + * The default CATEGORY name used when creating categories + */ + public static String CATEGORY_NAME = "CATEGORY NAME"+ getRandomAlphanumeric(); + + /** + * The default CATEGORY title used when creating categories + */ + public static String CATEGORY_TITLE = "CATEGORY TITLE" + getRandomAlphanumeric(); + + /** + * The default FOLDER name used when creating categories + */ + public static String FOLDER_NAME = "FOLDER NAME" + getRandomAlphanumeric(); + + /** + * The default FOLDER title used when creating categories + */ + public static String FOLDER_TITLE = "FOLDER TITLE" + getRandomAlphanumeric(); } diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java index 67d73d42c6..544e97c79b 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java @@ -341,7 +341,7 @@ public class RecordCategoryTest extends BaseRestTest * @return The created category * @throws Exception on unsuccessful component creation */ - private FilePlanComponent createCategory(String parentCategoryId, String categoryName) throws Exception + public FilePlanComponent createCategory(String parentCategoryId, String categoryName) throws Exception { return createComponent(parentCategoryId, categoryName, RECORD_CATEGORY_TYPE); } diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordFolderTests.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordFolderTests.java new file mode 100644 index 0000000000..ab8409c7aa --- /dev/null +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordFolderTests.java @@ -0,0 +1,350 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.rest.fileplancomponents; + +import static org.alfresco.rest.base.TestData.CATEGORY_NAME; +import static org.alfresco.rest.base.TestData.FOLDER_NAME; +import static org.alfresco.rest.base.TestData.FOLDER_TITLE; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.IS_CLOSED; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.NAME; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.NODE_TYPE; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_DESCRIPTION; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_LOCATION; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_REVIEW_PERIOD; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR; +import static org.alfresco.rest.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE; +import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; +import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; +import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.NOT_FOUND; +import static org.springframework.http.HttpStatus.NO_CONTENT; +import static org.springframework.http.HttpStatus.OK; +import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY; +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 com.google.gson.JsonObject; + +import org.alfresco.rest.base.BaseRestTest; +import org.alfresco.rest.base.TestData; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.model.fileplancomponents.FilePlanComponent; +import org.alfresco.rest.model.fileplancomponents.FilePlanComponentProperties; +import org.alfresco.rest.model.fileplancomponents.FilePlanComponentsCollection; +import org.alfresco.rest.requests.FilePlanComponentAPI; +import org.alfresco.utility.data.DataUser; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Test; + +/** + * This class contains the tests for the + * the Record Folder CRUD API + * + * @author Rodica Sutu + * @since 1.0 + */ +public class RecordFolderTests extends BaseRestTest +{ + @Autowired + public FilePlanComponentAPI filePlanComponentAPI; + + @Autowired + public DataUser dataUser; + + private static final int NUMBER_OF_FOLDER= 5; + /** + * Given that a record category exists + * When I use the API to create a new record folder + * Then it is created within the record category + */ + @Test + ( + description = "Create a folder into a record category" + ) + public void createFolderTest() throws Exception + { + String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric(); + // Authenticate with admin user + RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + FilePlanComponent filePlanComponent=createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY); + + // Build the record category properties + JsonObject recordFolderProperties = buildObject() + .add(NAME, FOLDER_NAME) + .add(NODE_TYPE, RECORD_FOLDER_TYPE.toString()) + .addObject(PROPERTIES) + .add(PROPERTIES_TITLE, FOLDER_TITLE) + .end() + .getJson(); + + // Create the record folder + FilePlanComponent folder = filePlanComponentAPI.createFilePlanComponent(recordFolderProperties, filePlanComponent.getId()); + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED); + // Check folder has been created within the category created + assertEquals(filePlanComponent.getId(),folder.getParentId()); + // Verify the returned properties for the file plan component + assertFalse(folder.isIsCategory()); + assertFalse(folder.isIsFile()); + assertTrue(folder.isIsRecordFolder()); + + assertEquals(folder.getName(), FOLDER_NAME); + assertEquals(folder.getNodeType(), RECORD_FOLDER_TYPE.toString()); + assertEquals(folder.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername()); + + // Verify the returned file plan component properties + FilePlanComponentProperties folderProperties = folder.getProperties(); + assertEquals(folderProperties.getTitle(), FOLDER_TITLE); + } + + /** + * Given that RM site is created + * When I use the API to create a new record folder into transfers container/holds container/unfiled + * Then the operation fails + */ + @Test + ( + description = "Create a folder into hold/transfers/unfiled/file plan container", + dataProviderClass = TestData.class, + dataProvider = "getContainers" + ) + public void createFolderIntoSpecialContainers(String filePlanComponent) throws Exception + { + // Authenticate with admin user + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + String componentID = filePlanComponentAPI.getFilePlanComponent(filePlanComponent).getId(); + + // Build the record category properties + JsonObject recordFolderProperties = buildObject() + .add(NAME, FOLDER_NAME) + .add(NODE_TYPE, RECORD_FOLDER_TYPE.toString()) + .addObject(PROPERTIES) + .add(PROPERTIES_TITLE, FOLDER_TITLE) + .end() + .getJson(); + + // Create a record folder + filePlanComponentAPI.createFilePlanComponent(recordFolderProperties, componentID); + + // Check the API Response code + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); + } + + /** + * Given that a record folder exists + * When I ask for the details of a record folder + * Then I am given the details of a record folder + */ + @Test + ( + description = "Check the details returned for a record folder" + ) + public void checkTheRecordFolderProperties() throws Exception + { + String CATEGORY=CATEGORY_NAME + getRandomAlphanumeric(); + // Authenticate with admin user + RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY); + FilePlanComponent folder =createFolder(category.getId(),FOLDER_NAME); + + FilePlanComponent folderDetails=filePlanComponentAPI.withParams("include="+IS_CLOSED).getFilePlanComponent(folder.getId()); + assertEquals(RECORD_FOLDER_TYPE.toString(),folderDetails.getNodeType()); + assertTrue(folderDetails.isIsRecordFolder()); + assertFalse(folderDetails.isCategory()); + assertFalse(folderDetails.isFile()); + assertFalse(folderDetails.isClosed()); + + assertEquals(FOLDER_NAME,folderDetails.getName()); + assertEquals(dataUser.getAdminUser().getUsername(),folderDetails.getCreatedByUser().getId()); + assertEquals(dataUser.getAdminUser().getUsername(), folderDetails.getModifiedByUser().getId()); + assertEquals(FOLDER_TITLE,folderDetails.getProperties().getTitle()); + + } + + + /** + * Given that a record folder exists + * When I use the API to update its details + * Then the details of the record folder are updated + * The above test does treat any custom metadata + * Note: the details of the record folder includes any custom meta-data + */ + @Test + ( + description = "Update the details returned for a record folder" + ) + public void updateTheRecordFolderProperties() throws Exception + { + String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric(); + // Authenticate with admin user + RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY); + FilePlanComponent folder = createFolder(category.getId(), FOLDER_NAME); + + // Create record category first + String folderDescription = "The folder description is updated" + getRandomAlphanumeric(); + String folderName= "The folder name is updated" + getRandomAlphanumeric(); + String folderTitle = "Update title " + getRandomAlphanumeric(); + // Build the file plan root properties + JsonObject folderProperties = buildObject() + .add(NAME, folderName) + .addObject(PROPERTIES) + .add(PROPERTIES_TITLE, folderTitle) + .add(PROPERTIES_DESCRIPTION, folderDescription) + //.addArray(PROPERTIES_SUPPLEMENTAL_MARKING_LIST).add("list1").end() + .add(PROPERTIES_VITAL_RECORD_INDICATOR,true) + .add(PROPERTIES_REVIEW_PERIOD,"month|1") + .add(PROPERTIES_LOCATION,"Location") + .end() + + .getJson(); + + // Update the record category + FilePlanComponent folderUpdated = filePlanComponentAPI.updateFilePlanComponent(folderProperties, folder.getId()); + } + + /** + * Given that a record folder exists + * When I use the API to delete the record folder + * Then it deleted according to the normal rules governing the deletion of record folders + */ + @Test + ( + description = "Delete record folder" + ) + public void deleteRecordFolder() throws Exception + { + String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric(); + + // Authenticate with admin user + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY); + FilePlanComponent folder = createFolder(category.getId(), FOLDER_NAME); + // Delete the Record folder + filePlanComponentAPI.deleteFilePlanComponent(folder.getId()); + // Check the Response Status Code + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(NO_CONTENT); + // Check the File Plan Component is not found + filePlanComponentAPI.getFilePlanComponent(folder.getId()); + // Check the Response Status Code + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(NOT_FOUND); + } + + /** + * Given that a record category exists + * And contains several record folders + * When I use the APi to get the file plan component children for the existing category + * Then I am provided with a list of the contained record folders + * And their details + */ + @Test + ( + description = "List children of a category" + ) + public void listFolders() throws Exception + { + + String CATEGORY = CATEGORY_NAME + getRandomAlphanumeric(); + + // Authenticate with admin user + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + FilePlanComponent category = createCategory(FILE_PLAN_ALIAS.toString(), CATEGORY); + + // Add child olders + ArrayList children = new ArrayList(); + for (int i = 0; i < NUMBER_OF_FOLDER; i++) + { + // Create a child + FilePlanComponent child = createFolder(category.getId(), + getRandomAlphanumeric()); + assertNotNull(child.getId()); + children.add(child); + } + + // Authenticate with admin user + RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + // List children from API + FilePlanComponentsCollection apiChildren = filePlanComponentAPI.listChildComponents(category.getId()); + + // 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(), category.getId()); + + // Only categories or folders have been created + assertFalse(filePlanComponent.isIsFile()); + + // Boolean properties related to node type + // Only RECORD_FOLDER_TYPE have been created + assertTrue(filePlanComponent.isIsRecordFolder()); + assertFalse(filePlanComponent.isIsCategory()); + // Does returned object have the same contents as the created one? + assertEquals(createdComponent.getName(), filePlanComponent.getName()); + assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType()); + + } catch (NoSuchElementException e) + { + fail("No child element for " + filePlanComponent.getId()); + } + } + ); + + } + @AfterClass (alwaysRun = true) + public void tearDown() throws Exception + { + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + filePlanComponentAPI.listChildComponents(FILE_PLAN_ALIAS.toString()).getEntries().forEach(filePlanComponentEntry -> + { + try + { + filePlanComponentAPI.deleteFilePlanComponent(filePlanComponentEntry.getFilePlanComponent().getId()); + } catch (Exception e) + { + e.printStackTrace(); + } + }); + } + + + +} From 71de2f36979d5d93feec5cd96956d0f70d69e718 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Mon, 14 Nov 2016 10:40:16 +0200 Subject: [PATCH 46/49] add comments, tidy up the code --- .../fileplancomponents/FilePlanComponent.java | 45 ++++++++++++------- .../FilePlanComponentProperties.java | 18 ++++++++ .../fileplancomponents/ReviewPeriod.java | 18 ++++++-- .../fileplancomponents/RecordFolderTests.java | 36 ++++++++++----- 4 files changed, 88 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java index 438fcf03f8..b0f8fb7872 100644 --- a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java @@ -266,66 +266,81 @@ public class FilePlanComponent return this.allowableOperations; } + /** + * @param modifiedAt the modifiedAt to set + */ public void setModifiedAt(String modifiedAt) { this.modifiedAt = modifiedAt; } + /** + * @param createdAt the createdAt to set + */ public void setCreatedAt(String createdAt) { this.createdAt = createdAt; } + /** + * @param modifiedByUser the modifiedByUser to set + */ public void setModifiedByUser(FilePlanComponentUserInfo modifiedByUser) { this.modifiedByUser = modifiedByUser; } - public boolean isCategory() - { - return this.isCategory; - } - - public boolean isRecordFolder() - { - return this.isRecordFolder; - } - - public boolean isFile() - { - return this.isFile; - } - + /** + * @return the modifiedAt + */ public String getModifiedAt() { return this.modifiedAt; } + /** + * @return the createdAt + */ public String getCreatedAt() { return this.createdAt; } + /** + * @return the modifiedByUser + */ public FilePlanComponentUserInfo getModifiedByUser() { return this.modifiedByUser; } + /** + * @return the isClosed + */ public boolean isClosed() { return this.isClosed; } + /** + * @param closed the isClosed to set + */ public void setClosed(boolean closed) { this.isClosed = closed; } + /** + * @return the isCompleted + */ public boolean isCompleted() { return this.isCompleted; } + /** + * @param completed the isCompleted to set + */ public void setCompleted(boolean completed) { this.isCompleted = completed; diff --git a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java index e3bbd4458b..1ba6ea10b1 100644 --- a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponentProperties.java @@ -121,31 +121,49 @@ public class FilePlanComponentProperties return this.description; } + /** + * @return the supplementalMarkingList + */ public List getSupplementalMarkingList() { return this.supplementalMarkingList; } + /** + * @param supplementalMarkingList the supplementalMarkingList to set + */ public void setSupplementalMarkingList(List supplementalMarkingList) { this.supplementalMarkingList = supplementalMarkingList; } + /** + * @return the reviewPeriod + */ public ReviewPeriod getReviewPeriod() { return reviewPeriod; } + /** + * @param reviewPeriod the reviewPeriod to set + */ public void setReviewPeriod(ReviewPeriod reviewPeriod) { this.reviewPeriod = reviewPeriod; } + /** + * @return the location + */ public String getLocation() { return location; } + /** + * @param location the location to set + */ public void setLocation(String location) { this.location = location; diff --git a/src/main/java/org/alfresco/rest/model/fileplancomponents/ReviewPeriod.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/ReviewPeriod.java index 475b761ab9..331cc6f23e 100644 --- a/src/main/java/org/alfresco/rest/model/fileplancomponents/ReviewPeriod.java +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/ReviewPeriod.java @@ -1,7 +1,7 @@ package org.alfresco.rest.model.fileplancomponents; /** - * POJO for file plan component review period + * POJO for the review period * * @author Rodica Sutu * @since 1.0 @@ -11,21 +11,33 @@ public class ReviewPeriod private String periodType; private String expression; + /** + * @return the periodType + */ public String getPeriodType() { - return periodType; + return this.periodType; } + /** + * @param periodType the periodType to set + */ public void setPeriodType(String periodType) { this.periodType = periodType; } + /** + * @return the expression + */ public String getExpression() { - return expression; + return this.expression; } + /** + * @param expression the expression to set + */ public void setExpression(String expression) { this.expression = expression; diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordFolderTests.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordFolderTests.java index ab8409c7aa..77e4db794a 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordFolderTests.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordFolderTests.java @@ -101,7 +101,7 @@ public class RecordFolderTests extends BaseRestTest filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(CREATED); // Check folder has been created within the category created assertEquals(filePlanComponent.getId(),folder.getParentId()); - // Verify the returned properties for the file plan component + // Verify the returned properties for the file plan component - record folder assertFalse(folder.isIsCategory()); assertFalse(folder.isIsFile()); assertTrue(folder.isIsRecordFolder()); @@ -167,10 +167,12 @@ public class RecordFolderTests extends BaseRestTest FilePlanComponent folder =createFolder(category.getId(),FOLDER_NAME); FilePlanComponent folderDetails=filePlanComponentAPI.withParams("include="+IS_CLOSED).getFilePlanComponent(folder.getId()); + + // Verify the returned properties for the file plan component - record folder assertEquals(RECORD_FOLDER_TYPE.toString(),folderDetails.getNodeType()); assertTrue(folderDetails.isIsRecordFolder()); - assertFalse(folderDetails.isCategory()); - assertFalse(folderDetails.isFile()); + assertFalse(folderDetails.isIsCategory()); + assertFalse(folderDetails.isIsFile()); assertFalse(folderDetails.isClosed()); assertEquals(FOLDER_NAME,folderDetails.getName()); @@ -204,22 +206,37 @@ public class RecordFolderTests extends BaseRestTest String folderDescription = "The folder description is updated" + getRandomAlphanumeric(); String folderName= "The folder name is updated" + getRandomAlphanumeric(); String folderTitle = "Update title " + getRandomAlphanumeric(); + String location="Location"+getRandomAlphanumeric(); + String review_period="month|1"; + // Build the file plan root properties JsonObject folderProperties = buildObject() .add(NAME, folderName) .addObject(PROPERTIES) .add(PROPERTIES_TITLE, folderTitle) .add(PROPERTIES_DESCRIPTION, folderDescription) - //.addArray(PROPERTIES_SUPPLEMENTAL_MARKING_LIST).add("list1").end() .add(PROPERTIES_VITAL_RECORD_INDICATOR,true) - .add(PROPERTIES_REVIEW_PERIOD,"month|1") - .add(PROPERTIES_LOCATION,"Location") + .add(PROPERTIES_REVIEW_PERIOD, review_period) + .add(PROPERTIES_LOCATION, location) .end() - .getJson(); // Update the record category FilePlanComponent folderUpdated = filePlanComponentAPI.updateFilePlanComponent(folderProperties, folder.getId()); + + // Check the Response Status Code + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(OK); + + // Verify the returned properties for the file plan component - record folder + assertEquals(folderName, folderUpdated.getName()); + assertEquals(folderDescription, folderUpdated.getProperties().getDescription()); + assertEquals(folderTitle, folderUpdated.getProperties().getTitle()); + assertTrue(folderUpdated.getProperties().isVitalRecord()); + assertEquals(location, folderUpdated.getProperties().getLocation()); + assertNotNull(folderUpdated.getProperties().getReviewPeriod().getPeriodType()); + assertNotNull(folderUpdated.getProperties().getReviewPeriod().getExpression()); + + } /** @@ -309,15 +326,12 @@ public class RecordFolderTests extends BaseRestTest // Is parent Id set correctly assertEquals(filePlanComponent.getParentId(), category.getId()); - - // Only categories or folders have been created assertFalse(filePlanComponent.isIsFile()); // Boolean properties related to node type - // Only RECORD_FOLDER_TYPE have been created assertTrue(filePlanComponent.isIsRecordFolder()); assertFalse(filePlanComponent.isIsCategory()); - // Does returned object have the same contents as the created one? + assertEquals(createdComponent.getName(), filePlanComponent.getName()); assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType()); From 4aa72d45919a7eb915f9845da0518cad07532977 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Mon, 14 Nov 2016 11:00:12 +0200 Subject: [PATCH 47/49] update the response status code for createFilePlanSpecialContainerWhenExists() to 422 --- .../alfresco/rest/fileplancomponents/FilePlanTests.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java index 427e080cde..99b1cc459c 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/FilePlanTests.java @@ -27,6 +27,7 @@ import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; import static org.springframework.http.HttpStatus.FORBIDDEN; import static org.springframework.http.HttpStatus.NOT_FOUND; import static org.springframework.http.HttpStatus.OK; +import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; @@ -254,15 +255,15 @@ public class FilePlanTests extends BaseRestTest filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); // Create the special containers into RM site - parent folder filePlanComponentAPI.createFilePlanComponent(componentProperties, rmSiteId); - filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); // Create the special containers into RM site - parent folder filePlanComponentAPI.createFilePlanComponent(componentProperties, FILE_PLAN_ALIAS.toString()); - filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); // Create the special containers into the root of special containers containers filePlanComponentAPI.createFilePlanComponent(componentProperties, filePlanAlias.toString()); - filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(FORBIDDEN); + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); } /** From 709b6d7d133027a6dcfb2dc69b23a818e7577f1d Mon Sep 17 00:00:00 2001 From: Silviu Dinuta Date: Mon, 14 Nov 2016 12:27:27 +0200 Subject: [PATCH 48/49] RM-4368: changed links from sites to ig-sites --- src/main/java/org/alfresco/rest/requests/RMSiteAPI.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/alfresco/rest/requests/RMSiteAPI.java b/src/main/java/org/alfresco/rest/requests/RMSiteAPI.java index 580d7703ea..46fd602d61 100644 --- a/src/main/java/org/alfresco/rest/requests/RMSiteAPI.java +++ b/src/main/java/org/alfresco/rest/requests/RMSiteAPI.java @@ -53,7 +53,7 @@ public class RMSiteAPI extends RestAPI { return usingRestWrapper().processModel(RMSite.class, simpleRequest( GET, - "sites/rm" + "ig-sites/rm" )); } @@ -77,7 +77,7 @@ public class RMSiteAPI extends RestAPI return usingRestWrapper().processModel(RMSite.class, requestWithBody( POST, rmSiteProperties.toString(), - "sites" + "ig-sites" )); } @@ -96,7 +96,7 @@ public class RMSiteAPI extends RestAPI { usingRestWrapper().processEmptyModel(simpleRequest( DELETE, - "sites/rm" + "ig-sites/rm" )); } @@ -121,7 +121,7 @@ public class RMSiteAPI extends RestAPI return usingRestWrapper().processModel(RMSite.class, requestWithBody( PUT, rmSiteProperties.toString(), - "sites/rm" + "ig-sites/rm" )); } } From 03be67b0733e8a217b220adaf874e1d06a9a8601 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Mon, 14 Nov 2016 13:35:18 +0200 Subject: [PATCH 49/49] updates after review --- .../model/fileplancomponents/FilePlanComponent.java | 2 -- .../rest/fileplancomponents/RecordFolderTests.java | 10 ++++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java index 75be896761..5e8c1b08c0 100644 --- a/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java +++ b/src/main/java/org/alfresco/rest/model/fileplancomponents/FilePlanComponent.java @@ -25,8 +25,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; * @author Tuna Aksoy * @since 1.0 */ -//FIXME: Once the fields have been added the JsonIgnoreProperties annotation should be removed - public class FilePlanComponent { @JsonProperty (required = true) diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordFolderTests.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordFolderTests.java index b4b0be64cf..1d47785196 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordFolderTests.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordFolderTests.java @@ -71,7 +71,7 @@ public class RecordFolderTests extends BaseRestTest @Autowired public DataUser dataUser; - private static final int NUMBER_OF_FOLDER= 5; + private static final int NUMBER_OF_FOLDERS= 5; /** * Given that a record category exists * When I use the API to create a new record folder @@ -290,7 +290,7 @@ public class RecordFolderTests extends BaseRestTest // Add child olders ArrayList children = new ArrayList(); - for (int i = 0; i < NUMBER_OF_FOLDER; i++) + for (int i = 0; i < NUMBER_OF_FOLDERS; i++) { // Create a child FilePlanComponent child = createFolder(category.getId(), @@ -337,7 +337,8 @@ public class RecordFolderTests extends BaseRestTest assertEquals(createdComponent.getName(), filePlanComponent.getName()); assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType()); - } catch (NoSuchElementException e) + } + catch (NoSuchElementException e) { fail("No child element for " + filePlanComponent.getId()); } @@ -354,7 +355,8 @@ public class RecordFolderTests extends BaseRestTest try { filePlanComponentAPI.deleteFilePlanComponent(filePlanComponentEntry.getFilePlanComponent().getId()); - } catch (Exception e) + } + catch (Exception e) { e.printStackTrace(); }