package org.alfresco.rest.comments; import org.alfresco.dataprep.CMISUtil; 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.RandomData; import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.SiteModel; 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.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; /** * Created by Claudia Agache on 10/10/2016. */ @Test(groups = { "rest-api", "comments", "sanity" }) public class AddCommentsSanityTests extends RestTest { @Autowired RestCommentsApi commentsAPI; @Autowired DataUser dataUser; private UserModel adminUserModel; private FileModel document; private SiteModel siteModel; private DataUser.ListUserWithRoles usersWithRoles; private String comment1, comment2; @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(CMISUtil.DocumentType.TEXT_PLAIN); usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); } @BeforeMethod(alwaysRun = true) public void generateRandomComments() { comment1 = RandomData.getRandomName("comment1"); comment2 = RandomData.getRandomName("comment2"); } @TestRail(section = { "rest-api", "comments" }, executionType = ExecutionType.SANITY, description = "Verify admin user adds multiple comments with Rest API and status code is 201") public void adminIsAbleToAddComments() throws JsonToModelConversionException, Exception { commentsAPI.addComments(document, comment1, comment2); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED); } @TestRail(section = { "rest-api", "comments" }, executionType = ExecutionType.SANITY, description = "Verify Manager user adds multiple comments with Rest API and status code is 201") public void managerIsAbleToAddComments() throws JsonToModelConversionException, Exception { restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); commentsAPI.addComments(document, comment1, comment2); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED); } @TestRail(section = { "rest-api", "comments" }, executionType = ExecutionType.SANITY, description = "Verify Contributor user adds multiple comments with Rest API and status code is 201") public void contributorIsAbleToAddComments() throws JsonToModelConversionException, Exception { restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); commentsAPI.addComments(document, comment1, comment2); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED); } @TestRail(section = { "rest-api", "comments" }, executionType = ExecutionType.SANITY, description = "Verify Collaborator user adds multiple comments with Rest API and status code is 201") public void collaboratorIsAbleToAddComments() throws JsonToModelConversionException, Exception { restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); commentsAPI.addComments(document, comment1, comment2); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED); } @TestRail(section = { "rest-api", "comments" }, executionType = ExecutionType.SANITY, description = "Verify Consumer user adds multiple comments with Rest API and status code is 201") public void consumerIsAbleToAddComments() throws JsonToModelConversionException, Exception { restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); commentsAPI.addComments(document, comment1, comment2); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN); } @TestRail(section = { "rest-api", "comments" }, executionType = ExecutionType.SANITY, description = "Verify unauthenticated user gets status code 401 on post multiple comments call") @Bug(id="MNT-16904") public void unauthenticatedUserIsNotAbleToAddComments() throws JsonToModelConversionException, Exception { restClient.authenticateUser(new UserModel("random user", "random password")); commentsAPI.addComments(document, comment1, comment2); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED); } }