Added Asserts on comments

This commit is contained in:
Andreea Nechifor
2016-10-25 10:23:30 +03:00
parent 07262e8a70
commit 7539ab5097
5 changed files with 114 additions and 53 deletions
@@ -7,6 +7,7 @@ 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.ErrorModel;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.TestGroup;
@@ -15,6 +16,7 @@ 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.dao.PermissionDeniedDataAccessException;
import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -24,15 +26,15 @@ public class AddCommentSanityTests 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
{
@@ -40,60 +42,70 @@ public class AddCommentSanityTests extends RestTest
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);
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 adds comments with Rest API and status code is 201")
@TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify admin user adds comments with Rest API and status code is 201")
public void adminIsAbleToAddComment() throws JsonToModelConversionException, Exception
{
restClient.authenticateUser(adminUserModel);
commentsAPI.addComment(document, "This is a new comment added by " + adminUserModel.getUsername());
String newContent = "This is a new comment added by " + adminUserModel.getUsername();
commentsAPI.addComment(document, newContent)
.and().assertField("content").isNotEmpty()
.and().assertField("content").is(newContent);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify Manager user adds comments with Rest API and status code is 201")
@TestRail(section = { TestGroup.REST_API, TestGroup.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);
String contentSiteManger = "This is a new comment added by user with role: " + UserRole.SiteManager;
commentsAPI.addComment(document, contentSiteManger)
.and().assertField("content").isNotEmpty()
.and().assertField("content").is(contentSiteManger);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify Contributor user adds comments with Rest API and status code is 201")
@TestRail(section = { TestGroup.REST_API, TestGroup.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);
String contentSiteContributor = "This is a new comment added by user with role" + UserRole.SiteContributor;
commentsAPI.addComment(document, contentSiteContributor)
.and().assertField("content").isNotEmpty()
.and().assertField("content").is(contentSiteContributor);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify Collaborator user adds comments with Rest API and status code is 201")
@TestRail(section = { TestGroup.REST_API, TestGroup.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);
String contentSiteCollaborator = "This is a new comment added by user with role: " + UserRole.SiteCollaborator;
commentsAPI.addComment(document, contentSiteCollaborator)
.and().assertField("content").isNotEmpty()
.and().assertField("content").is(contentSiteCollaborator);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify Consumer user adds comments with Rest API and status code is 201")
public void consumerIsAbleToAddComment() throws JsonToModelConversionException, Exception
@TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify Consumer user can't add comments with Rest API and status code is 403")
public void consumerIsNotAbleToAddComment() 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);
String contentSiteConsumer = "This is a new comment added by user with role: " + UserRole.SiteConsumer;
commentsAPI.addComment(document, contentSiteConsumer);
commentsAPI.usingRestWrapper()
.assertStatusCodeIs(HttpStatus.FORBIDDEN)
.assertLastError().containsSummary(ErrorModel.PERMISSION_WAS_DENIED);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify unauthenticated user gets status code 401 on post comments call")
@Bug(id="MNT-16904")
@TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify unauthenticated user gets status code 401 on post comments call")
@Bug(id = "MNT-16904")
public void unauthenticatedUserIsNotAbleToAddComment() throws JsonToModelConversionException, Exception
{
{
restClient.authenticateUser(new UserModel("random user", "random password"));
commentsAPI.addComment(document, "This is a new comment");
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED);
@@ -7,6 +7,7 @@ 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.ErrorModel;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.TestGroup;
@@ -59,7 +60,10 @@ public class AddCommentsSanityTests extends RestTest
public void adminIsAbleToAddComments() throws JsonToModelConversionException, Exception
{
restClient.authenticateUser(adminUserModel);
commentsAPI.addComments(document, comment1, comment2);
commentsAPI.addComments(document, comment1, comment2)
.assertEntriesListIsNotEmpty()
.assertEntriesListContains("content", comment1)
.assertEntriesListContains("content", comment2);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED);
}
@@ -68,7 +72,11 @@ public class AddCommentsSanityTests extends RestTest
public void managerIsAbleToAddComments() throws JsonToModelConversionException, Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
commentsAPI.addComments(document, comment1, comment2);
commentsAPI.addComments(document, comment1, comment2)
.assertEntriesListIsNotEmpty()
.assertEntriesListContains("content", comment1)
.assertEntriesListContains("content", comment2);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED);
}
@@ -77,7 +85,10 @@ public class AddCommentsSanityTests extends RestTest
public void contributorIsAbleToAddComments() throws JsonToModelConversionException, Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor));
commentsAPI.addComments(document, comment1, comment2);
commentsAPI.addComments(document, comment1, comment2)
.assertEntriesListIsNotEmpty()
.assertEntriesListContains("content", comment1)
.assertEntriesListContains("content", comment2);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED);
}
@@ -86,7 +97,10 @@ public class AddCommentsSanityTests extends RestTest
public void collaboratorIsAbleToAddComments() throws JsonToModelConversionException, Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
commentsAPI.addComments(document, comment1, comment2);
commentsAPI.addComments(document, comment1, comment2)
.assertEntriesListIsNotEmpty()
.assertEntriesListContains("content", comment1)
.assertEntriesListContains("content", comment2);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED);
}
@@ -96,7 +110,10 @@ public class AddCommentsSanityTests extends RestTest
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer));
commentsAPI.addComments(document, comment1, comment2);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN);
commentsAPI.usingRestWrapper()
.assertStatusCodeIs(HttpStatus.FORBIDDEN)
.assertLastError().containsSummary(ErrorModel.PERMISSION_WAS_DENIED);
}
@TestRail(section = { TestGroup.REST_API,
@@ -8,6 +8,7 @@ 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.ErrorModel;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.TestGroup;
@@ -81,7 +82,8 @@ public class DeleteCommentsSanityTests extends RestTest
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
commentsAPI.deleteComment(document, comment);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN)
.assertLastError().containsSummary(ErrorModel.PERMISSION_WAS_DENIED);
}
@TestRail(section = { TestGroup.REST_API,
@@ -90,7 +92,9 @@ public class DeleteCommentsSanityTests extends RestTest
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor));
commentsAPI.deleteComment(document, comment);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN);
commentsAPI.usingRestWrapper()
.assertStatusCodeIs(HttpStatus.FORBIDDEN)
.assertLastError().containsSummary(ErrorModel.PERMISSION_WAS_DENIED);
}
@TestRail(section = { TestGroup.REST_API,
@@ -99,7 +103,9 @@ public class DeleteCommentsSanityTests extends RestTest
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer));
commentsAPI.deleteComment(document, comment);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN);
commentsAPI.usingRestWrapper()
.assertStatusCodeIs(HttpStatus.FORBIDDEN)
.assertLastError().containsSummary(ErrorModel.PERMISSION_WAS_DENIED);
}
@TestRail(section = { TestGroup.REST_API,
@@ -110,6 +116,7 @@ public class DeleteCommentsSanityTests extends RestTest
restClient.authenticateUser(nonexistentModel);
commentsAPI.deleteComment(document, comment);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED);
}
}
@@ -34,6 +34,7 @@ public class GetCommentsSanityTests extends RestTest
private SiteModel siteModel;
private UserModel userModel;
private ListUserWithRoles usersWithRoles;
private String content;
@BeforeClass(alwaysRun=true)
public void dataPreparation() throws Exception
@@ -43,7 +44,8 @@ public class GetCommentsSanityTests extends RestTest
siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite();
commentsAPI.useRestClient(restClient);
document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN);
commentsAPI.addComment(document, "This is a new comment");
content = "This is a new comment";
commentsAPI.addComment(document, content);
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor);
}
@@ -62,7 +64,9 @@ public class GetCommentsSanityTests extends RestTest
public void managerIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
commentsAPI.getNodeComments(document);
commentsAPI.getNodeComments(document)
.and().assertField("content").isNotEmpty()
.and().assertField("content").is(content);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
}
@@ -71,7 +75,9 @@ public class GetCommentsSanityTests extends RestTest
public void contributorIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor));
commentsAPI.getNodeComments(document);
commentsAPI.getNodeComments(document)
.and().assertField("content").isNotEmpty()
.and().assertField("content").is(content);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
}
@@ -80,7 +86,9 @@ public class GetCommentsSanityTests extends RestTest
public void collaboratorIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
commentsAPI.getNodeComments(document);
commentsAPI.getNodeComments(document)
.and().assertField("content").isNotEmpty()
.and().assertField("content").is(content);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
}
@@ -89,7 +97,9 @@ public class GetCommentsSanityTests extends RestTest
public void consumerIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer));
commentsAPI.getNodeComments(document);
commentsAPI.getNodeComments(document)
.and().assertField("content").isNotEmpty()
.and().assertField("content").is(content);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
}
@@ -110,10 +120,13 @@ public class GetCommentsSanityTests extends RestTest
{
userModel = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator);
restClient.authenticateUser(userModel);
commentsAPI.addComment(document, "This is a new comment added by " + userModel.getUsername());
String contentManager = "This is a new comment added by " + userModel.getUsername();
commentsAPI.addComment(document,contentManager);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
commentsAPI.getNodeComments(document);
commentsAPI.getNodeComments(document)
.and().assertField("content").isNotEmpty()
.and().assertField("content").is(contentManager);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
}
@@ -123,10 +136,13 @@ public class GetCommentsSanityTests extends RestTest
{
userModel = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator);
restClient.authenticateUser(userModel);
commentsAPI.addComment(document, "This is a new comment added by " + userModel.getUsername());
String contentCollaborator = "This is a new comment added by " + userModel.getUsername();
commentsAPI.addComment(document, contentCollaborator);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED);
restClient.authenticateUser(adminUserModel);
commentsAPI.getNodeComments(document);
commentsAPI.getNodeComments(document)
.and().assertField("content").isNotEmpty()
.and().assertField("content").is(contentCollaborator);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
}
}
@@ -8,6 +8,7 @@ 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.ErrorModel;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FolderModel;
import org.alfresco.utility.model.SiteModel;
@@ -54,7 +55,10 @@ public class UpdateCommentsSanityTests extends RestTest
public void adminIsAbleToUpdateComments() throws JsonToModelConversionException, Exception
{
restClient.authenticateUser(adminUserModel);
commentsAPI.updateComment(document, commentModel, "This is the updated comment with admin user");
String updatedContent = "This is the updated comment with admin user";
commentsAPI.updateComment(document, commentModel, updatedContent)
.and().assertField("content").isNotEmpty()
.and().assertField("content").is(updatedContent);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
}
@@ -65,7 +69,7 @@ public class UpdateCommentsSanityTests extends RestTest
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
commentsAPI.updateComment(document, commentModel, "This is the updated comment with Manager user")
.and().assertField("content").is("This is the updated comment with Manager user")
.and().assertField("canDelete").is(true);
.and().assertField("canEdit").is(true);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
}
@@ -74,8 +78,10 @@ public class UpdateCommentsSanityTests extends RestTest
public void contributorIsNotAbleToUpdateComment() throws JsonToModelConversionException, Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor));
commentsAPI.updateComment(document, commentModel, "This is the updated comment with Contributor user");
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN);
String updatedContent = "This is the updated comment with Contributor user";
commentsAPI.updateComment(document, commentModel, updatedContent);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN)
.assertLastError().containsSummary(ErrorModel.PERMISSION_WAS_DENIED);
}
@TestRail(section = { TestGroup.REST_API,
@@ -84,7 +90,8 @@ public class UpdateCommentsSanityTests extends RestTest
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer));
commentsAPI.updateComment(document, commentModel, "This is the updated comment with Consumer user");
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN)
.assertLastError().containsSummary(ErrorModel.PERMISSION_WAS_DENIED);
}
@TestRail(section = { TestGroup.REST_API,
@@ -93,10 +100,10 @@ public class UpdateCommentsSanityTests extends RestTest
public void collaboratorIsNotAbleToUpdateComment() throws JsonToModelConversionException, Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
commentsAPI.updateComment(document, commentModel, "This is the updated comment with Collaborator user")
.and().assertField("content").is("This is the updated comment with Collaborator user");
commentsAPI.updateComment(document, commentModel, "This is the updated comment with Collaborator user");
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN)
.assertLastError().containsSummary(ErrorModel.PERMISSION_WAS_DENIED);
}
@TestRail(section = { TestGroup.REST_API,
@@ -118,7 +125,8 @@ public class UpdateCommentsSanityTests extends RestTest
FolderModel content = FolderModel.getRandomFolderModel();
content.setNodeRef("node ref that does not exist");
commentsAPI.updateComment(content, commentModel, "This is the updated comment.");
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.NOT_FOUND);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.NOT_FOUND)
.assertLastError().containsSummary("node ref that does not exist was not found");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.SANITY }, executionType = ExecutionType.SANITY, description = "Verify if commentId is not set the status code is 404")
@@ -130,7 +138,8 @@ public class UpdateCommentsSanityTests extends RestTest
comment.setId("comment id that does not exist");
commentsAPI.updateComment(document, comment, "This is the updated comment.");
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.NOT_FOUND);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.NOT_FOUND)
.assertLastError().containsSummary("node ref that does not exist was not found");
}
}