Search in sources :

Example 61 with Task

use of org.activiti.engine.task.Task in project Activiti by Activiti.

the class TaskVariableResourceTest method testGetTaskVariableDataForIllegalVariables.

/**
   * Test getting a task variable. GET
   * runtime/tasks/{taskId}/variables/{variableName}/data
   */
public void testGetTaskVariableDataForIllegalVariables() throws Exception {
    try {
        // Test variable behaviour on standalone tasks
        Task task = taskService.newTask();
        taskService.saveTask(task);
        taskService.setVariableLocal(task.getId(), "localTaskVariable", "this is a plain string variable");
        // Try getting data for non-binary variable
        closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLE_DATA, task.getId(), "localTaskVariable")), HttpStatus.SC_NOT_FOUND));
        // Try getting data for unexisting property
        closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLE_DATA, task.getId(), "unexistingVariable")), HttpStatus.SC_NOT_FOUND));
    } finally {
        // Clean adhoc-tasks even if test fails
        List<Task> tasks = taskService.createTaskQuery().list();
        for (Task task : tasks) {
            taskService.deleteTask(task.getId(), true);
        }
    }
}
Also used : Task(org.activiti.engine.task.Task) HttpGet(org.apache.http.client.methods.HttpGet)

Example 62 with Task

use of org.activiti.engine.task.Task in project Activiti by Activiti.

the class TaskVariableResourceTest method testDeleteTaskVariable.

/**
   * Test deleting a single task variable in all scopes, including "not found" check.
   * 
   * DELETE runtime/tasks/{taskId}/variables/{variableName}
   */
@Deployment
public void testDeleteTaskVariable() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", Collections.singletonMap("overlappingVariable", (Object) "processValue"));
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.setVariableLocal(task.getId(), "overlappingVariable", "taskValue");
    taskService.setVariableLocal(task.getId(), "anotherTaskVariable", "taskValue");
    // Delete variable without scope, local should be presumed -> local removed and global should be retained
    HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLE, task.getId(), "overlappingVariable"));
    closeResponse(executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
    assertFalse(taskService.hasVariableLocal(task.getId(), "overlappingVariable"));
    assertTrue(taskService.hasVariable(task.getId(), "overlappingVariable"));
    // Delete local scope variable
    httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLE, task.getId(), "anotherTaskVariable") + "?scope=local");
    closeResponse(executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
    assertFalse(taskService.hasVariableLocal(task.getId(), "anotherTaskVariable"));
    // Delete global scope variable
    assertTrue(taskService.hasVariable(task.getId(), "overlappingVariable"));
    httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLE, task.getId(), "overlappingVariable") + "?scope=global");
    closeResponse(executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
    assertFalse(taskService.hasVariable(task.getId(), "overlappingVariable"));
    // Run the same delete again, variable is not there so 404 should be returned
    closeResponse(executeRequest(httpDelete, HttpStatus.SC_NOT_FOUND));
}
Also used : Task(org.activiti.engine.task.Task) HttpDelete(org.apache.http.client.methods.HttpDelete) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 63 with Task

use of org.activiti.engine.task.Task in project Activiti by Activiti.

the class TaskVariablesCollectionResourceTest method testDeleteAllLocalVariables.

/**
   * Test deleting all local task variables.
   * DELETE runtime/tasks/{taskId}/variables
   */
@Deployment
public void testDeleteAllLocalVariables() throws Exception {
    // Start process with all types of variables
    Map<String, Object> processVariables = new HashMap<String, Object>();
    processVariables.put("var1", "This is a ProcVariable");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables);
    // Set local task variables
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    Map<String, Object> taskVariables = new HashMap<String, Object>();
    taskVariables.put("var1", "This is a TaskVariable");
    taskVariables.put("var2", 123);
    taskService.setVariablesLocal(task.getId(), taskVariables);
    assertEquals(2, taskService.getVariablesLocal(task.getId()).size());
    HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
    closeResponse(executeBinaryRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
    // Check if local variables are gone and global remain unchanged
    assertEquals(0, taskService.getVariablesLocal(task.getId()).size());
    assertEquals(1, taskService.getVariables(task.getId()).size());
}
Also used : Task(org.activiti.engine.task.Task) HttpDelete(org.apache.http.client.methods.HttpDelete) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 64 with Task

use of org.activiti.engine.task.Task in project Activiti by Activiti.

the class TaskVariablesCollectionResourceTest method testCreateSingleSerializableTaskVariable.

/**
   * Test creating a single task variable using a binary stream.
   * POST runtime/tasks/{taskId}/variables
   */
public void testCreateSingleSerializableTaskVariable() throws Exception {
    try {
        Task task = taskService.newTask();
        taskService.saveTask(task);
        TestSerializableVariable serializable = new TestSerializableVariable();
        serializable.setSomeField("some value");
        // Serialize object to readable stream for representation
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutputStream output = new ObjectOutputStream(buffer);
        output.writeObject(serializable);
        output.close();
        InputStream binaryContent = new ByteArrayInputStream(buffer.toByteArray());
        // Add name, type and scope
        Map<String, String> additionalFields = new HashMap<String, String>();
        additionalFields.put("name", "serializableVariable");
        additionalFields.put("type", "serializable");
        additionalFields.put("scope", "local");
        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
        httpPost.setEntity(HttpMultipartHelper.getMultiPartEntity("value", "application/x-java-serialized-object", binaryContent, additionalFields));
        CloseableHttpResponse response = executeBinaryRequest(httpPost, HttpStatus.SC_CREATED);
        // Check "CREATED" status
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertNotNull(responseNode);
        assertEquals("serializableVariable", responseNode.get("name").asText());
        assertTrue(responseNode.get("value").isNull());
        assertEquals("local", responseNode.get("scope").asText());
        assertEquals("serializable", responseNode.get("type").asText());
        assertNotNull(responseNode.get("valueUrl").isNull());
        assertTrue(responseNode.get("valueUrl").asText().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLE_DATA, task.getId(), "serializableVariable")));
        // Check actual value of variable in engine
        Object variableValue = taskService.getVariableLocal(task.getId(), "serializableVariable");
        assertNotNull(variableValue);
        assertTrue(variableValue instanceof TestSerializableVariable);
        assertEquals("some value", ((TestSerializableVariable) variableValue).getSomeField());
    } finally {
        // Clean adhoc-tasks even if test fails
        List<Task> tasks = taskService.createTaskQuery().list();
        for (Task task : tasks) {
            taskService.deleteTask(task.getId(), true);
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 65 with Task

use of org.activiti.engine.task.Task in project Activiti by Activiti.

the class TaskVariablesCollectionResourceTest method testCreateSingleTaskVariableDefaultTypes.

/**
   * Test creating a single task variable, testing default types when omitted. 
   * POST runtime/tasks/{taskId}/variables
   */
public void testCreateSingleTaskVariableDefaultTypes() throws Exception {
    try {
        Task task = taskService.newTask();
        taskService.saveTask(task);
        // String type detection
        ArrayNode requestNode = objectMapper.createArrayNode();
        ObjectNode varNode = requestNode.addObject();
        varNode.put("name", "stringVar");
        varNode.put("value", "String value");
        varNode.put("scope", "local");
        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_CREATED));
        assertEquals("String value", taskService.getVariable(task.getId(), "stringVar"));
        // Integer type detection
        varNode.put("name", "integerVar");
        varNode.put("value", 123);
        varNode.put("scope", "local");
        httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_CREATED));
        assertEquals(123, taskService.getVariable(task.getId(), "integerVar"));
        // Double type detection
        varNode.put("name", "doubleVar");
        varNode.put("value", 123.456);
        varNode.put("scope", "local");
        httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_CREATED));
        assertEquals(123.456, taskService.getVariable(task.getId(), "doubleVar"));
        // Boolean type detection
        varNode.put("name", "booleanVar");
        varNode.put("value", Boolean.TRUE);
        varNode.put("scope", "local");
        httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_CREATED));
        assertEquals(Boolean.TRUE, taskService.getVariable(task.getId(), "booleanVar"));
    } finally {
        // Clean adhoc-tasks even if test fails
        List<Task> tasks = taskService.createTaskQuery().list();
        for (Task task : tasks) {
            taskService.deleteTask(task.getId(), true);
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) Task(org.activiti.engine.task.Task) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

Task (org.activiti.engine.task.Task)955 Deployment (org.activiti.engine.test.Deployment)548 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)502 HashMap (java.util.HashMap)197 Test (org.junit.Test)123 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)109 ArrayList (java.util.ArrayList)74 Date (java.util.Date)65 Execution (org.activiti.engine.runtime.Execution)59 DelegateTask (org.activiti.engine.delegate.DelegateTask)54 TaskQuery (org.activiti.engine.task.TaskQuery)54 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)51 Job (org.activiti.engine.runtime.Job)49 Calendar (java.util.Calendar)44 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)44 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)44 JsonNode (com.fasterxml.jackson.databind.JsonNode)41 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)41 JSONObject (org.json.simple.JSONObject)40 TasksClient (org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient)38