CORE-REST API: postFavorites

This commit is contained in:
Valentin Popa
2016-11-22 17:25:56 +02:00
parent 275cb3912a
commit 8595fb3174
@@ -0,0 +1,219 @@
package org.alfresco.rest.favorites;
import org.alfresco.dataprep.CMISUtil.DocumentType;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestCommentModel;
import org.alfresco.rest.model.RestPersonFavoritesModel;
import org.alfresco.rest.model.RestTagModel;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.model.ErrorModel;
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.report.Bug;
import org.alfresco.utility.testrail.ExecutionType;
import org.alfresco.utility.testrail.annotation.TestRail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.CORE })
public class AddFavoritesCoreTests extends RestTest
{
@Autowired
DataUser dataUser;
private UserModel adminUserModel;
private SiteModel siteModel;
private ListUserWithRoles usersWithRoles;
private RestPersonFavoritesModel restPersonFavoritesModel;
FileModel document;
FolderModel folder;
private RestCommentModel comment;
private RestTagModel returnedModel;
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws Exception
{
adminUserModel = dataUser.getAdminUser();
siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite();
siteModel.setGuid(restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(siteModel).getSite().getGuid());
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer,
UserRole.SiteContributor);
document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN);
folder = dataContent.usingSite(siteModel).usingUser(adminUserModel).createFolder();
}
@TestRail(section = { TestGroup.REST_API,TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION,
description = "Check that if target guid does not describe a site, file, or folder status code is 400")
public void addFavoriteUsingInvalidGuid() throws Exception
{
LinkModel link = dataLink.usingAdmin().usingSite(siteModel).createRandomLink();
SiteModel site = dataSite.usingUser(adminUserModel).createPublicRandomSite();
site.setGuid(link.getNodeRef());
restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(site);
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(ErrorModel.ENTITY_NOT_FOUND, site.getGuid().split("/")[3]));
}
@TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION,
description = "Check that if personId does not exist, status code is 404")
public void addFavoriteUsingInexistentUser() throws Exception
{
restClient.withCoreAPI().usingUser(new UserModel("random_user", "random_password")).addSiteToFavorites(siteModel);
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError()
.containsSummary(String.format(ErrorModel.ENTITY_NOT_FOUND, "random_user"));
}
@TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION,
description = "Check that if target guid does not exist, status code is 404")
public void addFavoriteUsingInexistentGuid() throws Exception
{
SiteModel site = dataSite.usingUser(adminUserModel).createPublicRandomSite();
site.setGuid("random_guid");
restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(site);
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError()
.containsSummary(String.format(ErrorModel.ENTITY_NOT_FOUND, "random_guid"));
}
@TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION,
description = "Check that if a favorite already exists with the specified id status code is 404")
@Bug(id = "MNT-17157")
public void addFavoriteTwice() throws Exception
{
restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel);
restClient.assertStatusCodeIs(HttpStatus.CONFLICT);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION,
description = "Check that if user provides file in target but guid is of a folder status code is 404")
public void addFileToFavoritesUsingFolderGuid() throws Exception
{
String nodeRef = document.getNodeRef();
document.setNodeRef(folder.getNodeRef());
restClient.withCoreAPI().usingAuthUser().addFileToFavorites(document);
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(ErrorModel.RELATIONSHIP_NOT_FOUND,
adminUserModel.getUsername(), folder.getNodeRefWithoutVersion()));
document.setNodeRef(nodeRef);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION,
description = "Add to favorites a file for a Manager, check it was added")
public void managerIsAbleToAddFileToFavorites() throws Exception
{
restPersonFavoritesModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager))
.withCoreAPI().usingAuthUser().addFileToFavorites(document);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
restPersonFavoritesModel.assertThat().field("targetGuid").is(document.getNodeRefWithoutVersion());
}
@TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION,
description = "Verify add favorite, perform getFavorites call, check value is updated")
public void verifyGetFavoritesAfterFavoritingSite() throws Exception
{
restPersonFavoritesModel = restClient.authenticateUser(adminUserModel)
.withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
restClient.withCoreAPI().usingAuthUser().getFavoriteSites().assertThat().entriesListContains("guid", siteModel.getGuid());
}
@TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION,
description = "Add to favorites a folder for a Manager, check it was added")
public void managerIsAbleToAddFolderToFavorites() throws Exception
{
restPersonFavoritesModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager))
.withCoreAPI().usingAuthUser().addFolderToFavorites(folder);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
restPersonFavoritesModel.assertThat().field("targetGuid").is(folder.getNodeRefWithoutVersion());
}
@TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION,
description = "Add to favorites a site for a Manager, check it was added")
public void managerIsAbleToAddSiteToFavorites() throws Exception
{
restPersonFavoritesModel = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager))
.withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
restPersonFavoritesModel.assertThat().field("targetGuid").is(siteModel.getGuid());
}
@TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION,
description = "Verify add favorite specifying -me- string in place of <personid> for request")
public void userIsAbleToAddFavoriteWhenUsingMeAsUsername() throws Exception
{
restPersonFavoritesModel = restClient.authenticateUser(adminUserModel)
.withCoreAPI().usingMe().addSiteToFavorites(siteModel);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
restPersonFavoritesModel.assertThat().field("targetGuid").is(siteModel.getGuid());
restClient.withCoreAPI().usingAuthUser().getFavoriteSites().assertThat().entriesListContains("guid", siteModel.getGuid());
}
@TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION,
description = "Verify add file favorite with comment id returns status code 404")
@Bug(id = "MNT-17158")
public void addFileFavoriteUsingCommentId() throws Exception
{
FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN);
comment = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).addComment("This is a comment");
file.setNodeRef(comment.getId());
restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addFileToFavorites(file);
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION,
description = "Verify add file favorite with tag id returns status code 404")
public void addFileFavoriteUsingTagId() throws Exception
{
FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN);
returnedModel = restClient.withCoreAPI().usingResource(document).addTag("random_tag");
file.setNodeRef(returnedModel.getId());
restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().addFileToFavorites(file);
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(ErrorModel.RELATIONSHIP_NOT_FOUND,
adminUserModel.getUsername(), returnedModel.getId()));
}
@TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION,
description = "Check that if user provides site in target but id is of a file status code is 404")
public void addSiteToFavoritesUsingFileId() throws Exception
{
String guid = siteModel.getGuid();
siteModel.setGuid(document.getNodeRefWithoutVersion());
restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(siteModel);
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(ErrorModel.ENTITY_NOT_FOUND, document.getNodeRefWithoutVersion()));
siteModel.setGuid(guid);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION,
description = "Check that if user provides folder in target but guid is of a file status code is 404")
public void addFolderToFavoritesUsingFileGuid() throws Exception
{
String nodeRef = folder.getNodeRef();
folder.setNodeRef(document.getNodeRef());
restClient.withCoreAPI().usingAuthUser().addFolderToFavorites(folder);
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(ErrorModel.ENTITY_NOT_FOUND, document.getNodeRef()));
folder.setNodeRef(nodeRef);
}
}