Merge branch 'TAS-CommentsAsserts' of gitlab.alfresco.com:tas/alfresco-tas-restapi-test

# Conflicts:
#	src/test/java/org/alfresco/rest/comments/AddCommentsSanityTests.java
#	src/test/java/org/alfresco/rest/comments/UpdateCommentsSanityTests.java
This commit is contained in:
Paul Brodner
2016-10-25 13:48:28 +03:00
5 changed files with 108 additions and 52 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;
@@ -24,15 +25,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 +41,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)
.assertThat().field("content").isNotEmpty()
.and().field("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)
.assertThat().field("content").isNotEmpty()
.and().field("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)
.assertThat().field("content").isNotEmpty()
.and().field("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)
.assertThat().field("content").isNotEmpty()
.and().field("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)
.assertThat().entriesListIsNotEmpty()
.and().entriesListContains("content", comment1)
.and().entriesListContains("content", comment2);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED);
}
@@ -68,7 +72,10 @@ 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)
.assertThat().entriesListIsNotEmpty()
.and().entriesListContains("content", comment1)
.and().entriesListContains("content", comment2);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED);
}
@@ -77,7 +84,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)
.assertThat().entriesListIsNotEmpty()
.and().entriesListContains("content", comment1)
.and().entriesListContains("content", comment2);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED);
}
@@ -88,7 +98,8 @@ public class AddCommentsSanityTests extends RestTest
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
commentsAPI.addComments(document, comment1, comment2)
.assertThat().paginationExist().and().entriesListIsNotEmpty()
.and().paginationExist().and().paginationField("maxItems").is("100");
.and().entriesListContains("content", comment1)
.and().entriesListContains("content", comment2);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED);
}
@@ -99,7 +110,9 @@ 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)
.assertThat().entriesListContains("content", 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)
.assertThat().entriesListContains("content", content);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
}
@@ -80,7 +86,8 @@ public class GetCommentsSanityTests extends RestTest
public void collaboratorIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
commentsAPI.getNodeComments(document);
commentsAPI.getNodeComments(document)
.assertThat().entriesListContains("content", content);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
}
@@ -89,7 +96,8 @@ public class GetCommentsSanityTests extends RestTest
public void consumerIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer));
commentsAPI.getNodeComments(document);
commentsAPI.getNodeComments(document)
.assertThat().entriesListContains("content", content);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
}
@@ -110,10 +118,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)
.assertThat().entriesListContains("content", contentManager);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
}
@@ -123,10 +134,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)
.assertThat().entriesListContains("content", 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)
.assertThat().field("content").isNotEmpty()
.and().field("content").is(updatedContent);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
}
@@ -63,8 +67,9 @@ public class UpdateCommentsSanityTests extends RestTest
public void managerIsAbleToUpdateComment() throws JsonToModelConversionException, Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
commentsAPI.updateComment(document, commentModel, "This is the updated comment with Manager user")
.assertThat().field("content").is("This is the updated comment with Manager user")
commentsAPI.updateComment(document, commentModel, "This is the updated comment with Manager user")
.and().field("content").is("This is the updated comment with Manager user")
.and().field("canEdit").is(true)
.and().field("canDelete").is(true);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
}
@@ -74,8 +79,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 +91,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,
@@ -96,7 +104,8 @@ public class UpdateCommentsSanityTests extends RestTest
commentsAPI.updateComment(document, commentModel, "This is the updated comment with Collaborator user")
.assertThat().field("content").is("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 +127,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 +140,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");
}
}