From e31f0a30fce5d8b8d9192e9919a940cbaf840d14 Mon Sep 17 00:00:00 2001 From: Valentin Popa Date: Wed, 25 Jan 2017 17:45:15 +0200 Subject: [PATCH] Get ratings full tests and fixes --- .../rest/ratings/GetRatingsCoreTests.java | 51 ++++---- .../rest/ratings/GetRatingsFullTests.java | 116 ++++++++++++++++++ 2 files changed, 145 insertions(+), 22 deletions(-) create mode 100644 e2e-test/java/org/alfresco/rest/ratings/GetRatingsFullTests.java diff --git a/e2e-test/java/org/alfresco/rest/ratings/GetRatingsCoreTests.java b/e2e-test/java/org/alfresco/rest/ratings/GetRatingsCoreTests.java index 54d0da2b4..3051df8f4 100644 --- a/e2e-test/java/org/alfresco/rest/ratings/GetRatingsCoreTests.java +++ b/e2e-test/java/org/alfresco/rest/ratings/GetRatingsCoreTests.java @@ -3,7 +3,7 @@ package org.alfresco.rest.ratings; import org.alfresco.dataprep.CMISUtil; import org.alfresco.rest.RestTest; import org.alfresco.rest.model.RestErrorModel; -import org.alfresco.rest.model.RestRatingModel; +import org.alfresco.rest.model.RestRatingModelsCollection; import org.alfresco.utility.exception.DataPreparationException; import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.SiteModel; @@ -22,7 +22,7 @@ public class GetRatingsCoreTests extends RestTest private SiteModel siteModel; private UserModel adminUserModel, userModel; private FileModel document; - private RestRatingModel returnedRatingModel; + private RestRatingModelsCollection ratingsModel; @BeforeClass(alwaysRun = true) public void dataPreparation() throws DataPreparationException @@ -36,63 +36,70 @@ public class GetRatingsCoreTests extends RestTest public void setUp() throws DataPreparationException, Exception { document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + restClient.authenticateUser(userModel).withCoreAPI().usingNode(document).rateStarsToDocument(5); + restClient.authenticateUser(userModel).withCoreAPI().usingNode(document).likeDocument(); } - @TestRail(section = { TestGroup.REST_API, - TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Check that rating for invalid maxItems status code is 400") + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Check that rating for invalid maxItems status code is 400") @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE }) public void checkInvalidMaxItemsStatusCode() throws Exception { - restClient.authenticateUser(adminUserModel).withParams("maxItems=0").withCoreAPI().usingResource(document).getLikeRating(); + restClient.authenticateUser(adminUserModel).withParams("maxItems=0").withCoreAPI().usingResource(document).getRatings(); restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("Only positive values supported for maxItems"); } - @TestRail(section = { TestGroup.REST_API, - TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Check that rating for invalid skipCount status code is 400") + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Check that rating for invalid skipCount status code is 400") @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE }) public void checkInvalidSkipCountStatusCode() throws Exception { - restClient.authenticateUser(adminUserModel).withParams("skipCount=AB").withCoreAPI().usingResource(document).getLikeRating(); + restClient.authenticateUser(adminUserModel).withParams("skipCount=AB").withCoreAPI().usingResource(document).getRatings(); restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("Invalid paging parameter skipCount:AB"); } - @TestRail(section = { TestGroup.REST_API, - TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "If nodeId does not exist status code is 404 when a document is liked") + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "If nodeId does not exist status code is 404 when a document is liked") @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE }) public void addLikeUsingInvalidNodeId() throws Exception { - + FileModel document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + restClient.authenticateUser(userModel).withCoreAPI().usingNode(document).rateStarsToDocument(5); + restClient.authenticateUser(userModel).withCoreAPI().usingNode(document).likeDocument(); document.setNodeRef(RandomStringUtils.randomAlphanumeric(20)); - returnedRatingModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).likeDocument(); + + restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).getRatings(); restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, document.getNodeRef())); } - @TestRail(section = { TestGroup.REST_API, - TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Check that rating value is TRUE for a like rating") + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Check that rating value is TRUE for a like rating") @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE }) public void checkRatingValueIsTrueForLikedDoc() throws Exception { - returnedRatingModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).likeDocument(); - restClient.assertStatusCodeIs(HttpStatus.CREATED); + ratingsModel = restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.OK); - returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes"); + ratingsModel.assertThat().entriesListContains("myRating", "true") + .assertThat().entriesListContains("id", "likes"); } - @TestRail(section = { TestGroup.REST_API, - TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Check that rating value is an INTEGER value for stars rating") + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Check that rating value is an INTEGER value for stars rating") @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE }) public void checkRatingValueIsIntegerForStarsRating() throws Exception { - returnedRatingModel = restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).rateStarsToDocument(5); - restClient.assertStatusCodeIs(HttpStatus.CREATED); + ratingsModel = restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.OK); - returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty(); + ratingsModel.assertThat().entriesListContains("myRating", "5") + .assertThat().entriesListContains("id", "fiveStar"); } } diff --git a/e2e-test/java/org/alfresco/rest/ratings/GetRatingsFullTests.java b/e2e-test/java/org/alfresco/rest/ratings/GetRatingsFullTests.java new file mode 100644 index 000000000..1fdbd80ba --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/ratings/GetRatingsFullTests.java @@ -0,0 +1,116 @@ +package org.alfresco.rest.ratings; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestRatingModelsCollection; +import org.alfresco.utility.exception.DataPreparationException; +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.BeforeMethod; +import org.testng.annotations.Test; + +public class GetRatingsFullTests extends RestTest +{ + private SiteModel siteModel; + private UserModel adminUserModel, userModel; + private FileModel document; + private RestRatingModelsCollection ratingsModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws DataPreparationException + { + adminUserModel = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingAdmin().createPublicRandomSite(); + } + + @BeforeMethod(alwaysRun = true) + public void setUp() throws DataPreparationException, Exception + { + document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + restClient.authenticateUser(userModel).withCoreAPI().usingNode(document).rateStarsToDocument(5); + restClient.authenticateUser(userModel).withCoreAPI().usingNode(document).likeDocument(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Check default error schema in case of failure") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL }) + public void checkDefaultErrorSchema() throws Exception + { + FileModel document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + document.setNodeRef("abc"); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "abc")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Check maxItems and skipCount parameters") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL }) + public void checkMaxItemsAndSkipCountParameters() throws Exception + { + ratingsModel = restClient.authenticateUser(adminUserModel).withParams("maxItems=1", "skipCount=1").withCoreAPI().usingResource(document).getRatings(); + ratingsModel.assertThat().entriesListCountIs(1); + ratingsModel.getPagination().assertThat().field("maxItems").is("1") + .and().field("skipCount").is("1"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Check totalItems and hasMoreitems parameters") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL }) + public void checkTotalItemsAndHasMoreItemsParameters() throws Exception + { + ratingsModel = restClient.authenticateUser(adminUserModel).withParams("maxItems=1").withCoreAPI().usingResource(document).getRatings(); + ratingsModel.assertThat().entriesListCountIs(1); + ratingsModel.getPagination().assertThat().field("hasMoreItems").is("true") + .and().field("totalItems").is("2"); + } + + @Bug(id = "REPO-1831") + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Get ratings for a document to which authenticated user does not have access") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL }) + public void userIsNotAbleToGetRatingsOfDocumentToWhichItHasNoAccess() throws Exception + { + SiteModel privateSite = dataSite.usingAdmin().createPrivateRandomSite(); + FileModel file = dataContent.usingSite(privateSite).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + ratingsModel = restClient.authenticateUser(userModel).withCoreAPI().usingResource(file).getRatings(); + ratingsModel.assertThat().entriesListIsEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Check high value for skipCount parameter") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL }) + public void getRatingsUsingHighValueForSkipCount() throws Exception + { + ratingsModel = restClient.authenticateUser(adminUserModel).withParams("skipCount=100").withCoreAPI().usingResource(document).getRatings(); + ratingsModel.getPagination().assertThat().field("skipCount").is("100"); + ratingsModel.assertThat().entriesListIsEmpty(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, + description = "Get ratings using site id instead of node id") + @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL }) + public void getRatingsUsingSiteId() throws Exception + { + FileModel document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + document.setNodeRef(siteModel.getId()); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).getRatings(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY) + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, siteModel.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } +} \ No newline at end of file