From e865021920f89b90c288761dda7174fa305aea17 Mon Sep 17 00:00:00 2001 From: Cristina Axinte Date: Fri, 9 Dec 2016 16:13:35 +0200 Subject: [PATCH] Added 9 more core tests --- .../tasks/UpdateTaskCoreTestsBulk2.java | 189 ++++++++++++++++-- 1 file changed, 172 insertions(+), 17 deletions(-) diff --git a/e2e-test/java/org/alfresco/rest/workflow/tasks/UpdateTaskCoreTestsBulk2.java b/e2e-test/java/org/alfresco/rest/workflow/tasks/UpdateTaskCoreTestsBulk2.java index 07a033297..98a22e34c 100644 --- a/e2e-test/java/org/alfresco/rest/workflow/tasks/UpdateTaskCoreTestsBulk2.java +++ b/e2e-test/java/org/alfresco/rest/workflow/tasks/UpdateTaskCoreTestsBulk2.java @@ -13,11 +13,13 @@ 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.HttpMethod; import org.springframework.http.HttpStatus; import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; /** @@ -25,7 +27,6 @@ import org.testng.annotations.Test; * @author Cristina Axinte * */ -@Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.CORE }) public class UpdateTaskCoreTestsBulk2 extends RestTest { UserModel owner; @@ -46,10 +47,17 @@ public class UpdateTaskCoreTestsBulk2 extends RestTest taskModel = dataWorkflow.usingUser(owner).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser); } + @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.CORE }) @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Verify task owner can update twice task with status resolve successfully (200)") public void taskOwnerCanUpdateTaskWithResolveStateTwice() throws Exception - { + { restTaskModel = restClient.authenticateUser(assigneeUser) .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); restClient.assertStatusCodeIs(HttpStatus.OK); @@ -62,10 +70,11 @@ public class UpdateTaskCoreTestsBulk2 extends RestTest } + @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 task asignee cannot update twice task with status resolve - Forbidden (403)") public void taskAssigneeCanNotUpdateTaskWithResolveStateTwice() throws Exception - { + { restTaskModel = restClient.authenticateUser(assigneeUser) .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("resolved"); restClient.assertStatusCodeIs(HttpStatus.OK); @@ -79,6 +88,7 @@ public class UpdateTaskCoreTestsBulk2 extends RestTest } + @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 task cannot be update using a invalid json body property - Bad Request (400)") public void taskCanNotBeUpdatedWithInvalidJsonBodyProperty() throws Exception @@ -93,6 +103,7 @@ public class UpdateTaskCoreTestsBulk2 extends RestTest .assertLastError().containsSummary(String.format(RestErrorModel.NO_CONTENT, "Unrecognized field \""+invalidJsonProperty+"\"")); } + @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 task cannot be update using a invalid state - Bad Request (400)") public void taskCanNotBeUpdatedWithInvalidState() throws Exception @@ -103,10 +114,11 @@ public class UpdateTaskCoreTestsBulk2 extends RestTest .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_VALUE, "task state", "continued")); } + @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 task cannot be update using a invalid property - Bad Request (400)") public void taskCanNotBeUpdatedWithInvalidSelectProperty() throws Exception - { + { String invalidProperty= "states"; restClient.authenticateUser(assigneeUser) .withParams("select=" + invalidProperty).withWorkflowAPI().usingTask(taskModel); @@ -117,12 +129,13 @@ public class UpdateTaskCoreTestsBulk2 extends RestTest .assertLastError().containsSummary(String.format(RestErrorModel.PROPERTY_DOES_NOT_EXIST, invalidProperty)); } + @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 task can be update using multiple select values successfully (200)") public void taskCanBeUpdatedWithMultipleSelectValues() throws Exception - { + { restClient.authenticateUser(assigneeUser) - .withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel);//.updateTask("completed"); + .withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel); HashMap body = new HashMap(); body.put("state", "resolved"); body.put("assignee", "admin"); @@ -134,10 +147,11 @@ public class UpdateTaskCoreTestsBulk2 extends RestTest .and().field("state").is("resolved"); } + @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 task assignee can complete task successfully (200)") public void taskAssigneeCanCompleteTask() throws Exception - { + { restTaskModel = restClient.authenticateUser(assigneeUser) .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("completed"); restClient.assertStatusCodeIs(HttpStatus.OK); @@ -145,6 +159,7 @@ public class UpdateTaskCoreTestsBulk2 extends RestTest .and().field("state").is("completed"); } + @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 task owner can complete task successfully (200))") public void taskOwnerCanCompleteTask() throws Exception @@ -156,6 +171,7 @@ public class UpdateTaskCoreTestsBulk2 extends RestTest .and().field("state").is("completed"); } + @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 any user cannot complete task - Forbidden (403))") public void anyUserCannotCompleteTask() throws Exception @@ -168,24 +184,163 @@ public class UpdateTaskCoreTestsBulk2 extends RestTest .assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); } + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.CORE }) + @Bug(id = "TBD") @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Verify task owner cannot complete task with invalid name - (200))") public void taskOwnerCannotCompleteTaskWithInvalidName() throws Exception { - restClient.authenticateUser(assigneeUser) + restClient.authenticateUser(owner) .withParams("select=state,variables").withWorkflowAPI().usingTask(taskModel); - String postBody = "{\"state\" : \"completed\", \"variables\" : [{\"name\" : \"bpm_priorityx\",\"type\" : \"d_int\",\"value\" : 1,\"scope\" : \"global\"}]}"; + String postBody = "{\"state\" : \"completed\", \"variables\" : [{\"name\" : \"bpmx_priorityx\",\"type\" : \"d:int\",\"value\" : 1,\"scope\" : \"global\"}]}"; RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "tasks/{taskId}?{parameters}", taskModel.getId(), restClient.getParameters()); restTaskModel =restClient.processModel(RestTaskModel.class, request); restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) .assertLastError().containsSummary(String.format(RestErrorModel.UNSUPPORTED_TYPE,"bpm_priorityx")); } -// provide invalid type(0.5) -// provide invalid value(0.5) -// provide invalid scope(0.5) -// claim a task as asignee - 200(0.5) -// unclaim a task as current asignee - 200(0.5) -// delegate a task as asignee - 200(0.5) -// "delegate a task as owner - provide the same user as asignee"(0.5) -// provide invalid asignee value(0.5) + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.CORE }) + @Bug(id = "TBD") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task owner cannot complete task with invalid Type - Bad Request(400))") + public void taskOwnerCannotCompleteTaskWithInvalidType() throws Exception + { + restClient.authenticateUser(owner) + .withParams("select=state,variables").withWorkflowAPI().usingTask(taskModel); + String postBody = "{\"state\" : \"completed\", \"variables\" : [{\"name\" : \"bpm_priority\",\"type\" : \"d_int\",\"value\" : 1,\"scope\" : \"global\"}]}"; + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "tasks/{taskId}?{parameters}", taskModel.getId(), restClient.getParameters()); + restTaskModel =restClient.processModel(RestTaskModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.UNSUPPORTED_TYPE,"d_int")); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.CORE }) + @Bug(id = "TBD") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task owner cannot complete task with invalid value - Bad Request(400))") + public void taskOwnerCannotCompleteTaskWithInvalidValue() throws Exception + { + restClient.authenticateUser(owner) + .withParams("select=state,variables").withWorkflowAPI().usingTask(taskModel); + String postBody = "{\"state\" : \"completed\", \"variables\" : [{\"name\" : \"bpm_priority\",\"type\" : \"d:int\",\"value\" : \"text\",\"scope\" : \"global\"}]}"; + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "tasks/{taskId}?{parameters}", taskModel.getId(), restClient.getParameters()); + restTaskModel =restClient.processModel(RestTaskModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.UNSUPPORTED_TYPE, "text")); + } + + @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 task owner cannot complete task with invalid scope - Bad Request(400))") + public void taskOwnerCannotCompleteTaskWithInvalidScope() throws Exception + { + restClient.authenticateUser(owner) + .withParams("select=state,variables").withWorkflowAPI().usingTask(taskModel); + String postBody = "{\"state\" : \"completed\", \"variables\" : [{\"name\" : \"bpm_priority\",\"type\" : \"d:int\",\"value\" : 1,\"scope\" : \"globalscope\"}]}"; + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "tasks/{taskId}?{parameters}", taskModel.getId(), restClient.getParameters()); + restTaskModel =restClient.processModel(RestTaskModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.ILLEGAL_SCOPE, "globalscope")); + } + + @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 task assignee can claim task successfully (200)") + public void taskAssigneeCanClaimTask() throws Exception + { + restTaskModel = restClient.authenticateUser(assigneeUser) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("claimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("claimed"); + } + + @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 task assignee can unclaim task successfully (200)") + public void taskAssigneeCanUnclaimTask() throws Exception + { + restTaskModel = restClient.authenticateUser(assigneeUser) + .withParams("select=state").withWorkflowAPI().usingTask(taskModel).updateTask("unclaimed"); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("unclaimed"); + } + + @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 task assignee can delegate task successfully (200)") + public void taskAssigneeCanDelegateTask() throws Exception + { + UserModel delagateToUser = dataUser.createRandomTestUser(); + + restClient.authenticateUser(assigneeUser) + .withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel); + HashMap body = new HashMap(); + body.put("state", "delegated"); + body.put("assignee", delagateToUser.getUsername()); + String postBody = JsonBodyGenerator.keyValueJson(body); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "tasks/{taskId}?{parameters}", taskModel.getId(), restClient.getParameters()); + restTaskModel =restClient.processModel(RestTaskModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("delegated") + .and().field("assignee").is(delagateToUser.getUsername()); + } + + @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 task owner can delegate task to same assignee successfully (200)") + public void taskOwnerCanDelegateTaskToSameAssignee() throws Exception + { + restClient.authenticateUser(owner) + .withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel); + HashMap body = new HashMap(); + body.put("state", "delegated"); + body.put("assignee", assigneeUser.getUsername()); + String postBody = JsonBodyGenerator.keyValueJson(body); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "tasks/{taskId}?{parameters}", taskModel.getId(), restClient.getParameters()); + restTaskModel =restClient.processModel(RestTaskModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.OK); + restTaskModel.assertThat().field("id").is(taskModel.getId()) + .and().field("state").is("delegated") + .and().field("assignee").is(assigneeUser.getUsername()); + } + + + @Bug(id = "TBD") //as per api-explorer: should not have OK status + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task assignee cannot delegate task to task owner - (200)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.CORE }) + public void taskAssigneeCannotDelegateTaskToTaskOwner() throws Exception + { + restClient.authenticateUser(owner) + .withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel); + HashMap body = new HashMap(); + body.put("state", "delegated"); + body.put("assignee", owner.getUsername()); + String postBody = JsonBodyGenerator.keyValueJson(body); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "tasks/{taskId}?{parameters}", taskModel.getId(), restClient.getParameters()); + restTaskModel =restClient.processModel(RestTaskModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.CORE }) + @Bug(id = "TBD") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, + description = "Verify task owner cannot delegate task to invalid assignee - (200)") + public void taskOwnerCannotDelegateTaskToInvalidAssignee() throws Exception + { + UserModel invalidAssignee = new UserModel("invalidAssignee", "password"); + + restClient.authenticateUser(owner) + .withParams("select=state,assignee").withWorkflowAPI().usingTask(taskModel); + HashMap body = new HashMap(); + body.put("state", "delegated"); + body.put("assignee", invalidAssignee.getUsername()); + String postBody = JsonBodyGenerator.keyValueJson(body); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, postBody, "tasks/{taskId}?{parameters}", taskModel.getId(), restClient.getParameters()); + restTaskModel =restClient.processModel(RestTaskModel.class, request); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + } }