diff --git a/e2e-test/java/org/alfresco/rest/GetSiteSanityTests.java b/e2e-test/java/org/alfresco/rest/GetSiteSanityTests.java index e96d59e3f..b38609f39 100644 --- a/e2e-test/java/org/alfresco/rest/GetSiteSanityTests.java +++ b/e2e-test/java/org/alfresco/rest/GetSiteSanityTests.java @@ -1,13 +1,11 @@ package org.alfresco.rest; -import java.util.Arrays; -import java.util.HashMap; - import org.alfresco.rest.exception.JsonToModelConversionException; import org.alfresco.rest.requests.RestSitesApi; import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.data.DataSite; import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; import org.alfresco.utility.exception.DataPreparationException; import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.UserModel; @@ -25,7 +23,6 @@ import org.testng.annotations.Test; @Test(groups = { "rest-api", "sites", "sanity" }) public class GetSiteSanityTests extends RestTest { - @Autowired DataUser dataUser; @@ -36,55 +33,54 @@ public class GetSiteSanityTests extends RestTest DataSite dataSite; private UserModel adminUserModel; - private HashMap usersWithRoles; + private ListUserWithRoles usersWithRoles; private UserModel userModel; private SiteModel siteModel; - @BeforeClass - public void initTest() throws DataPreparationException + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws DataPreparationException { adminUserModel = dataUser.getAdminUser(); restClient.authenticateUser(adminUserModel); siteAPI.useRestClient(restClient); siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); - usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, - Arrays.asList(UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor)); + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel,UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); } @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Manager role gets site information and gets status code OK (200)") public void getSiteWithManagerRole() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); - siteAPI.getSite(siteModel.getId()); - siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + siteAPI.getSite(siteModel); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK); } @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Collaborator role gets site information and gets status code OK (200)") public void getSiteWithCollaboratorRole() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteCollaborator)); - siteAPI.getSite(siteModel.getId()); - siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + siteAPI.getSite(siteModel); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK); } @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Contributor role gets site information and gets status code OK (200)") public void getSiteWithContributorRole() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteContributor)); - siteAPI.getSite(siteModel.getId()); - siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + siteAPI.getSite(siteModel); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK); } @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Consumer role gets site information and gets status code OK (200)") public void getSiteWithConsumerRole() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteConsumer)); - siteAPI.getSite(siteModel.getId()); - siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + siteAPI.getSite(siteModel); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK); } @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, @@ -92,8 +88,8 @@ public class GetSiteSanityTests extends RestTest public void getSiteWithAdminRole() throws JsonToModelConversionException, Exception { restClient.authenticateUser(adminUserModel); - siteAPI.getSite(siteModel.getId()); - siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + siteAPI.getSite(siteModel); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK); } @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, @@ -105,6 +101,6 @@ public class GetSiteSanityTests extends RestTest dataUser.addUserToSite(userModel, siteModel, UserRole.SiteManager); restClient.authenticateUser(userModel); siteAPI.getAllSites(); - siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED.toString()); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED); } } diff --git a/e2e-test/java/org/alfresco/rest/GetSitesSanityTests.java b/e2e-test/java/org/alfresco/rest/GetSitesSanityTests.java index bf783d99b..a25066a81 100644 --- a/e2e-test/java/org/alfresco/rest/GetSitesSanityTests.java +++ b/e2e-test/java/org/alfresco/rest/GetSitesSanityTests.java @@ -1,13 +1,11 @@ package org.alfresco.rest; -import java.util.Arrays; -import java.util.HashMap; - import org.alfresco.rest.exception.JsonToModelConversionException; import org.alfresco.rest.requests.RestSitesApi; import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.data.DataSite; import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.UserModel; import org.alfresco.utility.testrail.ExecutionType; @@ -34,27 +32,26 @@ public class GetSitesSanityTests extends RestTest private UserModel adminUserModel; private UserModel userModel; - private HashMap usersWithRoles; + private ListUserWithRoles usersWithRoles; private SiteModel siteModel; - @BeforeClass - public void initTest() throws Exception + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception { adminUserModel = dataUser.getAdminUser(); restClient.authenticateUser(adminUserModel); siteAPI.useRestClient(restClient); siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); - usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, - Arrays.asList(UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor)); + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel,UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); } @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Manager role gets sites information and gets status code OK (200)") public void getSitesWithManagerRole() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); siteAPI.getAllSites(); - siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK); } @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, @@ -62,9 +59,9 @@ public class GetSitesSanityTests extends RestTest public void getSitesWithCollaboratorRole() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteCollaborator)); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); siteAPI.getAllSites(); - siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK); } @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, @@ -72,9 +69,9 @@ public class GetSitesSanityTests extends RestTest public void getSitesWithContributorRole() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteContributor)); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); siteAPI.getAllSites(); - siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK); } @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, @@ -82,9 +79,9 @@ public class GetSitesSanityTests extends RestTest public void getSitesWithConsumerRole() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteConsumer)); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); siteAPI.getAllSites(); - siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK); } @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, @@ -93,19 +90,19 @@ public class GetSitesSanityTests extends RestTest { restClient.authenticateUser(adminUserModel); siteAPI.getAllSites(); - siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK); } @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Failed authentication get sites call returns status code 401 with Manager role") public void getSitesWithManagerRoleFailedAuth() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); userModel = dataUser.createRandomTestUser(); userModel.setPassword("user wrong password"); dataUser.addUserToSite(userModel, siteModel, UserRole.SiteManager); restClient.authenticateUser(userModel); siteAPI.getAllSites(); - siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED.toString()); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED); } } diff --git a/e2e-test/java/org/alfresco/rest/GetSitesTests.java b/e2e-test/java/org/alfresco/rest/GetSitesTests.java index 7a594bbdb..5790a8dc8 100644 --- a/e2e-test/java/org/alfresco/rest/GetSitesTests.java +++ b/e2e-test/java/org/alfresco/rest/GetSitesTests.java @@ -1,13 +1,11 @@ package org.alfresco.rest; -import java.util.Arrays; -import java.util.HashMap; - import org.alfresco.rest.exception.JsonToModelConversionException; import org.alfresco.rest.requests.RestSitesApi; import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.data.DataSite; import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.UserModel; import org.alfresco.utility.testrail.ExecutionType; @@ -34,55 +32,53 @@ public class GetSitesTests extends RestTest private UserModel adminUserModel; private UserModel userModel; - private HashMap usersWithRoles; + private ListUserWithRoles usersWithRoles; private SiteModel siteModel; - @BeforeClass - public void initTest() throws Exception + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception { adminUserModel = dataUser.getAdminUser(); restClient.authenticateUser(adminUserModel); siteAPI.useRestClient(restClient); siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); - usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, - Arrays.asList(UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor)); - + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel,UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); } @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Manager role gets sites information and gets status code OK (200)") public void getSitesWithManagerRole() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); siteAPI.getAllSites(); - siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK); } @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Collaborator role gets sites information and gets status code OK (200)") public void getSitesWithCollaboratorRole() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteCollaborator)); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); siteAPI.getAllSites(); - siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK); } @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Contributor role gets sites information and gets status code OK (200)") public void getSitesWithContributorRole() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteContributor)); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); siteAPI.getAllSites(); - siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK); } @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Consumer role gets sites information and gets status code OK (200)") public void getSitesWithConsumerRole() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteConsumer)); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); siteAPI.getAllSites(); - siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK); } @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Admin user gets sites information and gets status code OK (200)") @@ -90,18 +86,18 @@ public class GetSitesTests extends RestTest { restClient.authenticateUser(adminUserModel); siteAPI.getAllSites(); - siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK); } @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Failed authentication get sites call returns status code 401 with Manager role") public void getSitesWithManagerRoleFailedAuth() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); userModel = dataUser.createRandomTestUser(); userModel.setPassword("user wrong password"); dataUser.addUserToSite(userModel, siteModel, UserRole.SiteManager); restClient.authenticateUser(userModel); siteAPI.getAllSites(); - siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED.toString()); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED); } } diff --git a/e2e-test/java/org/alfresco/rest/RestTest.java b/e2e-test/java/org/alfresco/rest/RestTest.java index b50cad0ea..69cc678cc 100644 --- a/e2e-test/java/org/alfresco/rest/RestTest.java +++ b/e2e-test/java/org/alfresco/rest/RestTest.java @@ -8,12 +8,16 @@ import org.alfresco.utility.data.DataSite; import org.alfresco.utility.data.DataUser; import org.alfresco.utility.network.ServerHealth; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; import org.testng.annotations.BeforeClass; import com.jayway.restassured.RestAssured; +@Component +@Scope(value = "prototype") @ContextConfiguration("classpath:alfresco-restapi-context.xml") public abstract class RestTest extends AbstractTestNGSpringContextTests { @@ -39,7 +43,7 @@ public abstract class RestTest extends AbstractTestNGSpringContextTests protected DataContent dataContent; @BeforeClass(alwaysRun = true) - public void setupRestTest() throws Exception + public void checkServerHealth() throws Exception { serverHealth.assertServerIsOnline(); diff --git a/e2e-test/java/org/alfresco/rest/comments/GetCommentsSanityTest.java b/e2e-test/java/org/alfresco/rest/comments/GetCommentsSanityTests.java similarity index 71% rename from e2e-test/java/org/alfresco/rest/comments/GetCommentsSanityTest.java rename to e2e-test/java/org/alfresco/rest/comments/GetCommentsSanityTests.java index c57e55d23..6b38898d0 100644 --- a/e2e-test/java/org/alfresco/rest/comments/GetCommentsSanityTest.java +++ b/e2e-test/java/org/alfresco/rest/comments/GetCommentsSanityTests.java @@ -1,14 +1,12 @@ package org.alfresco.rest.comments; -import java.util.Arrays; -import java.util.HashMap; - import org.alfresco.dataprep.CMISUtil.DocumentType; import org.alfresco.rest.RestTest; import org.alfresco.rest.exception.JsonToModelConversionException; 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.FileModel; import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.UserModel; @@ -20,7 +18,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @Test(groups = { "rest-api", "comments", "sanity" }) -public class GetCommentsSanityTest extends RestTest +public class GetCommentsSanityTests extends RestTest { @Autowired RestCommentsApi commentsAPI; @@ -33,63 +31,63 @@ public class GetCommentsSanityTest extends RestTest private FileModel document; private SiteModel siteModel; private UserModel userModel; - private HashMap usersWithRoles; + private ListUserWithRoles usersWithRoles; - @BeforeClass - public void initTest() throws Exception + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception { adminUserModel = dataUser.getAdminUser(); restClient.authenticateUser(adminUserModel); siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); commentsAPI.useRestClient(restClient); document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); - commentsAPI.addComment(document.getNodeRef(), "This is a new comment"); + commentsAPI.addComment(document, "This is a new comment"); - usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, Arrays.asList(UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor)); + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); } @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, description= "Verify Admin user gets comments with Rest API and status code is 200") public void adminIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception { - commentsAPI.getNodeComments(document.getNodeRef()); - commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + commentsAPI.getNodeComments(document); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK); } @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, description= "Verify Manager user gets comments created by admin user with Rest API and status code is 200") public void managerIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); - commentsAPI.getNodeComments(document.getNodeRef()); - commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + commentsAPI.getNodeComments(document); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK); } @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, description= "Verify Contributor user gets comments created by admin user with Rest API and status code is 200") public void contributorIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteContributor)); - commentsAPI.getNodeComments(document.getNodeRef()); - commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); + commentsAPI.getNodeComments(document); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK); } @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, description= "Verify Collaborator user gets comments created by admin user with Rest API and status code is 200") public void collaboratorIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteCollaborator)); - commentsAPI.getNodeComments(document.getNodeRef()); - commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); + commentsAPI.getNodeComments(document); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK); } @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, description= "Verify Consumer user gets comments created by admin user with Rest API and status code is 200") public void consumerIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteConsumer)); - commentsAPI.getNodeComments(document.getNodeRef()); - commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); + commentsAPI.getNodeComments(document); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK); } @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, @@ -98,33 +96,33 @@ public class GetCommentsSanityTest extends RestTest { UserModel nonexistentModel = new UserModel("nonexistentUser", "nonexistentPassword"); restClient.authenticateUser(nonexistentModel); - commentsAPI.getNodeComments(document.getNodeRef()); - commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED.toString()); + commentsAPI.getNodeComments(document); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED); } @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, description= "Verify Manager user gets comments created by another user and status code is 200") public void managerIsAbleToRetrieveCommentsCreatedByAnotherUser() throws JsonToModelConversionException, Exception { - userModel = usersWithRoles.get(UserRole.SiteCollaborator); + userModel = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator); restClient.authenticateUser(userModel); - commentsAPI.addComment(document.getNodeRef(), "This is a new comment added by " + userModel.getUsername()); - commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED.toString()); - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); - commentsAPI.getNodeComments(document.getNodeRef()); - commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + commentsAPI.addComment(document, "This is a new comment added by " + userModel.getUsername()); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + commentsAPI.getNodeComments(document); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK); } @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, description= "Verify admin user gets comments created by another user and status code is 200") public void adminIsAbleToRetrieveCommentsCreatedByAnotherUser() throws JsonToModelConversionException, Exception { - userModel = usersWithRoles.get(UserRole.SiteCollaborator); + userModel = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator); restClient.authenticateUser(userModel); - commentsAPI.addComment(document.getNodeRef(), "This is a new comment added by " + userModel.getUsername()); - commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED.toString()); + commentsAPI.addComment(document, "This is a new comment added by " + userModel.getUsername()); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED); restClient.authenticateUser(adminUserModel); - commentsAPI.getNodeComments(document.getNodeRef()); - commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + commentsAPI.getNodeComments(document); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK); } } diff --git a/e2e-test/java/org/alfresco/rest/demo/RestDemoTest.java b/e2e-test/java/org/alfresco/rest/demo/RestDemoTests.java similarity index 79% rename from e2e-test/java/org/alfresco/rest/demo/RestDemoTest.java rename to e2e-test/java/org/alfresco/rest/demo/RestDemoTests.java index 6a3fea0e6..c68d578fc 100644 --- a/e2e-test/java/org/alfresco/rest/demo/RestDemoTest.java +++ b/e2e-test/java/org/alfresco/rest/demo/RestDemoTests.java @@ -19,7 +19,8 @@ import org.springframework.social.alfresco.api.entities.Site.Visibility; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -public class RestDemoTest extends RestTest +@Test(groups = { "demo" }) +public class RestDemoTests extends RestTest { @Autowired RestSitesApi sitesApi; @@ -30,8 +31,8 @@ public class RestDemoTest extends RestTest private UserModel userModel; private SiteModel siteModel; - @BeforeClass - public void setUp() throws DataPreparationException + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws DataPreparationException { userModel = dataUser.getAdminUser(); siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); @@ -70,24 +71,24 @@ public class RestDemoTest extends RestTest */ @Test public void adminCanPostAndUpdateComments() throws Exception - { - FileModel fileModel = dataContent.usingResource(new FolderModel("Shared")) - .usingUser(userModel) + { + FileModel fileModel = dataContent.usingUser(userModel) + .usingResource(FolderModel.getSharedFolderModel()) .createContent(DocumentType.TEXT_PLAIN); // add new comment - RestCommentModel commentEntry = commentsAPI.addComment(fileModel.getNodeRef(), "This is a new comment"); - commentsAPI.getNodeComments(fileModel.getNodeRef()) + RestCommentModel commentEntry = commentsAPI.addComment(fileModel, "This is a new comment"); + commentsAPI.getNodeComments(fileModel) .assertThatResponseIsNotEmpty() - .assertThatCommentWithIdExists(commentEntry.getId()) + .assertThatCommentWithIdExists(commentEntry) .assertThatCommentWithContentExists("This is a new comment"); // update comment - commentEntry = commentsAPI.updateComment(fileModel.getNodeRef(), - commentEntry.getId(), + commentEntry = commentsAPI.updateComment(fileModel, + commentEntry, "This is the updated comment"); - commentsAPI.getNodeComments(fileModel.getNodeRef()) + commentsAPI.getNodeComments(fileModel) .assertThatResponseIsNotEmpty() - .assertThatCommentWithIdExists(commentEntry.getId()) + .assertThatCommentWithIdExists(commentEntry) .assertThatCommentWithContentExists("This is the updated comment"); } @@ -108,25 +109,22 @@ public class RestDemoTest extends RestTest newUser.getUsername()); // add user as Consumer to site - sitesApi.addPerson(siteModel.getId(), siteMember); - sitesApi.getSiteMembers(siteModel.getId()) + sitesApi.addPerson(siteModel, siteMember); + sitesApi.getSiteMembers(siteModel) .assertThatSiteHasMember(siteMember.getId()) .getSiteMember(siteMember.getId()) .assertSiteMemberHasRole(Role.SiteConsumer); // update site member to Manager siteMember.setRole(Role.SiteManager.toString()); - sitesApi.updateSiteMember(siteModel.getId(), - newUser.getUsername(), siteMember); - sitesApi.getSiteMembers(siteModel.getId()) + sitesApi.updateSiteMember(siteModel, newUser, siteMember); + sitesApi.getSiteMembers(siteModel) .assertThatSiteHasMember(siteMember.getId()) .getSiteMember(siteMember.getId()) .assertSiteMemberHasRole(Role.SiteManager); - // delete site member - sitesApi.deleteSiteMember(siteModel.getId(), - newUser.getUsername()); + sitesApi.deleteSiteMember(siteModel, newUser); sitesApi.usingRestWrapper() - .assertStatusCodeIs(HttpStatus.NO_CONTENT.toString()); + .assertStatusCodeIs(HttpStatus.NO_CONTENT); } } \ No newline at end of file diff --git a/e2e-test/java/org/alfresco/rest/demo/SampleCommentsTest.java b/e2e-test/java/org/alfresco/rest/demo/SampleCommentsTests.java similarity index 73% rename from e2e-test/java/org/alfresco/rest/demo/SampleCommentsTest.java rename to e2e-test/java/org/alfresco/rest/demo/SampleCommentsTests.java index 1551c0fb9..0398cadae 100644 --- a/e2e-test/java/org/alfresco/rest/demo/SampleCommentsTest.java +++ b/e2e-test/java/org/alfresco/rest/demo/SampleCommentsTests.java @@ -17,8 +17,8 @@ import org.springframework.http.HttpStatus; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -@Test(groups = { "rest-api", "comments", "sanity" }) -public class SampleCommentsTest extends RestTest +@Test(groups = { "demo" }) +public class SampleCommentsTests extends RestTest { @Autowired DataUser dataUser; @@ -31,8 +31,8 @@ public class SampleCommentsTest extends RestTest private SiteModel siteModel; private FileModel document; - @BeforeClass - public void initTest() throws Exception + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception { userModel = dataUser.getAdminUser(); siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); @@ -43,33 +43,33 @@ public class SampleCommentsTest extends RestTest document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); } - @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, + @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY, description= "Verify admin user adds comments with Rest API and status code is 200") public void admiShouldAddComment() throws JsonToModelConversionException, Exception { - commentsAPI.addComment(document.getNodeRef(), "This is a new comment"); + commentsAPI.addComment(document, "This is a new comment"); commentsAPI.usingRestWrapper() - .assertStatusCodeIs(HttpStatus.CREATED.toString()); + .assertStatusCodeIs(HttpStatus.CREATED); } - @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, + @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY, description= "Verify admin user gets comments with Rest API and status code is 200") public void admiShouldRetrieveComments() throws JsonToModelConversionException { - commentsAPI.getNodeComments(document.getNodeRef()); + commentsAPI.getNodeComments(document); commentsAPI.usingRestWrapper() - .assertStatusCodeIs(HttpStatus.OK.toString()); + .assertStatusCodeIs(HttpStatus.OK); } - @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, + @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY, description= "Verify admin user updates comments with Rest API") public void adminShouldUpdateComment() throws JsonToModelConversionException, Exception { // add initial comment - String commentId = commentsAPI.addComment(document.getNodeRef(), "This is a new comment").getId(); + RestCommentModel commentModel = commentsAPI.addComment(document, "This is a new comment"); // update comment - RestCommentModel commentEntry = commentsAPI.updateComment(document.getNodeRef(), commentId, "This is the updated comment"); + RestCommentModel commentEntry = commentsAPI.updateComment(document, commentModel, "This is the updated comment"); commentEntry.assertCommentContentIs("This is the updated comment"); } diff --git a/e2e-test/java/org/alfresco/rest/demo/SamplePeopleTest.java b/e2e-test/java/org/alfresco/rest/demo/SamplePeopleTests.java similarity index 69% rename from e2e-test/java/org/alfresco/rest/demo/SamplePeopleTest.java rename to e2e-test/java/org/alfresco/rest/demo/SamplePeopleTests.java index a5718b2dc..1eba0d771 100644 --- a/e2e-test/java/org/alfresco/rest/demo/SamplePeopleTest.java +++ b/e2e-test/java/org/alfresco/rest/demo/SamplePeopleTests.java @@ -13,8 +13,8 @@ import org.springframework.http.HttpStatus; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -@Test(groups = { "rest-api", "people", "sanity" }) -public class SamplePeopleTest extends RestTest +@Test(groups = { "demo" }) +public class SamplePeopleTests extends RestTest { @Autowired RestPeopleApi peopleAPI; @@ -25,8 +25,8 @@ public class SamplePeopleTest extends RestTest private UserModel userModel; private UserModel adminUser; - @BeforeClass - public void setUp() throws DataPreparationException + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws DataPreparationException { userModel = dataUser.createUser(RandomStringUtils.randomAlphanumeric(20)); adminUser = dataUser.getAdminUser(); @@ -34,23 +34,21 @@ public class SamplePeopleTest extends RestTest peopleAPI.useRestClient(restClient); } - @TestRail(section={"rest-api", "people"}, executionType= ExecutionType.SANITY, + @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY, description = "Verify admin user gets person with Rest API and response is not empty") public void adminShouldRetrievePerson() throws Exception { - peopleAPI.getPerson(userModel.getUsername()) - .assertResponseIsNotEmpty(); + peopleAPI.getPerson(userModel).assertResponseIsNotEmpty(); peopleAPI.usingRestWrapper() - .assertStatusCodeIs(HttpStatus.OK.toString()); + .assertStatusCodeIs(HttpStatus.OK); } - @TestRail(section={"rest-api", "people"}, executionType= ExecutionType.SANITY, + @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY, description = "Admin user gets own person information with Rest Api and assert that name is correct") public void adminShouldRetrieveItself() throws Exception { - peopleAPI.getPerson(adminUser.getUsername()) - .assertPersonHasName(adminUser.getUsername()); + peopleAPI.getPerson(adminUser).assertPersonHasName(adminUser); } } \ No newline at end of file diff --git a/e2e-test/java/org/alfresco/rest/demo/SampleSitesTest.java b/e2e-test/java/org/alfresco/rest/demo/SampleSitesTests.java similarity index 74% rename from e2e-test/java/org/alfresco/rest/demo/SampleSitesTest.java rename to e2e-test/java/org/alfresco/rest/demo/SampleSitesTests.java index 53bcfad31..b759bd775 100644 --- a/e2e-test/java/org/alfresco/rest/demo/SampleSitesTest.java +++ b/e2e-test/java/org/alfresco/rest/demo/SampleSitesTests.java @@ -17,8 +17,8 @@ import org.springframework.social.alfresco.api.entities.Role; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -@Test(groups = { "rest-api", "people", "sanity" }) -public class SampleSitesTest extends RestTest +@Test(groups = { "demo" }) +public class SampleSitesTests extends RestTest { @Autowired RestSitesApi siteAPI; @@ -32,8 +32,8 @@ public class SampleSitesTest extends RestTest private UserModel userModel; private SiteModel siteModel; - @BeforeClass - public void initTest() throws DataPreparationException + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws DataPreparationException { userModel = dataUser.getAdminUser(); restClient.authenticateUser(userModel); @@ -41,24 +41,24 @@ public class SampleSitesTest extends RestTest siteAPI.useRestClient(restClient); } - @TestRail(section={"rest-api", "sites"}, executionType= ExecutionType.SANITY, + @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY, description = "Verify admin user gets site details with Rest API and response is not empty") public void adminShouldGetSiteDetails() throws JsonToModelConversionException, Exception { - siteAPI.getSite(siteModel.getId()) + siteAPI.getSite(siteModel) .assertResponseIsNotEmpty(); } - @TestRail(section={"rest-api", "sites"}, executionType= ExecutionType.SANITY, + @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY, description = "Verify admin user gets site information and gets status code OK (200)") public void adminShouldGetSites() throws JsonToModelConversionException, Exception { - siteAPI.getSite(siteModel.getId()); + siteAPI.getSite(siteModel); siteAPI.usingRestWrapper() - .assertStatusCodeIs(HttpStatus.OK.toString()); + .assertStatusCodeIs(HttpStatus.OK); } - @TestRail(section={"rest-api", "sites"}, executionType= ExecutionType.SANITY, + @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY, description = "Verify admin user gets sites with Rest API and the response is not empty") public void adminShouldAccessSites() throws JsonToModelConversionException, Exception { @@ -66,16 +66,16 @@ public class SampleSitesTest extends RestTest .assertThatResponseIsNotEmpty(); } - @TestRail(section={"rest-api", "sites"}, executionType= ExecutionType.SANITY, + @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY, description = "Verify admin user gets sites with Rest API and status code is 200") public void adminShouldRetrieveSites() throws JsonToModelConversionException, Exception { siteAPI.getSites(); siteAPI.usingRestWrapper() - .assertStatusCodeIs(HttpStatus.OK.toString()); + .assertStatusCodeIs(HttpStatus.OK); } - @TestRail(section={"rest-api", "sites"}, executionType= ExecutionType.SANITY, + @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY, description = "Verify admin user gets sites with Rest API and status code is 200") public void adminShouldAccessResponsePagination() throws JsonToModelConversionException, Exception { @@ -83,31 +83,31 @@ public class SampleSitesTest extends RestTest .assertResponseHasPagination(); } - @TestRail(section={"rest-api", "sites"}, executionType= ExecutionType.SANITY, + @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY, description = "Verify admin user adds site member with Rest API and status code is 201") public void adminShouldAddNewSiteMember() throws JsonToModelConversionException, DataPreparationException, Exception { UserModel newMember = dataUser.createRandomTestUser(); SiteMember siteMember = new SiteMember(Role.SiteCollaborator.toString(), newMember.getUsername()); - siteAPI.addPerson(siteModel.getId(), siteMember); + siteAPI.addPerson(siteModel, siteMember); siteAPI.usingRestWrapper() - .assertStatusCodeIs(HttpStatus.CREATED.toString()); + .assertStatusCodeIs(HttpStatus.CREATED); } - @TestRail(section={"rest-api", "sites"}, executionType= ExecutionType.SANITY, + @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY, description = "Verify that site exists from get all sites request") public void adminShouldGetSiteFromSitesList() throws JsonToModelConversionException, Exception { siteAPI.getAllSites() - .assertThatResponseHasSite(siteModel.getId()); + .assertThatResponseHasSite(siteModel); } - @TestRail(section={"rest-api", "sites"}, executionType= ExecutionType.SANITY, + @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY, description = "Verify site details: response not empty, description, title, visibility") public void adminShouldAccessSiteDetails() throws JsonToModelConversionException, Exception { - siteAPI.getSite(siteModel.getId()) + siteAPI.getSite(siteModel) .assertResponseIsNotEmpty() .assertSiteHasDescription(siteModel.getDescription()) .assertSiteHasTitle(siteModel.getTitle()) diff --git a/e2e-test/java/org/alfresco/rest/sites/AddSiteMembershipRequestSanityTest.java b/e2e-test/java/org/alfresco/rest/sites/AddSiteMembershipRequestSanityTests.java similarity index 66% rename from e2e-test/java/org/alfresco/rest/sites/AddSiteMembershipRequestSanityTest.java rename to e2e-test/java/org/alfresco/rest/sites/AddSiteMembershipRequestSanityTests.java index f47f6de31..28722398e 100644 --- a/e2e-test/java/org/alfresco/rest/sites/AddSiteMembershipRequestSanityTest.java +++ b/e2e-test/java/org/alfresco/rest/sites/AddSiteMembershipRequestSanityTests.java @@ -1,8 +1,5 @@ package org.alfresco.rest.sites; -import java.util.Arrays; -import java.util.HashMap; - import org.alfresco.rest.RestTest; import org.alfresco.rest.body.SiteMembership; import org.alfresco.rest.exception.JsonToModelConversionException; @@ -10,9 +7,11 @@ import org.alfresco.rest.requests.RestSitesApi; import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.data.DataSite; import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; import org.alfresco.utility.exception.DataPreparationException; import org.alfresco.utility.model.SiteModel; 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.beans.factory.annotation.Autowired; @@ -20,7 +19,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @Test(groups = { "rest-api", "sites", "sanity" }) -public class AddSiteMembershipRequestSanityTest extends RestTest +public class AddSiteMembershipRequestSanityTests extends RestTest { @Autowired RestSitesApi siteAPI; @@ -33,32 +32,31 @@ public class AddSiteMembershipRequestSanityTest extends RestTest private SiteModel siteModel; - private HashMap usersWithRoles; + private ListUserWithRoles usersWithRoles; private UserModel adminUser; - @BeforeClass + @BeforeClass(alwaysRun=true) public void initTest() throws DataPreparationException { adminUser = dataUser.getAdminUser(); siteModel = dataSite.usingUser(adminUser).createPublicRandomSite(); - usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, - Arrays.asList(UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor)); + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel,UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); siteAPI.useRestClient(restClient); } - @TestRail(section = { "rest-api", - "sites" }, executionType = ExecutionType.SANITY, description = "Verify site manager is able to create new site membership request") - @Test(enabled = false, description = "Fails due to MNT-16557") + @TestRail(section = { "rest-api","sites" }, executionType = ExecutionType.SANITY, description = "Verify site manager is able to create new site membership request") + @Bug(id="MNT-16557") + @Test(enabled=false) public void siteManagerCanCreateSiteMembershipRequest() throws JsonToModelConversionException, Exception { UserModel newMember = dataUser.createRandomTestUser(); SiteMembership siteMembership = new SiteMembership("Please accept me", siteModel.getId(), "New request"); - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); - siteAPI.addSiteMembershipRequest(newMember.getUsername(), siteMembership); - siteAPI.getSite(siteModel.getId()).assertResponseIsNotEmpty(); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); + siteAPI.addSiteMembershipRequest(newMember, siteMembership); + siteAPI.getSite(siteModel).assertResponseIsNotEmpty(); } } \ No newline at end of file diff --git a/e2e-test/java/org/alfresco/rest/sites/GetSiteMembershipInformationSanityTest.java b/e2e-test/java/org/alfresco/rest/sites/GetSiteMembershipInformationSanityTests.java similarity index 75% rename from e2e-test/java/org/alfresco/rest/sites/GetSiteMembershipInformationSanityTest.java rename to e2e-test/java/org/alfresco/rest/sites/GetSiteMembershipInformationSanityTests.java index e395d0177..7e9254d97 100644 --- a/e2e-test/java/org/alfresco/rest/sites/GetSiteMembershipInformationSanityTest.java +++ b/e2e-test/java/org/alfresco/rest/sites/GetSiteMembershipInformationSanityTests.java @@ -1,15 +1,12 @@ package org.alfresco.rest.sites; -import java.util.Arrays; -import java.util.HashMap; - import org.alfresco.rest.RestTest; import org.alfresco.rest.exception.JsonToModelConversionException; import org.alfresco.rest.requests.RestSitesApi; import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.data.DataSite; import org.alfresco.utility.data.DataUser; -import org.alfresco.utility.data.TestData; +import org.alfresco.utility.data.DataUser.ListUserWithRoles; import org.alfresco.utility.exception.DataPreparationException; import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.UserModel; @@ -21,7 +18,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @Test(groups = { "rest-api", "sites", "sanity" }) -public class GetSiteMembershipInformationSanityTest extends RestTest +public class GetSiteMembershipInformationSanityTests extends RestTest { @Autowired RestSitesApi siteAPI; @@ -34,15 +31,14 @@ public class GetSiteMembershipInformationSanityTest extends RestTest private SiteModel siteModel; private UserModel adminUser; - private HashMap usersWithRoles; + private ListUserWithRoles usersWithRoles; - @BeforeClass - public void initTest() throws DataPreparationException + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws DataPreparationException { adminUser = dataUser.getAdminUser(); siteModel = dataSite.usingUser(adminUser).createPublicRandomSite(); - usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, - Arrays.asList(UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor)); + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); siteAPI.useRestClient(restClient); } @@ -52,10 +48,10 @@ public class GetSiteMembershipInformationSanityTest extends RestTest description = "Verify site manager is able to retrieve site membership information of another user") public void siteManagerCanRetrieveSiteMembershipInformation() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); siteAPI.getSiteMembershipInformation(adminUser.getUsername()); siteAPI.usingRestWrapper() - .assertStatusCodeIs(HttpStatus.OK.toString()); + .assertStatusCodeIs(HttpStatus.OK); } @TestRail(section = { "rest-api", "sites" }, @@ -63,10 +59,10 @@ public class GetSiteMembershipInformationSanityTest extends RestTest description = "Verify site collaborator is able to retrieve site membership information of another user") public void siteCollaboratorCanRetrieveSiteMembershipInformation() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteCollaborator)); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); siteAPI.getSiteMembershipInformation(adminUser.getUsername()); siteAPI.usingRestWrapper() - .assertStatusCodeIs(HttpStatus.OK.toString()); + .assertStatusCodeIs(HttpStatus.OK); } @TestRail(section = { "rest-api", "sites" }, @@ -74,10 +70,10 @@ public class GetSiteMembershipInformationSanityTest extends RestTest description = "Verify site contributor is able to retrieve site membership information of another user") public void siteContributorCanRetrieveSiteMembershipInformation() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteContributor)); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); siteAPI.getSiteMembershipInformation(adminUser.getUsername()); siteAPI.usingRestWrapper() - .assertStatusCodeIs(HttpStatus.OK.toString()); + .assertStatusCodeIs(HttpStatus.OK); } @TestRail(section = { "rest-api", "sites" }, @@ -85,10 +81,10 @@ public class GetSiteMembershipInformationSanityTest extends RestTest description = "Verify site consumer is able to retrieve site membership information of another user") public void siteConsumerCanRetrieveSiteMembershipInformation() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(usersWithRoles.get(UserRole.SiteConsumer)); + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); siteAPI.getSiteMembershipInformation(adminUser.getUsername()); siteAPI.usingRestWrapper() - .assertStatusCodeIs(HttpStatus.OK.toString()); + .assertStatusCodeIs(HttpStatus.OK); } @TestRail(section = { "rest-api", "sites" }, @@ -97,9 +93,9 @@ public class GetSiteMembershipInformationSanityTest extends RestTest public void siteAdminCanRetrieveSiteMembershipInformation() throws JsonToModelConversionException, Exception { restClient.authenticateUser(adminUser); - siteAPI.getSiteMembershipInformation(usersWithRoles.get(UserRole.SiteManager).getUsername()); + siteAPI.getSiteMembershipInformation(usersWithRoles.getOneUserWithRole(UserRole.SiteManager).getUsername()); siteAPI.usingRestWrapper() - .assertStatusCodeIs(HttpStatus.OK.toString()); + .assertStatusCodeIs(HttpStatus.OK); } @TestRail(section = { "rest-api", "sites" }, @@ -109,9 +105,9 @@ public class GetSiteMembershipInformationSanityTest extends RestTest { UserModel inexistentUser = new UserModel("inexistent user", "wrong password"); restClient.authenticateUser(inexistentUser); - siteAPI.getSiteMembershipInformation(usersWithRoles.get(UserRole.SiteManager).getUsername()); + siteAPI.getSiteMembershipInformation(usersWithRoles.getOneUserWithRole(UserRole.SiteManager).getUsername()); siteAPI.usingRestWrapper() - .assertStatusCodeIs(HttpStatus.UNAUTHORIZED.toString()); + .assertStatusCodeIs(HttpStatus.UNAUTHORIZED); } } \ No newline at end of file diff --git a/e2e-test/resources/sanity-rest.xml b/e2e-test/resources/sanity-rest.xml index 385353b4f..36b07a328 100644 --- a/e2e-test/resources/sanity-rest.xml +++ b/e2e-test/resources/sanity-rest.xml @@ -1,17 +1,22 @@ - + - - - - - - + + + + + + + + + + +