REPO-2755 / REPO-2251: changed CORE and FULL groups with REGRESSION in ratings package

This commit is contained in:
cagache
2017-10-06 14:18:34 +03:00
parent 7b0e1919a8
commit b1c63bd2e1
16 changed files with 2089 additions and 2531 deletions
@@ -1,302 +0,0 @@
package org.alfresco.rest.ratings;
import org.alfresco.dataprep.CMISUtil.DocumentType;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestCommentModel;
import org.alfresco.rest.model.RestErrorModel;
import org.alfresco.rest.model.RestRatingModel;
import org.alfresco.rest.model.RestTagModel;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.exception.DataPreparationException;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FolderModel;
import org.alfresco.utility.model.LinkModel;
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.lang3.RandomStringUtils;
import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class AddRatingCoreTests extends RestTest
{
private UserModel userModel;
private SiteModel siteModel;
private UserModel adminUser;
private ListUserWithRoles usersWithRoles;
private RestRatingModel returnedRatingModel; // placeholder for returned model
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws DataPreparationException
{
userModel = dataUser.createUser(RandomStringUtils.randomAlphanumeric(20));
adminUser = dataUser.getAdminUser();
siteModel = dataSite.usingUser(userModel).createPublicRandomSite();
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer,
UserRole.SiteContributor);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify that if unknown rating scheme is provided status code is 400")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void unknownRatingSchemeReturnsBadRequest() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"invalidRate\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(String.format(RestErrorModel.INVALID_RATING, "invalidRate"))
.containsErrorKey(String.format(RestErrorModel.INVALID_RATING, "invalidRate"))
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify that if nodeId does not exist status code 404 is returned")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void invalidNodeIdReturnsNotFound() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
document.setNodeRef(RandomStringUtils.randomAlphanumeric(10));
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND)
.assertLastError()
.containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, document.getNodeRef()))
.containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify that if nodeId provided cannot be rated 405 status code is returned")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void likeResourceThatCannotBeRated() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
LinkModel link = dataLink.usingAdmin().usingSite(siteModel).createRandomLink();
document.setNodeRef(link.getNodeRef().replace("workspace://SpacesStore/", "workspace%3A%2F%2FSpacesStore%2F"));
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND)
.assertLastError()
.containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, document.getNodeRef()))
.containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify that manager is able to like a file")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void managerIsAbleToLikeAFile() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(document)
.likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify that manager is able to like a folder")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void managerIsAbleToLikeAFolder() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(folderModel)
.likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify that manager is able to like a site")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void managerIsAbleToLikeASite() throws Exception
{
FolderModel folderModel = new FolderModel();
folderModel.setNodeRef(siteModel.getGuid());
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(folderModel)
.likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
restClient.withCoreAPI().usingResource(folderModel).getRatings()
.assertNodeIsLiked();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify that manager is able to rate a folder")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void managerIsAbleToRateAFolder() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(folderModel)
.rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify that manager is able to rate a file")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void managerIsAbleToRateAFile() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(document)
.rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify that manager is able to rate a site")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void managerIsAbleToRateASite() throws Exception
{
FolderModel folderModel = new FolderModel();
folderModel.setNodeRef(siteModel.getGuid());
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(folderModel)
.rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
restClient.withCoreAPI().usingResource(folderModel).getRatings()
.assertNodeHasFiveStarRating();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify that adding like again has no effect on a file")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void fileCanBeLikedTwice() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify that adding rate again has no effect on a file")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void fileCanBeRatedTwice() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify that rate is not added if empty rating object is provided")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void addRateUsingEmptyRatingObject() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError()
.containsSummary(String.format(RestErrorModel.NO_CONTENT, "No content to map to Object due to end of input"));
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify that if empty rate id is provided status code is 400")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void addRateUsingEmptyValueForId() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError()
.containsSummary(String.format(RestErrorModel.NO_CONTENT, "N/A (through reference chain: org.alfresco.rest.api.model.NodeRating[\"id\"])"));
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify that if empty rating is provided status code is 400")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void addRateUsingEmptyValueForMyRating() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"likes\", \"myRating\":\"\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.NULL_LIKE_RATING));
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"fiveStar\", \"myRating\":\"\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.NULL_FIVESTAR_RATING));
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify that user is not able to rate a comment")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void addRatingToAComment() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
RestCommentModel comment = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addComment("This is a comment");
document.setNodeRef(comment.getId());
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED)
.assertLastError()
.containsSummary(String.format(RestErrorModel.CANNOT_RATE))
.containsErrorKey(RestErrorModel.CANNOT_RATE)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError().containsSummary(String.format(RestErrorModel.CANNOT_RATE));
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify that user is not able to rate a tag")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void addRatingToATag() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
RestTagModel tag = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addTag("randomTag");
document.setNodeRef(tag.getId());
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError().containsSummary(String.format(RestErrorModel.CANNOT_RATE));
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError().containsSummary(String.format(RestErrorModel.CANNOT_RATE));
}
}
@@ -1,518 +0,0 @@
package org.alfresco.rest.ratings;
import org.alfresco.dataprep.CMISUtil.DocumentType;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestCommentModel;
import org.alfresco.rest.model.RestErrorModel;
import org.alfresco.rest.model.RestRatingModel;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.exception.DataPreparationException;
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.lang3.RandomStringUtils;
import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class AddRatingFullTests extends RestTest
{
private UserModel userModel;
private SiteModel siteModel;
private UserModel adminUser;
private ListUserWithRoles usersWithRoles;
private RestRatingModel returnedRatingModel;
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws DataPreparationException
{
userModel = dataUser.createUser(RandomStringUtils.randomAlphanumeric(20));
adminUser = dataUser.getAdminUser();
siteModel = dataSite.usingUser(userModel).createPublicRandomSite();
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer,
UserRole.SiteContributor);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that Contributor is able to like a file")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void contributorIsAbleToLikeAFile() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI()
.usingResource(document)
.likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true")
.and().field("id").is("likes")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that Collaborator is able to like a file")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void collaboratorIsAbleToLikeAFile() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI()
.usingResource(document)
.likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true")
.and().field("id").is("likes")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that Consumer is able to like a file")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void consumerIsAbleToLikeAFile() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI()
.usingResource(document)
.likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true")
.and().field("id").is("likes")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that Contributor is able to like a folder")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void contributorIsAbleToLikeAFolder() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI()
.usingResource(folderModel)
.likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true")
.and().field("id").is("likes")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that Collaborator is able to like a folder")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void collaboratorIsAbleToLikeAFolder() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI()
.usingResource(folderModel)
.likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true")
.and().field("id").is("likes")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that Consumer is able to like a folder")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void consumerIsAbleToLikeAFolder() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI()
.usingResource(folderModel)
.likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true")
.and().field("id").is("likes")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that Contributor is able to rate a file")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void contributorIsAbleToRateAFile() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI()
.usingResource(document)
.rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5")
.and().field("id").is("fiveStar")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that Collaborator is able to rate a file")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void collaboratorIsAbleToRateAFile() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI()
.usingResource(document)
.rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5")
.and().field("id").is("fiveStar")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that Consumer is able to rate a file")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void consumerIsAbleToRateAFile() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI()
.usingResource(document)
.rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5")
.and().field("id").is("fiveStar")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that Contributor is able to rate a folder")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void contributorIsAbleToRateAFolder() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI()
.usingResource(folderModel)
.rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5")
.and().field("id").is("fiveStar")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that Collaborator is able to rate a folder")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void collaboratorIsAbleToRateAFolder() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI()
.usingResource(folderModel)
.rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5")
.and().field("id").is("fiveStar")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that Consumer is able to rate a folder")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void consumerIsAbleToRateAFolder() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI()
.usingResource(folderModel)
.rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5")
.and().field("id").is("fiveStar")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that adding like again has no effect on a folder")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void folderCanBeLikedTwice() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folderModel).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folderModel).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true")
.and().field("id").is("likes")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that adding rate again has no effect on a folder")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void folderCanBeRatedTwice() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folderModel).rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folderModel).rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5")
.and().field("id").is("fiveStar")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that if invalid rate id is provided status code is 400")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void addRateUsingInvalidValueForId() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"like\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(String.format(RestErrorModel.INVALID_RATING, "like"))
.containsErrorKey(String.format(RestErrorModel.INVALID_RATING, "like"))
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that rate id is case sensitive is provided status code is 400")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void addRateUsingInvalidValueForIdCaseSensitive() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"Likes\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(String.format(RestErrorModel.INVALID_RATING, "Likes"))
.containsErrorKey(String.format(RestErrorModel.INVALID_RATING, "Likes"))
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"FiveStar\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(String.format(RestErrorModel.INVALID_RATING, "FiveStar"))
.containsErrorKey(String.format(RestErrorModel.INVALID_RATING, "FiveStar"))
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that if invalid rating is provided status code is 400")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void addRateUsingInvalidValueForMyRating() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"likes\", \"myRating\":\"skiped\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(String.format(RestErrorModel.NULL_LIKE_RATING));
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"fiveStar\", \"myRating\":\"string\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(String.format(RestErrorModel.NULL_FIVESTAR_RATING));
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Like file created by a different user")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void addLikeToAnotherUserFile() throws Exception
{
UserModel user = dataUser.usingAdmin().createRandomTestUser();
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(user).withCoreAPI().usingResource(document).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true")
.and().field("id").is("likes")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Rate a file created by a different user")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void addRatingToAnotherUserFile() throws Exception
{
UserModel user = dataUser.usingAdmin().createRandomTestUser();
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(user).withCoreAPI().usingResource(document).rateStarsToDocument(5);
returnedRatingModel.assertThat().field("myRating").is("5")
.and().field("id").is("fiveStar")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Add Rate Using Boolean Value For 'myRating'")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void addRateUsingBooleanValueForMyRating() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"fiveStar\", \"myRating\":\"true\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(RestErrorModel.NULL_FIVESTAR_RATING)
.containsErrorKey(RestErrorModel.NULL_FIVESTAR_RATING)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Add Like Using Integer Value For 'myRating'")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void addLikeUsingIntegerValueForMyRating() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"likes\", \"myRating\":\"2\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(RestErrorModel.NULL_LIKE_RATING)
.containsErrorKey(RestErrorModel.NULL_LIKE_RATING)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that user is not able to like his own comment")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void userCannotLikeHisOwnComment() throws Exception
{
UserModel user = usersWithRoles.getOneUserWithRole(UserRole.SiteManager);
FolderModel folderModel = dataContent.usingUser(user).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(user).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
RestCommentModel comment = restClient.authenticateUser(user).withCoreAPI().usingResource(document).addComment("This is a comment");
document.setNodeRef(comment.getId());
returnedRatingModel = restClient.authenticateUser(user).withCoreAPI().usingResource(document).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED)
.assertLastError()
.containsSummary(String.format(RestErrorModel.CANNOT_RATE))
.containsErrorKey(RestErrorModel.CANNOT_RATE)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER).stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that user is not able to rate his own comment")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void userCannotRateHisOwnComment() throws Exception
{
UserModel user = usersWithRoles.getOneUserWithRole(UserRole.SiteManager);
FolderModel folderModel = dataContent.usingUser(user).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(user).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
RestCommentModel comment = restClient.authenticateUser(user).withCoreAPI().usingResource(document).addComment("This is a comment");
document.setNodeRef(comment.getId());
returnedRatingModel = restClient.authenticateUser(user).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED)
.assertLastError()
.containsSummary(String.format(RestErrorModel.CANNOT_RATE))
.containsErrorKey(RestErrorModel.CANNOT_RATE)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that Collaborator is NOT able to add a negative rating to a file")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void collaboratorIsNotAbleToAddANegativeRatingToAFile() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI()
.usingResource(document)
.rateStarsToDocument(-5);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(RestErrorModel.RATING_OUT_OF_BOUNDS)
.containsErrorKey(RestErrorModel.RATING_OUT_OF_BOUNDS)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that Collaborator is NOT able to add a high rating to a file")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void collaboratorIsNotAbleToAddAHighRatingToAFile() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI()
.usingResource(document)
.rateStarsToDocument(10);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(RestErrorModel.RATING_OUT_OF_BOUNDS)
.containsErrorKey(RestErrorModel.RATING_OUT_OF_BOUNDS)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
// @Bug(id = "MNT-17375", description = "Won't Fix, the error message is not ideal and a little cryptic but it does provide the reason i.e. ratingSchemeId is null.")
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Do not provide field - 'id'")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void notProvideIdLikeFile() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"myRating\":\"true\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(String.format(RestErrorModel.INVALID_RATING, "null"))
.containsErrorKey(String.format(RestErrorModel.INVALID_RATING, "null"))
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Do not provide field - 'myRating'")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void notProvideMyRatingRateFile() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"likes\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(RestErrorModel.NULL_LIKE_RATING)
.containsErrorKey(RestErrorModel.NULL_LIKE_RATING)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
}
@@ -1,214 +0,0 @@
package org.alfresco.rest.ratings;
import org.alfresco.dataprep.CMISUtil.DocumentType;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestErrorModel;
import org.alfresco.rest.model.RestRatingModel;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.exception.DataPreparationException;
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.report.Bug;
import org.alfresco.utility.testrail.ExecutionType;
import org.alfresco.utility.testrail.annotation.TestRail;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class AddRatingSanityTests extends RestTest
{
private UserModel userModel;
private SiteModel siteModel;
private UserModel adminUser;
private ListUserWithRoles usersWithRoles;
private RestRatingModel returnedRatingModel; // placeholder for returned model
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws DataPreparationException
{
userModel = dataUser.createUser(RandomStringUtils.randomAlphanumeric(20));
adminUser = dataUser.getAdminUser();
siteModel = dataSite.usingUser(userModel).createPublicRandomSite();
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer,
UserRole.SiteContributor);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify user with Manager role is able to post like rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void managerIsAbleToLikeDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(document)
.likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify user with Collaborator role is able to post like rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void collaboratorIsAbleToLikeDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(document)
.likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify user with Contributor role is able to post like rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void contributorIsAbleToLikeDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI().usingResource(document)
.likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify user with Consumer role is able to post like rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void consumerIsAbleToLikeDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingResource(document)
.likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify admin user is able to post like rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void adminIsAbleToLikeDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify unauthenticated user is not able to post like rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
@Bug(id="MNT-16904", description = "It fails only on environment with tenants")
public void unauthenticatedUserIsNotAbleToLikeDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(new UserModel("random user", "random password")).withCoreAPI().usingResource(document).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError()
.containsSummary(RestErrorModel.AUTHENTICATION_FAILED);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify user with Manager role is able to post stars rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void managerIsAbleToAddStarsToDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(document)
.rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify user with Collaborator role is able to post stars rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void collaboratorIsAbleToAddStarsToDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(document)
.rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify user with Contributor role is able to post stars rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void contributorIsAbleToAddStarsToDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI().usingResource(document)
.rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify user with Consumer role is able to post stars rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void consumerIsAbleToAddStarsToDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingResource(document)
.rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify admin user is able to post stars rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void adminIsAbleToAddStarsToDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).rateStarsToDocument(3);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("3").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify unauthenticated user is not able to post stars rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
@Bug(id="MNT-16904", description = "fails only on environment with tenants")
public void unauthenticatedUserIsNotAbleToRateStarsToDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(new UserModel("random user", "random password")).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError()
.containsSummary(RestErrorModel.AUTHENTICATION_FAILED);
}
}
@@ -0,0 +1,813 @@
package org.alfresco.rest.ratings;
import org.alfresco.dataprep.CMISUtil.DocumentType;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestCommentModel;
import org.alfresco.rest.model.RestErrorModel;
import org.alfresco.rest.model.RestRatingModel;
import org.alfresco.rest.model.RestTagModel;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.exception.DataPreparationException;
import org.alfresco.utility.model.*;
import org.alfresco.utility.report.Bug;
import org.alfresco.utility.testrail.ExecutionType;
import org.alfresco.utility.testrail.annotation.TestRail;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class AddRatingTests extends RestTest
{
private UserModel userModel;
private SiteModel siteModel;
private UserModel adminUser;
private ListUserWithRoles usersWithRoles;
private RestRatingModel returnedRatingModel; // placeholder for returned model
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws DataPreparationException
{
userModel = dataUser.createRandomTestUser();
adminUser = dataUser.getAdminUser();
siteModel = dataSite.usingUser(userModel).createPublicRandomSite();
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer,
UserRole.SiteContributor);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.SANITY, description = "Verify user with Manager role is able to post like rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void managerIsAbleToLikeDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(document)
.likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify user with Collaborator role is able to post like rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void collaboratorIsAbleToLikeDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(document)
.likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify user with Contributor role is able to post like rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void contributorIsAbleToLikeDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI().usingResource(document)
.likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify user with Consumer role is able to post like rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void consumerIsAbleToLikeDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingResource(document)
.likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify admin user is able to post like rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void adminIsAbleToLikeDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.SANITY, description = "Verify unauthenticated user is not able to post like rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
// @Bug(id="MNT-16904", description = "It fails only on environment with tenants")
public void unauthenticatedUserIsNotAbleToLikeDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(new UserModel("random user", "random password")).withCoreAPI().usingResource(document).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError()
.containsSummary(RestErrorModel.AUTHENTICATION_FAILED);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.SANITY, description = "Verify user with Manager role is able to post stars rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void managerIsAbleToAddStarsToDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(document)
.rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify user with Collaborator role is able to post stars rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void collaboratorIsAbleToAddStarsToDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(document)
.rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify user with Contributor role is able to post stars rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void contributorIsAbleToAddStarsToDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI().usingResource(document)
.rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify user with Consumer role is able to post stars rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void consumerIsAbleToAddStarsToDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingResource(document)
.rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.REGRESSION },
executionType = ExecutionType.SANITY, description = "Verify admin user is able to post stars rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void adminIsAbleToAddStarsToDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).rateStarsToDocument(3);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("3").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.SANITY, description = "Verify unauthenticated user is not able to post stars rating to a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
// @Bug(id="MNT-16904", description = "fails only on environment with tenants")
public void unauthenticatedUserIsNotAbleToRateStarsToDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(new UserModel("random user", "random password")).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError()
.containsSummary(RestErrorModel.AUTHENTICATION_FAILED);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify that if unknown rating scheme is provided status code is 400")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void unknownRatingSchemeReturnsBadRequest() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"invalidRate\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(String.format(RestErrorModel.INVALID_RATING, "invalidRate"))
.containsErrorKey(String.format(RestErrorModel.INVALID_RATING, "invalidRate"))
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify that if nodeId does not exist status code 404 is returned")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void invalidNodeIdReturnsNotFound() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
document.setNodeRef(RandomStringUtils.randomAlphanumeric(10));
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND)
.assertLastError()
.containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, document.getNodeRef()))
.containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify that if nodeId provided cannot be rated 405 status code is returned")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void likeResourceThatCannotBeRated() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
LinkModel link = dataLink.usingAdmin().usingSite(siteModel).createRandomLink();
document.setNodeRef(link.getNodeRef().replace("workspace://SpacesStore/", "workspace%3A%2F%2FSpacesStore%2F"));
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND)
.assertLastError()
.containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, document.getNodeRef()))
.containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.SANITY, description = "Verify that manager is able to like a folder")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void managerIsAbleToLikeAFolder() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(folderModel)
.likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.SANITY, description = "Verify that manager is able to like a site")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void managerIsAbleToLikeASite() throws Exception
{
FolderModel folderModel = new FolderModel();
folderModel.setNodeRef(siteModel.getGuid());
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(folderModel)
.likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
restClient.withCoreAPI().usingResource(folderModel).getRatings()
.assertNodeIsLiked();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.SANITY, description = "Verify that manager is able to rate a folder")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void managerIsAbleToRateAFolder() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(folderModel)
.rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.SANITY },
executionType = ExecutionType.REGRESSION, description = "Verify that manager is able to rate a site")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void managerIsAbleToRateASite() throws Exception
{
FolderModel folderModel = new FolderModel();
folderModel.setNodeRef(siteModel.getGuid());
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(folderModel)
.rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
restClient.withCoreAPI().usingResource(folderModel).getRatings()
.assertNodeHasFiveStarRating();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify that adding like again has no effect on a file")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void fileCanBeLikedTwice() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify that adding rate again has no effect on a file")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void fileCanBeRatedTwice() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify that rate is not added if empty rating object is provided")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void addRateUsingEmptyRatingObject() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError()
.containsSummary(String.format(RestErrorModel.NO_CONTENT, "No content to map to Object due to end of input"));
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify that if empty rate id is provided status code is 400")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void addRateUsingEmptyValueForId() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError()
.containsSummary(String.format(RestErrorModel.NO_CONTENT, "N/A (through reference chain: org.alfresco.rest.api.model.NodeRating[\"id\"])"));
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify that if empty rating is provided status code is 400")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void addRateUsingEmptyValueForMyRating() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"likes\", \"myRating\":\"\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.NULL_LIKE_RATING));
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"fiveStar\", \"myRating\":\"\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.NULL_FIVESTAR_RATING));
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify that user is not able to rate a comment")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void addRatingToAComment() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
RestCommentModel comment = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addComment("This is a comment");
document.setNodeRef(comment.getId());
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED)
.assertLastError()
.containsSummary(String.format(RestErrorModel.CANNOT_RATE))
.containsErrorKey(RestErrorModel.CANNOT_RATE)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError().containsSummary(String.format(RestErrorModel.CANNOT_RATE));
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify that user is not able to rate a tag")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void addRatingToATag() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
RestTagModel tag = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addTag("randomTag");
document.setNodeRef(tag.getId());
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError().containsSummary(String.format(RestErrorModel.CANNOT_RATE));
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError().containsSummary(String.format(RestErrorModel.CANNOT_RATE));
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that Contributor is able to like a folder")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void contributorIsAbleToLikeAFolder() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI()
.usingResource(folderModel)
.likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true")
.and().field("id").is("likes")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that Collaborator is able to like a folder")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void collaboratorIsAbleToLikeAFolder() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI()
.usingResource(folderModel)
.likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true")
.and().field("id").is("likes")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that Consumer is able to like a folder")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void consumerIsAbleToLikeAFolder() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI()
.usingResource(folderModel)
.likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true")
.and().field("id").is("likes")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that Contributor is able to rate a folder")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void contributorIsAbleToRateAFolder() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI()
.usingResource(folderModel)
.rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5")
.and().field("id").is("fiveStar")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that Collaborator is able to rate a folder")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void collaboratorIsAbleToRateAFolder() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI()
.usingResource(folderModel)
.rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5")
.and().field("id").is("fiveStar")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that Consumer is able to rate a folder")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void consumerIsAbleToRateAFolder() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI()
.usingResource(folderModel)
.rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5")
.and().field("id").is("fiveStar")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that adding like again has no effect on a folder")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void folderCanBeLikedTwice() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folderModel).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folderModel).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true")
.and().field("id").is("likes")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that adding rate again has no effect on a folder")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void folderCanBeRatedTwice() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folderModel).rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folderModel).rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5")
.and().field("id").is("fiveStar")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that if invalid rate id is provided status code is 400")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void addRateUsingInvalidValueForId() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"like\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(String.format(RestErrorModel.INVALID_RATING, "like"))
.containsErrorKey(String.format(RestErrorModel.INVALID_RATING, "like"))
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that rate id is case sensitive is provided status code is 400")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void addRateUsingInvalidValueForIdCaseSensitive() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"Likes\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(String.format(RestErrorModel.INVALID_RATING, "Likes"))
.containsErrorKey(String.format(RestErrorModel.INVALID_RATING, "Likes"))
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"FiveStar\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(String.format(RestErrorModel.INVALID_RATING, "FiveStar"))
.containsErrorKey(String.format(RestErrorModel.INVALID_RATING, "FiveStar"))
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that if invalid rating is provided status code is 400")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void addRateUsingInvalidValueForMyRating() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"likes\", \"myRating\":\"skiped\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(String.format(RestErrorModel.NULL_LIKE_RATING));
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"fiveStar\", \"myRating\":\"string\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(String.format(RestErrorModel.NULL_FIVESTAR_RATING));
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Like file created by a different user")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void addLikeToAnotherUserFile() throws Exception
{
UserModel user = dataUser.usingAdmin().createRandomTestUser();
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(user).withCoreAPI().usingResource(document).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true")
.and().field("id").is("likes")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Rate a file created by a different user")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void addRatingToAnotherUserFile() throws Exception
{
UserModel user = dataUser.usingAdmin().createRandomTestUser();
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(user).withCoreAPI().usingResource(document).rateStarsToDocument(5);
returnedRatingModel.assertThat().field("myRating").is("5")
.and().field("id").is("fiveStar")
.and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Add Rate Using Boolean Value For 'myRating'")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void addRateUsingBooleanValueForMyRating() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"fiveStar\", \"myRating\":\"true\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(RestErrorModel.NULL_FIVESTAR_RATING)
.containsErrorKey(RestErrorModel.NULL_FIVESTAR_RATING)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Add Like Using Integer Value For 'myRating'")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void addLikeUsingIntegerValueForMyRating() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"likes\", \"myRating\":\"2\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(RestErrorModel.NULL_LIKE_RATING)
.containsErrorKey(RestErrorModel.NULL_LIKE_RATING)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that user is not able to like his own comment")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void userCannotLikeHisOwnComment() throws Exception
{
UserModel user = usersWithRoles.getOneUserWithRole(UserRole.SiteManager);
FolderModel folderModel = dataContent.usingUser(user).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(user).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
RestCommentModel comment = restClient.authenticateUser(user).withCoreAPI().usingResource(document).addComment("This is a comment");
document.setNodeRef(comment.getId());
returnedRatingModel = restClient.authenticateUser(user).withCoreAPI().usingResource(document).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED)
.assertLastError()
.containsSummary(String.format(RestErrorModel.CANNOT_RATE))
.containsErrorKey(RestErrorModel.CANNOT_RATE)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER).stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that user is not able to rate his own comment")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void userCannotRateHisOwnComment() throws Exception
{
UserModel user = usersWithRoles.getOneUserWithRole(UserRole.SiteManager);
FolderModel folderModel = dataContent.usingUser(user).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(user).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
RestCommentModel comment = restClient.authenticateUser(user).withCoreAPI().usingResource(document).addComment("This is a comment");
document.setNodeRef(comment.getId());
returnedRatingModel = restClient.authenticateUser(user).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED)
.assertLastError()
.containsSummary(String.format(RestErrorModel.CANNOT_RATE))
.containsErrorKey(RestErrorModel.CANNOT_RATE)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that Collaborator is NOT able to add a negative rating to a file")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void collaboratorIsNotAbleToAddANegativeRatingToAFile() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI()
.usingResource(document)
.rateStarsToDocument(-5);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(RestErrorModel.RATING_OUT_OF_BOUNDS)
.containsErrorKey(RestErrorModel.RATING_OUT_OF_BOUNDS)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that Collaborator is NOT able to add a high rating to a file")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void collaboratorIsNotAbleToAddAHighRatingToAFile() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
returnedRatingModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI()
.usingResource(document)
.rateStarsToDocument(10);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(RestErrorModel.RATING_OUT_OF_BOUNDS)
.containsErrorKey(RestErrorModel.RATING_OUT_OF_BOUNDS)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
// @Bug(id = "MNT-17375", description = "Won't Fix, the error message is not ideal and a little cryptic but it does provide the reason i.e. ratingSchemeId is null.")
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Do not provide field - 'id'")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void notProvideIdLikeFile() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"myRating\":\"true\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(String.format(RestErrorModel.INVALID_RATING, "null"))
.containsErrorKey(String.format(RestErrorModel.INVALID_RATING, "null"))
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Do not provide field - 'myRating'")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void notProvideMyRatingRateFile() throws Exception
{
FolderModel folderModel = dataContent.usingUser(userModel).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).addInvalidRating("{\"id\":\"likes\"}");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(RestErrorModel.NULL_LIKE_RATING)
.containsErrorKey(RestErrorModel.NULL_LIKE_RATING)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
}
@@ -1,149 +0,0 @@
package org.alfresco.rest.ratings;
import org.alfresco.dataprep.CMISUtil.DocumentType;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestErrorModel;
import org.alfresco.rest.model.RestRatingModel;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.exception.DataPreparationException;
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.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 DeleteRatingCoreTests extends RestTest
{
private SiteModel siteModel;
private UserModel adminUser;
private ListUserWithRoles usersWithRoles;
private RestRatingModel returnedRatingModel;
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws DataPreparationException
{
adminUser = dataUser.getAdminUser();
siteModel = dataSite.usingUser(adminUser).createPublicRandomSite();
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer,
UserRole.SiteContributor);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify that if ratingId provided is unknown status code returned is 400")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void deleteInvalidRating() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).deleteInvalidRating("random_rating");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(String.format(RestErrorModel.INVALID_RATING, "random_rating"))
.containsErrorKey(String.format(RestErrorModel.INVALID_RATING, "random_rating"))
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify that if nodeId does not exist status code returned is 404")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void deleteRatingUsingInvalidDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
document.setNodeRef("random_value");
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "random_value"));
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Delete rating stars for a document that was not rated")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
@Bug(id = "MNT-17181")
public void deleteStarsForANotRatedDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Delete like rating for a document that was not liked")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
@Bug(id = "MNT-17181")
public void deleteLikeForANotLikedDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Delete like for a file then add it again")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void likeDocumentAfterLikeRatingIsDeleted() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
returnedRatingModel = restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Delete stars for a file then add them again")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void addStarsToDocumentAfterRatingIsDeleted() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
returnedRatingModel = restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify site manager is not able to remove rating added by another user")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
@Bug(id = "ACE-5459")
public void deleteDocumentRatingUsingManager() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
restClient.withCoreAPI().usingResource(document).getRatings()
.assertNodeIsLiked()
.assertNodeHasFiveStarRating();
}
}
@@ -1,241 +0,0 @@
package org.alfresco.rest.ratings;
import org.alfresco.dataprep.CMISUtil.DocumentType;
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.constants.UserRole;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.exception.DataPreparationException;
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.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 Claudia Agache on 1/25/2017.
*/
public class DeleteRatingFullTests extends RestTest
{
private SiteModel siteModel;
private UserModel adminUser;
private DataUser.ListUserWithRoles usersWithRoles;
private RestRatingModelsCollection returnedRatingModelCollection;
private RestRatingModel returnedRatingModel;
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws DataPreparationException
{
adminUser = dataUser.getAdminUser();
siteModel = dataSite.usingUser(adminUser).createPublicRandomSite();
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer,
UserRole.SiteContributor);
}
@TestRail(section = { TestGroup.REST_API,TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify site contributor is not able to remove rating added by another user")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
@Bug(id = "ACE-5459")
public void contributorIsNotAbleToDeleteRatingsOfAnotherUser() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
restClient.withCoreAPI().usingResource(document).getRatings()
.assertNodeIsLiked()
.assertNodeHasFiveStarRating();
}
@TestRail(section = { TestGroup.REST_API,TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify site collaborator is not able to remove rating added by another user")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
@Bug(id = "ACE-5459")
public void collaboratorIsNotAbleToDeleteRatingsOfAnotherUser() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
restClient.withCoreAPI().usingResource(document).getRatings()
.assertNodeIsLiked()
.assertNodeHasFiveStarRating();
}
@TestRail(section = { TestGroup.REST_API,TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify site consumer is not able to remove rating added by another user")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
@Bug(id = "ACE-5459")
public void consumerIsNotAbleToDeleteRatingsOfAnotherUser() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
restClient.withCoreAPI().usingResource(document).getRatings()
.assertNodeIsLiked()
.assertNodeHasFiveStarRating();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Delete rating stars twice")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
@Bug(id = "MNT-17181")
public void deleteStarsTwice() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager))
.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedRatingModelCollection.assertNodeHasNoFiveStarRating();
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Delete like rating twice")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
@Bug(id = "MNT-17181")
public void deleteLikeTwice() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedRatingModelCollection.assertNodeIsNotLiked();
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Delete like for a folder then add it again")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void likeFolderAfterLikeRatingIsDeleted() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folderModel).likeDocument();
restClient.withCoreAPI().usingResource(folderModel).deleteLikeRating();
returnedRatingModel = restClient.withCoreAPI().usingResource(folderModel).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Delete stars for a folder then add them again")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void addStarsToFolderAfterRatingIsDeleted() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(folderModel).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(folderModel).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
returnedRatingModel = restClient.withCoreAPI().usingResource(folderModel).rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Delete like for a site then add it again")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void likeSiteAfterLikeRatingIsDeleted() throws Exception
{
FolderModel folderModel = new FolderModel();
folderModel.setNodeRef(siteModel.getGuid());
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folderModel).likeDocument();
restClient.withCoreAPI().usingResource(folderModel).deleteLikeRating();
returnedRatingModel = restClient.withCoreAPI().usingResource(folderModel).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Delete stars for a site then add them again")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void addStarsToSiteAfterRatingIsDeleted() throws Exception
{
FolderModel folderModel = new FolderModel();
folderModel.setNodeRef(siteModel.getGuid());
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(folderModel).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(folderModel).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
returnedRatingModel = restClient.withCoreAPI().usingResource(folderModel).rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify user with Manager role is able to remove one star rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void removeOneStarRating() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(1);
restClient.withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedRatingModelCollection.assertNodeIsNotLiked().assertNodeHasNoFiveStarRating().and().entriesListIsNotEmpty().and().paginationExist();
}
}
@@ -1,215 +0,0 @@
package org.alfresco.rest.ratings;
import org.alfresco.dataprep.CMISUtil.DocumentType;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestErrorModel;
import org.alfresco.rest.model.RestRatingModelsCollection;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.exception.DataPreparationException;
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.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 DeleteRatingSanityTests extends RestTest
{
private SiteModel siteModel;
private UserModel adminUser;
private ListUserWithRoles usersWithRoles;
private RestRatingModelsCollection returnedRatingModelCollection;
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws DataPreparationException
{
adminUser = dataUser.getAdminUser();
siteModel = dataSite.usingUser(adminUser).createPublicRandomSite();
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer,
UserRole.SiteContributor);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify user with Manager role is able to remove its own rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void managerIsAbleToDeleteItsOwnRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
restClient.withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedRatingModelCollection.assertNodeIsNotLiked().assertNodeHasNoFiveStarRating().and().entriesListIsNotEmpty().and().paginationExist();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify user with Collaborator role is able to remove its own rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void collaboratorIsAbleToDeleteItsOwnRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
restClient.withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedRatingModelCollection.assertNodeIsNotLiked().assertNodeHasNoFiveStarRating().and().entriesListIsNotEmpty().and().paginationExist();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify user with Contributor role is able to remove its own rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void contributorIsAbleToDeleteItsOwnRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
restClient.withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedRatingModelCollection.assertNodeIsNotLiked().assertNodeHasNoFiveStarRating().and().entriesListIsNotEmpty().and().paginationExist();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify user with Consumer role is able to remove its own rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void consumerIsAbleToDeleteItsOwnRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
restClient.withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedRatingModelCollection.assertNodeIsNotLiked().assertNodeHasNoFiveStarRating().and().entriesListIsNotEmpty().and().paginationExist();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify admin user is able to remove its own rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void adminIsAbleToDeleteItsOwnRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
document = dataContent.usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).usingResource(folderModel)
.createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser);
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
restClient.withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedRatingModelCollection.assertNodeIsNotLiked().assertNodeHasNoFiveStarRating().and().entriesListIsNotEmpty().and().paginationExist();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify unauthenticated user is not able to remove its own rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
@Bug(id="MNT-16904", description = "It fails only on environment with tenants")
public void unauthenticatedUserIsNotAbleToDeleteRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
document = dataContent.usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).usingResource(folderModel)
.createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser);
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.authenticateUser(new UserModel("random user", "random password"));
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError()
.containsSummary(RestErrorModel.AUTHENTICATION_FAILED);
restClient.withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError()
.containsSummary(RestErrorModel.AUTHENTICATION_FAILED);
}
@TestRail(section = { TestGroup.REST_API,TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify one user is not able to remove rating added by another user")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
@Bug(id = "ACE-5459")
public void oneUserIsNotAbleToDeleteRatingsOfAnotherUser() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
UserModel userA = dataUser.createRandomTestUser();
UserModel userB = dataUser.createRandomTestUser();
restClient.authenticateUser(userA);
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.authenticateUser(userB);
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
restClient.withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
restClient.withCoreAPI().usingResource(document).getRatings()
.assertNodeIsLiked()
.assertNodeHasFiveStarRating();
}
}
@@ -0,0 +1,525 @@
package org.alfresco.rest.ratings;
import org.alfresco.dataprep.CMISUtil.DocumentType;
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.constants.UserRole;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.exception.DataPreparationException;
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.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 DeleteRatingTests extends RestTest
{
private SiteModel siteModel;
private UserModel adminUser;
private ListUserWithRoles usersWithRoles;
private RestRatingModelsCollection returnedRatingModelCollection;
private RestRatingModel returnedRatingModel;
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws DataPreparationException
{
adminUser = dataUser.getAdminUser();
siteModel = dataSite.usingUser(adminUser).createPublicRandomSite();
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer,
UserRole.SiteContributor);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.SANITY, description = "Verify user with Manager role is able to remove its own rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void managerIsAbleToDeleteItsOwnRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
restClient.withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedRatingModelCollection.assertNodeIsNotLiked().assertNodeHasNoFiveStarRating().and().entriesListIsNotEmpty().and().paginationExist();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify user with Collaborator role is able to remove its own rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void collaboratorIsAbleToDeleteItsOwnRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
restClient.withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedRatingModelCollection.assertNodeIsNotLiked().assertNodeHasNoFiveStarRating().and().entriesListIsNotEmpty().and().paginationExist();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify user with Contributor role is able to remove its own rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void contributorIsAbleToDeleteItsOwnRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
restClient.withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedRatingModelCollection.assertNodeIsNotLiked().assertNodeHasNoFiveStarRating().and().entriesListIsNotEmpty().and().paginationExist();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify user with Consumer role is able to remove its own rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void consumerIsAbleToDeleteItsOwnRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
restClient.withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedRatingModelCollection.assertNodeIsNotLiked().assertNodeHasNoFiveStarRating().and().entriesListIsNotEmpty().and().paginationExist();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify admin user is able to remove its own rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void adminIsAbleToDeleteItsOwnRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
document = dataContent.usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).usingResource(folderModel)
.createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser);
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
restClient.withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedRatingModelCollection.assertNodeIsNotLiked().assertNodeHasNoFiveStarRating().and().entriesListIsNotEmpty().and().paginationExist();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.SANITY, description = "Verify unauthenticated user is not able to remove its own rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
// @Bug(id="MNT-16904", description = "It fails only on environment with tenants")
public void unauthenticatedUserIsNotAbleToDeleteRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
document = dataContent.usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).usingResource(folderModel)
.createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser);
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.authenticateUser(new UserModel("random user", "random password"));
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError()
.containsSummary(RestErrorModel.AUTHENTICATION_FAILED);
restClient.withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError()
.containsSummary(RestErrorModel.AUTHENTICATION_FAILED);
}
@TestRail(section = { TestGroup.REST_API,TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Verify one user is not able to remove rating added by another user")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
@Bug(id = "ACE-5459")
public void oneUserIsNotAbleToDeleteRatingsOfAnotherUser() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
UserModel userA = dataUser.createRandomTestUser();
UserModel userB = dataUser.createRandomTestUser();
restClient.authenticateUser(userA);
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.authenticateUser(userB);
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
restClient.withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
restClient.withCoreAPI().usingResource(document).getRatings()
.assertNodeIsLiked()
.assertNodeHasFiveStarRating();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify that if ratingId provided is unknown status code returned is 400")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void deleteInvalidRating() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).deleteInvalidRating("random_rating");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError()
.containsSummary(String.format(RestErrorModel.INVALID_RATING, "random_rating"))
.containsErrorKey(String.format(RestErrorModel.INVALID_RATING, "random_rating"))
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify that if nodeId does not exist status code returned is 404")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void deleteRatingUsingInvalidDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
document.setNodeRef("random_value");
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "random_value"));
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Delete rating stars for a document that was not rated")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
@Bug(id = "MNT-17181")
public void deleteStarsForANotRatedDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Delete like rating for a document that was not liked")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
@Bug(id = "MNT-17181")
public void deleteLikeForANotLikedDocument() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Delete like for a file then add it again")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void likeDocumentAfterLikeRatingIsDeleted() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
returnedRatingModel = restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Delete stars for a file then add them again")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void addStarsToDocumentAfterRatingIsDeleted() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
returnedRatingModel = restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify site manager is not able to remove rating added by another user")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
@Bug(id = "ACE-5459")
public void deleteDocumentRatingUsingManager() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
restClient.withCoreAPI().usingResource(document).getRatings()
.assertNodeIsLiked()
.assertNodeHasFiveStarRating();
}
@TestRail(section = { TestGroup.REST_API,TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify site contributor is not able to remove rating added by another user")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
@Bug(id = "ACE-5459")
public void contributorIsNotAbleToDeleteRatingsOfAnotherUser() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
restClient.withCoreAPI().usingResource(document).getRatings()
.assertNodeIsLiked()
.assertNodeHasFiveStarRating();
}
@TestRail(section = { TestGroup.REST_API,TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify site collaborator is not able to remove rating added by another user")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
@Bug(id = "ACE-5459")
public void collaboratorIsNotAbleToDeleteRatingsOfAnotherUser() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
restClient.withCoreAPI().usingResource(document).getRatings()
.assertNodeIsLiked()
.assertNodeHasFiveStarRating();
}
@TestRail(section = { TestGroup.REST_API,TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify site consumer is not able to remove rating added by another user")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
@Bug(id = "ACE-5459")
public void consumerIsNotAbleToDeleteRatingsOfAnotherUser() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
restClient.withCoreAPI().usingResource(document).getRatings()
.assertNodeIsLiked()
.assertNodeHasFiveStarRating();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Delete rating stars twice")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
@Bug(id = "MNT-17181")
public void deleteStarsTwice() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager))
.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedRatingModelCollection.assertNodeHasNoFiveStarRating();
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Delete like rating twice")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
@Bug(id = "MNT-17181")
public void deleteLikeTwice() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedRatingModelCollection.assertNodeIsNotLiked();
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).deleteLikeRating();
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Delete like for a folder then add it again")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void likeFolderAfterLikeRatingIsDeleted() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folderModel).likeDocument();
restClient.withCoreAPI().usingResource(folderModel).deleteLikeRating();
returnedRatingModel = restClient.withCoreAPI().usingResource(folderModel).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Delete stars for a folder then add them again")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void addStarsToFolderAfterRatingIsDeleted() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(folderModel).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(folderModel).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
returnedRatingModel = restClient.withCoreAPI().usingResource(folderModel).rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Delete like for a site then add it again")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void likeSiteAfterLikeRatingIsDeleted() throws Exception
{
FolderModel folderModel = new FolderModel();
folderModel.setNodeRef(siteModel.getGuid());
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folderModel).likeDocument();
restClient.withCoreAPI().usingResource(folderModel).deleteLikeRating();
returnedRatingModel = restClient.withCoreAPI().usingResource(folderModel).likeDocument();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("true").and().field("id").is("likes").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Delete stars for a site then add them again")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void addStarsToSiteAfterRatingIsDeleted() throws Exception
{
FolderModel folderModel = new FolderModel();
folderModel.setNodeRef(siteModel.getGuid());
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)).withCoreAPI().usingResource(folderModel).rateStarsToDocument(5);
restClient.withCoreAPI().usingResource(folderModel).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
returnedRatingModel = restClient.withCoreAPI().usingResource(folderModel).rateStarsToDocument(5);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify user with Manager role is able to remove one star rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void removeOneStarRating() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(1);
restClient.withCoreAPI().usingResource(document).deleteFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
returnedRatingModelCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedRatingModelCollection.assertNodeIsNotLiked().assertNodeHasNoFiveStarRating().and().entriesListIsNotEmpty().and().paginationExist();
}
}
@@ -1,150 +0,0 @@
package org.alfresco.rest.ratings;
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.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.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
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();
}
@BeforeMethod(alwaysRun = true)
public void setUp() throws DataPreparationException, Exception
{
document = dataContent.usingSite(siteModel).usingAdmin().createContent(DocumentType.TEXT_PLAIN);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Check that using invalid ratingId for get rating call returns status code 400.")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
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(String.format(RestErrorModel.INVALID_RATING, "invalid ratingId"));
}
@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.")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void getRatingUsingInvalidNodeId() throws Exception
{
document.setNodeRef(RandomStringUtils.randomAlphanumeric(20));
returnedRatingModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).getFiveStarRating();
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 = "Get rating of a file that has only likes.")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void getRatingOfFileThatHasOnlyLikes() throws Exception
{
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");
returnedRatingModel.getAggregate().assertThat().field("numberOfRatings").is("1");
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 stars.")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void getRatingOfFileThatHasOnlyStars() throws Exception
{
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).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.")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void getRatingOfFileThatHasLikesAndStars() throws Exception
{
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");
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();
returnedRatingModel.getAggregate().assertThat().field("numberOfRatings").is("1");
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Get rating of a folder that has only likes.")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
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");
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.")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void getRatingOfFileThatHasNoRatings() throws Exception
{
returnedRatingModel = restClient.authenticateUser(adminUserModel).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);
returnedRatingModel.getAggregate().assertThat().field("numberOfRatings").is("0");
}
}
@@ -1,199 +0,0 @@
package org.alfresco.rest.ratings;
import org.alfresco.dataprep.CMISUtil.DocumentType;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestErrorModel;
import org.alfresco.rest.model.RestRatingModel;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.exception.DataPreparationException;
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.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class GetRatingFullTests extends RestTest
{
private SiteModel siteModel;
private UserModel adminUserModel, userModel;
private RestRatingModel returnedRatingModel;
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws DataPreparationException
{
adminUserModel = dataUser.getAdminUser();
userModel = dataUser.createRandomTestUser();
siteModel = dataSite.usingAdmin().createPublicRandomSite();
dataUser.addUserToSite(userModel, siteModel, UserRole.SiteManager);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Check default error schema")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void checkDefaultErrorSchema() throws Exception
{
FileModel document = dataContent.usingSite(siteModel).usingAdmin().createContent(DocumentType.TEXT_PLAIN);
String randomNodeRef = RandomStringUtils.randomAlphanumeric(10);
document.setNodeRef(randomNodeRef);
restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).getLikeRating();
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError()
.containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY)
.containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, randomNodeRef))
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Get rating of a folder that has only stars")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void getRatingOfFolderThatHasOnlyStars() throws Exception
{
FolderModel folder = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder();
restClient.authenticateUser(userModel).withCoreAPI().usingResource(folder).rateStarsToDocument(3);
returnedRatingModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(folder).getFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedRatingModel.assertThat().field("id").is("fiveStar")
.getAggregate().assertThat().field("numberOfRatings").is("1")
.assertThat().field("average").is("3.0");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Get rating of a folder that has both likes and stars")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void getRatingOfFolderThatHasLikedAndStars() throws Exception
{
FolderModel folder = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder();
restClient.authenticateUser(userModel).withCoreAPI().usingResource(folder).rateStarsToDocument(3);
restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(folder).likeDocument();
returnedRatingModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(folder).getFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedRatingModel.assertThat().field("id").is("fiveStar")
.getAggregate().assertThat().field("numberOfRatings").is("1")
.assertThat().field("average").is("3.0");
returnedRatingModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(folder).getLikeRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedRatingModel.assertThat().field("id").is("likes")
.assertThat().field("myRating").is("true");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Get rating of a folder that has no ratings")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void getRatingOfFolderThatHasNoRatings() throws Exception
{
FolderModel folder = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder();
returnedRatingModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(folder).getFiveStarRating();
returnedRatingModel.getAggregate().assertThat().field("numberOfRatings").is("0");
returnedRatingModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(folder).getLikeRating();
returnedRatingModel.getAggregate().assertThat().field("numberOfRatings").is("0");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Get rating of a folder after rating was deleted")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void getDeletedRatingOfAFolder() throws Exception
{
FolderModel folder = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder();
restClient.authenticateUser(userModel).withCoreAPI().usingResource(folder).rateStarsToDocument(3);
restClient.authenticateUser(userModel).withCoreAPI().usingResource(folder).deleteFiveStarRating();
restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(folder).likeDocument();
restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(folder).deleteLikeRating();
returnedRatingModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(folder).getFiveStarRating();
returnedRatingModel.assertThat().field("id").is("fiveStar").getAggregate().assertThat().field("numberOfRatings").is("0")
.assertThat().field("average").isNull();
returnedRatingModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(folder).getLikeRating();
returnedRatingModel.assertThat().field("id").is("likes").assertThat().field("myRating").isNull()
.getAggregate().assertThat().field("numberOfRatings").is("0");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Get rating of a file after rating was deleted")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void getDeletedRatingOfAFile() throws Exception
{
FileModel file = dataContent.usingUser(adminUserModel).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(userModel).withCoreAPI().usingResource(file).rateStarsToDocument(3);
restClient.authenticateUser(userModel).withCoreAPI().usingResource(file).deleteFiveStarRating();
restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).likeDocument();
restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).deleteLikeRating();
returnedRatingModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getFiveStarRating();
returnedRatingModel.assertThat().field("id").is("fiveStar").getAggregate().assertThat().field("numberOfRatings").is("0")
.assertThat().field("average").isNull();
returnedRatingModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getLikeRating();
returnedRatingModel.assertThat().field("id").is("likes").assertThat().field("myRating").isNull()
.getAggregate().assertThat().field("numberOfRatings").is("0");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Get rating of another user as admin")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void getRatingOfAnotherUserAsAdmin() throws Exception
{
FileModel file = dataContent.usingUser(adminUserModel).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(userModel).withCoreAPI().usingResource(file).rateStarsToDocument(3);
restClient.authenticateUser(userModel).withCoreAPI().usingResource(file).likeDocument();
returnedRatingModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getFiveStarRating();
returnedRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").isNull()
.getAggregate().assertThat().field("numberOfRatings").is("1").assertThat().field("average").is("3.0");
returnedRatingModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).getLikeRating();
returnedRatingModel.assertThat().field("id").is("likes").assertThat().field("myRating").isNull()
.getAggregate().assertThat().field("numberOfRatings").is("1");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Get rating of admin with another user")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void getRatingOfAdminWithAnotherUser() throws Exception
{
FileModel file = dataContent.usingUser(userModel).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).rateStarsToDocument(3);
restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).likeDocument();
returnedRatingModel = restClient.authenticateUser(userModel).withCoreAPI().usingResource(file).getFiveStarRating();
returnedRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").isNull()
.getAggregate().assertThat().field("numberOfRatings").is("1").assertThat().field("average").is("3.0");
returnedRatingModel = restClient.authenticateUser(userModel).withCoreAPI().usingResource(file).getLikeRating();
returnedRatingModel.assertThat().field("id").is("likes").assertThat().field("myRating").isNull()
.getAggregate().assertThat().field("numberOfRatings").is("1");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Get five star rating")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void getFiveStarRating() throws Exception
{
FileModel file = dataContent.usingUser(userModel).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).rateStarsToDocument(5);
returnedRatingModel = restClient.authenticateUser(userModel).withCoreAPI().usingResource(file).getFiveStarRating();
returnedRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").isNull()
.getAggregate().assertThat().field("numberOfRatings").is("1").assertThat().field("average").is("5.0");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Get one star rating")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.FULL })
public void getOneStarRating() throws Exception
{
FileModel file = dataContent.usingUser(userModel).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).rateStarsToDocument(1);
returnedRatingModel = restClient.authenticateUser(userModel).withCoreAPI().usingResource(file).getFiveStarRating();
returnedRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").isNull()
.getAggregate().assertThat().field("numberOfRatings").is("1").assertThat().field("average").is("1.0");
}
}
@@ -1,172 +0,0 @@
package org.alfresco.rest.ratings;
import org.alfresco.dataprep.CMISUtil.DocumentType;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestErrorModel;
import org.alfresco.rest.model.RestRatingModel;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.exception.DataPreparationException;
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.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 GetRatingSanityTests extends RestTest
{
private SiteModel siteModel;
private UserModel adminUser;
private ListUserWithRoles usersWithRoles;
private RestRatingModel restRatingModel;
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws DataPreparationException
{
adminUser = dataUser.getAdminUser();
siteModel = dataSite.usingUser(adminUser).createPublicRandomSite();
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer,
UserRole.SiteContributor);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify user with Manager role is able to retrieve rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void managerIsAbleToRetrieveRating() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true");
restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").is("5");
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify user with Collaborator role is able to retrieve rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void collaboratorIsAbleToRetrieveRating() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true");
restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").is("5");
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify user with Contributor role is able to retrieve rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void contributorIsAbleToRetrieveRating() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true");
restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").is("5");
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify user with Consumer role is able to retrieve rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void consumerIsAbleToRetrieveRating() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true");
restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").is("5");
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify admin user is able to retrieve rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void adminIsAbleToRetrieveRating() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
document = dataContent.usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingResource(folderModel)
.createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser);
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true");
restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").is("5");
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify unauthenticated user is not able to retrieve rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
@Bug(id = "MNT-16904", description = "It fails only on environment with tenants")
public void unauthenticatedUserIsNotAbleToRetrieveRating() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser);
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.authenticateUser(new UserModel("random user", "random password"));
restClient.withCoreAPI().usingResource(document).getLikeRating();
restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError().containsSummary(RestErrorModel.AUTHENTICATION_FAILED);
restClient.withCoreAPI().usingResource(document).getFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError().containsSummary(RestErrorModel.AUTHENTICATION_FAILED);
}
}
@@ -0,0 +1,438 @@
package org.alfresco.rest.ratings;
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.constants.UserRole;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.exception.DataPreparationException;
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.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class GetRatingTests extends RestTest
{
private SiteModel siteModel;
private UserModel adminUser, userModel, managerUser;
private FileModel document;
private ListUserWithRoles usersWithRoles;
private RestRatingModel restRatingModel;
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws DataPreparationException
{
adminUser = dataUser.getAdminUser();
userModel = dataUser.createRandomTestUser();
managerUser = dataUser.createRandomTestUser();
siteModel = dataSite.usingUser(adminUser).createPublicRandomSite();
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer,
UserRole.SiteContributor);
dataUser.addUserToSite(managerUser, siteModel, UserRole.SiteManager);
}
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
document = dataContent.usingSite(siteModel).usingAdmin().createContent(DocumentType.TEXT_PLAIN);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.SANITY, description = "Verify user with Manager role is able to retrieve rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void managerIsAbleToRetrieveRating() throws Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true");
restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").is("5");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify user with Collaborator role is able to retrieve rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void collaboratorIsAbleToRetrieveRating() throws Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true");
restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").is("5");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify user with Contributor role is able to retrieve rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void contributorIsAbleToRetrieveRating() throws Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true");
restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").is("5");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify user with Consumer role is able to retrieve rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void consumerIsAbleToRetrieveRating() throws Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true");
restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").is("5");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Verify admin user is able to retrieve rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void adminIsAbleToRetrieveRating() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingResource(folderModel)
.createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser);
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true");
restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").is("5");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.SANITY, description = "Verify unauthenticated user is not able to retrieve rating of a document")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
// @Bug(id = "MNT-16904", description = "It fails only on environment with tenants")
public void unauthenticatedUserIsNotAbleToRetrieveRating() throws Exception
{
restClient.authenticateUser(adminUser);
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.authenticateUser(new UserModel("random user", "random password"));
restClient.withCoreAPI().usingResource(document).getLikeRating();
restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError().containsSummary(RestErrorModel.AUTHENTICATION_FAILED);
restClient.withCoreAPI().usingResource(document).getFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError().containsSummary(RestErrorModel.AUTHENTICATION_FAILED);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Check that using invalid ratingId for get rating call returns status code 400.")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void checkInvalidRatingIdStatusCode() throws Exception
{
restClient.authenticateUser(adminUser).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(String.format(RestErrorModel.INVALID_RATING, "invalid ratingId"));
}
@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.")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void getRatingUsingInvalidNodeId() throws Exception
{
document.setNodeRef(RandomStringUtils.randomAlphanumeric(20));
restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).getFiveStarRating();
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 = "Get rating of a file that has only likes.")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void getRatingOfFileThatHasOnlyLikes() throws Exception
{
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).likeDocument();
restRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true");
restRatingModel.getAggregate().assertThat().field("numberOfRatings").is("1");
restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.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 stars.")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void getRatingOfFileThatHasOnlyStars() throws Exception
{
restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
restRatingModel.getAggregate().assertThat().field("numberOfRatings").is("1");
restRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.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.")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void getRatingOfFileThatHasLikesAndStars() throws Exception
{
restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).likeDocument();
restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).rateStarsToDocument(5);
restRatingModel = restClient.withCoreAPI().usingResource(document).getLikeRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true");
restRatingModel.getAggregate().assertThat().field("numberOfRatings").is("1");
restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("myRating").is("5").and().field("id").is("fiveStar").and().field("aggregate").isNotEmpty();
restRatingModel.getAggregate().assertThat().field("numberOfRatings").is("1");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Get rating of a folder that has only likes.")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void getRatingOfFolderThatHasOnlyLikes() throws Exception
{
FolderModel firstFolderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(firstFolderModel).likeDocument();
restRatingModel = restClient.withCoreAPI().usingResource(firstFolderModel).getLikeRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("likes").and().field("myRating").is("true");
restRatingModel.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.")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void getRatingOfFileThatHasNoRatings() throws Exception
{
restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).getLikeRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.getAggregate().assertThat().field("numberOfRatings").is("0");
restRatingModel = restClient.withCoreAPI().usingResource(document).getFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.getAggregate().assertThat().field("numberOfRatings").is("0");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Check default error schema")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void checkDefaultErrorSchema() throws Exception
{
FileModel document = dataContent.usingSite(siteModel).usingAdmin().createContent(DocumentType.TEXT_PLAIN);
String randomNodeRef = RandomStringUtils.randomAlphanumeric(10);
document.setNodeRef(randomNodeRef);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(document).getLikeRating();
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError()
.containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY)
.containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, randomNodeRef))
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Get rating of a folder that has only stars")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void getRatingOfFolderThatHasOnlyStars() throws Exception
{
FolderModel folder = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
restClient.authenticateUser(managerUser).withCoreAPI().usingResource(folder).rateStarsToDocument(3);
restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folder).getFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("fiveStar")
.getAggregate().assertThat().field("numberOfRatings").is("1")
.assertThat().field("average").is("3.0");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Get rating of a folder that has both likes and stars")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void getRatingOfFolderThatHasLikedAndStars() throws Exception
{
FolderModel folder = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
restClient.authenticateUser(managerUser).withCoreAPI().usingResource(folder).rateStarsToDocument(3);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folder).likeDocument();
restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folder).getFiveStarRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("fiveStar")
.getAggregate().assertThat().field("numberOfRatings").is("1")
.assertThat().field("average").is("3.0");
restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folder).getLikeRating();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModel.assertThat().field("id").is("likes")
.assertThat().field("myRating").is("true");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Get rating of a folder that has no ratings")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void getRatingOfFolderThatHasNoRatings() throws Exception
{
FolderModel folder = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folder).getFiveStarRating();
restRatingModel.getAggregate().assertThat().field("numberOfRatings").is("0");
restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folder).getLikeRating();
restRatingModel.getAggregate().assertThat().field("numberOfRatings").is("0");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Get rating of a folder after rating was deleted")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void getDeletedRatingOfAFolder() throws Exception
{
FolderModel folder = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
restClient.authenticateUser(managerUser).withCoreAPI().usingResource(folder).rateStarsToDocument(3);
restClient.authenticateUser(managerUser).withCoreAPI().usingResource(folder).deleteFiveStarRating();
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folder).likeDocument();
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folder).deleteLikeRating();
restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folder).getFiveStarRating();
restRatingModel.assertThat().field("id").is("fiveStar").getAggregate().assertThat().field("numberOfRatings").is("0")
.assertThat().field("average").isNull();
restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(folder).getLikeRating();
restRatingModel.assertThat().field("id").is("likes").assertThat().field("myRating").isNull()
.getAggregate().assertThat().field("numberOfRatings").is("0");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Get rating of a file after rating was deleted")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void getDeletedRatingOfAFile() throws Exception
{
FileModel file = dataContent.usingUser(adminUser).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(managerUser).withCoreAPI().usingResource(file).rateStarsToDocument(3);
restClient.authenticateUser(managerUser).withCoreAPI().usingResource(file).deleteFiveStarRating();
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).likeDocument();
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).deleteLikeRating();
restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).getFiveStarRating();
restRatingModel.assertThat().field("id").is("fiveStar").getAggregate().assertThat().field("numberOfRatings").is("0")
.assertThat().field("average").isNull();
restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).getLikeRating();
restRatingModel.assertThat().field("id").is("likes").assertThat().field("myRating").isNull()
.getAggregate().assertThat().field("numberOfRatings").is("0");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Get rating of another user as admin")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void getRatingOfAnotherUserAsAdmin() throws Exception
{
FileModel file = dataContent.usingUser(adminUser).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(managerUser).withCoreAPI().usingResource(file).rateStarsToDocument(3);
restClient.authenticateUser(managerUser).withCoreAPI().usingResource(file).likeDocument();
restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).getFiveStarRating();
restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").isNull()
.getAggregate().assertThat().field("numberOfRatings").is("1").assertThat().field("average").is("3.0");
restRatingModel = restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).getLikeRating();
restRatingModel.assertThat().field("id").is("likes").assertThat().field("myRating").isNull()
.getAggregate().assertThat().field("numberOfRatings").is("1");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION,
description = "Get rating of admin with another user")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void getRatingOfAdminWithAnotherUser() throws Exception
{
FileModel file = dataContent.usingUser(managerUser).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).rateStarsToDocument(3);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).likeDocument();
restRatingModel = restClient.authenticateUser(managerUser).withCoreAPI().usingResource(file).getFiveStarRating();
restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").isNull()
.getAggregate().assertThat().field("numberOfRatings").is("1").assertThat().field("average").is("3.0");
restRatingModel = restClient.authenticateUser(managerUser).withCoreAPI().usingResource(file).getLikeRating();
restRatingModel.assertThat().field("id").is("likes").assertThat().field("myRating").isNull()
.getAggregate().assertThat().field("numberOfRatings").is("1");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Get five star rating")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void getFiveStarRating() throws Exception
{
FileModel file = dataContent.usingUser(managerUser).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).rateStarsToDocument(5);
restRatingModel = restClient.authenticateUser(managerUser).withCoreAPI().usingResource(file).getFiveStarRating();
restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").isNull()
.getAggregate().assertThat().field("numberOfRatings").is("1").assertThat().field("average").is("5.0");
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS }, executionType = ExecutionType.REGRESSION, description = "Get one star rating")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void getOneStarRating() throws Exception
{
FileModel file = dataContent.usingUser(managerUser).usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser).withCoreAPI().usingResource(file).rateStarsToDocument(1);
restRatingModel = restClient.authenticateUser(managerUser).withCoreAPI().usingResource(file).getFiveStarRating();
restRatingModel.assertThat().field("id").is("fiveStar").and().field("myRating").isNull()
.getAggregate().assertThat().field("numberOfRatings").is("1").assertThat().field("average").is("1.0");
}
}
@@ -1,105 +0,0 @@
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.testrail.ExecutionType;
import org.alfresco.utility.testrail.annotation.TestRail;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class GetRatingsCoreTests 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 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).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")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void checkInvalidSkipCountStatusCode() throws Exception
{
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")
@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));
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")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void checkRatingValueIsTrueForLikedDoc() throws Exception
{
ratingsModel = restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
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")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.CORE })
public void checkRatingValueIsIntegerForStarsRating() throws Exception
{
ratingsModel = restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
ratingsModel.assertThat().entriesListContains("myRating", "5")
.assertThat().entriesListContains("id", "fiveStar");
}
}
@@ -1,116 +0,0 @@
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("count").is("1").and().field("maxItems").is("1");
}
@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);
}
}
@@ -1,150 +0,0 @@
package org.alfresco.rest.ratings;
import org.alfresco.dataprep.CMISUtil.DocumentType;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestErrorModel;
import org.alfresco.rest.model.RestRatingModelsCollection;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.exception.DataPreparationException;
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.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 GetRatingsSanityTests extends RestTest
{
private SiteModel siteModel;
private UserModel adminUser;
private ListUserWithRoles usersWithRoles;
private RestRatingModelsCollection restRatingModelsCollection;
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws DataPreparationException
{
adminUser = dataUser.getAdminUser();
siteModel = dataSite.usingUser(adminUser).createPublicRandomSite();
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer,
UserRole.SiteContributor);
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Manager is able to retrieve document ratings")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void managerIsAbleToRetrieveDocumentRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restRatingModelsCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModelsCollection.assertNodeHasFiveStarRating().assertNodeIsLiked();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Collaborator is able to retrieve document ratings")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void collaboratorIsAbleToRetrieveDocumentRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restRatingModelsCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModelsCollection.assertNodeHasFiveStarRating().assertNodeIsLiked();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Contributor is able to retrieve document ratings")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void contributorIsAbleToRetrieveDocumentRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restRatingModelsCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModelsCollection.assertNodeHasFiveStarRating().assertNodeIsLiked();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Consumer is able to retrieve document ratings")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void consumerIsAbleToRetrieveDocumentRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restRatingModelsCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModelsCollection.assertNodeHasFiveStarRating().assertNodeIsLiked();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Admin user is able to retrieve document ratings")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void adminIsAbleToRetrieveDocumentRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
document = dataContent.usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingResource(folderModel)
.createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser);
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restRatingModelsCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModelsCollection.assertNodeHasFiveStarRating().assertNodeIsLiked();
}
@TestRail(section = { TestGroup.REST_API,
TestGroup.RATINGS }, executionType = ExecutionType.SANITY, description = "Verify unauthenticated user is not able to retrieve document ratings")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
@Bug(id="MNT-16904", description = "It fails only on environment with tenants")
public void unauthenticatedUserIsNotAbleToRetrieveRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
FileModel document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser);
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.authenticateUser(new UserModel("random user", "random password"));
restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError()
.containsSummary(RestErrorModel.AUTHENTICATION_FAILED);
}
}
@@ -0,0 +1,313 @@
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.model.RestErrorModel;
import org.alfresco.rest.model.RestRatingModelsCollection;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.exception.DataPreparationException;
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.report.Bug;
import org.alfresco.utility.testrail.ExecutionType;
import org.alfresco.utility.testrail.annotation.TestRail;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class GetRatingsTests extends RestTest
{
private SiteModel siteModel;
private UserModel adminUser, userModel;
private ListUserWithRoles usersWithRoles;
private RestRatingModelsCollection restRatingModelsCollection;
private FileModel document;
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws DataPreparationException
{
adminUser = dataUser.getAdminUser();
userModel = dataUser.createRandomTestUser();
siteModel = dataSite.usingUser(adminUser).createPublicRandomSite();
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer,
UserRole.SiteContributor);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.SANITY, description = "Manager is able to retrieve document ratings")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
public void managerIsAbleToRetrieveDocumentRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restRatingModelsCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModelsCollection.assertNodeHasFiveStarRating().assertNodeIsLiked();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Collaborator is able to retrieve document ratings")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void collaboratorIsAbleToRetrieveDocumentRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restRatingModelsCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModelsCollection.assertNodeHasFiveStarRating().assertNodeIsLiked();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Contributor is able to retrieve document ratings")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void contributorIsAbleToRetrieveDocumentRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restRatingModelsCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModelsCollection.assertNodeHasFiveStarRating().assertNodeIsLiked();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Consumer is able to retrieve document ratings")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void consumerIsAbleToRetrieveDocumentRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer));
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restRatingModelsCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModelsCollection.assertNodeHasFiveStarRating().assertNodeIsLiked();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.REGRESSION, description = "Admin user is able to retrieve document ratings")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void adminIsAbleToRetrieveDocumentRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
document = dataContent.usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingResource(folderModel)
.createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser);
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restRatingModelsCollection = restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModelsCollection.assertNodeHasFiveStarRating().assertNodeIsLiked();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.RATINGS },
executionType = ExecutionType.SANITY, description = "Verify unauthenticated user is not able to retrieve document ratings")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.SANITY })
// @Bug(id="MNT-16904", description = "It fails only on environment with tenants")
public void unauthenticatedUserIsNotAbleToRetrieveRatings() throws Exception
{
FolderModel folderModel = dataContent.usingUser(adminUser).usingSite(siteModel).createFolder();
document = dataContent.usingUser(adminUser).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
restClient.authenticateUser(adminUser);
restClient.withCoreAPI().usingResource(document).likeDocument();
restClient.withCoreAPI().usingResource(document).rateStarsToDocument(5);
restClient.authenticateUser(new UserModel("random user", "random password"));
restClient.withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError()
.containsSummary(RestErrorModel.AUTHENTICATION_FAILED);
}
@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.REGRESSION })
public void checkInvalidMaxItemsStatusCode() throws 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();
restClient.authenticateUser(adminUser).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")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void checkInvalidSkipCountStatusCode() throws 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();
restClient.authenticateUser(adminUser).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")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void addLikeUsingInvalidNodeId() throws 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();
document.setNodeRef(RandomStringUtils.randomAlphanumeric(20));
restClient.authenticateUser(adminUser).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")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void checkRatingValueIsTrueForLikedDoc() throws 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();
restRatingModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModelsCollection.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")
@Test(groups = { TestGroup.REST_API, TestGroup.RATINGS, TestGroup.REGRESSION })
public void checkRatingValueIsIntegerForStarsRating() throws 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();
restRatingModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingResource(document).getRatings();
restClient.assertStatusCodeIs(HttpStatus.OK);
restRatingModelsCollection.assertThat().entriesListContains("myRating", "5")
.assertThat().entriesListContains("id", "fiveStar");
}
@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.REGRESSION })
public void checkDefaultErrorSchema() throws Exception
{
FileModel document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN);
document.setNodeRef("abc");
restClient.authenticateUser(adminUser).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.REGRESSION })
public void checkMaxItemsAndSkipCountParameters() throws 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();
restRatingModelsCollection = restClient.authenticateUser(adminUser).withParams("maxItems=1", "skipCount=1").withCoreAPI().usingResource(document).getRatings();
restRatingModelsCollection.assertThat().entriesListCountIs(1);
restRatingModelsCollection.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.REGRESSION })
public void checkTotalItemsAndHasMoreItemsParameters() throws 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();
restRatingModelsCollection = restClient.authenticateUser(adminUser).withParams("maxItems=1").withCoreAPI().usingResource(document).getRatings();
restRatingModelsCollection.assertThat().entriesListCountIs(1);
restRatingModelsCollection.getPagination().assertThat().field("hasMoreItems").is("true")
.and().field("count").is("1").and().field("maxItems").is("1");
}
@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.REGRESSION })
public void userIsNotAbleToGetRatingsOfDocumentToWhichItHasNoAccess() throws Exception
{
SiteModel privateSite = dataSite.usingAdmin().createPrivateRandomSite();
FileModel file = dataContent.usingSite(privateSite).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN);
restRatingModelsCollection = restClient.authenticateUser(userModel).withCoreAPI().usingResource(file).getRatings();
restRatingModelsCollection.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.REGRESSION })
public void getRatingsUsingHighValueForSkipCount() throws 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();
restRatingModelsCollection = restClient.authenticateUser(adminUser).withParams("skipCount=100").withCoreAPI().usingResource(document).getRatings();
restRatingModelsCollection.getPagination().assertThat().field("skipCount").is("100");
restRatingModelsCollection.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.REGRESSION })
public void getRatingsUsingSiteId() throws Exception
{
FileModel document = dataContent.usingSite(siteModel).usingAdmin().createContent(CMISUtil.DocumentType.TEXT_PLAIN);
document.setNodeRef(siteModel.getId());
restClient.authenticateUser(adminUser).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);
}
}