Search in sources :

Example 36 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.

the class TaskAttachmentResourceTest method testCreateAttachmentNoName.

/**
   * Test creating a single attachments for a task, without a name
   * POST runtime/tasks/{taskId}/attachments/{attachmentId}
   */
public void testCreateAttachmentNoName() throws Exception {
    try {
        Task task = taskService.newTask();
        taskService.saveTask(task);
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("description", "Simple attachment description");
        requestNode.put("type", "simpleType");
        requestNode.put("externalUrl", "http://activiti.org");
        // Post JSON without name
        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT_COLLECTION, task.getId()));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_BAD_REQUEST));
    } 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)

Example 37 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.

the class TaskAttachmentResourceTest method testCreateAttachment.

/**
   * Test creating a single attachments for a task
   * POST runtime/tasks/{taskId}/attachments/{attachmentId}
   */
public void testCreateAttachment() throws Exception {
    try {
        Task task = taskService.newTask();
        taskService.saveTask(task);
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("name", "Simple attachment");
        requestNode.put("description", "Simple attachment description");
        requestNode.put("type", "simpleType");
        requestNode.put("externalUrl", "http://activiti.org");
        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT_COLLECTION, task.getId()));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
        // Check if attachment is created
        List<Attachment> attachments = taskService.getTaskAttachments(task.getId());
        assertEquals(1, attachments.size());
        Attachment urlAttachment = attachments.get(0);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertEquals(urlAttachment.getId(), responseNode.get("id").textValue());
        assertEquals("simpleType", responseNode.get("type").textValue());
        assertEquals("Simple attachment", responseNode.get("name").textValue());
        assertEquals("Simple attachment description", responseNode.get("description").textValue());
        assertEquals("http://activiti.org", responseNode.get("externalUrl").textValue());
        assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT, task.getId(), urlAttachment.getId())));
        assertTrue(responseNode.get("taskUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, task.getId())));
        assertTrue(responseNode.get("contentUrl").isNull());
        assertTrue(responseNode.get("processInstanceUrl").isNull());
        assertFalse(responseNode.get("time").isNull());
    } 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) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Attachment(org.activiti.engine.task.Attachment) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 38 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.

the class TaskCollectionResourceTest method testCreateTask.

/**
   * Test creating a task.
   * POST runtime/tasks
   */
public void testCreateTask() throws Exception {
    try {
        Task parentTask = taskService.newTask();
        taskService.saveTask(parentTask);
        ObjectNode requestNode = objectMapper.createObjectNode();
        Calendar dueDate = Calendar.getInstance();
        String dueDateString = getISODateString(dueDate.getTime());
        requestNode.put("name", "New task name");
        requestNode.put("description", "New task description");
        requestNode.put("assignee", "assignee");
        requestNode.put("owner", "owner");
        requestNode.put("priority", 20);
        requestNode.put("delegationState", "resolved");
        requestNode.put("dueDate", dueDateString);
        requestNode.put("parentTaskId", parentTask.getId());
        requestNode.put("formKey", "testKey");
        requestNode.put("tenantId", "test");
        // Execute the request
        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        String createdTaskId = responseNode.get("id").asText();
        // Check if task is created with right arguments
        Task task = taskService.createTaskQuery().taskId(createdTaskId).singleResult();
        assertEquals("New task name", task.getName());
        assertEquals("New task description", task.getDescription());
        assertEquals("assignee", task.getAssignee());
        assertEquals("owner", task.getOwner());
        assertEquals(20, task.getPriority());
        assertEquals(DelegationState.RESOLVED, task.getDelegationState());
        assertEquals(dateFormat.parse(dueDateString), task.getDueDate());
        assertEquals(parentTask.getId(), task.getParentTaskId());
        assertEquals("testKey", task.getFormKey());
        assertEquals("test", task.getTenantId());
    } 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) Calendar(java.util.Calendar) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 39 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.

the class ProcessInstanceVariableResourceTest method testUpdateProcessVariable.

/**
   * Test updating a single process variable, including "not found" check.
   * 
   * PUT runtime/process-instances/{processInstanceId}/variables/{variableName}
   */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceVariableResourceTest.testProcess.bpmn20.xml" })
public void testUpdateProcessVariable() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", Collections.singletonMap("overlappingVariable", (Object) "processValue"));
    runtimeService.setVariable(processInstance.getId(), "myVar", "value");
    // Update variable 
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("name", "myVar");
    requestNode.put("value", "updatedValue");
    requestNode.put("type", "string");
    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "myVar"));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("updatedValue", responseNode.get("value").asText());
    // Try updating with mismatch between URL and body variableName
    requestNode.put("name", "unexistingVariable");
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPut, HttpStatus.SC_BAD_REQUEST));
    // Try updating unexisting property
    requestNode.put("name", "unexistingVariable");
    httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "unexistingVariable"));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPut, HttpStatus.SC_NOT_FOUND));
}
Also used : StringEntity(org.apache.http.entity.StringEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) HttpPut(org.apache.http.client.methods.HttpPut) Deployment(org.activiti.engine.test.Deployment)

Example 40 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.

the class ProcessInstanceVariablesCollectionResourceTest method testCreateSingleProcessInstanceVariable.

/**
   * Test creating a single process variable.
   * POST runtime/process-instance/{processInstanceId}/variables
   */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml" })
public void testCreateSingleProcessInstanceVariable() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    ArrayNode requestNode = objectMapper.createArrayNode();
    ObjectNode variableNode = requestNode.addObject();
    variableNode.put("name", "myVariable");
    variableNode.put("value", "simple string value");
    variableNode.put("type", "string");
    // Create a new local variable
    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId()));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeBinaryRequest(httpPost, HttpStatus.SC_CREATED);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()).get(0);
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("myVariable", responseNode.get("name").asText());
    assertEquals("simple string value", responseNode.get("value").asText());
    assertEquals("local", responseNode.get("scope").asText());
    assertEquals("string", responseNode.get("type").asText());
    assertNull(responseNode.get("valueUrl"));
    assertTrue(runtimeService.hasVariableLocal(processInstance.getId(), "myVariable"));
    assertEquals("simple string value", runtimeService.getVariableLocal(processInstance.getId(), "myVariable"));
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Deployment(org.activiti.engine.test.Deployment)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2465 JsonNode (com.fasterxml.jackson.databind.JsonNode)564 Test (org.junit.Test)559 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)514 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)379 IOException (java.io.IOException)221 ArrayList (java.util.ArrayList)123 Map (java.util.Map)111 HashMap (java.util.HashMap)107 List (java.util.List)98 StringEntity (org.apache.http.entity.StringEntity)94 Deployment (org.activiti.engine.test.Deployment)85 Test (org.testng.annotations.Test)81 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)69 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)65 HttpPost (org.apache.http.client.methods.HttpPost)57 AbstractRpcLwM2MIntegrationTest (org.thingsboard.server.transport.lwm2m.rpc.AbstractRpcLwM2MIntegrationTest)54 TextNode (com.fasterxml.jackson.databind.node.TextNode)52 File (java.io.File)51 Task (org.activiti.engine.task.Task)51