diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplan/FilePlanProperties.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplan/FilePlanProperties.java index 5143d3e2c6..59219e2c35 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplan/FilePlanProperties.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplan/FilePlanProperties.java @@ -28,8 +28,10 @@ package org.alfresco.rest.rm.community.model.fileplan; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_COMPONENT_ID; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_COUNT; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_DESCRIPTION; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_IDENTIFIER; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_ROOT_NODE_REF; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; import com.fasterxml.jackson.annotation.JsonProperty; @@ -71,4 +73,10 @@ public class FilePlanProperties extends TestModel /************************/ @JsonProperty (PROPERTIES_COUNT) private Integer count; + + @JsonProperty (PROPERTIES_TITLE) + private String title; + + @JsonProperty (PROPERTIES_DESCRIPTION) + private String description; } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/unfiledcontainer/UnfiledContainerChild.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/unfiledcontainer/UnfiledContainerChild.java index 3affd91574..2360135800 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/unfiledcontainer/UnfiledContainerChild.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/unfiledcontainer/UnfiledContainerChild.java @@ -96,9 +96,6 @@ public class UnfiledContainerChild extends TestModel @JsonProperty private List aspectNames; - @JsonProperty - private Boolean hasRetentionSchedule; - @JsonProperty private Boolean isClosed; diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/unfiledcontainer/UnfiledContainerChildProperties.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/unfiledcontainer/UnfiledContainerChildProperties.java index 440efd42aa..f8bde1a223 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/unfiledcontainer/UnfiledContainerChildProperties.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/unfiledcontainer/UnfiledContainerChildProperties.java @@ -45,8 +45,8 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_PHYSICAL_SIZE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_PIXEL_X_DIMENSION; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_PIXEL_Y_DIMENSION; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_RECORD_SEARCH_HAS_DISPOSITION_SCHEDULE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_RESOLUTION_UNIT; -import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_REVIEW_PERIOD; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_ROOT_NODE_REF; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_SHELF; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_SOFTWARE; @@ -54,7 +54,6 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VERSION_LABEL; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VERSION_TYPE; -import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_INDICATOR; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_X_RESOLUTION; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_Y_RESOLUTION; @@ -64,7 +63,6 @@ import org.alfresco.rest.rm.community.util.ReviewPeriodSerializer; import org.alfresco.utility.model.TestModel; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; import lombok.AllArgsConstructor; import lombok.Builder; @@ -92,22 +90,18 @@ public class UnfiledContainerChildProperties extends TestModel @JsonProperty (required = true, value = PROPERTIES_TITLE) private String title; - @JsonProperty (required = true, value = PROPERTIES_VITAL_RECORD_INDICATOR) - private Boolean vitalRecordIndicator; - @JsonProperty (required = true, value = PROPERTIES_ROOT_NODE_REF) private String rootNodeRef; @JsonProperty (required = true, value = PROPERTIES_IDENTIFIER) private String identifier; - @JsonProperty (required = true, value = PROPERTIES_REVIEW_PERIOD) - @JsonSerialize (using = ReviewPeriodSerializer.class) - private ReviewPeriod reviewPeriod; - @JsonProperty (required = true, value = PROPERTIES_DESCRIPTION) private String description; + @JsonProperty (value = PROPERTIES_RECORD_SEARCH_HAS_DISPOSITION_SCHEDULE) + private Boolean recordSearchHasDispositionSchedule; + /*********************************/ /** Electronic record parameters */ /*********************************/ diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/FilePlanAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/FilePlanAPI.java index fcaea4b6a1..d1102fed09 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/FilePlanAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/FilePlanAPI.java @@ -34,6 +34,7 @@ import static org.alfresco.rest.rm.community.util.PojoUtility.toJson; import static org.apache.commons.lang3.StringUtils.EMPTY; 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.RMRestWrapper; import org.alfresco.rest.rm.community.model.fileplan.FilePlan; @@ -172,4 +173,44 @@ public class FilePlanAPI extends RMModelRequest parameters )); } + + /** + * see {@link #updateFilePlan(FilePlan, String, String) + */ + public FilePlan updateFilePlan(FilePlan filePlanModel, String filePlanId) throws Exception + { + mandatoryObject("filePlanModel", filePlanModel); + mandatoryString("filePlanId", filePlanId); + + return updateFilePlan(filePlanModel, filePlanId, EMPTY); + } + + /** + * Updates a file plan. + * + * @param filePlanModel The file plan model which holds the information + * @param filePlanId The identifier of the file plan + * @param parameters The URL parameters to add + * @throws Exception for the following cases: + * + */ + public FilePlan updateFilePlan(FilePlan filePlanModel, String filePlanId, String parameters) throws Exception + { + mandatoryObject("filePlanModel", filePlanModel); + mandatoryString("filePlanId", filePlanId); + + return getRmRestWrapper().processModel(FilePlan.class, requestWithBody( + PUT, + toJson(filePlanModel), + "file-plans/{filePlanId}?{parameters}", + filePlanId, + parameters)); + } + } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RecordFolderAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RecordFolderAPI.java index 46e0824eeb..d88d2b3a3f 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RecordFolderAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RecordFolderAPI.java @@ -263,7 +263,7 @@ public class RecordFolderAPI extends RMModelRequest * Creates a record in a record folder child, i.e. a record. * * @param recordModel The record model which holds the information - * @param recordfolderId The identifier of a record folder + * @param recordFolderId The identifier of a record folder * @param parameters The URL parameters to add * @return The created {@link Record} * @throws Exception for the following cases: diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/UnfiledContainerAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/UnfiledContainerAPI.java index b1d91fbdbd..916b2488fa 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/UnfiledContainerAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/UnfiledContainerAPI.java @@ -108,7 +108,7 @@ public class UnfiledContainerAPI extends RMModelRequest } /** - * see {@link #getRootRecordCategories(String, String)} + * see {@link #getUnfiledContainerChildren(String)} (String, String)} */ public UnfiledContainerChildCollection getUnfiledContainerChildren(String unfiledContainerId) { diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/TestData.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/TestData.java index 16c611a200..3c799ebb61 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/TestData.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/TestData.java @@ -80,23 +80,7 @@ public interface TestData }; } - /** - * Data Provider with: - * the special file plan components alias - * file plan component node type - * @return file plan component alias - */ - @DataProvider - public static String[][] getContainersAndTypes() - { - return new String[][] { - { FILE_PLAN_ALIAS, FILE_PLAN_TYPE }, - { TRANSFERS_ALIAS, TRANSFER_CONTAINER_TYPE }, - { UNFILED_RECORDS_CONTAINER_ALIAS, UNFILED_CONTAINER_TYPE }, - }; - } - - /** + /** * The default record category name used when creating categories */ public static String RECORD_CATEGORY_NAME = "CATEGORY NAME" + getRandomAlphanumeric(); @@ -174,4 +158,20 @@ public interface TestData { RECORD_CATEGORY_TYPE } }; } + + /** + * Invalid root level types, at unfiled record folder/unfiled containers container level that shouldn't be possible to create + */ + @DataProvider (name = "invalidRootTypes") + public static Object[][] getInvalidRootTypes() + { + return new String[][] + { + { FILE_PLAN_TYPE }, + { RECORD_CATEGORY_TYPE }, + { RECORD_FOLDER_TYPE }, + { TRANSFER_CONTAINER_TYPE }, + { UNFILED_CONTAINER_TYPE } + }; + } } diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/FilePlanTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/FilePlanTests.java deleted file mode 100644 index 950b116341..0000000000 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/FilePlanTests.java +++ /dev/null @@ -1,258 +0,0 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2017 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * - - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ -package org.alfresco.rest.rm.community.fileplancomponents; - -import static java.util.Arrays.asList; -import static org.alfresco.rest.rm.community.base.AllowableOperations.CREATE; -import static org.alfresco.rest.rm.community.base.AllowableOperations.DELETE; -import static org.alfresco.rest.rm.community.base.AllowableOperations.UPDATE; -import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; -import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS; -import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.ALLOWABLE_OPERATIONS; -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 org.alfresco.rest.rm.community.base.BaseRMRestTest; -import org.alfresco.rest.rm.community.base.TestData; -import org.alfresco.rest.rm.community.model.fileplan.FilePlan; -import org.alfresco.rest.rm.community.model.transfercontainer.TransferContainer; -import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer; -import org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI; -import org.alfresco.utility.model.UserModel; -import org.testng.annotations.Test; - -/** - * This class contains the tests for the File Plan CRUD API - * - * @author Rodica Sutu - * @since 2.6 - */ -public class FilePlanTests extends BaseRMRestTest -{ - /** - *
-     * Given that the RM site doesn't exist
-     * When I use the API to get the File Plan/Holds/Unfiled Records Container/Transfers
-     * Then I get the 404 response code
-     * 
- */ - @Test - ( - description = "Check the GET response for the special contianers when the RM site doesn't exist", - dataProviderClass = TestData.class, - dataProvider = "getContainers" - ) - public void getContainersWhenRMIsNotCreated(String containerAlias) throws Exception - { - RMSiteAPI rmSiteAPI = getRestAPIFactory().getRMSiteAPI(); - - // Check RM Site Exist - if (rmSiteAPI.existsRMSite()) - { - // Delete RM Site - rmSiteAPI.deleteRMSite(); - } - - if (FILE_PLAN_ALIAS.equalsIgnoreCase(containerAlias)) - { - getRestAPIFactory().getFilePlansAPI().getFilePlan(containerAlias); - } - else if(TRANSFERS_ALIAS.equalsIgnoreCase(containerAlias)) - { - getRestAPIFactory().getTransferContainerAPI().getTransferContainer(containerAlias); - } - else - { - getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(containerAlias); - } - - // Check the response code is NOT_FOUND - assertStatusCode(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 the special containers when the RM site exit", - dataProviderClass = TestData.class, - dataProvider = "getContainersAndTypes" - ) - public void getContainersWhenRMIsCreated(String containerAlias, String containerType) throws Exception - { - // Create RM Site if doesn't exist - createRMSiteIfNotExists(); - - // Get the file plan special container - FilePlan filePlan = null; - TransferContainer transferContainer = null; - UnfiledContainer unfiledContainer = null; - - if (FILE_PLAN_ALIAS.equalsIgnoreCase(containerAlias)) - { - filePlan = getRestAPIFactory().getFilePlansAPI().getFilePlan(containerAlias); - } - else if(TRANSFERS_ALIAS.equalsIgnoreCase(containerAlias)) - { - transferContainer = getRestAPIFactory().getTransferContainerAPI().getTransferContainer(containerAlias); - } - else - { - unfiledContainer = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(containerAlias); - } - - // Check the response code - assertStatusCode(OK); - - // Check the response contains the right node type - if (FILE_PLAN_ALIAS.equalsIgnoreCase(containerAlias)) - { - assertEquals(filePlan.getNodeType(), containerType); - } - else if(TRANSFERS_ALIAS.equalsIgnoreCase(containerAlias)) - { - assertEquals(transferContainer.getNodeType(), containerType); - } - else - { - assertEquals(unfiledContainer.getNodeType(), containerType); - } - } - - /** - *
-     * 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(String containerAlias) throws Exception - { - // Create RM Site if doesn't exist - createRMSiteIfNotExists(); - - // Get the file plan special containers with the optional parameter allowableOperations - FilePlan filePlan = null; - TransferContainer transferContainer = null; - UnfiledContainer unfiledContainer = null; - - if (FILE_PLAN_ALIAS.equalsIgnoreCase(containerAlias)) - { - // Check the list of allowableOperations returned - filePlan = getRestAPIFactory().getFilePlansAPI().getFilePlan(containerAlias, "include=" + ALLOWABLE_OPERATIONS); - - assertTrue(filePlan.getAllowableOperations().containsAll(asList(UPDATE, CREATE)), - "Wrong list of the allowable operations is return" + filePlan.getAllowableOperations().toString()); - - // Check the list of allowableOperations doesn't contain DELETE operation - assertFalse(filePlan.getAllowableOperations().contains(DELETE), - "The list of allowable operations contains delete option" + filePlan.getAllowableOperations().toString()); - } - else if (TRANSFERS_ALIAS.equalsIgnoreCase(containerAlias)) - { - // Check the list of allowableOperations returned - transferContainer = getRestAPIFactory().getTransferContainerAPI().getTransferContainer(containerAlias, "include=" + ALLOWABLE_OPERATIONS); - - assertTrue(transferContainer.getAllowableOperations().containsAll(asList(UPDATE)), - "Wrong list of the allowable operations is return" + transferContainer.getAllowableOperations().toString()); - - // Check the list of allowableOperations doesn't contain DELETE operation - assertFalse(transferContainer.getAllowableOperations().contains(DELETE), - "The list of allowable operations contains delete option" + transferContainer.getAllowableOperations().toString()); - - // Check the list of allowableOperations doesn't contain DELETE operation - assertFalse(transferContainer.getAllowableOperations().contains(CREATE), - "The list of allowable operations contains delete option" + transferContainer.getAllowableOperations().toString()); - } - else - { - unfiledContainer = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(containerAlias, "include=" + ALLOWABLE_OPERATIONS); - - // Check the list of allowableOperations returned - assertTrue(unfiledContainer.getAllowableOperations().containsAll(asList(UPDATE, CREATE)), - "Wrong list of the allowable operations is return" + unfiledContainer.getAllowableOperations().toString()); - - // Check the list of allowableOperations doesn't contain DELETE operation - assertFalse(unfiledContainer.getAllowableOperations().contains(DELETE), - "The list of allowable operations contains delete option" + unfiledContainer.getAllowableOperations().toString()); - } - } - - /** - *
-     * Given that RM site exists
-     * When a non-RM user asks 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 getContainersWithNonRMuser(String containerAlias) throws Exception - { - // Create RM Site if doesn't exist - createRMSiteIfNotExists(); - - // Create a random user - UserModel nonRMuser = getDataUser().createRandomTestUser("testUser"); - - // Get the special file plan components - if (FILE_PLAN_ALIAS.equalsIgnoreCase(containerAlias)) - { - getRestAPIFactory().getFilePlansAPI(nonRMuser).getFilePlan(containerAlias); - } - else if(TRANSFERS_ALIAS.equalsIgnoreCase(containerAlias)) - { - getRestAPIFactory().getTransferContainerAPI(nonRMuser).getTransferContainer(containerAlias); - } - else - { - getRestAPIFactory().getUnfiledContainersAPI(nonRMuser).getUnfiledContainer(containerAlias); - } - - // Check the response status code is FORBIDDEN - assertStatusCode(FORBIDDEN); - } -} diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/RecordCategoryTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/RecordCategoryTests.java deleted file mode 100644 index 0ee2456877..0000000000 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/RecordCategoryTests.java +++ /dev/null @@ -1,331 +0,0 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2017 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * - - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ -package org.alfresco.rest.rm.community.fileplancomponents; - -import static org.alfresco.rest.rm.community.base.TestData.RECORD_CATEGORY_NAME; -import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; -import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE; -import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE; -import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; -import static org.springframework.http.HttpStatus.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.assertTrue; -import static org.testng.Assert.fail; - -import java.util.ArrayList; -import java.util.List; -import java.util.NoSuchElementException; - -import org.alfresco.rest.rm.community.base.BaseRMRestTest; -import org.alfresco.rest.rm.community.base.TestData; -import org.alfresco.rest.rm.community.model.fileplan.FilePlan; -import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; -import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild; -import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChildCollection; -import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryProperties; -import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI; -import org.alfresco.utility.report.Bug; -import org.testng.annotations.Test; - -/** - * Record category related API tests - * - * @author Kristijan Conkas - * @author Tuna Aksoy - * @since 2.6 - */ -public class RecordCategoryTests extends BaseRMRestTest -{ - /** Number of children (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
-     * 
- *
-     * Given that a file plan exists
-     * When I use the API to create a folder (cm:folder type) into the fileplan
-     * Then the folder is converted to rma:recordCategory
-     * (see RM-4572 comments)
-     * 
- */ - @Test - ( - description = "Create root category", - dataProviderClass= TestData.class, - dataProvider = "categoryTypes" - ) - public void createCategoryTest(String nodeType) throws Exception - { - String categoryName = "Category name " + getRandomAlphanumeric(); - String categoryTitle = "Category title " + getRandomAlphanumeric(); - - // Create the root record category - RecordCategory rootRecordCategory = createRootCategory(categoryName, categoryTitle); - - // Verify the status code - assertStatusCode(CREATED); - - assertEquals(rootRecordCategory.getName(), categoryName); - assertEquals(rootRecordCategory.getNodeType(), RECORD_CATEGORY_TYPE); - - assertEquals(rootRecordCategory.getCreatedByUser().getId(), getAdminUser().getUsername()); - - // Verify the returned root record category properties - RecordCategoryProperties rootRecordCategoryProperties = rootRecordCategory.getProperties(); - assertEquals(rootRecordCategoryProperties.getTitle(), categoryTitle); - assertNotNull(rootRecordCategoryProperties.getIdentifier()); - logger.info("Aspects: " + rootRecordCategory.getAspectNames()); - } - - /** - *
-     * 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 root category" - ) - public void renameCategory() throws Exception - { - // Create record category first - String categoryName = "Category name " + getRandomAlphanumeric(); - String categoryTitle = "Category title " + getRandomAlphanumeric(); - - // Create the root record category - RecordCategory rootRecordCategory = createRootCategory(categoryName, categoryTitle); - - String newCategoryName = "Rename " + categoryName; - - // Build the properties which will be updated - RecordCategory recordCategoryUpdated = RecordCategory.builder().name(newCategoryName).build(); - - // Update the record category - RecordCategory renamedRecordCategory = getRestAPIFactory().getRecordCategoryAPI().updateRecordCategory(recordCategoryUpdated, rootRecordCategory.getId()); - - // Verify the status code - assertStatusCode(OK); - - // Verify the returned file plan component - assertEquals(renamedRecordCategory.getName(), newCategoryName); - - // Get actual FILE_PLAN_ALIAS id - FilePlan filePlan = getRestAPIFactory().getFilePlansAPI().getFilePlan(FILE_PLAN_ALIAS); - - // verify renamed component still has this parent - assertEquals(renamedRecordCategory.getParentId(), filePlan.getId()); - } - - /** - *
-     * Given that a record category exists
-     * When I ask the API to delete the record category
-     * Then the record category and all its contents are deleted
-     * 
- */ - @Test - ( - description = "Delete category" - ) - public void deleteCategory() throws Exception - { - // Create record category first - String categoryName = "Category name " + getRandomAlphanumeric(); - String categoryTitle = "Category title " + getRandomAlphanumeric(); - - // Create the root record category - RecordCategory rootRecordCategory = createRootCategory(categoryName, categoryTitle); - - // Delete the record category - RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI(); - String recordCategoryId = rootRecordCategory.getId(); - recordCategoryAPI.deleteRecordCategory(recordCategoryId); - - // Verify the status code - assertStatusCode(NO_CONTENT); - - // Deleted component should no longer be retrievable - recordCategoryAPI.getRecordCategory(recordCategoryId); - assertStatusCode(NOT_FOUND); - } - - /** - *
-     * 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 - RecordCategory rootCategory = createRootCategory(getRandomAlphanumeric()); - assertNotNull(rootCategory.getId()); - - // Create sub-category as a child of rootCategory - RecordCategoryChild recordCategory = createRecordCategoryChild(rootCategory.getId(), RECORD_CATEGORY_NAME, RECORD_CATEGORY_TYPE); - - // Child category created? - assertNotNull(recordCategory.getId()); - - // Verify child category - assertEquals(recordCategory.getParentId(), rootCategory.getId()); - assertTrue(recordCategory.getIsRecordCategory()); - assertFalse(recordCategory.getIsRecordFolder()); - assertEquals(recordCategory.getNodeType(), RECORD_CATEGORY_TYPE); - } - - /** - *
-     * 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 = "Get children of a record category" - ) - public void getRecordCategoryChildren() throws Exception - { - // Create root level category - RecordCategory rootRecordCategory = createRootCategory(getRandomAlphanumeric()); - assertNotNull(rootRecordCategory.getId()); - - // Add record category children - List children = new ArrayList(); - for (int i=0; i < NUMBER_OF_CHILDREN; i++) - { - // Create a record category child - RecordCategoryChild child = createRecordCategoryChild(rootRecordCategory.getId(), - getRandomAlphanumeric(), - // half of the children should be sub-categories, the other sub-folders - (i <= NUMBER_OF_CHILDREN / 2) ? RECORD_CATEGORY_TYPE : RECORD_FOLDER_TYPE); - assertNotNull(child.getId()); - children.add(child); - } - - // Get children from API - RecordCategoryChildCollection recordCategoryChildren = getRestAPIFactory().getRecordCategoryAPI().getRecordCategoryChildren(rootRecordCategory.getId(),"include=isRecordCategory,isRecordFolder"); - - // Check status code - assertStatusCode(OK); - logger.info("Parent: " + rootRecordCategory.getId()); - - // Check listed children against created list - recordCategoryChildren.getEntries().forEach(c -> - { - RecordCategoryChild recordCategoryChild = c.getEntry(); - String recordCategoryChildId = recordCategoryChild.getId(); - - assertNotNull(recordCategoryChildId); - logger.info("Checking child " + recordCategoryChildId); - - try - { - // Find this child in created children list - RecordCategoryChild createdComponent = children.stream() - .filter(child -> child.getId().equals(recordCategoryChildId)) - .findFirst() - .get(); - - // Created by - assertEquals(recordCategoryChild.getCreatedByUser().getId(), getAdminUser().getUsername()); - - // Is parent id set correctly? - assertEquals(recordCategoryChild.getParentId(), rootRecordCategory.getId()); - - // Boolean properties related to node type - // Only RECORD_CATEGORY_TYPE and RECORD_FOLDER_TYPE have been created - if (recordCategoryChild.getNodeType().equals(RECORD_CATEGORY_TYPE)) - { - assertTrue(recordCategoryChild.getIsRecordCategory()); - assertFalse(recordCategoryChild.getIsRecordFolder()); - } - else - { - assertTrue(recordCategoryChild.getIsRecordFolder()); - assertFalse(recordCategoryChild.getIsRecordCategory()); - } - - // Does returned object have the same contents as the created one? - assertEquals(createdComponent.getName(), recordCategoryChild.getName()); - assertEquals(createdComponent.getNodeType(), recordCategoryChild.getNodeType()); - - // FIXME: Verify properties - assertNotNull(createdComponent.getProperties().getIdentifier()); - } - catch (NoSuchElementException e) - { - fail("No child element for " + recordCategoryChildId); - } - }); - } - - /** - *
-     * Given that a record category exists
-     * When I ask to create an object type which is not a record category or a record folder as a child
-     * Then the children are not created and the 422 response code is returned
-     * 
- */ - @Test - ( - description = "Create node types not allowed inside a category", - dataProviderClass = TestData.class, - dataProvider = "childrenNotAllowedForCategory" - ) - @Bug (id="RM-4367, RM-4572") - public void createTypesNotAllowedInCategory(String nodeType) throws Exception - { - String componentName = "Component" + getRandomAlphanumeric(); - - // Create the category - RecordCategory rootRecordCategory = createRootCategory(componentName); - - // Create the invalid node type - createRecordCategoryChild(rootRecordCategory.getId(), componentName, nodeType); - assertStatusCode(UNPROCESSABLE_ENTITY); - } -} diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/RecordFolderTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/RecordFolderTests.java deleted file mode 100644 index 92d1da8749..0000000000 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/RecordFolderTests.java +++ /dev/null @@ -1,530 +0,0 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2017 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * - - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ -package org.alfresco.rest.rm.community.fileplancomponents; - -import static java.time.LocalDateTime.now; -import static org.alfresco.rest.rm.community.base.TestData.RECORD_CATEGORY_NAME; -import static org.alfresco.rest.rm.community.base.TestData.RECORD_FOLDER_NAME; -import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; -import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS; -import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.IS_CLOSED; -import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PATH; -import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE; -import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE; -import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.TITLE_PREFIX; -import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; -import static org.springframework.http.HttpStatus.BAD_REQUEST; -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.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.fail; -import static org.testng.AssertJUnit.assertTrue; - -import java.util.ArrayList; -import java.util.NoSuchElementException; - -import org.alfresco.rest.rm.community.base.BaseRMRestTest; -import org.alfresco.rest.rm.community.base.TestData; -import org.alfresco.rest.rm.community.model.common.ReviewPeriod; -import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; -import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild; -import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChildCollection; -import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChildProperties; -import org.alfresco.rest.rm.community.model.recordfolder.RecordFolder; -import org.alfresco.rest.rm.community.model.recordfolder.RecordFolderProperties; -import org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI; -import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI; -import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI; -import org.alfresco.utility.report.Bug; -import org.testng.AssertJUnit; -import org.testng.annotations.AfterClass; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.Test; - -/** - * This class contains the tests for the Record Folder CRUD API - * - * @author Rodica Sutu - * @since 2.6 - */ -public class RecordFolderTests extends BaseRMRestTest -{ - 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
-     * Then it is created within the record category
-     * 
- *
-     * Given that a record category exists
-     * When I use the API to create a folder (cm:folder type)
-     * Then the folder is converted to rma:recordFolder within the record category
-     * (see RM-4572 comments)
-     * 
- */ - @Test - ( - description = "Create a record folder into a record category.", - dataProviderClass = TestData.class, - dataProvider = "folderTypes" - ) - @Bug (id = "RM-4572") - public void createFolderTest(String folderType) throws Exception - { - // Authenticate with admin user - RecordCategory rootRecordCategory = createRootCategory(RECORD_CATEGORY_NAME + getRandomAlphanumeric()); - - // Create the record folder - RecordCategoryChild recordFolder = createRecordCategoryChild(rootRecordCategory.getId(), RECORD_FOLDER_NAME, folderType); - - // Assert status code - assertStatusCode(CREATED); - - // Check record folder has been created within the record category - AssertJUnit.assertEquals(rootRecordCategory.getId(), recordFolder.getParentId()); - - // Verify the returned values for the record folder - assertFalse(recordFolder.getIsRecordCategory()); - assertTrue(recordFolder.getIsRecordFolder()); - AssertJUnit.assertEquals(recordFolder.getName(), RECORD_FOLDER_NAME); - AssertJUnit.assertEquals(recordFolder.getNodeType(), RECORD_FOLDER_TYPE); - AssertJUnit.assertEquals(recordFolder.getCreatedByUser().getId(), getAdminUser().getUsername()); - - // Verify the returned record folder properties - RecordCategoryChildProperties folderProperties = recordFolder.getProperties(); - AssertJUnit.assertEquals(folderProperties.getTitle(), TITLE_PREFIX + RECORD_FOLDER_NAME); - assertNotNull(folderProperties.getIdentifier()); - } - - /** - *
-     * Given that RM site is created
-     * When I use the API to create a new record folder into transfers/holds/unfiled containers
-     * Then the operation fails
-     * 
- */ - @Test - ( - description = "Create a record folder into transfers/unfiled/file plan container", - dataProviderClass = TestData.class, - dataProvider = "getContainers" - ) - @Bug(id="RM-4327") - public void createRecordFolderIntoSpecialContainers(String containerAlias) throws Exception - { - String containerId; - if (FILE_PLAN_ALIAS.equalsIgnoreCase(containerAlias)) - { - containerId = getRestAPIFactory().getFilePlansAPI().getFilePlan(containerAlias).getId(); - } - else if(TRANSFERS_ALIAS.equalsIgnoreCase(containerAlias)) - { - containerId = getRestAPIFactory().getTransferContainerAPI().getTransferContainer(containerAlias).getId(); - } - else - { - //is unfiled container - containerId = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(containerAlias).getId();; - } - - // Create a record folder - createRecordFolder(containerId, RECORD_FOLDER_NAME); - - // Check the API Response code - assertStatusCode(BAD_REQUEST); - } - - /** - *
-     * 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 of a record folder" - ) - public void checkRecordFolderDetails() throws Exception - { - // Create a category - RecordCategory rootRecordCategory = createRootCategory(RECORD_CATEGORY_NAME + getRandomAlphanumeric()); - - // Create a folder - RecordCategoryChild recordCategoryChild = createRecordFolder(rootRecordCategory.getId(), RECORD_FOLDER_NAME); - - // Get the folder including extra information - RecordFolder recordFolder = getRestAPIFactory().getRecordFolderAPI().getRecordFolder(recordCategoryChild.getId(), "include=" + IS_CLOSED); - - // Verify the returned record folder details - AssertJUnit.assertEquals(recordFolder.getNodeType(), RECORD_FOLDER_TYPE); - assertTrue(RECORD_FOLDER_TYPE.equals(recordFolder.getNodeType())); - AssertJUnit.assertEquals(recordFolder.getName(), RECORD_FOLDER_NAME); - AssertJUnit.assertEquals(recordFolder.getCreatedByUser().getId(), getAdminUser().getUsername()); - AssertJUnit.assertEquals(recordFolder.getModifiedByUser().getId(), getAdminUser().getUsername()); - AssertJUnit.assertEquals(recordFolder.getProperties().getTitle(), TITLE_PREFIX + RECORD_FOLDER_NAME); - } - - /** - *
-     * 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 of a record folder" - ) - public void updateRecordFolderDetails() throws Exception - { - // Create a record category - RecordCategory rootRecordCategory = createRootCategory(RECORD_CATEGORY_NAME + getRandomAlphanumeric()); - - // Create a record folder - RecordCategoryChild recordCategoryChild = createRecordFolder(rootRecordCategory.getId(), RECORD_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(); - String location = "Location "+ getRandomAlphanumeric(); - - // Create the record folder properties to update - RecordFolder recordFolder = RecordFolder.builder() - .name(folderName) - .properties(RecordFolderProperties.builder() - .title(folderTitle) - .description(folderDescription) - .vitalRecordIndicator(true) - .reviewPeriod(new ReviewPeriod("month","1")) - .location(location) - .build()) - .build(); - - // Update the record folder - RecordFolder updatedRecordFolder = getRestAPIFactory().getRecordFolderAPI().updateRecordFolder(recordFolder, recordCategoryChild.getId()); - - // Check the Response Status Code - assertStatusCode(OK); - - // Verify the returned details for the record folder - AssertJUnit.assertEquals(updatedRecordFolder.getName(), folderName); - RecordFolderProperties recordFolderProperties = updatedRecordFolder.getProperties(); - AssertJUnit.assertEquals(recordFolderProperties.getDescription(), folderDescription); - AssertJUnit.assertEquals(recordFolderProperties.getTitle(), folderTitle); - assertTrue(recordFolderProperties.getVitalRecordIndicator()); - AssertJUnit.assertEquals(recordFolderProperties.getLocation(), location); - assertNotNull(recordFolderProperties.getReviewPeriod().getPeriodType()); - assertNotNull(recordFolderProperties.getReviewPeriod().getExpression()); - } - - /** - *
-     * Given that a record folder exists
-     * When I use the API to delete the record folder
-     * Then it is deleted according to the normal rules governing the deletion of record folders
-     * 
- */ - @Test - ( - description = "Delete record folder" - ) - public void deleteRecordFolder() throws Exception - { - // Create the record category - RecordCategory rootRecordCategory = createRootCategory(RECORD_CATEGORY_NAME + getRandomAlphanumeric()); - - // Create the record folder - RecordCategoryChild recordFolder = createRecordFolder(rootRecordCategory.getId(), RECORD_FOLDER_NAME); - - // Delete the record folder - RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI(); - String recordFolderId = recordFolder.getId(); - recordFolderAPI.deleteRecordFolder(recordFolderId); - - // Check the response status code - assertStatusCode(NO_CONTENT); - - // Check the record folder is not found - recordFolderAPI.getRecordFolder(recordFolderId); - - // Check the response status code - assertStatusCode(NOT_FOUND); - } - - /** - *
-     * Given that a record category exists
-     * And contains several record folders
-     * When I use the API to get the record category children for an existing record category
-     * Then I am provided with a list of the contained record category children and their details
-     * 
- */ - @Test - ( - description = "Get children of a record category" - ) - public void getFolders() throws Exception - { - // Authenticate with admin user - RecordCategory rootRecordCategory = createRootCategory(RECORD_CATEGORY_NAME + getRandomAlphanumeric()); - - // Add child folders - ArrayList children = new ArrayList(); - for (int i = 0; i < NUMBER_OF_FOLDERS; i++) - { - // Create a record folder - RecordCategoryChild recordCategoryChild = createRecordFolder(rootRecordCategory.getId(), getRandomAlphanumeric()); - assertNotNull(recordCategoryChild.getId()); - children.add(recordCategoryChild); - } - - // Get record category children from API - RecordCategoryChildCollection recordCategoryChildren = getRestAPIFactory().getRecordCategoryAPI().getRecordCategoryChildren(rootRecordCategory.getId(), "include=isRecordCategory,isRecordFolder"); - - // Check status code - assertStatusCode(OK); - - // Check children against created list - recordCategoryChildren.getEntries().forEach(c -> - { - RecordCategoryChild recordCategoryChild = c.getEntry(); - String recordCategoryChildId = recordCategoryChild.getId(); - assertNotNull(recordCategoryChildId); - logger.info("Checking child " + recordCategoryChildId); - - try - { - // Find this child in created children list - RecordCategoryChild createdComponent = children.stream() - .filter(child -> child.getId().equals(recordCategoryChildId)) - .findFirst() - .get(); - - // Created by - assertEquals(recordCategoryChild.getCreatedByUser().getId(), getAdminUser().getUsername()); - - // Is parent id set correctly - assertEquals(recordCategoryChild.getParentId(), rootRecordCategory.getId()); - - // Boolean properties related to node type - assertTrue(recordCategoryChild.getIsRecordFolder()); - assertFalse(recordCategoryChild.getIsRecordCategory()); - - assertEquals(createdComponent.getName(), recordCategoryChild.getName()); - assertEquals(createdComponent.getNodeType(), recordCategoryChild.getNodeType()); - - } - catch (NoSuchElementException e) - { - fail("No child element for " + recordCategoryChildId); - } - } - ); - - } - - /** - *
-     * Given that I want to create a record folder
-     * When I use the API with the relativePath
-     * Then the categories specified in the relativePath that don't exist are created
-     * 
- */ - @Test - ( - description = "Create a folder using record-categories endpoint, based on the relativePath. " + - "Containers in the relativePath that do not exist are created before the node is created" - ) - public void createRecordFolderWithRelativePath() throws Exception - { - // The record category to be created - RecordCategory recordCategoryModel = RecordCategory.builder() - .name(RECORD_CATEGORY_NAME) - .nodeType(RECORD_CATEGORY_TYPE) - .build(); - FilePlanAPI filePlansAPI = getRestAPIFactory().getFilePlansAPI(); - RecordCategory createRootRecordCategory = filePlansAPI.createRootRecordCategory(recordCategoryModel, FILE_PLAN_ALIAS, "include=" + PATH); - // Check the API response code - assertStatusCode(CREATED); - String recordCategoryId = createRootRecordCategory.getId(); - - // relativePath specify the container structure to create relative to the record folder to be created - String relativePath = now().getYear() + "/" + now().getMonth() + "/" + now().getDayOfMonth(); - - // The record folder to be created - RecordCategoryChild recordFolderModel = RecordCategoryChild.builder() - .name(RECORD_FOLDER_NAME) - .nodeType(RECORD_FOLDER_TYPE) - .relativePath(relativePath) - .build(); - - // Create the record folder - RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI(); - RecordCategoryChild recordCategoryChild = recordCategoryAPI.createRecordCategoryChild(recordFolderModel, recordCategoryId, "include=" + PATH); - - // Check the API response code - assertStatusCode(CREATED); - - // Verify the returned details for the record folder - assertFalse(recordCategoryChild.getIsRecordCategory()); - assertTrue(recordCategoryChild.getIsRecordFolder()); - - // Check the path return contains the relativePath - AssertJUnit.assertTrue(recordCategoryChild.getPath().getName().contains(relativePath)); - - // Check the parent is a category - assertNotNull(recordCategoryAPI.getRecordCategory(recordCategoryChild.getParentId()).getId()); - - // Check the created folder from the server - RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI(); - RecordFolder recordFolder = recordFolderAPI.getRecordFolder(recordCategoryChild.getId(), "include=" + PATH); - - // Check the API response code - assertStatusCode(OK); - - // Verify the returned details for the record folder - assertTrue(RECORD_FOLDER_TYPE.equals(recordFolder.getNodeType())); - - // Check the path return contains the relativePath - AssertJUnit.assertTrue(recordFolder.getPath().getName().contains(relativePath)); - - // New relative path only a part of containers need to be created before the record folder - String newRelativePath = now().getYear() + "/" + now().getMonth() + "/" + (now().getDayOfMonth() + 1); - - // The record folder to be created - RecordCategoryChild newRecordFolderModel = RecordCategoryChild.builder() - .name(RECORD_FOLDER_NAME) - .nodeType(RECORD_FOLDER_TYPE) - .relativePath(newRelativePath) - .build(); - - // Create the record folder - RecordCategoryChild newRecordCategoryChild = recordCategoryAPI.createRecordCategoryChild(newRecordFolderModel, recordCategoryId, "include=" + PATH); - - // Check the API response code - assertStatusCode(CREATED); - - // Verify the returned properties for the file plan component - record folder - assertFalse(newRecordCategoryChild.getIsRecordCategory()); - assertTrue(newRecordCategoryChild.getIsRecordFolder()); - - // Check the path return contains the newRelativePath - AssertJUnit.assertTrue(newRecordCategoryChild.getPath().getName().contains(newRelativePath)); - - // Check the parent is a category - assertNotNull(recordCategoryAPI.getRecordCategory(newRecordCategoryChild.getParentId()).getId()); - - // Check the folder created on the server - RecordFolder newRecordFolder = recordFolderAPI.getRecordFolder(newRecordCategoryChild.getId(), "include=" + PATH); - - // Check the API response code - assertStatusCode(OK); - - // Verify the returned details for the record folder - assertTrue(RECORD_FOLDER_TYPE.equals(recordFolder.getNodeType())); - - // Check the path return contains the newRelativePath - AssertJUnit.assertTrue(newRecordFolder.getPath().getName().contains(newRelativePath)); - } - - /** - * Given that a record folder exists - * When the record folder is closed - * Then a request can be made to reopen it - */ - @Test - ( - description = "A closed record folder can be reopened" - ) - @Bug(id="RM-4808") - public void openClosedRecordFolder() throws Exception - { - // Create a record folder - RecordCategoryChild recordFolder = createCategoryFolderInFilePlan(); - - // Assert that the record folder is not closed - assertFalse(recordFolder.getProperties().getIsClosed()); - - // Get the record folder API - RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI(); - - // Create a record folder model to close it - RecordFolder recordFolderModel = RecordFolder.builder() - .properties(RecordFolderProperties.builder() - .isClosed(true) - .build()) - .build(); - - // Make a request to close the record folder - RecordFolder updatedRecordFolder = recordFolderAPI.updateRecordFolder(recordFolderModel, recordFolder.getId()); - - //FIXME - remove this workaround after RM-4921 is fixed. - updatedRecordFolder = recordFolderAPI.getRecordFolder(updatedRecordFolder.getId()); - - // Verify that the record folder is closed now - assertTrue(updatedRecordFolder.getProperties().getIsClosed()); - - // Create a record folder model to reopen it - recordFolderModel = RecordFolder.builder() - .properties(RecordFolderProperties.builder() - .isClosed(false) - .build()) - .build(); - - // Make a request to reopen the record folder - updatedRecordFolder = recordFolderAPI.updateRecordFolder(recordFolderModel, recordFolder.getId()); - - //FIXME - remove this workaround after RM-4921 is fixed. - updatedRecordFolder = recordFolderAPI.getRecordFolder(updatedRecordFolder.getId()); - - // Verify that the record folder is open now - assertFalse(updatedRecordFolder.getProperties().getIsClosed()); - } - - @AfterMethod - @AfterClass (alwaysRun = true) - public void tearDown() throws Exception - { - FilePlanAPI filePlansAPI = getRestAPIFactory().getFilePlansAPI(); - RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI(); - - filePlansAPI.getRootRecordCategories(FILE_PLAN_ALIAS).getEntries().forEach(recordCategoryEntry -> - { - recordCategoryAPI.deleteRecordCategory(recordCategoryEntry.getEntry().getId()); - }); - } -} diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplans/FilePlanTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplans/FilePlanTests.java new file mode 100644 index 0000000000..73b1780b84 --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplans/FilePlanTests.java @@ -0,0 +1,485 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2017 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.rest.rm.community.fileplans; + +import static java.util.Arrays.asList; + +import static org.alfresco.rest.rm.community.base.AllowableOperations.CREATE; +import static org.alfresco.rest.rm.community.base.AllowableOperations.DELETE; +import static org.alfresco.rest.rm.community.base.AllowableOperations.UPDATE; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.ALLOWABLE_OPERATIONS; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.FILE_PLAN_TYPE; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.TRANSFER_CONTAINER_TYPE; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.TRANSFER_TYPE; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE; +import static org.alfresco.rest.rm.community.model.user.UserPermissions.PERMISSION_FILING; +import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_MANAGER; +import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; +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.OK; +import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; +import static org.testng.AssertJUnit.assertEquals; + +import java.util.ArrayList; +import java.util.NoSuchElementException; + +import org.alfresco.rest.rm.community.base.BaseRMRestTest; +import org.alfresco.rest.rm.community.base.TestData; +import org.alfresco.rest.rm.community.model.fileplan.FilePlan; +import org.alfresco.rest.rm.community.model.fileplan.FilePlanProperties; +import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryCollection; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryProperties; +import org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI; +import org.alfresco.utility.constants.ContainerName; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * This class contains the tests for the File Plan CRUD API + * + * @author Rodica Sutu + * @since 2.6 + */ +public class FilePlanTests extends BaseRMRestTest +{ + //** Number of children (for children creation test) */ + private static final int NUMBER_OF_CHILDREN = 10; + + /** + * Data Provider with: + * with the object types not allowed as children for a record category + * + * @return file plan component alias + */ + @DataProvider + public static Object[][] childrenNotAllowedForFilePlan() + { + return new String[][] { + { FILE_PLAN_TYPE }, + { TRANSFER_CONTAINER_TYPE }, + { UNFILED_CONTAINER_TYPE }, + { UNFILED_RECORD_FOLDER_TYPE }, + { TRANSFER_TYPE }, + { CONTENT_TYPE }, + { NON_ELECTRONIC_RECORD_TYPE}, + { RECORD_FOLDER_TYPE} + }; + } + + /** + *
+     * Given that the RM site doesn't exist
+     * When I use the API to get the File Plan
+     * Then I get the 404 response code
+     * 
+ */ + @Test + public void getFilePlanWhenRMIsNotCreated() throws Exception + { + RMSiteAPI rmSiteAPI = getRestAPIFactory().getRMSiteAPI(); + + // Check RM Site Exist + if (rmSiteAPI.existsRMSite()) + { + // Delete RM Site + rmSiteAPI.deleteRMSite(); + } + //get file plan + getRestAPIFactory().getFilePlansAPI().getFilePlan(FILE_PLAN_ALIAS); + + // Check the response code is NOT_FOUND + assertStatusCode(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 + public void getFilePlanWhenRMIsCreated() throws Exception + { + // Create RM Site if doesn't exist + createRMSiteIfNotExists(); + + FilePlan filePlan = getRestAPIFactory().getFilePlansAPI().getFilePlan(FILE_PLAN_ALIAS); + + // Check the response code + assertStatusCode(OK); + //check file plan details + assertTrue(filePlan.getNodeType().equals(FilePlanComponentType.FILE_PLAN_TYPE)); + assertTrue(filePlan.getName().equals(ContainerName.documentLibrary.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 + public void includeAllowableOperations() throws Exception + { + // Create RM Site if doesn't exist + createRMSiteIfNotExists(); + + // Check the list of allowableOperations returned + FilePlan filePlan = getRestAPIFactory().getFilePlansAPI().getFilePlan(FILE_PLAN_ALIAS, "include=" + ALLOWABLE_OPERATIONS); + + assertTrue(filePlan.getAllowableOperations().containsAll(asList(UPDATE, CREATE)), + "Wrong list of the allowable operations is return" + filePlan.getAllowableOperations().toString()); + + // Check the list of allowableOperations doesn't contain DELETE operation + assertFalse(filePlan.getAllowableOperations().contains(DELETE), + "The list of allowable operations contains delete option" + filePlan.getAllowableOperations().toString()); + + } + + /** + *
+     * Given that RM site exists
+     * When a non-RM user asks the API for the details of the file plan
+     * Then the status code 403 (Permission denied) is return
+     * 
+ */ + @Test + public void getFilePlanWithNonRMuser() throws Exception + { + // Create RM Site if doesn't exist + createRMSiteIfNotExists(); + + // Create a random user + UserModel nonRMuser = getDataUser().createRandomTestUser("testUser"); + + // Get the special file plan components + getRestAPIFactory().getFilePlansAPI(nonRMuser).getFilePlan(FILE_PLAN_ALIAS); + + // Check the response status code is FORBIDDEN + assertStatusCode(FORBIDDEN); + } + + /** + * 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 " + getRandomAlphanumeric(); + String FILE_PLAN_TITLE = "Title updated " + getRandomAlphanumeric(); + + // Create RM Site if doesn't exist + createRMSiteIfNotExists(); + + // Build object for updating the filePlan + FilePlan filePlanComponent = FilePlan.builder() + .properties(FilePlanProperties.builder() + .title(FILE_PLAN_TITLE) + .description(FILE_PLAN_DESCRIPTION) + .build()) + .build(); + // Create a random user + UserModel nonRMuser = getDataUser().createRandomTestUser("testUser"); + + // Update the file plan + getRestAPIFactory().getFilePlansAPI(nonRMuser).updateFilePlan(filePlanComponent, FILE_PLAN_ALIAS); + + //Check the response status code is FORBIDDEN + assertStatusCode(FORBIDDEN); + + // Update the file plan + FilePlan renamedFilePlan = getRestAPIFactory().getFilePlansAPI().updateFilePlan(filePlanComponent, FILE_PLAN_ALIAS); + + // Verify the response status code + assertStatusCode(OK); + + // Verify the returned description field for the file plan component + assertEquals(renamedFilePlan.getProperties().getDescription(), FILE_PLAN_DESCRIPTION); + + // Verify the returned title field for the file plan component + assertEquals(renamedFilePlan.getProperties().getTitle(), FILE_PLAN_TITLE); + } + + /** + * Given that a file plan exists + * When I ask the API to modify the name of the file plan + * Then a error is returned (422 response code) + */ + @Test + @Bug (id = "RM-4295") + public void updateFilePlanName() throws Exception + { + String FILE_PLAN_NAME = "File Plan name updated " + getRandomAlphanumeric(); + + // Create RM Site if doesn't exist + createRMSiteIfNotExists(); + + // Build object for updating the filePlan + FilePlan filePlanComponent = FilePlan.builder() + .name(FILE_PLAN_NAME) + .build(); + + // Update the file plan + getRestAPIFactory().getFilePlansAPI().updateFilePlan(filePlanComponent, FILE_PLAN_ALIAS); + + // Verify the response status code + assertStatusCode(UNPROCESSABLE_ENTITY); + } + + /** + *
+     * 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
+     * 
+ *
+     * Given that a file plan exists
+     * When I use the API to create a folder (cm:folder type) into the fileplan
+     * Then the folder is converted to rma:recordCategory
+     * (see RM-4572 comments)
+     * 
+ */ + @Test + ( + description = "Create root category", + dataProviderClass = TestData.class, + dataProvider = "categoryTypes" + ) + public void createFilePlanChildren(String nodeType) throws Exception + { + String categoryName = "Category name " + getRandomAlphanumeric(); + String categoryTitle = "Category title " + getRandomAlphanumeric(); + + // Create the root record category + RecordCategory recordCategory = RecordCategory.builder() + .name(categoryName) + .properties(RecordCategoryProperties.builder() + .title(categoryTitle) + .build()) + .nodeType(nodeType) + .build(); + RecordCategory rootRecordCategory = getRestAPIFactory().getFilePlansAPI() + .createRootRecordCategory(recordCategory,FILE_PLAN_ALIAS); + + // Verify the status code + assertStatusCode(CREATED); + + assertEquals(rootRecordCategory.getName(), categoryName); + assertEquals(rootRecordCategory.getNodeType(), RECORD_CATEGORY_TYPE); + + assertEquals(rootRecordCategory.getCreatedByUser().getId(), getAdminUser().getUsername()); + + // Verify the returned root record category properties + RecordCategoryProperties rootRecordCategoryProperties = rootRecordCategory.getProperties(); + assertEquals(rootRecordCategoryProperties.getTitle(), categoryTitle); + assertNotNull(rootRecordCategoryProperties.getIdentifier()); + } + + @Test + public void listFilePlanChildren() throws Exception + { + //delete all the root categories + getRestAPIFactory().getFilePlansAPI().getRootRecordCategories(FILE_PLAN_ALIAS).getEntries().forEach(recordCategoryEntry -> + { + getRestAPIFactory().getRecordCategoryAPI().deleteRecordCategory(recordCategoryEntry.getEntry().getId()); + }); + // Add child folders + ArrayList children = new ArrayList(); + for (int i = 0; i < NUMBER_OF_CHILDREN; i++) + { + String categoryName = "Category name " + getRandomAlphanumeric(); + String categoryTitle = "Category title " + getRandomAlphanumeric(); + // Create a record folder + RecordCategory recordCategory = createRootCategory(categoryName, categoryTitle); + assertNotNull(recordCategory.getId()); + children.add(recordCategory); + } + + // Get record category children from API + RecordCategoryCollection recordCategoryChildren = getRestAPIFactory().getFilePlansAPI() + .getRootRecordCategories(FILE_PLAN_ALIAS, "include=aspects,properties"); + + // Check status code + assertStatusCode(OK); + + // Check children against created list + recordCategoryChildren.getEntries().forEach(c -> + { + RecordCategory recordCategoryChild = c.getEntry(); + String recordCategoryChildId = recordCategoryChild.getId(); + assertNotNull(recordCategoryChildId); + logger.info("Checking child " + recordCategoryChildId); + + try + { + // Find this child in created children list + RecordCategory createdComponent = children.stream() + .filter(child -> child.getId().equals(recordCategoryChildId)) + .findFirst() + .get(); + + // Created by + assertEquals(recordCategoryChild.getCreatedByUser().getId(), getAdminUser().getUsername()); + + assertEquals(createdComponent.getName(), recordCategoryChild.getName()); + assertEquals(createdComponent.getNodeType(), recordCategoryChild.getNodeType()); + + } + catch (NoSuchElementException e) + { + fail("No child element for " + recordCategoryChildId); + } + } + ); + } + + /** + *
+     * Given that RM site is created
+     * When I use the API to create invalid types inside a file plan
+     * Then the node type provided is converted to a record category
+     * 
+ */ + @Test + ( + description = "Create a record folder/unfiled container/unfiled folder/record/file plan container", + dataProvider = "childrenNotAllowedForFilePlan" + ) + public void createChildrenNotAllowedInFilePlan(String nodeType) throws Exception + { + String componentName = "Component" + getRandomAlphanumeric(); + + // Create the root record category + RecordCategory component = RecordCategory.builder() + .name(componentName) + .nodeType(nodeType) + .build(); + // Create the invalid node type + RecordCategory rootRecordCategory = getRestAPIFactory().getFilePlansAPI() + .createRootRecordCategory(component, FILE_PLAN_ALIAS); + //check the response status code + assertStatusCode(CREATED); + assertEquals(rootRecordCategory.getName(), componentName); + assertEquals(rootRecordCategory.getNodeType(), RECORD_CATEGORY_TYPE); + + assertEquals(rootRecordCategory.getCreatedByUser().getId(), getAdminUser().getUsername()); + + // Verify the returned root record category properties + assertNotNull(rootRecordCategory.getProperties().getIdentifier()); + } + + @Test + public void listChildrenUserPermission() throws Exception + { + // Create RM Site if doesn't exist + createRMSiteIfNotExists(); + + // Create a random user + UserModel managerUser = getDataUser().createRandomTestUser("managerUser"); + + // Add child folders + ArrayList children = new ArrayList(); + for (int i = 0; i < NUMBER_OF_CHILDREN/2; i++) + { + String categoryName = "Category name " + getRandomAlphanumeric(); + String categoryTitle = "Category title " + getRandomAlphanumeric(); + // Create a record folder + RecordCategory recordCategory = createRootCategory(categoryName, categoryTitle); + assertNotNull(recordCategory.getId()); + children.add(recordCategory); + } + + getRestAPIFactory().getRMUserAPI().assignRoleToUser(managerUser.getUsername(), ROLE_RM_MANAGER); + // Get record category children from API + getRestAPIFactory().getFilePlansAPI(managerUser).getRootRecordCategories(FILE_PLAN_ALIAS) + .assertThat().entriesListIsEmpty().assertThat().paginationExist(); + + ArrayList childrenManager = new ArrayList(); + for (int i = 0; i < NUMBER_OF_CHILDREN / 2; i++) + { + String categoryName = "Category for manager " + getRandomAlphanumeric(); + String categoryTitle = "Category for manager " + getRandomAlphanumeric(); + // Create a record folder + RecordCategory recordCategory = createRootCategory(categoryName, categoryTitle); + assertNotNull(recordCategory.getId()); + getRestAPIFactory().getRMUserAPI().addUserPermission(recordCategory.getId(), managerUser, PERMISSION_FILING); + childrenManager.add(recordCategory); + } + // Get record category children from API + RecordCategoryCollection recordCategoryChildren = getRestAPIFactory().getFilePlansAPI(managerUser).getRootRecordCategories(FILE_PLAN_ALIAS); + + //Check children against created list + recordCategoryChildren.getEntries().forEach(c -> + { + RecordCategory recordCategoryChild = c.getEntry(); + String recordCategoryChildId = recordCategoryChild.getId(); + assertNotNull(recordCategoryChildId); + logger.info("Checking child " + recordCategoryChildId); + + try + { + // Find this child in created children list + assertTrue(childrenManager.stream() + .anyMatch(child -> child.getId().equals(recordCategoryChildId)) + ); + assertFalse(children.stream() + .anyMatch(child -> child.getId().equals(recordCategoryChildId)) + + ); + } catch (NoSuchElementException e) + { + fail("No child element for " + recordCategoryChildId); + } + } + ); + } + + +} diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/recordcategories/RecordCategoryTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/recordcategories/RecordCategoryTests.java new file mode 100644 index 0000000000..9d1dfa9a90 --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/recordcategories/RecordCategoryTests.java @@ -0,0 +1,719 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2017 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.rest.rm.community.recordcategories; + +import static java.time.LocalDateTime.now; + +import static org.alfresco.rest.rm.community.base.TestData.RECORD_CATEGORY_NAME; +import static org.alfresco.rest.rm.community.base.TestData.RECORD_FOLDER_NAME; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PATH; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE; +import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.TITLE_PREFIX; +import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; +import static org.springframework.http.HttpStatus.BAD_REQUEST; +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.assertTrue; +import static org.testng.Assert.fail; + +import java.util.ArrayList; +import java.util.List; +import java.util.NoSuchElementException; + +import org.alfresco.rest.rm.community.base.BaseRMRestTest; +import org.alfresco.rest.rm.community.base.TestData; +import org.alfresco.rest.rm.community.model.fileplan.FilePlan; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChildCollection; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChildProperties; +import org.alfresco.rest.rm.community.model.recordfolder.RecordFolder; +import org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI; +import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI; +import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI; +import org.alfresco.utility.report.Bug; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * Record category related API tests + * + * @author Kristijan Conkas + * @author Tuna Aksoy + * @since 2.6 + */ +public class RecordCategoryTests extends BaseRMRestTest +{ + /** Number of children (for children creation test) */ + private static final int NUMBER_OF_CHILDREN = 10; + private static final int NUMBER_OF_FOLDERS = 5; + + /** + * Invalid containers that cannot be deleted with record category end-point + */ + @DataProvider (name = "invalidContainersToDelete") + public Object[][] getNodesToDelete() throws Exception + { + return new String[][] { + { FILE_PLAN_ALIAS }, + { UNFILED_RECORDS_CONTAINER_ALIAS }, + { TRANSFERS_ALIAS }, + // an arbitrary record category + { createCategoryFolderInFilePlan(getAdminUser()).getId() }, + // an arbitrary unfiled records folder + { createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Folder " + getRandomAlphanumeric(), UNFILED_RECORD_FOLDER_TYPE).getId() } + }; + } + + /** + *
+     * 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 root category" + ) + public void renameCategory() throws Exception + { + // Create record category first + String categoryName = "Category name " + getRandomAlphanumeric(); + String categoryTitle = "Category title " + getRandomAlphanumeric(); + + // Create the root record category + RecordCategory rootRecordCategory = createRootCategory(categoryName, categoryTitle); + + String newCategoryName = "Rename " + categoryName; + + // Build the properties which will be updated + RecordCategory recordCategoryUpdated = RecordCategory.builder().name(newCategoryName).build(); + + // Update the record category + RecordCategory renamedRecordCategory = getRestAPIFactory().getRecordCategoryAPI().updateRecordCategory(recordCategoryUpdated, rootRecordCategory.getId()); + + // Verify the status code + assertStatusCode(OK); + + // Verify the returned file plan component + assertEquals(renamedRecordCategory.getName(), newCategoryName); + + // Get actual FILE_PLAN_ALIAS id + FilePlan filePlan = getRestAPIFactory().getFilePlansAPI().getFilePlan(FILE_PLAN_ALIAS); + + // verify renamed component still has this parent + assertEquals(renamedRecordCategory.getParentId(), filePlan.getId()); + } + + /** + *
+     * Given that a record category exists
+     * When I ask the API to delete the record category
+     * Then the record category and all its contents are deleted
+     * 
+ */ + @Test + ( + description = "Delete category" + ) + public void deleteCategory() throws Exception + { + // Create record category first + String categoryName = "Category name " + getRandomAlphanumeric(); + String categoryTitle = "Category title " + getRandomAlphanumeric(); + + // Create the root record category + RecordCategory rootRecordCategory = createRootCategory(categoryName, categoryTitle); + + int totalEntries= getRestAPIFactory().getFilePlansAPI().getRootRecordCategories(FILE_PLAN_ALIAS).getPagination().getTotalItems(); + // Delete the record category + RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI(); + String recordCategoryId = rootRecordCategory.getId(); + recordCategoryAPI.deleteRecordCategory(recordCategoryId); + + // Verify the status code + assertStatusCode(NO_CONTENT); + + // Deleted component should no longer be retrievable + recordCategoryAPI.getRecordCategory(recordCategoryId); + assertStatusCode(NOT_FOUND); + //check the number of entries after delete + int totalEntriesAfterDelete = getRestAPIFactory().getFilePlansAPI().getRootRecordCategories(FILE_PLAN_ALIAS).getPagination().getTotalItems(); + assertEquals(totalEntriesAfterDelete,(totalEntries-1)); + } + + /** + *
+     * Given that  nodes that are not record category
+     * When I ask  to delete the nodes  with the delete request from the record-categories endpoint
+     * Then the request fails
+     * 
+ */ + @Test + ( + description = "Delete invalid nodes with delete category endpoint", + dataProvider = "invalidContainersToDelete" + ) + public void deleteInvalidNodes(String nodeId) throws Exception + { + + // Delete the record category + RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI(); + recordCategoryAPI.deleteRecordCategory(nodeId); + + // Verify the status code + assertStatusCode(BAD_REQUEST); + + } + + /** + *
+     * 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 + RecordCategory rootCategory = createRootCategory(getRandomAlphanumeric()); + assertNotNull(rootCategory.getId()); + + // Create sub-category as a child of rootCategory + RecordCategoryChild recordCategory = createRecordCategoryChild(rootCategory.getId(), RECORD_CATEGORY_NAME, RECORD_CATEGORY_TYPE); + + // Child category created? + assertNotNull(recordCategory.getId()); + + // Verify child category + assertEquals(recordCategory.getParentId(), rootCategory.getId()); + assertTrue(recordCategory.getIsRecordCategory()); + assertFalse(recordCategory.getIsRecordFolder()); + assertEquals(recordCategory.getNodeType(), RECORD_CATEGORY_TYPE); + + + //get the sub-category + RecordCategory subCategory = getRestAPIFactory().getRecordCategoryAPI().getRecordCategory(recordCategory.getId(),"include=isRecordCategory,isRecordFolder"); + // Verify child category + assertEquals(subCategory.getParentId(), rootCategory.getId()); + assertEquals(subCategory.getNodeType(), RECORD_CATEGORY_TYPE); + assertFalse(subCategory.getAspectNames().isEmpty()); + assertNotNull(subCategory.getProperties().getIdentifier()); + } + + /** + *
+     * Given that a record category exists
+     * When I use the API to create children of type record folder
+     * Then  a record folder it is created within the record category
+     * 
+ *
+     * Given that a record category exists
+     * When I use the API to create children of type folder (cm:folder type)
+     * Then the folder is converted to rma:recordFolder within the record category
+     * (see RM-4572 comments)
+     * 
+ */ + @Test + ( + description = "Create a record folder into a record category.", + dataProviderClass = TestData.class, + dataProvider = "folderTypes" + ) + @Bug (id = "RM-4572") + public void createFolderTest(String folderType) throws Exception + { + // Authenticate with admin user + RecordCategory rootRecordCategory = createRootCategory(RECORD_CATEGORY_NAME + getRandomAlphanumeric()); + + // Create the record folder + RecordCategoryChild recordFolder = createRecordCategoryChild(rootRecordCategory.getId(), RECORD_FOLDER_NAME, folderType); + + // Assert status code + assertStatusCode(CREATED); + + // Check record folder has been created within the record category + assertEquals(rootRecordCategory.getId(), recordFolder.getParentId()); + + // Verify the returned values for the record folder + assertFalse(recordFolder.getIsRecordCategory()); + assertTrue(recordFolder.getIsRecordFolder()); + assertEquals(recordFolder.getName(), RECORD_FOLDER_NAME); + assertEquals(recordFolder.getNodeType(), RECORD_FOLDER_TYPE); + assertEquals(recordFolder.getCreatedByUser().getId(), getAdminUser().getUsername()); + + // Verify the returned record folder properties + RecordCategoryChildProperties folderProperties = recordFolder.getProperties(); + assertEquals(folderProperties.getTitle(), TITLE_PREFIX + RECORD_FOLDER_NAME); + assertNotNull(folderProperties.getIdentifier()); + } + /** + *
+     * 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 = "Get children of a record category" + ) + public void getRecordCategoryChildren() throws Exception + { + // Create root level category + RecordCategory rootRecordCategory = createRootCategory(getRandomAlphanumeric()); + assertNotNull(rootRecordCategory.getId()); + + // Add record category children + List children = new ArrayList(); + for (int i=0; i < NUMBER_OF_CHILDREN; i++) + { + // Create a record category child + RecordCategoryChild child = createRecordCategoryChild(rootRecordCategory.getId(), + getRandomAlphanumeric(), + // half of the children should be sub-categories, the other sub-folders + (i <= NUMBER_OF_CHILDREN / 2) ? RECORD_CATEGORY_TYPE : RECORD_FOLDER_TYPE); + assertNotNull(child.getId()); + children.add(child); + } + + // Get children from API + RecordCategoryChildCollection recordCategoryChildren = getRestAPIFactory().getRecordCategoryAPI().getRecordCategoryChildren(rootRecordCategory.getId(),"include=isRecordCategory,isRecordFolder"); + + // Check status code + assertStatusCode(OK); + logger.info("Parent: " + rootRecordCategory.getId()); + + // Check listed children against created list + recordCategoryChildren.getEntries().forEach(c -> + { + RecordCategoryChild recordCategoryChild = c.getEntry(); + String recordCategoryChildId = recordCategoryChild.getId(); + + assertNotNull(recordCategoryChildId); + logger.info("Checking child " + recordCategoryChildId); + + try + { + // Find this child in created children list + RecordCategoryChild createdComponent = children.stream() + .filter(child -> child.getId().equals(recordCategoryChildId)) + .findFirst() + .get(); + + // Created by + assertEquals(recordCategoryChild.getCreatedByUser().getId(), getAdminUser().getUsername()); + + // Is parent id set correctly? + assertEquals(recordCategoryChild.getParentId(), rootRecordCategory.getId()); + + // Boolean properties related to node type + // Only RECORD_CATEGORY_TYPE and RECORD_FOLDER_TYPE have been created + if (recordCategoryChild.getNodeType().equals(RECORD_CATEGORY_TYPE)) + { + assertTrue(recordCategoryChild.getIsRecordCategory()); + assertFalse(recordCategoryChild.getIsRecordFolder()); + } + else + { + assertTrue(recordCategoryChild.getIsRecordFolder()); + assertFalse(recordCategoryChild.getIsRecordCategory()); + } + + // Does returned object have the same contents as the created one? + assertEquals(createdComponent.getName(), recordCategoryChild.getName()); + assertEquals(createdComponent.getNodeType(), recordCategoryChild.getNodeType()); + + // verify the record categories children identifier + assertNotNull(createdComponent.getProperties().getIdentifier()); + } + catch (NoSuchElementException e) + { + fail("No child element for " + recordCategoryChildId); + } + }); + } + + /** + *
+     * Given that a record category exists
+     * When I ask to create an object type which is not a record category or a record folder as a child
+     * Then the children are not created and the 422 response code is returned
+     * 
+ */ + @Test + ( + description = "Create node types not allowed inside a category", + dataProviderClass = TestData.class, + dataProvider = "childrenNotAllowedForCategory" + ) + @Bug (id="RM-4367, RM-4572") + public void createTypesNotAllowedInCategory(String nodeType) throws Exception + { + String componentName = "Component" + getRandomAlphanumeric(); + + // Create the category + RecordCategory rootRecordCategory = createRootCategory(componentName); + + // Create the invalid node type + createRecordCategoryChild(rootRecordCategory.getId(), componentName, nodeType); + assertStatusCode(UNPROCESSABLE_ENTITY); + } + + /** + *
+     * Given that a record category exists
+     * And contains several record folders
+     * When I use the API to get the record category children for an existing record category
+     * Then I am provided with a list of the contained record category children and their details
+     * 
+ */ + @Test + ( + description = "Get children of a record category" + ) + public void getFolders() throws Exception + { + // Authenticate with admin user + RecordCategory rootRecordCategory = createRootCategory(RECORD_CATEGORY_NAME + getRandomAlphanumeric()); + + // Add child folders + ArrayList children = new ArrayList(); + for (int i = 0; i < NUMBER_OF_FOLDERS; i++) + { + // Create a record folder + RecordCategoryChild recordCategoryChild = createRecordFolder(rootRecordCategory.getId(), getRandomAlphanumeric()); + assertNotNull(recordCategoryChild.getId()); + children.add(recordCategoryChild); + } + + // Get record category children from API + RecordCategoryChildCollection recordCategoryChildren = getRestAPIFactory().getRecordCategoryAPI().getRecordCategoryChildren(rootRecordCategory.getId(), "include=isRecordCategory,isRecordFolder"); + + // Check status code + assertStatusCode(OK); + + // Check children against created list + recordCategoryChildren.getEntries().forEach(c -> + { + RecordCategoryChild recordCategoryChild = c.getEntry(); + String recordCategoryChildId = recordCategoryChild.getId(); + assertNotNull(recordCategoryChildId); + logger.info("Checking child " + recordCategoryChildId); + + try + { + // Find this child in created children list + RecordCategoryChild createdComponent = children.stream() + .filter(child -> child.getId().equals(recordCategoryChildId)) + .findFirst() + .get(); + + // Created by + assertEquals(recordCategoryChild.getCreatedByUser().getId(), getAdminUser().getUsername()); + + // Is parent id set correctly + assertEquals(recordCategoryChild.getParentId(), rootRecordCategory.getId()); + + // Boolean properties related to node type + assertTrue(recordCategoryChild.getIsRecordFolder()); + assertFalse(recordCategoryChild.getIsRecordCategory()); + + assertEquals(createdComponent.getName(), recordCategoryChild.getName()); + assertEquals(createdComponent.getNodeType(), recordCategoryChild.getNodeType()); + + } catch (NoSuchElementException e) + { + fail("No child element for " + recordCategoryChildId); + } + } + ); + + } + + /** + *
+     * Given that I want to create a record folder
+     * When I use the API with the relativePath
+     * Then the categories specified in the relativePath that don't exist are created
+     * 
+ */ + @Test + ( + description = "Create a folder using record-categories endpoint, based on the relativePath. " + + "Containers in the relativePath that do not exist are created before the node is created" + ) + public void createRecordFolderWithRelativePath() throws Exception + { + // The record category to be created + RecordCategory recordCategoryModel = RecordCategory.builder() + .name(RECORD_CATEGORY_NAME) + .nodeType(RECORD_CATEGORY_TYPE) + .build(); + FilePlanAPI filePlansAPI = getRestAPIFactory().getFilePlansAPI(); + RecordCategory createRootRecordCategory = filePlansAPI.createRootRecordCategory(recordCategoryModel, FILE_PLAN_ALIAS, "include=" + PATH); + // Check the API response code + assertStatusCode(CREATED); + String recordCategoryId = createRootRecordCategory.getId(); + + // relativePath specify the container structure to create relative to the record folder to be created + String relativePath = now().getYear() + "/" + now().getMonth() + "/" + now().getDayOfMonth(); + + // The record folder to be created + RecordCategoryChild recordFolderModel = RecordCategoryChild.builder() + .name(RECORD_FOLDER_NAME) + .nodeType(RECORD_FOLDER_TYPE) + .relativePath(relativePath) + .build(); + + // Create the record folder + RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI(); + RecordCategoryChild recordCategoryChild = recordCategoryAPI.createRecordCategoryChild(recordFolderModel, recordCategoryId, "include=" + PATH); + + // Check the API response code + assertStatusCode(CREATED); + + // Verify the returned details for the record folder + assertFalse(recordCategoryChild.getIsRecordCategory()); + assertTrue(recordCategoryChild.getIsRecordFolder()); + + // Check the path return contains the relativePath + assertTrue(recordCategoryChild.getPath().getName().contains(relativePath)); + + // Check the parent is a category + assertNotNull(recordCategoryAPI.getRecordCategory(recordCategoryChild.getParentId()).getId()); + + // Check the created folder from the server + RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI(); + RecordFolder recordFolder = recordFolderAPI.getRecordFolder(recordCategoryChild.getId(), "include=" + PATH); + + // Check the API response code + assertStatusCode(OK); + + // Verify the returned details for the record folder + assertTrue(RECORD_FOLDER_TYPE.equals(recordFolder.getNodeType())); + + // Check the path return contains the relativePath + assertTrue(recordFolder.getPath().getName().contains(relativePath)); + + // New relative path only a part of containers need to be created before the record folder + String newRelativePath = now().getYear() + "/" + now().getMonth() + "/" + (now().getDayOfMonth() + 1); + + // The record folder to be created + RecordCategoryChild newRecordFolderModel = RecordCategoryChild.builder() + .name(RECORD_FOLDER_NAME) + .nodeType(RECORD_FOLDER_TYPE) + .relativePath(newRelativePath) + .build(); + + // Create the record folder + RecordCategoryChild newRecordCategoryChild = recordCategoryAPI.createRecordCategoryChild(newRecordFolderModel, recordCategoryId, "include=" + PATH); + + // Check the API response code + assertStatusCode(CREATED); + + // Verify the returned properties for the file plan component - record folder + assertFalse(newRecordCategoryChild.getIsRecordCategory()); + assertTrue(newRecordCategoryChild.getIsRecordFolder()); + + // Check the path return contains the newRelativePath + assertTrue(newRecordCategoryChild.getPath().getName().contains(newRelativePath)); + + // Check the parent is a category + assertNotNull(recordCategoryAPI.getRecordCategory(newRecordCategoryChild.getParentId()).getId()); + + // Check the folder created on the server + RecordFolder newRecordFolder = recordFolderAPI.getRecordFolder(newRecordCategoryChild.getId(), "include=" + PATH); + + // Check the API response code + assertStatusCode(OK); + + // Verify the returned details for the record folder + assertTrue(RECORD_FOLDER_TYPE.equals(recordFolder.getNodeType())); + + // Check the path return contains the newRelativePath + assertTrue(newRecordFolder.getPath().getName().contains(newRelativePath)); + } + + + /** + *
+     * Given that I want to create a record sub-category
+     * When I use the API with the relativePath
+     * Then the categories specified in the relativePath that don't exist are created
+     * 
+ */ + @Test + ( + description = "Create a sub-category using record-categories endpoint, based on the relativePath. " + + "Containers in the relativePath that do not exist are created before the node is created" + ) + public void createRecordSubCategoryWithRelativePath() throws Exception + { + // The record category to be created + RecordCategory recordCategoryModel = RecordCategory.builder() + .name(RECORD_CATEGORY_NAME+getRandomAlphanumeric()) + .nodeType(RECORD_CATEGORY_TYPE) + .build(); + FilePlanAPI filePlansAPI = getRestAPIFactory().getFilePlansAPI(); + RecordCategory createRootRecordCategory = filePlansAPI.createRootRecordCategory(recordCategoryModel, FILE_PLAN_ALIAS, "include=" + PATH); + // Check the API response code + assertStatusCode(CREATED); + String recordCategoryId = createRootRecordCategory.getId(); + + // relativePath specify the container structure to create relative to the record folder to be created + String relativePath = now().getYear() + "/" + now().getMonth() + "/" + now().getDayOfMonth()+ "/"+getRandomAlphanumeric(); + + // The record folder to be created + RecordCategoryChild recordFolderModel = RecordCategoryChild.builder() + .name(RECORD_CATEGORY_NAME) + .nodeType(RECORD_CATEGORY_TYPE) + .relativePath(relativePath) + .build(); + + // Create the record folder + RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI(); + RecordCategoryChild recordCategoryChild = recordCategoryAPI.createRecordCategoryChild(recordFolderModel, recordCategoryId, "include=" + PATH); + + // Check the API response code + assertStatusCode(CREATED); + + // Verify the returned details for the record sub-category + assertTrue(recordCategoryChild.getIsRecordCategory()); + assertFalse(recordCategoryChild.getIsRecordFolder()); + + // Check the path return contains the relativePath + assertTrue(recordCategoryChild.getPath().getName().contains(relativePath)); + + // Check the parent is a category + assertNotNull(recordCategoryAPI.getRecordCategory(recordCategoryChild.getParentId()).getId()); + + // Check the created folder from the server + RecordCategory recordSubCategory = recordCategoryAPI.getRecordCategory(recordCategoryChild.getId(), "include=" + PATH); + + // Check the API response code + assertStatusCode(OK); + + // Verify the returned details for the record folder + assertTrue(RECORD_CATEGORY_TYPE.equals(recordSubCategory.getNodeType())); + + // Check the path return contains the relativePath + assertTrue(recordSubCategory.getPath().getName().contains(relativePath)); + + // New relative path only a part of containers need to be created before the record folder + String newRelativePath = now().getYear() + "/" + now().getMonth() + "/" + (now().getDayOfMonth() + 1) +"/"+getRandomAlphanumeric(); + + // The record folder to be created + RecordCategoryChild newRecordFolderModel = RecordCategoryChild.builder() + .name(RECORD_CATEGORY_NAME) + .nodeType(RECORD_CATEGORY_TYPE) + .relativePath(newRelativePath) + .build(); + + // Create the record folder + RecordCategoryChild newRecordCategoryChild = recordCategoryAPI.createRecordCategoryChild(newRecordFolderModel, recordCategoryId, "include=" + PATH); + + // Check the API response code + assertStatusCode(CREATED); + + // Verify the returned properties for the file plan component - record folder + assertTrue(newRecordCategoryChild.getIsRecordCategory()); + assertFalse(newRecordCategoryChild.getIsRecordFolder()); + + // Check the path return contains the newRelativePath + assertTrue(newRecordCategoryChild.getPath().getName().contains(newRelativePath)); + + // Check the parent is a category + assertNotNull(recordCategoryAPI.getRecordCategory(newRecordCategoryChild.getParentId()).getId()); + + // Check the folder created on the server + RecordCategory newRecordFolder = recordCategoryAPI.getRecordCategory(newRecordCategoryChild.getId(), "include=" + PATH); + + // Check the API response code + assertStatusCode(OK); + + // Verify the returned details for the record folder + assertTrue(RECORD_CATEGORY_TYPE.equals(recordSubCategory.getNodeType())); + + // Check the path return contains the newRelativePath + assertTrue(newRecordFolder.getPath().getName().contains(newRelativePath)); + } + + /** + *
+     * Given that RM site is created
+     * When I use the API to create a new record folder into transfers/holds/unfiled containers
+     * Then the operation fails
+     * 
+ */ + @Test + ( + description = "Create a record folder into transfers/unfiled/file plan container", + dataProviderClass = TestData.class, + dataProvider = "getContainers" + ) + @Bug (id = "RM-4327") + public void createRecordFolderIntoSpecialContainers(String containerAlias) throws Exception + { + String containerId; + if (FILE_PLAN_ALIAS.equalsIgnoreCase(containerAlias)) + { + containerId = getRestAPIFactory().getFilePlansAPI().getFilePlan(containerAlias).getId(); + } else if (TRANSFERS_ALIAS.equalsIgnoreCase(containerAlias)) + { + containerId = getRestAPIFactory().getTransferContainerAPI().getTransferContainer(containerAlias).getId(); + } else + { + //is unfiled container + containerId = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(containerAlias).getId(); + ; + } + + // Create a record folder + createRecordFolder(containerId, RECORD_FOLDER_NAME); + + // Check the API Response code + assertStatusCode(BAD_REQUEST); + } +} diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/ElectronicRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/recordfolders/ElectronicRecordTests.java similarity index 99% rename from rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/ElectronicRecordTests.java rename to rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/recordfolders/ElectronicRecordTests.java index b4f0dacb94..f226c946b2 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/ElectronicRecordTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/recordfolders/ElectronicRecordTests.java @@ -24,7 +24,7 @@ * along with Alfresco. If not, see . * #L% */ -package org.alfresco.rest.rm.community.fileplancomponents; +package org.alfresco.rest.rm.community.recordfolders; import static org.alfresco.rest.rm.community.base.TestData.ELECTRONIC_RECORD_NAME; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; @@ -72,7 +72,7 @@ public class ElectronicRecordTests extends BaseRMRestTest /** Invalid parent containers where electronic records can't be created */ @DataProvider(name = "invalidParentContainers") - public String[][] invalidParentContainers() throws Exception + public Object[][] invalidParentContainers() throws Exception { return new String[][] { @@ -326,8 +326,6 @@ public class ElectronicRecordTests extends BaseRMRestTest assertTrue(electronicRecord.getName().contains(electronicRecord.getProperties().getIdentifier())); } - @Test - @Bug (id = "RM-4568") /** *
      * Given that I want to create an electronic record in one unfiled record folder
@@ -335,6 +333,8 @@ public class ElectronicRecordTests extends BaseRMRestTest
      * Then the containers in the relativePath that don't exist are created before creating the electronic record
      * 
      */
+    @Test
+    @Bug (id = "RM-4568")
     public void createElectronicRecordWithRelativePath() throws Exception
     {
         // The containers specified on the relativePath parameter don't exist on server
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/recordfolders/NonElectronicRecordTests.java
similarity index 99%
rename from rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/NonElectronicRecordTests.java
rename to rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/recordfolders/NonElectronicRecordTests.java
index fb7c8afd4c..0c022e09b3 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/recordfolders/NonElectronicRecordTests.java
@@ -24,7 +24,7 @@
  * along with Alfresco. If not, see .
  * #L%
  */
-package org.alfresco.rest.rm.community.fileplancomponents;
+package org.alfresco.rest.rm.community.recordfolders;
 
 import static java.lang.Integer.MAX_VALUE;
 import static java.util.Arrays.asList;
diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/recordfolders/RecordFolderTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/recordfolders/RecordFolderTests.java
new file mode 100644
index 0000000000..2843995a80
--- /dev/null
+++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/recordfolders/RecordFolderTests.java
@@ -0,0 +1,492 @@
+/*
+ * #%L
+ * Alfresco Records Management Module
+ * %%
+ * Copyright (C) 2005 - 2017 Alfresco Software Limited
+ * %%
+ * This file is part of the Alfresco software.
+ * -
+ * If the software was purchased under a paid Alfresco license, the terms of
+ * the paid license agreement will prevail.  Otherwise, the software is
+ * provided under the following open source license terms:
+ * -
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * -
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ * -
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see .
+ * #L%
+ */
+package org.alfresco.rest.rm.community.recordfolders;
+
+import static org.alfresco.rest.rm.community.base.TestData.RECORD_CATEGORY_NAME;
+import static org.alfresco.rest.rm.community.base.TestData.RECORD_FOLDER_NAME;
+import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
+import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS;
+import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
+import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.IS_CLOSED;
+import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE;
+import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.FILE_PLAN_TYPE;
+import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE;
+import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE;
+import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
+import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.TRANSFER_CONTAINER_TYPE;
+import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.TRANSFER_TYPE;
+import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE;
+import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE;
+import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.TITLE_PREFIX;
+import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createTempFile;
+import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
+import static org.springframework.http.HttpStatus.BAD_REQUEST;
+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.assertTrue;
+import static org.testng.Assert.fail;
+
+
+import java.util.ArrayList;
+import java.util.NoSuchElementException;
+
+import org.alfresco.rest.rm.community.base.BaseRMRestTest;
+import org.alfresco.rest.rm.community.model.common.ReviewPeriod;
+import org.alfresco.rest.rm.community.model.record.Record;
+import org.alfresco.rest.rm.community.model.record.RecordProperties;
+import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory;
+import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
+import org.alfresco.rest.rm.community.model.recordfolder.RecordFolder;
+import org.alfresco.rest.rm.community.model.recordfolder.RecordFolderCollection;
+import org.alfresco.rest.rm.community.model.recordfolder.RecordFolderProperties;
+import org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI;
+import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI;
+import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
+import org.alfresco.utility.report.Bug;
+import org.testng.AssertJUnit;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/**
+ * This class contains the tests for the Record Folder CRUD API
+ *
+ * @author Rodica Sutu
+ * @since 2.6
+ */
+public class RecordFolderTests extends BaseRMRestTest
+{
+    public static final String ELECTRONIC_RECORD_NAME = "Record electronic" + getRandomAlphanumeric();
+    public static final String NONELECTRONIC_RECORD_NAME = "Record nonelectronic" + getRandomAlphanumeric();
+
+
+    /**
+     * Data Provider with:
+     * with the object types not allowed as children for a record folder
+     *
+     * @return node type to be created
+     */
+    @DataProvider
+    public static Object[][] childrenNotAllowedForFolder()
+    {
+        return new String[][] {
+                { FILE_PLAN_TYPE },
+                { TRANSFER_CONTAINER_TYPE },
+                { UNFILED_CONTAINER_TYPE },
+                { UNFILED_RECORD_FOLDER_TYPE },
+                { TRANSFER_TYPE },
+                { RECORD_CATEGORY_TYPE }
+        };
+    }
+
+    /**
+     * Invalid  containers that cannot be updated/deleted with record folder endpoint
+     */
+    @DataProvider
+    public Object[][] getInvalidNodesForRecordFolders() throws Exception
+    {
+        return new String[][] {
+                { getRestAPIFactory().getFilePlansAPI().getFilePlan(FILE_PLAN_ALIAS).getId()},
+                { getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS).getId() },
+                { getRestAPIFactory().getTransferContainerAPI().getTransferContainer(TRANSFERS_ALIAS).getId() },
+                // an arbitrary record category
+                { createRootCategory(RECORD_CATEGORY_NAME+getRandomAlphanumeric()).getId()},
+                // an arbitrary unfiled records folder
+                { createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Folder " + getRandomAlphanumeric(), UNFILED_RECORD_FOLDER_TYPE).getId() },
+                { createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Record " + getRandomAlphanumeric(), CONTENT_TYPE).getId()}
+        };
+    }
+
+
+    /**
+     * 
+     * Given that RM site is created
+     * When I use the API to create a children inside a record folder with wron  types
+     * Then the operation fails
+     * 
+ */ + @Test + ( + description = "Create invalid types as children for a record folder", + dataProvider = "childrenNotAllowedForFolder" + ) + + public void createRecordFolderIntoSpecialContainers(String nodeType) throws Exception + { + //create a record folder + RecordCategoryChild folder = createCategoryFolderInFilePlan(); + Record record = Record.builder() + .name(ELECTRONIC_RECORD_NAME) + .nodeType(nodeType) + .build(); + //create invalid child typefor the record folder + getRestAPIFactory().getRecordFolderAPI().createRecord(record,folder.getId()); + // Check the API Response code + assertStatusCode(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 of a record folder" + ) + public void checkRecordFolderDetails() throws Exception + { + // Create a category + RecordCategory rootRecordCategory = createRootCategory(RECORD_CATEGORY_NAME + getRandomAlphanumeric()); + + // Create a folder + RecordCategoryChild recordCategoryChild = createRecordFolder(rootRecordCategory.getId(), RECORD_FOLDER_NAME); + + // Get the folder including extra information + RecordFolder recordFolder = getRestAPIFactory().getRecordFolderAPI().getRecordFolder(recordCategoryChild.getId(), "include=" + IS_CLOSED); + + // Verify the returned record folder details + assertEquals(recordFolder.getNodeType(), RECORD_FOLDER_TYPE); + assertTrue(RECORD_FOLDER_TYPE.equals(recordFolder.getNodeType())); + assertEquals(recordFolder.getName(), RECORD_FOLDER_NAME); + assertEquals(recordFolder.getCreatedByUser().getId(), getAdminUser().getUsername()); + assertEquals(recordFolder.getModifiedByUser().getId(), getAdminUser().getUsername()); + assertEquals(recordFolder.getProperties().getTitle(), TITLE_PREFIX + RECORD_FOLDER_NAME); + assertNotNull(recordFolder.getProperties().getIdentifier(),"The record folder doesn't have a identifier"); + assertFalse(recordFolder.getProperties().getVitalRecordIndicator(), "The record folder has the vital record identifier"); + assertFalse(recordFolder.getProperties().getIsClosed(), "The record folder is closed"); + } + + /** + *
+     * 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 of a record folder" + ) + public void updateRecordFolderDetails() throws Exception + { + // Create a record category + RecordCategory rootRecordCategory = createRootCategory(RECORD_CATEGORY_NAME + getRandomAlphanumeric()); + + // Create a record folder + RecordCategoryChild recordCategoryChild = createRecordFolder(rootRecordCategory.getId(), RECORD_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(); + String location = "Location "+ getRandomAlphanumeric(); + + // Create the record folder properties to update + RecordFolder recordFolder = RecordFolder.builder() + .name(folderName) + .properties(RecordFolderProperties.builder() + .title(folderTitle) + .description(folderDescription) + .vitalRecordIndicator(true) + .reviewPeriod(new ReviewPeriod("month","1")) + .location(location) + .build()) + .build(); + + // Update the record folder + RecordFolder updatedRecordFolder = getRestAPIFactory().getRecordFolderAPI().updateRecordFolder(recordFolder, recordCategoryChild.getId()); + + // Check the Response Status Code + assertStatusCode(OK); + + // Verify the returned details for the record folder + AssertJUnit.assertEquals(updatedRecordFolder.getName(), folderName); + RecordFolderProperties recordFolderProperties = updatedRecordFolder.getProperties(); + AssertJUnit.assertEquals(recordFolderProperties.getDescription(), folderDescription); + AssertJUnit.assertEquals(recordFolderProperties.getTitle(), folderTitle); + assertTrue(recordFolderProperties.getVitalRecordIndicator()); + AssertJUnit.assertEquals(recordFolderProperties.getLocation(), location); + assertNotNull(recordFolderProperties.getReviewPeriod().getPeriodType()); + assertNotNull(recordFolderProperties.getReviewPeriod().getExpression()); + } + + /** + *
+     * Given other nodes type than record folders exists
+     * When I use the API to update its details
+     * Then the request fails
+     * 
+ */ + @Test + ( + description = "Update the details for other nodes than record folder with the request used for record-folders ", + dataProvider = "getInvalidNodesForRecordFolders" + ) + public void updateOtherNodeTypesDetails(String nodeId) throws Exception + { + // Create record category first + String nodeDescription = "The folder description is updated" + getRandomAlphanumeric(); + String nodeName = "The folder name is updated" + getRandomAlphanumeric(); + String nodeTitle = "Update title " + getRandomAlphanumeric(); + + + // Create the record folder properties to update + RecordFolder recordFolder = RecordFolder.builder() + .name(nodeName) + .properties(RecordFolderProperties.builder() + .title(nodeTitle) + .description(nodeDescription) + .vitalRecordIndicator(true) + .reviewPeriod(new ReviewPeriod("month", "1")) + .build()) + .build(); + + // Update the record folder + getRestAPIFactory().getRecordFolderAPI().updateRecordFolder(recordFolder, nodeId); + + // Check the Response Status Code + assertStatusCode(BAD_REQUEST); + } + + /** + *
+     * Given other nodes type than record folders exists
+     * When I use the API from record-folders to delete the nodes
+     * Then the request fails
+     * 
+ */ + @Test + ( + description = "Delete invalid nodes type with the DELETE record folders request", + dataProvider = "getInvalidNodesForRecordFolders" + ) + public void deleteInvalidNodesRecordFolder(String nodeId) throws Exception + { + // Delete the nodes with record-folders end-point + RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI(); + recordFolderAPI.deleteRecordFolder(nodeId); + + // Check the response status code + assertStatusCode(BAD_REQUEST); + } + + /** + *
+     * Given that a record folder exists
+     * When I use the API to delete the record folder
+     * Then it is deleted according to the normal rules governing the deletion of record folders
+     * 
+ */ + @Test + ( + description = "Delete record folder" + ) + public void deleteRecordFolder() throws Exception + { + // Create the record category + RecordCategory rootRecordCategory = createRootCategory(RECORD_CATEGORY_NAME + getRandomAlphanumeric()); + + // Create the record folder + RecordCategoryChild recordFolder = createRecordFolder(rootRecordCategory.getId(), RECORD_FOLDER_NAME); + + // Delete the record folder + RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI(); + String recordFolderId = recordFolder.getId(); + recordFolderAPI.deleteRecordFolder(recordFolderId); + + // Check the response status code + assertStatusCode(NO_CONTENT); + + // Check the record folder is not found + recordFolderAPI.getRecordFolder(recordFolderId); + + // Check the response status code + assertStatusCode(NOT_FOUND); + } + + /** + * Given that a record folder exists + * When the record folder is closed + * Then a request can be made to reopen it + */ + @Test + ( + description = "A closed record folder can be reopened" + ) + @Bug(id="RM-4808") + public void openClosedRecordFolder() throws Exception + { + // Create a record folder + RecordCategoryChild recordFolder = createCategoryFolderInFilePlan(); + + // Assert that the record folder is not closed + assertFalse(recordFolder.getProperties().getIsClosed()); + + // Get the record folder API + RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI(); + + // Create a record folder model to close it + RecordFolder recordFolderModel = RecordFolder.builder() + .properties(RecordFolderProperties.builder() + .isClosed(true) + .build()) + .build(); + + // Make a request to close the record folder + RecordFolder updatedRecordFolder = recordFolderAPI.updateRecordFolder(recordFolderModel, recordFolder.getId()); + + //FIXME - remove this workaround after RM-4921 is fixed. + updatedRecordFolder = recordFolderAPI.getRecordFolder(updatedRecordFolder.getId()); + + // Verify that the record folder is closed now + assertTrue(updatedRecordFolder.getProperties().getIsClosed()); + + // Create a record folder model to reopen it + recordFolderModel = RecordFolder.builder() + .properties(RecordFolderProperties.builder() + .isClosed(false) + .build()) + .build(); + + // Make a request to reopen the record folder + updatedRecordFolder = recordFolderAPI.updateRecordFolder(recordFolderModel, recordFolder.getId()); + + //FIXME - remove this workaround after RM-4921 is fixed. + updatedRecordFolder = recordFolderAPI.getRecordFolder(updatedRecordFolder.getId()); + + // Verify that the record folder is open now + assertFalse(updatedRecordFolder.getProperties().getIsClosed()); + } + + /** + * Given a container that is a record folder + * When I try to list the records from the record folder + * Then I receive a list of all the records contained within the record folder + */ + @Test + public void listRecordsFromRecordFolder() throws Exception + { + final int NUMBER_OF_RECORDS = 5; + String containerId = createCategoryFolderInFilePlan().getId(); + RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI(); + // Create Electronic Records + ArrayList children = new ArrayList(); + for (int i = 0; i < NUMBER_OF_RECORDS; i++) + { + //build the electronic record + Record record = Record.builder() + .name(ELECTRONIC_RECORD_NAME + i) + .nodeType(CONTENT_TYPE) + .build(); + //create a child + Record child = recordFolderAPI.createRecord(record, containerId, createTempFile(ELECTRONIC_RECORD_NAME + i, ELECTRONIC_RECORD_NAME + i)); + + children.add(child); + } + //Create NonElectronicRecords + for (int i = 0; i < NUMBER_OF_RECORDS; i++) + { + Record nonelectronicRecord = Record.builder() + .properties(RecordProperties.builder() + .description("Description") + .title("Title") + .build()) + .name(NONELECTRONIC_RECORD_NAME + i) + .nodeType(NON_ELECTRONIC_RECORD_TYPE) + .build(); + //create records + Record child = recordFolderAPI.createRecord(nonelectronicRecord, containerId); + + children.add(child); + } + + // List children from API + RecordFolderCollection apiChildren = (RecordFolderCollection) recordFolderAPI.getRecordFolderChildren(containerId,"include=properties").assertThat().entriesListIsNotEmpty(); + + // Check status code + assertStatusCode(OK); + + + // Check listed children against created list + apiChildren.getEntries().forEach(c -> + { + Record record = c.getEntry(); + assertNotNull(record.getId()); + logger.info("Checking child " + record.getId()); + + try + { + // Find this child in created children list + Record createdComponent = children.stream() + .filter(child -> child.getId().equals(record.getId())) + .findFirst() + .get(); + + // Created by + assertEquals(record.getCreatedByUser().getId(), getAdminUser().getUsername()); + + // Is parent Id set correctly + assertEquals(record.getParentId(), containerId); + + //check the record name + assertFalse(record.getName().equals(createdComponent.getName()), + "Record Name"+ record.getName()+" doesn't contain the record identifier"); + assertTrue(createdComponent.getName().contains(createdComponent.getProperties().getIdentifier()), + "Record Name"+ createdComponent.getName()+" doesn't contain the record identifier in response when creating"); + assertEquals(createdComponent.getNodeType(), record.getNodeType()); + + } catch (NoSuchElementException e) + { + fail("No child element for " + record.getId()); + } + }); + } + + @AfterTest + @AfterClass (alwaysRun = true) + public void tearDown() throws Exception + { + FilePlanAPI filePlansAPI = getRestAPIFactory().getFilePlansAPI(); + RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI(); + + filePlansAPI.getRootRecordCategories(FILE_PLAN_ALIAS).getEntries().forEach(recordCategoryEntry -> + { + recordCategoryAPI.deleteRecordCategory(recordCategoryEntry.getEntry().getId()); + }); + } +} diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/DeleteRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/DeleteRecordTests.java similarity index 99% rename from rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/DeleteRecordTests.java rename to rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/DeleteRecordTests.java index 4980112bac..427b1b271e 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/DeleteRecordTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/DeleteRecordTests.java @@ -24,7 +24,7 @@ * along with Alfresco. If not, see . * #L% */ -package org.alfresco.rest.rm.community.fileplancomponents; +package org.alfresco.rest.rm.community.records; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE; @@ -262,4 +262,5 @@ public class DeleteRecordTests extends BaseRMRestTest recordsAPI.deleteRecord(recordId); assertStatusCode(NOT_FOUND); } + } diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/FileRecordsTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/FileRecordsTests.java similarity index 96% rename from rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/FileRecordsTests.java rename to rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/FileRecordsTests.java index 02e2686707..41a42b2bc8 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/FileRecordsTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/FileRecordsTests.java @@ -24,7 +24,7 @@ * along with Alfresco. If not, see . * #L% */ -package org.alfresco.rest.rm.community.fileplancomponents; +package org.alfresco.rest.rm.community.records; import static org.alfresco.rest.rm.community.base.TestData.ELECTRONIC_RECORD_NAME; import static org.alfresco.rest.rm.community.base.TestData.NONELECTRONIC_RECORD_NAME; @@ -43,17 +43,12 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.AssertJUnit.assertTrue; -import java.util.List; - import org.alfresco.rest.rm.community.base.BaseRMRestTest; import org.alfresco.rest.rm.community.model.record.Record; import org.alfresco.rest.rm.community.model.record.RecordBodyFile; import org.alfresco.rest.rm.community.model.record.RecordContent; -import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChildCollection; -import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChildEntry; import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild; import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildProperties; -import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI; import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI; import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI; import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI; @@ -89,7 +84,7 @@ public class FileRecordsTests extends BaseRMRestTest /** * Invalid containers where electronic and non-electronic records can be filed */ - @DataProvider (name = "invalidContainersForFile") + @DataProvider (name = "invalidContainersToFile") public String[][] getFolderContainers() throws Exception { return new String[][] { @@ -399,11 +394,11 @@ public class FileRecordsTests extends BaseRMRestTest c.getEntry().getParentId().equals(parentFolderId))); // check the record doesn't exist into unfiled record container - // TODO add a check after the issue will be fixed RM-4578 assertTrue(recordFolderAPI.getRecordFolderChildren(folderToLink) .getEntries().stream() - .anyMatch(c -> c.getEntry().getId().equals(recordFiled.getId()))); - + .anyMatch(c -> c.getEntry().getId().equals(recordFiled.getId()) && + c.getEntry().getParentId().equals(parentFolderId) && + !c.getEntry().getParentId().equals(folderToLink))); // check the record is added into the record folder assertTrue(recordFolderAPI.getRecordFolderChildren(parentFolderId) .getEntries() @@ -412,21 +407,22 @@ public class FileRecordsTests extends BaseRMRestTest c.getEntry().getParentId().equals(parentFolderId))); // check the record doesn't exist into unfiled record container - // TODO add a check after the issue will be fixed RM-4578 assertTrue(recordFolderAPI.getRecordFolderChildren(folderToLink) .getEntries().stream() - .anyMatch(c -> c.getEntry().getId().equals(nonElectronicFiled.getId()))); + .anyMatch(c -> c.getEntry().getId().equals(nonElectronicFiled.getId()) && + c.getEntry().getParentId().equals(parentFolderId) && + !c.getEntry().getParentId().equals(folderToLink))); } /** - * Given an unfiled or filed record + * Given an unfiled container or filed record * And a container that is NOT a record folder - * When I file the unfiled or filed record to the container + * When I file the unfiled container or filed record to the container * Then I get an unsupported operation exception */ @Test ( - dataProvider = "invalidContainersForFile", + dataProvider = "invalidContainersToFile", description = "File the unfiled record to the container that is not a record folder" ) public void invalidContainerToFile(String containerId) throws Exception diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/ReadRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/ReadRecordTests.java similarity index 65% rename from rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/ReadRecordTests.java rename to rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/ReadRecordTests.java index 9545a142fd..89c28e55a5 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/ReadRecordTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/ReadRecordTests.java @@ -24,20 +24,16 @@ * along with Alfresco. If not, see . * #L% */ -package org.alfresco.rest.rm.community.fileplancomponents; +package org.alfresco.rest.rm.community.records; -import static org.alfresco.rest.rm.community.base.TestData.RECORD_CATEGORY_NAME; -import static org.alfresco.rest.rm.community.base.TestData.RECORD_CATEGORY_TITLE; import static org.alfresco.rest.rm.community.base.TestData.RECORD_FOLDER_NAME; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS; -import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS; -import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.IS_COMPLETED; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.CONTENT; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.IS_COMPLETED; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PATH; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE; -import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE; import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.IMAGE_FILE; import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createRecordCategoryModel; @@ -49,13 +45,10 @@ import static org.springframework.http.HttpStatus.OK; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.fail; import static org.testng.AssertJUnit.assertTrue; import java.io.FileInputStream; import java.io.InputStream; -import java.util.ArrayList; -import java.util.NoSuchElementException; import org.alfresco.rest.rm.community.base.BaseRMRestTest; import org.alfresco.rest.rm.community.base.TestData; @@ -64,14 +57,10 @@ import org.alfresco.rest.rm.community.model.record.RecordContent; import org.alfresco.rest.rm.community.model.record.RecordProperties; import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild; -import org.alfresco.rest.rm.community.model.recordfolder.RecordFolderCollection; -import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild; -import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildCollection; -import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildProperties; import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI; import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI; import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI; -import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledRecordFolderAPI; +import org.alfresco.test.AlfrescoTest; import org.apache.commons.codec.digest.DigestUtils; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -109,7 +98,7 @@ public class ReadRecordTests extends BaseRMRestTest * Then I receive an empty list */ @DataProvider(name="invalidContainersForRecords") - public String[][] getInvalidContainersForRecords() throws Exception + public Object[][] getInvalidContainersForRecords() throws Exception { return new String[][] { { FILE_PLAN_ALIAS }, @@ -119,9 +108,10 @@ public class ReadRecordTests extends BaseRMRestTest } @Test ( - dataProvider ="invalidContainersForRecords", - description ="Reading records from invalid containers" + dataProvider ="invalidContainersForRecords", + description ="Reading records from invalid containers" ) + @AlfrescoTest(jira="RM-4361") public void readRecordsFromInvalidContainers(String container) throws Exception { Record electronicRecord = Record.builder() @@ -154,7 +144,7 @@ public class ReadRecordTests extends BaseRMRestTest } else if(TRANSFERS_ALIAS.equals(container)) { - getRestAPIFactory().getTransferContainerAPI().getTransfers(container, "where=(isFile=true)") + getRestAPIFactory().getTransferContainerAPI().getTransfers(container, "where=(isRecord=true)") .assertThat()//check the list returned is empty .entriesListIsEmpty().assertThat().paginationExist(); //check response status code @@ -181,11 +171,12 @@ public class ReadRecordTests extends BaseRMRestTest * Then I successfully receive the meta-data values for that record */ @Test + @AlfrescoTest (jira = "RM-4361") public void readRecordMetadata() throws Exception { String RELATIVE_PATH = "/" + CATEGORY_NAME + getRandomAlphanumeric() + "/folder"; - RecordCategory recordCategoryModel = createRecordCategoryModel(RECORD_CATEGORY_NAME, RECORD_CATEGORY_TITLE); + RecordCategory recordCategoryModel = createRecordCategoryModel(CATEGORY_NAME, CATEGORY_NAME); String recordCategoryId = getRestAPIFactory().getFilePlansAPI().createRootRecordCategory(recordCategoryModel, FILE_PLAN_ALIAS).getId(); //create the containers from the relativePath @@ -236,6 +227,7 @@ public class ReadRecordTests extends BaseRMRestTest * Then I successfully receive the content of the record */ @Test + @AlfrescoTest (jira = "RM-4361") public void readRecordContent() throws Exception { RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI(); @@ -299,6 +291,7 @@ public class ReadRecordTests extends BaseRMRestTest * Then I am informed that the record has no content */ @Test + @AlfrescoTest (jira = "RM-4361") public void readNonElectronicRecordContent() throws Exception { @@ -322,7 +315,7 @@ public class ReadRecordTests extends BaseRMRestTest * Then I receive an error */ @DataProvider(name="noContentNodes") - public String[][] getNonRecordTypes() throws Exception + public Object[][] getNonRecordTypes() throws Exception { return new String[][] { { getFilePlan(FILE_PLAN_ALIAS).getId() }, @@ -335,180 +328,12 @@ public class ReadRecordTests extends BaseRMRestTest dataProvider = "noContentNodes", description = "Reading records from invalid containers" ) + @AlfrescoTest (jira = "RM-4361") public void readContentFromInvalidContainers(String container) throws Exception { getRestAPIFactory().getRecordsAPI().getRecordContent(container).asString(); assertStatusCode(BAD_REQUEST); } - /** - * Given a container that is a record folder - * When I try to record the containers records - * Then I receive a list of all the records contained within the record folder - */ - @Test - public void readRecordsFromRecordFolder() throws Exception - { - final int NUMBER_OF_RECORDS = 5; - String containerId = createCategoryFolderInFilePlan().getId(); - RecordFolderAPI recordFolderAPI = getRestAPIFactory().getRecordFolderAPI(); - // Create Electronic Records - ArrayList children = new ArrayList(); - for (int i = 0; i < NUMBER_OF_RECORDS; i++) - { - //build the electronic record - Record record = Record.builder() - .name(ELECTRONIC_RECORD_NAME + i) - .nodeType(CONTENT_TYPE) - .build(); - //create a child - Record child = recordFolderAPI.createRecord(record, containerId, createTempFile(ELECTRONIC_RECORD_NAME + i, ELECTRONIC_RECORD_NAME + i )); - children.add(child); - } - //Create NonElectronicRecords - for (int i = 0; i < NUMBER_OF_RECORDS; i++) - { - Record nonelectronicRecord = Record.builder() - .properties(RecordProperties.builder() - .description("Description") - .title("Title") - .build()) - .name(NONELECTRONIC_RECORD_NAME+i) - .nodeType(NON_ELECTRONIC_RECORD_TYPE) - .build(); - //create records - Record child = recordFolderAPI.createRecord(nonelectronicRecord, containerId); - - children.add(child); - } - - // List children from API - RecordFolderCollection apiChildren = (RecordFolderCollection) recordFolderAPI.getRecordFolderChildren(containerId).assertThat().entriesListIsNotEmpty(); - - // Check status code - assertStatusCode(OK); - - - // Check listed children against created list - apiChildren.getEntries().forEach(c -> - { - Record record = c.getEntry(); - assertNotNull(record.getId()); - logger.info("Checking child " + record.getId()); - - try - { - // Find this child in created children list - Record createdComponent = children.stream() - .filter(child -> child.getId().equals(record.getId())) - .findFirst() - .get(); - - // Created by - assertEquals(record.getCreatedByUser().getId(), getAdminUser().getUsername()); - - // Is parent Id set correctly - assertEquals(record.getParentId(), containerId); - - //check the record name - assertTrue(record.getName().equals(createdComponent.getName())); - assertTrue(createdComponent.getName().contains(createdComponent.getProperties().getIdentifier())); - assertEquals(createdComponent.getNodeType(), record.getNodeType()); - - } - catch (NoSuchElementException e) - { - fail("No child element for " + record.getId()); - } - }); - } - - /** - * Given a container that is a unfiled record folder - * When I try to record the containers records - * Then I receive a list of all the records contained within the unfiled record folder - */ - @Test - public void readRecordsFromUnfiledRecordFolder() throws Exception - { - final int NUMBER_OF_RECORDS = 5; - String containerId = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Folder " + getRandomAlphanumeric(), UNFILED_RECORD_FOLDER_TYPE).getId(); - //we have unfiled record folder - UnfiledRecordFolderAPI unfiledRecordFoldersAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI(); - // Create Electronic Records - ArrayList children = new ArrayList(); - for (int i = 0; i < NUMBER_OF_RECORDS; i++) - { - //build the electronic record - UnfiledContainerChild record = UnfiledContainerChild.builder() - .name(ELECTRONIC_RECORD_NAME + i) - .nodeType(CONTENT_TYPE) - .build(); - //create a child - UnfiledContainerChild child = unfiledRecordFoldersAPI.uploadRecord(record, containerId, createTempFile(ELECTRONIC_RECORD_NAME + i, ELECTRONIC_RECORD_NAME + i )); - - children.add(child); - } - //Create NonElectronicRecords - for (int i = 0; i < NUMBER_OF_RECORDS; i++) - { - UnfiledContainerChild nonelectronicRecord = UnfiledContainerChild.builder() - .properties(UnfiledContainerChildProperties.builder() - .description("Description") - .title("Title") - .build()) - .name(NONELECTRONIC_RECORD_NAME+i) - .nodeType(NON_ELECTRONIC_RECORD_TYPE) - .build(); - //create records - UnfiledContainerChild child = unfiledRecordFoldersAPI.createUnfiledRecordFolderChild(nonelectronicRecord, containerId); - - children.add(child); - } - - // List children from API - UnfiledContainerChildCollection apiChildren = (UnfiledContainerChildCollection) unfiledRecordFoldersAPI.getUnfiledRecordFolderChildren(containerId).assertThat().entriesListIsNotEmpty(); - - // Check status code - assertStatusCode(OK); - - - // Check listed children against created list - apiChildren.getEntries().forEach(c -> - { - UnfiledContainerChild record = c.getEntry(); - assertNotNull(record.getId()); - logger.info("Checking child " + record.getId()); - - try - { - // Find this child in created children list - UnfiledContainerChild createdComponent = children.stream() - .filter(child -> child.getId().equals(record.getId())) - .findFirst() - .get(); - - // Created by - assertEquals(record.getCreatedByUser().getId(), getAdminUser().getUsername()); - - // Is parent Id set correctly - assertEquals(record.getParentId(), containerId); - assertTrue(record.getIsRecord()); - - // Boolean properties related to node type - assertFalse(record.getIsUnfiledRecordFolder()); - - //check the record name - assertTrue(record.getName().equals(createdComponent.getName())); - assertTrue(createdComponent.getName().contains(createdComponent.getProperties().getIdentifier())); - assertEquals(createdComponent.getNodeType(), record.getNodeType()); - - } - catch (NoSuchElementException e) - { - fail("No child element for " + record.getId()); - } - }); - } } diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/UpdateRecordsTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/UpdateRecordsTests.java similarity index 99% rename from rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/UpdateRecordsTests.java rename to rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/UpdateRecordsTests.java index 356171f399..5b50c36fd9 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/UpdateRecordsTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/UpdateRecordsTests.java @@ -24,7 +24,7 @@ * along with Alfresco. If not, see . * #L% */ -package org.alfresco.rest.rm.community.fileplancomponents; +package org.alfresco.rest.rm.community.records; import static org.alfresco.rest.rm.community.base.TestData.NONELECTRONIC_RECORD_NAME; import static org.alfresco.rest.rm.community.base.TestData.RECORD_FOLDER_NAME; @@ -89,7 +89,7 @@ public class UpdateRecordsTests extends BaseRMRestTest /** Incomplete electronic and non electronic records created in one record folder, unfiled records container and one unfiled record folder */ @DataProvider(name = "incompleteRecords") - public String[][] getIncompleteRecords() throws Exception + public Object[][] getIncompleteRecords() throws Exception { //create electronic and nonElectronic record in record folder String recordFolderId = createCategoryFolderInFilePlan().getId(); @@ -131,7 +131,7 @@ public class UpdateRecordsTests extends BaseRMRestTest /** Complete electronic and non electronic records created in one record folder, unfiled records container and one unfiled record folder */ @DataProvider(name = "completeRecords") - public String[][] getCompleteRecords() throws Exception + public Object[][] getCompleteRecords() throws Exception { //create electronic and nonElectronic record in record folder String recordFolderId = createCategoryFolderInFilePlan().getId(); diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/UnfiledContainerTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/unfiledcontainers/UnfiledContainerTests.java similarity index 76% rename from rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/UnfiledContainerTests.java rename to rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/unfiledcontainers/UnfiledContainerTests.java index b115446add..719d1dddd1 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/UnfiledContainerTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/unfiledcontainers/UnfiledContainerTests.java @@ -24,18 +24,22 @@ * along with Alfresco. If not, see . * #L% */ -package org.alfresco.rest.rm.community.fileplancomponents; +package org.alfresco.rest.rm.community.unfiledcontainers; import static java.time.LocalDateTime.now; + import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.FOLDER_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE; +import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createUnfiledContainerChildModel; import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.OK; +import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; @@ -46,13 +50,18 @@ import java.util.List; import java.util.NoSuchElementException; import org.alfresco.rest.rm.community.base.BaseRMRestTest; +import org.alfresco.rest.rm.community.base.TestData; import org.alfresco.rest.rm.community.model.fileplan.FilePlan; import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer; import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild; import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildCollection; +import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildProperties; +import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledRecordFolder; import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI; +import org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil; import org.testng.annotations.AfterClass; import org.testng.annotations.AfterMethod; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; /** @@ -66,6 +75,22 @@ public class UnfiledContainerTests extends BaseRMRestTest /** Number of children (for children creation test) */ private static final int NUMBER_OF_CHILDREN = 10; + /** + * Data Provider with: + * with the object types for creating a Unfiled Record Folder + * + * @return file plan component alias + */ + @DataProvider (name = "unfiledFolderTypes") + public static Object[][] unfiledFolderTypes() + { + return new String[][] { + { UNFILED_RECORD_FOLDER_TYPE }, + { FOLDER_TYPE } + }; + } + + /** *
      * Given the RM site exists
@@ -132,18 +157,32 @@ public class UnfiledContainerTests extends BaseRMRestTest
      */
     @Test
     (
-        description = "Create unfiled record folder child in unfiled root container"
+        description = "Create unfiled record folder child in unfiled root container",
+        dataProvider = "unfiledFolderTypes"
     )
-    public void createUnfiledRecordFolderChild() throws Exception
+    public void createUnfiledRecordFolderChild(String folderType) throws Exception
     {
         String unfiledRecordFolderName = "UnfiledRecordFolder-" + getRandomAlphanumeric();
-        UnfiledContainerChild unfiledRecordFolder = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, unfiledRecordFolderName, UNFILED_RECORD_FOLDER_TYPE);
+        UnfiledContainerChild unfiledRecordFolderChild = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, unfiledRecordFolderName, UNFILED_RECORD_FOLDER_TYPE);
 
-        assertNotNull(unfiledRecordFolder.getId());
-        UnfiledContainer container = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS);
-        assertEquals(unfiledRecordFolder.getParentId(), container.getId());
-        assertFalse(unfiledRecordFolder.getIsRecord());
-        assertEquals(unfiledRecordFolder.getNodeType(), UNFILED_RECORD_FOLDER_TYPE);
+        assertNotNull(unfiledRecordFolderChild.getId());
+
+        // Verify the returned file plan component
+        assertFalse(unfiledRecordFolderChild.getIsRecord());
+        assertTrue(unfiledRecordFolderChild.getIsUnfiledRecordFolder()); // it is not a _normal_ record folder!
+
+        assertEquals(unfiledRecordFolderChild.getName(), unfiledRecordFolderName);
+        assertEquals(unfiledRecordFolderChild.getNodeType(), UNFILED_RECORD_FOLDER_TYPE);
+
+        assertEquals(unfiledRecordFolderChild.getCreatedByUser().getId(), getAdminUser().getUsername());
+
+        UnfiledRecordFolder unfiledRecordFolder = getRestAPIFactory().getUnfiledRecordFoldersAPI().getUnfiledRecordFolder(unfiledRecordFolderChild.getId());
+        // Verify the returned file plan component properties
+        UnfiledContainerChildProperties unfiledRecordFolderChildProperties = unfiledRecordFolder.getProperties();
+        assertEquals(unfiledRecordFolderChildProperties.getTitle(), FilePlanComponentsUtil.TITLE_PREFIX + unfiledRecordFolderName);
+        assertNotNull(unfiledRecordFolderChildProperties.getIdentifier());
+        assertEquals(unfiledRecordFolder.getParentId(),
+                getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS).getId());
     }
     
     /**
@@ -157,7 +196,7 @@ public class UnfiledContainerTests extends BaseRMRestTest
     (
         description = "Create unfiled record folder child in unfiled root container"
     )
-    public void createUnfiledRecordFolderChildWithRealtivePathNotSuported() throws Exception
+    public void createUnfiledRecordFolderChildWithRelativePathNotSuported() throws Exception
     {
         UnfiledContainerAPI unfiledContainerAPI = getRestAPIFactory().getUnfiledContainersAPI();
         // relativePath specify the container structure to create relative to
@@ -186,7 +225,7 @@ public class UnfiledContainerTests extends BaseRMRestTest
      */
     @Test
     (
-        description = "Create record child in unfiled root container"
+        description = "Create non-electronic record child in unfiled root container"
     )
     public void createNonElectronicRecordChild() throws Exception
     {
@@ -196,7 +235,7 @@ public class UnfiledContainerTests extends BaseRMRestTest
         assertNotNull(unfiledRecord.getId());
         assertTrue(unfiledRecord.getIsRecord());
         assertEquals(unfiledRecord.getNodeType(), NON_ELECTRONIC_RECORD_TYPE);
-        // check it was created in the unfiled root container 
+        // check it was created in the unfiled root container
         UnfiledContainer container = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS);
         assertEquals(unfiledRecord.getParentId(), container.getId());
         // check the name contains the identifier
@@ -224,7 +263,7 @@ public class UnfiledContainerTests extends BaseRMRestTest
         assertNotNull(unfiledRecord.getId());
         assertTrue(unfiledRecord.getIsRecord());
         assertEquals(unfiledRecord.getNodeType(), CONTENT_TYPE);
-        // check it was created in the unfiled root container 
+        // check it was created in the unfiled root container
         UnfiledContainer container = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS);
         assertEquals(unfiledRecord.getParentId(), container.getId());
         // check the name contains the identifier
@@ -270,7 +309,7 @@ public class UnfiledContainerTests extends BaseRMRestTest
         }
 
         // Get children from API
-        UnfiledContainerChildCollection listedChildren = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS);
+        UnfiledContainerChildCollection listedChildren = getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS,"include=properties");
 
         // Check status code
         assertStatusCode(OK);
@@ -308,13 +347,15 @@ public class UnfiledContainerTests extends BaseRMRestTest
                 else
                 {
                     assertTrue(containerChild.getIsRecord());
+                    assertTrue(containerChild.getName().contains(containerChild.getProperties().getIdentifier()),
+                            "Records don't have in name the identifier");
                 }
 
                 // Does returned object have the same contents as the created one?
                 assertEquals(createdComponent.getName(), containerChild.getName());
                 assertEquals(createdComponent.getNodeType(), containerChild.getNodeType());
 
-                // FIXME: Verify properties
+                // check rm identifier
                 assertNotNull(createdComponent.getProperties().getIdentifier());
 
                 // add the element to the matched children list
@@ -331,6 +372,34 @@ public class UnfiledContainerTests extends BaseRMRestTest
         assertTrue(createdChildren.containsAll(verifiedChildren));
     }
 
+    /**
+     * Negative test to check that invalid types cannot be created at unfiled container root level
+     * Only unfiled record folders and records can be created into unfiled container
+     */
+    @Test
+    (
+        dataProvider = "invalidRootTypes",
+        dataProviderClass = TestData.class,
+        description = "Only unfiled records folders and records  can be created as children for unfiled container root"
+    )
+    public void createInvalidUnfiledChildren(String filePlanComponentType)
+    {
+        String unfiledRecordFolderName = "UnfiledRecordFolder-" + getRandomAlphanumeric();
+
+        logger.info("creating " + filePlanComponentType);
+
+        // Build unfiled records folder properties
+        UnfiledContainerChild unfiledFolderModel = createUnfiledContainerChildModel(unfiledRecordFolderName, filePlanComponentType);
+
+        try
+        {
+            getRestAPIFactory().getUnfiledContainersAPI().createUnfiledContainerChild(unfiledFolderModel, UNFILED_RECORDS_CONTAINER_ALIAS);
+        } catch (Exception error)
+        {
+        }
+        // Verify the status code
+        assertStatusCode(UNPROCESSABLE_ENTITY);
+    }
     @AfterMethod
     @AfterClass (alwaysRun = true)
     public void tearDown() throws Exception
diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/UnfiledRecordsFolderTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/unfiledrecordfolders/UnfiledRecordsFolderTests.java
similarity index 59%
rename from rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/UnfiledRecordsFolderTests.java
rename to rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/unfiledrecordfolders/UnfiledRecordsFolderTests.java
index 54b86f5aab..cfca221474 100644
--- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/fileplancomponents/UnfiledRecordsFolderTests.java
+++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/unfiledrecordfolders/UnfiledRecordsFolderTests.java
@@ -24,21 +24,22 @@
  * along with Alfresco. If not, see .
  * #L%
  */
-package org.alfresco.rest.rm.community.fileplancomponents;
+package org.alfresco.rest.rm.community.unfiledrecordfolders;
 
 import static java.time.LocalDateTime.now;
+
+import static org.alfresco.rest.rm.community.base.TestData.RECORD_CATEGORY_NAME;
+import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
+import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.TRANSFERS_ALIAS;
 import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
 import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentFields.PATH;
 import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE;
-import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.FILE_PLAN_TYPE;
 import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE;
-import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE;
-import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
-import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.TRANSFER_CONTAINER_TYPE;
-import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE;
 import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE;
+import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createTempFile;
 import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createUnfiledContainerChildModel;
 import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
+import static org.springframework.http.HttpStatus.BAD_REQUEST;
 import static org.springframework.http.HttpStatus.CREATED;
 import static org.springframework.http.HttpStatus.NOT_FOUND;
 import static org.springframework.http.HttpStatus.NO_CONTENT;
@@ -48,18 +49,23 @@ 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;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.NoSuchElementException;
 import java.util.stream.Collectors;
 
 import org.alfresco.rest.rm.community.base.BaseRMRestTest;
+import org.alfresco.rest.rm.community.base.TestData;
 import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild;
 import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildCollection;
 import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildProperties;
 import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledRecordFolder;
+import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledRecordFolderAPI;
 import org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil;
 import org.testng.annotations.AfterClass;
-import org.testng.annotations.AfterMethod;
+import org.testng.annotations.AfterTest;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
@@ -71,49 +77,40 @@ import org.testng.annotations.Test;
  */
 public class UnfiledRecordsFolderTests extends BaseRMRestTest
 {
-    /** invalid root level types, at unfiled records root level these shouldn't be possible to create */
+    public static final String ELECTRONIC_RECORD_NAME = "Record electronic" + getRandomAlphanumeric();
+    public static final String NONELECTRONIC_RECORD_NAME = "Record nonelectronic" + getRandomAlphanumeric();
 
-    @DataProvider(name = "invalidRootTypes")
-    public String[][] createData()
+    /**
+     * valid root level types, at unfiled record folder  level these  possible to create
+     */
+
+    @DataProvider (name = "validChildren")
+    public Object[][] childrenForUnfiledRecord()
     {
         return new String[][]
-        {
-            { FILE_PLAN_TYPE },
-            { RECORD_CATEGORY_TYPE },
-            { RECORD_FOLDER_TYPE },
-            { TRANSFER_CONTAINER_TYPE },
-            { UNFILED_CONTAINER_TYPE }
-        };
+                {
+                        { UNFILED_RECORD_FOLDER_TYPE },
+                        { CONTENT_TYPE },
+                        { NON_ELECTRONIC_RECORD_TYPE }
+                };
     }
 
     /**
-     * Given the unfiled record container root
-     * When I create an unfiled record folder via the ReST API
-     * Then a root unfiled record folder is created
-     *
-     * @throws Exception if folder couldn't be created
+     * Invalid  containers that cannot be updated/deleted with record folder endpoint
      */
-    @Test(description = "Create root unfiled records folder")
-    public void createRootUnfiledRecordsFolder() throws Exception
+    @DataProvider (name = "invalidNodesForDelete")
+    public Object[][] getInvalidNodes() throws Exception
     {
-        String unfiledRecordFolderName = "UnfiledRecordFolder-" + getRandomAlphanumeric();
-        UnfiledContainerChild unfiledRecordFolderChild = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, unfiledRecordFolderName, UNFILED_RECORD_FOLDER_TYPE);
-
-        assertNotNull(unfiledRecordFolderChild.getId());
-
-        // Verify the returned file plan component
-        assertFalse(unfiledRecordFolderChild.getIsRecord());
-        assertTrue(unfiledRecordFolderChild.getIsUnfiledRecordFolder()); // it is not a _normal_ record folder!
-
-        assertEquals(unfiledRecordFolderChild.getName(), unfiledRecordFolderName);
-        assertEquals(unfiledRecordFolderChild.getNodeType(), UNFILED_RECORD_FOLDER_TYPE);
-
-        assertEquals(unfiledRecordFolderChild.getCreatedByUser().getId(), getAdminUser().getUsername());
-
-        UnfiledRecordFolder unfiledRecordFolder = getRestAPIFactory().getUnfiledRecordFoldersAPI().getUnfiledRecordFolder(unfiledRecordFolderChild.getId());
-        // Verify the returned file plan component properties
-        UnfiledContainerChildProperties unfiledRecordFolderChildProperties = unfiledRecordFolder.getProperties();
-        assertEquals(unfiledRecordFolderChildProperties.getTitle(), FilePlanComponentsUtil.TITLE_PREFIX + unfiledRecordFolderName);
+        return new String[][] {
+                { getRestAPIFactory().getFilePlansAPI().getFilePlan(FILE_PLAN_ALIAS).getId() },
+                { getRestAPIFactory().getUnfiledContainersAPI().getUnfiledContainer(UNFILED_RECORDS_CONTAINER_ALIAS).getId() },
+                { getRestAPIFactory().getTransferContainerAPI().getTransferContainer(TRANSFERS_ALIAS).getId() },
+                // an arbitrary record category
+                { createRootCategory(RECORD_CATEGORY_NAME).getId() },
+                // an arbitrary unfiled records folder
+                {createCategoryFolderInFilePlan().getId()},
+                {createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Record " + getRandomAlphanumeric(), CONTENT_TYPE).getId() }
+        };
     }
     
     /**
@@ -125,10 +122,11 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
      */
     @Test
     (
-        description = "Create a folder based on the relativePath. " +
-            "Containers in the relativePath that do not exist are created before the node is created"
+        description = "Create a child into unfiled record folder based on the relativePath. " +
+            "Containers in the relativePath that do not exist are created before the node is created",
+        dataProvider = "validChildren"
     )
-    public void createUnfiledRecordFolderWithRelativePath() throws Exception
+    public void createUnfiledRecordFolderWithRelativePath(String  nodeType) throws Exception
     {
         String unfiledRecordFolderName1 = "UnfiledRecordFolder-" + getRandomAlphanumeric();
         UnfiledContainerChild unfiledRecordFolderChild1 = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, unfiledRecordFolderName1, UNFILED_RECORD_FOLDER_TYPE);
@@ -139,21 +137,19 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
         String relativePath = now().getYear() + "/" + now().getMonth() + "/" + now().getDayOfMonth();
 
         // The record folder to be created
-        UnfiledContainerChild unfiledFolderModel =UnfiledContainerChild.builder()
+        UnfiledContainerChild unfiledChildModel =UnfiledContainerChild.builder()
                 .name(unfiledRecordFolderName2)
-                .nodeType(UNFILED_RECORD_FOLDER_TYPE)
+                .nodeType(nodeType)
                 .relativePath(relativePath)
                 .build();
                 
-        UnfiledContainerChild unfiledRecordFolderChild = getRestAPIFactory().getUnfiledRecordFoldersAPI().createUnfiledRecordFolderChild(unfiledFolderModel, unfiledRecordFolderChild1.getId(), "include=" + PATH);
+        UnfiledContainerChild unfiledRecordFolderChild = getRestAPIFactory().getUnfiledRecordFoldersAPI().createUnfiledRecordFolderChild(unfiledChildModel, unfiledRecordFolderChild1.getId(), "include=" + PATH);
 
         // Check the API response code
         assertStatusCode(CREATED);
 
-        // Verify the returned details for the record folder
-        assertFalse(unfiledRecordFolderChild.getIsRecord());
-        assertTrue(unfiledRecordFolderChild.getIsUnfiledRecordFolder());
-        assertTrue(UNFILED_RECORD_FOLDER_TYPE.equals(unfiledRecordFolderChild.getNodeType()));
+        // Verify the returned node type
+        assertTrue(nodeType.equals(unfiledRecordFolderChild.getNodeType()));
 
         // Check the path return contains the relativePath
         assertTrue(unfiledRecordFolderChild.getPath().getName().contains(relativePath));
@@ -161,15 +157,6 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
         // Check the parent is a folder, not a record
         assertTrue(getRestAPIFactory().getUnfiledRecordFoldersAPI().getUnfiledRecordFolder(unfiledRecordFolderChild.getParentId()).getNodeType().equals(UNFILED_RECORD_FOLDER_TYPE));
 
-        // Check the created folder from the server
-        UnfiledRecordFolder recordFolder = getRestAPIFactory().getUnfiledRecordFoldersAPI().getUnfiledRecordFolder(unfiledRecordFolderChild.getId(), "include=" + PATH);
-
-        // Check the API response code
-        assertStatusCode(OK);
-
-        // Check the path return contains the relativePath
-        assertTrue(recordFolder.getPath().getName().contains(relativePath));
-
         // New relative path only a part of containers need to be created before the record folder
         String newRelativePath = now().getYear() + "/" + now().getMonth() + "/" + (now().getDayOfMonth() + 1);
 
@@ -177,7 +164,7 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
         // The record folder to be created
         UnfiledContainerChild newUnfiledFolderModel =UnfiledContainerChild.builder()
                 .name(unfiledRecordFolderName3)
-                .nodeType(UNFILED_RECORD_FOLDER_TYPE)
+                .nodeType(nodeType)
                 .relativePath(newRelativePath)
                 .build();
                 
@@ -185,30 +172,17 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
 
         // Check the API response code
         assertStatusCode(CREATED);
-        // Check the API response code
-        assertStatusCode(CREATED);
-
-        // Verify the returned properties for the unfiled record folder
-        assertTrue(newUnfiledRecordFolderChild.getIsUnfiledRecordFolder());
-        assertFalse(newUnfiledRecordFolderChild.getIsRecord());
 
         // Check the path return contains the newRelativePath
         assertTrue(newUnfiledRecordFolderChild.getPath().getName().contains(newRelativePath));
 
         // Check the parent is a folder, not a record
         assertFalse(getRestAPIFactory().getUnfiledRecordFoldersAPI().getUnfiledRecordFolder(newUnfiledRecordFolderChild.getParentId()).equals(UNFILED_RECORD_FOLDER_TYPE));
+        // Verify the returned node type
+        assertTrue(nodeType.equals(newUnfiledRecordFolderChild.getNodeType()));
 
-        // Check the folder created on the server
-        UnfiledRecordFolder newRecordFolder = getRestAPIFactory().getUnfiledRecordFoldersAPI().getUnfiledRecordFolder(newUnfiledRecordFolderChild.getId(), "include=" + PATH);
-
-        // Check the API response code
-        assertStatusCode(OK);
-
-        // Check the path return contains the newRelativePath
-        assertTrue(newRecordFolder.getPath().getName().contains(newRelativePath));
     }
 
-
     /**
      * Negative test to check that invalid types cannot be created at unfiled container root level
      * Only unfiled record folders and records can be created into unfiled container
@@ -216,12 +190,13 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
     @Test
     (
         dataProvider = "invalidRootTypes",
-        description = "Only unfiled records folders  can be created at unfiled records root level"
+        dataProviderClass = TestData.class,
+        description = "Only unfiled records folders and records  can be created as children for unfiled container root"
     )
-    public void onlyRecordFoldersCanBeCreatedAtUnfiledRecordsRoot(String filePlanComponentType)
+    public void createInvalidUnfiledChildren(String filePlanComponentType) throws Exception
     {
         String unfiledRecordFolderName = "UnfiledRecordFolder-" + getRandomAlphanumeric();
-
+        UnfiledContainerChild unfiledRecordFolderChild = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, unfiledRecordFolderName, UNFILED_RECORD_FOLDER_TYPE);
         logger.info("creating " + filePlanComponentType);
 
         // Build unfiled records folder properties
@@ -229,12 +204,11 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
 
         try
         {
-            getRestAPIFactory().getUnfiledContainersAPI().createUnfiledContainerChild(unfiledFolderModel, UNFILED_RECORDS_CONTAINER_ALIAS);
+            getRestAPIFactory().getUnfiledRecordFoldersAPI().createUnfiledRecordFolderChild(unfiledFolderModel, unfiledRecordFolderChild.getId());
         }
         catch (Exception error)
         {
         }
-
         // Verify the status code
         assertStatusCode(UNPROCESSABLE_ENTITY);
     }
@@ -261,11 +235,14 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
         assertEquals(unfiledParentFolderName, unfiledParentFolder.getName());
 
         // Build the unfiled records folder properties
-        UnfiledContainerChild unfiledChildFolderModel = UnfiledContainerChild.builder().name(unfiledChildFolderName)
-                .nodeType(UNFILED_RECORD_FOLDER_TYPE)
-                .properties(UnfiledContainerChildProperties.builder().title(FilePlanComponentsUtil.TITLE_PREFIX + unfiledChildFolderName)
-                        .description(FilePlanComponentsUtil.DESCRIPTION_PREFIX + unfiledChildFolderName).build())
-                .build();
+        UnfiledContainerChild unfiledChildFolderModel =
+                    UnfiledContainerChild.builder()
+                                            .name(unfiledChildFolderName)
+                                            .nodeType(UNFILED_RECORD_FOLDER_TYPE)
+                                            .properties(UnfiledContainerChildProperties.builder()
+                                                                .title(FilePlanComponentsUtil.TITLE_PREFIX + unfiledChildFolderName)
+                                                                .description(FilePlanComponentsUtil.DESCRIPTION_PREFIX + unfiledChildFolderName).build())
+                                        .build();
 
         // Create it as a child of parentFolder
         UnfiledContainerChild unfiledChildFolder = getRestAPIFactory().getUnfiledRecordFoldersAPI()
@@ -331,16 +308,32 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
         assertEquals(unfiledFolderName, unfiledFolderToModify.getName());
 
         // Build the properties which will be updated
-        UnfiledRecordFolder unfiledChildFolderModel = UnfiledRecordFolder.builder().name(modified + unfiledFolderName)
-                .properties(UnfiledContainerChildProperties.builder().title(modified + unfiledFolderToModify.getProperties().getTitle())
-                        .description(modified + unfiledFolderToModify.getProperties().getDescription()).build())
-                .build();
+        UnfiledRecordFolder unfiledChildFolderModel =
+                    UnfiledRecordFolder.builder()
+                                         .name(modified + unfiledFolderName)
+                                         .properties
+                                             (UnfiledContainerChildProperties.builder()
+                                                                                .title(modified + unfiledFolderToModify.getProperties().getTitle())
+                                                                                .description(modified + unfiledFolderToModify.getProperties().getDescription())
+                                                                                .build()
+                                             )
+                                       .build();
+
+
+
 
         // Update the unfiled records folder
-        getRestAPIFactory().getUnfiledRecordFoldersAPI().updateUnfiledRecordFolder(unfiledChildFolderModel, unfiledFolderToModify.getId());
+        UnfiledRecordFolder updatedRecordFolder=getRestAPIFactory().getUnfiledRecordFoldersAPI().updateUnfiledRecordFolder(unfiledChildFolderModel, unfiledFolderToModify.getId());
+
         // Verify the status code
         assertStatusCode(OK);
-
+        // Verify the returned file plan component
+        assertEquals(unfiledChildFolderModel.getName(),
+                updatedRecordFolder.getName());
+        assertEquals(unfiledChildFolderModel.getProperties().getTitle(),
+                updatedRecordFolder.getProperties().getTitle());
+        assertEquals(unfiledChildFolderModel.getProperties().getDescription(),
+                updatedRecordFolder.getProperties().getDescription());
         // This is to ensure the change was actually applied, rather than simply trusting the object returned by PUT
         UnfiledRecordFolder renamedUnfiledFolder = getRestAPIFactory().getUnfiledRecordFoldersAPI().getUnfiledRecordFolder(unfiledFolderToModify.getId());
 
@@ -392,8 +385,122 @@ public class UnfiledRecordsFolderTests extends BaseRMRestTest
         getRestAPIFactory().getUnfiledRecordFoldersAPI().getUnfiledRecordFolder(unfiledFolderToDelete.getId());
         assertStatusCode(NOT_FOUND);
     }
+
+    /**
+     * 
+     * Given other nodes type than unfiled record folders exists
+     * When I use the API from unfiled record-folders to delete the nodes
+     * Then the request fails
+     * 
+ */ + @Test + ( + description = "Delete invalid nodes type with the DELETE unfiled record folders request", + dataProvider = "invalidNodesForDelete" + ) + public void deleteInvalidNodesUnfiled(String nodeId) throws Exception + { + // Delete the nodes with record-folders end-point + UnfiledRecordFolderAPI unfiledFolderAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI(); + unfiledFolderAPI.deleteUnfiledRecordFolder(nodeId); + + // Check the response status code + assertStatusCode(BAD_REQUEST); + } + + /** + * Given a container that is a unfiled record folder + * When I try to record the containers records + * Then I receive a list of all the records contained within the unfiled record folder + */ + @Test + public void readRecordsFromUnfiledRecordFolder() throws Exception + { + final int NUMBER_OF_RECORDS = 5; + String containerId = createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Folder " + getRandomAlphanumeric(), UNFILED_RECORD_FOLDER_TYPE).getId(); + //we have unfiled record folder + UnfiledRecordFolderAPI unfiledRecordFoldersAPI = getRestAPIFactory().getUnfiledRecordFoldersAPI(); + // Create Electronic Records + ArrayList children = new ArrayList(); + for (int i = 0; i < NUMBER_OF_RECORDS; i++) + { + //build the electronic record + UnfiledContainerChild record = UnfiledContainerChild.builder() + .name(ELECTRONIC_RECORD_NAME + i) + .nodeType(CONTENT_TYPE) + .build(); + //create a child + UnfiledContainerChild child = unfiledRecordFoldersAPI.uploadRecord(record, containerId, createTempFile(ELECTRONIC_RECORD_NAME + i, ELECTRONIC_RECORD_NAME + i)); + + children.add(child); + } + //Create NonElectronicRecords + for (int i = 0; i < NUMBER_OF_RECORDS; i++) + { + UnfiledContainerChild nonelectronicRecord = UnfiledContainerChild.builder() + .properties(UnfiledContainerChildProperties.builder() + .description("Description") + .title("Title") + .build()) + .name(NONELECTRONIC_RECORD_NAME + i) + .nodeType(NON_ELECTRONIC_RECORD_TYPE) + .build(); + //create records + UnfiledContainerChild child = unfiledRecordFoldersAPI.createUnfiledRecordFolderChild(nonelectronicRecord, containerId); + + children.add(child); + } + + // List children from API + UnfiledContainerChildCollection apiChildren = (UnfiledContainerChildCollection) unfiledRecordFoldersAPI.getUnfiledRecordFolderChildren(containerId,"include=properties").assertThat().entriesListIsNotEmpty(); + + // Check status code + assertStatusCode(OK); + + + // Check listed children against created list + apiChildren.getEntries().forEach(c -> + { + UnfiledContainerChild record = c.getEntry(); + assertNotNull(record.getId()); + logger.info("Checking child " + record.getId()); + + try + { + // Find this child in created children list + UnfiledContainerChild createdComponent = children.stream() + .filter(child -> child.getId().equals(record.getId())) + .findFirst() + .get(); + + // Created by + assertEquals(record.getCreatedByUser().getId(), getAdminUser().getUsername()); + + // Is parent Id set correctly + assertEquals(record.getParentId(), containerId); + assertTrue(record.getIsRecord()); + + // Boolean properties related to node type + assertFalse(record.getIsUnfiledRecordFolder()); + + //check the record name + assertTrue(record.getName().equals(createdComponent.getName()), + "The record name "+ record.getName()+" is not equal with the record name returned when creating the record " + createdComponent + .getName()); + + assertTrue(record.getName().equals(record.getProperties().getIdentifier())); + assertTrue(createdComponent.getName().contains(createdComponent.getProperties().getIdentifier())); + assertEquals(createdComponent.getNodeType(), record.getNodeType()); + + } + catch (NoSuchElementException e) + { + fail("No child element for " + record.getId()); + } + }); + } - @AfterMethod + @AfterTest @AfterClass (alwaysRun = true) public void tearDown() throws Exception { diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml index a268d0264b..048f415c31 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml @@ -106,6 +106,7 @@ + diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/recordcategories/RecordCategoryChildrenRelation.java b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/recordcategories/RecordCategoryChildrenRelation.java index 7863035e60..198863b2d8 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/recordcategories/RecordCategoryChildrenRelation.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/recordcategories/RecordCategoryChildrenRelation.java @@ -35,6 +35,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -42,6 +43,7 @@ import java.util.Set; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.query.PagingResults; import org.alfresco.repo.node.getchildren.FilterProp; +import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.impl.Util; import org.alfresco.rest.api.model.UserInfo; @@ -60,6 +62,7 @@ import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.model.FileInfo; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.namespace.QName; +import org.alfresco.service.transaction.TransactionService; import org.apache.commons.lang3.StringUtils; /** @@ -81,6 +84,7 @@ public class RecordCategoryChildrenRelation implements RelationshipResourceActio private SearchTypesFactory searchTypesFactory; private FileFolderService fileFolderService; private ApiNodesModelFactory nodesModelFactory; + private TransactionService transactionService; public void setApiUtils(FilePlanComponentsApiUtils apiUtils) { @@ -102,6 +106,11 @@ public class RecordCategoryChildrenRelation implements RelationshipResourceActio this.nodesModelFactory = nodesModelFactory; } + public void setTransactionService(TransactionService transactionService) + { + this.transactionService = transactionService; + } + @Override @WebApiDescription(title = "Return a paged list of record category children for the container identified by 'recordCategoryId'") public CollectionWithPagingInfo readAll(String recordCategoryId, Parameters parameters) @@ -164,18 +173,33 @@ public class RecordCategoryChildrenRelation implements RelationshipResourceActio List result = new ArrayList<>(nodeInfos.size()); Map mapUserInfo = new HashMap<>(); - for (RecordCategoryChild nodeInfo : nodeInfos) - { - // Resolve the parent node - NodeRef nodeParent = parentNodeRef; - if(StringUtils.isNoneBlank(nodeInfo.getRelativePath())) - { - nodeParent = apiUtils.lookupAndValidateRelativePath(parentNodeRef, nodeInfo.getRelativePath(), RecordsManagementModel.TYPE_RECORD_CATEGORY); - } - // Create the node - NodeRef newNode = apiUtils.createRMNode(nodeParent, nodeInfo.getName(), nodeInfo.getNodeType(), nodeInfo.getProperties(), nodeInfo.getAspectNames()); - FileInfo info = fileFolderService.getFileInfo(newNode); + RetryingTransactionCallback> callback = new RetryingTransactionCallback>() + { + public List execute() + { + List createdNodes = new LinkedList<>(); + for (RecordCategoryChild nodeInfo : nodeInfos) + { + // Resolve the parent node + NodeRef nodeParent = parentNodeRef; + if (StringUtils.isNoneBlank(nodeInfo.getRelativePath())) + { + nodeParent = apiUtils.lookupAndValidateRelativePath(parentNodeRef, nodeInfo.getRelativePath(), + RecordsManagementModel.TYPE_RECORD_CATEGORY); + } + // Create the node + NodeRef newNode = apiUtils.createRMNode(nodeParent, nodeInfo.getName(), nodeInfo.getNodeType(), nodeInfo.getProperties(), nodeInfo.getAspectNames()); + createdNodes.add(newNode); + } + return createdNodes; + } + }; + List createdNodes = transactionService.getRetryingTransactionHelper().doInTransaction(callback); + + for (NodeRef nodeInfo : createdNodes) + { + FileInfo info = fileFolderService.getFileInfo(nodeInfo); result.add(nodesModelFactory.createRecordCategoryChild(info, parameters, mapUserInfo, false)); } diff --git a/rm-community/rm-community-rest-api-explorer/src/main/webapp/definitions/gs-core-api.yaml b/rm-community/rm-community-rest-api-explorer/src/main/webapp/definitions/gs-core-api.yaml index 070ee6efdd..a8218af2f3 100644 --- a/rm-community/rm-community-rest-api-explorer/src/main/webapp/definitions/gs-core-api.yaml +++ b/rm-community/rm-community-rest-api-explorer/src/main/webapp/definitions/gs-core-api.yaml @@ -307,7 +307,6 @@ paths: - $ref: '#/parameters/filePlanIdWithAliasParam' - $ref: '#/parameters/skipCountParam' - $ref: '#/parameters/maxItemsParam' - - $ref: '#/parameters/orderByParam' - $ref: '#/parameters/recordCategoryEntryIncludeParam' - $ref: '#/parameters/filePlanIncludeSourceParam' - $ref: '#/parameters/fieldsParam' @@ -536,7 +535,6 @@ paths: - $ref: '#/parameters/unfiledContainerIdParam' - $ref: '#/parameters/skipCountParam' - $ref: '#/parameters/maxItemsParam' - - $ref: '#/parameters/orderByParam' - $ref: '#/parameters/unfiledRecordFolderAndContainerWhereParam' - $ref: '#/parameters/unfiledContainerEntryIncludeParam' - $ref: '#/parameters/unfiledContainerIncludeSourceParam' @@ -839,7 +837,6 @@ paths: - $ref: '#/parameters/unfiledRecordFolderIdParam' - $ref: '#/parameters/skipCountParam' - $ref: '#/parameters/maxItemsParam' - - $ref: '#/parameters/orderByParam' - $ref: '#/parameters/unfiledRecordFolderAndContainerWhereParam' - $ref: '#/parameters/unfiledRecordFolderEntryIncludeParam' - $ref: '#/parameters/unfiledRecordFolderRelativePathParam' @@ -1148,7 +1145,6 @@ paths: - $ref: '#/parameters/recordCategoryIdParam' - $ref: '#/parameters/skipCountParam' - $ref: '#/parameters/maxItemsParam' - - $ref: '#/parameters/orderByParam' - $ref: '#/parameters/recordCategoryWhereParam' - $ref: '#/parameters/recordCategoryChildIncludeParam' - $ref: '#/parameters/recordCategoryRelativePathParam' @@ -1453,7 +1449,6 @@ paths: - $ref: '#/parameters/recordFolderIdParam' - $ref: '#/parameters/skipCountParam' - $ref: '#/parameters/maxItemsParam' - - $ref: '#/parameters/orderByParam' - $ref: '#/parameters/recordFolderWhereParam' - $ref: '#/parameters/recordFolderChildEntryIncludeParam' - $ref: '#/parameters/recordFolderIncludeSourceParam' @@ -1962,7 +1957,6 @@ paths: - $ref: '#/parameters/transferContainerIdWithAliasParam' - $ref: '#/parameters/skipCountParam' - $ref: '#/parameters/maxItemsParam' - - $ref: '#/parameters/orderByParam' - $ref: '#/parameters/transferEntryIncludeParam' - $ref: '#/parameters/transferContainerIncludeSourceParam' - $ref: '#/parameters/fieldsParam' @@ -2037,7 +2031,6 @@ paths: - $ref: '#/parameters/transferIdParam' - $ref: '#/parameters/skipCountParam' - $ref: '#/parameters/maxItemsParam' - - $ref: '#/parameters/orderByParam' - $ref: '#/parameters/transferChildEntryIncludeParam' - $ref: '#/parameters/transferIncludeSourceParam' - $ref: '#/parameters/fieldsParam' @@ -2422,23 +2415,6 @@ parameters: required: false type: integer minimum: 1 - ## Core parameter - orderByParam: - name: orderBy - in: query - description: | - A string to control the order of the entities returned in a list. You can use the **orderBy** parameter to - sort the list by one or more fields. - - Each field has a default sort order, which is normally acending order. Read the API method implementation notes - above to check if any fields used in this method have a descending default search order. - - To sort the entities in a specific order, you can use the **ASC** and **DESC** keywords for any field. - required: false - type: array - items: - type: string - collectionFormat: csv # Core definition attachmentParam: name: attachment