diff --git a/e2e-test/java/org/alfresco/rest/GetSiteSanityTests.java b/e2e-test/java/org/alfresco/rest/GetSiteSanityTests.java new file mode 100644 index 000000000..32076dc28 --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/GetSiteSanityTests.java @@ -0,0 +1,110 @@ +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.data.DataSite; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.data.UserRole; +import org.alfresco.utility.exception.DataPreparationException; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author iulia.cojocea + */ + +@Test(groups = { "rest-api", "sites", "sanity" }) +public class GetSiteSanityTests extends RestTest +{ + + @Autowired + DataUser dataUser; + + @Autowired + RestSitesApi siteAPI; + + @Autowired + DataSite dataSite; + + private UserModel adminUserModel; + private HashMap usersWithRoles; + private UserModel userModel; + private SiteModel siteModel; + + @BeforeClass + public void initTest() 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)); + } + + @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()); + } + + @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()); + } + + @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()); + } + + @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()); + } + + @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, + description = "Verify user with admin role gets site information and gets status code OK (200)") + public void getSiteWithAdminRole() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUserModel); + siteAPI.getSite(siteModel.getId()); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + } + + @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, + description = "Failed authentication get site call returns status code 401 with Manager role") + public void getSiteWithManagerRoleFailedAuth() throws JsonToModelConversionException, Exception + { + 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()); + } +} diff --git a/e2e-test/java/org/alfresco/rest/GetSitesSanityTests.java b/e2e-test/java/org/alfresco/rest/GetSitesSanityTests.java new file mode 100644 index 000000000..610954b34 --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/GetSitesSanityTests.java @@ -0,0 +1,111 @@ +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.data.DataSite; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.data.UserRole; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author iulia.cojocea + */ +@Test(groups = { "rest-api", "sites", "sanity" }) +public class GetSitesSanityTests extends RestTest +{ + @Autowired + RestSitesApi siteAPI; + + @Autowired + DataUser dataUser; + + @Autowired + DataSite dataSite; + + private UserModel adminUserModel; + private UserModel userModel; + private HashMap usersWithRoles; + private SiteModel siteModel; + + @BeforeClass + public void initTest() 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)); + } + + @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)); + siteAPI.getAllSites(); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + } + + @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)); + siteAPI.getAllSites(); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + } + + @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)); + siteAPI.getAllSites(); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + } + + @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)); + siteAPI.getAllSites(); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + } + + @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, + description = "Verify user with Admin user gets sites information and gets status code OK (200)") + public void getSitesWithAdminUser() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUserModel); + siteAPI.getAllSites(); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + } + + @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)); + 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()); + } +} diff --git a/e2e-test/java/org/alfresco/rest/GetSitesTests.java b/e2e-test/java/org/alfresco/rest/GetSitesTests.java new file mode 100644 index 000000000..e1e38d290 --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/GetSitesTests.java @@ -0,0 +1,107 @@ +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.data.DataSite; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.data.UserRole; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author iulia.cojocea + */ +@Test(groups = { "rest-api", "comments", "sanity" }) +public class GetSitesTests extends RestTest +{ + @Autowired + RestSitesApi siteAPI; + + @Autowired + DataUser dataUser; + + @Autowired + DataSite dataSite; + + private UserModel adminUserModel; + private UserModel userModel; + private HashMap usersWithRoles; + private SiteModel siteModel; + + @BeforeClass + public void initTest() 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)); + + } + + @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)); + siteAPI.getAllSites(); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + } + + @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)); + siteAPI.getAllSites(); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + } + + @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)); + siteAPI.getAllSites(); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + } + + @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)); + siteAPI.getAllSites(); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + } + + @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Admin user gets sites information and gets status code OK (200)") + public void getSitesWithAdminUser() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUserModel); + siteAPI.getAllSites(); + siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + } + + @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)); + 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()); + } +} diff --git a/e2e-test/java/org/alfresco/rest/comments/GetCommentsSanityTest.java b/e2e-test/java/org/alfresco/rest/comments/GetCommentsSanityTest.java new file mode 100644 index 000000000..d2e81797d --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/comments/GetCommentsSanityTest.java @@ -0,0 +1,130 @@ +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.data.DataUser; +import org.alfresco.utility.data.UserRole; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +@Test(groups = { "rest-api", "comments", "sanity" }) +public class GetCommentsSanityTest extends RestTest +{ + @Autowired + RestCommentsApi commentsAPI; + + @Autowired + DataUser dataUser; + + private UserModel adminUserModel; + + private FileModel document; + private SiteModel siteModel; + private UserModel userModel; + private HashMap usersWithRoles; + + @BeforeClass + public void initTest() 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"); + + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, Arrays.asList(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()); + } + + @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()); + } + + @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()); + } + + @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()); + } + + @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()); + } + + @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, + description= "Verify Manager user gets status code 401 if authentication call fails") + public void managerIsNotAbleToRetrieveCommentIfAuthenticationFails() throws JsonToModelConversionException, Exception + { + UserModel nonexistentModel = new UserModel("nonexistentUser", "nonexistentPassword"); + restClient.authenticateUser(nonexistentModel); + commentsAPI.getNodeComments(document.getNodeRef()); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED.toString()); + } + + @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); + 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()); + } + + @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); + restClient.authenticateUser(userModel); + commentsAPI.addComment(document.getNodeRef(), "This is a new comment added by " + userModel.getUsername()); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED.toString()); + restClient.authenticateUser(adminUserModel); + commentsAPI.getNodeComments(document.getNodeRef()); + commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); + } +}