From ab6566da4e9be075d088bf58a289c0f73c798010 Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Thu, 1 Dec 2016 11:29:47 +0000 Subject: [PATCH] RM-4391: Closed folder creation test. --- .../FilePlanComponentFields.java | 1 + .../FilePlanComponentProperties.java | 20 ++++++ .../rest/rm/community/base/BaseRestTest.java | 21 ++++++ .../NonElectronicRecordTests.java | 70 ++++++++++++++----- 4 files changed, 96 insertions(+), 16 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentFields.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentFields.java index f839ffda9a..11b14c1906 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentFields.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentFields.java @@ -48,6 +48,7 @@ public class FilePlanComponentFields public static final String IS_CLOSED = "isClosed"; public static final String PROPERTIES_REVIEW_PERIOD = "rma:reviewPeriod"; public static final String PROPERTIES_LOCATION = "rma:location"; + public static final String PROPERTIES_IS_CLOSED = "rma:isClosed"; // not to be confused with IS_CLOSED! // for non-electronic records public static final String PROPERTIES_BOX = "rma:box"; diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentProperties.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentProperties.java index 261bf546e0..9c17419680 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentProperties.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentProperties.java @@ -30,6 +30,7 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_DESCRIPTION; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_FILE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_HOLD_REASON; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_IS_CLOSED; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_LOCATION; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_NUMBER_OF_COPIES; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_PHYSICAL_SIZE; @@ -80,6 +81,9 @@ public class FilePlanComponentProperties @JsonProperty(PROPERTIES_LOCATION) private String location; + @JsonProperty(value = PROPERTIES_IS_CLOSED, required = false) + private Boolean isClosed; + @JsonProperty(value = PROPERTIES_BOX, required = false) private String box; @@ -303,4 +307,20 @@ public class FilePlanComponentProperties { this.physicalSize = physicalSize; } + + /** + * @return the isClosed + */ + public Boolean getIsClosed() + { + return this.isClosed; + } + + /** + * @param isClosed the isClosed to set + */ + public void setIsClosed(Boolean isClosed) + { + this.isClosed = isClosed; + } } diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java index 7eade80baa..601d1437e2 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRestTest.java @@ -35,6 +35,7 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE; import static org.alfresco.rest.rm.community.model.site.RMSiteCompliance.STANDARD; import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.OK; import com.jayway.restassured.RestAssured; @@ -190,4 +191,24 @@ public class BaseRestTest extends RestTest return fpc; } + /** + * Helper method to close folder + * @param folderToClose + * @return + * @throws Exception + */ + public FilePlanComponent closeFolder(String folderId) throws Exception + { + RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + // build fileplan component + properties for update request + FilePlanComponentProperties properties = new FilePlanComponentProperties(); + properties.setIsClosed(true); + FilePlanComponent filePlanComponent = new FilePlanComponent(); + filePlanComponent.setProperties(properties); + + FilePlanComponent updatedComponent = filePlanComponentAPI.updateFilePlanComponent(filePlanComponent, folderId); + restWrapper.assertStatusCodeIs(OK); + return updatedComponent; + } } \ No newline at end of file diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java index 1528f02404..257548c797 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java @@ -121,24 +121,12 @@ public class NonElectronicRecordTests extends BaseRestTest public void canCreateInOpenFolder() throws Exception { filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); - - // create root category - FilePlanComponent recordCategory = filePlanComponentAPI.createFilePlanComponent( - new FilePlanComponent("Category " + getRandomAlphanumeric(), - RECORD_CATEGORY_TYPE.toString(), - new FilePlanComponentProperties()), - FILE_PLAN_ALIAS.toString()); - - // create record folder as a child of recordCategory - FilePlanComponent recordFolder = filePlanComponentAPI.withParams("include=" + IS_CLOSED) - .createFilePlanComponent(new FilePlanComponent("Folder " + getRandomAlphanumeric(), - RECORD_FOLDER_TYPE.toString(), - new FilePlanComponentProperties()), - recordCategory.getId()); + FilePlanComponent recordFolder = createFolderInFilePlan(); // the folder should be open - assertFalse(recordFolder.isClosed()); + assertFalse(recordFolder.getProperties().getIsClosed()); + // use these properties for non-electronic record to be created String title = "Title " + getRandomAlphanumeric(); String description = "Description " + getRandomAlphanumeric(); String box = "Box "+ getRandomAlphanumeric(); @@ -180,5 +168,55 @@ public class NonElectronicRecordTests extends BaseRestTest assertEquals(location, nonElectronicRecord.getProperties().getLocation()); assertEquals(copies, nonElectronicRecord.getProperties().getNumberOfCopies()); assertEquals(size, nonElectronicRecord.getProperties().getPhysicalSize()); - } + } + + /** + * Given a parent container that is a record folder + * And the record folder is closed + * When I try to create a non-electronic record within the parent container + * Then nothing happens + * And an error is reported + * @throws Exception on failed component creation + */ + @Test(description = "Non-electronic record can't be created in closed record folder") + public void noCreateInClosedFolder() throws Exception + { + filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + FilePlanComponent recordFolder = createFolderInFilePlan(); + + // the folder should be open + assertFalse(recordFolder.getProperties().getIsClosed()); + + // close the folder + closeFolder(recordFolder.getId()); + + try + { + filePlanComponentAPI.createFilePlanComponent( + new FilePlanComponent("Record " + getRandomAlphanumeric(), + NON_ELECTRONIC_RECORD_TYPE.toString(), + new FilePlanComponentProperties()), + recordFolder.getId()).getId(); + } + catch (Exception e) + { + } + + // verify the status code + filePlanComponentAPI.usingRestWrapper().assertStatusCodeIs(UNPROCESSABLE_ENTITY); + } + + /** + * Helper method to create a randomly-named / structure in fileplan + * @return record folder + * @throws Exception on failed creation + */ + private FilePlanComponent createFolderInFilePlan() throws Exception + { + // create root category + FilePlanComponent recordCategory = createCategory(FILE_PLAN_ALIAS.toString(), "Category " + getRandomAlphanumeric()); + + // and return a folder underneath + return createFolder(recordCategory.getId(), "Folder " + getRandomAlphanumeric()); + } }