Files
SearchServices/e2e-test/java/org/alfresco/rest/comments/DeleteCommentsSanityTests.java
T
2016-11-23 14:27:09 +02:00

90 lines
5.0 KiB
Java

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.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.model.*;
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;
@Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY })
public class DeleteCommentsSanityTests extends RestTest
{
private UserModel adminUserModel;
private FileModel document;
private SiteModel siteModel;
private RestCommentModel comment;
private ListUserWithRoles usersWithRoles;
@BeforeClass(alwaysRun=true)
public void dataPreparation() throws Exception
{
adminUserModel = dataUser.getAdminUser();
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")
public void adminIsAbleToDeleteComments() throws JsonToModelConversionException, Exception
{
restClient.authenticateUser(adminUserModel);
comment = restClient.withCoreAPI().usingResource(document).addComment("This is a new comment");
restClient.withCoreAPI().usingResource(document).deleteComment(comment);
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify Manager user deletes own comments and status code is 204")
public void managerIsAbleToDeleteComments() throws JsonToModelConversionException, Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
comment = restClient.withCoreAPI().usingResource(document).addComment("New comment added by Manager");
restClient.withCoreAPI().usingResource(document).deleteComment(comment);
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify Collaborator user deletes own comments and status code is 204")
public void collaboratorIsAbleToDeleteComments() throws JsonToModelConversionException, Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
comment = restClient.withCoreAPI().usingResource(document).addComment("New comment added by Collaborator");
restClient.withCoreAPI().usingResource(document).deleteComment(comment);
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify Contributor user deletes own comments and status code is 204")
public void contributorIsAbleToDeleteComments() throws JsonToModelConversionException, Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor));
comment = restClient.withCoreAPI().usingResource(document).addComment("New comment added by Contributor");
restClient.withCoreAPI().usingResource(document).deleteComment(comment);
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
}
@Bug(id="MNT-16904")
@TestRail(section = { TestGroup.REST_API,
TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify User gets status code 401 if authentication call fails")
public void userIsNotAbleToDeleteCommentIfAuthenticationFails() throws JsonToModelConversionException, Exception
{
restClient.authenticateUser(adminUserModel);
comment = restClient.withCoreAPI().usingResource(document).addComment("New comment addded by admin");
UserModel nonexistentModel = new UserModel("nonexistentUser", "nonexistentPassword");
restClient.authenticateUser(nonexistentModel);
restClient.withCoreAPI().usingResource(document).deleteComment(comment);
restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastException().hasName(StatusModel.UNAUTHORIZED);
}
}