TAS-2936: add full tests for 'get /tasks/{taskId}/candidates'

This commit is contained in:
Bogdan Bocancea
2017-02-07 15:01:36 +02:00
parent b41f75263b
commit 7de693b069
@@ -0,0 +1,215 @@
package org.alfresco.rest.workflow.tasks;
import org.alfresco.dataprep.CMISUtil.DocumentType;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestCandidateModelsCollection;
import org.alfresco.rest.model.RestErrorModel;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.GroupModel;
import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.TaskModel;
import org.alfresco.utility.model.TestGroup;
import org.alfresco.utility.model.UserModel;
import org.alfresco.utility.report.Bug;
import org.alfresco.utility.testrail.ExecutionType;
import org.alfresco.utility.testrail.annotation.TestRail;
import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
*
* @author bogdan.bocancea
*
*/
public class GetTaskCandidatesFullTests extends RestTest
{
private UserModel userModel, userModel1, userModel2;
private SiteModel siteModel;
private FileModel fileModel;
private TaskModel taskModel;
private GroupModel group;
private RestCandidateModelsCollection candidateModels;
@BeforeClass(alwaysRun=true)
public void dataPreparation() throws Exception
{
userModel = dataUser.createRandomTestUser();
siteModel = dataSite.usingUser(userModel).createPublicRandomSite();
fileModel = dataContent.usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN);
userModel1 = dataUser.createRandomTestUser();
userModel2 = dataUser.createRandomTestUser();
group = dataGroup.createRandomGroup();
dataGroup.addListOfUsersToGroup(group, userModel1, userModel2);
}
@Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL })
@TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION,
description = "Check default error model schema for get task candidates")
public void getTaskCandidatesErrorSchemaCheck() throws Exception
{
taskModel = dataWorkflow.usingUser(userModel)
.usingSite(siteModel)
.usingResource(fileModel).createPooledReviewTaskAndAssignTo(group);
taskModel.setId("invalid-id");
restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).getTaskCandidates();
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND)
.assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalid-id"))
.containsErrorKey(RestErrorModel.ENTITY_NOT_FOUND_ERRORKEY)
.stackTraceIs(RestErrorModel.STACKTRACE)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER);
}
@Bug(id="MNT-17438")
@Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL })
@TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION,
description = "Get task candidates with skip count parameter")
public void getTaskCandidatesWithSkipCount() throws Exception
{
taskModel = dataWorkflow.usingUser(userModel)
.usingSite(siteModel)
.usingResource(fileModel).createPooledReviewTaskAndAssignTo(group);
candidateModels = restClient.authenticateUser(userModel).withWorkflowAPI()
.usingParams("skipCount=1").usingTask(taskModel).getTaskCandidates();
restClient.assertStatusCodeIs(HttpStatus.OK);
candidateModels.assertThat()
.entriesListIsNotEmpty()
.and().paginationField("count").is("0");
}
@Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL })
@TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION,
description = "Get task candidates with max items parameter set to 0")
public void getTaskCandidatesWithZeroMaxItems() throws Exception
{
taskModel = dataWorkflow.usingUser(userModel)
.usingSite(siteModel)
.usingResource(fileModel).createPooledReviewTaskAndAssignTo(group);
candidateModels = restClient.authenticateUser(userModel).withWorkflowAPI()
.usingParams("maxItems=0").usingTask(taskModel).getTaskCandidates();
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError().containsErrorKey(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS)
.containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS)
.stackTraceIs(RestErrorModel.STACKTRACE)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER);
}
@Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL })
@TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION,
description = "Get task candidates with max items parameter")
public void getTaskCandidatesWithMaxItems() throws Exception
{
taskModel = dataWorkflow.usingUser(userModel)
.usingSite(siteModel)
.usingResource(fileModel).createPooledReviewTaskAndAssignTo(group);
candidateModels = restClient.authenticateUser(userModel).withWorkflowAPI()
.usingParams("maxItems=2").usingTask(taskModel).getTaskCandidates();
restClient.assertStatusCodeIs(HttpStatus.OK);
candidateModels.assertThat()
.entriesListIsNotEmpty()
.and().paginationField("count").is("1");
}
@Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL })
@TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION,
description = "Get task candidates with properties")
public void getTaskCandidatesWithProperties() throws Exception
{
taskModel = dataWorkflow.usingUser(userModel)
.usingSite(siteModel)
.usingResource(fileModel).createPooledReviewTaskAndAssignTo(group);
candidateModels = restClient.authenticateUser(userModel).withWorkflowAPI()
.usingParams("properties=candidateId").usingTask(taskModel).getTaskCandidates();
restClient.assertStatusCodeIs(HttpStatus.OK);
candidateModels.getEntries().get(0).onModel().assertThat()
.field("candidateId").contains(group.getGroupIdentifier()).and()
.field("candidateType").isNull();
}
@Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL })
@TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION,
description = "Get task candidates with invalid properties")
public void getTaskCandidatesWithInvalidProperties() throws Exception
{
taskModel = dataWorkflow.usingUser(userModel)
.usingSite(siteModel)
.usingResource(fileModel).createPooledReviewTaskAndAssignTo(group);
candidateModels = restClient.authenticateUser(userModel).withWorkflowAPI()
.usingParams("properties=unknown-prop").usingTask(taskModel).getTaskCandidates();
restClient.assertStatusCodeIs(HttpStatus.OK);
candidateModels.getEntries().get(0).onModel().assertThat()
.fieldsCount().is(0).and();
}
@Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL })
@TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION,
description = "Get task candidates by deleted candidate")
public void getTaskCandidatesByDeletedCandidate() throws Exception
{
taskModel = dataWorkflow.usingUser(userModel)
.usingSite(siteModel)
.usingResource(fileModel).createPooledReviewTaskAndAssignTo(group);
restClient.authenticateUser(userModel1).withWorkflowAPI()
.usingTask(taskModel).getTaskCandidates();
restClient.assertStatusCodeIs(HttpStatus.OK);
dataUser.usingAdmin().deleteUser(userModel1);
restClient.authenticateUser(userModel1).withWorkflowAPI()
.usingTask(taskModel).getTaskCandidates();
restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED)
.assertLastError().containsErrorKey(RestErrorModel.API_DEFAULT_ERRORKEY)
.containsSummary(RestErrorModel.AUTHENTICATION_FAILED)
.stackTraceIs(RestErrorModel.STACKTRACE)
.descriptionURLIs(RestErrorModel.RESTAPIEXPLORER);
}
@Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL })
@TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION,
description = "Get task candidates by deleted group")
public void getTaskCandidatesByDeletedGroup() throws Exception
{
GroupModel deletedGroup = dataGroup.createRandomGroup();
UserModel newUser = dataUser.createRandomTestUser();
dataGroup.addListOfUsersToGroup(deletedGroup, userModel2, newUser);
taskModel = dataWorkflow.usingUser(userModel)
.usingSite(siteModel)
.usingResource(fileModel).createPooledReviewTaskAndAssignTo(deletedGroup);
restClient.authenticateUser(newUser).withWorkflowAPI()
.usingTask(taskModel).getTaskCandidates();
restClient.assertStatusCodeIs(HttpStatus.OK);
dataGroup.usingAdmin().deleteGroup(deletedGroup);
restClient.authenticateUser(newUser).withWorkflowAPI()
.usingTask(taskModel).getTaskCandidates();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN)
.assertLastError().containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY)
.containsSummary(RestErrorModel.PERMISSION_WAS_DENIED)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
@Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL })
@TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION,
description = "Get task candidates by user that was removed from group")
public void getTaskCandidatesByUserRemovedFromGroup() throws Exception
{
UserModel newUser = dataUser.createRandomTestUser();
dataGroup.addListOfUsersToGroup(group, newUser);
taskModel = dataWorkflow.usingUser(userModel)
.usingSite(siteModel)
.usingResource(fileModel).createPooledReviewTaskAndAssignTo(group);
restClient.authenticateUser(newUser).withWorkflowAPI()
.usingTask(taskModel).getTaskCandidates();
restClient.assertStatusCodeIs(HttpStatus.OK);
dataGroup.usingAdmin().removeUserFromGroup(group, newUser);
restClient.authenticateUser(newUser).withWorkflowAPI()
.usingTask(taskModel).getTaskCandidates();
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN)
.assertLastError().containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY)
.containsSummary(RestErrorModel.PERMISSION_WAS_DENIED)
.stackTraceIs(RestErrorModel.STACKTRACE);
}
}