REPO-3023: Fix quarantined TAS REST API GetTagsTests

This commit is contained in:
Alexandru Epure
2017-11-27 16:13:56 +00:00
parent 401df13b6a
commit 7084d319cd
10 changed files with 177 additions and 251 deletions
@@ -13,25 +13,13 @@ public abstract class NetworkDataPrep extends RestTest
protected static RestNetworkModel restNetworkModel;
protected static String tenantDomain;
private static boolean isInitialized = false;
public void init()
public void init() throws Exception
{
if(isInitialized)
{
}
else
if(!isInitialized)
{
isInitialized = true;
try
{
initialization();
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
initialization();
}
}
@@ -6,6 +6,8 @@ import javax.json.Json;
import javax.json.JsonObject;
import org.alfresco.rest.RestTest;
import org.alfresco.utility.RetryOperation;
import org.alfresco.utility.Utility;
import org.alfresco.utility.model.TestGroup;
import org.alfresco.utility.model.UserModel;
import org.alfresco.utility.testrail.ExecutionType;
@@ -136,15 +138,20 @@ public class GroupsTests extends RestTest
String groupMembershipBodyCreate = groupMembershipBody.toString();
//MembershipCreation
restClient.withCoreAPI().usingGroups().createGroupMembershipUntilIsCreated("GROUP_"+groupName, groupMembershipBodyCreate, userModel.getUsername())
restClient.withCoreAPI().usingGroups().createGroupMembership("GROUP_"+groupName, groupMembershipBodyCreate)
.assertThat().field("displayName").is(userModel.getUsername())
.and().field("id").is(userModel.getUsername())
.and().field("memberType").is("PERSON");
restClient.assertStatusCodeIs(HttpStatus.CREATED);
//ListGroupMembership
restClient.withCoreAPI().usingGroups().listGroupMemberships("GROUP_"+groupName)
.assertThat().entriesListContains("id", userModel.getUsername());
restClient.assertStatusCodeIs(HttpStatus.OK);
RetryOperation op = new RetryOperation(){
public void execute() throws Exception{
restClient.withCoreAPI().usingGroups().listGroupMemberships("GROUP_"+groupName)
.assertThat().entriesListContains("id", userModel.getUsername());
restClient.assertStatusCodeIs(HttpStatus.OK);
}
};
Utility.sleep(1000, 35000, op);// Allow indexing to complete.
}
}
@@ -1,113 +1,74 @@
package org.alfresco.rest.tags;
import org.alfresco.dataprep.CMISUtil.DocumentType;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestErrorModel;
import org.alfresco.rest.model.RestTagModel;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.data.RandomData;
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.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class GetTagTests extends RestTest
public class GetTagTests extends TagsDataPrep
{
private UserModel adminUserModel;
private SiteModel siteModel;
private ListUserWithRoles usersWithRoles;
private FileModel document;
private String tagValue;
private RestTagModel tag;
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws Exception
{
adminUserModel = dataUser.getAdminUser();
restClient.authenticateUser(adminUserModel);
siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite();
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer,
UserRole.SiteContributor);
document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN);
init();
}
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception {
tagValue = RandomData.getRandomName("tag");
restClient.authenticateUser(adminUserModel);
tag = restClient.withCoreAPI().usingResource(document).addTag(tagValue);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify admin user gets tag using REST API and status code is OK (200)")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void adminIsAbleToGetTag() throws Exception
{
RestTagModel returnedTag = restClient.authenticateUser(adminUserModel).withCoreAPI().getTag(tag);
RestTagModel returnedTag = restClient.authenticateUser(adminUserModel).withCoreAPI().getTag(documentTag);
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedTag.assertThat().field("tag").is(tagValue.toLowerCase());
returnedTag.assertThat().field("tag").is(documentTagValue.toLowerCase());
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, description = "Verify user with Manager role gets tag using REST API and status code is OK (200)")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY })
public void userWithManagerRoleIsAbleToGetTag() throws Exception
{
String tagValue = RandomData.getRandomName("tag");
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
RestTagModel tag = restClient.withCoreAPI().usingResource(document).addTag(tagValue);
RestTagModel returnedTag = restClient.withCoreAPI().getTag(tag);
RestTagModel returnedTag = restClient.withCoreAPI().getTag(documentTag);
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedTag.assertThat().field("tag").is(tagValue.toLowerCase())
.assertThat().field("id").is(tag.getId());
returnedTag.assertThat().field("tag").is(documentTagValue.toLowerCase())
.assertThat().field("id").is(documentTag.getId());
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify user with Collaborator role gets tag using REST API and status code is OK (200)")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void userWithCollaboratorRoleIsAbleToGetTag() throws Exception
{
String tagValue = RandomData.getRandomName("tag");
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
RestTagModel tag = restClient.withCoreAPI().usingResource(document).addTag(tagValue);
RestTagModel returnedTag = restClient.withCoreAPI().getTag(tag);
RestTagModel returnedTag = restClient.withCoreAPI().getTag(documentTag);
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedTag.assertThat().field("tag").is(tagValue.toLowerCase());
returnedTag.assertThat().field("tag").is(documentTagValue.toLowerCase());
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify user with Contributor role gets tag using REST API and status code is OK (200)")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void userWithContributorRoleIsAbleToGetTag() throws Exception
{
String tagValue = RandomData.getRandomName("tag");
restClient.authenticateUser(adminUserModel);
RestTagModel tag = restClient.withCoreAPI().usingResource(document).addTag(tagValue);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor));
RestTagModel returnedTag = restClient.withCoreAPI().getTag(tag);
RestTagModel returnedTag = restClient.withCoreAPI().getTag(documentTag);
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedTag.assertThat().field("tag").is(tagValue.toLowerCase());
returnedTag.assertThat().field("tag").is(documentTagValue.toLowerCase());
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify user with Consumer role gets tag using REST API and status code is OK (200)")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void userWithConsumerRoleIsAbleToGetTag() throws Exception
{
String tagValue = RandomData.getRandomName("tag");
restClient.authenticateUser(adminUserModel);
RestTagModel tag = restClient.withCoreAPI().usingResource(document).addTag(tagValue);
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer));
RestTagModel returnedTag = restClient.withCoreAPI().getTag(tag);
RestTagModel returnedTag = restClient.withCoreAPI().getTag(documentTag);
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedTag.assertThat().field("tag").is(tagValue.toLowerCase());
returnedTag.assertThat().field("tag").is(documentTagValue.toLowerCase());
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, description = "Verify Manager user gets status code 401 if authentication call fails")
@@ -116,9 +77,11 @@ public class GetTagTests extends RestTest
public void managerIsNotAbleToGetTagIfAuthenticationFails() throws Exception
{
UserModel managerUser = dataUser.usingAdmin().createRandomTestUser();
String managerPassword = managerUser.getPassword();
dataUser.addUserToSite(managerUser, siteModel, UserRole.SiteManager);
managerUser.setPassword("wrongPassword");
restClient.authenticateUser(managerUser).withCoreAPI().getTag(tag);
restClient.authenticateUser(managerUser).withCoreAPI().getTag(documentTag);
managerUser.setPassword(managerPassword);
restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError()
.containsSummary(RestErrorModel.AUTHENTICATION_FAILED);
}
@@ -128,9 +91,11 @@ public class GetTagTests extends RestTest
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void invalidTagIdTest() throws Exception
{
tag.setId("random_tag_value");
restClient.withCoreAPI().getTag(tag);
String tagId = documentTag.getId();
documentTag.setId("random_tag_value");
restClient.authenticateUser(adminUserModel).withCoreAPI().getTag(documentTag);
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "random_tag_value"));
documentTag.setId(tagId);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS },
@@ -139,10 +104,10 @@ public class GetTagTests extends RestTest
public void checkPropertiesFilterIsApplied() throws Exception
{
RestTagModel returnedTag = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager))
.withParams("properties=id,tag").withCoreAPI().getTag(tag);
.withParams("properties=id,tag").withCoreAPI().getTag(documentTag);
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedTag.assertThat().field("id").is(tag.getId())
.assertThat().field("tag").is(tag.getTag().toLowerCase())
returnedTag.assertThat().field("id").is(documentTag.getId())
.assertThat().field("tag").is(documentTag.getTag().toLowerCase())
.assertThat().fieldsCount().is(2);
}
@@ -151,16 +116,10 @@ public class GetTagTests extends RestTest
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void getTagOfAFolder() throws Exception
{
String tagValue = RandomData.getRandomName("tagFolder");
FolderModel folder = dataContent.usingAdmin().usingSite(siteModel).createFolder();
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
RestTagModel tag = restClient.withCoreAPI().usingResource(folder).addTag(tagValue);
RestTagModel returnedTag = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager))
.withCoreAPI().getTag(tag);
.withCoreAPI().getTag(folderTag);
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedTag.assertThat().field("tag").is(tagValue.toLowerCase());
returnedTag.assertThat().field("tag").is(folderTagValue.toLowerCase());
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS },
@@ -169,7 +128,7 @@ public class GetTagTests extends RestTest
public void checkDefaultErrorModelSchema() throws Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager))
.withParams("skipCount=abc").withCoreAPI().getTag(tag);
.withParams("skipCount=abc").withCoreAPI().getTag(documentTag);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError()
.containsErrorKey(String.format(RestErrorModel.INVALID_SKIPCOUNT, "abc"))
.containsSummary(String.format(RestErrorModel.INVALID_SKIPCOUNT, "abc"))
@@ -1,69 +1,26 @@
package org.alfresco.rest.tags;
import org.alfresco.dataprep.CMISUtil;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestErrorModel;
import org.alfresco.rest.model.RestTagModel;
import org.alfresco.rest.model.RestTagModelsCollection;
import org.alfresco.utility.Utility;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.data.RandomData;
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.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class GetTagsTests extends RestTest
public class GetTagsTests extends TagsDataPrep
{
private UserModel adminUserModel;
private UserModel userModel;
private SiteModel siteModel;
private ListUserWithRoles usersWithRoles;
private RestTagModelsCollection returnedCollection;
private String tagValue;
private String tagValue2;
private String tagValue3;
private FileModel document;
private FolderModel folder;
@BeforeClass(alwaysRun=true)
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws Exception
{
adminUserModel = dataUser.getAdminUser();
restClient.authenticateUser(adminUserModel);
siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite();
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor);
document = dataContent.usingUser(adminUserModel).usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
folder = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder();
returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags();
int noTagsBefore = returnedCollection.getEntries().size();
tagValue = RandomData.getRandomName("tag");
tagValue2 = RandomData.getRandomName("tag");
tagValue3 = RandomData.getRandomName("tag");
restClient.withCoreAPI().usingResource(document).addTags(tagValue, tagValue2);
restClient.withCoreAPI().usingResource(folder).addTags(tagValue3);
returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags();
int noTagsAfter = returnedCollection.getEntries().size();
int retry = 0;
while(noTagsAfter < noTagsBefore + 3 && retry < 30)
{
Utility.waitToLoopTime(2);
returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags();
noTagsAfter = returnedCollection.getEntries().size();
retry++;
}
init();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, description = "Verify user with Manager role gets tags using REST API and status code is OK (200)")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY })
public void getTagsWithManagerRole() throws Exception
@@ -72,8 +29,8 @@ public class GetTagsTests extends RestTest
returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedCollection.assertThat().entriesListIsNotEmpty()
.and().entriesListContains("tag", tagValue.toLowerCase())
.and().entriesListContains("tag", tagValue2.toLowerCase());
.and().entriesListContains("tag", documentTagValue.toLowerCase())
.and().entriesListContains("tag", documentTagValue2.toLowerCase());
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify user with Collaborator role gets tags using REST API and status code is OK (200)")
@@ -84,8 +41,8 @@ public class GetTagsTests extends RestTest
returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedCollection.assertThat().entriesListIsNotEmpty()
.and().entriesListContains("tag", tagValue.toLowerCase())
.and().entriesListContains("tag", tagValue2.toLowerCase());
.and().entriesListContains("tag", documentTagValue.toLowerCase())
.and().entriesListContains("tag", documentTagValue2.toLowerCase());
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify user with Contributor role gets tags using REST API and status code is OK (200)")
@@ -96,8 +53,8 @@ public class GetTagsTests extends RestTest
returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedCollection.assertThat().entriesListIsNotEmpty()
.and().entriesListContains("tag", tagValue.toLowerCase())
.and().entriesListContains("tag", tagValue2.toLowerCase());
.and().entriesListContains("tag", documentTagValue.toLowerCase())
.and().entriesListContains("tag", documentTagValue2.toLowerCase());
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify user with Consumer role gets tags using REST API and status code is OK (200)")
@@ -108,8 +65,8 @@ public class GetTagsTests extends RestTest
returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedCollection.assertThat().entriesListIsNotEmpty()
.and().entriesListContains("tag", tagValue.toLowerCase())
.and().entriesListContains("tag", tagValue2.toLowerCase());
.and().entriesListContains("tag", documentTagValue.toLowerCase())
.and().entriesListContains("tag", documentTagValue2.toLowerCase());
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, description = "Failed authentication get tags call returns status code 401 with Manager role")
@@ -154,8 +111,8 @@ public class GetTagsTests extends RestTest
returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedCollection.assertThat().entriesListIsNotEmpty()
.and().entriesListContains("tag", tagValue.toLowerCase())
.and().entriesListContains("tag", tagValue2.toLowerCase());
.and().entriesListContains("tag", documentTagValue.toLowerCase())
.and().entriesListContains("tag", documentTagValue2.toLowerCase());
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
@@ -167,7 +124,7 @@ public class GetTagsTests extends RestTest
returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedCollection.assertThat().entriesListIsNotEmpty()
.and().entriesListContains("tag", tagValue3.toLowerCase());
.and().entriesListContains("tag", folderTagValue.toLowerCase());
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
@@ -180,8 +137,8 @@ public class GetTagsTests extends RestTest
.withParams("maxItems=5000&properties=tag").withCoreAPI().getTags();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedCollection.assertThat().entriesListIsNotEmpty()
.and().entriesListContains("tag", tagValue.toLowerCase())
.and().entriesListContains("tag", tagValue2.toLowerCase())
.and().entriesListContains("tag", documentTagValue.toLowerCase())
.and().entriesListContains("tag", documentTagValue2.toLowerCase())
.and().entriesListDoesNotContain("id");
}
@@ -0,0 +1,67 @@
package org.alfresco.rest.tags;
import org.alfresco.dataprep.CMISUtil;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestTagModel;
import org.alfresco.rest.model.RestTagModelsCollection;
import org.alfresco.utility.Utility;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.data.RandomData;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FolderModel;
import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel;
public class TagsDataPrep extends RestTest
{
protected static UserModel adminUserModel;
protected static UserModel userModel;
protected static ListUserWithRoles usersWithRoles;
protected static SiteModel siteModel;
protected static FileModel document;
protected static FolderModel folder;
protected static String documentTagValue, documentTagValue2, folderTagValue;
protected static RestTagModel documentTag, documentTag2, folderTag, returnedModel;
protected static RestTagModelsCollection returnedCollection;
private static boolean isInitialized = false;
public void init() throws Exception
{
if(!isInitialized)
{
isInitialized = true;
initialization();
}
}
public void initialization() throws Exception
{
adminUserModel = dataUser.getAdminUser();
//Create public site
siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite();
usersWithRoles = dataUser.usingAdmin().addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor);
document = dataContent.usingUser(adminUserModel).usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
folder = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder();
documentTagValue = RandomData.getRandomName("tag");
documentTagValue2 = RandomData.getRandomName("tag");
folderTagValue = RandomData.getRandomName("tag");
restClient.authenticateUser(adminUserModel);
documentTag = restClient.withCoreAPI().usingResource(document).addTag(documentTagValue);
documentTag2 = restClient.withCoreAPI().usingResource(document).addTag(documentTagValue2);
folderTag = restClient.withCoreAPI().usingResource(folder).addTag(folderTagValue);
// Allow indexing to complete.
Utility.sleep(1000, 35000, () ->
{
returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags();
returnedCollection.assertThat().entriesListContains("tag", documentTagValue.toLowerCase())
.and().entriesListContains("tag", documentTagValue2.toLowerCase())
.and().entriesListContains("tag", folderTagValue.toLowerCase());
});
}
}
@@ -1,15 +1,10 @@
package org.alfresco.rest.tags;
import org.alfresco.dataprep.CMISUtil;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestErrorModel;
import org.alfresco.rest.model.RestTagModel;
import org.alfresco.utility.Utility;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.data.RandomData;
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;
@@ -24,23 +19,15 @@ import org.testng.annotations.Test;
/**
* Created by Claudia Agache on 10/4/2016.
*/
public class UpdateTagTests extends RestTest
public class UpdateTagTests extends TagsDataPrep
{
private UserModel adminUserModel;
private FileModel document;
private SiteModel siteModel;
private RestTagModel oldTag;
private DataUser.ListUserWithRoles usersWithRoles;
private String randomTag = "";
private RestTagModel returnedModel;
@BeforeClass(alwaysRun=true)
public void dataPreparation() throws Exception
{
adminUserModel = dataUser.getAdminUser();
siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite();
document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor);
init();
}
@BeforeMethod(alwaysRun=true)
@@ -112,9 +99,11 @@ public class UpdateTagTests extends RestTest
public void userIsNotAbleToUpdateTagIfAuthenticationFails() throws Exception
{
UserModel siteManager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager);
String managerPassword = siteManager.getPassword();
siteManager.setPassword("wrongPassword");
restClient.authenticateUser(siteManager);
restClient.withCoreAPI().usingTag(oldTag).update(randomTag);
siteManager.setPassword(managerPassword);
restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError()
.containsSummary(RestErrorModel.AUTHENTICATION_FAILED);
}
@@ -1,17 +1,15 @@
package org.alfresco.rest.tags.nodes;
import org.alfresco.dataprep.CMISUtil;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestCommentModel;
import org.alfresco.rest.model.RestErrorModel;
import org.alfresco.rest.model.RestTagModel;
import org.alfresco.rest.model.RestTagModelsCollection;
import org.alfresco.rest.tags.TagsDataPrep;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.data.RandomData;
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;
@@ -25,12 +23,8 @@ import org.testng.annotations.Test;
/**
* Created by Claudia Agache on 10/3/2016.
*/
public class AddTagTests extends RestTest
public class AddTagTests extends TagsDataPrep
{
private UserModel adminUserModel, userModel;
private FileModel document;
private SiteModel siteModel;
private DataUser.ListUserWithRoles usersWithRoles;
private String tagValue;
private RestTagModel returnedModel;
private RestCommentModel returnedModelComment;
@@ -39,11 +33,7 @@ public class AddTagTests extends RestTest
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws Exception
{
adminUserModel = dataUser.getAdminUser();
siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite();
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer,
UserRole.SiteContributor);
document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
init();
}
@BeforeMethod(alwaysRun = true)
@@ -129,11 +119,13 @@ public class AddTagTests extends RestTest
public void userIsNotAbleToAddTagIfAuthenticationFails() throws Exception
{
UserModel siteManager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager);
String managerPassword = siteManager.getPassword();
siteManager.setPassword("wrongPassword");
restClient.authenticateUser(siteManager);
restClient.withCoreAPI().usingResource(document).addTag("tagUnauthorized");
restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError()
.containsSummary(RestErrorModel.AUTHENTICATION_FAILED);
siteManager.setPassword(managerPassword);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
@@ -161,14 +153,14 @@ public class AddTagTests extends RestTest
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void addTagToInexistentNode() throws Exception
{
FileModel document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
String oldNodeRef = document.getNodeRef();
String nodeRef = RandomStringUtils.randomAlphanumeric(10);
document.setNodeRef(nodeRef);
restClient.authenticateUser(adminUserModel);
returnedModel = restClient.withCoreAPI().usingResource(document).addTag(tagValue);
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, nodeRef));
document.setNodeRef(oldNodeRef);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY,
@@ -189,7 +181,6 @@ public class AddTagTests extends RestTest
public void addTagToATaggedFile() throws Exception
{
restClient.authenticateUser(adminUserModel);
document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
returnedModel = restClient.withCoreAPI().usingResource(document).addTag(tagValue);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
@@ -1,14 +1,12 @@
package org.alfresco.rest.tags.nodes;
import org.alfresco.dataprep.CMISUtil;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestErrorModel;
import org.alfresco.rest.model.RestTagModelsCollection;
import org.alfresco.rest.tags.TagsDataPrep;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.data.RandomData;
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;
@@ -21,23 +19,16 @@ import org.testng.annotations.Test;
/**
* Created by Claudia Agache on 10/7/2016.
*/
public class AddTagsTests extends RestTest
public class AddTagsTests extends TagsDataPrep
{
private UserModel adminUserModel, userModel;
private FileModel document, contributorDoc;
private SiteModel siteModel;
private DataUser.ListUserWithRoles usersWithRoles;
private FileModel contributorDoc;
private String tag1, tag2;
private RestTagModelsCollection returnedCollection;
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws Exception
{
adminUserModel = dataUser.getAdminUser();
siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite();
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer,
UserRole.SiteContributor);
document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
init();
}
@BeforeMethod(alwaysRun = true)
@@ -123,9 +114,11 @@ public class AddTagsTests extends RestTest
public void userIsNotAbleToAddTagsIfAuthenticationFails() throws Exception
{
UserModel siteManager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager);
String managerPassword = siteManager.getPassword();
siteManager.setPassword("wrongPassword");
restClient.authenticateUser(siteManager).withCoreAPI().usingResource(document).addTags(tag1, tag2);
restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError()
.containsSummary(RestErrorModel.AUTHENTICATION_FAILED);
siteManager.setPassword(managerPassword);
}
}
@@ -1,13 +1,15 @@
package org.alfresco.rest.tags.nodes;
import org.alfresco.dataprep.CMISUtil;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestErrorModel;
import org.alfresco.rest.model.RestTagModel;
import org.alfresco.rest.tags.TagsDataPrep;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.data.RandomData;
import org.alfresco.utility.model.*;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FolderModel;
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;
@@ -19,21 +21,15 @@ import org.testng.annotations.Test;
/**
* Created by Claudia Agache on 10/4/2016.
*/
public class DeleteTagTests extends RestTest
public class DeleteTagTests extends TagsDataPrep
{
private UserModel adminUserModel, userModel;
private SiteModel siteModel;
private DataUser.ListUserWithRoles usersWithRoles;
private RestTagModel tag;
private FileModel document, contributorDoc;
private FileModel contributorDoc;
@BeforeClass(alwaysRun=true)
public void dataPreparation() throws Exception
{
adminUserModel = dataUser.getAdminUser();
siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite();
document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor);
init();
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
@@ -126,11 +122,13 @@ public class DeleteTagTests extends RestTest
tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag"));
UserModel siteManager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager);
String managerPassword = siteManager.getPassword();
siteManager.setPassword("wrongPassword");
restClient.authenticateUser(siteManager);
restClient.withCoreAPI().usingResource(document).deleteTag(tag);
restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED).assertLastError()
.containsSummary(RestErrorModel.AUTHENTICATION_FAILED);
siteManager.setPassword(managerPassword);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
@@ -1,12 +1,9 @@
package org.alfresco.rest.tags.nodes;
import org.alfresco.dataprep.CMISUtil;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestErrorModel;
import org.alfresco.rest.model.RestTagModelsCollection;
import org.alfresco.rest.tags.TagsDataPrep;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.data.RandomData;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FolderModel;
import org.alfresco.utility.model.SiteModel;
@@ -19,32 +16,17 @@ import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class GetNodeTagsTests extends RestTest
public class GetNodeTagsTests extends TagsDataPrep
{
private UserModel adminUserModel;
private SiteModel siteModel;
private ListUserWithRoles usersWithRoles;
private FileModel document;
private RestTagModelsCollection returnedCollection;
private String tagValue;
private String tagValue2;
@BeforeClass(alwaysRun=true)
public void dataPreparation() throws Exception
{
adminUserModel = dataUser.getAdminUser();
restClient.authenticateUser(adminUserModel);
siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite();
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel,
UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor);
document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
tagValue = RandomData.getRandomName("tag");
restClient.withCoreAPI().usingResource(document).addTag(tagValue);
tagValue2 = RandomData.getRandomName("tag");
restClient.withCoreAPI().usingResource(document).addTag(tagValue2);
init();
tagValue = documentTagValue;
tagValue2 = documentTagValue2;
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS },
@@ -53,7 +35,7 @@ public class GetNodeTagsTests extends RestTest
public void siteManagerIsAbleToRetrieveNodeTags() throws Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
returnedCollection = restClient.withCoreAPI().usingResource(document).getNodeTags();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedCollection.assertThat()
@@ -67,7 +49,7 @@ public class GetNodeTagsTests extends RestTest
public void siteCollaboratorIsAbleToRetrieveNodeTags() throws Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
returnedCollection = restClient.withCoreAPI().usingResource(document).getNodeTags();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedCollection.assertThat()
@@ -81,7 +63,7 @@ public class GetNodeTagsTests extends RestTest
public void siteContributorIsAbleToRetrieveNodeTags() throws Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor));
returnedCollection = restClient.withCoreAPI().usingResource(document).getNodeTags();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedCollection.assertThat()
@@ -95,7 +77,7 @@ public class GetNodeTagsTests extends RestTest
public void siteConsumerIsAbleToRetrieveNodeTags() throws Exception
{
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer));
returnedCollection = restClient.withCoreAPI().usingResource(document).getNodeTags();
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedCollection.assertThat()
@@ -157,12 +139,10 @@ public class GetNodeTagsTests extends RestTest
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION})
public void userWithoutPermissionsTest() throws Exception
{
SiteModel site = dataSite.usingUser(adminUserModel).createModeratedRandomSite();
FileModel document = dataContent.usingSite(site).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
String tagValue = RandomData.getRandomName("tag");
restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).addTag(tagValue);
SiteModel moderatedSite = dataSite.usingUser(adminUserModel).createModeratedRandomSite();
FileModel moderatedDocument = dataContent.usingSite(moderatedSite).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
restClient.authenticateUser(dataUser.createRandomTestUser()).withCoreAPI().usingResource(document).getNodeTags();
restClient.authenticateUser(dataUser.createRandomTestUser()).withCoreAPI().usingResource(moderatedDocument).getNodeTags();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED)
.containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER)
@@ -174,11 +154,11 @@ public class GetNodeTagsTests extends RestTest
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION})
public void nonexistentNodeTest() throws Exception
{
FileModel document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
FileModel badDocument = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
String nodeRef = RandomStringUtils.randomAlphanumeric(10);
document.setNodeRef(nodeRef);
badDocument.setNodeRef(nodeRef);
restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).getNodeTags();
restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(badDocument).getNodeTags();
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, nodeRef));
}
@@ -187,10 +167,10 @@ public class GetNodeTagsTests extends RestTest
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION})
public void emptyNodeIdTest() throws Exception
{
FileModel document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
document.setNodeRef("");
FileModel badDocument = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
badDocument.setNodeRef("");
restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).getNodeTags();
restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(badDocument).getNodeTags();
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, ""));
}
@@ -247,8 +227,7 @@ public class GetNodeTagsTests extends RestTest
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedCollection.getPagination().assertThat().field("maxItems").is(100)
.and().field("hasMoreItems").is("false")
.and().field("totalItems").is(2)
.and().field("count").is("1");
.and().field("count").isGreaterThan(1);
}
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
@@ -261,7 +240,6 @@ public class GetNodeTagsTests extends RestTest
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedCollection.getPagination().assertThat().field("maxItems").is(1)
.and().field("hasMoreItems").is("true")
.and().field("totalItems").is("2")
.and().field("count").is("1")
.and().field("skipCount").is("0");
}
@@ -333,7 +311,6 @@ public class GetNodeTagsTests extends RestTest
restClient.assertStatusCodeIs(HttpStatus.OK);
returnedCollection.getPagination().assertThat().field("maxItems").is(100)
.and().field("hasMoreItems").is("false")
.and().field("totalItems").is("2")
.and().field("count").is("0")
.and().field("skipCount").is("10000");
returnedCollection.assertThat().entriesListCountIs(0);