using only models as parameters

adding ListUserWithRoles (removing HashMaps)
update sanity-rest
This commit is contained in:
Paul Brodner
2016-09-29 14:56:54 +03:00
parent 2810e995d7
commit 44b810bffa
12 changed files with 195 additions and 209 deletions

View File

@@ -1,13 +1,11 @@
package org.alfresco.rest; package org.alfresco.rest;
import java.util.Arrays;
import java.util.HashMap;
import org.alfresco.rest.exception.JsonToModelConversionException; import org.alfresco.rest.exception.JsonToModelConversionException;
import org.alfresco.rest.requests.RestSitesApi; import org.alfresco.rest.requests.RestSitesApi;
import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataSite; import org.alfresco.utility.data.DataSite;
import org.alfresco.utility.data.DataUser; import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.exception.DataPreparationException; import org.alfresco.utility.exception.DataPreparationException;
import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel; import org.alfresco.utility.model.UserModel;
@@ -25,7 +23,6 @@ import org.testng.annotations.Test;
@Test(groups = { "rest-api", "sites", "sanity" }) @Test(groups = { "rest-api", "sites", "sanity" })
public class GetSiteSanityTests extends RestTest public class GetSiteSanityTests extends RestTest
{ {
@Autowired @Autowired
DataUser dataUser; DataUser dataUser;
@@ -36,55 +33,54 @@ public class GetSiteSanityTests extends RestTest
DataSite dataSite; DataSite dataSite;
private UserModel adminUserModel; private UserModel adminUserModel;
private HashMap<UserRole, UserModel> usersWithRoles; private ListUserWithRoles usersWithRoles;
private UserModel userModel; private UserModel userModel;
private SiteModel siteModel; private SiteModel siteModel;
@BeforeClass @BeforeClass(alwaysRun=true)
public void initTest() throws DataPreparationException public void dataPreparation() throws DataPreparationException
{ {
adminUserModel = dataUser.getAdminUser(); adminUserModel = dataUser.getAdminUser();
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
siteAPI.useRestClient(restClient); siteAPI.useRestClient(restClient);
siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite();
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel,UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor);
Arrays.asList(UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor));
} }
@TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY,
description = "Verify user with Manager role gets site information and gets status code OK (200)") description = "Verify user with Manager role gets site information and gets status code OK (200)")
public void getSiteWithManagerRole() throws JsonToModelConversionException, Exception public void getSiteWithManagerRole() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
siteAPI.getSite(siteModel.getId()); siteAPI.getSite(siteModel);
siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY,
description = "Verify user with Collaborator role gets site information and gets status code OK (200)") description = "Verify user with Collaborator role gets site information and gets status code OK (200)")
public void getSiteWithCollaboratorRole() throws JsonToModelConversionException, Exception public void getSiteWithCollaboratorRole() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteCollaborator)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
siteAPI.getSite(siteModel.getId()); siteAPI.getSite(siteModel);
siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY,
description = "Verify user with Contributor role gets site information and gets status code OK (200)") description = "Verify user with Contributor role gets site information and gets status code OK (200)")
public void getSiteWithContributorRole() throws JsonToModelConversionException, Exception public void getSiteWithContributorRole() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteContributor)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor));
siteAPI.getSite(siteModel.getId()); siteAPI.getSite(siteModel);
siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY,
description = "Verify user with Consumer role gets site information and gets status code OK (200)") description = "Verify user with Consumer role gets site information and gets status code OK (200)")
public void getSiteWithConsumerRole() throws JsonToModelConversionException, Exception public void getSiteWithConsumerRole() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteConsumer)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer));
siteAPI.getSite(siteModel.getId()); siteAPI.getSite(siteModel);
siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY,
@@ -92,8 +88,8 @@ public class GetSiteSanityTests extends RestTest
public void getSiteWithAdminRole() throws JsonToModelConversionException, Exception public void getSiteWithAdminRole() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
siteAPI.getSite(siteModel.getId()); siteAPI.getSite(siteModel);
siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY,
@@ -105,6 +101,6 @@ public class GetSiteSanityTests extends RestTest
dataUser.addUserToSite(userModel, siteModel, UserRole.SiteManager); dataUser.addUserToSite(userModel, siteModel, UserRole.SiteManager);
restClient.authenticateUser(userModel); restClient.authenticateUser(userModel);
siteAPI.getAllSites(); siteAPI.getAllSites();
siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED.toString()); siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED);
} }
} }

View File

@@ -1,13 +1,11 @@
package org.alfresco.rest; package org.alfresco.rest;
import java.util.Arrays;
import java.util.HashMap;
import org.alfresco.rest.exception.JsonToModelConversionException; import org.alfresco.rest.exception.JsonToModelConversionException;
import org.alfresco.rest.requests.RestSitesApi; import org.alfresco.rest.requests.RestSitesApi;
import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataSite; import org.alfresco.utility.data.DataSite;
import org.alfresco.utility.data.DataUser; import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel; import org.alfresco.utility.model.UserModel;
import org.alfresco.utility.testrail.ExecutionType; import org.alfresco.utility.testrail.ExecutionType;
@@ -34,27 +32,26 @@ public class GetSitesSanityTests extends RestTest
private UserModel adminUserModel; private UserModel adminUserModel;
private UserModel userModel; private UserModel userModel;
private HashMap<UserRole, UserModel> usersWithRoles; private ListUserWithRoles usersWithRoles;
private SiteModel siteModel; private SiteModel siteModel;
@BeforeClass @BeforeClass(alwaysRun=true)
public void initTest() throws Exception public void dataPreparation() throws Exception
{ {
adminUserModel = dataUser.getAdminUser(); adminUserModel = dataUser.getAdminUser();
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
siteAPI.useRestClient(restClient); siteAPI.useRestClient(restClient);
siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite();
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel,UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor);
Arrays.asList(UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor));
} }
@TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Manager role gets sites information and gets status code OK (200)") @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Manager role gets sites information and gets status code OK (200)")
public void getSitesWithManagerRole() throws JsonToModelConversionException, Exception public void getSitesWithManagerRole() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
siteAPI.getAllSites(); siteAPI.getAllSites();
siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY,
@@ -62,9 +59,9 @@ public class GetSitesSanityTests extends RestTest
public void getSitesWithCollaboratorRole() throws JsonToModelConversionException, Exception public void getSitesWithCollaboratorRole() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteCollaborator)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
siteAPI.getAllSites(); siteAPI.getAllSites();
siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY,
@@ -72,9 +69,9 @@ public class GetSitesSanityTests extends RestTest
public void getSitesWithContributorRole() throws JsonToModelConversionException, Exception public void getSitesWithContributorRole() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteContributor)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor));
siteAPI.getAllSites(); siteAPI.getAllSites();
siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY,
@@ -82,9 +79,9 @@ public class GetSitesSanityTests extends RestTest
public void getSitesWithConsumerRole() throws JsonToModelConversionException, Exception public void getSitesWithConsumerRole() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteConsumer)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer));
siteAPI.getAllSites(); siteAPI.getAllSites();
siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY,
@@ -93,19 +90,19 @@ public class GetSitesSanityTests extends RestTest
{ {
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
siteAPI.getAllSites(); siteAPI.getAllSites();
siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY,
description = "Failed authentication get sites call returns status code 401 with Manager role") description = "Failed authentication get sites call returns status code 401 with Manager role")
public void getSitesWithManagerRoleFailedAuth() throws JsonToModelConversionException, Exception public void getSitesWithManagerRoleFailedAuth() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
userModel = dataUser.createRandomTestUser(); userModel = dataUser.createRandomTestUser();
userModel.setPassword("user wrong password"); userModel.setPassword("user wrong password");
dataUser.addUserToSite(userModel, siteModel, UserRole.SiteManager); dataUser.addUserToSite(userModel, siteModel, UserRole.SiteManager);
restClient.authenticateUser(userModel); restClient.authenticateUser(userModel);
siteAPI.getAllSites(); siteAPI.getAllSites();
siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED.toString()); siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED);
} }
} }

View File

@@ -1,13 +1,11 @@
package org.alfresco.rest; package org.alfresco.rest;
import java.util.Arrays;
import java.util.HashMap;
import org.alfresco.rest.exception.JsonToModelConversionException; import org.alfresco.rest.exception.JsonToModelConversionException;
import org.alfresco.rest.requests.RestSitesApi; import org.alfresco.rest.requests.RestSitesApi;
import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataSite; import org.alfresco.utility.data.DataSite;
import org.alfresco.utility.data.DataUser; import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel; import org.alfresco.utility.model.UserModel;
import org.alfresco.utility.testrail.ExecutionType; import org.alfresco.utility.testrail.ExecutionType;
@@ -34,55 +32,53 @@ public class GetSitesTests extends RestTest
private UserModel adminUserModel; private UserModel adminUserModel;
private UserModel userModel; private UserModel userModel;
private HashMap<UserRole, UserModel> usersWithRoles; private ListUserWithRoles usersWithRoles;
private SiteModel siteModel; private SiteModel siteModel;
@BeforeClass @BeforeClass(alwaysRun=true)
public void initTest() throws Exception public void dataPreparation() throws Exception
{ {
adminUserModel = dataUser.getAdminUser(); adminUserModel = dataUser.getAdminUser();
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
siteAPI.useRestClient(restClient); siteAPI.useRestClient(restClient);
siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite();
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel,UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor);
Arrays.asList(UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor));
} }
@TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Manager role gets sites information and gets status code OK (200)") @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Manager role gets sites information and gets status code OK (200)")
public void getSitesWithManagerRole() throws JsonToModelConversionException, Exception public void getSitesWithManagerRole() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
siteAPI.getAllSites(); siteAPI.getAllSites();
siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Collaborator role gets sites information and gets status code OK (200)") @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Collaborator role gets sites information and gets status code OK (200)")
public void getSitesWithCollaboratorRole() throws JsonToModelConversionException, Exception public void getSitesWithCollaboratorRole() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteCollaborator)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
siteAPI.getAllSites(); siteAPI.getAllSites();
siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Contributor role gets sites information and gets status code OK (200)") @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Contributor role gets sites information and gets status code OK (200)")
public void getSitesWithContributorRole() throws JsonToModelConversionException, Exception public void getSitesWithContributorRole() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteContributor)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor));
siteAPI.getAllSites(); siteAPI.getAllSites();
siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Consumer role gets sites information and gets status code OK (200)") @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Consumer role gets sites information and gets status code OK (200)")
public void getSitesWithConsumerRole() throws JsonToModelConversionException, Exception public void getSitesWithConsumerRole() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteConsumer)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer));
siteAPI.getAllSites(); siteAPI.getAllSites();
siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Admin user gets sites information and gets status code OK (200)") @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Verify user with Admin user gets sites information and gets status code OK (200)")
@@ -90,18 +86,18 @@ public class GetSitesTests extends RestTest
{ {
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
siteAPI.getAllSites(); siteAPI.getAllSites();
siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Failed authentication get sites call returns status code 401 with Manager role") @TestRail(section = { "rest-api", "sites" }, executionType = ExecutionType.SANITY, description = "Failed authentication get sites call returns status code 401 with Manager role")
public void getSitesWithManagerRoleFailedAuth() throws JsonToModelConversionException, Exception public void getSitesWithManagerRoleFailedAuth() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
userModel = dataUser.createRandomTestUser(); userModel = dataUser.createRandomTestUser();
userModel.setPassword("user wrong password"); userModel.setPassword("user wrong password");
dataUser.addUserToSite(userModel, siteModel, UserRole.SiteManager); dataUser.addUserToSite(userModel, siteModel, UserRole.SiteManager);
restClient.authenticateUser(userModel); restClient.authenticateUser(userModel);
siteAPI.getAllSites(); siteAPI.getAllSites();
siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED.toString()); siteAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED);
} }
} }

View File

@@ -8,12 +8,16 @@ import org.alfresco.utility.data.DataSite;
import org.alfresco.utility.data.DataUser; import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.network.ServerHealth; import org.alfresco.utility.network.ServerHealth;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import com.jayway.restassured.RestAssured; import com.jayway.restassured.RestAssured;
@Component
@Scope(value = "prototype")
@ContextConfiguration("classpath:alfresco-restapi-context.xml") @ContextConfiguration("classpath:alfresco-restapi-context.xml")
public abstract class RestTest extends AbstractTestNGSpringContextTests public abstract class RestTest extends AbstractTestNGSpringContextTests
{ {
@@ -39,7 +43,7 @@ public abstract class RestTest extends AbstractTestNGSpringContextTests
protected DataContent dataContent; protected DataContent dataContent;
@BeforeClass(alwaysRun = true) @BeforeClass(alwaysRun = true)
public void setupRestTest() throws Exception public void checkServerHealth() throws Exception
{ {
serverHealth.assertServerIsOnline(); serverHealth.assertServerIsOnline();

View File

@@ -1,14 +1,12 @@
package org.alfresco.rest.comments; package org.alfresco.rest.comments;
import java.util.Arrays;
import java.util.HashMap;
import org.alfresco.dataprep.CMISUtil.DocumentType; import org.alfresco.dataprep.CMISUtil.DocumentType;
import org.alfresco.rest.RestTest; import org.alfresco.rest.RestTest;
import org.alfresco.rest.exception.JsonToModelConversionException; import org.alfresco.rest.exception.JsonToModelConversionException;
import org.alfresco.rest.requests.RestCommentsApi; import org.alfresco.rest.requests.RestCommentsApi;
import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser; import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel; import org.alfresco.utility.model.UserModel;
@@ -20,7 +18,7 @@ import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@Test(groups = { "rest-api", "comments", "sanity" }) @Test(groups = { "rest-api", "comments", "sanity" })
public class GetCommentsSanityTest extends RestTest public class GetCommentsSanityTests extends RestTest
{ {
@Autowired @Autowired
RestCommentsApi commentsAPI; RestCommentsApi commentsAPI;
@@ -33,63 +31,63 @@ public class GetCommentsSanityTest extends RestTest
private FileModel document; private FileModel document;
private SiteModel siteModel; private SiteModel siteModel;
private UserModel userModel; private UserModel userModel;
private HashMap<UserRole, UserModel> usersWithRoles; private ListUserWithRoles usersWithRoles;
@BeforeClass @BeforeClass(alwaysRun=true)
public void initTest() throws Exception public void dataPreparation() throws Exception
{ {
adminUserModel = dataUser.getAdminUser(); adminUserModel = dataUser.getAdminUser();
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); siteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite();
commentsAPI.useRestClient(restClient); commentsAPI.useRestClient(restClient);
document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN); document = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(DocumentType.TEXT_PLAIN);
commentsAPI.addComment(document.getNodeRef(), "This is a new comment"); commentsAPI.addComment(document, "This is a new comment");
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, Arrays.asList(UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor)); usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor);
} }
@TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY,
description= "Verify Admin user gets comments with Rest API and status code is 200") description= "Verify Admin user gets comments with Rest API and status code is 200")
public void adminIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception public void adminIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception
{ {
commentsAPI.getNodeComments(document.getNodeRef()); commentsAPI.getNodeComments(document);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY,
description= "Verify Manager user gets comments created by admin user with Rest API and status code is 200") description= "Verify Manager user gets comments created by admin user with Rest API and status code is 200")
public void managerIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception public void managerIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
commentsAPI.getNodeComments(document.getNodeRef()); commentsAPI.getNodeComments(document);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY,
description= "Verify Contributor user gets comments created by admin user with Rest API and status code is 200") description= "Verify Contributor user gets comments created by admin user with Rest API and status code is 200")
public void contributorIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception public void contributorIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteContributor)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor));
commentsAPI.getNodeComments(document.getNodeRef()); commentsAPI.getNodeComments(document);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY,
description= "Verify Collaborator user gets comments created by admin user with Rest API and status code is 200") description= "Verify Collaborator user gets comments created by admin user with Rest API and status code is 200")
public void collaboratorIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception public void collaboratorIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteCollaborator)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
commentsAPI.getNodeComments(document.getNodeRef()); commentsAPI.getNodeComments(document);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY,
description= "Verify Consumer user gets comments created by admin user with Rest API and status code is 200") description= "Verify Consumer user gets comments created by admin user with Rest API and status code is 200")
public void consumerIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception public void consumerIsAbleToRetrieveComments() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteConsumer)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer));
commentsAPI.getNodeComments(document.getNodeRef()); commentsAPI.getNodeComments(document);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY,
@@ -98,33 +96,33 @@ public class GetCommentsSanityTest extends RestTest
{ {
UserModel nonexistentModel = new UserModel("nonexistentUser", "nonexistentPassword"); UserModel nonexistentModel = new UserModel("nonexistentUser", "nonexistentPassword");
restClient.authenticateUser(nonexistentModel); restClient.authenticateUser(nonexistentModel);
commentsAPI.getNodeComments(document.getNodeRef()); commentsAPI.getNodeComments(document);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED.toString()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.UNAUTHORIZED);
} }
@TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY,
description= "Verify Manager user gets comments created by another user and status code is 200") description= "Verify Manager user gets comments created by another user and status code is 200")
public void managerIsAbleToRetrieveCommentsCreatedByAnotherUser() throws JsonToModelConversionException, Exception public void managerIsAbleToRetrieveCommentsCreatedByAnotherUser() throws JsonToModelConversionException, Exception
{ {
userModel = usersWithRoles.get(UserRole.SiteCollaborator); userModel = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator);
restClient.authenticateUser(userModel); restClient.authenticateUser(userModel);
commentsAPI.addComment(document.getNodeRef(), "This is a new comment added by " + userModel.getUsername()); commentsAPI.addComment(document, "This is a new comment added by " + userModel.getUsername());
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED.toString()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED);
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
commentsAPI.getNodeComments(document.getNodeRef()); commentsAPI.getNodeComments(document);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, @TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY,
description= "Verify admin user gets comments created by another user and status code is 200") description= "Verify admin user gets comments created by another user and status code is 200")
public void adminIsAbleToRetrieveCommentsCreatedByAnotherUser() throws JsonToModelConversionException, Exception public void adminIsAbleToRetrieveCommentsCreatedByAnotherUser() throws JsonToModelConversionException, Exception
{ {
userModel = usersWithRoles.get(UserRole.SiteCollaborator); userModel = usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator);
restClient.authenticateUser(userModel); restClient.authenticateUser(userModel);
commentsAPI.addComment(document.getNodeRef(), "This is a new comment added by " + userModel.getUsername()); commentsAPI.addComment(document, "This is a new comment added by " + userModel.getUsername());
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED.toString()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.CREATED);
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
commentsAPI.getNodeComments(document.getNodeRef()); commentsAPI.getNodeComments(document);
commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK.toString()); commentsAPI.usingRestWrapper().assertStatusCodeIs(HttpStatus.OK);
} }
} }

View File

@@ -19,7 +19,8 @@ import org.springframework.social.alfresco.api.entities.Site.Visibility;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
public class RestDemoTest extends RestTest @Test(groups = { "demo" })
public class RestDemoTests extends RestTest
{ {
@Autowired @Autowired
RestSitesApi sitesApi; RestSitesApi sitesApi;
@@ -30,8 +31,8 @@ public class RestDemoTest extends RestTest
private UserModel userModel; private UserModel userModel;
private SiteModel siteModel; private SiteModel siteModel;
@BeforeClass @BeforeClass(alwaysRun=true)
public void setUp() throws DataPreparationException public void dataPreparation() throws DataPreparationException
{ {
userModel = dataUser.getAdminUser(); userModel = dataUser.getAdminUser();
siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); siteModel = dataSite.usingUser(userModel).createPublicRandomSite();
@@ -71,23 +72,23 @@ public class RestDemoTest extends RestTest
@Test @Test
public void adminCanPostAndUpdateComments() throws Exception public void adminCanPostAndUpdateComments() throws Exception
{ {
FileModel fileModel = dataContent.usingResource(new FolderModel("Shared")) FileModel fileModel = dataContent.usingUser(userModel)
.usingUser(userModel) .usingResource(FolderModel.getSharedFolderModel())
.createContent(DocumentType.TEXT_PLAIN); .createContent(DocumentType.TEXT_PLAIN);
// add new comment // add new comment
RestCommentModel commentEntry = commentsAPI.addComment(fileModel.getNodeRef(), "This is a new comment"); RestCommentModel commentEntry = commentsAPI.addComment(fileModel, "This is a new comment");
commentsAPI.getNodeComments(fileModel.getNodeRef()) commentsAPI.getNodeComments(fileModel)
.assertThatResponseIsNotEmpty() .assertThatResponseIsNotEmpty()
.assertThatCommentWithIdExists(commentEntry.getId()) .assertThatCommentWithIdExists(commentEntry)
.assertThatCommentWithContentExists("This is a new comment"); .assertThatCommentWithContentExists("This is a new comment");
// update comment // update comment
commentEntry = commentsAPI.updateComment(fileModel.getNodeRef(), commentEntry = commentsAPI.updateComment(fileModel,
commentEntry.getId(), commentEntry,
"This is the updated comment"); "This is the updated comment");
commentsAPI.getNodeComments(fileModel.getNodeRef()) commentsAPI.getNodeComments(fileModel)
.assertThatResponseIsNotEmpty() .assertThatResponseIsNotEmpty()
.assertThatCommentWithIdExists(commentEntry.getId()) .assertThatCommentWithIdExists(commentEntry)
.assertThatCommentWithContentExists("This is the updated comment"); .assertThatCommentWithContentExists("This is the updated comment");
} }
@@ -108,25 +109,22 @@ public class RestDemoTest extends RestTest
newUser.getUsername()); newUser.getUsername());
// add user as Consumer to site // add user as Consumer to site
sitesApi.addPerson(siteModel.getId(), siteMember); sitesApi.addPerson(siteModel, siteMember);
sitesApi.getSiteMembers(siteModel.getId()) sitesApi.getSiteMembers(siteModel)
.assertThatSiteHasMember(siteMember.getId()) .assertThatSiteHasMember(siteMember.getId())
.getSiteMember(siteMember.getId()) .getSiteMember(siteMember.getId())
.assertSiteMemberHasRole(Role.SiteConsumer); .assertSiteMemberHasRole(Role.SiteConsumer);
// update site member to Manager // update site member to Manager
siteMember.setRole(Role.SiteManager.toString()); siteMember.setRole(Role.SiteManager.toString());
sitesApi.updateSiteMember(siteModel.getId(), sitesApi.updateSiteMember(siteModel, newUser, siteMember);
newUser.getUsername(), siteMember); sitesApi.getSiteMembers(siteModel)
sitesApi.getSiteMembers(siteModel.getId())
.assertThatSiteHasMember(siteMember.getId()) .assertThatSiteHasMember(siteMember.getId())
.getSiteMember(siteMember.getId()) .getSiteMember(siteMember.getId())
.assertSiteMemberHasRole(Role.SiteManager); .assertSiteMemberHasRole(Role.SiteManager);
// delete site member sitesApi.deleteSiteMember(siteModel, newUser);
sitesApi.deleteSiteMember(siteModel.getId(),
newUser.getUsername());
sitesApi.usingRestWrapper() sitesApi.usingRestWrapper()
.assertStatusCodeIs(HttpStatus.NO_CONTENT.toString()); .assertStatusCodeIs(HttpStatus.NO_CONTENT);
} }
} }

View File

@@ -17,8 +17,8 @@ import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@Test(groups = { "rest-api", "comments", "sanity" }) @Test(groups = { "demo" })
public class SampleCommentsTest extends RestTest public class SampleCommentsTests extends RestTest
{ {
@Autowired @Autowired
DataUser dataUser; DataUser dataUser;
@@ -31,8 +31,8 @@ public class SampleCommentsTest extends RestTest
private SiteModel siteModel; private SiteModel siteModel;
private FileModel document; private FileModel document;
@BeforeClass @BeforeClass(alwaysRun=true)
public void initTest() throws Exception public void dataPreparation() throws Exception
{ {
userModel = dataUser.getAdminUser(); userModel = dataUser.getAdminUser();
siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); siteModel = dataSite.usingUser(userModel).createPublicRandomSite();
@@ -43,33 +43,33 @@ public class SampleCommentsTest extends RestTest
document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN); document = dataContent.usingUser(userModel).usingResource(folderModel).createContent(DocumentType.TEXT_PLAIN);
} }
@TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY,
description= "Verify admin user adds comments with Rest API and status code is 200") description= "Verify admin user adds comments with Rest API and status code is 200")
public void admiShouldAddComment() throws JsonToModelConversionException, Exception public void admiShouldAddComment() throws JsonToModelConversionException, Exception
{ {
commentsAPI.addComment(document.getNodeRef(), "This is a new comment"); commentsAPI.addComment(document, "This is a new comment");
commentsAPI.usingRestWrapper() commentsAPI.usingRestWrapper()
.assertStatusCodeIs(HttpStatus.CREATED.toString()); .assertStatusCodeIs(HttpStatus.CREATED);
} }
@TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY,
description= "Verify admin user gets comments with Rest API and status code is 200") description= "Verify admin user gets comments with Rest API and status code is 200")
public void admiShouldRetrieveComments() throws JsonToModelConversionException public void admiShouldRetrieveComments() throws JsonToModelConversionException
{ {
commentsAPI.getNodeComments(document.getNodeRef()); commentsAPI.getNodeComments(document);
commentsAPI.usingRestWrapper() commentsAPI.usingRestWrapper()
.assertStatusCodeIs(HttpStatus.OK.toString()); .assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section={"rest-api", "comments"}, executionType= ExecutionType.SANITY, @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY,
description= "Verify admin user updates comments with Rest API") description= "Verify admin user updates comments with Rest API")
public void adminShouldUpdateComment() throws JsonToModelConversionException, Exception public void adminShouldUpdateComment() throws JsonToModelConversionException, Exception
{ {
// add initial comment // add initial comment
String commentId = commentsAPI.addComment(document.getNodeRef(), "This is a new comment").getId(); RestCommentModel commentModel = commentsAPI.addComment(document, "This is a new comment");
// update comment // update comment
RestCommentModel commentEntry = commentsAPI.updateComment(document.getNodeRef(), commentId, "This is the updated comment"); RestCommentModel commentEntry = commentsAPI.updateComment(document, commentModel, "This is the updated comment");
commentEntry.assertCommentContentIs("This is the updated comment"); commentEntry.assertCommentContentIs("This is the updated comment");
} }

View File

@@ -13,8 +13,8 @@ import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@Test(groups = { "rest-api", "people", "sanity" }) @Test(groups = { "demo" })
public class SamplePeopleTest extends RestTest public class SamplePeopleTests extends RestTest
{ {
@Autowired @Autowired
RestPeopleApi peopleAPI; RestPeopleApi peopleAPI;
@@ -25,8 +25,8 @@ public class SamplePeopleTest extends RestTest
private UserModel userModel; private UserModel userModel;
private UserModel adminUser; private UserModel adminUser;
@BeforeClass @BeforeClass(alwaysRun=true)
public void setUp() throws DataPreparationException public void dataPreparation() throws DataPreparationException
{ {
userModel = dataUser.createUser(RandomStringUtils.randomAlphanumeric(20)); userModel = dataUser.createUser(RandomStringUtils.randomAlphanumeric(20));
adminUser = dataUser.getAdminUser(); adminUser = dataUser.getAdminUser();
@@ -34,23 +34,21 @@ public class SamplePeopleTest extends RestTest
peopleAPI.useRestClient(restClient); peopleAPI.useRestClient(restClient);
} }
@TestRail(section={"rest-api", "people"}, executionType= ExecutionType.SANITY, @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY,
description = "Verify admin user gets person with Rest API and response is not empty") description = "Verify admin user gets person with Rest API and response is not empty")
public void adminShouldRetrievePerson() throws Exception public void adminShouldRetrievePerson() throws Exception
{ {
peopleAPI.getPerson(userModel.getUsername()) peopleAPI.getPerson(userModel).assertResponseIsNotEmpty();
.assertResponseIsNotEmpty();
peopleAPI.usingRestWrapper() peopleAPI.usingRestWrapper()
.assertStatusCodeIs(HttpStatus.OK.toString()); .assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section={"rest-api", "people"}, executionType= ExecutionType.SANITY, @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY,
description = "Admin user gets own person information with Rest Api and assert that name is correct") description = "Admin user gets own person information with Rest Api and assert that name is correct")
public void adminShouldRetrieveItself() throws Exception public void adminShouldRetrieveItself() throws Exception
{ {
peopleAPI.getPerson(adminUser.getUsername()) peopleAPI.getPerson(adminUser).assertPersonHasName(adminUser);
.assertPersonHasName(adminUser.getUsername());
} }
} }

View File

@@ -17,8 +17,8 @@ import org.springframework.social.alfresco.api.entities.Role;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@Test(groups = { "rest-api", "people", "sanity" }) @Test(groups = { "demo" })
public class SampleSitesTest extends RestTest public class SampleSitesTests extends RestTest
{ {
@Autowired @Autowired
RestSitesApi siteAPI; RestSitesApi siteAPI;
@@ -32,8 +32,8 @@ public class SampleSitesTest extends RestTest
private UserModel userModel; private UserModel userModel;
private SiteModel siteModel; private SiteModel siteModel;
@BeforeClass @BeforeClass(alwaysRun=true)
public void initTest() throws DataPreparationException public void dataPreparation() throws DataPreparationException
{ {
userModel = dataUser.getAdminUser(); userModel = dataUser.getAdminUser();
restClient.authenticateUser(userModel); restClient.authenticateUser(userModel);
@@ -41,24 +41,24 @@ public class SampleSitesTest extends RestTest
siteAPI.useRestClient(restClient); siteAPI.useRestClient(restClient);
} }
@TestRail(section={"rest-api", "sites"}, executionType= ExecutionType.SANITY, @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY,
description = "Verify admin user gets site details with Rest API and response is not empty") description = "Verify admin user gets site details with Rest API and response is not empty")
public void adminShouldGetSiteDetails() throws JsonToModelConversionException, Exception public void adminShouldGetSiteDetails() throws JsonToModelConversionException, Exception
{ {
siteAPI.getSite(siteModel.getId()) siteAPI.getSite(siteModel)
.assertResponseIsNotEmpty(); .assertResponseIsNotEmpty();
} }
@TestRail(section={"rest-api", "sites"}, executionType= ExecutionType.SANITY, @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY,
description = "Verify admin user gets site information and gets status code OK (200)") description = "Verify admin user gets site information and gets status code OK (200)")
public void adminShouldGetSites() throws JsonToModelConversionException, Exception public void adminShouldGetSites() throws JsonToModelConversionException, Exception
{ {
siteAPI.getSite(siteModel.getId()); siteAPI.getSite(siteModel);
siteAPI.usingRestWrapper() siteAPI.usingRestWrapper()
.assertStatusCodeIs(HttpStatus.OK.toString()); .assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section={"rest-api", "sites"}, executionType= ExecutionType.SANITY, @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY,
description = "Verify admin user gets sites with Rest API and the response is not empty") description = "Verify admin user gets sites with Rest API and the response is not empty")
public void adminShouldAccessSites() throws JsonToModelConversionException, Exception public void adminShouldAccessSites() throws JsonToModelConversionException, Exception
{ {
@@ -66,16 +66,16 @@ public class SampleSitesTest extends RestTest
.assertThatResponseIsNotEmpty(); .assertThatResponseIsNotEmpty();
} }
@TestRail(section={"rest-api", "sites"}, executionType= ExecutionType.SANITY, @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY,
description = "Verify admin user gets sites with Rest API and status code is 200") description = "Verify admin user gets sites with Rest API and status code is 200")
public void adminShouldRetrieveSites() throws JsonToModelConversionException, Exception public void adminShouldRetrieveSites() throws JsonToModelConversionException, Exception
{ {
siteAPI.getSites(); siteAPI.getSites();
siteAPI.usingRestWrapper() siteAPI.usingRestWrapper()
.assertStatusCodeIs(HttpStatus.OK.toString()); .assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section={"rest-api", "sites"}, executionType= ExecutionType.SANITY, @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY,
description = "Verify admin user gets sites with Rest API and status code is 200") description = "Verify admin user gets sites with Rest API and status code is 200")
public void adminShouldAccessResponsePagination() throws JsonToModelConversionException, Exception public void adminShouldAccessResponsePagination() throws JsonToModelConversionException, Exception
{ {
@@ -83,31 +83,31 @@ public class SampleSitesTest extends RestTest
.assertResponseHasPagination(); .assertResponseHasPagination();
} }
@TestRail(section={"rest-api", "sites"}, executionType= ExecutionType.SANITY, @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY,
description = "Verify admin user adds site member with Rest API and status code is 201") description = "Verify admin user adds site member with Rest API and status code is 201")
public void adminShouldAddNewSiteMember() throws JsonToModelConversionException, DataPreparationException, Exception public void adminShouldAddNewSiteMember() throws JsonToModelConversionException, DataPreparationException, Exception
{ {
UserModel newMember = dataUser.createRandomTestUser(); UserModel newMember = dataUser.createRandomTestUser();
SiteMember siteMember = new SiteMember(Role.SiteCollaborator.toString(), newMember.getUsername()); SiteMember siteMember = new SiteMember(Role.SiteCollaborator.toString(), newMember.getUsername());
siteAPI.addPerson(siteModel.getId(), siteMember); siteAPI.addPerson(siteModel, siteMember);
siteAPI.usingRestWrapper() siteAPI.usingRestWrapper()
.assertStatusCodeIs(HttpStatus.CREATED.toString()); .assertStatusCodeIs(HttpStatus.CREATED);
} }
@TestRail(section={"rest-api", "sites"}, executionType= ExecutionType.SANITY, @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY,
description = "Verify that site exists from get all sites request") description = "Verify that site exists from get all sites request")
public void adminShouldGetSiteFromSitesList() throws JsonToModelConversionException, Exception public void adminShouldGetSiteFromSitesList() throws JsonToModelConversionException, Exception
{ {
siteAPI.getAllSites() siteAPI.getAllSites()
.assertThatResponseHasSite(siteModel.getId()); .assertThatResponseHasSite(siteModel);
} }
@TestRail(section={"rest-api", "sites"}, executionType= ExecutionType.SANITY, @TestRail(section={"demo", "sample-section"}, executionType= ExecutionType.SANITY,
description = "Verify site details: response not empty, description, title, visibility") description = "Verify site details: response not empty, description, title, visibility")
public void adminShouldAccessSiteDetails() throws JsonToModelConversionException, Exception public void adminShouldAccessSiteDetails() throws JsonToModelConversionException, Exception
{ {
siteAPI.getSite(siteModel.getId()) siteAPI.getSite(siteModel)
.assertResponseIsNotEmpty() .assertResponseIsNotEmpty()
.assertSiteHasDescription(siteModel.getDescription()) .assertSiteHasDescription(siteModel.getDescription())
.assertSiteHasTitle(siteModel.getTitle()) .assertSiteHasTitle(siteModel.getTitle())

View File

@@ -1,8 +1,5 @@
package org.alfresco.rest.sites; package org.alfresco.rest.sites;
import java.util.Arrays;
import java.util.HashMap;
import org.alfresco.rest.RestTest; import org.alfresco.rest.RestTest;
import org.alfresco.rest.body.SiteMembership; import org.alfresco.rest.body.SiteMembership;
import org.alfresco.rest.exception.JsonToModelConversionException; import org.alfresco.rest.exception.JsonToModelConversionException;
@@ -10,9 +7,11 @@ import org.alfresco.rest.requests.RestSitesApi;
import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataSite; import org.alfresco.utility.data.DataSite;
import org.alfresco.utility.data.DataUser; import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.exception.DataPreparationException; import org.alfresco.utility.exception.DataPreparationException;
import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel; import org.alfresco.utility.model.UserModel;
import org.alfresco.utility.report.Bug;
import org.alfresco.utility.testrail.ExecutionType; import org.alfresco.utility.testrail.ExecutionType;
import org.alfresco.utility.testrail.annotation.TestRail; import org.alfresco.utility.testrail.annotation.TestRail;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -20,7 +19,7 @@ import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@Test(groups = { "rest-api", "sites", "sanity" }) @Test(groups = { "rest-api", "sites", "sanity" })
public class AddSiteMembershipRequestSanityTest extends RestTest public class AddSiteMembershipRequestSanityTests extends RestTest
{ {
@Autowired @Autowired
RestSitesApi siteAPI; RestSitesApi siteAPI;
@@ -33,32 +32,31 @@ public class AddSiteMembershipRequestSanityTest extends RestTest
private SiteModel siteModel; private SiteModel siteModel;
private HashMap<UserRole, UserModel> usersWithRoles; private ListUserWithRoles usersWithRoles;
private UserModel adminUser; private UserModel adminUser;
@BeforeClass @BeforeClass(alwaysRun=true)
public void initTest() throws DataPreparationException public void initTest() throws DataPreparationException
{ {
adminUser = dataUser.getAdminUser(); adminUser = dataUser.getAdminUser();
siteModel = dataSite.usingUser(adminUser).createPublicRandomSite(); siteModel = dataSite.usingUser(adminUser).createPublicRandomSite();
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel,UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor);
Arrays.asList(UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor));
siteAPI.useRestClient(restClient); siteAPI.useRestClient(restClient);
} }
@TestRail(section = { "rest-api", @TestRail(section = { "rest-api","sites" }, executionType = ExecutionType.SANITY, description = "Verify site manager is able to create new site membership request")
"sites" }, executionType = ExecutionType.SANITY, description = "Verify site manager is able to create new site membership request") @Bug(id="MNT-16557")
@Test(enabled = false, description = "Fails due to MNT-16557") @Test(enabled=false)
public void siteManagerCanCreateSiteMembershipRequest() throws JsonToModelConversionException, Exception public void siteManagerCanCreateSiteMembershipRequest() throws JsonToModelConversionException, Exception
{ {
UserModel newMember = dataUser.createRandomTestUser(); UserModel newMember = dataUser.createRandomTestUser();
SiteMembership siteMembership = new SiteMembership("Please accept me", siteModel.getId(), "New request"); SiteMembership siteMembership = new SiteMembership("Please accept me", siteModel.getId(), "New request");
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
siteAPI.addSiteMembershipRequest(newMember.getUsername(), siteMembership); siteAPI.addSiteMembershipRequest(newMember, siteMembership);
siteAPI.getSite(siteModel.getId()).assertResponseIsNotEmpty(); siteAPI.getSite(siteModel).assertResponseIsNotEmpty();
} }
} }

View File

@@ -1,15 +1,12 @@
package org.alfresco.rest.sites; package org.alfresco.rest.sites;
import java.util.Arrays;
import java.util.HashMap;
import org.alfresco.rest.RestTest; import org.alfresco.rest.RestTest;
import org.alfresco.rest.exception.JsonToModelConversionException; import org.alfresco.rest.exception.JsonToModelConversionException;
import org.alfresco.rest.requests.RestSitesApi; import org.alfresco.rest.requests.RestSitesApi;
import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataSite; import org.alfresco.utility.data.DataSite;
import org.alfresco.utility.data.DataUser; import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.data.TestData; import org.alfresco.utility.data.DataUser.ListUserWithRoles;
import org.alfresco.utility.exception.DataPreparationException; import org.alfresco.utility.exception.DataPreparationException;
import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel; import org.alfresco.utility.model.UserModel;
@@ -21,7 +18,7 @@ import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@Test(groups = { "rest-api", "sites", "sanity" }) @Test(groups = { "rest-api", "sites", "sanity" })
public class GetSiteMembershipInformationSanityTest extends RestTest public class GetSiteMembershipInformationSanityTests extends RestTest
{ {
@Autowired @Autowired
RestSitesApi siteAPI; RestSitesApi siteAPI;
@@ -34,15 +31,14 @@ public class GetSiteMembershipInformationSanityTest extends RestTest
private SiteModel siteModel; private SiteModel siteModel;
private UserModel adminUser; private UserModel adminUser;
private HashMap<UserRole, UserModel> usersWithRoles; private ListUserWithRoles usersWithRoles;
@BeforeClass @BeforeClass(alwaysRun=true)
public void initTest() throws DataPreparationException public void dataPreparation() throws DataPreparationException
{ {
adminUser = dataUser.getAdminUser(); adminUser = dataUser.getAdminUser();
siteModel = dataSite.usingUser(adminUser).createPublicRandomSite(); siteModel = dataSite.usingUser(adminUser).createPublicRandomSite();
usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, usersWithRoles = dataUser.addUsersWithRolesToSite(siteModel, UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor);
Arrays.asList(UserRole.SiteManager, UserRole.SiteCollaborator, UserRole.SiteConsumer, UserRole.SiteContributor));
siteAPI.useRestClient(restClient); siteAPI.useRestClient(restClient);
} }
@@ -52,10 +48,10 @@ public class GetSiteMembershipInformationSanityTest extends RestTest
description = "Verify site manager is able to retrieve site membership information of another user") description = "Verify site manager is able to retrieve site membership information of another user")
public void siteManagerCanRetrieveSiteMembershipInformation() throws JsonToModelConversionException, Exception public void siteManagerCanRetrieveSiteMembershipInformation() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteManager)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
siteAPI.getSiteMembershipInformation(adminUser.getUsername()); siteAPI.getSiteMembershipInformation(adminUser.getUsername());
siteAPI.usingRestWrapper() siteAPI.usingRestWrapper()
.assertStatusCodeIs(HttpStatus.OK.toString()); .assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section = { "rest-api", "sites" }, @TestRail(section = { "rest-api", "sites" },
@@ -63,10 +59,10 @@ public class GetSiteMembershipInformationSanityTest extends RestTest
description = "Verify site collaborator is able to retrieve site membership information of another user") description = "Verify site collaborator is able to retrieve site membership information of another user")
public void siteCollaboratorCanRetrieveSiteMembershipInformation() throws JsonToModelConversionException, Exception public void siteCollaboratorCanRetrieveSiteMembershipInformation() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteCollaborator)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
siteAPI.getSiteMembershipInformation(adminUser.getUsername()); siteAPI.getSiteMembershipInformation(adminUser.getUsername());
siteAPI.usingRestWrapper() siteAPI.usingRestWrapper()
.assertStatusCodeIs(HttpStatus.OK.toString()); .assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section = { "rest-api", "sites" }, @TestRail(section = { "rest-api", "sites" },
@@ -74,10 +70,10 @@ public class GetSiteMembershipInformationSanityTest extends RestTest
description = "Verify site contributor is able to retrieve site membership information of another user") description = "Verify site contributor is able to retrieve site membership information of another user")
public void siteContributorCanRetrieveSiteMembershipInformation() throws JsonToModelConversionException, Exception public void siteContributorCanRetrieveSiteMembershipInformation() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteContributor)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor));
siteAPI.getSiteMembershipInformation(adminUser.getUsername()); siteAPI.getSiteMembershipInformation(adminUser.getUsername());
siteAPI.usingRestWrapper() siteAPI.usingRestWrapper()
.assertStatusCodeIs(HttpStatus.OK.toString()); .assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section = { "rest-api", "sites" }, @TestRail(section = { "rest-api", "sites" },
@@ -85,10 +81,10 @@ public class GetSiteMembershipInformationSanityTest extends RestTest
description = "Verify site consumer is able to retrieve site membership information of another user") description = "Verify site consumer is able to retrieve site membership information of another user")
public void siteConsumerCanRetrieveSiteMembershipInformation() throws JsonToModelConversionException, Exception public void siteConsumerCanRetrieveSiteMembershipInformation() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(usersWithRoles.get(UserRole.SiteConsumer)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer));
siteAPI.getSiteMembershipInformation(adminUser.getUsername()); siteAPI.getSiteMembershipInformation(adminUser.getUsername());
siteAPI.usingRestWrapper() siteAPI.usingRestWrapper()
.assertStatusCodeIs(HttpStatus.OK.toString()); .assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section = { "rest-api", "sites" }, @TestRail(section = { "rest-api", "sites" },
@@ -97,9 +93,9 @@ public class GetSiteMembershipInformationSanityTest extends RestTest
public void siteAdminCanRetrieveSiteMembershipInformation() throws JsonToModelConversionException, Exception public void siteAdminCanRetrieveSiteMembershipInformation() throws JsonToModelConversionException, Exception
{ {
restClient.authenticateUser(adminUser); restClient.authenticateUser(adminUser);
siteAPI.getSiteMembershipInformation(usersWithRoles.get(UserRole.SiteManager).getUsername()); siteAPI.getSiteMembershipInformation(usersWithRoles.getOneUserWithRole(UserRole.SiteManager).getUsername());
siteAPI.usingRestWrapper() siteAPI.usingRestWrapper()
.assertStatusCodeIs(HttpStatus.OK.toString()); .assertStatusCodeIs(HttpStatus.OK);
} }
@TestRail(section = { "rest-api", "sites" }, @TestRail(section = { "rest-api", "sites" },
@@ -109,9 +105,9 @@ public class GetSiteMembershipInformationSanityTest extends RestTest
{ {
UserModel inexistentUser = new UserModel("inexistent user", "wrong password"); UserModel inexistentUser = new UserModel("inexistent user", "wrong password");
restClient.authenticateUser(inexistentUser); restClient.authenticateUser(inexistentUser);
siteAPI.getSiteMembershipInformation(usersWithRoles.get(UserRole.SiteManager).getUsername()); siteAPI.getSiteMembershipInformation(usersWithRoles.getOneUserWithRole(UserRole.SiteManager).getUsername());
siteAPI.usingRestWrapper() siteAPI.usingRestWrapper()
.assertStatusCodeIs(HttpStatus.UNAUTHORIZED.toString()); .assertStatusCodeIs(HttpStatus.UNAUTHORIZED);
} }
} }

View File

@@ -1,17 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="REST API DEMO TESTS" parallel="classes"> <suite name="REST API DEMO TESTS" parallel="classes" preserve-order="true" thread-count="5">
<listeners> <listeners>
<listener class-name="org.alfresco.utility.report.ReportListenerAdapter"></listener> <listener class-name="org.alfresco.utility.report.ReportListenerAdapter"></listener>
<listener class-name="org.alfresco.utility.testrail.TestRailExecutorListener"></listener> <listener class-name="org.alfresco.utility.testrail.TestRailExecutorListener"></listener>
<listener class-name="org.alfresco.utility.report.log.LogsListener"></listener> <listener class-name="org.alfresco.utility.report.log.LogsListener"></listener>
</listeners> </listeners>
<test name="Test"> <test name="RestAPI Sanity Tests">
<classes> <groups>
<class name="org.alfresco.rest.demo.SamplePeopleTest"></class> <run>
<class name="org.alfresco.rest.demo.SampleSitesTest"></class> <include name="sanity" />
<class name="org.alfresco.rest.demo.SampleCommentsTest"></class> <exclude name="demo"></exclude>
</classes> <exclude name=""></exclude>
</run>
</groups>
<packages>
<package name="org.alfresco.rest.*"></package>
</packages>
</test> <!-- Test --> </test> <!-- Test -->
</suite> <!-- Suite --> </suite> <!-- Suite -->