Changes for getRatingCoreTests

This commit is contained in:
Andrei Rusu
2016-12-06 10:23:57 +02:00
parent 3b6dd5502f
commit 0c1419af51
@@ -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");
}
}