From 3b6dd5502fdfcccd98982615dfeb163df9289b4c Mon Sep 17 00:00:00 2001 From: Andrei Rusu Date: Thu, 24 Nov 2016 17:20:42 +0200 Subject: [PATCH 1/3] Added tests for getRating CoreTests --- .../rest/ratings/GetRatingCoreTests.java | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 e2e-test/java/org/alfresco/rest/ratings/GetRatingCoreTests.java diff --git a/e2e-test/java/org/alfresco/rest/ratings/GetRatingCoreTests.java b/e2e-test/java/org/alfresco/rest/ratings/GetRatingCoreTests.java new file mode 100644 index 000000000..232dced69 --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/ratings/GetRatingCoreTests.java @@ -0,0 +1,161 @@ +package org.alfresco.rest.ratings; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestRatingModel; +import org.alfresco.utility.exception.DataPreparationException; +import org.alfresco.utility.model.ErrorModel; +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.apache.commons.lang.RandomStringUtils; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE }) +public class GetRatingCoreTests extends RestTest { + + private SiteModel siteModel; + private UserModel adminUserModel, userModel; + private FileModel document; + private RestRatingModel returnedRatingModel; + private FolderModel firstFolderModel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws DataPreparationException { + adminUserModel = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingAdmin().createPublicRandomSite(); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Check that rating for invalid ratingId provided status code is 400.") + public void checkInvalidRatingIdStatusCode() throws Exception { + + document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + + restClient.authenticateUser(adminUserModel).withCoreAPI(); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/ratings/{ratingId}", + document.getNodeRef(), "invalid ratingId"); + restClient.processModel(RestRatingModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() + .containsSummary("Invalid ratingSchemeId invalid ratingId"); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Check that rating for nodeId does not exist status code 404 is returned.") + public void getRatingUsingInvalidNodeId() throws Exception { + + document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + document.setNodeRef(RandomStringUtils.randomAlphanumeric(20)); + returnedRatingModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document) + .getFiveStarRating(); + + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(ErrorModel.ENTITY_NOT_FOUND, document.getNodeRef())); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Get rating of a file that has only likes.") + public void getRatingOfFileThatHasOnlyLikes() throws Exception { + + document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).likeDocument(); + + returnedRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true"); + Assert.assertEquals(returnedRatingModel.getAggregate().getNumberOfRatings(), 1, + "Node should have 1 like ratings"); + + returnedRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(returnedRatingModel.getAggregate().getNumberOfRatings(), 0, + "Node should have no five star ratings"); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Get rating of a file that has only stars.") + public void getRatingOfFileThatHasOnlyStars() throws Exception { + + document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).rateStarsToDocument(5); + + returnedRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and() + .field("aggregate").isNotEmpty(); + Assert.assertEquals(returnedRatingModel.getAggregate().getNumberOfRatings(), 1, + "Node should have 1 five star ratings"); + + returnedRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(returnedRatingModel.getAggregate().getNumberOfRatings(), 0, + "Node should have no like ratings"); + + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Get rating of a file that has likes and stars.") + public void getRatingOfFileThatHasLikesAndStars() throws Exception { + + document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).likeDocument(); + restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).rateStarsToDocument(5); + + returnedRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true"); + Assert.assertEquals(returnedRatingModel.getAggregate().getNumberOfRatings(), 1, + "Node should have 1 like ratings"); + + returnedRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and() + .field("aggregate").isNotEmpty(); + Assert.assertEquals(returnedRatingModel.getAggregate().getNumberOfRatings(), 1, + "Node should have 1 five stars ratings"); + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Get rating of a folder that has only likes.") + public void getRatingOfFolderThatHasOnlyLikes() throws Exception { + + firstFolderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder(); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(firstFolderModel).likeDocument(); + + returnedRatingModel = restClient.withCoreAPI().usingResource(firstFolderModel).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true"); + Assert.assertEquals(returnedRatingModel.getAggregate().getNumberOfRatings(), 1, + "Node should have 1 like rating"); + + } + + @TestRail(section = { TestGroup.REST_API, + TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Get rating of a file that has no ratings.") + public void getRatingOfFileThatHasNoRatings() throws Exception { + + document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + restClient.authenticateUser(adminUserModel).withCoreAPI(); + + returnedRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(returnedRatingModel.getAggregate().getNumberOfRatings(), 0, + "Node should have no likes ratings"); + + returnedRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + Assert.assertEquals(returnedRatingModel.getAggregate().getNumberOfRatings(), 0, + "Node should have no five star ratings"); + } + +} From 0c1419af51be68229346492136ac8a27d7bcb5db Mon Sep 17 00:00:00 2001 From: Andrei Rusu Date: Tue, 6 Dec 2016 10:23:57 +0200 Subject: [PATCH 2/3] Changes for getRatingCoreTests --- .../rest/ratings/GetRatingCoreTests.java | 220 ++++++++---------- 1 file changed, 102 insertions(+), 118 deletions(-) diff --git a/e2e-test/java/org/alfresco/rest/ratings/GetRatingCoreTests.java b/e2e-test/java/org/alfresco/rest/ratings/GetRatingCoreTests.java index 232dced69..6cbef9d9e 100644 --- a/e2e-test/java/org/alfresco/rest/ratings/GetRatingCoreTests.java +++ b/e2e-test/java/org/alfresco/rest/ratings/GetRatingCoreTests.java @@ -1,6 +1,7 @@ package org.alfresco.rest.ratings; import org.alfresco.dataprep.CMISUtil; +import org.alfresco.dataprep.CMISUtil.DocumentType; import org.alfresco.rest.RestTest; import org.alfresco.rest.core.RestRequest; import org.alfresco.rest.model.RestRatingModel; @@ -18,144 +19,127 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.testng.Assert; import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE }) -public class GetRatingCoreTests extends RestTest { +public class GetRatingCoreTests extends RestTest +{ + private SiteModel siteModel; + private UserModel adminUserModel, userModel; + private FileModel document; + private RestRatingModel returnedRatingModel; + private FolderModel firstFolderModel; - private SiteModel siteModel; - private UserModel adminUserModel, userModel; - private FileModel document; - private RestRatingModel returnedRatingModel; - private FolderModel firstFolderModel; + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws DataPreparationException + { + adminUserModel = dataUser.getAdminUser(); + userModel = dataUser.createRandomTestUser(); + siteModel = dataSite.usingAdmin().createPublicRandomSite(); + } - @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); + } - @TestRail(section = { TestGroup.REST_API, - TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Check that rating for invalid ratingId provided status code is 400.") - public void checkInvalidRatingIdStatusCode() throws Exception { + @TestRail(section = { TestGroup.REST_API, + TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Check that using invalid ratingId for get rating call returns status code 400.") + public void checkInvalidRatingIdStatusCode() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI(); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/ratings/{ratingId}", document.getNodeRef(), "invalid ratingId"); + restClient.processModel(RestRatingModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("invalid ratingId"); + } - document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + @TestRail(section = { TestGroup.REST_API, + TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Check that using invalid node ID for get rating call returns status code 404.") + public void getRatingUsingInvalidNodeId() throws Exception + { + document.setNodeRef(RandomStringUtils.randomAlphanumeric(20)); + returnedRatingModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).getFiveStarRating(); - restClient.authenticateUser(adminUserModel).withCoreAPI(); - RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/ratings/{ratingId}", - document.getNodeRef(), "invalid ratingId"); - restClient.processModel(RestRatingModel.class, request); - restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() - .containsSummary("Invalid ratingSchemeId invalid ratingId"); - } + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() + .containsSummary(String.format(ErrorModel.ENTITY_NOT_FOUND, document.getNodeRef())); + } - @TestRail(section = { TestGroup.REST_API, - TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Check that rating for nodeId does not exist status code 404 is returned.") - public void getRatingUsingInvalidNodeId() throws Exception { + @TestRail(section = { TestGroup.REST_API, + TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Get rating of a file that has only likes.") + public void getRatingOfFileThatHasOnlyLikes() throws Exception + { + restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).likeDocument(); - document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); - document.setNodeRef(RandomStringUtils.randomAlphanumeric(20)); - returnedRatingModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document) - .getFiveStarRating(); + returnedRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true"); + returnedRatingModel.getAggregate().assertThat().field("numberOfRatings").is("1"); - restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() - .containsSummary(String.format(ErrorModel.ENTITY_NOT_FOUND, document.getNodeRef())); - } + returnedRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModel.getAggregate().assertThat().field("numberOfRatings").is("0"); + } - @TestRail(section = { TestGroup.REST_API, - TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Get rating of a file that has only likes.") - public void getRatingOfFileThatHasOnlyLikes() throws Exception { + @TestRail(section = { TestGroup.REST_API, + TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Get rating of a file that has only stars.") + public void getRatingOfFileThatHasOnlyStars() throws Exception + { + restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).rateStarsToDocument(5); - document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); - restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).likeDocument(); + returnedRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty(); + returnedRatingModel.getAggregate().assertThat().field("numberOfRatings").is("1"); - returnedRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating(); - restClient.assertStatusCodeIs(HttpStatus.OK); - returnedRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true"); - Assert.assertEquals(returnedRatingModel.getAggregate().getNumberOfRatings(), 1, - "Node should have 1 like ratings"); + returnedRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModel.getAggregate().assertThat().field("numberOfRatings").is("0"); + } - returnedRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating(); - restClient.assertStatusCodeIs(HttpStatus.OK); - Assert.assertEquals(returnedRatingModel.getAggregate().getNumberOfRatings(), 0, - "Node should have no five star ratings"); - } + @TestRail(section = { TestGroup.REST_API, + TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Get rating of a file that has likes and stars.") + public void getRatingOfFileThatHasLikesAndStars() throws Exception + { + restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).likeDocument(); + restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).rateStarsToDocument(5); - @TestRail(section = { TestGroup.REST_API, - TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Get rating of a file that has only stars.") - public void getRatingOfFileThatHasOnlyStars() throws Exception { + returnedRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true"); + returnedRatingModel.getAggregate().assertThat().field("numberOfRatings").is("1"); - document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); - restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).rateStarsToDocument(5); + returnedRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty(); + returnedRatingModel.getAggregate().assertThat().field("numberOfRatings").is("1"); + } - returnedRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating(); - restClient.assertStatusCodeIs(HttpStatus.OK); - returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and() - .field("aggregate").isNotEmpty(); - Assert.assertEquals(returnedRatingModel.getAggregate().getNumberOfRatings(), 1, - "Node should have 1 five star ratings"); + @TestRail(section = { TestGroup.REST_API, + TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Get rating of a folder that has only likes.") + public void getRatingOfFolderThatHasOnlyLikes() throws Exception + { + firstFolderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder(); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(firstFolderModel).likeDocument(); - returnedRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating(); - restClient.assertStatusCodeIs(HttpStatus.OK); - Assert.assertEquals(returnedRatingModel.getAggregate().getNumberOfRatings(), 0, - "Node should have no like ratings"); + returnedRatingModel = restClient.withCoreAPI().usingResource(firstFolderModel).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true"); + returnedRatingModel.getAggregate().assertThat().field("numberOfRatings").is("1"); + } - } + @TestRail(section = { TestGroup.REST_API, + TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Get rating of a file that has no ratings.") + public void getRatingOfFileThatHasNoRatings() throws Exception + { + returnedRatingModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).getLikeRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModel.getAggregate().assertThat().field("numberOfRatings").is("0"); - @TestRail(section = { TestGroup.REST_API, - TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Get rating of a file that has likes and stars.") - public void getRatingOfFileThatHasLikesAndStars() throws Exception { - - document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); - restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).likeDocument(); - restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).rateStarsToDocument(5); - - returnedRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating(); - restClient.assertStatusCodeIs(HttpStatus.OK); - returnedRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true"); - Assert.assertEquals(returnedRatingModel.getAggregate().getNumberOfRatings(), 1, - "Node should have 1 like ratings"); - - returnedRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating(); - restClient.assertStatusCodeIs(HttpStatus.OK); - returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and() - .field("aggregate").isNotEmpty(); - Assert.assertEquals(returnedRatingModel.getAggregate().getNumberOfRatings(), 1, - "Node should have 1 five stars ratings"); - } - - @TestRail(section = { TestGroup.REST_API, - TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Get rating of a folder that has only likes.") - public void getRatingOfFolderThatHasOnlyLikes() throws Exception { - - firstFolderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder(); - restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(firstFolderModel).likeDocument(); - - returnedRatingModel = restClient.withCoreAPI().usingResource(firstFolderModel).getLikeRating(); - restClient.assertStatusCodeIs(HttpStatus.OK); - returnedRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true"); - Assert.assertEquals(returnedRatingModel.getAggregate().getNumberOfRatings(), 1, - "Node should have 1 like rating"); - - } - - @TestRail(section = { TestGroup.REST_API, - TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Get rating of a file that has no ratings.") - public void getRatingOfFileThatHasNoRatings() throws Exception { - - document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); - restClient.authenticateUser(adminUserModel).withCoreAPI(); - - returnedRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating(); - restClient.assertStatusCodeIs(HttpStatus.OK); - Assert.assertEquals(returnedRatingModel.getAggregate().getNumberOfRatings(), 0, - "Node should have no likes ratings"); - - returnedRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating(); - restClient.assertStatusCodeIs(HttpStatus.OK); - Assert.assertEquals(returnedRatingModel.getAggregate().getNumberOfRatings(), 0, - "Node should have no five star ratings"); - } + returnedRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating(); + restClient.assertStatusCodeIs(HttpStatus.OK); + returnedRatingModel.getAggregate().assertThat().field("numberOfRatings").is("0"); + } } From b887a6fcff1725141cc09a0aadc66cdd16e69dc5 Mon Sep 17 00:00:00 2001 From: Valentin Popa Date: Wed, 7 Dec 2016 17:18:57 +0200 Subject: [PATCH 3/3] Merge master into TAS-2039 --- .../alfresco/rest/ratings/GetRatingCoreTests.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/e2e-test/java/org/alfresco/rest/ratings/GetRatingCoreTests.java b/e2e-test/java/org/alfresco/rest/ratings/GetRatingCoreTests.java index 6cbef9d9e..38c120997 100644 --- a/e2e-test/java/org/alfresco/rest/ratings/GetRatingCoreTests.java +++ b/e2e-test/java/org/alfresco/rest/ratings/GetRatingCoreTests.java @@ -1,12 +1,11 @@ package org.alfresco.rest.ratings; -import org.alfresco.dataprep.CMISUtil; import org.alfresco.dataprep.CMISUtil.DocumentType; import org.alfresco.rest.RestTest; import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestErrorModel; import org.alfresco.rest.model.RestRatingModel; import org.alfresco.utility.exception.DataPreparationException; -import org.alfresco.utility.model.ErrorModel; import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FolderModel; import org.alfresco.utility.model.SiteModel; @@ -17,7 +16,6 @@ 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.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -42,7 +40,7 @@ public class GetRatingCoreTests extends RestTest @BeforeMethod(alwaysRun = true) public void setUp() throws DataPreparationException, Exception { - document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN); + document = dataContent.usingSite(siteModel).usingAdmin().createContent(DocumentType.TEXT_PLAIN); } @TestRail(section = { TestGroup.REST_API, @@ -52,7 +50,7 @@ public class GetRatingCoreTests extends RestTest restClient.authenticateUser(adminUserModel).withCoreAPI(); RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/ratings/{ratingId}", document.getNodeRef(), "invalid ratingId"); restClient.processModel(RestRatingModel.class, request); - restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("invalid ratingId"); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.INVALID_RATING, "invalid ratingId")); } @TestRail(section = { TestGroup.REST_API, @@ -63,7 +61,7 @@ public class GetRatingCoreTests extends RestTest returnedRatingModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).getFiveStarRating(); restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError() - .containsSummary(String.format(ErrorModel.ENTITY_NOT_FOUND, document.getNodeRef())); + .containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, document.getNodeRef())); } @TestRail(section = { TestGroup.REST_API, @@ -142,4 +140,4 @@ public class GetRatingCoreTests extends RestTest returnedRatingModel.getAggregate().assertThat().field("numberOfRatings").is("0"); } -} +} \ No newline at end of file