From 62a6f1edd378cd87c611556f475113b82ab1d0c5 Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Thu, 27 Oct 2016 12:04:03 +0100 Subject: [PATCH 1/4] RM-3964: more verification for positive tests. --- .../alfresco/com/FilePlanComponentFields.java | 1 + .../rest/model/FilePlanComponent.java | 38 ++++++++++ .../model/FilePlanComponentCreatedByUser.java | 51 ++++++++++++++ .../model/FilePlanComponentProperties.java | 3 - .../RecordCategoryTest.java | 69 +++++++++++++++---- 5 files changed, 147 insertions(+), 15 deletions(-) create mode 100644 src/main/java/org/alfresco/rest/model/FilePlanComponentCreatedByUser.java diff --git a/src/main/java/org/alfresco/com/FilePlanComponentFields.java b/src/main/java/org/alfresco/com/FilePlanComponentFields.java index 76b91035c4..473fd396ed 100644 --- a/src/main/java/org/alfresco/com/FilePlanComponentFields.java +++ b/src/main/java/org/alfresco/com/FilePlanComponentFields.java @@ -21,6 +21,7 @@ public class FilePlanComponentFields { public static final String NAME = "name"; public static final String NODE_TYPE = "nodeType"; + public static final String NODE_PARENT_ID = "parentId"; public static final String PROPERTIES = "properties"; public static final String PROPERTIES_TITLE = "cm:title"; public static final String PROPERTIES_VITAL_RECORD_INDICATOR = "rma:vitalRecordIndicator"; diff --git a/src/main/java/org/alfresco/rest/model/FilePlanComponent.java b/src/main/java/org/alfresco/rest/model/FilePlanComponent.java index efe28755fc..36b48489f9 100644 --- a/src/main/java/org/alfresco/rest/model/FilePlanComponent.java +++ b/src/main/java/org/alfresco/rest/model/FilePlanComponent.java @@ -13,6 +13,8 @@ package org.alfresco.rest.model; import static org.alfresco.com.FilePlanComponentFields.PROPERTIES; +import java.util.List; + import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; @@ -42,8 +44,12 @@ public class FilePlanComponent private boolean hasRetentionSchedule; + private List aspectNames; + @JsonProperty(PROPERTIES) private FilePlanComponentProperties properties; + + private FilePlanComponentCreatedByUser createdByUser; /** * @return the id @@ -188,4 +194,36 @@ public class FilePlanComponent { this.properties = properties; } + + /** + * @return the aspectNames + */ + public List getAspectNames() + { + return this.aspectNames; + } + + /** + * @param aspectNames the aspectNames to set + */ + public void setAspectNames(List aspectNames) + { + this.aspectNames = aspectNames; + } + + /** + * @return the createdByUser + */ + public FilePlanComponentCreatedByUser getCreatedByUser() + { + return this.createdByUser; + } + + /** + * @param createdByUser the createdByUser to set + */ + public void setCreatedByUser(FilePlanComponentCreatedByUser createdByUser) + { + this.createdByUser = createdByUser; + } } diff --git a/src/main/java/org/alfresco/rest/model/FilePlanComponentCreatedByUser.java b/src/main/java/org/alfresco/rest/model/FilePlanComponentCreatedByUser.java new file mode 100644 index 0000000000..37994c350e --- /dev/null +++ b/src/main/java/org/alfresco/rest/model/FilePlanComponentCreatedByUser.java @@ -0,0 +1,51 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.rest.model; + +/** + * POJO for file plan component created by object + * @author Kristijan Conkas + * @since 1.0 + */ +public class FilePlanComponentCreatedByUser +{ + private String id; + private String displayName; + /** + * @return the id + */ + public String getId() + { + return this.id; + } + /** + * @param id the id to set + */ + public void setId(String id) + { + this.id = id; + } + /** + * @return the displayName + */ + public String getDisplayName() + { + return this.displayName; + } + /** + * @param displayName the displayName to set + */ + public void setDisplayName(String displayName) + { + this.displayName = displayName; + } +} diff --git a/src/main/java/org/alfresco/rest/model/FilePlanComponentProperties.java b/src/main/java/org/alfresco/rest/model/FilePlanComponentProperties.java index dbb1cbb82f..89357f51a8 100644 --- a/src/main/java/org/alfresco/rest/model/FilePlanComponentProperties.java +++ b/src/main/java/org/alfresco/rest/model/FilePlanComponentProperties.java @@ -18,9 +18,6 @@ import static org.alfresco.com.FilePlanComponentFields.PROPERTIES_VITAL_RECORD_I import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; - /** * POJO for file plan component properties * diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java index 8b74076d36..b27353a3d4 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java @@ -23,8 +23,10 @@ import static org.alfresco.com.FilePlanComponentType.RECORD_FOLDER_TYPE; import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.NO_CONTENT; +import static org.springframework.http.HttpStatus.NOT_FOUND; import static org.springframework.http.HttpStatus.OK; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; @@ -46,6 +48,7 @@ import org.alfresco.rest.requests.FilePlanComponentApi; import org.alfresco.utility.data.DataUser; import org.alfresco.utility.data.RandomData; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; import org.testng.annotations.Test; /** @@ -76,7 +79,7 @@ public class RecordCategoryTest extends BaseRestTest ( description = "Create category as authorised user" ) - public void createCategoryAsAuthorisedUser() throws Exception + public void createCategoryTest() throws Exception { RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); @@ -102,10 +105,13 @@ public class RecordCategoryTest extends BaseRestTest assertTrue(filePlanComponent.isIsCategory()); assertEquals(filePlanComponent.getName(), categoryName); assertEquals(filePlanComponent.getNodeType(), RECORD_CATEGORY_TYPE.toString()); - + assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername()); + // Verify the returned file plan component properties FilePlanComponentProperties filePlanComponentProperties = filePlanComponent.getProperties(); assertEquals(filePlanComponentProperties.getTitle(), categoryTitle); + + logger.info("aspects: " + filePlanComponent.getAspectNames()); } /** @@ -118,12 +124,11 @@ public class RecordCategoryTest extends BaseRestTest ( description = "Rename category as authorised user" ) - public void renameCategoryAsAuthorisedUser() throws Exception + public void renameCategory() throws Exception { RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); // Create record category first - String categoryName = "Category name " + randomUUID().toString().substring(0, 8); String categoryTitle = "Category title " + randomUUID().toString().substring(0, 8); @@ -154,6 +159,11 @@ public class RecordCategoryTest extends BaseRestTest // Verify the returned file plan component assertEquals(renamedFilePlanComponent.getName(), newCategoryName); + + // get actual FILE_PLAN_ALIAS id + FilePlanComponent parentComponent = filePlanComponentApi.getFilePlanComponent(FILE_PLAN_ALIAS.toString()); + // verify renamed component still has this parent + assertEquals(renamedFilePlanComponent.getParentId(), parentComponent.getId()); } /** @@ -166,12 +176,11 @@ public class RecordCategoryTest extends BaseRestTest ( description = "Delete category as authorised user" ) - public void deleteCategoryAsAuthorisedUser() throws Exception + public void deleteCategory() throws Exception { RestWrapper restWrapper = filePlanComponentApi.usingRestWrapper().authenticateUser(dataUser.getAdminUser()); // Create record category first - String categoryName = "Category name " + randomUUID().toString().substring(0, 8); String categoryTitle = "Category title " + randomUUID().toString().substring(0, 8); @@ -192,6 +201,10 @@ public class RecordCategoryTest extends BaseRestTest // Verify the status code restWrapper.assertStatusCodeIs(NO_CONTENT); + + // deleted component should no longer be retrievable + filePlanComponentApi.getFilePlanComponent(filePlanComponent.getId()); + restWrapper.assertStatusCodeIs(NOT_FOUND); } /** @@ -215,6 +228,13 @@ public class RecordCategoryTest extends BaseRestTest // child category created? assertNotNull(childCategory.getId()); + + // verify child category + assertEquals(childCategory.getParentId(), rootCategory.getId()); + assertTrue(childCategory.isIsCategory()); + assertFalse(childCategory.isIsFile()); + assertFalse(childCategory.isIsRecordFolder()); + assertEquals(childCategory.getNodeType(), RECORD_CATEGORY_TYPE.toString()); } /** @@ -233,7 +253,7 @@ public class RecordCategoryTest extends BaseRestTest { // create root level category FilePlanComponent rootCategory = createCategory(FILE_PLAN_ALIAS.toString(), RandomData.getRandomAlphanumeric()); - assertNotNull(rootCategory.getId()); + assertNotNull(rootCategory.getId()); // add child categories/folders ArrayList children = new ArrayList(); @@ -253,25 +273,50 @@ public class RecordCategoryTest extends BaseRestTest FilePlanComponentsCollection apiChildren = filePlanComponentApi.listChildComponents(rootCategory.getId()); restWrapper.assertStatusCodeIs(OK); + logger.info("parent: " + rootCategory.getId()); + // check listed children against created list - List childrenApi = apiChildren.getEntries(); - childrenApi.forEach(c -> + apiChildren.getEntries().forEach(c -> { FilePlanComponent filePlanComponent = c.getFilePlanComponent(); assertNotNull(filePlanComponent.getId()); - - logger.info(c + " id=" + filePlanComponent.getId() + " name=" + filePlanComponent.getName() + " properties=" + filePlanComponent.getProperties()); + logger.info("checking child " + filePlanComponent.getId()); try { + // find this child in created children list FilePlanComponent createdComponent = children.stream() - .filter(child -> child.getId().compareTo(filePlanComponent.getId()) == 0) + .filter(child -> child.getId().equals(filePlanComponent.getId())) .findFirst() .get(); + // created by + assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername()); + + // is parent Id set correctly? + assertEquals(filePlanComponent.getParentId(), rootCategory.getId()); + + // only categories or folders have been created + assertFalse(filePlanComponent.isIsFile()); + + // boolean properties related to node type + // only RECORD_CATEGORY_TYPE and RECORD_FOLDER_TYPE have been created + if (filePlanComponent.getNodeType().equals(RECORD_CATEGORY_TYPE.toString())) + { + assertTrue(filePlanComponent.isIsCategory()); + assertFalse(filePlanComponent.isIsRecordFolder()); + } + else + { + assertTrue(filePlanComponent.isIsRecordFolder()); + assertFalse(filePlanComponent.isIsCategory()); + } + // does returned object have the same contents as the created one? assertEquals(createdComponent.getName(), filePlanComponent.getName()); assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType()); + + // verify properties assertEquals(createdComponent.getProperties().getTitle(), filePlanComponent.getProperties().getTitle()); } catch (NoSuchElementException e) From 524b771342553d0c5ec977246a3766fe4fb78ca6 Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Thu, 27 Oct 2016 15:27:35 +0100 Subject: [PATCH 2/4] RM-3964: test updates. --- .../RecordCategoryTest.java | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java index b27353a3d4..e2f31ef8e3 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java @@ -22,8 +22,8 @@ import static org.alfresco.com.FilePlanComponentType.RECORD_CATEGORY_TYPE; import static org.alfresco.com.FilePlanComponentType.RECORD_FOLDER_TYPE; import static org.jglue.fluentjson.JsonBuilderFactory.buildObject; import static org.springframework.http.HttpStatus.CREATED; -import static org.springframework.http.HttpStatus.NO_CONTENT; import static org.springframework.http.HttpStatus.NOT_FOUND; +import static org.springframework.http.HttpStatus.NO_CONTENT; import static org.springframework.http.HttpStatus.OK; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; @@ -32,7 +32,6 @@ import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; import java.util.ArrayList; -import java.util.List; import java.util.NoSuchElementException; import com.google.gson.JsonObject; @@ -40,7 +39,6 @@ import com.google.gson.JsonObject; import org.alfresco.com.FilePlanComponentType; import org.alfresco.rest.BaseRestTest; import org.alfresco.rest.core.RestWrapper; -import org.alfresco.rest.model.FilePlanComponentEntry; import org.alfresco.rest.model.FilePlanComponent; import org.alfresco.rest.model.FilePlanComponentProperties; import org.alfresco.rest.model.FilePlanComponentsCollection; @@ -48,7 +46,6 @@ import org.alfresco.rest.requests.FilePlanComponentApi; import org.alfresco.utility.data.DataUser; import org.alfresco.utility.data.RandomData; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; import org.testng.annotations.Test; /** @@ -103,8 +100,13 @@ public class RecordCategoryTest extends BaseRestTest // Verify the returned file plan component assertTrue(filePlanComponent.isIsCategory()); + assertFalse(filePlanComponent.isIsFile()); + assertFalse(filePlanComponent.isIsRecordFolder()); + assertEquals(filePlanComponent.getName(), categoryName); assertEquals(filePlanComponent.getNodeType(), RECORD_CATEGORY_TYPE.toString()); + assertFalse(filePlanComponent.isHasRetentionSchedule()); + assertEquals(filePlanComponent.getCreatedByUser().getId(), dataUser.getAdminUser().getUsername()); // Verify the returned file plan component properties @@ -317,7 +319,7 @@ public class RecordCategoryTest extends BaseRestTest assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType()); // verify properties - assertEquals(createdComponent.getProperties().getTitle(), filePlanComponent.getProperties().getTitle()); + //assertEquals(createdComponent.getProperties().getTitle(), filePlanComponent.getProperties().getTitle()); } catch (NoSuchElementException e) { @@ -337,17 +339,6 @@ public class RecordCategoryTest extends BaseRestTest return createComponent(parentCategoryId, categoryName, RECORD_CATEGORY_TYPE); } - /** - * Helper method to create child folder - * @param parentComponentId parent category or folder id - * @param folderName new folder name - * @throws Exception on unsuccessful folder creation - */ - private FilePlanComponent createFolder(String parentComponentId, String folderName) throws Exception - { - return createComponent(parentComponentId, folderName, RECORD_FOLDER_TYPE); - } - /** * Helper method to create generic child component * @param parentComponentId From c611f6ff87fb3ea40b87cd9609109269ca20217a Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Fri, 28 Oct 2016 09:20:51 +0100 Subject: [PATCH 3/4] RM-3964: fixed a FIXME. --- .../com/fileplancomponents/FilePlanComponentFields.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentFields.java b/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentFields.java index 71495ca033..0981bcfc2a 100644 --- a/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentFields.java +++ b/src/main/java/org/alfresco/com/fileplancomponents/FilePlanComponentFields.java @@ -12,7 +12,7 @@ package org.alfresco.com.fileplancomponents; /** - * FIXME: Document me :) + * File plan component field names constants * * @author Tuna Aksoy * @since 1.0 From d50590c5f0375c10843419c5835eb0d7ee2d4e3f Mon Sep 17 00:00:00 2001 From: Kristijan Conkas Date: Fri, 28 Oct 2016 11:53:04 +0100 Subject: [PATCH 4/4] RM-3964: Update further to code inspection comments. --- .../rest/fileplancomponents/RecordCategoryTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java index c969906e79..9744ac702e 100644 --- a/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java +++ b/src/test/java/org/alfresco/rest/fileplancomponents/RecordCategoryTest.java @@ -74,7 +74,7 @@ public class RecordCategoryTest extends BaseRestTest */ @Test ( - description = "Create category as authorised user" + description = "Create root category" ) public void createCategoryTest() throws Exception { @@ -124,7 +124,7 @@ public class RecordCategoryTest extends BaseRestTest */ @Test ( - description = "Rename category as authorised user" + description = "Rename root category" ) public void renameCategory() throws Exception { @@ -176,7 +176,7 @@ public class RecordCategoryTest extends BaseRestTest */ @Test ( - description = "Delete category as authorised user" + description = "Delete category" ) public void deleteCategory() throws Exception {