From 6f43b2b6ad0b1504eab90ba4c9b1f12e3e4348a4 Mon Sep 17 00:00:00 2001 From: Cristina Jalba Date: Wed, 28 Sep 2016 13:39:14 +0300 Subject: [PATCH 1/9] TAS-903 updateComment with admin --- .../rest/comments/UpdateCommentsTest.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 e2e-test/java/org/alfresco/rest/comments/UpdateCommentsTest.java diff --git a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsTest.java b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsTest.java new file mode 100644 index 000000000..7e0d3dd0e --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsTest.java @@ -0,0 +1,53 @@ +package org.alfresco.rest.comments; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestCommentModel; +import org.alfresco.rest.requests.RestCommentsApi; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +@Test(groups = { "rest-api", "comments", "sanity" }) +public class UpdateCommentsTest extends RestTest +{ + + @Autowired + RestCommentsApi commentsAPI; + + @Autowired + DataUser dataUser; + + private UserModel adminUserModel; + private FileModel document; + private SiteModel siteModel; + private RestCommentModel commentModel; + + @BeforeClass + public void initTest() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + restClient.authenticateUser(adminUserModel); + siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + commentsAPI.useRestClient(restClient); + document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + commentModel = commentsAPI.addComment(document.getNodeRef(), "This is a new comment"); + } + + @TestRail(section = { "rest-api", + "comments" }, executionType = ExecutionType.SANITY, description = "Verify Admin user updates comments with Rest API and status code is 200") + public void adminIsAbleToUpdateComments() throws JsonToModelConversionException, Exception + { + commentsAPI.updateComment(document.getNodeRef(), commentModel.getId(), commentModel.getContent()); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + } + +} From 4e133b2a921fc31788319a985e461e276b9e4b6c Mon Sep 17 00:00:00 2001 From: Cristina Jalba Date: Wed, 28 Sep 2016 13:42:17 +0300 Subject: [PATCH 2/9] TAS-926 updateComment with Manager --- ...Test.java => UpdateCommentsSanityTest.java} | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) rename e2e-test/java/org/alfresco/rest/comments/{UpdateCommentsTest.java => UpdateCommentsSanityTest.java} (65%) diff --git a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsTest.java b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java similarity index 65% rename from e2e-test/java/org/alfresco/rest/comments/UpdateCommentsTest.java rename to e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java index 7e0d3dd0e..c9db75e0e 100644 --- a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsTest.java +++ b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java @@ -1,10 +1,14 @@ package org.alfresco.rest.comments; +import java.util.Arrays; +import java.util.HashMap; + import org.alfresco.dataprep.CMISUtil.DocumentType; import org.alfresco.rest.RestTest; import org.alfresco.rest.exception.JsonToModelConversionException; import org.alfresco.rest.model.RestCommentModel; import org.alfresco.rest.requests.RestCommentsApi; +import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.data.DataUser; import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.SiteModel; @@ -17,7 +21,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @Test(groups = { "rest-api", "comments", "sanity" }) -public class UpdateCommentsTest extends RestTest +public class UpdateCommentsSanityTest extends RestTest { @Autowired @@ -30,6 +34,7 @@ public class UpdateCommentsTest extends RestTest private FileModel document; private SiteModel siteModel; private RestCommentModel commentModel; + private HashMap usersWithRoles; @BeforeClass public void initTest() throws Exception @@ -40,6 +45,8 @@ public class UpdateCommentsTest extends RestTest commentsAPI.useRestClient(restClient); document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); commentModel = commentsAPI.addComment(document.getNodeRef(), "This is a new comment"); + + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, Arrays.asList(UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor)); } @TestRail(section = { "rest-api", @@ -49,5 +56,14 @@ public class UpdateCommentsTest extends RestTest commentsAPI.updateComment(document.getNodeRef(), commentModel.getId(), commentModel.getContent()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); } + + @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, + description= "Verify Manager user updates comments created by admin user with Rest API and status code is 200") + public void managerIsAbleToUpdateComment() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); + commentsAPI.updateComment(document.getNodeRef(), commentModel.getId(), commentModel.getContent()); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + } } From d5ca004407ebf62ce88517eee8fcb6865100e0cf Mon Sep 17 00:00:00 2001 From: Cristina Jalba Date: Wed, 28 Sep 2016 13:43:46 +0300 Subject: [PATCH 3/9] TAS-928 --- .../comments/UpdateCommentsSanityTest.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java index c9db75e0e..551e26dfe 100644 --- a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java +++ b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java @@ -45,8 +45,9 @@ public class UpdateCommentsSanityTest extends RestTest commentsAPI.useRestClient(restClient); document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); commentModel = commentsAPI.addComment(document.getNodeRef(), "This is a new comment"); - - usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, Arrays.asList(UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor)); + + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, + Arrays.asList(UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor)); } @TestRail(section = { "rest-api", @@ -56,9 +57,9 @@ public class UpdateCommentsSanityTest extends RestTest commentsAPI.updateComment(document.getNodeRef(), commentModel.getId(), commentModel.getContent()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); } - - @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, - description= "Verify Manager user updates comments created by admin user with Rest API and status code is 200") + + @TestRail(section = { "rest-api", + "comments" }, executionType = ExecutionType.SANITY, description = "Verify Manager user updates comments created by admin user with Rest API and status code is 200") public void managerIsAbleToUpdateComment() throws JsonToModelConversionException, Exception { restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); @@ -66,4 +67,13 @@ public class UpdateCommentsSanityTest extends RestTest commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); } + @TestRail(section = { "rest-api", + "comments" }, executionType = ExecutionType.SANITY, description = "Verify Contributor user updates comments created by admin user with Rest API and status code is 200") + public void contributorIsAbleToUpdateComment() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.get(UserRole.SiteContributor)); + commentsAPI.updateComment(document.getNodeRef(), commentModel.getId(), "This is the updated comment with Contributor user"); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN.toString()); + } + } From cffdbe4a4e71cd08c3104bdeb1529ce2b18c9c32 Mon Sep 17 00:00:00 2001 From: Cristina Jalba Date: Wed, 28 Sep 2016 13:45:02 +0300 Subject: [PATCH 4/9] TAS-929 updateComment with Consumer --- .../alfresco/rest/comments/UpdateCommentsSanityTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java index 551e26dfe..8281cd17b 100644 --- a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java +++ b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java @@ -76,4 +76,13 @@ public class UpdateCommentsSanityTest extends RestTest commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN.toString()); } + @TestRail(section = { "rest-api", + "comments" }, executionType = ExecutionType.SANITY, description = "Verify Consumer user updates comments created by admin user with Rest API and status code is 200") + public void consumerIsAbleToUpdateComment() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.get(UserRole.SiteConsumer)); + commentsAPI.updateComment(document.getNodeRef(), commentModel.getId(), commentModel.getContent()); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN.toString()); + } + } From 5db79de2f5518107964690f3506c52a433fcc62b Mon Sep 17 00:00:00 2001 From: Cristina Jalba Date: Wed, 28 Sep 2016 15:37:42 +0300 Subject: [PATCH 5/9] TAS-931 failed authentication call returns status code 401 with Manager role --- .../rest/comments/UpdateCommentsSanityTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java index 8281cd17b..379d8cf51 100644 --- a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java +++ b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java @@ -85,4 +85,14 @@ public class UpdateCommentsSanityTest extends RestTest commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN.toString()); } + @TestRail(section = { "rest-api", + "comments" }, executionType = ExecutionType.SANITY, description = "Verify Manager user gets status code 401 if authentication call fails") + public void managerIsNotAbleToUpdateCommentIfAuthenticationFails() throws JsonToModelConversionException, Exception + { + UserModel incorrectUserModel = new UserModel("userName", "password"); + restClient.authenticateUser(incorrectUserModel); + commentsAPI.getNodeComments(document.getNodeRef()); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED.toString()); + } + } From 3d6f93d2357c908dd8842ca124af0d2faaf76799 Mon Sep 17 00:00:00 2001 From: Cristina Jalba Date: Wed, 28 Sep 2016 15:43:59 +0300 Subject: [PATCH 6/9] TAS-932 status 404 if nodeId doesn not exist --- .../alfresco/rest/comments/UpdateCommentsSanityTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java index 379d8cf51..f982b4136 100644 --- a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java +++ b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java @@ -94,5 +94,14 @@ public class UpdateCommentsSanityTest extends RestTest commentsAPI.getNodeComments(document.getNodeRef()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED.toString()); } + + @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, + description= "Verify if nodeId is not set the status code is 404") + public void canNotUpdateCommentIfNodeIdIsNotSet() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUserModel); + commentsAPI.updateComment("unexistingId", commentModel.getId(), commentModel.getContent()); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.NOT_FOUND.toString()); + } } From c7091d7f2a7461f8c28853b645aa4ae1ec65fd20 Mon Sep 17 00:00:00 2001 From: Cristina Jalba Date: Wed, 28 Sep 2016 15:44:51 +0300 Subject: [PATCH 7/9] TAS-933 status 404 if commentId does not exist --- .../alfresco/rest/comments/UpdateCommentsSanityTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java index f982b4136..fe79d5cbd 100644 --- a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java +++ b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java @@ -103,5 +103,14 @@ public class UpdateCommentsSanityTest extends RestTest commentsAPI.updateComment("unexistingId", commentModel.getId(), commentModel.getContent()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.NOT_FOUND.toString()); } + + @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, + description= "Verify if commentId is not set the status code is 404") + public void canNotUpdateCommentIfCommentIdIsNotSet() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUserModel); + commentsAPI.updateComment(document.getNodeRef(), "unexistingId", commentModel.getContent()); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.NOT_FOUND.toString()); + } } From a65db3e70bd278f06025303996940ba5eb79ba4c Mon Sep 17 00:00:00 2001 From: Cristina Jalba Date: Wed, 28 Sep 2016 15:46:11 +0300 Subject: [PATCH 8/9] TAS-927 updateComment with Collaborator --- .../rest/comments/UpdateCommentsSanityTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java index fe79d5cbd..acbc78d8e 100644 --- a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java +++ b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java @@ -84,6 +84,16 @@ public class UpdateCommentsSanityTest extends RestTest commentsAPI.updateComment(document.getNodeRef(), commentModel.getId(), commentModel.getContent()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN.toString()); } + + @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, + description= "Verify Collaborator user updates comments created by admin user with Rest API and status code is 200") + public void collaboratorIsAbleToUpdateComment() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.get(UserRole.SiteCollaborator)); + RestCommentModel commentEntry = commentsAPI.updateComment(document.getNodeRef(), commentModel.getId(), "This is the updated comment with Collaborator user"); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN.toString()); + commentEntry.assertCommentContentIs("This is the updated comment with Collaborator user"); + } @TestRail(section = { "rest-api", "comments" }, executionType = ExecutionType.SANITY, description = "Verify Manager user gets status code 401 if authentication call fails") From c1b62b69292a3093cad233c2a5e772a8e154af13 Mon Sep 17 00:00:00 2001 From: Cristina Jalba Date: Wed, 28 Sep 2016 16:07:10 +0300 Subject: [PATCH 9/9] Formatting the code --- .../comments/UpdateCommentsSanityTest.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java index acbc78d8e..1c141f75b 100644 --- a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java +++ b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTest.java @@ -84,13 +84,14 @@ public class UpdateCommentsSanityTest extends RestTest commentsAPI.updateComment(document.getNodeRef(), commentModel.getId(), commentModel.getContent()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN.toString()); } - - @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, - description= "Verify Collaborator user updates comments created by admin user with Rest API and status code is 200") + + @TestRail(section = { "rest-api", + "comments" }, executionType = ExecutionType.SANITY, description = "Verify Collaborator user updates comments created by admin user with Rest API and status code is 200") public void collaboratorIsAbleToUpdateComment() throws JsonToModelConversionException, Exception { restClient.authenticateUser(usersWithRoles.get(UserRole.SiteCollaborator)); - RestCommentModel commentEntry = commentsAPI.updateComment(document.getNodeRef(), commentModel.getId(), "This is the updated comment with Collaborator user"); + RestCommentModel commentEntry = commentsAPI.updateComment(document.getNodeRef(), commentModel.getId(), + "This is the updated comment with Collaborator user"); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN.toString()); commentEntry.assertCommentContentIs("This is the updated comment with Collaborator user"); } @@ -104,18 +105,16 @@ public class UpdateCommentsSanityTest extends RestTest commentsAPI.getNodeComments(document.getNodeRef()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED.toString()); } - - @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, - description= "Verify if nodeId is not set the status code is 404") + + @TestRail(section = { "rest-api", "comments" }, executionType = ExecutionType.SANITY, description = "Verify if nodeId is not set the status code is 404") public void canNotUpdateCommentIfNodeIdIsNotSet() throws JsonToModelConversionException, Exception { restClient.authenticateUser(adminUserModel); commentsAPI.updateComment("unexistingId", commentModel.getId(), commentModel.getContent()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.NOT_FOUND.toString()); } - - @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, - description= "Verify if commentId is not set the status code is 404") + + @TestRail(section = { "rest-api", "comments" }, executionType = ExecutionType.SANITY, description = "Verify if commentId is not set the status code is 404") public void canNotUpdateCommentIfCommentIdIsNotSet() throws JsonToModelConversionException, Exception { restClient.authenticateUser(adminUserModel);