diff --git a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsCoreTests.java b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentCoreTests.java similarity index 89% rename from e2e-test/java/org/alfresco/rest/comments/UpdateCommentsCoreTests.java rename to e2e-test/java/org/alfresco/rest/comments/UpdateCommentCoreTests.java index 43ed657fb..1625945e8 100644 --- a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsCoreTests.java +++ b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentCoreTests.java @@ -21,7 +21,7 @@ import org.springframework.http.HttpStatus; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -public class UpdateCommentsCoreTests extends RestTest +public class UpdateCommentCoreTests extends RestTest { private UserModel adminUserModel; private FileModel document; @@ -74,21 +74,22 @@ public class UpdateCommentsCoreTests extends RestTest @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") +// @Bug(id="REPO-1011") @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) public void updatedCommentByManagerIsListed() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); - 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"); + 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 Collaborator user"); + comments.assertThat().entriesListContains("content", "This is the updated comment with Manager user"); } @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") +// @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 { diff --git a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentFullTests.java b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentFullTests.java new file mode 100644 index 000000000..f15aba274 --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentFullTests.java @@ -0,0 +1,285 @@ +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; +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.apache.commons.lang.RandomStringUtils; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class UpdateCommentFullTests extends RestTest +{ + private UserModel adminUserModel, networkUserModel; + private SiteModel siteModel; + private RestCommentModel commentModel, returnedCommentModel; + private RestCommentModelsCollection comments; + private DataUser.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(); + networkUserModel = dataUser.createRandomTestUser(); + restClient.authenticateUser(adminUserModel); + siteModel = dataSite.usingUser(adminUserModel).createPrivateRandomSite(); + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, + UserRole.SiteConsumer, UserRole.SiteContributor); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.FULL}, 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.FULL}, 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.FULL}, 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.FULL}, 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.FULL}, 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.FULL}, 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.FULL}, 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.FULL}, 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.FULL}, 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.FULL}, 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.FULL }, 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.FULL, 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.FULL, 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); + } +} \ No newline at end of file diff --git a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTests.java b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentSanityTests.java similarity index 97% rename from e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTests.java rename to e2e-test/java/org/alfresco/rest/comments/UpdateCommentSanityTests.java index 05badefac..87756ff4e 100644 --- a/e2e-test/java/org/alfresco/rest/comments/UpdateCommentsSanityTests.java +++ b/e2e-test/java/org/alfresco/rest/comments/UpdateCommentSanityTests.java @@ -19,7 +19,7 @@ import org.springframework.http.HttpStatus; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -public class UpdateCommentsSanityTests extends RestTest +public class UpdateCommentSanityTests extends RestTest { private UserModel adminUserModel; private FileModel document; @@ -93,7 +93,7 @@ public class UpdateCommentsSanityTests extends RestTest @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify Collaborator user can update his own comment and status code is 200") - @Bug(id="REPO-1011") +// @Bug(id="REPO-1011") @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) public void collaboratorIsAbleToUpdateHisComment() throws JsonToModelConversionException, Exception {