From 3ee3529ebed7a920193961979265936fa8a3dd88 Mon Sep 17 00:00:00 2001 From: Valentin Popa Date: Mon, 23 Jan 2017 17:56:13 +0200 Subject: [PATCH 1/2] Add site member - full tests --- .../rest/sites/AddSiteMemberFullTests.java | 254 ++++++++++++++++++ 1 file changed, 254 insertions(+) create mode 100644 e2e-test/java/org/alfresco/rest/sites/AddSiteMemberFullTests.java diff --git a/e2e-test/java/org/alfresco/rest/sites/AddSiteMemberFullTests.java b/e2e-test/java/org/alfresco/rest/sites/AddSiteMemberFullTests.java new file mode 100644 index 000000000..4c4c2ad93 --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/sites/AddSiteMemberFullTests.java @@ -0,0 +1,254 @@ +package org.alfresco.rest.sites; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestSiteMemberModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class AddSiteMemberFullTests extends RestTest +{ + private UserModel adminUserModel; + private SiteModel publicSiteModel; + private SiteModel moderatedSiteModel; + private SiteModel privateSiteModel; + private String addMembersJson; + private RestSiteMemberModel memberModel; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + publicSiteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + moderatedSiteModel = dataSite.usingUser(adminUserModel).createModeratedRandomSite(); + privateSiteModel = dataSite.usingUser(adminUserModel).createPrivateRandomSite(); + addMembersJson = "{\"role\":\"%s\",\"id\":\"%s\"}"; + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.FULL }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, description = "Check default error schema when request fails") + public void checkDefaultErrorSchema() throws Exception + { + UserModel testUser = new UserModel("inexistentUser", "password"); + testUser.setUserRole(UserRole.SiteManager); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(publicSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, testUser.getUsername())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.FULL }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Add new site member request by providing an empty body") + public void addSiteMemberUsingEmptyBody() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, "", "sites/{siteId}/members?{parameters}", + publicSiteModel.getId(), restClient.getParameters()); + restClient.processModel(RestSiteMemberModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.NO_CONTENT, "No content to map to Object due to end of input")) + .containsErrorKey(String.format(RestErrorModel.NO_CONTENT, "No content to map to Object due to end of input")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.FULL }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Check lower and upper case letters for role field") + public void checkLowerUpperCaseLettersForRole() throws Exception + { + UserModel user = dataUser.createRandomTestUser(); + + String json = String.format(addMembersJson, "SITEMANAGER", user.getUsername()); + restClient.authenticateUser(adminUserModel).withCoreAPI(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, json, "sites/{siteId}/members?{parameters}", publicSiteModel.getId(), restClient.getParameters()); + restClient.processModel(RestSiteMemberModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.UNKNOWN_ROLE, "SITEMANAGER")) + .containsErrorKey(String.format(RestErrorModel.UNKNOWN_ROLE, "SITEMANAGER")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + + json = String.format(addMembersJson, "sitemanager", user.getUsername()); + restClient.authenticateUser(adminUserModel).withCoreAPI(); + request = RestRequest.requestWithBody(HttpMethod.POST, json, "sites/{siteId}/members?{parameters}", publicSiteModel.getId(), restClient.getParameters()); + restClient.processModel(RestSiteMemberModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.UNKNOWN_ROLE, "sitemanager")) + .containsErrorKey(String.format(RestErrorModel.UNKNOWN_ROLE, "sitemanager")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.FULL }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Check empty value for user role") + public void checkEmptyValueForRole() throws Exception + { + UserModel user = dataUser.createRandomTestUser(); + + String json = String.format(addMembersJson, "", user.getUsername()); + restClient.authenticateUser(adminUserModel).withCoreAPI(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, json, "sites/{siteId}/members?{parameters}", publicSiteModel.getId(), restClient.getParameters()); + restClient.processModel(RestSiteMemberModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary(String.format(RestErrorModel.NO_CONTENT, + "N/A (through reference chain: org.alfresco.rest.api.model.SiteMember[\"role\"])")); + + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.FULL }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that collaborator role can be added to public site") + public void addCollaboratorToPublicSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteCollaborator); + memberModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(publicSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + memberModel.assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.FULL }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that contributor role can be added to public site") + public void addContributorToPublicSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteContributor); + memberModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(publicSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + memberModel.assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.FULL }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that consumer role can be added to public site") + public void addConsumerToPublicSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteConsumer); + memberModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(publicSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + memberModel.assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.FULL }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that collaborator role can be added to moderated site") + public void addCollaboratorToModeratedSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteCollaborator); + memberModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(moderatedSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + memberModel.assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.FULL }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that contributor role can be added to moderated site") + public void addContributorToModeratedSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteContributor); + memberModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(moderatedSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + memberModel.assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.FULL }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that consumer role can be added to moderated site") + public void addConsumerToModeratedSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteConsumer); + memberModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(moderatedSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + memberModel.assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.FULL }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that collaborator role can be added to private site") + public void addCollaboratorToPrivateSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteCollaborator); + memberModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(privateSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + memberModel.assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.FULL }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that contributor role can be added to private site") + public void addContributorToPrivateSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteContributor); + memberModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(privateSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + memberModel.assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.FULL }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that consumer role can be added to private site") + public void addConsumerToPrivateSite() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser("testUser"); + testUser.setUserRole(UserRole.SiteConsumer); + memberModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(privateSiteModel).addPerson(testUser); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + memberModel.assertThat().field("id").is(testUser.getUsername()) + .and().field("role").is(testUser.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.FULL }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that admin can be added to private site by site manager") + public void adminCanBeAddedToPrivateSiteBySiteManager() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser(); + SiteModel privateSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + memberModel = restClient.authenticateUser(testUser).withCoreAPI().usingSite(privateSite).addPerson(adminUserModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + memberModel.assertThat().field("id").is(adminUserModel.getUsername()) + .and().field("role").is(adminUserModel.getUserRole()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.FULL }) + @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that admin can be added to private site by site manager") + public void adminCanBeAddedToPrivateSiteBySiteCollaborator() throws Exception + { + UserModel testUser = dataUser.createRandomTestUser(); + SiteModel privateSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + UserModel siteCollaborator = dataUser.createRandomTestUser(); + dataUser.addUserToSite(siteCollaborator, privateSite, UserRole.SiteCollaborator); + memberModel = restClient.authenticateUser(siteCollaborator).withCoreAPI().usingSite(privateSite).addPerson(adminUserModel); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } +} \ No newline at end of file From 61e579efe42eca33e7fca7e1703c5b4c6ddc825a Mon Sep 17 00:00:00 2001 From: Valentin Popa Date: Wed, 25 Jan 2017 11:41:43 +0200 Subject: [PATCH 2/2] Fix some failing tests --- .../rest/sites/AddSiteMemberFullTests.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/e2e-test/java/org/alfresco/rest/sites/AddSiteMemberFullTests.java b/e2e-test/java/org/alfresco/rest/sites/AddSiteMemberFullTests.java index 4c4c2ad93..ed5f3e0b5 100644 --- a/e2e-test/java/org/alfresco/rest/sites/AddSiteMemberFullTests.java +++ b/e2e-test/java/org/alfresco/rest/sites/AddSiteMemberFullTests.java @@ -104,9 +104,10 @@ public class AddSiteMemberFullTests extends RestTest RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, json, "sites/{siteId}/members?{parameters}", publicSiteModel.getId(), restClient.getParameters()); restClient.processModel(RestSiteMemberModel.class, request); restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() - .containsSummary(String.format(RestErrorModel.NO_CONTENT, - "N/A (through reference chain: org.alfresco.rest.api.model.SiteMember[\"role\"])")); - + .containsErrorKey(String.format(RestErrorModel.NO_CONTENT, "N/A (through reference chain: org.alfresco.rest.api.model.SiteMember[\"role\"])")) + .containsSummary(String.format(RestErrorModel.NO_CONTENT, "N/A (through reference chain: org.alfresco.rest.api.model.SiteMember[\"role\"])")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); } @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.FULL }) @@ -233,21 +234,22 @@ public class AddSiteMemberFullTests extends RestTest { UserModel testUser = dataUser.createRandomTestUser(); SiteModel privateSite = dataSite.usingUser(testUser).createPrivateRandomSite(); + adminUserModel.setUserRole(UserRole.SiteContributor); memberModel = restClient.authenticateUser(testUser).withCoreAPI().usingSite(privateSite).addPerson(adminUserModel); restClient.assertStatusCodeIs(HttpStatus.CREATED); - memberModel.assertThat().field("id").is(adminUserModel.getUsername()) - .and().field("role").is(adminUserModel.getUserRole()); + memberModel.assertThat().field("id").is(adminUserModel.getUsername()).and().field("role").is(adminUserModel.getUserRole()); } @Test(groups = { TestGroup.REST_API, TestGroup.SITES, TestGroup.FULL }) @TestRail(section = {TestGroup.REST_API, TestGroup.SITES }, executionType = ExecutionType.REGRESSION, - description = "Verify that admin can be added to private site by site manager") - public void adminCanBeAddedToPrivateSiteBySiteCollaborator() throws Exception + description = "Verify that admin cannot be added to private site by site collaborator") + public void adminCannotBeAddedToPrivateSiteBySiteCollaborator() throws Exception { UserModel testUser = dataUser.createRandomTestUser(); SiteModel privateSite = dataSite.usingUser(testUser).createPrivateRandomSite(); UserModel siteCollaborator = dataUser.createRandomTestUser(); dataUser.addUserToSite(siteCollaborator, privateSite, UserRole.SiteCollaborator); + adminUserModel.setUserRole(UserRole.SiteContributor); memberModel = restClient.authenticateUser(siteCollaborator).withCoreAPI().usingSite(privateSite).addPerson(adminUserModel); restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); }