refacor based on naming conventions

This commit is contained in:
Paul Brodner
2016-09-29 16:17:50 +03:00
parent 91bafce719
commit 0a0e586283

View File

@@ -1,8 +1,5 @@
package org.alfresco.rest.comments; package org.alfresco.rest.comments;
import java.util.Arrays;
import java.util.HashMap;
import org.alfresco.dataprep.CMISUtil.DocumentType; import org.alfresco.dataprep.CMISUtil.DocumentType;
import org.alfresco.rest.RestTest; import org.alfresco.rest.RestTest;
import org.alfresco.rest.exception.JsonToModelConversionException; import org.alfresco.rest.exception.JsonToModelConversionException;
@@ -10,7 +7,9 @@ import org.alfresco.rest.model.RestCommentModel;
import org.alfresco.rest.requests.RestCommentsApi; import org.alfresco.rest.requests.RestCommentsApi;
import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser; import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FolderModel;
import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel; import org.alfresco.utility.model.UserModel;
import org.alfresco.utility.testrail.ExecutionType; import org.alfresco.utility.testrail.ExecutionType;
@@ -21,9 +20,8 @@ import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@Test(groups = { "rest-api", "comments", "sanity" }) @Test(groups = { "rest-api", "comments", "sanity" })
public class UpdateCommentsSanityTest extends RestTest public class UpdateCommentsSanityTests extends RestTest
{ {
@Autowired @Autowired
RestCommentsApi commentsAPI; RestCommentsApi commentsAPI;
@@ -34,65 +32,64 @@ public class UpdateCommentsSanityTest extends RestTest
private FileModel document; private FileModel document;
private SiteModel siteModel; private SiteModel siteModel;
private RestCommentModel commentModel; private RestCommentModel commentModel;
private HashMap<UserRole, UserModel> usersWithRoles; private ListUserWithRoles usersWithRoles;
@BeforeClass @BeforeClass(alwaysRun=true)
public void initTest() throws Exception public void dataPreparation() throws Exception
{ {
adminUserModel = dataUser.getAdminUser(); adminUserModel = dataUser.getAdminUser();
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite();
commentsAPI.useRestClient(restClient); commentsAPI.useRestClient(restClient);
document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN);
commentModel = commentsAPI.addComment(document.getNodeRef(), "This is a new comment"); commentModel = commentsAPI.addComment(document, "This is a new comment");
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel,UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor);
Arrays.asList(UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor));
} }
@TestRail(section = { "rest-api", @TestRail(section = { "rest-api",
"comments" }, executionType = ExecutionType.SANITY, description = "Verify Admin user updates comments with Rest API and status code is 200") "comments" }, executionType = ExecutionType.SANITY, description = "Verify Admin user updates comments with Rest API and status code is 200")
public void adminIsAbleToUpdateComments() throws JsonToModelConversionException, Exception public void adminIsAbleToUpdateComments() throws JsonToModelConversionException, Exception
{ {
commentsAPI.updateComment(document.getNodeRef(), commentModel.getId(), commentModel.getContent()); commentsAPI.updateComment(document, commentModel, commentModel.getContent());
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section = { "rest-api", @TestRail(section = { "rest-api",
"comments" }, executionType = ExecutionType.SANITY, description = "Verify Manager user updates comments created by admin user with Rest API and status code is 200") "comments" }, executionType = ExecutionType.SANITY, description = "Verify Manager user updates comments created by admin user with Rest API and status code is 200")
public void managerIsAbleToUpdateComment() throws JsonToModelConversionException, Exception public void managerIsAbleToUpdateComment() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
commentsAPI.updateComment(document.getNodeRef(), commentModel.getId(), commentModel.getContent()); commentsAPI.updateComment(document, commentModel, commentModel.getContent());
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section = { "rest-api", @TestRail(section = { "rest-api",
"comments" }, executionType = ExecutionType.SANITY, description = "Verify Contributor user updates comments created by admin user with Rest API and status code is 200") "comments" }, executionType = ExecutionType.SANITY, description = "Verify Contributor user updates comments created by admin user with Rest API and status code is 200")
public void contributorIsAbleToUpdateComment() throws JsonToModelConversionException, Exception public void contributorIsAbleToUpdateComment() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteContributor)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor));
commentsAPI.updateComment(document.getNodeRef(), commentModel.getId(), "This is the updated comment with Contributor user"); commentsAPI.updateComment(document, commentModel, "This is the updated comment with Contributor user");
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN.toString()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN);
} }
@TestRail(section = { "rest-api", @TestRail(section = { "rest-api",
"comments" }, executionType = ExecutionType.SANITY, description = "Verify Consumer user updates comments created by admin user with Rest API and status code is 200") "comments" }, executionType = ExecutionType.SANITY, description = "Verify Consumer user updates comments created by admin user with Rest API and status code is 200")
public void consumerIsAbleToUpdateComment() throws JsonToModelConversionException, Exception public void consumerIsAbleToUpdateComment() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteConsumer)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer));
commentsAPI.updateComment(document.getNodeRef(), commentModel.getId(), commentModel.getContent()); commentsAPI.updateComment(document, commentModel, commentModel.getContent());
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN.toString()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN);
} }
@TestRail(section = { "rest-api", @TestRail(section = { "rest-api",
"comments" }, executionType = ExecutionType.SANITY, description = "Verify Collaborator user updates comments created by admin user with Rest API and status code is 200") "comments" }, executionType = ExecutionType.SANITY, description = "Verify Collaborator user updates comments created by admin user with Rest API and status code is 200")
public void collaboratorIsAbleToUpdateComment() throws JsonToModelConversionException, Exception public void collaboratorIsAbleToUpdateComment() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteCollaborator)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
RestCommentModel commentEntry = commentsAPI.updateComment(document.getNodeRef(), commentModel.getId(), RestCommentModel commentEntry = commentsAPI.updateComment(document, commentModel,
"This is the updated comment with Collaborator user"); "This is the updated comment with Collaborator user");
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN.toString()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.FORBIDDEN);
commentEntry.assertCommentContentIs("This is the updated comment with Collaborator user"); commentEntry.assertCommentContentIs("This is the updated comment with Collaborator user");
} }
@@ -102,24 +99,24 @@ public class UpdateCommentsSanityTest extends RestTest
{ {
UserModel incorrectUserModel = new UserModel("userName", "password"); UserModel incorrectUserModel = new UserModel("userName", "password");
restClient.authenticateUser(incorrectUserModel); restClient.authenticateUser(incorrectUserModel);
commentsAPI.getNodeComments(document.getNodeRef()); commentsAPI.getNodeComments(document);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED.toString()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED);
} }
@TestRail(section = { "rest-api", "comments" }, executionType = ExecutionType.SANITY, description = "Verify if nodeId is not set the status code is 404") @TestRail(section = { "rest-api", "comments" }, executionType = ExecutionType.SANITY, description = "Verify if nodeId is not set the status code is 404")
public void canNotUpdateCommentIfNodeIdIsNotSet() throws JsonToModelConversionException, Exception public void canNotUpdateCommentIfNodeIdIsNotSet() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
commentsAPI.updateComment("unexistingId", commentModel.getId(), commentModel.getContent()); commentsAPI.updateComment(FolderModel.getRandomFolderModel(), commentModel, commentModel.getContent());
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.NOT_FOUND.toString()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.NOT_FOUND);
} }
@TestRail(section = { "rest-api", "comments" }, executionType = ExecutionType.SANITY, description = "Verify if commentId is not set the status code is 404") @TestRail(section = { "rest-api", "comments" }, executionType = ExecutionType.SANITY, description = "Verify if commentId is not set the status code is 404")
public void canNotUpdateCommentIfCommentIdIsNotSet() throws JsonToModelConversionException, Exception public void canNotUpdateCommentIfCommentIdIsNotSet() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
commentsAPI.updateComment(document.getNodeRef(), "unexistingId", commentModel.getContent()); commentsAPI.updateComment(document, new RestCommentModel(), commentModel.getContent());
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.NOT_FOUND.toString()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.NOT_FOUND);
} }
} }