From 7afbe20d0cb624b44eb133f4a87eacc7576354fa Mon Sep 17 00:00:00 2001 From: Andrei Forascu Date: Wed, 4 Oct 2017 15:03:11 +0300 Subject: [PATCH] REPO-2755: REST API & CMIS TAS sanity builds: - refactored RestAPI "Comments" API tests to be included in a single class per endpoint (not separate Sanity/Core/Full tests) (3) --- .../rest/comments/DeleteCommentTests.java | 592 +++++------ .../rest/comments/GetCommentsTests.java | 848 ++++++++-------- .../rest/comments/UpdateCommentTests.java | 924 +++++++++--------- 3 files changed, 1182 insertions(+), 1182 deletions(-) diff --git a/e2e-test/java/org/alfresco/rest/comments/DeleteCommentTests.java b/e2e-test/java/org/alfresco/rest/comments/DeleteCommentTests.java index 3762e6238..0500bf2a1 100644 --- a/e2e-test/java/org/alfresco/rest/comments/DeleteCommentTests.java +++ b/e2e-test/java/org/alfresco/rest/comments/DeleteCommentTests.java @@ -1,296 +1,296 @@ -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.model.RestCommentModelsCollection; -import org.alfresco.rest.model.RestErrorModel; -import org.alfresco.utility.constants.UserRole; -import org.alfresco.utility.data.DataUser.ListUserWithRoles; -import org.alfresco.utility.model.FileModel; -import org.alfresco.utility.model.SiteModel; -import org.alfresco.utility.model.TestGroup; -import org.alfresco.utility.model.UserModel; -import org.alfresco.utility.report.Bug; -import org.alfresco.utility.testrail.ExecutionType; -import org.alfresco.utility.testrail.annotation.TestRail; -import org.springframework.http.HttpStatus; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -public class DeleteCommentTests extends RestTest -{ - private UserModel adminUserModel, networkUserModel; - - private FileModel document; - private SiteModel siteModel; - private RestCommentModelsCollection comments; - private RestCommentModel commentModel; - private ListUserWithRoles usersWithRoles; - private String commentText = "This is a new comment"; - - @BeforeClass(alwaysRun=true) - public void dataPreparation() throws Exception - { - adminUserModel = dataUser.getAdminUser(); - networkUserModel = dataUser.createRandomTestUser(); - restClient.authenticateUser(adminUserModel); - siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); - document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel,UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); - } - - @TestRail(section = { TestGroup.REST_API, - TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify Admin user deletes comments with Rest API and status code is 204") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) - public void adminIsAbleToDeleteComments() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(adminUserModel); - commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment"); - restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); - restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); - } - - @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify User gets status code 401 if authentication call fails") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) - @Bug(id="MNT-16904", description = "It fails only on environment with tenants") - public void userIsNotAbleToDeleteCommentIfAuthenticationFails() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(adminUserModel); - commentModel = restClient.withCoreAPI().usingResource(document).addComment("New comment addded by admin"); - UserModel nonexistentModel = new UserModel("nonexistentUser", "nonexistentPassword"); - restClient.authenticateUser(nonexistentModel); - restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); - restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError() - .containsSummary(RestErrorModel.AUTHENTICATION_FAILED); - } - - @TestRail(section = { TestGroup.REST_API, - TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Manager user deletes own comments and status code is 204") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) - public void managerIsAbleToDeleteComments() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); - commentModel = restClient.withCoreAPI().usingResource(document).addComment("New comment added by Manager"); - restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); - restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); - } - - @TestRail(section = { TestGroup.REST_API, - TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Collaborator user deletes own comments and status code is 204") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) - public void collaboratorIsAbleToDeleteComments() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); - commentModel = restClient.withCoreAPI().usingResource(document).addComment("New comment added by Collaborator"); - restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); - restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); - } - - @TestRail(section = { TestGroup.REST_API, - TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Contributor user deletes own comments and status code is 204") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) - public void contributorIsAbleToDeleteComments() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); - commentModel = restClient.withCoreAPI().usingResource(document).addComment("New comment added by Contributor"); - restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); - restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); - } - - @TestRail(section = { TestGroup.REST_API, - TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Consumer user can't delete comments created by admin user and status code is 403") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) - public void consumerIsNotAbleToDeleteComments() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(adminUserModel); - commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment"); - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); - restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); - restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) - .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); - } - - @TestRail(section = { TestGroup.REST_API, - TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Admin user can't delete comments with inexistent ID and status code is 404") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) - public void userIsNotAbleToDeleteInexistentComment() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(adminUserModel); - commentModel = new RestCommentModel(); - commentModel.setId("inexistent"); - restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); - restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); - } - - @TestRail(section = { TestGroup.REST_API, - TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Admin user can't delete comments with inexistend NodeId and status code is 404") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) - public void userIsNotAbleToDeleteCommentWithInexistentNodeId() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(adminUserModel); - commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment"); - FileModel inexistentDocument = new FileModel(); - inexistentDocument.setNodeRef("inexistent"); - restClient.withCoreAPI().usingResource(inexistentDocument).deleteComment(commentModel); - restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); - } - - @TestRail(section = { TestGroup.REST_API, - TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Admin user can't delete deleted comments and status code is 404") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) - public void userIsNotAbleToDeleteDeletedComment() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(adminUserModel); - commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment"); - restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); - restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); - restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); - restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); - } - - @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, - executionType = ExecutionType.REGRESSION, description = "Verify Manager user deletes comment created by admin" - + " and status code is 204. Check with getComments for validation") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void managerIsAbleToDeleteCommentCreatedByOthers() throws JsonToModelConversionException, Exception - { - FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - - commentModel = restClient.authenticateUser(adminUserModel) - .withCoreAPI().usingResource(file).addComment(commentText); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) - .withCoreAPI().usingResource(file).deleteComment(commentModel); - restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); - - comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().entriesListDoesNotContain("content", commentText); - comments.getPagination().assertThat().field("totalItems").is("0").and().field("count").is("0"); - } - - @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, - executionType = ExecutionType.REGRESSION, description = "Verify Collaborator user can delete comment created by self" - + " and status code is 204. Check with getComments for validation") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void collaboratorIsAbleToDeleteCommentCreatedBySelf() throws JsonToModelConversionException, Exception - { - FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - - commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) - .withCoreAPI().usingResource(file).addComment(commentText); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - restClient.withCoreAPI().usingResource(file).deleteComment(commentModel); - restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); - - comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().entriesListDoesNotContain("content", commentText); - comments.getPagination().assertThat().field("totalItems").is("0").and().field("count").is("0"); - } - - @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, - executionType = ExecutionType.REGRESSION, description = "Verify Contributor user deletes comment created by self" - + " and status code is 204. Check with getComments for validation") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - @Bug(id = "ACE-4614") - public void contributorIsAbleToDeleteCommentCreatedBySelf() throws JsonToModelConversionException, Exception - { - FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - - commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) - .withCoreAPI().usingResource(file).addComment(commentText); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - restClient.withCoreAPI().usingResource(file).deleteComment(commentModel); - restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); - - comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().entriesListDoesNotContain("content", commentText); - comments.getPagination().assertThat().field("totalItems").is("0").and().field("count").is("0"); - } - - @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, - executionType = ExecutionType.REGRESSION, description = "Verify Consumer user cannot delete comment created by admin" - + " and status code is 403. Check with getComments for validation and check default error model schema.") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void consumerIsNotAbleToDeleteCommentCreatedByOthersDefaultErrorModelSchema() throws JsonToModelConversionException, Exception - { - FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - - commentModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(commentText); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) - .withCoreAPI().usingResource(file).deleteComment(commentModel); - restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) - .statusCodeIs(HttpStatus.FORBIDDEN) - .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) - .stackTraceIs(RestErrorModel.STACKTRACE) - .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY); - - comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().entriesListContains("content", commentText); - comments.getPagination().assertThat().field("totalItems").is("1").and().field("count").is("1"); - } - - @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, - executionType = ExecutionType.REGRESSION, description = "Verify Manager can delete comment with version number") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void usingManagerDeleteCommentWithVersionNumber() throws JsonToModelConversionException, Exception - { - FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - dataContent.usingAdmin().usingResource(file).updateContent("updated content to increase version number"); - - commentModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(commentText); - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) - .withCoreAPI().usingResource(file).deleteComment(commentModel); - restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); - } - - @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, - executionType = ExecutionType.REGRESSION, description = "Verify Manager user cannot delete comment with invalid node " - + "and status code is 404. Check with getComments for validation") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void usingManagerDeleteCommentWithInvalidNode() throws JsonToModelConversionException, Exception - { - FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - - commentModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(commentText); - file.setNodeRef("invalid"); - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) - .withCoreAPI().usingResource(file).deleteComment(commentModel); - restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(file.getNodeRef() + " was not found"); - - comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(file.getNodeRef() + " was not found"); - } - - @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS}, executionType = ExecutionType.REGRESSION, - description = "Verify deleteComment from node with invalid network id returns status code 401") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void deleteCommentWithInvalidNetworkId() throws Exception - { - FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - - commentModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(commentText); - networkUserModel.setDomain("invalidNetwork"); - restClient.authenticateUser(networkUserModel).withCoreAPI().usingResource(file).deleteComment(commentModel); - restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError().containsSummary(RestErrorModel.AUTHENTICATION_FAILED); - } - - @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, - executionType = ExecutionType.REGRESSION, description = "Verify deleteComment from node with empty network id returns status code 401") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void deleteCommentWithEmptyNetworkId() throws JsonToModelConversionException, Exception - { - FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - - commentModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(commentText); - networkUserModel.setDomain(""); - restClient.authenticateUser(networkUserModel).withCoreAPI().usingResource(file).deleteComment(commentModel); - restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError().containsSummary(RestErrorModel.AUTHENTICATION_FAILED); - } -} +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.model.RestCommentModelsCollection; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class DeleteCommentTests extends RestTest +{ + private UserModel adminUserModel, networkUserModel; + + private FileModel document; + private SiteModel siteModel; + private RestCommentModelsCollection comments; + private RestCommentModel commentModel; + private ListUserWithRoles usersWithRoles; + private String commentText = "This is a new comment"; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + networkUserModel = dataUser.createRandomTestUser(); + restClient.authenticateUser(adminUserModel); + siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel,UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify Admin user deletes comments with Rest API and status code is 204") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) + public void adminIsAbleToDeleteComments() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment"); + restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify User gets status code 401 if authentication call fails") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) + @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void userIsNotAbleToDeleteCommentIfAuthenticationFails() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("New comment addded by admin"); + UserModel nonexistentModel = new UserModel("nonexistentUser", "nonexistentPassword"); + restClient.authenticateUser(nonexistentModel); + restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError() + .containsSummary(RestErrorModel.AUTHENTICATION_FAILED); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Manager user deletes own comments and status code is 204") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void managerIsAbleToDeleteComments() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("New comment added by Manager"); + restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Collaborator user deletes own comments and status code is 204") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void collaboratorIsAbleToDeleteComments() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("New comment added by Collaborator"); + restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Contributor user deletes own comments and status code is 204") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void contributorIsAbleToDeleteComments() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("New comment added by Contributor"); + restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Consumer user can't delete comments created by admin user and status code is 403") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void consumerIsNotAbleToDeleteComments() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment"); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Admin user can't delete comments with inexistent ID and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void userIsNotAbleToDeleteInexistentComment() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = new RestCommentModel(); + commentModel.setId("inexistent"); + restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Admin user can't delete comments with inexistend NodeId and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void userIsNotAbleToDeleteCommentWithInexistentNodeId() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment"); + FileModel inexistentDocument = new FileModel(); + inexistentDocument.setNodeRef("inexistent"); + restClient.withCoreAPI().usingResource(inexistentDocument).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Admin user can't delete deleted comments and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void userIsNotAbleToDeleteDeletedComment() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment"); + restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingResource(document).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, + executionType = ExecutionType.REGRESSION, description = "Verify Manager user deletes comment created by admin" + + " and status code is 204. Check with getComments for validation") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void managerIsAbleToDeleteCommentCreatedByOthers() throws JsonToModelConversionException, Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(file).addComment(commentText); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(file).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListDoesNotContain("content", commentText); + comments.getPagination().assertThat().field("totalItems").is("0").and().field("count").is("0"); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, + executionType = ExecutionType.REGRESSION, description = "Verify Collaborator user can delete comment created by self" + + " and status code is 204. Check with getComments for validation") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void collaboratorIsAbleToDeleteCommentCreatedBySelf() throws JsonToModelConversionException, Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(file).addComment(commentText); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withCoreAPI().usingResource(file).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListDoesNotContain("content", commentText); + comments.getPagination().assertThat().field("totalItems").is("0").and().field("count").is("0"); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, + executionType = ExecutionType.REGRESSION, description = "Verify Contributor user deletes comment created by self" + + " and status code is 204. Check with getComments for validation") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + @Bug(id = "ACE-4614") + public void contributorIsAbleToDeleteCommentCreatedBySelf() throws JsonToModelConversionException, Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .withCoreAPI().usingResource(file).addComment(commentText); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withCoreAPI().usingResource(file).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListDoesNotContain("content", commentText); + comments.getPagination().assertThat().field("totalItems").is("0").and().field("count").is("0"); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, + executionType = ExecutionType.REGRESSION, description = "Verify Consumer user cannot delete comment created by admin" + + " and status code is 403. Check with getComments for validation and check default error model schema.") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void consumerIsNotAbleToDeleteCommentCreatedByOthersDefaultErrorModelSchema() throws JsonToModelConversionException, Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(commentText); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .withCoreAPI().usingResource(file).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .statusCodeIs(HttpStatus.FORBIDDEN) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", commentText); + comments.getPagination().assertThat().field("totalItems").is("1").and().field("count").is("1"); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, + executionType = ExecutionType.REGRESSION, description = "Verify Manager can delete comment with version number") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void usingManagerDeleteCommentWithVersionNumber() throws JsonToModelConversionException, Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + dataContent.usingAdmin().usingResource(file).updateContent("updated content to increase version number"); + + commentModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(commentText); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(file).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, + executionType = ExecutionType.REGRESSION, description = "Verify Manager user cannot delete comment with invalid node " + + "and status code is 404. Check with getComments for validation") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void usingManagerDeleteCommentWithInvalidNode() throws JsonToModelConversionException, Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(commentText); + file.setNodeRef("invalid"); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(file).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(file.getNodeRef() + " was not found"); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(file.getNodeRef() + " was not found"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS}, executionType = ExecutionType.REGRESSION, + description = "Verify deleteComment from node with invalid network id returns status code 401") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void deleteCommentWithInvalidNetworkId() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(commentText); + networkUserModel.setDomain("invalidNetwork"); + restClient.authenticateUser(networkUserModel).withCoreAPI().usingResource(file).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError().containsSummary(RestErrorModel.AUTHENTICATION_FAILED); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.COMMENTS }, + executionType = ExecutionType.REGRESSION, description = "Verify deleteComment from node with empty network id returns status code 401") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void deleteCommentWithEmptyNetworkId() throws JsonToModelConversionException, Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(commentText); + networkUserModel.setDomain(""); + restClient.authenticateUser(networkUserModel).withCoreAPI().usingResource(file).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError().containsSummary(RestErrorModel.AUTHENTICATION_FAILED); + } +} diff --git a/e2e-test/java/org/alfresco/rest/comments/GetCommentsTests.java b/e2e-test/java/org/alfresco/rest/comments/GetCommentsTests.java index ad5675cc9..d8fe7d9d0 100644 --- a/e2e-test/java/org/alfresco/rest/comments/GetCommentsTests.java +++ b/e2e-test/java/org/alfresco/rest/comments/GetCommentsTests.java @@ -1,424 +1,424 @@ -package org.alfresco.rest.comments; - -import org.alfresco.dataprep.CMISUtil; -import org.alfresco.dataprep.CMISUtil.DocumentType; -import org.alfresco.rest.RestTest; -import org.alfresco.rest.exception.JsonToModelConversionException; -import org.alfresco.rest.model.RestCommentModelsCollection; -import org.alfresco.rest.model.RestErrorModel; -import org.alfresco.utility.constants.UserRole; -import org.alfresco.utility.data.DataUser.ListUserWithRoles; -import org.alfresco.utility.model.FileModel; -import org.alfresco.utility.model.FileType; -import org.alfresco.utility.model.LinkModel; -import org.alfresco.utility.model.SiteModel; -import org.alfresco.utility.model.TestGroup; -import org.alfresco.utility.model.UserModel; -import org.alfresco.utility.report.Bug; -import org.alfresco.utility.testrail.ExecutionType; -import org.alfresco.utility.testrail.annotation.TestRail; -import org.springframework.http.HttpStatus; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -public class GetCommentsTests extends RestTest -{ - private FileModel file, document, document1; - private SiteModel siteModel, privateSiteModel; - private UserModel adminUserModel, userModel, networkUserModel; - private ListUserWithRoles usersWithRoles; - private String comment = "This is a new comment"; - private String comment2 = "This is a 2nd comment"; - private String comment3 = "This is a 3rd comment"; - private RestCommentModelsCollection comments; - - @BeforeClass(alwaysRun=true) - public void dataPreparation() throws Exception - { - adminUserModel = dataUser.getAdminUser(); - networkUserModel = dataUser.createRandomTestUser(); - siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); - privateSiteModel = dataSite.usingUser(adminUserModel).createPrivateRandomSite(); - document = dataContent.usingSite(privateSiteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - document1 = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - restClient.authenticateUser(adminUserModel).withCoreAPI() - .usingResource(document1).addComment(comment); - restClient.withCoreAPI().usingResource(document).addComment(comment); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - restClient.withCoreAPI().usingResource(document).addComment(comment2); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - restClient.withCoreAPI().usingResource(document).addComment(comment3); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.SANITY, - description= "Verify Admin user gets comments with Rest API and status code is 200") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) - public void adminIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception - { - comments = restClient.authenticateUser(adminUserModel).withCoreAPI() - .usingResource(document1).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().entriesListContains("content", comment); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.SANITY, - description= "Verify Manager user gets status code 401 if authentication call fails") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) - @Bug(id="MNT-16904", description = "It fails only on environment with tenants") - public void managerIsNotAbleToRetrieveCommentIfAuthenticationFails() throws JsonToModelConversionException, Exception - { - UserModel nonexistentModel = new UserModel("nonexistentUser", "nonexistentPassword"); - restClient.authenticateUser(nonexistentModel).withCoreAPI() - .usingResource(document1).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError() - .containsSummary(RestErrorModel.AUTHENTICATION_FAILED); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify Manager user gets comments created by admin user with Rest API and status code is 200") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) - public void managerIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception - { - comments = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI() - .usingResource(document1).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().entriesListContains("content", comment); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify Contributor user gets comments created by admin user with Rest API and status code is 200") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) - public void contributorIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception - { - comments = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI() - .usingResource(document1).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().entriesListContains("content", comment); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify Collaborator user gets comments created by admin user with Rest API and status code is 200") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) - public void collaboratorIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception - { - comments = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI() - .usingResource(document1).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().entriesListContains("content", comment); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify Consumer user gets comments created by admin user with Rest API and status code is 200") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) - public void consumerIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception - { - comments = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI() - .usingResource(document1).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().entriesListContains("content", comment); - } - - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify Manager user gets comments created by another user and status code is 200") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) - public void managerIsAbleToRetrieveCommentsCreatedByAnotherUser() throws JsonToModelConversionException, Exception - { - userModel = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator); - String contentManager = "This is a new comment added by " + userModel.getUsername(); - restClient.authenticateUser(userModel).withCoreAPI() - .usingResource(document1).addComment(contentManager); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - comments = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI() - .usingResource(document1).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().entriesListContains("content", contentManager) - .and().entriesListContains("content", comment); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify admin user gets comments created by another user and status code is 200") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) - public void adminIsAbleToRetrieveCommentsCreatedByAnotherUser() throws JsonToModelConversionException, Exception - { - userModel = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator); - String contentCollaborator = "This is a new comment added by " + userModel.getUsername(); - restClient.authenticateUser(userModel).withCoreAPI() - .usingResource(document1).addComment(contentCollaborator); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - comments = restClient.authenticateUser(adminUserModel).withCoreAPI() - .usingResource(document1).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().entriesListContains("content", contentCollaborator) - .and().entriesListContains("content", comment); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify request returns status 403 if the user does not have permission read comments on the node") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) - public void uninvitedUserCanNotGetCommentsFromPrivateSite() throws Exception - { - restClient.authenticateUser(userModel).withCoreAPI() - .usingResource(document).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) - .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify user gets comments without the first 2 and status code is 200") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) - public void skipFirst2Comments() throws Exception - { - comments = restClient.authenticateUser(adminUserModel).withParams("skipCount=2") - .withCoreAPI().usingResource(document).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().entriesListContains("content", comment) - .and().paginationField("count").is("1"); - comments.assertThat().paginationField("skipCount").is("2"); - comments.assertThat().paginationField("totalItems").is("3"); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify invalid request returns status code 400 for invalid maxItems or skipCount") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void checkStatusCodeForInvalidMaxItems() throws Exception - { - restClient.authenticateUser(adminUserModel).withParams("maxItems=0") - .withCoreAPI().usingResource(document).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) - .assertLastError().containsSummary("Only positive values supported for maxItems"); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify User can't get comments for node with ID that does not exist and status code is 404") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void userCanNotGetCommentsOnNonExistentFile() throws Exception - { - FileModel nonexistentFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); - nonexistentFile.setNodeRef("ABC"); - restClient.authenticateUser(adminUserModel).withCoreAPI() - .usingResource(nonexistentFile).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) - .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, nonexistentFile.getNodeRef())); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify User can't get comments for node that exists but is not a document or a folder and status code is 400") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void userCanNotGetCommentsOnLink() throws Exception - { - LinkModel link = dataLink.usingAdmin().usingSite(siteModel).createRandomLink(); - FileModel fileWithNodeRefFromLink = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); - fileWithNodeRefFromLink.setNodeRef(link.getNodeRef().replace("workspace://SpacesStore/", "workspace%3A%2F%2FSpacesStore%2F")); - restClient.authenticateUser(adminUserModel).withCoreAPI() - .usingResource(fileWithNodeRefFromLink).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) - .assertLastError() - .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, fileWithNodeRefFromLink.getNodeRef())) - .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) - .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) - .stackTraceIs(RestErrorModel.STACKTRACE); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify get comments from node with invalid network id returns status code 401") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void getCommentsWithInvalidNetwork() throws Exception - { - networkUserModel.setDomain("invalidNetwork"); - restClient.authenticateUser(networkUserModel).withCoreAPI().usingResource(document).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError().containsSummary(RestErrorModel.AUTHENTICATION_FAILED); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify get comments from node with empty network id returns status code 401") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void getCommentsWithEmptyNetwork() throws Exception - { - networkUserModel.setDomain(""); - restClient.authenticateUser(networkUserModel).withCoreAPI().usingResource(document).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError().containsSummary(RestErrorModel.AUTHENTICATION_FAILED); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify that if manager adds one comment, it will be returned in getComments response") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void addCommentWithManagerAndCheckThatCommentIsReturned() throws Exception - { - file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(file).addComment(comment); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - - comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().entriesListContains("content", comment) - .getPagination().assertThat().field("totalItems").is("1") - .assertThat().field("count").is("1"); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify that if collaborator adds one comment, it will be returned in getComments response") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void addCommentWithCollaboratorAndCheckThatCommentIsReturned() throws Exception - { - file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) - .withCoreAPI().usingResource(file).addComment(comment); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - - comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().entriesListContains("content", comment) - .getPagination().assertThat().field("totalItems").is("1") - .assertThat().field("count").is("1"); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify that if contributor adds one comment, it will be returned in getComments response") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - @Bug(id = "ACE-4614") - public void addCommentWithContributorAndCheckThatCommentIsReturned() throws Exception - { - file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) - .withCoreAPI().usingResource(file).addComment(comment); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - - comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().entriesListContains("content", comment) - .getPagination().assertThat().field("totalItems").is("1") - .assertThat().field("count").is("1"); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify that consumer cannot add a comment and no comments will be returned in getComments response") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void addCommentWithConsumerAndCheckThatCommentIsNotReturned() throws Exception - { - file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) - .withCoreAPI().usingResource(file).addComment(comment); - restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); - - comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().paginationField("totalItems").is("0"); - comments.assertThat().paginationField("count").is("0"); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Add one comment with Manager and check that returned person is the right one") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void addCommentWithManagerCheckReturnedPersonIsTheRightOne() throws Exception - { - file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - UserModel user1 = dataUser.createRandomTestUser(); - dataUser.addUserToSite(user1, siteModel, UserRole.SiteManager); - - restClient.authenticateUser(user1).withCoreAPI().usingResource(file).addComment(comment); - comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); - comments.getOneRandomEntry().onModel().getCreatedBy().assertThat().field("firstName").is(user1.getUsername() + " FirstName") - .assertThat().field("lastName").is("LN-" + user1.getUsername()); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Add one comment with Collaborator and check that returned company details are correct") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void addCommentWithCollaboratorCheckReturnedCompanyDetails() throws Exception - { - file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(file).addComment(comment); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - - comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); - comments.getOneRandomEntry().onModel().getCreatedBy().getCompany() - .assertThat().field("organization").isNull() - .assertThat().field("address1").isNull() - .assertThat().field("address2").isNull() - .assertThat().field("address3").isNull() - .assertThat().field("postcode").isNull() - .assertThat().field("telephone").isNull() - .assertThat().field("fax").isNull() - .assertThat().field("email").isNull(); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Add 2 comments with Manager and Collaborator users and verify valid request using skipCount. Check that param is applied") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void addTwoCommentsWithManagerCollaboratorVerifySkipCountParamIsApplied() throws Exception - { - file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(file).addComment(comment); - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(file).addComment(comment2); - - comments = restClient.authenticateUser(adminUserModel).withParams("skipCount=1") - .withCoreAPI().usingResource(file).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().entriesListContains("content", comment) - .and().paginationField("count").is("1"); - comments.assertThat().paginationField("skipCount").is("1"); - comments.assertThat().paginationField("totalItems").is("2"); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Add 2 comments with Admin and Collaborator users and verify valid request using maxItems. Check that param is applied") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void addTwoCommentsWithAdminCollaboratorVerifyMaxItemsParamIsApplied() throws Exception - { - file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(comment); - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(file).addComment(comment2); - - comments = restClient.authenticateUser(adminUserModel).withParams("maxItems=1") - .withCoreAPI().usingResource(file).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().entriesListContains("content", comment2) - .and().paginationField("count").is("1"); - comments.assertThat().paginationField("totalItems").is("2"); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Add 2 comments with Manager and Admin users and verify valid request using properties. Check that param is applied") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void addTwoCommentsWithAdminManagerVerifyPropertiesParamIsApplied() throws Exception - { - file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(comment); - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(file).addComment(comment2); - - comments = restClient.authenticateUser(adminUserModel).withParams("properties=createdBy,modifiedBy") - .withCoreAPI().usingResource(file).getNodeComments(); - comments.assertThat().entriesListIsNotEmpty() - .and().paginationField("count").is("2"); - comments.assertThat().paginationField("totalItems").is("2"); - - comments.getEntries().get(0).onModel().getCreatedBy() - .assertThat().field("firstName").is(usersWithRoles.getOneUserWithRole(UserRole.SiteManager).getUsername() + " FirstName") - .assertThat().field("lastName").is("LN-" + usersWithRoles.getOneUserWithRole(UserRole.SiteManager).getUsername()); - - comments.getEntries().get(1).onModel().getCreatedBy() - .assertThat().field("firstName").is("Administrator") - .assertThat().field("id").is("admin"); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Check default error model schema") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void addTwoCommentsWithManagerCheckDefaultErrorModelSchema() throws Exception - { - file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) - .withCoreAPI().usingResource(file).addComments(comment, comment2); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - - restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).usingParams("maxItems=0").getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS); - restClient.assertLastError().containsErrorKey(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS); - restClient.assertLastError().containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS); - restClient.assertLastError().descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); - restClient.assertLastError().stackTraceIs(RestErrorModel.STACKTRACE); - } -} +package org.alfresco.rest.comments; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestCommentModelsCollection; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.LinkModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetCommentsTests extends RestTest +{ + private FileModel file, document, document1; + private SiteModel siteModel, privateSiteModel; + private UserModel adminUserModel, userModel, networkUserModel; + private ListUserWithRoles usersWithRoles; + private String comment = "This is a new comment"; + private String comment2 = "This is a 2nd comment"; + private String comment3 = "This is a 3rd comment"; + private RestCommentModelsCollection comments; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + networkUserModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + privateSiteModel = dataSite.usingUser(adminUserModel).createPrivateRandomSite(); + document = dataContent.usingSite(privateSiteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + document1 = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(adminUserModel).withCoreAPI() + .usingResource(document1).addComment(comment); + restClient.withCoreAPI().usingResource(document).addComment(comment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withCoreAPI().usingResource(document).addComment(comment2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.withCoreAPI().usingResource(document).addComment(comment3); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.SANITY, + description= "Verify Admin user gets comments with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) + public void adminIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception + { + comments = restClient.authenticateUser(adminUserModel).withCoreAPI() + .usingResource(document1).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.SANITY, + description= "Verify Manager user gets status code 401 if authentication call fails") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) + @Bug(id="MNT-16904", description = "It fails only on environment with tenants") + public void managerIsNotAbleToRetrieveCommentIfAuthenticationFails() throws JsonToModelConversionException, Exception + { + UserModel nonexistentModel = new UserModel("nonexistentUser", "nonexistentPassword"); + restClient.authenticateUser(nonexistentModel).withCoreAPI() + .usingResource(document1).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError() + .containsSummary(RestErrorModel.AUTHENTICATION_FAILED); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify Manager user gets comments created by admin user with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void managerIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception + { + comments = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI() + .usingResource(document1).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify Contributor user gets comments created by admin user with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void contributorIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception + { + comments = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI() + .usingResource(document1).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify Collaborator user gets comments created by admin user with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void collaboratorIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception + { + comments = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI() + .usingResource(document1).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify Consumer user gets comments created by admin user with Rest API and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void consumerIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception + { + comments = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI() + .usingResource(document1).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment); + } + + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify Manager user gets comments created by another user and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void managerIsAbleToRetrieveCommentsCreatedByAnotherUser() throws JsonToModelConversionException, Exception + { + userModel = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator); + String contentManager = "This is a new comment added by " + userModel.getUsername(); + restClient.authenticateUser(userModel).withCoreAPI() + .usingResource(document1).addComment(contentManager); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + comments = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI() + .usingResource(document1).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", contentManager) + .and().entriesListContains("content", comment); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify admin user gets comments created by another user and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void adminIsAbleToRetrieveCommentsCreatedByAnotherUser() throws JsonToModelConversionException, Exception + { + userModel = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator); + String contentCollaborator = "This is a new comment added by " + userModel.getUsername(); + restClient.authenticateUser(userModel).withCoreAPI() + .usingResource(document1).addComment(contentCollaborator); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + comments = restClient.authenticateUser(adminUserModel).withCoreAPI() + .usingResource(document1).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", contentCollaborator) + .and().entriesListContains("content", comment); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify request returns status 403 if the user does not have permission read comments on the node") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void uninvitedUserCanNotGetCommentsFromPrivateSite() throws Exception + { + restClient.authenticateUser(userModel).withCoreAPI() + .usingResource(document).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify user gets comments without the first 2 and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void skipFirst2Comments() throws Exception + { + comments = restClient.authenticateUser(adminUserModel).withParams("skipCount=2") + .withCoreAPI().usingResource(document).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment) + .and().paginationField("count").is("1"); + comments.assertThat().paginationField("skipCount").is("2"); + comments.assertThat().paginationField("totalItems").is("3"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify invalid request returns status code 400 for invalid maxItems or skipCount") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void checkStatusCodeForInvalidMaxItems() throws Exception + { + restClient.authenticateUser(adminUserModel).withParams("maxItems=0") + .withCoreAPI().usingResource(document).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary("Only positive values supported for maxItems"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify User can't get comments for node with ID that does not exist and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void userCanNotGetCommentsOnNonExistentFile() throws Exception + { + FileModel nonexistentFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + nonexistentFile.setNodeRef("ABC"); + restClient.authenticateUser(adminUserModel).withCoreAPI() + .usingResource(nonexistentFile).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, nonexistentFile.getNodeRef())); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify User can't get comments for node that exists but is not a document or a folder and status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void userCanNotGetCommentsOnLink() throws Exception + { + LinkModel link = dataLink.usingAdmin().usingSite(siteModel).createRandomLink(); + FileModel fileWithNodeRefFromLink = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + fileWithNodeRefFromLink.setNodeRef(link.getNodeRef().replace("workspace://SpacesStore/", "workspace%3A%2F%2FSpacesStore%2F")); + restClient.authenticateUser(adminUserModel).withCoreAPI() + .usingResource(fileWithNodeRefFromLink).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, fileWithNodeRefFromLink.getNodeRef())) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify get comments from node with invalid network id returns status code 401") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void getCommentsWithInvalidNetwork() throws Exception + { + networkUserModel.setDomain("invalidNetwork"); + restClient.authenticateUser(networkUserModel).withCoreAPI().usingResource(document).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError().containsSummary(RestErrorModel.AUTHENTICATION_FAILED); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify get comments from node with empty network id returns status code 401") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void getCommentsWithEmptyNetwork() throws Exception + { + networkUserModel.setDomain(""); + restClient.authenticateUser(networkUserModel).withCoreAPI().usingResource(document).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError().containsSummary(RestErrorModel.AUTHENTICATION_FAILED); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify that if manager adds one comment, it will be returned in getComments response") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void addCommentWithManagerAndCheckThatCommentIsReturned() throws Exception + { + file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(file).addComment(comment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment) + .getPagination().assertThat().field("totalItems").is("1") + .assertThat().field("count").is("1"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify that if collaborator adds one comment, it will be returned in getComments response") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void addCommentWithCollaboratorAndCheckThatCommentIsReturned() throws Exception + { + file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(file).addComment(comment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment) + .getPagination().assertThat().field("totalItems").is("1") + .assertThat().field("count").is("1"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify that if contributor adds one comment, it will be returned in getComments response") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + @Bug(id = "ACE-4614") + public void addCommentWithContributorAndCheckThatCommentIsReturned() throws Exception + { + file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .withCoreAPI().usingResource(file).addComment(comment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment) + .getPagination().assertThat().field("totalItems").is("1") + .assertThat().field("count").is("1"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify that consumer cannot add a comment and no comments will be returned in getComments response") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void addCommentWithConsumerAndCheckThatCommentIsNotReturned() throws Exception + { + file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .withCoreAPI().usingResource(file).addComment(comment); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().paginationField("totalItems").is("0"); + comments.assertThat().paginationField("count").is("0"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Add one comment with Manager and check that returned person is the right one") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void addCommentWithManagerCheckReturnedPersonIsTheRightOne() throws Exception + { + file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + UserModel user1 = dataUser.createRandomTestUser(); + dataUser.addUserToSite(user1, siteModel, UserRole.SiteManager); + + restClient.authenticateUser(user1).withCoreAPI().usingResource(file).addComment(comment); + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + comments.getOneRandomEntry().onModel().getCreatedBy().assertThat().field("firstName").is(user1.getUsername() + " FirstName") + .assertThat().field("lastName").is("LN-" + user1.getUsername()); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Add one comment with Collaborator and check that returned company details are correct") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void addCommentWithCollaboratorCheckReturnedCompanyDetails() throws Exception + { + file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(file).addComment(comment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + comments.getOneRandomEntry().onModel().getCreatedBy().getCompany() + .assertThat().field("organization").isNull() + .assertThat().field("address1").isNull() + .assertThat().field("address2").isNull() + .assertThat().field("address3").isNull() + .assertThat().field("postcode").isNull() + .assertThat().field("telephone").isNull() + .assertThat().field("fax").isNull() + .assertThat().field("email").isNull(); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Add 2 comments with Manager and Collaborator users and verify valid request using skipCount. Check that param is applied") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void addTwoCommentsWithManagerCollaboratorVerifySkipCountParamIsApplied() throws Exception + { + file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(file).addComment(comment); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(file).addComment(comment2); + + comments = restClient.authenticateUser(adminUserModel).withParams("skipCount=1") + .withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment) + .and().paginationField("count").is("1"); + comments.assertThat().paginationField("skipCount").is("1"); + comments.assertThat().paginationField("totalItems").is("2"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Add 2 comments with Admin and Collaborator users and verify valid request using maxItems. Check that param is applied") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void addTwoCommentsWithAdminCollaboratorVerifyMaxItemsParamIsApplied() throws Exception + { + file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(comment); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(file).addComment(comment2); + + comments = restClient.authenticateUser(adminUserModel).withParams("maxItems=1") + .withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment2) + .and().paginationField("count").is("1"); + comments.assertThat().paginationField("totalItems").is("2"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Add 2 comments with Manager and Admin users and verify valid request using properties. Check that param is applied") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void addTwoCommentsWithAdminManagerVerifyPropertiesParamIsApplied() throws Exception + { + file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(comment); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(file).addComment(comment2); + + comments = restClient.authenticateUser(adminUserModel).withParams("properties=createdBy,modifiedBy") + .withCoreAPI().usingResource(file).getNodeComments(); + comments.assertThat().entriesListIsNotEmpty() + .and().paginationField("count").is("2"); + comments.assertThat().paginationField("totalItems").is("2"); + + comments.getEntries().get(0).onModel().getCreatedBy() + .assertThat().field("firstName").is(usersWithRoles.getOneUserWithRole(UserRole.SiteManager).getUsername() + " FirstName") + .assertThat().field("lastName").is("LN-" + usersWithRoles.getOneUserWithRole(UserRole.SiteManager).getUsername()); + + comments.getEntries().get(1).onModel().getCreatedBy() + .assertThat().field("firstName").is("Administrator") + .assertThat().field("id").is("admin"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Check default error model schema") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void addTwoCommentsWithManagerCheckDefaultErrorModelSchema() throws Exception + { + file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(file).addComments(comment, comment2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).usingParams("maxItems=0").getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS); + restClient.assertLastError().containsErrorKey(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS); + restClient.assertLastError().containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS); + restClient.assertLastError().descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + restClient.assertLastError().stackTraceIs(RestErrorModel.STACKTRACE); + } +} diff --git a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentTests.java b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentTests.java index fd8661ef3..07d4d11e6 100644 --- a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentTests.java +++ b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentTests.java @@ -1,462 +1,462 @@ -package org.alfresco.rest.comments; - -import org.alfresco.dataprep.CMISUtil; -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.model.RestCommentModelsCollection; -import org.alfresco.rest.model.RestErrorModel; -import org.alfresco.utility.constants.UserRole; -import org.alfresco.utility.data.DataUser.ListUserWithRoles; -import org.alfresco.utility.model.FileModel; -import org.alfresco.utility.model.FileType; -import org.alfresco.utility.model.FolderModel; -import org.alfresco.utility.model.LinkModel; -import org.alfresco.utility.model.SiteModel; -import org.alfresco.utility.model.TestGroup; -import org.alfresco.utility.model.UserModel; -import org.alfresco.utility.report.Bug; -import org.alfresco.utility.testrail.ExecutionType; -import org.alfresco.utility.testrail.annotation.TestRail; -import org.apache.commons.lang.RandomStringUtils; -import org.springframework.http.HttpStatus; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -public class UpdateCommentTests extends RestTest -{ - private UserModel adminUserModel, networkUserModel; - private FileModel document; - private SiteModel siteModel; - private RestCommentModel commentModel, returnedCommentModel; - private RestCommentModelsCollection comments;; - private ListUserWithRoles usersWithRoles; - private String firstComment = "This is a new comment"; - private String updatedComment = "This is the updated comment"; - - @BeforeClass(alwaysRun=true) - public void dataPreparation() throws Exception - { - adminUserModel = dataUser.getAdminUser(); - restClient.authenticateUser(adminUserModel); - networkUserModel = dataUser.createRandomTestUser(); - siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); - - document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel,UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); - } - - @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify Admin user updates comments and status code is 200") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) - public void adminIsAbleToUpdateHisComment() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(adminUserModel); - commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by admin"); - String updatedContent = "This is the updated comment with admin user"; - restClient.withCoreAPI().usingResource(document).updateComment(commentModel, updatedContent) - .assertThat().field("content").isNotEmpty() - .and().field("content").is(updatedContent); - restClient.assertStatusCodeIs(HttpStatus.OK); - } - - @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify unauthenticated user gets status code 401 on update comment call") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) - @Bug(id = "MNT-16904", description = "fails only on environment with tenants") - public void unauthenticatedUserIsNotAbleToUpdateComment() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(adminUserModel); - commentModel = restClient.withCoreAPI().usingResource(document).addComment("To be updated by unauthenticated user."); - UserModel incorrectUserModel = new UserModel("userName", "password"); - restClient.authenticateUser(incorrectUserModel) - .withCoreAPI().usingResource(document).updateComment(commentModel, "try to update"); - restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError() - .containsSummary(RestErrorModel.AUTHENTICATION_FAILED); - } - - @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify entry content in response") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) - public void checkEntryContentInResponse() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(adminUserModel); - commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by admin"); - commentModel = restClient.withCoreAPI().usingResource(document).updateComment(commentModel, "This is the updated comment with admin user"); - restClient.assertStatusCodeIs(HttpStatus.OK); - commentModel.assertThat().field("content").is("This is the updated comment with admin user"); - } - - @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Manager user updates comments created by admin user and status code is 200") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) - public void managerIsAbleToUpdateHisComment() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); - commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by manager"); - restClient.withCoreAPI().usingResource(document).updateComment(commentModel, "This is the updated comment with Manager user") - .and().field("content").is("This is the updated comment with Manager user") - .and().field("canEdit").is(true) - .and().field("canDelete").is(true); - restClient.assertStatusCodeIs(HttpStatus.OK); - } - - @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Contributor user can update his own comment and status code is 200") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) - public void contributorIsAbleToUpdateHisComment() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); - commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by contributor"); - String updatedContent = "This is the updated comment with Contributor user"; - restClient.withCoreAPI().usingResource(document).updateComment(commentModel, updatedContent); - restClient.assertStatusCodeIs(HttpStatus.OK); - } - - @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Consumer user can not update comments created by admin user and status code is 403") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) - public void consumerIsNotAbleToUpdateComment() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(adminUserModel); - commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by admin"); - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); - restClient.withCoreAPI().usingResource(document).updateComment(commentModel, "This is the updated comment with Consumer user"); - restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) - .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); - } - - @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Collaborator user can update his own comment and status code is 200") -// @Bug(id="REPO-1011") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) - public void collaboratorIsAbleToUpdateHisComment() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); - commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by collaborator"); - restClient.withCoreAPI().usingResource(document).updateComment(commentModel, "This is the updated comment with Collaborator user"); - restClient.assertStatusCodeIs(HttpStatus.OK); - } - - @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Collaborator user can not update comments of another user and status code is 200") -// @Bug(id="MNT-2502",description="seems it's one old issue: also logged as MNT-2502, MNT-2346") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) - public void collaboratorIsNotAbleToUpdateCommentOfAnotherUser() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(adminUserModel); - commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by admin"); - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) - .withCoreAPI().usingResource(document).updateComment(commentModel, "This is the updated comment with Collaborator user"); - restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); - } - - @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify update comment with inexistent nodeId returns status code 404") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void canNotUpdateCommentIfNodeIdIsNotSet() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(adminUserModel); - - FolderModel content = FolderModel.getRandomFolderModel(); - content.setNodeRef("node ref that does not exist"); - commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment"); - restClient.withCoreAPI().usingResource(content).updateComment(commentModel, "This is the updated comment."); - restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) - .assertLastError().containsSummary("node ref that does not exist was not found"); - } - - @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify if commentId is not set the status code is 404") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void canNotUpdateCommentIfCommentIdIsNotSet() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(adminUserModel); - - RestCommentModel comment = new RestCommentModel(); - String id = "comment id that does not exist"; - comment.setId(id); - restClient.withCoreAPI().usingResource(document).updateComment(comment, "This is the updated comment."); - restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) - .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, id)); - } - - @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify can not update comment if NodeId is neither document or folder and returns status code 405") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void canNotUpdateCommentIfNodeIdIsNeitherDocumentOrFolder() throws JsonToModelConversionException, Exception - { - FileModel content = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); - content = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - - restClient.authenticateUser(adminUserModel); - commentModel = restClient.withCoreAPI().usingResource(content).addComment("This is a new comment"); - - LinkModel link = dataLink.usingAdmin().usingSite(siteModel).createRandomLink(); - content.setNodeRef(link.getNodeRef().replace("workspace://SpacesStore/", "workspace%3A%2F%2FSpacesStore%2F")); - - restClient.withCoreAPI().usingResource(content).updateComment(commentModel, "This is the updated comment."); - restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) - .assertLastError() - .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, content.getNodeRef())) - .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) - .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) - .stackTraceIs(RestErrorModel.STACKTRACE); - } - - @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Admin user is not able to update with empty comment body and status code is 400") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void adminIsNotAbleToUpdateWithEmptyCommentBody() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(adminUserModel); - commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by admin"); - restClient.withCoreAPI().usingResource(document).updateComment(commentModel, ""); - restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) - .assertLastError().containsSummary("An invalid argument was received"); - } - - @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify updated comment by Manager is listed when calling getComments and status code is 200") -// @Bug(id="REPO-1011") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void updatedCommentByManagerIsListed() throws JsonToModelConversionException, Exception - { - commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) - .withCoreAPI().usingResource(document).addComment("This is a new comment added by collaborator"); - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI() - .usingResource(document).updateComment(commentModel, "This is the updated comment with Manager user"); - comments = restClient.withCoreAPI().usingResource(document).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().entriesListContains("content", "This is the updated comment with Manager user"); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify Manager user can update a comment with a large string") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void managerIsAbleToUpdateACommentWithALargeString() throws JsonToModelConversionException, Exception - { - FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - String longString = RandomStringUtils.randomAlphanumeric(10000); - - commentModel = restClient.authenticateUser(adminUserModel) - .withCoreAPI().usingResource(file).addComment(firstComment); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - - returnedCommentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) - .withCoreAPI().usingResource(file).updateComment(commentModel, longString); - restClient.assertStatusCodeIs(HttpStatus.OK); - returnedCommentModel.assertThat().field("content").is(longString); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify Manager user can update a comment with a short string") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void managerIsAbleToUpdateACommentWithAShortString() throws JsonToModelConversionException, Exception - { - FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - String shortString = RandomStringUtils.randomAlphanumeric(2); - - commentModel = restClient.authenticateUser(adminUserModel) - .withCoreAPI().usingResource(file).addComment(firstComment); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - - returnedCommentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) - .withCoreAPI().usingResource(file).updateComment(commentModel, shortString); - restClient.assertStatusCodeIs(HttpStatus.OK); - returnedCommentModel.assertThat().field("content").is(shortString); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify Collaborator user can update a comment with special characters") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void collaboratorIsAbleToUpdateACommentThatContainsSpecialChars() throws JsonToModelConversionException, Exception - { - FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - String specialChars = "!@#$%^&*()'\".,<>-_+=|\\"; - - commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) - .withCoreAPI().usingResource(file).addComment(firstComment); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - - returnedCommentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) - .withCoreAPI().usingResource(file).updateComment(commentModel, specialChars); - restClient.assertStatusCodeIs(HttpStatus.OK); - returnedCommentModel.assertThat().field("content").is(specialChars); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Check that you cannot update comment with Consumer then call getComments and check new comment is not listed") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void cannotUpdateCommentWithConsumerCallGetComments() throws JsonToModelConversionException, Exception - { - FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - - commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) - .withCoreAPI().usingResource(file).addComment(firstComment); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); - restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); - - comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().entriesListContains("content", firstComment) - .and().entriesListDoesNotContain("content", updatedComment) - .and().paginationField("totalItems").is("1"); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Update comment with Contributor then call getComments and check new comment is listed") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - @Bug(id = "ACE-4614") - public void updateCommentWithContributorCallGetComments() throws JsonToModelConversionException, Exception - { - FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - - commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) - .withCoreAPI().usingResource(file).addComment(firstComment); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); - restClient.assertStatusCodeIs(HttpStatus.OK); - - comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().entriesListContains("content", updatedComment) - .and().entriesListDoesNotContain("content", firstComment) - .and().paginationField("totalItems").is("1"); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Update comment with Collaborator then call getComments and check new comment is listed") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void updateCommentWithCollaboratorCallGetComments() throws JsonToModelConversionException, Exception - { - FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - - commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) - .withCoreAPI().usingResource(file).addComment(firstComment); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); - restClient.assertStatusCodeIs(HttpStatus.OK); - - comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); - restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().entriesListContains("content", updatedComment) - .and().entriesListDoesNotContain("content", firstComment) - .and().paginationField("totalItems").is("1"); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Update comment with Manager then check modified by information in response") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void updateCommentWithManagerCheckModifiedBy() throws JsonToModelConversionException, Exception - { - FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - UserModel manager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); - - commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) - .withCoreAPI().usingResource(file).addComment(firstComment); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - - returnedCommentModel = restClient.authenticateUser(manager).withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); - restClient.assertStatusCodeIs(HttpStatus.OK); - returnedCommentModel.assertThat().field("modifiedBy.id").is(manager.getUsername()) - .and().field("content").is(updatedComment); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Delete comment with Admin then try to update it") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void deleteCommentThenTryToUpdateIt() throws JsonToModelConversionException, Exception - { - FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - - commentModel = restClient.authenticateUser(adminUserModel) - .withCoreAPI().usingResource(file).addComment(firstComment); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - - restClient.withCoreAPI().usingResource(file).deleteComment(commentModel); - restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); - - restClient.withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); - restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify Manager user can update a comment with multi byte content") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void managerIsAbleToUpdateACommentWithMultiByteContent() throws JsonToModelConversionException, Exception - { - FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - String multiByte = "\ufeff\u6768\u6728\u91d1"; - - commentModel = restClient.authenticateUser(adminUserModel) - .withCoreAPI().usingResource(file).addComment(firstComment); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - - returnedCommentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) - .withCoreAPI().usingResource(file).updateComment(commentModel, multiByte); - restClient.assertStatusCodeIs(HttpStatus.OK); - returnedCommentModel.assertThat().field("content").is(multiByte); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify Admin user can update a comment with properties parameter") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void adminIsAbleToUpdateACommentWithPropertiesParameter() throws JsonToModelConversionException, Exception - { - FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - - commentModel = restClient.authenticateUser(adminUserModel) - .withCoreAPI().usingResource(file).addComment(firstComment); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - UserModel manager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); - - returnedCommentModel = restClient.authenticateUser(manager) - .withParams("properties=createdBy,modifiedBy,canEdit,canDelete").withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); - restClient.assertStatusCodeIs(HttpStatus.OK); - returnedCommentModel.assertThat().field("createdBy.id").is(adminUserModel.getUsername()) - .assertThat().field("modifiedBy.id").is(manager.getUsername()) - .assertThat().fieldsCount().is(4); - } - - @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, - description = "Update comment with invalid node") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void updateCommentUsingInvalidNodeId() throws JsonToModelConversionException, Exception - { - FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); - - commentModel = restClient.authenticateUser(adminUserModel) - .withCoreAPI().usingResource(file).addComment(firstComment); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - - file.setNodeRef(RandomStringUtils.randomAlphanumeric(20)); - restClient.withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); - restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, file.getNodeRef())); - } - - @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Verify update comment from node with invalid network id returns status code 401") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void updateCommentWithInvalidNetworkId() throws Exception - { - FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - - commentModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(firstComment); - networkUserModel.setDomain("invalidNetwork"); - restClient.authenticateUser(networkUserModel).withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); - restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError().containsSummary(RestErrorModel.AUTHENTICATION_FAILED); - } - - @TestRail(section = { TestGroup.REST_API, - TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify User can not update comment to a not joined private site. Status code returned is 403") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void userCanNotUpdateCommentToANotJoinedPrivateSiteDefaultErrorModelSchema() throws Exception - { - UserModel newUser = dataUser.createRandomTestUser(); - FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); - - commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) - .withCoreAPI().usingResource(file).addComment(firstComment); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - - restClient.authenticateUser(newUser).withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); - restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) - .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) - .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) - .stackTraceIs(RestErrorModel.STACKTRACE) - .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY); - } -} +package org.alfresco.rest.comments; + +import org.alfresco.dataprep.CMISUtil; +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.model.RestCommentModelsCollection; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.LinkModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.apache.commons.lang.RandomStringUtils; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class UpdateCommentTests extends RestTest +{ + private UserModel adminUserModel, networkUserModel; + private FileModel document; + private SiteModel siteModel; + private RestCommentModel commentModel, returnedCommentModel; + private RestCommentModelsCollection comments;; + private ListUserWithRoles usersWithRoles; + private String firstComment = "This is a new comment"; + private String updatedComment = "This is the updated comment"; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + restClient.authenticateUser(adminUserModel); + networkUserModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + + document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel,UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify Admin user updates comments and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) + public void adminIsAbleToUpdateHisComment() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by admin"); + String updatedContent = "This is the updated comment with admin user"; + restClient.withCoreAPI().usingResource(document).updateComment(commentModel, updatedContent) + .assertThat().field("content").isNotEmpty() + .and().field("content").is(updatedContent); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify unauthenticated user gets status code 401 on update comment call") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) + @Bug(id = "MNT-16904", description = "fails only on environment with tenants") + public void unauthenticatedUserIsNotAbleToUpdateComment() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("To be updated by unauthenticated user."); + UserModel incorrectUserModel = new UserModel("userName", "password"); + restClient.authenticateUser(incorrectUserModel) + .withCoreAPI().usingResource(document).updateComment(commentModel, "try to update"); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError() + .containsSummary(RestErrorModel.AUTHENTICATION_FAILED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify entry content in response") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) + public void checkEntryContentInResponse() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by admin"); + commentModel = restClient.withCoreAPI().usingResource(document).updateComment(commentModel, "This is the updated comment with admin user"); + restClient.assertStatusCodeIs(HttpStatus.OK); + commentModel.assertThat().field("content").is("This is the updated comment with admin user"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Manager user updates comments created by admin user and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void managerIsAbleToUpdateHisComment() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by manager"); + restClient.withCoreAPI().usingResource(document).updateComment(commentModel, "This is the updated comment with Manager user") + .and().field("content").is("This is the updated comment with Manager user") + .and().field("canEdit").is(true) + .and().field("canDelete").is(true); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Contributor user can update his own comment and status code is 200") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void contributorIsAbleToUpdateHisComment() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by contributor"); + String updatedContent = "This is the updated comment with Contributor user"; + restClient.withCoreAPI().usingResource(document).updateComment(commentModel, updatedContent); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Consumer user can not update comments created by admin user and status code is 403") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void consumerIsNotAbleToUpdateComment() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by admin"); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + restClient.withCoreAPI().usingResource(document).updateComment(commentModel, "This is the updated comment with Consumer user"); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Collaborator user can update his own comment and status code is 200") +// @Bug(id="REPO-1011") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void collaboratorIsAbleToUpdateHisComment() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by collaborator"); + restClient.withCoreAPI().usingResource(document).updateComment(commentModel, "This is the updated comment with Collaborator user"); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Collaborator user can not update comments of another user and status code is 200") +// @Bug(id="MNT-2502",description="seems it's one old issue: also logged as MNT-2502, MNT-2346") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void collaboratorIsNotAbleToUpdateCommentOfAnotherUser() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by admin"); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(document).updateComment(commentModel, "This is the updated comment with Collaborator user"); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify update comment with inexistent nodeId returns status code 404") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void canNotUpdateCommentIfNodeIdIsNotSet() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUserModel); + + FolderModel content = FolderModel.getRandomFolderModel(); + content.setNodeRef("node ref that does not exist"); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment"); + restClient.withCoreAPI().usingResource(content).updateComment(commentModel, "This is the updated comment."); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary("node ref that does not exist was not found"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify if commentId is not set the status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void canNotUpdateCommentIfCommentIdIsNotSet() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUserModel); + + RestCommentModel comment = new RestCommentModel(); + String id = "comment id that does not exist"; + comment.setId(id); + restClient.withCoreAPI().usingResource(document).updateComment(comment, "This is the updated comment."); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, id)); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify can not update comment if NodeId is neither document or folder and returns status code 405") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void canNotUpdateCommentIfNodeIdIsNeitherDocumentOrFolder() throws JsonToModelConversionException, Exception + { + FileModel content = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); + content = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(content).addComment("This is a new comment"); + + LinkModel link = dataLink.usingAdmin().usingSite(siteModel).createRandomLink(); + content.setNodeRef(link.getNodeRef().replace("workspace://SpacesStore/", "workspace%3A%2F%2FSpacesStore%2F")); + + restClient.withCoreAPI().usingResource(content).updateComment(commentModel, "This is the updated comment."); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, content.getNodeRef())) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify Admin user is not able to update with empty comment body and status code is 400") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void adminIsNotAbleToUpdateWithEmptyCommentBody() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUserModel); + commentModel = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment added by admin"); + restClient.withCoreAPI().usingResource(document).updateComment(commentModel, ""); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary("An invalid argument was received"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify updated comment by Manager is listed when calling getComments and status code is 200") +// @Bug(id="REPO-1011") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void updatedCommentByManagerIsListed() throws JsonToModelConversionException, Exception + { + commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(document).addComment("This is a new comment added by collaborator"); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI() + .usingResource(document).updateComment(commentModel, "This is the updated comment with Manager user"); + comments = restClient.withCoreAPI().usingResource(document).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", "This is the updated comment with Manager user"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify Manager user can update a comment with a large string") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void managerIsAbleToUpdateACommentWithALargeString() throws JsonToModelConversionException, Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + String longString = RandomStringUtils.randomAlphanumeric(10000); + + commentModel = restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedCommentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(file).updateComment(commentModel, longString); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCommentModel.assertThat().field("content").is(longString); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify Manager user can update a comment with a short string") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void managerIsAbleToUpdateACommentWithAShortString() throws JsonToModelConversionException, Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + String shortString = RandomStringUtils.randomAlphanumeric(2); + + commentModel = restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedCommentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(file).updateComment(commentModel, shortString); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCommentModel.assertThat().field("content").is(shortString); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify Collaborator user can update a comment with special characters") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void collaboratorIsAbleToUpdateACommentThatContainsSpecialChars() throws JsonToModelConversionException, Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + String specialChars = "!@#$%^&*()'\".,<>-_+=|\\"; + + commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedCommentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(file).updateComment(commentModel, specialChars); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCommentModel.assertThat().field("content").is(specialChars); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Check that you cannot update comment with Consumer then call getComments and check new comment is not listed") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void cannotUpdateCommentWithConsumerCallGetComments() throws JsonToModelConversionException, Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", firstComment) + .and().entriesListDoesNotContain("content", updatedComment) + .and().paginationField("totalItems").is("1"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Update comment with Contributor then call getComments and check new comment is listed") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + @Bug(id = "ACE-4614") + public void updateCommentWithContributorCallGetComments() throws JsonToModelConversionException, Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); + restClient.assertStatusCodeIs(HttpStatus.OK); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", updatedComment) + .and().entriesListDoesNotContain("content", firstComment) + .and().paginationField("totalItems").is("1"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Update comment with Collaborator then call getComments and check new comment is listed") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void updateCommentWithCollaboratorCallGetComments() throws JsonToModelConversionException, Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); + restClient.assertStatusCodeIs(HttpStatus.OK); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", updatedComment) + .and().entriesListDoesNotContain("content", firstComment) + .and().paginationField("totalItems").is("1"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Update comment with Manager then check modified by information in response") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void updateCommentWithManagerCheckModifiedBy() throws JsonToModelConversionException, Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + UserModel manager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); + + commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedCommentModel = restClient.authenticateUser(manager).withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCommentModel.assertThat().field("modifiedBy.id").is(manager.getUsername()) + .and().field("content").is(updatedComment); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Delete comment with Admin then try to update it") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void deleteCommentThenTryToUpdateIt() throws JsonToModelConversionException, Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.withCoreAPI().usingResource(file).deleteComment(commentModel); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + restClient.withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify Manager user can update a comment with multi byte content") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void managerIsAbleToUpdateACommentWithMultiByteContent() throws JsonToModelConversionException, Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + String multiByte = "\ufeff\u6768\u6728\u91d1"; + + commentModel = restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + returnedCommentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(file).updateComment(commentModel, multiByte); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCommentModel.assertThat().field("content").is(multiByte); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify Admin user can update a comment with properties parameter") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void adminIsAbleToUpdateACommentWithPropertiesParameter() throws JsonToModelConversionException, Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + UserModel manager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); + + returnedCommentModel = restClient.authenticateUser(manager) + .withParams("properties=createdBy,modifiedBy,canEdit,canDelete").withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedCommentModel.assertThat().field("createdBy.id").is(adminUserModel.getUsername()) + .assertThat().field("modifiedBy.id").is(manager.getUsername()) + .assertThat().fieldsCount().is(4); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, + description = "Update comment with invalid node") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void updateCommentUsingInvalidNodeId() throws JsonToModelConversionException, Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(adminUserModel) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + file.setNodeRef(RandomStringUtils.randomAlphanumeric(20)); + restClient.withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, file.getNodeRef())); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Verify update comment from node with invalid network id returns status code 401") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void updateCommentWithInvalidNetworkId() throws Exception + { + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment(firstComment); + networkUserModel.setDomain("invalidNetwork"); + restClient.authenticateUser(networkUserModel).withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError().containsSummary(RestErrorModel.AUTHENTICATION_FAILED); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.COMMENTS }, executionType = ExecutionType.REGRESSION, description = "Verify User can not update comment to a not joined private site. Status code returned is 403") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void userCanNotUpdateCommentToANotJoinedPrivateSiteDefaultErrorModelSchema() throws Exception + { + UserModel newUser = dataUser.createRandomTestUser(); + FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + commentModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(file).addComment(firstComment); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + restClient.authenticateUser(newUser).withCoreAPI().usingResource(file).updateComment(commentModel, updatedComment); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY); + } +}