From 176ebbdcd6a7afc354e587f2200f8875a78611d4 Mon Sep 17 00:00:00 2001 From: Paul Brodner Date: Thu, 29 Sep 2016 15:26:44 +0300 Subject: [PATCH] refactor based on latest conventions --- .../rest/comments/PostCommentsSanityTest.java | 101 ------------------ .../comments/PostCommentsSanityTests.java | 100 +++++++++++++++++ 2 files changed, 100 insertions(+), 101 deletions(-) delete mode 100644 e2e-test/java/org/alfresco/rest/comments/PostCommentsSanityTest.java create mode 100644 e2e-test/java/org/alfresco/rest/comments/PostCommentsSanityTests.java diff --git a/e2e-test/java/org/alfresco/rest/comments/PostCommentsSanityTest.java b/e2e-test/java/org/alfresco/rest/comments/PostCommentsSanityTest.java deleted file mode 100644 index fa884f8eb..000000000 --- a/e2e-test/java/org/alfresco/rest/comments/PostCommentsSanityTest.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.alfresco.rest.comments; - -import java.util.Arrays; -import java.util.HashMap; - -import org.alfresco.dataprep.CMISUtil.DocumentType; -import org.alfresco.rest.RestTest; -import org.alfresco.rest.exception.JsonToModelConversionException; -import org.alfresco.rest.requests.RestCommentsApi; -import org.alfresco.utility.data.DataUser; -import org.alfresco.utility.data.UserRole; -import org.alfresco.utility.model.FileModel; -import org.alfresco.utility.model.SiteModel; -import org.alfresco.utility.model.UserModel; -import org.alfresco.utility.testrail.ExecutionType; -import org.alfresco.utility.testrail.annotation.TestRail; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -@Test(groups = { "rest-api", "comments", "sanity" }) -public class PostCommentsSanityTest extends RestTest -{ - @Autowired - RestCommentsApi commentsAPI; - - @Autowired - DataUser dataUser; - - private UserModel adminUserModel; - private FileModel document; - private SiteModel siteModel; - private HashMap usersWithRoles; - - @BeforeClass - public void initTest() throws Exception - { - adminUserModel = dataUser.getAdminUser(); - restClient.authenticateUser(adminUserModel); - siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); - commentsAPI.useRestClient(restClient); - document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, Arrays.asList(UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor)); - } - - @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, - description= "Verify admin user adds comments with Rest API and status code is 201") - public void admiIsAbleToAddComment() throws JsonToModelConversionException, Exception - { - commentsAPI.addComment(document.getNodeRef(), "This is a new comment added by " + adminUserModel.getUsername()); - commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED.toString()); - } - - @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, - description= "Verify Manager user adds comments with Rest API and status code is 201") - public void managerIsAbleToAddComment() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); - commentsAPI.addComment(document.getNodeRef(), "This is a new comment added by user with role: " + UserRole.SiteManager); - commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED.toString()); - } - - @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, - description= "Verify Contributor user adds comments with Rest API and status code is 201") - public void contributorIsAbleToAddComment() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteContributor)); - commentsAPI.addComment(document.getNodeRef(), "This is a new comment added by user with role" + UserRole.SiteContributor); - commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED.toString()); - } - - @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, - description= "Verify Collaborator user adds comments with Rest API and status code is 201") - public void collaboratorIsAbleToAddComment() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteCollaborator)); - commentsAPI.addComment(document.getNodeRef(), "This is a new comment added by user with role: " + UserRole.SiteCollaborator); - commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED.toString()); - } - - @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, - description= "Verify Consumer user adds comments with Rest API and status code is 201") - public void consumerIsAbleToAddComment() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteConsumer)); - commentsAPI.addComment(document.getNodeRef(), "This is a new comment added by user with role: " + UserRole.SiteConsumer); - commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN.toString()); - } - - @TestRail(section = { "rest-api", - "comments" }, executionType = ExecutionType.SANITY, description = "Verify Manager user gets status code 401 if authentication call fails") - public void managerIsNotAbleToAddCommentIfAuthenticationFails() throws JsonToModelConversionException, Exception - { - usersWithRoles.get(UserRole.SiteManager).setPassword("wrongPassword"); - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); - commentsAPI.addComment(document.getNodeRef(), "This is a new comment added by user with role: " + UserRole.SiteManager); - commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED.toString()); - } - -} diff --git a/e2e-test/java/org/alfresco/rest/comments/PostCommentsSanityTests.java b/e2e-test/java/org/alfresco/rest/comments/PostCommentsSanityTests.java new file mode 100644 index 000000000..d7e8f85d7 --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/comments/PostCommentsSanityTests.java @@ -0,0 +1,100 @@ +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.requests.RestCommentsApi; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +@Test(groups = { "rest-api", "comments", "sanity" }) +public class PostCommentsSanityTests extends RestTest +{ + @Autowired + RestCommentsApi commentsAPI; + + @Autowired + DataUser dataUser; + + private UserModel adminUserModel; + private FileModel document; + private SiteModel siteModel; + private ListUserWithRoles usersWithRoles; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + restClient.authenticateUser(adminUserModel); + siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + commentsAPI.useRestClient(restClient); + document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); + } + + @TestRail(section = { "rest-api", + "comments" }, executionType = ExecutionType.SANITY, description = "Verify admin user adds comments with Rest API and status code is 201") + public void admiIsAbleToAddComment() throws JsonToModelConversionException, Exception + { + commentsAPI.addComment(document, "This is a new comment added by " + adminUserModel.getUsername()); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED); + } + + @TestRail(section = { "rest-api", + "comments" }, executionType = ExecutionType.SANITY, description = "Verify Manager user adds comments with Rest API and status code is 201") + public void managerIsAbleToAddComment() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + commentsAPI.addComment(document, "This is a new comment added by user with role: " + UserRole.SiteManager); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED); + } + + @TestRail(section = { "rest-api", + "comments" }, executionType = ExecutionType.SANITY, description = "Verify Contributor user adds comments with Rest API and status code is 201") + public void contributorIsAbleToAddComment() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + commentsAPI.addComment(document, "This is a new comment added by user with role" + UserRole.SiteContributor); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED); + } + + @TestRail(section = { "rest-api", + "comments" }, executionType = ExecutionType.SANITY, description = "Verify Collaborator user adds comments with Rest API and status code is 201") + public void collaboratorIsAbleToAddComment() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + commentsAPI.addComment(document, "This is a new comment added by user with role: " + UserRole.SiteCollaborator); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED); + } + + @TestRail(section = { "rest-api", + "comments" }, executionType = ExecutionType.SANITY, description = "Verify Consumer user adds comments with Rest API and status code is 201") + public void consumerIsAbleToAddComment() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + commentsAPI.addComment(document, "This is a new comment added by user with role: " + UserRole.SiteConsumer); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN); + } + + @TestRail(section = { "rest-api", + "comments" }, executionType = ExecutionType.SANITY, description = "Verify Manager user gets status code 401 if authentication call fails") + public void managerIsNotAbleToAddCommentIfAuthenticationFails() throws JsonToModelConversionException, Exception + { + UserModel siteManager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); + siteManager.setPassword("wrongPassword"); + restClient.authenticateUser(siteManager); + commentsAPI.addComment(document, "This is a new comment added by user with role: " + UserRole.SiteManager); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } + +}