From 46270b72d2b2df131d690271dba4ce66bfb678c1 Mon Sep 17 00:00:00 2001 From: Bogdan Bocancea Date: Tue, 29 Nov 2016 16:45:47 +0200 Subject: [PATCH] TAS-2054: add core tests to update tag --- .../rest/tags/UpdateTagCoreTests.java | 150 ++++++++++++++++++ .../rest/tags/UpdateTagSanityTests.java | 5 +- 2 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 e2e-test/java/org/alfresco/rest/tags/UpdateTagCoreTests.java diff --git a/e2e-test/java/org/alfresco/rest/tags/UpdateTagCoreTests.java b/e2e-test/java/org/alfresco/rest/tags/UpdateTagCoreTests.java new file mode 100644 index 000000000..a1419c732 --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/tags/UpdateTagCoreTests.java @@ -0,0 +1,150 @@ +package org.alfresco.rest.tags; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestTagModel; +import org.alfresco.utility.Utility; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.data.RandomData; +import org.alfresco.utility.model.ErrorModel; +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.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; + +/** + * Created by Bogdan Bocancea + */ +@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.CORE }) +public class UpdateTagCoreTests extends RestTest +{ + private UserModel managerUser; + private FileModel document; + private SiteModel siteModel; + private DataUser.ListUserWithRoles usersWithRoles; + private RestTagModel oldTag; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + managerUser = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(managerUser).createPublicRandomSite(); + document = dataContent.usingSite(siteModel).usingUser(managerUser).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor); + + restClient.authenticateUser(managerUser); + oldTag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("old")); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.TAGS }, executionType = ExecutionType.SANITY, description = "Verify contributor user gets status code 401 if authentication call fails") + @Bug(id="MNT-16904", description = "Reproduced only on 5.1.N") + public void contributorIsNotAbleToUpdateTagIfAuthenticationFails() throws JsonToModelConversionException, Exception + { + UserModel siteContributor = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor); + siteContributor.setPassword("wrongPassword"); + restClient.authenticateUser(siteContributor); + restClient.withCoreAPI().usingTag(oldTag).update(RandomData.getRandomName("tag")); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED) + .assertLastError().containsSummary(ErrorModel.AUTHENTICATION_FAILED); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.TAGS }, executionType = ExecutionType.SANITY, description = "Verify collaborator user gets status code 401 if authentication call fails") + @Bug(id="MNT-16904", description = "Reproduced only on 5.1.N") + public void collaboratorIsNotAbleToUpdateTagIfAuthenticationFails() throws JsonToModelConversionException, Exception + { + UserModel siteCollaborator = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor); + siteCollaborator.setPassword("wrongPassword"); + restClient.authenticateUser(siteCollaborator); + restClient.withCoreAPI().usingTag(oldTag).update(RandomData.getRandomName("tag")); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED) + .assertLastError().containsSummary(ErrorModel.AUTHENTICATION_FAILED); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.TAGS }, executionType = ExecutionType.SANITY, description = "Verify consumer user gets status code 401 if authentication call fails") + @Bug(id="MNT-16904", description = "Reproduced only on 5.1.N") + public void consumerIsNotAbleToUpdateTagIfAuthenticationFails() throws JsonToModelConversionException, Exception + { + UserModel siteConsumer = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor); + siteConsumer.setPassword("wrongPassword"); + restClient.authenticateUser(siteConsumer); + restClient.withCoreAPI().usingTag(oldTag).update(RandomData.getRandomName("tag")); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED) + .assertLastError().containsSummary(ErrorModel.AUTHENTICATION_FAILED); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.TAGS }, executionType = ExecutionType.SANITY, description = "Verify site manager is not able to update tag with invalid id") + public void managerIsNotAbleToUpdateTagWithInvalidId() throws JsonToModelConversionException, Exception + { + String invalidTagId = "invalid-id"; + restClient.authenticateUser(managerUser); + RestTagModel tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); + tag.setId(invalidTagId); + restClient.withCoreAPI().usingTag(tag).update(RandomData.getRandomName("tag")); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(ErrorModel.ENTITY_NOT_FOUND, invalidTagId)); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.TAGS }, executionType = ExecutionType.SANITY, description = "Verify site manager is not able to update tag with empty id") + public void managerIsNotAbleToUpdateTagWithEmptyId() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(managerUser); + RestTagModel tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); + tag.setId(""); + restClient.withCoreAPI().usingTag(tag).update(RandomData.getRandomName("tag")); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.TAGS }, executionType = ExecutionType.SANITY, description = "Verify site manager is not able to update tag with invalid body") + public void managerIsNotAbleToUpdateTagWithEmptyBody() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(managerUser); + RestTagModel tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); + restClient.withCoreAPI().usingTag(tag).update(""); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(ErrorModel.EMPTY_TAG); + } + + @Bug(id="ACE-5629") + @TestRail(section = { TestGroup.REST_API, + TestGroup.TAGS }, executionType = ExecutionType.SANITY, + description = "Verify site manager is not able to update tag with invalid body containing '|' symbol") + public void managerIsNotAbleToUpdateTagWithInvalidBodyScenario1() throws JsonToModelConversionException, Exception + { + String invalidTagBody = "|.\"/<>*"; + restClient.authenticateUser(managerUser); + RestTagModel tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); + Utility.waitToLoopTime(20); + restClient.withCoreAPI().usingTag(tag).update(invalidTagBody); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(ErrorModel.INVALID_TAG, invalidTagBody)); + } + + @Bug(id="ACE-5629") + @TestRail(section = { TestGroup.REST_API, + TestGroup.TAGS }, executionType = ExecutionType.SANITY, + description = "Verify site manager is not able to update tag with invalid body without '|' symbol") + public void managerIsNotAbleToUpdateTagWithInvalidBodyScenario2() throws JsonToModelConversionException, Exception + { + String invalidTagBody = ".\"/<>*"; + restClient.authenticateUser(managerUser); + RestTagModel tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); + Utility.waitToLoopTime(20); + restClient.withCoreAPI().usingTag(tag).update(invalidTagBody); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(ErrorModel.INVALID_TAG, invalidTagBody)); + } +} diff --git a/e2e-test/java/org/alfresco/rest/tags/UpdateTagSanityTests.java b/e2e-test/java/org/alfresco/rest/tags/UpdateTagSanityTests.java index cc0e69d12..be11c0477 100644 --- a/e2e-test/java/org/alfresco/rest/tags/UpdateTagSanityTests.java +++ b/e2e-test/java/org/alfresco/rest/tags/UpdateTagSanityTests.java @@ -10,7 +10,6 @@ import org.alfresco.utility.data.RandomData; import org.alfresco.utility.model.ErrorModel; import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.SiteModel; -import org.alfresco.utility.model.StatusModel; import org.alfresco.utility.model.TestGroup; import org.alfresco.utility.model.UserModel; import org.alfresco.utility.report.Bug; @@ -27,7 +26,6 @@ import org.testng.annotations.Test; @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) public class UpdateTagSanityTests extends RestTest { - private UserModel adminUserModel; private FileModel document; private SiteModel siteModel; @@ -108,6 +106,7 @@ public class UpdateTagSanityTests extends RestTest siteManager.setPassword("wrongPassword"); restClient.authenticateUser(siteManager); restClient.withCoreAPI().usingTag(oldTag).update(randomTag); - restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastException().hasName(StatusModel.UNAUTHORIZED); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED) + .assertLastError().containsSummary(ErrorModel.AUTHENTICATION_FAILED); } } \ No newline at end of file