From 07ad6dc1d77f28da110528d758316b61cfe41af1 Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Tue, 15 Nov 2016 16:33:48 +0000 Subject: [PATCH 1/6] RM-4023: Unfiled records folders tests --- .../alfresco/rest/rm/base/BaseRestTest.java | 14 + .../UnfiledRecordsFolderTests.java | 241 ++++++++++++++++++ 2 files changed, 255 insertions(+) create mode 100644 rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/base/BaseRestTest.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/base/BaseRestTest.java index 6129987124..2af7cfcf86 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/base/BaseRestTest.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/base/BaseRestTest.java @@ -21,6 +21,7 @@ import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFie import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE; import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE; +import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE; import static org.alfresco.rest.rm.model.site.RMSiteCompliance.STANDARD; import static org.alfresco.rest.rm.model.site.RMSiteFields.COMPLIANCE; import static org.alfresco.rest.rm.model.site.RMSiteFields.DESCRIPTION; @@ -163,6 +164,19 @@ public class BaseRestTest extends RestTest return createComponent(parentCategoryId, folderName, RECORD_FOLDER_TYPE, FOLDER_TITLE); } + /** + * Helper method to create child unfiled record folder + * + * @param parentId The id of the parent folder + * @param folderName The name of the folder + * @return The created folder + * @throws Exception on unsuccessful component creation + */ + public FilePlanComponent createUnfiledRecordsFolder(String parentId, String folderName) throws Exception + { + return createComponent(parentId, folderName, UNFILED_RECORD_FOLDER_TYPE, FOLDER_TITLE); + } + /** * Helper method to create generic child component * diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java new file mode 100644 index 0000000000..4c44b2e196 --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java @@ -0,0 +1,241 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.rest.rm.fileplancomponents; + +import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; +import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.NAME; +import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.NODE_TYPE; +import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES; +import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; +import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_DESCRIPTION; +import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.*; +import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS; +import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; +import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; +import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.NOT_FOUND; +import static org.springframework.http.HttpStatus.NO_CONTENT; +import static org.springframework.http.HttpStatus.OK; +import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.stream.Collectors; + +import com.google.gson.JsonObject; + +import org.alfresco.rest.rm.base.BaseRestTest; +import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponent; +import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentEntry; +import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentProperties; +import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType; +import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentsCollection; +import org.alfresco.rest.rm.requests.FilePlanComponentAPI; +import org.alfresco.utility.data.DataUser; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.Test; + +/** + * Unfiled Records folder CRUD API tests + * + * @author Kristijan Conkas + * @since 1.0 + */ +public class UnfiledRecordsFolderTests extends BaseRestTest +{ + @Autowired + private FilePlanComponentAPI filePlanComponentAPI; + + @Autowired + private DataUser dataUser; + + /** invalid root level types, at root level these shouldn't be possible to create */ + private static final List INVALID_ROOT_TYPES = Arrays.asList( + FILE_PLAN_TYPE, + RECORD_CATEGORY_TYPE, + RECORD_FOLDER_TYPE, + HOLD_TYPE, + HOLD_CONTAINER_TYPE, + TRANSFER_CONTAINER_TYPE, + UNFILED_CONTAINER_TYPE); + + // Number of children (for children creation test) + private static final int NUMBER_OF_CHILDREN = 10; + + /** + * 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 + */ + @Test(description = "Create root unfiled records folder") + public void createRootUnfiledRecordsFolder() throws Exception + { + // Authenticate with admin user + RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + String folderName = "Folder " + getRandomAlphanumeric(); + String folderTitle = folderName + " Title"; + String folderDescription = folderName + " Description"; + + // Build the record category properties + JsonObject unfiledFolderProperties = buildObject() + .add(NAME, folderName) + .add(NODE_TYPE, UNFILED_RECORD_FOLDER_TYPE.toString()) + .addObject(PROPERTIES) + .add(PROPERTIES_TITLE, folderTitle) + .add(PROPERTIES_DESCRIPTION, folderDescription) + .end() + .getJson(); + + FilePlanComponent filePlanComponent = filePlanComponentAPI.createFilePlanComponent(unfiledFolderProperties, + UNFILED_RECORDS_CONTAINER_ALIAS.toString()); + + // Verify the status code + restWrapper.assertStatusCodeIs(CREATED); + + // Verify the returned file plan component + assertFalse(filePlanComponent.isIsCategory()); + assertFalse(filePlanComponent.isIsFile()); + assertFalse(filePlanComponent.isIsRecordFolder()); // it is not a _normal_ record folder! + + assertEquals(filePlanComponent.getName(), folderName); + assertEquals(filePlanComponent.getNodeType(), UNFILED_RECORD_FOLDER_TYPE.toString()); + assertFalse(filePlanComponent.isHasRetentionSchedule()); + + assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername()); + + // Verify the returned file plan component properties + FilePlanComponentProperties filePlanComponentProperties = filePlanComponent.getProperties(); + assertEquals(filePlanComponentProperties.getTitle(), folderTitle); + assertEquals(filePlanComponentProperties.getDescription(), folderDescription); + } + + /** + * Negative test to verify only unfiled record folders can be created at root level + */ + @Test(description = "Only unfiled records folders can be created at unfiled records root level") + public void onlyRecordFoldersCanBeCreatedAtUnfiledRecordsRoot() + { + RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + String folderName = "Folder " + getRandomAlphanumeric(); + String folderTitle = folderName + " Title"; + String folderDescription = folderName + " Description"; + + INVALID_ROOT_TYPES.stream() + .peek(a -> logger.info("creating " + a.toString())) + .forEach(t -> { + JsonObject unfiledFolderProperties = buildObject() + .add(NAME, folderName) + .add(NODE_TYPE, t.toString()) + .addObject(PROPERTIES) + .add(PROPERTIES_TITLE, folderTitle) + .add(PROPERTIES_DESCRIPTION, folderDescription) + .end() + .getJson(); + try + { + filePlanComponentAPI.createFilePlanComponent(unfiledFolderProperties, + UNFILED_RECORDS_CONTAINER_ALIAS.toString()); + } + catch (Exception error) + { + } + + // Verify the status code + restWrapper.assertStatusCodeIs(UNPROCESSABLE_ENTITY); + }); + } + + /** + * Given an unfiled record folder + * When I create an unfiled record folder via the ReST API + * Then an unfiled record folder is created within the unfiled record folder + * + * @throws Exception + */ + @Test(description = "Child unfiled records folder can be created in a parent unfiled records folder") + public void childUnfiledRecordsFolderCanBeCreated() throws Exception + { + RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + + String parentFolderName = "Parent Folder " + getRandomAlphanumeric(); + String childFolderName = "Child Folder " + getRandomAlphanumeric(); + String childFolderTitle = childFolderName + " Title"; + String childFolderDescription = childFolderName + " Description"; + + // no need for fine control, create it using utility function + FilePlanComponent parentFolder = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), parentFolderName); + assertEquals(parentFolderName, parentFolder.getName()); + + // Build the record category properties + JsonObject unfiledFolderProperties = buildObject() + .add(NAME, childFolderName) + .add(NODE_TYPE, UNFILED_RECORD_FOLDER_TYPE.toString()) + .addObject(PROPERTIES) + .add(PROPERTIES_TITLE, childFolderTitle) + .add(PROPERTIES_DESCRIPTION, childFolderDescription) + .end() + .getJson(); + + // create it as a child of parentFolder + FilePlanComponent childFolder = filePlanComponentAPI.createFilePlanComponent(unfiledFolderProperties, + parentFolder.getId()); + + // Verify the status code + restWrapper.assertStatusCodeIs(CREATED); + + // Verify the returned file plan component + assertFalse(childFolder.isIsCategory()); + assertFalse(childFolder.isIsFile()); + assertFalse(childFolder.isIsRecordFolder()); // it is not a _normal_ record folder! + + assertEquals(childFolder.getName(), childFolderName); + assertEquals(childFolder.getNodeType(), UNFILED_RECORD_FOLDER_TYPE.toString()); + assertFalse(childFolder.isHasRetentionSchedule()); + + assertEquals(childFolder.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername()); + + // Verify the returned file plan component properties + FilePlanComponentProperties childProperties = childFolder.getProperties(); + assertEquals(childProperties.getTitle(), childFolderTitle); + assertEquals(childProperties.getDescription(), childFolderDescription); + + // does this child point to its parent? + assertEquals(childFolder.getParentId(), parentFolder.getId()); + + // does child's parent point to it? + // perform another call as our parentFolder was executed before childFolder existed + FilePlanComponentsCollection parentsChildren = filePlanComponentAPI.listChildComponents(parentFolder.getId()); + restWrapper.assertStatusCodeIs(OK); + List childIds = parentsChildren.getEntries() + .stream() + .map(c -> c.getFilePlanComponent().getId()) + .collect(Collectors.toList()); + + // child folder is listed in parent + assertTrue(childIds.contains(childFolder.getId())); + + // there is only one child + assertEquals(1, childIds.size()); + } +} From b78970484ea740dafe604bbd8c1f76adaa770e20 Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Tue, 15 Nov 2016 16:59:14 +0000 Subject: [PATCH 2/6] RM-4023: edit tests --- .../UnfiledRecordsFolderTests.java | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java index 4c44b2e196..1b67bb8bb2 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java @@ -83,7 +83,7 @@ public class UnfiledRecordsFolderTests extends BaseRestTest * 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 */ @Test(description = "Create root unfiled records folder") @@ -238,4 +238,44 @@ public class UnfiledRecordsFolderTests extends BaseRestTest // there is only one child assertEquals(1, childIds.size()); } + + /** + * Given an unfiled record folder + * When I modify the unfiled record folder details via the ReST API + * Then the details of the unfiled record folder are modified + * + * @throws Exception + */ + @Test(description = "Child unfiled records folder can be created in a parent unfiled records folder") + public void editUnfiledRecordsFolder() throws Exception + { + RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + String modified = "Modified "; + String folderName = "Folder To Modify" + getRandomAlphanumeric(); + + // no need for fine control, create it using utility function + FilePlanComponent folderToModify = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), folderName); + assertEquals(folderName, folderToModify.getName()); + + // Build the properties which will be updated + JsonObject updateFolderProperties = buildObject() + .add(NAME, modified + folderToModify.getName()) + .addObject(PROPERTIES) + .add(PROPERTIES_TITLE, modified + folderToModify.getProperties().getTitle()) + .add(PROPERTIES_DESCRIPTION, modified + folderToModify.getProperties().getDescription()) + .end() + .getJson(); + + // Update the unfiled records folder + FilePlanComponent renamedFolder = filePlanComponentAPI.updateFilePlanComponent(updateFolderProperties, + folderToModify.getId()); + + // Verify the status code + restWrapper.assertStatusCodeIs(OK); + + // Verify the returned file plan component + assertEquals(modified + folderToModify.getName(), renamedFolder.getName()); + assertEquals(modified + folderToModify.getProperties().getTitle(), renamedFolder.getProperties().getTitle()); + assertEquals(modified + folderToModify.getProperties().getDescription(), renamedFolder.getProperties().getDescription()); + } } From d991e65d6c15b3d019edd4cf0870142fb0d10282 Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Tue, 15 Nov 2016 17:12:00 +0000 Subject: [PATCH 3/6] RM-4023: better check for PUT request --- .../rm/fileplancomponents/UnfiledRecordsFolderTests.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java index 1b67bb8bb2..97bc8a9fb7 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java @@ -246,7 +246,7 @@ public class UnfiledRecordsFolderTests extends BaseRestTest * * @throws Exception */ - @Test(description = "Child unfiled records folder can be created in a parent unfiled records folder") + @Test(description = "Unfiled record folder") public void editUnfiledRecordsFolder() throws Exception { RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); @@ -267,11 +267,12 @@ public class UnfiledRecordsFolderTests extends BaseRestTest .getJson(); // Update the unfiled records folder - FilePlanComponent renamedFolder = filePlanComponentAPI.updateFilePlanComponent(updateFolderProperties, - folderToModify.getId()); - + filePlanComponentAPI.updateFilePlanComponent(updateFolderProperties, folderToModify.getId()); // Verify the status code restWrapper.assertStatusCodeIs(OK); + + // this is to ensure the change was actually applied, rather than simply trusting the object returned by PUT + FilePlanComponent renamedFolder = filePlanComponentAPI.getFilePlanComponent(folderToModify.getId()); // Verify the returned file plan component assertEquals(modified + folderToModify.getName(), renamedFolder.getName()); From 837d7e22c6a6c5e0a4d964044a30b5ef19580947 Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Wed, 16 Nov 2016 11:52:22 +0000 Subject: [PATCH 4/6] RM-4023: Delete test --- .../UnfiledRecordsFolderTests.java | 100 +++++++++++------- 1 file changed, 63 insertions(+), 37 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java index 97bc8a9fb7..532b81bfb1 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java @@ -11,14 +11,20 @@ */ package org.alfresco.rest.rm.fileplancomponents; -import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS; +import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS; import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.NAME; import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.NODE_TYPE; import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES; -import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_DESCRIPTION; -import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.*; -import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS; +import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentFields.PROPERTIES_TITLE; +import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.FILE_PLAN_TYPE; +import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.HOLD_CONTAINER_TYPE; +import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.HOLD_TYPE; +import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE; +import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE; +import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.TRANSFER_CONTAINER_TYPE; +import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE; +import static org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE; import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; import static org.springframework.http.HttpStatus.CREATED; @@ -28,22 +34,17 @@ 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.Arrays; import java.util.List; -import java.util.NoSuchElementException; import java.util.stream.Collectors; import com.google.gson.JsonObject; -import org.alfresco.rest.rm.base.BaseRestTest; import org.alfresco.rest.core.RestWrapper; +import org.alfresco.rest.rm.base.BaseRestTest; import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponent; -import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentEntry; import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentProperties; import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentType; import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentsCollection; @@ -76,9 +77,6 @@ public class UnfiledRecordsFolderTests extends BaseRestTest TRANSFER_CONTAINER_TYPE, UNFILED_CONTAINER_TYPE); - // Number of children (for children creation test) - private static final int NUMBER_OF_CHILDREN = 10; - /** * Given the unfiled record container root * When I create an unfiled record folder via the ReST API @@ -142,28 +140,28 @@ public class UnfiledRecordsFolderTests extends BaseRestTest String folderDescription = folderName + " Description"; INVALID_ROOT_TYPES.stream() - .peek(a -> logger.info("creating " + a.toString())) - .forEach(t -> { - JsonObject unfiledFolderProperties = buildObject() - .add(NAME, folderName) - .add(NODE_TYPE, t.toString()) - .addObject(PROPERTIES) - .add(PROPERTIES_TITLE, folderTitle) - .add(PROPERTIES_DESCRIPTION, folderDescription) - .end() - .getJson(); - try - { - filePlanComponentAPI.createFilePlanComponent(unfiledFolderProperties, - UNFILED_RECORDS_CONTAINER_ALIAS.toString()); - } - catch (Exception error) - { - } - - // Verify the status code - restWrapper.assertStatusCodeIs(UNPROCESSABLE_ENTITY); - }); + .peek(a -> logger.info("creating " + a.toString())) + .forEach(t -> { + JsonObject unfiledFolderProperties = buildObject() + .add(NAME, folderName) + .add(NODE_TYPE, t.toString()) + .addObject(PROPERTIES) + .add(PROPERTIES_TITLE, folderTitle) + .add(PROPERTIES_DESCRIPTION, folderDescription) + .end() + .getJson(); + try + { + filePlanComponentAPI.createFilePlanComponent(unfiledFolderProperties, + UNFILED_RECORDS_CONTAINER_ALIAS.toString()); + } + catch (Exception error) + { + } + + // Verify the status code + restWrapper.assertStatusCodeIs(UNPROCESSABLE_ENTITY); + }); } /** @@ -171,7 +169,7 @@ public class UnfiledRecordsFolderTests extends BaseRestTest * When I create an unfiled record folder via the ReST API * Then an unfiled record folder is created within the unfiled record folder * - * @throws Exception + * @throws Exception for failed actions */ @Test(description = "Child unfiled records folder can be created in a parent unfiled records folder") public void childUnfiledRecordsFolderCanBeCreated() throws Exception @@ -244,7 +242,7 @@ public class UnfiledRecordsFolderTests extends BaseRestTest * When I modify the unfiled record folder details via the ReST API * Then the details of the unfiled record folder are modified * - * @throws Exception + * @throws Exception for failed actions */ @Test(description = "Unfiled record folder") public void editUnfiledRecordsFolder() throws Exception @@ -279,4 +277,32 @@ public class UnfiledRecordsFolderTests extends BaseRestTest assertEquals(modified + folderToModify.getProperties().getTitle(), renamedFolder.getProperties().getTitle()); assertEquals(modified + folderToModify.getProperties().getDescription(), renamedFolder.getProperties().getDescription()); } + + /** + * Given an unfiled record folder + * When I delete the unfiled record folder via the ReST API + * Then the unfiled record folder is deleted + * + * @throws Exception for failed actions + */ + @Test(description = "Delete unfiled record folder") + public void deleteUnfiledRecordsFolder() throws Exception + { + RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); + String folderName = "Folder To Delete" + getRandomAlphanumeric(); + + // no need for fine control, create it using utility function + FilePlanComponent folderToModify = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), folderName); + assertEquals(folderName, folderToModify.getName()); + + // delete folderToModify + filePlanComponentAPI.deleteFilePlanComponent(folderToModify.getId()); + + // Verify the status code + restWrapper.assertStatusCodeIs(NO_CONTENT); + + // Deleted component should no longer be retrievable + filePlanComponentAPI.getFilePlanComponent(folderToModify.getId()); + restWrapper.assertStatusCodeIs(NOT_FOUND); + } } From 5262f62ed2068670e6f7a2bccb1dd717fa3bc283 Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Wed, 16 Nov 2016 11:59:23 +0000 Subject: [PATCH 5/6] RM-4023: javadoc + minor code tidy-up --- .../UnfiledRecordsFolderTests.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java index 532b81bfb1..e35f078103 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java @@ -57,7 +57,7 @@ import org.testng.annotations.Test; * Unfiled Records folder CRUD API tests * * @author Kristijan Conkas - * @since 1.0 + * @since 2.6 */ public class UnfiledRecordsFolderTests extends BaseRestTest { @@ -67,7 +67,7 @@ public class UnfiledRecordsFolderTests extends BaseRestTest @Autowired private DataUser dataUser; - /** invalid root level types, at root level these shouldn't be possible to create */ + /** invalid root level types, at unfiled records root level these shouldn't be possible to create */ private static final List INVALID_ROOT_TYPES = Arrays.asList( FILE_PLAN_TYPE, RECORD_CATEGORY_TYPE, @@ -181,7 +181,7 @@ public class UnfiledRecordsFolderTests extends BaseRestTest String childFolderTitle = childFolderName + " Title"; String childFolderDescription = childFolderName + " Description"; - // no need for fine control, create it using utility function + // No need for fine control, create it using utility function FilePlanComponent parentFolder = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), parentFolderName); assertEquals(parentFolderName, parentFolder.getName()); @@ -195,7 +195,7 @@ public class UnfiledRecordsFolderTests extends BaseRestTest .end() .getJson(); - // create it as a child of parentFolder + // Create it as a child of parentFolder FilePlanComponent childFolder = filePlanComponentAPI.createFilePlanComponent(unfiledFolderProperties, parentFolder.getId()); @@ -218,11 +218,11 @@ public class UnfiledRecordsFolderTests extends BaseRestTest assertEquals(childProperties.getTitle(), childFolderTitle); assertEquals(childProperties.getDescription(), childFolderDescription); - // does this child point to its parent? + // Does this child point to its parent? assertEquals(childFolder.getParentId(), parentFolder.getId()); - // does child's parent point to it? - // perform another call as our parentFolder was executed before childFolder existed + // Does child's parent point to it? + // Perform another call as our parentFolder had been executed before childFolder existed FilePlanComponentsCollection parentsChildren = filePlanComponentAPI.listChildComponents(parentFolder.getId()); restWrapper.assertStatusCodeIs(OK); List childIds = parentsChildren.getEntries() @@ -230,10 +230,10 @@ public class UnfiledRecordsFolderTests extends BaseRestTest .map(c -> c.getFilePlanComponent().getId()) .collect(Collectors.toList()); - // child folder is listed in parent + // Child folder is listed in parent assertTrue(childIds.contains(childFolder.getId())); - // there is only one child + // There should be only one child assertEquals(1, childIds.size()); } @@ -251,7 +251,7 @@ public class UnfiledRecordsFolderTests extends BaseRestTest String modified = "Modified "; String folderName = "Folder To Modify" + getRandomAlphanumeric(); - // no need for fine control, create it using utility function + // No need for fine control, create it using utility function FilePlanComponent folderToModify = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), folderName); assertEquals(folderName, folderToModify.getName()); @@ -269,7 +269,7 @@ public class UnfiledRecordsFolderTests extends BaseRestTest // Verify the status code restWrapper.assertStatusCodeIs(OK); - // this is to ensure the change was actually applied, rather than simply trusting the object returned by PUT + // This is to ensure the change was actually applied, rather than simply trusting the object returned by PUT FilePlanComponent renamedFolder = filePlanComponentAPI.getFilePlanComponent(folderToModify.getId()); // Verify the returned file plan component @@ -291,18 +291,18 @@ public class UnfiledRecordsFolderTests extends BaseRestTest RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); String folderName = "Folder To Delete" + getRandomAlphanumeric(); - // no need for fine control, create it using utility function - FilePlanComponent folderToModify = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), folderName); - assertEquals(folderName, folderToModify.getName()); + // Create folderToDelete + FilePlanComponent folderToDelete = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), folderName); + assertEquals(folderName, folderToDelete.getName()); - // delete folderToModify - filePlanComponentAPI.deleteFilePlanComponent(folderToModify.getId()); + // Delete folderToDelete + filePlanComponentAPI.deleteFilePlanComponent(folderToDelete.getId()); // Verify the status code restWrapper.assertStatusCodeIs(NO_CONTENT); // Deleted component should no longer be retrievable - filePlanComponentAPI.getFilePlanComponent(folderToModify.getId()); + filePlanComponentAPI.getFilePlanComponent(folderToDelete.getId()); restWrapper.assertStatusCodeIs(NOT_FOUND); } } From c5560f24db161f883e08fa37950825a58f9b77a2 Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Thu, 17 Nov 2016 09:23:35 +0000 Subject: [PATCH 6/6] RM-4023: fixed CI findings --- .../UnfiledRecordsFolderTests.java | 78 ++++++++++--------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java index e35f078103..542ebdb7b0 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/fileplancomponents/UnfiledRecordsFolderTests.java @@ -36,7 +36,6 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; -import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -51,6 +50,7 @@ import org.alfresco.rest.rm.model.fileplancomponents.FilePlanComponentsCollectio import org.alfresco.rest.rm.requests.FilePlanComponentAPI; import org.alfresco.utility.data.DataUser; import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; /** @@ -68,14 +68,18 @@ public class UnfiledRecordsFolderTests extends BaseRestTest private DataUser dataUser; /** invalid root level types, at unfiled records root level these shouldn't be possible to create */ - private static final List INVALID_ROOT_TYPES = Arrays.asList( - FILE_PLAN_TYPE, - RECORD_CATEGORY_TYPE, - RECORD_FOLDER_TYPE, - HOLD_TYPE, - HOLD_CONTAINER_TYPE, - TRANSFER_CONTAINER_TYPE, - UNFILED_CONTAINER_TYPE); + @DataProvider(name = "invalidRootTypes") + public Object[][] createData1() { + return new Object[][] { + { FILE_PLAN_TYPE }, + { RECORD_CATEGORY_TYPE }, + { RECORD_FOLDER_TYPE }, + { HOLD_TYPE }, + { HOLD_CONTAINER_TYPE }, + { TRANSFER_CONTAINER_TYPE }, + { UNFILED_CONTAINER_TYPE } + }; + } /** * Given the unfiled record container root @@ -94,7 +98,7 @@ public class UnfiledRecordsFolderTests extends BaseRestTest String folderTitle = folderName + " Title"; String folderDescription = folderName + " Description"; - // Build the record category properties + // Build unfiled records folder properties JsonObject unfiledFolderProperties = buildObject() .add(NAME, folderName) .add(NODE_TYPE, UNFILED_RECORD_FOLDER_TYPE.toString()) @@ -130,8 +134,12 @@ public class UnfiledRecordsFolderTests extends BaseRestTest /** * Negative test to verify only unfiled record folders can be created at root level */ - @Test(description = "Only unfiled records folders can be created at unfiled records root level") - public void onlyRecordFoldersCanBeCreatedAtUnfiledRecordsRoot() + @Test + ( + dataProvider = "invalidRootTypes", + description = "Only unfiled records folders can be created at unfiled records root level" + ) + public void onlyRecordFoldersCanBeCreatedAtUnfiledRecordsRoot(FilePlanComponentType componentType) { RestWrapper restWrapper = filePlanComponentAPI.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); @@ -139,29 +147,27 @@ public class UnfiledRecordsFolderTests extends BaseRestTest String folderTitle = folderName + " Title"; String folderDescription = folderName + " Description"; - INVALID_ROOT_TYPES.stream() - .peek(a -> logger.info("creating " + a.toString())) - .forEach(t -> { - JsonObject unfiledFolderProperties = buildObject() - .add(NAME, folderName) - .add(NODE_TYPE, t.toString()) - .addObject(PROPERTIES) - .add(PROPERTIES_TITLE, folderTitle) - .add(PROPERTIES_DESCRIPTION, folderDescription) - .end() - .getJson(); - try - { - filePlanComponentAPI.createFilePlanComponent(unfiledFolderProperties, - UNFILED_RECORDS_CONTAINER_ALIAS.toString()); - } - catch (Exception error) - { - } - - // Verify the status code - restWrapper.assertStatusCodeIs(UNPROCESSABLE_ENTITY); - }); + logger.info("creating " + componentType.toString()); + + JsonObject unfiledFolderProperties = buildObject() + .add(NAME, folderName) + .add(NODE_TYPE, componentType.toString()) + .addObject(PROPERTIES) + .add(PROPERTIES_TITLE, folderTitle) + .add(PROPERTIES_DESCRIPTION, folderDescription) + .end() + .getJson(); + try + { + filePlanComponentAPI.createFilePlanComponent(unfiledFolderProperties, + UNFILED_RECORDS_CONTAINER_ALIAS.toString()); + } + catch (Exception error) + { + } + + // Verify the status code + restWrapper.assertStatusCodeIs(UNPROCESSABLE_ENTITY); } /** @@ -185,7 +191,7 @@ public class UnfiledRecordsFolderTests extends BaseRestTest FilePlanComponent parentFolder = createUnfiledRecordsFolder(UNFILED_RECORDS_CONTAINER_ALIAS.toString(), parentFolderName); assertEquals(parentFolderName, parentFolder.getName()); - // Build the record category properties + // Build the unfiled records folder properties JsonObject unfiledFolderProperties = buildObject() .add(NAME, childFolderName) .add(NODE_TYPE, UNFILED_RECORD_FOLDER_TYPE.toString())