diff --git a/e2e-test/java/org/alfresco/rest/workflow/tasks/AddTaskVariablesFullTests.java b/e2e-test/java/org/alfresco/rest/workflow/tasks/AddTaskVariablesFullTests.java new file mode 100644 index 000000000..ceba3ab3f --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/workflow/tasks/AddTaskVariablesFullTests.java @@ -0,0 +1,129 @@ +package org.alfresco.rest.workflow.tasks; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestTaskModel; +import org.alfresco.rest.model.RestVariableModel; +import org.alfresco.utility.model.FileModel; +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.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 AddTaskVariablesFullTests extends RestTest +{ + private UserModel userWhoStartsTask, adminUser; + private SiteModel siteModel; + private FileModel fileModel; + private UserModel assigneeUser; + private TaskModel taskModel; + private RestVariableModel restVariablemodel; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userWhoStartsTask = dataUser.createRandomTestUser(); + assigneeUser = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(adminUser).createPublicRandomSite(); + fileModel = dataContent.usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL }) + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Create task variable with name containing symbols") + public void createTaskVariableWithSymbolsInName() throws Exception + { + UserModel adminUser = dataUser.getAdminUser(); + restClient.authenticateUser(adminUser); + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + variableModel.setName("!@#$%^&*({}<>.,;'=_|"); + restVariablemodel = restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restVariablemodel.assertThat() + .field("scope").is(variableModel.getScope()) + .and().field("name").is(variableModel.getName()) + .and().field("value").is(variableModel.getValue()) + .and().field("type").is(variableModel.getType()); + } + + @Test(groups = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL }) + @TestRail(section = {TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Create task variable with empty name") + public void createTaskVariableWithEmptyName() throws Exception + { + UserModel adminUser = dataUser.getAdminUser(); + restClient.authenticateUser(adminUser); + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + variableModel.setName(""); + restVariablemodel = restClient.withWorkflowAPI().usingTask(taskModel).addTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsErrorKey(RestErrorModel.VARIABLE_NAME_REQUIRED) + .containsSummary(RestErrorModel.VARIABLE_NAME_REQUIRED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL, TestGroup.NETWORKS }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that admin from the same network is able to add task variables") + public void addTaskVariablesByTenantAdmin() throws Exception + { + UserModel adminTenantUser1 = UserModel.getAdminTenantUser(); + restClient.authenticateUser(dataUser.getAdminUser()).usingTenant().createTenant(adminTenantUser1); + UserModel tenantUser1 = dataUser.usingUser(adminTenantUser1).createUserWithTenant("uTenant1"); + + RestProcessModel networkProcess1 = restClient.authenticateUser(tenantUser1).withWorkflowAPI() + .addProcess("activitiReview", tenantUser1, false, CMISUtil.Priority.High); + RestTaskModel task = restClient.authenticateUser(adminTenantUser1) + .withWorkflowAPI().usingProcess(networkProcess1).getProcessTasks().getOneRandomEntry(); + restClient.authenticateUser(adminTenantUser1); + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + restVariablemodel = restClient.withWorkflowAPI() + .usingTask(task.onModel()) + .addTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + restVariablemodel.assertThat() + .field("scope").is(variableModel.getScope()) + .and().field("name").is(variableModel.getName()) + .and().field("value").is(variableModel.getValue()) + .and().field("type").is(variableModel.getType()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL, TestGroup.NETWORKS }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that admin from another network is not able to add task variables") + public void addTaskVariablesByTenantFromAnotherNetwork() throws Exception + { + UserModel adminTenantUser1 = UserModel.getAdminTenantUser(); + UserModel adminTenantUser2 = UserModel.getAdminTenantUser(); + restClient.authenticateUser(dataUser.getAdminUser()).usingTenant().createTenant(adminTenantUser1); + restClient.authenticateUser(dataUser.getAdminUser()).usingTenant().createTenant(adminTenantUser2); + UserModel tenantUser1 = dataUser.usingUser(adminTenantUser1).createUserWithTenant("uTenant1"); + + RestProcessModel networkProcess1 = restClient.authenticateUser(tenantUser1).withWorkflowAPI() + .addProcess("activitiReview", tenantUser1, false, CMISUtil.Priority.High); + RestTaskModel task = restClient.authenticateUser(adminTenantUser1) + .withWorkflowAPI().usingProcess(networkProcess1).getProcessTasks().getOneRandomEntry(); + restClient.authenticateUser(adminTenantUser1); + RestVariableModel variableModel = RestVariableModel.getRandomTaskVariableModel("local", "d:text"); + restVariablemodel = restClient.authenticateUser(adminTenantUser2).withWorkflowAPI() + .usingTask(task.onModel()) + .addTaskVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } +} diff --git a/e2e-test/java/org/alfresco/rest/workflow/tasks/GetTaskVariablesFullTests.java b/e2e-test/java/org/alfresco/rest/workflow/tasks/GetTaskVariablesFullTests.java new file mode 100644 index 000000000..cc1faf53d --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/workflow/tasks/GetTaskVariablesFullTests.java @@ -0,0 +1,176 @@ +package org.alfresco.rest.workflow.tasks; + +import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestTaskModel; +import org.alfresco.rest.model.RestVariableModelsCollection; +import org.alfresco.utility.model.FileModel; +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; + +public class GetTaskVariablesFullTests extends RestTest +{ + private UserModel userWhoStartsTask, assignee; + private SiteModel siteModel; + private FileModel fileModel; + private TaskModel taskModel; + private RestVariableModelsCollection variableModels; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + userWhoStartsTask = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsTask).createPublicRandomSite(); + fileModel = dataContent.usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify default error shema for get task variables") + public void getTaskVariablesCheckDefaultErrorSchema() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask) + .usingSite(siteModel).usingResource(fileModel) + .createNewTaskAndAssignTo(assignee); + taskModel.setId("invalidId"); + + restClient.authenticateUser(userWhoStartsTask).withWorkflowAPI().usingTask(taskModel).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidId")) + .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.CORE }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify user gets task with 'maxItems' parameter") + public void getTaskVariablesWithMaxItems() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assignee); + variableModels = restClient.authenticateUser(userWhoStartsTask) + .withWorkflowAPI().usingParams("maxItems=2").usingTask(taskModel).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variableModels.assertThat().entriesListIsNotEmpty() + .and().paginationField("count").is("2"); + } + + @Bug(id="MNT-17438") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.CORE }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify user gets task with 'skipCount' parameter") + public void getTaskVariablesWithSkipCount() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assignee); + variableModels = restClient.authenticateUser(userWhoStartsTask) + .withWorkflowAPI().usingParams("skipCount=10").usingTask(taskModel).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variableModels.assertThat().entriesListIsNotEmpty() + .and().paginationField("count").is("20"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify user cannot get task variables with invalid where clause.") + public void getTaskVariablesWithInvalidWhereClauseAsParameter() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assignee); + variableModels = restClient.authenticateUser(userWhoStartsTask).where("scope='fake-where'") + .withWorkflowAPI().usingTask(taskModel).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_WHERE_QUERY, "Invalid value for 'scope' used in query: fake-where.")) + .containsErrorKey(RestErrorModel.INVALID_QUERY_ERRORKEY) + .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 = "Verify user gets tasks variables with 'properties' parameter") + public void getTaskVariablesWithValidProperties() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assignee); + variableModels = restClient.authenticateUser(userWhoStartsTask).withParams("properties=scope,name") + .withWorkflowAPI().usingTask(taskModel).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variableModels.assertThat().entriesListIsNotEmpty(); + variableModels.getOneRandomEntry().onModel().assertThat() + .fieldsCount().is(2).and() + .field("type").isNull().and() + .field("value").isNull().and() + .field("scope").isNotEmpty().and() + .field("name").isNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify user cannot get tasks variables with invalid 'properties' parameter") + public void getTaskVariablesWithInvalidProperties() throws Exception + { + taskModel = dataWorkflow.usingUser(userWhoStartsTask).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assignee); + variableModels = restClient.authenticateUser(userWhoStartsTask).withParams("properties=fake") + .withWorkflowAPI().usingTask(taskModel).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variableModels.getOneRandomEntry().onModel().assertThat() + .fieldsCount().is(0).and() + .field("type").isNull().and() + .field("value").isNull().and() + .field("scope").isNull().and() + .field("name").isNull(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL, TestGroup.NETWORKS }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that admin from the same network is able to retrieve network task variables") + public void getTaskVariablesByTenantAdmin() throws Exception + { + UserModel adminTenantUser1 = UserModel.getAdminTenantUser(); + restClient.authenticateUser(dataUser.getAdminUser()).usingTenant().createTenant(adminTenantUser1); + UserModel tenantUser1 = dataUser.usingUser(adminTenantUser1).createUserWithTenant("uTenant1"); + + RestProcessModel networkProcess1 = restClient.authenticateUser(tenantUser1).withWorkflowAPI() + .addProcess("activitiReview", tenantUser1, false, CMISUtil.Priority.High); + RestTaskModel task = restClient.authenticateUser(adminTenantUser1) + .withWorkflowAPI().usingProcess(networkProcess1).getProcessTasks().getOneRandomEntry(); + + variableModels = restClient.withWorkflowAPI().usingTask(task.onModel()).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.OK); + variableModels.assertThat().entriesListIsNotEmpty(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL, TestGroup.NETWORKS }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify that admin from another network is not able to retrieve network task variables") + public void getTaskVariablesByTenantFromAnotherNetwork() throws Exception + { + UserModel adminTenantUser1 = UserModel.getAdminTenantUser(); + UserModel adminTenantUser2= UserModel.getAdminTenantUser(); + restClient.authenticateUser(dataUser.getAdminUser()).usingTenant().createTenant(adminTenantUser1); + restClient.authenticateUser(dataUser.getAdminUser()).usingTenant().createTenant(adminTenantUser2); + UserModel tenantUser1 = dataUser.usingUser(adminTenantUser1).createUserWithTenant("uTenant1"); + + RestProcessModel networkProcess1 = restClient.authenticateUser(tenantUser1).withWorkflowAPI() + .addProcess("activitiReview", tenantUser1, false, CMISUtil.Priority.High); + RestTaskModel task = restClient.authenticateUser(adminTenantUser1) + .withWorkflowAPI().usingProcess(networkProcess1).getProcessTasks().getOneRandomEntry(); + + variableModels = restClient.authenticateUser(adminTenantUser2).withWorkflowAPI().usingTask(task.onModel()).getTaskVariables(); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .stackTraceIs(RestErrorModel.STACKTRACE) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + } +} diff --git a/e2e-test/java/org/alfresco/rest/workflow/tasks/UpdateTaskFullTestsBulk1.java b/e2e-test/java/org/alfresco/rest/workflow/tasks/UpdateTaskFullTestsBulk1.java new file mode 100644 index 000000000..f30efad31 --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/workflow/tasks/UpdateTaskFullTestsBulk1.java @@ -0,0 +1,277 @@ +package org.alfresco.rest.workflow.tasks; + +import javax.json.JsonObject; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.JsonBodyGenerator; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessDefinitionModel; +import org.alfresco.rest.model.RestTaskModel; +import org.alfresco.utility.model.FileModel; +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.BeforeMethod; +import org.testng.annotations.Test; + +/** + * + * @author Cristina Axinte + * + */ +public class UpdateTaskFullTestsBulk1 extends RestTest +{ + UserModel owner; + SiteModel siteModel; + UserModel candidateUser; + FileModel fileModel; + UserModel assigneeUser; + TaskModel taskModel; + RestTaskModel restTaskModel; + + @BeforeClass(alwaysRun=true) + public void dataPreparation() throws Exception + { + owner = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(owner).createPublicRandomSite(); + fileModel = dataContent.usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + assigneeUser = dataUser.createRandomTestUser(); + } + + @BeforeMethod(alwaysRun=true) + public void createTask() throws Exception + { + taskModel = dataWorkflow.usingUser(owner).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL, TestGroup.NETWORKS }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify tenant user that created the task can update task only in its network and response is 200, for other networks is 403") + public void ownerTenantCanUpdatedTaskOnlyInItsNetwork() throws Exception + { + UserModel adminUser = dataUser.getAdminUser(); + restClient.authenticateUser(adminUser); + + UserModel adminTenant1 = UserModel.getAdminTenantUser(); + restClient.authenticateUser(adminUser).usingTenant().createTenant(adminTenant1); + + UserModel ownerTenant1 = dataUser.usingUser(adminTenant1).createUserWithTenant("ownerTenant1"); + UserModel assigneeTenant1 = dataUser.usingUser(adminTenant1).createUserWithTenant("assigneeTenant1"); + SiteModel siteModel1 = dataSite.usingUser(ownerTenant1).createPublicRandomSite(); + FileModel fileModel1 = dataContent.usingUser(ownerTenant1).usingSite(siteModel1).createContent(DocumentType.TEXT_PLAIN); + RestProcessDefinitionModel def1 = restClient.authenticateUser(ownerTenant1).withWorkflowAPI().getAllProcessDefinitions().getEntries().get(0).onModel(); + TaskModel taskModel1 = dataWorkflow.usingUser(ownerTenant1).usingSite(siteModel1).usingResource(fileModel1) + .createTaskWithProcessDefAndAssignTo(def1.getId(), assigneeTenant1); + + UserModel adminTenant2 = UserModel.getAdminTenantUser(); + restClient.authenticateUser(adminUser).usingTenant().createTenant(adminTenant2); + + UserModel ownerTenant2 = dataUser.usingUser(adminTenant2).createUserWithTenant("ownerTenant2"); + UserModel assigneeTenant2 = dataUser.usingUser(adminTenant2).createUserWithTenant("userTenantAssignee2"); + SiteModel siteModel2 = dataSite.usingUser(ownerTenant2).createPublicRandomSite(); + FileModel fileModel2 = dataContent.usingUser(ownerTenant2).usingSite(siteModel2).createContent(DocumentType.TEXT_PLAIN); + RestProcessDefinitionModel def2 = restClient.authenticateUser(ownerTenant2).withWorkflowAPI().getAllProcessDefinitions().getEntries().get(0).onModel(); + TaskModel taskModel2 = dataWorkflow.usingUser(ownerTenant2).usingSite(siteModel2).usingResource(fileModel2) + .createTaskWithProcessDefAndAssignTo(def2.getId(), assigneeTenant2); + + restTaskModel = restClient.authenticateUser(ownerTenant2).withParams("select=state").withWorkflowAPI().usingTask(taskModel2).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel2.getId()) + .and().field("state").is("completed"); + + restTaskModel = restClient.authenticateUser(ownerTenant2).withParams("select=state").withWorkflowAPI().usingTask(taskModel1).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError() + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + + } + + @Bug(id = "REPO-1980") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL, TestGroup.NETWORKS }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify tenant admin can update only task from its network and response is 200") + public void adminTenantCanUpdateOnlyTaskInItsNetwork() throws Exception + { + UserModel adminUser = dataUser.getAdminUser(); + restClient.authenticateUser(adminUser); + + UserModel adminTenant1 = UserModel.getAdminTenantUser(); + restClient.authenticateUser(adminUser).usingTenant().createTenant(adminTenant1); + + UserModel ownerTenant1 = dataUser.usingUser(adminTenant1).createUserWithTenant("ownerTenant1"); + UserModel assigneeTenant1 = dataUser.usingUser(adminTenant1).createUserWithTenant("assigneeTenant1"); + SiteModel siteModel1 = dataSite.usingUser(ownerTenant1).createPublicRandomSite(); + FileModel fileModel1 = dataContent.usingUser(ownerTenant1).usingSite(siteModel1).createContent(DocumentType.TEXT_PLAIN); + RestProcessDefinitionModel def1 = restClient.authenticateUser(ownerTenant1).withWorkflowAPI().getAllProcessDefinitions().getEntries().get(0).onModel(); + TaskModel taskModel1 = dataWorkflow.usingUser(ownerTenant1).usingSite(siteModel1).usingResource(fileModel1) + .createTaskWithProcessDefAndAssignTo(def1.getId(), assigneeTenant1); + + UserModel adminTenant2 = UserModel.getAdminTenantUser(); + restClient.authenticateUser(adminUser).usingTenant().createTenant(adminTenant2); + + UserModel ownerTenant2 = dataUser.usingUser(adminTenant2).createUserWithTenant("ownerTenant2"); + UserModel assigneeTenant2 = dataUser.usingUser(adminTenant2).createUserWithTenant("userTenantAssignee2"); + SiteModel siteModel2 = dataSite.usingUser(ownerTenant2).createPublicRandomSite(); + FileModel fileModel2 = dataContent.usingUser(ownerTenant2).usingSite(siteModel2).createContent(DocumentType.TEXT_PLAIN); + RestProcessDefinitionModel def2 = restClient.authenticateUser(ownerTenant2).withWorkflowAPI().getAllProcessDefinitions().getEntries().get(0).onModel(); + TaskModel taskModel2 = dataWorkflow.usingUser(ownerTenant2).usingSite(siteModel2).usingResource(fileModel2) + .createTaskWithProcessDefAndAssignTo(def2.getId(), assigneeTenant2); + + restTaskModel = restClient.authenticateUser(adminTenant2).withParams("select=state").withWorkflowAPI().usingTask(taskModel2).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel2.getId()) + .and().field("state").is("completed"); + + restTaskModel = restClient.authenticateUser(adminTenant2).withParams("select=state").withWorkflowAPI().usingTask(taskModel1).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError() + .containsErrorKey(RestErrorModel.PERMISSION_DENIED_ERRORKEY) + .containsSummary(RestErrorModel.PERMISSION_WAS_DENIED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .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 = "Verify task cannot be updated from status completed to delegated and response is 404") + public void taskCannotBeUpdatedFromCompletedToDelegated() throws Exception + { + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("completed"); + + restClient.authenticateUser(assigneeUser) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("delegated"); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError() + .containsErrorKey(String.format(RestErrorModel.TASK_ALREADY_COMPLETED, taskModel.getId())) + .containsSummary(String.format(RestErrorModel.TASK_ALREADY_COMPLETED, taskModel.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .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 = "Verify task cannot be updated from status completed to resolved and response is 404") + public void taskCannotBeUpdatedFromCompletedToResolved() throws Exception + { + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("completed"); + + restClient.authenticateUser(assigneeUser) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError() + .containsErrorKey(String.format(RestErrorModel.TASK_ALREADY_COMPLETED, taskModel.getId())) + .containsSummary(String.format(RestErrorModel.TASK_ALREADY_COMPLETED, taskModel.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .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 = "Verify task cannot be updated from status completed to completed and response is 404") + public void taskCannotBeUpdatedFromCompletedToCompleted() throws Exception + { + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("completed"); + + restClient.authenticateUser(assigneeUser) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError() + .containsErrorKey(String.format(RestErrorModel.TASK_ALREADY_COMPLETED, taskModel.getId())) + .containsSummary(String.format(RestErrorModel.TASK_ALREADY_COMPLETED, taskModel.getId())) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .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 = "Verify task can be updated from status claimed to unclaimed and response is 200") + public void taskCanBeUpdatedFromClaimedToUnclaimed() throws Exception + { + restTaskModel = restClient.authenticateUser(owner).withWorkflowAPI().usingTask(taskModel).getTask(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("claimed"); + + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("unclaimed"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task can be updated from status claimed to delegated and response is 200") + public void taskCanBeUpdatedFromClaimedToDelegated() throws Exception + { + restTaskModel = restClient.authenticateUser(owner).withWorkflowAPI().usingTask(taskModel).getTask(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("claimed"); + + UserModel newAssignee = dataUser.createRandomTestUser(); + JsonObject inputJson = JsonBodyGenerator.defineJSON() + .add("state", "delegated") + .add("assignee", newAssignee.getUsername()).build(); + + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask(inputJson); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("delegated") + .and().field("assignee").is(newAssignee.getUsername()); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task can be updated from status claimed to resolved and response is 200") + public void taskCanBeUpdatedFromClaimedToResolved() throws Exception + { + restTaskModel = restClient.authenticateUser(owner).withWorkflowAPI().usingTask(taskModel).getTask(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("claimed"); + + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("resolved"); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task can be updated from status claimed to claimed and response is 200") + public void taskCanBeUpdatedFromClaimedToClaimed() throws Exception + { + restTaskModel = restClient.authenticateUser(owner).withWorkflowAPI().usingTask(taskModel).getTask(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("claimed"); + + restTaskModel = restClient.authenticateUser(owner) + .withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel).updateTask("claimed"); + restClient.assertStatusCodeIs(HttpStatus.CONFLICT).assertLastError() + .containsErrorKey(RestErrorModel.TAS_ALREADY_CLAIMED) + .containsSummary(RestErrorModel.TAS_ALREADY_CLAIMED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } +}