From d146c4454b0ce856261c30d12b925f74a1bebc0b Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Mon, 31 Oct 2016 08:33:41 +0200 Subject: [PATCH] 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); + } +}