From 4334ee217197eed3890622bbbb1ea1f5daa1c6ab Mon Sep 17 00:00:00 2001 From: Andrei Rusu Date: Thu, 5 Jan 2017 11:40:44 +0200 Subject: [PATCH 1/8] added tests for postComments updated unauthenticatedUserIsNotAbleToAddComments test from AddCommentsSanityTests --- .../rest/comments/AddCommentsCoreTests.java | 156 ++++++++++++++++++ .../rest/comments/AddCommentsSanityTests.java | 3 +- 2 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 e2e-test/java/org/alfresco/rest/comments/AddCommentsCoreTests.java diff --git a/e2e-test/java/org/alfresco/rest/comments/AddCommentsCoreTests.java b/e2e-test/java/org/alfresco/rest/comments/AddCommentsCoreTests.java new file mode 100644 index 000000000..f86866213 --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/comments/AddCommentsCoreTests.java @@ -0,0 +1,156 @@ +package org.alfresco.rest.comments; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestCommentModel; +import org.alfresco.rest.model.RestCommentModelsCollection; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FileModel; +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.apache.commons.lang.RandomStringUtils; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Created by Andrei Rusu + */ +public class AddCommentsCoreTests extends RestTest +{ + private UserModel adminUserModel; + private FileModel document; + private SiteModel siteModel; + private DataUser.ListUserWithRoles usersWithRoles; + private String comment = "This is a new comment"; + private String comment2 = "This is the second comment"; + private RestCommentModelsCollection comments; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + restClient.authenticateUser(adminUserModel); + siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.CORE, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Using Manager user verify that you can provide a large string for one comment") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void addLongCommentWithManagerAndCheckThatCommentIsReturned() throws Exception + { + document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + String longString = RandomStringUtils.randomAlphanumeric(10000); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(document).addComment(longString); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", longString); + comments.assertThat().paginationField("totalItems").is("1"); + comments.assertThat().paginationField("count").is("1"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.CORE, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Using Contributor user verify that you can provide a short string for one comment") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void addShortCommentWithContributorAndCheckThatCommentIsReturned() throws Exception + { + document = dataContent.usingSite(siteModel).usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).createContent(DocumentType.TEXT_PLAIN); + String shortString = RandomStringUtils.randomAlphanumeric(2); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + .withCoreAPI().usingResource(document).addComment(shortString); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", shortString); + comments.assertThat().paginationField("totalItems").is("1"); + comments.assertThat().paginationField("count").is("1"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.CORE, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Using Collaborator user verify that you can provide a string with special characters for one comment") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void addCommentWithSpecialCharsWithCollaboratorCheckCommentIsReturned() throws Exception + { + document = dataContent.usingSite(siteModel).usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).createContent(DocumentType.TEXT_PLAIN); + String specialCharsString = "!@#$%^&*()_+♂µΓyádo«√<╡┌6£"; + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(document).addComment(specialCharsString); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", specialCharsString); + comments.assertThat().paginationField("totalItems").is("1"); + comments.assertThat().paginationField("count").is("1"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.CORE, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Using Manager user verify that you can not provide an empty string for one comment") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void addEmptyStringCommentWithManagerCheckCommentIsReturned() throws Exception + { + document = dataContent.usingSite(siteModel).usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).createContent(DocumentType.TEXT_PLAIN); + String emptyString = ""; + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) + .withCoreAPI().usingResource(document).addComment(emptyString); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(RestErrorModel.NON_NULL_COMMENT); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.CORE, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Using Collaborator user verify that you can provide several comments in one request") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void addSeveralCommentsWithCollaboratorCheckCommentsAreReturned() throws Exception + { + document = dataContent.usingSite(siteModel).usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).createContent(DocumentType.TEXT_PLAIN); + String charString = RandomStringUtils.randomAlphanumeric(10); + String charString1 = RandomStringUtils.randomAlphanumeric(10); + String charString2 = RandomStringUtils.randomAlphanumeric(10); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) + .withCoreAPI().usingResource(document).addComments(comment, comment2, charString, charString1, charString2); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).getNodeComments(); + restClient.assertStatusCodeIs(HttpStatus.OK); + comments.assertThat().entriesListContains("content", comment); + comments.assertThat().paginationField("totalItems").is("5"); + comments.assertThat().paginationField("count").is("5"); + } + + @TestRail(section={TestGroup.REST_API, TestGroup.CORE, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Provide invalid request body parameter and check default error model schema") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + public void invalidRequestBodyParamenerCheckErrorModelSchema() throws Exception + { + document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUserModel).withCoreAPI(); + String postBody = JsonBodyGenerator.keyValueJson("content2", comment); + RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, postBody, "nodes/{nodeId}/comments", document.getNodeRef()); + restClient.processModel(RestCommentModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + restClient.assertLastError().getErrorKey().contains("Unrecognized field \"content2\""); + restClient.assertLastError().containsSummary("Unrecognized field \"content2\""); + restClient.assertLastError().getDescriptionURL().contains("https://api-explorer.alfresco.com"); + restClient.assertLastError().getStackTrace().contains("For security reasons the stack trace is no longer displayed, but the property is kept for previous versions"); + } +} diff --git a/e2e-test/java/org/alfresco/rest/comments/AddCommentsSanityTests.java b/e2e-test/java/org/alfresco/rest/comments/AddCommentsSanityTests.java index da6615e43..cc6838009 100644 --- a/e2e-test/java/org/alfresco/rest/comments/AddCommentsSanityTests.java +++ b/e2e-test/java/org/alfresco/rest/comments/AddCommentsSanityTests.java @@ -115,10 +115,9 @@ public class AddCommentsSanityTests extends RestTest @TestRail(section = { TestGroup.REST_API, TestGroup.COMMENTS }, executionType = ExecutionType.SANITY, description = "Verify unauthenticated user gets status code 401 on post multiple comments call") @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.SANITY }) - @Bug(id="MNT-16904") public void unauthenticatedUserIsNotAbleToAddComments() throws JsonToModelConversionException, Exception { - restClient.authenticateUser(new UserModel("random user", "random password")) + restClient.noAuthentication() .withCoreAPI().usingResource(document).addComments(comment1, comment2); restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError().containsSummary(RestErrorModel.AUTHENTICATION_FAILED); } From 199604f81ed5dae2fac66fc8de228fdafaa7dc27 Mon Sep 17 00:00:00 2001 From: mionescu Date: Mon, 9 Jan 2017 15:50:17 +0200 Subject: [PATCH 2/8] test - updated tests from class: DeleteFavoriteSanityTests --- ...ts.java => DeleteFavoriteSanityTests.java} | 129 +++++++----------- 1 file changed, 53 insertions(+), 76 deletions(-) rename e2e-test/java/org/alfresco/rest/favorites/{DeleteFavoritesSanityTests.java => DeleteFavoriteSanityTests.java} (67%) diff --git a/e2e-test/java/org/alfresco/rest/favorites/DeleteFavoritesSanityTests.java b/e2e-test/java/org/alfresco/rest/favorites/DeleteFavoriteSanityTests.java similarity index 67% rename from e2e-test/java/org/alfresco/rest/favorites/DeleteFavoritesSanityTests.java rename to e2e-test/java/org/alfresco/rest/favorites/DeleteFavoriteSanityTests.java index 2503d7c7a..dc6e83ae2 100644 --- a/e2e-test/java/org/alfresco/rest/favorites/DeleteFavoritesSanityTests.java +++ b/e2e-test/java/org/alfresco/rest/favorites/DeleteFavoriteSanityTests.java @@ -15,7 +15,7 @@ import org.springframework.http.HttpStatus; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -public class DeleteFavoritesSanityTests extends RestTest +public class DeleteFavoriteSanityTests extends RestTest { private UserModel adminUserModel; private SiteModel siteModel; @@ -28,7 +28,7 @@ public class DeleteFavoritesSanityTests extends RestTest siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); siteModel.setGuid(restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(siteModel).getSite().getGuid()); - + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); } @@ -36,54 +36,58 @@ public class DeleteFavoritesSanityTests extends RestTest @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, description = "Verify Admin user deletes site from favorites with Rest API and status code is 204") @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) - public void adminIsAbleToDeleteFavorites() throws JsonToModelConversionException, Exception + public void adminIsAbleToDeleteFavorite() throws JsonToModelConversionException, Exception { restClient.withCoreAPI().usingUser(adminUserModel).addSiteToFavorites(siteModel); restClient.withCoreAPI().usingAuthUser().deleteSiteFromFavorites(siteModel).assertStatusCodeIs(HttpStatus.NO_CONTENT); restClient.withCoreAPI().usingAuthUser().getFavorites().assertThat().entriesListDoesNotContain("targetGuid", siteModel.getGuid()); + } + + @Bug(id="MNT-16557") + @TestRail(section = { TestGroup.REST_API,TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, + description = "Verify user doesn't have permission to delete favorites of admin user with Rest API and status code is 404") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) + public void userIsNotAbleToDeleteFavoriteOfAdminUser() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) + .withCoreAPI().usingAuthUser().deleteSiteFromFavorites(siteModel) + .assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError() + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); } + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, + description = "Verify manager user gets status code 401 if authentication call fails") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) + public void managerIsNotAbleToDeleteFavoriteIfAuthenticationFails() throws JsonToModelConversionException, Exception + { + UserModel siteManager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); + siteManager.setPassword("wrongPassword"); + restClient.authenticateUser(siteManager).withCoreAPI().usingAuthUser() + .deleteSiteFromFavorites(siteModel).assertStatusCodeIs(HttpStatus.UNAUTHORIZED) + .assertLastError() + .containsSummary(RestErrorModel.AUTHENTICATION_FAILED); + } + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, description = "Verify Manager user deletes site from favorites with Rest API and status code is 204") @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) - public void managerIsAbleToDeleteFavorites() throws JsonToModelConversionException, Exception + public void managerIsAbleToDeleteFavorite() throws JsonToModelConversionException, Exception { UserModel siteManager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); restClient.authenticateUser(siteManager).withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); restClient.withCoreAPI().usingAuthUser().deleteSiteFromFavorites(siteModel).assertStatusCodeIs(HttpStatus.NO_CONTENT); restClient.withCoreAPI().usingAuthUser().getFavorites().assertThat().entriesListDoesNotContain("targetGuid", siteModel.getGuid()); - } - - @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, - description = "Verify Collaborator user deletes site from favorites with Rest API and status code is 204") - @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) - public void collaboratorIsAbleToDeleteFavorites() throws JsonToModelConversionException, Exception - { - UserModel siteCollaborator = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator); - restClient.authenticateUser(siteCollaborator).withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); - - restClient.withCoreAPI().usingAuthUser().deleteSiteFromFavorites(siteModel).assertStatusCodeIs(HttpStatus.NO_CONTENT); - restClient.withCoreAPI().usingAuthUser().getFavorites().assertThat().entriesListDoesNotContain("targetGuid", siteModel.getGuid()); - } - - @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, - description = "Verify Contributor user deletes site from favorites with Rest API and status code is 204") - @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) - public void contributorIsAbleToDeleteFavorites() throws JsonToModelConversionException, Exception - { - UserModel siteContributor = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor); - restClient.authenticateUser(siteContributor).withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); - - restClient.withCoreAPI().usingAuthUser().deleteSiteFromFavorites(siteModel).assertStatusCodeIs(HttpStatus.NO_CONTENT); - restClient.withCoreAPI().usingAuthUser().getFavorites().assertThat().entriesListDoesNotContain("targetGuid", siteModel.getGuid()); - } - + } + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, description = "Verify Consumer user delets site from favorites with Rest API and status code is 204") @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) - public void consumerIsAbleToDeleteFavorites() throws JsonToModelConversionException, Exception + public void consumerIsAbleToDeleteFavorite() throws JsonToModelConversionException, Exception { UserModel siteConsumer = usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer); restClient.authenticateUser(siteConsumer).withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); @@ -91,56 +95,29 @@ public class DeleteFavoritesSanityTests extends RestTest restClient.withCoreAPI().usingAuthUser().deleteSiteFromFavorites(siteModel).assertStatusCodeIs(HttpStatus.NO_CONTENT); restClient.withCoreAPI().usingAuthUser().getFavorites().assertThat().entriesListDoesNotContain("targetGuid", siteModel.getGuid()); } - - @Bug(id="MNT-16557") + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, - description = "Verify user doesn't have permission to delete favorites of another user with Rest API and status code is 404") + description = "Verify Contributor user deletes site from favorites with Rest API and status code is 204") @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) - public void userIsNotAbleToDeleteFavoritesOfAnotherUser() throws JsonToModelConversionException, Exception + public void contributorIsAbleToDeleteFavorite() throws JsonToModelConversionException, Exception + { + UserModel siteContributor = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor); + restClient.authenticateUser(siteContributor).withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); + + restClient.withCoreAPI().usingAuthUser().deleteSiteFromFavorites(siteModel).assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingAuthUser().getFavorites().assertThat().entriesListDoesNotContain("targetGuid", siteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, + description = "Verify Collaborator user deletes site from favorites with Rest API and status code is 204") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) + public void collaboratorIsAbleToDeleteFavorite() throws JsonToModelConversionException, Exception { UserModel siteCollaborator = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator); restClient.authenticateUser(siteCollaborator).withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI() - .usingAuthUser().deleteSiteFromFavorites(siteModel) - .assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); - } - - @Bug(id="MNT-16557") - @TestRail(section = { TestGroup.REST_API,TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, - description = "Verify user doesn't have permission to delete favorites of admin user with Rest API and status code is 404") - @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) - public void userIsNotAbleToDeleteFavoritesOfAdminUser() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)) - .withCoreAPI().usingAuthUser().deleteSiteFromFavorites(siteModel) - .assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); - } - - @Bug(id="MNT-16557") - @TestRail(section = { TestGroup.REST_API,TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, - description = "Verify admin user doesn't have permission to delete favorites of another user with Rest API and status code is 404") - @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) - public void adminIsNotAbleToDeleteFavoritesOfAnotherUser() throws JsonToModelConversionException, Exception - { - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) - .withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel); - - restClient.authenticateUser(adminUserModel) - .withCoreAPI().usingAuthUser().deleteSiteFromFavorites(siteModel) - .assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); - } - - @Bug(id = "MNT-16904") - @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.SANITY, - description = "Verify user gets status code 401 if authentication call fails") - @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.SANITY }) - public void userIsNotAbleToDeleteFavoritesIfAuthenticationFails() throws JsonToModelConversionException, Exception - { - UserModel siteManager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); - siteManager.setPassword("wrongPassword"); - restClient.authenticateUser(siteManager).withCoreAPI().usingAuthUser() - .deleteSiteFromFavorites(siteModel).assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + restClient.withCoreAPI().usingAuthUser().deleteSiteFromFavorites(siteModel).assertStatusCodeIs(HttpStatus.NO_CONTENT); + restClient.withCoreAPI().usingAuthUser().getFavorites().assertThat().entriesListDoesNotContain("targetGuid", siteModel.getGuid()); } + } From 0444372514987ae8805c9c9db7a4be5f4633f7d2 Mon Sep 17 00:00:00 2001 From: Andrei Rusu Date: Mon, 9 Jan 2017 18:22:18 +0200 Subject: [PATCH 3/8] made changes to AddCommentsFullTests --- ...reTests.java => AddCommentsFullTests.java} | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) rename e2e-test/java/org/alfresco/rest/comments/{AddCommentsCoreTests.java => AddCommentsFullTests.java} (83%) diff --git a/e2e-test/java/org/alfresco/rest/comments/AddCommentsCoreTests.java b/e2e-test/java/org/alfresco/rest/comments/AddCommentsFullTests.java similarity index 83% rename from e2e-test/java/org/alfresco/rest/comments/AddCommentsCoreTests.java rename to e2e-test/java/org/alfresco/rest/comments/AddCommentsFullTests.java index f86866213..c85085850 100644 --- a/e2e-test/java/org/alfresco/rest/comments/AddCommentsCoreTests.java +++ b/e2e-test/java/org/alfresco/rest/comments/AddCommentsFullTests.java @@ -24,7 +24,7 @@ import org.testng.annotations.Test; /** * Created by Andrei Rusu */ -public class AddCommentsCoreTests extends RestTest +public class AddCommentsFullTests extends RestTest { private UserModel adminUserModel; private FileModel document; @@ -39,14 +39,13 @@ public class AddCommentsCoreTests extends RestTest { adminUserModel = dataUser.getAdminUser(); restClient.authenticateUser(adminUserModel); - siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); - + siteModel = dataSite.usingUser(adminUserModel).createPrivateRandomSite(); usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); } - @TestRail(section={TestGroup.REST_API, TestGroup.CORE, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + @TestRail(section={TestGroup.REST_API, TestGroup.FULL, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, description= "Using Manager user verify that you can provide a large string for one comment") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) public void addLongCommentWithManagerAndCheckThatCommentIsReturned() throws Exception { document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); @@ -63,15 +62,15 @@ public class AddCommentsCoreTests extends RestTest comments.assertThat().paginationField("count").is("1"); } - @TestRail(section={TestGroup.REST_API, TestGroup.CORE, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, - description= "Using Contributor user verify that you can provide a short string for one comment") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) - public void addShortCommentWithContributorAndCheckThatCommentIsReturned() throws Exception + @TestRail(section={TestGroup.REST_API, TestGroup.FULL, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + description= "Using Manager user verify that you can provide a short string for one comment") + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void addShortCommentWithManagerAndCheckThatCommentIsReturned() throws Exception { - document = dataContent.usingSite(siteModel).usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).createContent(DocumentType.TEXT_PLAIN); + document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); String shortString = RandomStringUtils.randomAlphanumeric(2); - restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)) + restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) .withCoreAPI().usingResource(document).addComment(shortString); restClient.assertStatusCodeIs(HttpStatus.CREATED); @@ -82,12 +81,12 @@ public class AddCommentsCoreTests extends RestTest comments.assertThat().paginationField("count").is("1"); } - @TestRail(section={TestGroup.REST_API, TestGroup.CORE, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + @TestRail(section={TestGroup.REST_API, TestGroup.FULL, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, description= "Using Collaborator user verify that you can provide a string with special characters for one comment") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) public void addCommentWithSpecialCharsWithCollaboratorCheckCommentIsReturned() throws Exception { - document = dataContent.usingSite(siteModel).usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).createContent(DocumentType.TEXT_PLAIN); + document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); String specialCharsString = "!@#$%^&*()_+♂µΓyádo«√<╡┌6£"; restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) @@ -101,12 +100,12 @@ public class AddCommentsCoreTests extends RestTest comments.assertThat().paginationField("count").is("1"); } - @TestRail(section={TestGroup.REST_API, TestGroup.CORE, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + @TestRail(section={TestGroup.REST_API, TestGroup.FULL, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, description= "Using Manager user verify that you can not provide an empty string for one comment") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) public void addEmptyStringCommentWithManagerCheckCommentIsReturned() throws Exception { - document = dataContent.usingSite(siteModel).usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).createContent(DocumentType.TEXT_PLAIN); + document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); String emptyString = ""; restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) @@ -114,12 +113,12 @@ public class AddCommentsCoreTests extends RestTest restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(RestErrorModel.NON_NULL_COMMENT); } - @TestRail(section={TestGroup.REST_API, TestGroup.CORE, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + @TestRail(section={TestGroup.REST_API, TestGroup.FULL, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, description= "Using Collaborator user verify that you can provide several comments in one request") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) public void addSeveralCommentsWithCollaboratorCheckCommentsAreReturned() throws Exception { - document = dataContent.usingSite(siteModel).usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).createContent(DocumentType.TEXT_PLAIN); + document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); String charString = RandomStringUtils.randomAlphanumeric(10); String charString1 = RandomStringUtils.randomAlphanumeric(10); String charString2 = RandomStringUtils.randomAlphanumeric(10); @@ -135,10 +134,10 @@ public class AddCommentsCoreTests extends RestTest comments.assertThat().paginationField("count").is("5"); } - @TestRail(section={TestGroup.REST_API, TestGroup.CORE, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, + @TestRail(section={TestGroup.REST_API, TestGroup.FULL, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, description= "Provide invalid request body parameter and check default error model schema") - @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.CORE }) - public void invalidRequestBodyParamenerCheckErrorModelSchema() throws Exception + @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) + public void invalidRequestBodyParameterCheckErrorModelSchema() throws Exception { document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); From b16db5c37ed7c1aa6f1d2149a6403269c80cb04f Mon Sep 17 00:00:00 2001 From: Andrei Rusu Date: Tue, 10 Jan 2017 11:44:50 +0200 Subject: [PATCH 4/8] updated accordingly to addComments --- .../rest/comments/AddCommentsFullTests.java | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/e2e-test/java/org/alfresco/rest/comments/AddCommentsFullTests.java b/e2e-test/java/org/alfresco/rest/comments/AddCommentsFullTests.java index c85085850..23a46bacd 100644 --- a/e2e-test/java/org/alfresco/rest/comments/AddCommentsFullTests.java +++ b/e2e-test/java/org/alfresco/rest/comments/AddCommentsFullTests.java @@ -46,70 +46,77 @@ public class AddCommentsFullTests extends RestTest @TestRail(section={TestGroup.REST_API, TestGroup.FULL, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, description= "Using Manager user verify that you can provide a large string for one comment") @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void addLongCommentWithManagerAndCheckThatCommentIsReturned() throws Exception + public void addLongCommentsWithManagerAndCheckThatCommentIsReturned() throws Exception { document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); String longString = RandomStringUtils.randomAlphanumeric(10000); + String longString1 = RandomStringUtils.randomAlphanumeric(90000); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) - .withCoreAPI().usingResource(document).addComment(longString); + .withCoreAPI().usingResource(document).addComments(longString, longString1); restClient.assertStatusCodeIs(HttpStatus.CREATED); comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).getNodeComments(); restClient.assertStatusCodeIs(HttpStatus.OK); comments.assertThat().entriesListContains("content", longString); - comments.assertThat().paginationField("totalItems").is("1"); - comments.assertThat().paginationField("count").is("1"); + comments.assertThat().entriesListContains("content", longString1); + comments.assertThat().paginationField("totalItems").is("2"); + comments.assertThat().paginationField("count").is("2"); } @TestRail(section={TestGroup.REST_API, TestGroup.FULL, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, description= "Using Manager user verify that you can provide a short string for one comment") @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void addShortCommentWithManagerAndCheckThatCommentIsReturned() throws Exception + public void addShortCommentsWithManagerAndCheckThatCommentIsReturned() throws Exception { document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); String shortString = RandomStringUtils.randomAlphanumeric(2); + String shortString1 = RandomStringUtils.randomAlphanumeric(1); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) - .withCoreAPI().usingResource(document).addComment(shortString); + .withCoreAPI().usingResource(document).addComments(shortString, shortString1); restClient.assertStatusCodeIs(HttpStatus.CREATED); comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).getNodeComments(); restClient.assertStatusCodeIs(HttpStatus.OK); comments.assertThat().entriesListContains("content", shortString); - comments.assertThat().paginationField("totalItems").is("1"); - comments.assertThat().paginationField("count").is("1"); + comments.assertThat().entriesListContains("content", shortString1); + comments.assertThat().paginationField("totalItems").is("2"); + comments.assertThat().paginationField("count").is("2"); } @TestRail(section={TestGroup.REST_API, TestGroup.FULL, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, description= "Using Collaborator user verify that you can provide a string with special characters for one comment") @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void addCommentWithSpecialCharsWithCollaboratorCheckCommentIsReturned() throws Exception + public void addCommentsWithSpecialCharsWithCollaboratorCheckCommentIsReturned() throws Exception { document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); String specialCharsString = "!@#$%^&*()_+♂µΓyádo«√<╡┌6£"; + String shortString = RandomStringUtils.randomAlphanumeric(2); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) - .withCoreAPI().usingResource(document).addComment(specialCharsString); + .withCoreAPI().usingResource(document).addComments(specialCharsString, shortString); restClient.assertStatusCodeIs(HttpStatus.CREATED); comments = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).getNodeComments(); restClient.assertStatusCodeIs(HttpStatus.OK); - comments.assertThat().entriesListContains("content", specialCharsString); - comments.assertThat().paginationField("totalItems").is("1"); - comments.assertThat().paginationField("count").is("1"); + comments.assertThat().entriesListContains("content", specialCharsString); + comments.assertThat().entriesListContains("content", shortString); + comments.assertThat().paginationField("totalItems").is("2"); + comments.assertThat().paginationField("count").is("2"); } @TestRail(section={TestGroup.REST_API, TestGroup.FULL, TestGroup.COMMENTS}, executionType= ExecutionType.REGRESSION, description= "Using Manager user verify that you can not provide an empty string for one comment") @Test(groups = { TestGroup.REST_API, TestGroup.COMMENTS, TestGroup.FULL }) - public void addEmptyStringCommentWithManagerCheckCommentIsReturned() throws Exception + public void addEmptyStringCommentsWithManagerCheckCommentIsReturned() throws Exception { document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); String emptyString = ""; + String spaceString = " "; restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) - .withCoreAPI().usingResource(document).addComment(emptyString); + .withCoreAPI().usingResource(document).addComments(emptyString, spaceString); restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(RestErrorModel.NON_NULL_COMMENT); } From 955ad87826ee8174d0d5ec39ed56693b3806c4b2 Mon Sep 17 00:00:00 2001 From: Paul Brodner Date: Tue, 10 Jan 2017 17:39:43 +0200 Subject: [PATCH 5/8] update log4j to include threads --- e2e-test/resources/log4j.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e-test/resources/log4j.properties b/e2e-test/resources/log4j.properties index ede92a004..00e9b5a11 100644 --- a/e2e-test/resources/log4j.properties +++ b/e2e-test/resources/log4j.properties @@ -6,13 +6,13 @@ log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=./target/reports/alfresco-tas.log log4j.appender.file.MaxBackupIndex=10 log4j.appender.file.layout=org.apache.log4j.PatternLayout -log4j.appender.file.layout.ConversionPattern=%d{HH:mm:ss} %-5p %c{1}:%L - %m%n +log4j.appender.file.layout.ConversionPattern=[%t] %d{HH:mm:ss} %-5p %c{1}:%L - %m%n # Direct log messages to stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss} %-5p %c{1}:%L - %m%n +log4j.appender.stdout.layout.ConversionPattern=[%t] %d{HH:mm:ss} %-5p %c{1}:%L - %m%n # TestRail particular log file # Direct log messages to a log file From 70894b1ce7ecbe1d69f1db90701290986f569a1e Mon Sep 17 00:00:00 2001 From: Cristina Axinte Date: Tue, 10 Jan 2017 17:42:23 +0200 Subject: [PATCH 6/8] added core tests for GetPeopleActivities --- .../people/GetPeopleActivitiesCoreTests.java | 127 ++++++++++++++++++ .../people/GetPeopleActivitiesFullTests.java | 6 +- .../GetPeopleActivitiesSanityTests.java | 5 + 3 files changed, 135 insertions(+), 3 deletions(-) create mode 100644 e2e-test/java/org/alfresco/rest/people/GetPeopleActivitiesCoreTests.java diff --git a/e2e-test/java/org/alfresco/rest/people/GetPeopleActivitiesCoreTests.java b/e2e-test/java/org/alfresco/rest/people/GetPeopleActivitiesCoreTests.java new file mode 100644 index 000000000..1ecc70160 --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/people/GetPeopleActivitiesCoreTests.java @@ -0,0 +1,127 @@ +package org.alfresco.rest.people; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestActivityModelsCollection; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.utility.constants.ActivityType; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FolderModel; +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.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * + * @author Cristina Axinte + * + */ +public class GetPeopleActivitiesCoreTests extends RestTest +{ + UserModel userModel, adminUser, managerUser; + SiteModel siteModel1, siteModel2; + FileModel fileInSite1, fileInSite2; + FolderModel folderInSite2; + private RestActivityModelsCollection restActivityModelsCollection; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + siteModel1 = dataSite.usingUser(userModel).createPublicRandomSite(); + fileInSite1 = dataContent.usingUser(userModel).usingSite(siteModel1).createContent(DocumentType.TEXT_PLAIN); + + siteModel2 = dataSite.usingUser(userModel).createPublicRandomSite(); + folderInSite2 = dataContent.usingUser(userModel).usingSite(siteModel2).createFolder(); + fileInSite2 = dataContent.usingAdmin().usingSite(siteModel2).createContent(DocumentType.TEXT_PLAIN); + + managerUser = dataUser.createRandomTestUser(); + dataUser.usingUser(userModel).addUserToSite(managerUser, siteModel2, UserRole.SiteManager); + + // only once the activity list is checked with retry in order not to wait the entire list in each test + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingMe().getPersonActivitiesWithRetry(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restActivityModelsCollection.assertThat().paginationField("count").is("4"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.CORE }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user cannot get activities for inexistent user with Rest API and response is 404") + public void userCannotGetPeopleActivitiesForInexistentPersonId() throws Exception + { + UserModel inexistentUserName = new UserModel("inexistent", "password"); + + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingUser(inexistentUserName).getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, inexistentUserName.getUsername())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.CORE }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets its activities for inexistent siteId with Rest API and response is 404") + public void userGetItsPeopleActivitiesForInexistentSite() throws Exception + { + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingUser(userModel).usingParams(String.format("siteId=inexistent")).getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "inexistent")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.CORE }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets activities with invald skipCount parameter with Rest API and response is 400") + public void userGetPeopleActivitiesUsingSkipCountParameter() throws Exception + { + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingMe().usingParams("skipCount=-1").getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsErrorKey(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT) + .containsSummary(RestErrorModel.NEGATIVE_VALUES_SKIPCOUNT) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.CORE }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets activities with invalid maxItems parameter with Rest API and response is 400") + public void userGetPeopleActivitiesUsingMaxItemsParameter() throws Exception + { + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingMe().usingParams("maxItems=0").getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsErrorKey(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.CORE }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets activities using invalid value for parameter 'who'with Rest API and response is 400") + public void userGetsPeopleActivitiesUsingMeForWhoParameter() throws Exception + { + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingUser(userModel).usingParams("who=mee").getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsErrorKey(RestErrorModel.INVALID_PARAMETER_WHO) + .containsSummary(RestErrorModel.INVALID_PARAMETER_WHO) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.CORE }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets activities successfully using parameter 'who' with 'others' value with Rest API") + public void userGetsPeopleActivitiesUsingOthersForWhoParameter() throws Exception + { + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingUser(userModel).usingParams("who=others").getPersonActivities(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restActivityModelsCollection.assertThat().paginationField("count").is("2"); + restActivityModelsCollection.assertThat().entriesListDoesNotContain("postPersonId", userModel.getUsername().toLowerCase()) + .and().entriesListContains("postPersonId", adminUser.getUsername().toLowerCase()) + .and().entriesListContains("postPersonId", managerUser.getUsername().toLowerCase()); + } +} diff --git a/e2e-test/java/org/alfresco/rest/people/GetPeopleActivitiesFullTests.java b/e2e-test/java/org/alfresco/rest/people/GetPeopleActivitiesFullTests.java index df5246458..f6536c095 100644 --- a/e2e-test/java/org/alfresco/rest/people/GetPeopleActivitiesFullTests.java +++ b/e2e-test/java/org/alfresco/rest/people/GetPeopleActivitiesFullTests.java @@ -97,13 +97,13 @@ public class GetPeopleActivitiesFullTests extends RestTest @Bug(id = "ACE-5460") @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.FULL }) - @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user cannot get activities for empty user with Rest API and response is 404") + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user cannot get activities for empty user with Rest API and response is 400") public void userCannotGetPeopleActivitiesForEmptyPersonId() throws Exception { UserModel emptyUserName = new UserModel("", "password"); restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingUser(emptyUserName).getPersonActivities(); - restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) .assertLastError().containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) .containsSummary(RestErrorModel.LOCAL_NAME_CONSISTANCE) .stackTraceIs(RestErrorModel.STACKTRACE) @@ -111,7 +111,7 @@ public class GetPeopleActivitiesFullTests extends RestTest } @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.FULL }) - @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets activities successfully using parameter 'who' with 'me'vale with Rest API") + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets activities successfully using parameter 'who' with 'me' value with Rest API") public void userGetsPeopleActivitiesUsingMeForWhoParameter() throws Exception { restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingUser(userModel).usingParams("who=me").getPersonActivities(); diff --git a/e2e-test/java/org/alfresco/rest/people/GetPeopleActivitiesSanityTests.java b/e2e-test/java/org/alfresco/rest/people/GetPeopleActivitiesSanityTests.java index 0e3f3cd59..96fb63082 100644 --- a/e2e-test/java/org/alfresco/rest/people/GetPeopleActivitiesSanityTests.java +++ b/e2e-test/java/org/alfresco/rest/people/GetPeopleActivitiesSanityTests.java @@ -37,6 +37,11 @@ public class GetPeopleActivitiesSanityTests extends RestTest UserRole.SiteContributor); unauthenticatedUser = dataUser.usingAdmin().createRandomTestUser(); unauthenticatedUser.setPassword("newpassword"); + + // only once the activity list is checked with retry in order not to wait the entire list in each test + restActivityModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser().getPersonActivitiesWithRetry(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restActivityModelsCollection.assertThat().entriesListIsNotEmpty(); } @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.ACTIVITIES, TestGroup.SANITY }) From ed0944575adf7d7203ebc3270ff6416fa6aee1cb Mon Sep 17 00:00:00 2001 From: Cristina Axinte Date: Wed, 11 Jan 2017 11:11:24 +0200 Subject: [PATCH 7/8] added full tests for GetPeoplePreferences for tasks from TAS-2629 to TAS-2640 --- .../people/GetPeopleActivitiesCoreTests.java | 1 - .../people/GetPeoplePreferencesFullTests.java | 130 ++++++++++++++++++ 2 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 e2e-test/java/org/alfresco/rest/people/GetPeoplePreferencesFullTests.java diff --git a/e2e-test/java/org/alfresco/rest/people/GetPeopleActivitiesCoreTests.java b/e2e-test/java/org/alfresco/rest/people/GetPeopleActivitiesCoreTests.java index 1ecc70160..a7549c9c0 100644 --- a/e2e-test/java/org/alfresco/rest/people/GetPeopleActivitiesCoreTests.java +++ b/e2e-test/java/org/alfresco/rest/people/GetPeopleActivitiesCoreTests.java @@ -4,7 +4,6 @@ import org.alfresco.dataprep.CMISUtil.DocumentType; import org.alfresco.rest.RestTest; import org.alfresco.rest.model.RestActivityModelsCollection; import org.alfresco.rest.model.RestErrorModel; -import org.alfresco.utility.constants.ActivityType; import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FolderModel; diff --git a/e2e-test/java/org/alfresco/rest/people/GetPeoplePreferencesFullTests.java b/e2e-test/java/org/alfresco/rest/people/GetPeoplePreferencesFullTests.java new file mode 100644 index 000000000..8eda8ca1f --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/people/GetPeoplePreferencesFullTests.java @@ -0,0 +1,130 @@ +package org.alfresco.rest.people; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestPreferenceModelsCollection; +import org.alfresco.utility.constants.PreferenceName; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +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.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * + * @author Cristina Axinte + * + */ +public class GetPeoplePreferencesFullTests extends RestTest +{ + UserModel userModel, user1, user2, adminUser; + SiteModel siteModel; + FolderModel folderModel; + private RestPreferenceModelsCollection restPreferenceModelsCollection; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder(); + + user1 = dataUser.createRandomTestUser(); + dataSite.usingUser(user1).usingSite(siteModel).addSiteToFavorites(); + dataContent.usingUser(user1).usingSite(siteModel).addFolderToFavorites(folderModel); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets its preferences using me with Rest API and response is successful") + public void userGetsItsPeoplePreferencesUsingMe() throws Exception + { + restPreferenceModelsCollection = restClient.authenticateUser(user1).withCoreAPI().usingMe().getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModelsCollection.assertThat().paginationField("count").is("4"); + restPreferenceModelsCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("id", String.format(PreferenceName.EXT_FOLDERS_FAVORITES_PREFIX.toString(), "workspace://SpacesStore/" + folderModel.getNodeRef())) + .and().entriesListContains("id", String.format(PreferenceName.EXT_SITES_FAVORITES_PREFIX.toString(), siteModel.getId())) + .and().entriesListContains("id", PreferenceName.FOLDERS_FAVORITES_PREFIX.toString()) + .and().entriesListContains("value", "workspace://SpacesStore/" + folderModel.getNodeRef()) + .and().entriesListContains("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())) + .and().entriesListContains("value", "true"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets its preferences with skipCount parameter applied with Rest API and response is successful") + public void userGetsItsPeoplePreferencesUsingSkipCountParameter() throws Exception + { + restPreferenceModelsCollection = restClient.authenticateUser(user1).withCoreAPI().usingMe().usingParams("skipCount=2").getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModelsCollection.assertThat().paginationField("count").is("2"); + restPreferenceModelsCollection.assertThat().paginationField("skipCount").is("2"); + restPreferenceModelsCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListDoesNotContain("id", String.format(PreferenceName.EXT_FOLDERS_FAVORITES_PREFIX.toString(), "workspace://SpacesStore/" + folderModel.getNodeRef())) + .and().entriesListDoesNotContain("id", String.format(PreferenceName.EXT_SITES_FAVORITES_PREFIX.toString(), siteModel.getId())) + .and().entriesListContains("id", PreferenceName.FOLDERS_FAVORITES_PREFIX.toString()) + .and().entriesListContains("value", "workspace://SpacesStore/" + folderModel.getNodeRef()) + .and().entriesListContains("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())) + .and().entriesListContains("value", "true"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets its preferences with maxItems parameter applied with Rest API and response is successful") + public void userGetsItsPeoplePreferencesUsingMaxItemsParameter() throws Exception + { + restPreferenceModelsCollection = restClient.authenticateUser(user1).withCoreAPI().usingMe().usingParams("maxItems=1").getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModelsCollection.assertThat().paginationField("count").is("1"); + restPreferenceModelsCollection.assertThat().paginationField("maxItems").is("1"); + restPreferenceModelsCollection.assertThat().entriesListIsNotEmpty() + .and().entriesListContains("id", String.format(PreferenceName.EXT_FOLDERS_FAVORITES_PREFIX.toString(), "workspace://SpacesStore/" + folderModel.getNodeRef())) + .and().entriesListDoesNotContain("id", String.format(PreferenceName.EXT_SITES_FAVORITES_PREFIX.toString(), siteModel.getId())) + .and().entriesListDoesNotContain("id", PreferenceName.FOLDERS_FAVORITES_PREFIX.toString()) + .and().entriesListDoesNotContain("value", "workspace://SpacesStore/" + folderModel.getNodeRef()) + .and().entriesListDoesNotContain("id", String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())) + .and().entriesListDoesNotContain("value", "true"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets admin preferences with Rest API and response is permission denied") + public void userIsForbiddenToGetAdminPreferences() throws Exception + { + restPreferenceModelsCollection = restClient.authenticateUser(user1).withCoreAPI().usingUser(adminUser).getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + restClient.assertLastError().containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, description = "Verify user gets its preferences with skipCount parameter higher then no of entries with Rest API and response is empty") + public void userGetsItsPeoplePreferencesUsingHighSkipCount() throws Exception + { + restPreferenceModelsCollection = restClient.authenticateUser(user1).withCoreAPI().usingMe().usingParams("skipCount=100").getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModelsCollection.assertThat().paginationField("count").is("0"); + restPreferenceModelsCollection.assertThat().paginationField("skipCount").is("100"); + restPreferenceModelsCollection.assertThat().entriesListIsEmpty(); + } + + @Bug(id = "ACE-5460") + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, description = "Verify user cannot get preferences for empty user with Rest API and response is 400") + public void userGetsItsPeoplePreferencesForEmptyPersonId() throws Exception + { + UserModel emptyUserName = new UserModel("", "password"); + + restPreferenceModelsCollection = restClient.authenticateUser(user1).withCoreAPI().usingUser(emptyUserName).getPersonPreferences(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(RestErrorModel.LOCAL_NAME_CONSISTANCE) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } +} From df05293a5a1a6f3f75bdabb0b49479cbaf985387 Mon Sep 17 00:00:00 2001 From: Valentin Popa Date: Wed, 11 Jan 2017 11:41:30 +0200 Subject: [PATCH 8/8] Added tests for getPreference REST API call --- .../people/GetPeoplePreferenceFullTests.java | 222 ++++++++++++++++++ 1 file changed, 222 insertions(+) create mode 100644 e2e-test/java/org/alfresco/rest/people/GetPeoplePreferenceFullTests.java diff --git a/e2e-test/java/org/alfresco/rest/people/GetPeoplePreferenceFullTests.java b/e2e-test/java/org/alfresco/rest/people/GetPeoplePreferenceFullTests.java new file mode 100644 index 000000000..4cc9a45cb --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/people/GetPeoplePreferenceFullTests.java @@ -0,0 +1,222 @@ +package org.alfresco.rest.people; + +import java.nio.file.Paths; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestPreferenceModel; +import org.alfresco.utility.Utility; +import org.alfresco.utility.constants.PreferenceName; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +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.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class GetPeoplePreferenceFullTests extends RestTest +{ + private UserModel userModel; + private SiteModel siteModel; + private RestPreferenceModel restPreferenceModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); + dataSite.usingUser(userModel).usingSite(siteModel).addSiteToFavorites(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, + description = "Check default error schema in case of failure") + public void checkDefaultErrorSchema() throws Exception + { + restClient.authenticateUser(userModel).withCoreAPI().usingUser(new UserModel("invalidPersonID", "password")) + .getPersonPreferenceInformation(PreferenceName.SITES_FAVORITES_PREFIX + siteModel.getId()); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidPersonID")) + .statusCodeIs(HttpStatus.NOT_FOUND) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE) + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, + description = "Specify -me- string in place of for request") + public void preferenceIsReturnedWhenUsingMeAsPersonId() throws Exception + { + restPreferenceModel = restClient.authenticateUser(userModel).withCoreAPI().usingMe() + .getPersonPreferenceInformation(PreferenceName.SITES_FAVORITES_PREFIX + siteModel.getId()); + + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModel.assertThat().field("id").is(PreferenceName.SITES_FAVORITES_PREFIX + siteModel.getId()) + .and().field("value").is("true"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, + description = "Check that properties parameter is applied") + public void propertiesParameterIsAppliedWhenRetrievingPreference() throws Exception + { + restPreferenceModel = restClient.authenticateUser(userModel).withParams("properties=id").withCoreAPI().usingUser(userModel) + .getPersonPreferenceInformation(PreferenceName.SITES_FAVORITES_PREFIX + siteModel.getId()); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModel.assertThat().field("id").is(PreferenceName.SITES_FAVORITES_PREFIX + siteModel.getId()) + .and().field("value").isNull(); + + restPreferenceModel = restClient.authenticateUser(userModel).withParams("properties=id,value").withCoreAPI().usingUser(userModel) + .getPersonPreferenceInformation(PreferenceName.SITES_FAVORITES_PREFIX + siteModel.getId()); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModel.assertThat().field("id").is(PreferenceName.SITES_FAVORITES_PREFIX + siteModel.getId()) + .and().field("value").is("true"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, + description = "Validate ID element in get site preference response") + public void validateIdElementInGetSitePreferenceResponse() throws Exception + { + restPreferenceModel = restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(PreferenceName.SITES_FAVORITES_PREFIX + siteModel.getId()); + restPreferenceModel.assertThat().field("id").is(PreferenceName.SITES_FAVORITES_PREFIX + siteModel.getId()) + .and().field("value").is("true"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, + description = "Validate ID element in get folder preference response") + public void validateIdElementInGetFolderPreferenceResponse() throws Exception + { + FolderModel folderFavorite = new FolderModel("favoriteFolder"); + folderFavorite = dataContent.usingSite(siteModel).createFolder(folderFavorite); + dataContent.getContentActions().setFolderAsFavorite(userModel.getUsername(), userModel.getPassword(), siteModel.getId(), folderFavorite.getName()); + + restPreferenceModel = restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(PreferenceName.FOLDERS_FAVORITES_PREFIX.toString()); + restPreferenceModel.assertThat().field("id").is(PreferenceName.FOLDERS_FAVORITES_PREFIX) + .and().field("value").is(Utility.removeLastSlash(Utility.buildPath("workspace://SpacesStore", folderFavorite.getNodeRef()))); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, + description = "Validate ID element in get file preference response") + public void validateIdElementInGetFilePreferenceResponse() throws Exception + { + FileModel fileFavorite = new FileModel("favoriteFile", FileType.TEXT_PLAIN); + fileFavorite = dataContent.usingSite(siteModel).createContent(fileFavorite); + dataContent.getContentActions().setFileAsFavorite(userModel.getUsername(), userModel.getPassword(), siteModel.getId(), String.format("%s.%s", fileFavorite.getName(), fileFavorite.getFileType().extention)); + + restPreferenceModel = restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString()); + restPreferenceModel.assertThat().field("id").is(PreferenceName.DOCUMENTS_FAVORITES_PREFIX) + .and().field("value").is(Utility.removeLastSlash(Utility.buildPath("workspace://SpacesStore", fileFavorite.getNodeRefWithoutVersion()))); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, + description = "Get preference of an user that has no preferences") + public void getPreferenceForUserWithoutPreferences() throws Exception + { + UserModel newUser = dataUser.createRandomTestUser(); + + restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString()); + restClient.assertLastError().containsSummary( + String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(), + PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString())); + + restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(PreferenceName.FOLDERS_FAVORITES_PREFIX.toString()); + restClient.assertLastError().containsSummary( + String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(), + PreferenceName.FOLDERS_FAVORITES_PREFIX.toString())); + + restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(PreferenceName.SITES_FAVORITES_PREFIX.toString()); + restClient.assertLastError().containsSummary( + String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(), + PreferenceName.SITES_FAVORITES_PREFIX.toString())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, + description = "Change one preference for an user then perform get call") + @Bug(id = "ACE-5736") + public void changePreferenceThenPerformGetPreferenceCall() throws Exception + { + UserModel newUser = dataUser.createRandomTestUser(); + SiteModel site = dataSite.usingUser(newUser).createPublicRandomSite(); + + dataSite.usingUser(newUser).usingSite(site).addSiteToFavorites(); + + FileModel fileFavorite = new FileModel("favoriteFile", FileType.TEXT_PLAIN); + fileFavorite = dataContent.usingSite(site).createContent(fileFavorite); + dataContent.getContentActions().setFileAsFavorite(newUser.getUsername(), newUser.getPassword(), site.getId(), String.format("%s.%s", fileFavorite.getName(), fileFavorite.getFileType().extention)); + + FolderModel folderFavorite = new FolderModel("favoriteFolder"); + folderFavorite = dataContent.usingSite(site).createFolder(folderFavorite); + dataContent.getContentActions().setFolderAsFavorite(newUser.getUsername(), newUser.getPassword(), site.getId(), folderFavorite.getName()); + + dataSite.usingUser(newUser).usingSite(site).removeSiteFromFavorites(); + dataContent.getContentActions().removeFavorite(newUser.getUsername(), newUser.getPassword(), site.getId(), folderFavorite.getName()); + dataContent.getContentActions().removeFavorite(newUser.getUsername(), newUser.getPassword(), site.getId(), Paths.get(fileFavorite.getCmisLocation()).getFileName().toString()); + + restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(PreferenceName.FOLDERS_FAVORITES_PREFIX.toString()); + restClient.assertLastError().containsSummary( + String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(), + PreferenceName.FOLDERS_FAVORITES_PREFIX.toString())); + + restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(PreferenceName.SITES_FAVORITES_PREFIX.toString()); + restClient.assertLastError().containsSummary( + String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(), + PreferenceName.SITES_FAVORITES_PREFIX.toString())); + + restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString()); + restClient.assertLastError().containsSummary( + String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(), + PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString())); + + restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser() + .getPersonPreferenceInformation(PreferenceName.FOLDERS_FAVORITES_PREFIX.toString()); + restClient.assertLastError().containsSummary( + String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(), + PreferenceName.FOLDERS_FAVORITES_PREFIX.toString())); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, + description = "Verify admin is able to get preference of another user") + public void adminIsAbleToGetOtherUserPreference() throws Exception + { + restPreferenceModel = restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingUser(userModel) + .getPersonPreferenceInformation(PreferenceName.SITES_FAVORITES_PREFIX + siteModel.getId()); + restClient.assertStatusCodeIs(HttpStatus.OK); + restPreferenceModel.assertThat().field("id").is(PreferenceName.SITES_FAVORITES_PREFIX + siteModel.getId()).and().field("value").is("true"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, + description = "Verify regular user is not able to get preference of admin user") + public void regularUserIsNotAbleToGetAdminPreference() throws Exception + { + SiteModel newSite = dataSite.usingUser(dataUser.getAdminUser()).createPublicRandomSite(); + dataSite.usingUser(dataUser.getAdminUser()).usingSite(newSite).addSiteToFavorites(); + + restClient.authenticateUser(userModel).withCoreAPI().usingUser(dataUser.getAdminUser()) + .getPersonPreferenceInformation(PreferenceName.SITES_FAVORITES_PREFIX + newSite.getId()); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); + restClient.assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); + } +} \ No newline at end of file