Search in sources :

Example 41 with TasksClient

use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient in project alfresco-remote-api by Alfresco.

the class TaskWorkflowApiTest method testUpdateTaskVariablesExceptions.

@Test
@SuppressWarnings("unchecked")
public void testUpdateTaskVariablesExceptions() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    ProcessInstance processInstance = startAdhocProcess(requestContext.getRunAsUser(), requestContext.getNetworkId(), null);
    try {
        Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
        assertNotNull(task);
        // Update without name
        JSONObject variableBody = new JSONObject();
        variableBody.put("value", 1234);
        variableBody.put("scope", "global");
        TasksClient tasksClient = publicApiClient.tasksClient();
        try {
            tasksClient.updateTaskVariable(task.getId(), "newVariable", variableBody);
            fail("Exception expected");
        } catch (PublicApiException expected) {
            assertEquals(HttpStatus.BAD_REQUEST.value(), expected.getHttpResponse().getStatusCode());
            assertErrorSummary("Variable name is required.", expected.getHttpResponse());
        }
        // Update without scope
        variableBody = new JSONObject();
        variableBody.put("value", 1234);
        variableBody.put("name", "newVariable");
        try {
            tasksClient.updateTaskVariable(task.getId(), "newVariable", variableBody);
            fail("Exception expected");
        } catch (PublicApiException expected) {
            assertEquals(HttpStatus.BAD_REQUEST.value(), expected.getHttpResponse().getStatusCode());
            assertErrorSummary("Variable scope is required and can only be 'local' or 'global'.", expected.getHttpResponse());
        }
        // Update in 'any' scope
        variableBody = new JSONObject();
        variableBody.put("value", 1234);
        variableBody.put("name", "newVariable");
        variableBody.put("scope", "any");
        try {
            tasksClient.updateTaskVariable(task.getId(), "newVariable", variableBody);
            fail("Exception expected");
        } catch (PublicApiException expected) {
            assertEquals(HttpStatus.BAD_REQUEST.value(), expected.getHttpResponse().getStatusCode());
            assertErrorSummary("Variable scope is required and can only be 'local' or 'global'.", expected.getHttpResponse());
        }
        // Update in illegal scope
        variableBody = new JSONObject();
        variableBody.put("value", 1234);
        variableBody.put("name", "newVariable");
        variableBody.put("scope", "illegal");
        try {
            tasksClient.updateTaskVariable(task.getId(), "newVariable", variableBody);
            fail("Exception expected");
        } catch (PublicApiException expected) {
            assertEquals(HttpStatus.BAD_REQUEST.value(), expected.getHttpResponse().getStatusCode());
            assertErrorSummary("Illegal value for variable scope: 'illegal'.", expected.getHttpResponse());
        }
        // Update using unsupported type
        variableBody = new JSONObject();
        variableBody.put("value", 1234);
        variableBody.put("name", "newVariable");
        variableBody.put("scope", "local");
        variableBody.put("type", "d:unexisting");
        try {
            tasksClient.updateTaskVariable(task.getId(), "newVariable", variableBody);
            fail("Exception expected");
        } catch (PublicApiException expected) {
            assertEquals(HttpStatus.BAD_REQUEST.value(), expected.getHttpResponse().getStatusCode());
            assertErrorSummary("Unsupported type of variable: 'd:unexisting'.", expected.getHttpResponse());
        }
        // Update using unsupported type (invalid QName)
        variableBody = new JSONObject();
        variableBody.put("value", 1234);
        variableBody.put("name", "newVariable");
        variableBody.put("scope", "local");
        variableBody.put("type", " 12unexisting");
        try {
            tasksClient.updateTaskVariable(task.getId(), "newVariable", variableBody);
            fail("Exception expected");
        } catch (PublicApiException expected) {
            assertEquals(HttpStatus.BAD_REQUEST.value(), expected.getHttpResponse().getStatusCode());
            assertErrorSummary("Unsupported type of variable: ' 12unexisting'.", expected.getHttpResponse());
        }
    } finally {
        cleanupProcessInstance(processInstance);
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) Task(org.activiti.engine.task.Task) JSONObject(org.json.simple.JSONObject) TasksClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Aggregations

TasksClient (org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient)41 Test (org.junit.Test)41 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)39 Task (org.activiti.engine.task.Task)38 JSONObject (org.json.simple.JSONObject)36 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)32 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)22 ArrayList (java.util.ArrayList)17 JSONArray (org.json.simple.JSONArray)14 HashMap (java.util.HashMap)9 ProcessInfo (org.alfresco.rest.workflow.api.model.ProcessInfo)8 Calendar (java.util.Calendar)5 Date (java.util.Date)5 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)5 MemberOfSite (org.alfresco.rest.api.tests.client.data.MemberOfSite)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)3 HashSet (java.util.HashSet)2 TaskService (org.activiti.engine.TaskService)2 Clock (org.activiti.engine.runtime.Clock)2