mirror of
https://github.com/Alfresco/SearchServices.git
synced 2026-09-16 18:12:56 +00:00
110 lines
6.5 KiB
Java
110 lines
6.5 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.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 DeleteCommentSanityTests 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")
|
|
@Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY })
|
|
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")
|
|
@Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY })
|
|
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")
|
|
@Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY })
|
|
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")
|
|
@Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY })
|
|
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);
|
|
}
|
|
|
|
@TestRail(section = { TestGroup.REST_API,
|
|
TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify Consumer user cannot delete comments and status code returned is 403")
|
|
@Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY })
|
|
public void consumerIsNotAbleToDeleteComments() throws JsonToModelConversionException, Exception
|
|
{
|
|
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
|
|
comment = restClient.withCoreAPI().usingResource(document).addComment("New comment added by Manager");
|
|
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer));
|
|
restClient.withCoreAPI().usingResource(document).deleteComment(comment);
|
|
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
|
|
}
|
|
|
|
@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")
|
|
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).assertLastError()
|
|
.containsSummary(RestErrorModel.AUTHENTICATION_FAILED);
|
|
}
|
|
}
|