Search in sources :

Example 76 with JsonNode

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

the class ProcessDefinitionResourceTest method testGetProcessDefinitionWithGraphicalNotation.

/**
   * Test getting a single process definition with a graphical notation defined.
   * GET repository/process-definitions/{processDefinitionResource}
   */
@Deployment
public void testGetProcessDefinitionWithGraphicalNotation() throws Exception {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION, processDefinition.getId()));
    CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertEquals(processDefinition.getId(), responseNode.get("id").textValue());
    assertEquals(processDefinition.getKey(), responseNode.get("key").textValue());
    assertEquals(processDefinition.getCategory(), responseNode.get("category").textValue());
    assertEquals(processDefinition.getVersion(), responseNode.get("version").intValue());
    assertEquals(processDefinition.getDescription(), responseNode.get("description").textValue());
    assertEquals(processDefinition.getName(), responseNode.get("name").textValue());
    assertTrue(responseNode.get("graphicalNotationDefined").booleanValue());
    // Check URL's
    assertEquals(httpGet.getURI().toString(), responseNode.get("url").asText());
    assertEquals(processDefinition.getDeploymentId(), responseNode.get("deploymentId").textValue());
    assertTrue(responseNode.get("deploymentUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, processDefinition.getDeploymentId())));
    assertTrue(URLDecoder.decode(responseNode.get("resource").textValue(), "UTF-8").endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_RESOURCE, processDefinition.getDeploymentId(), processDefinition.getResourceName())));
    assertTrue(URLDecoder.decode(responseNode.get("diagramResource").textValue(), "UTF-8").endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_RESOURCE, processDefinition.getDeploymentId(), processDefinition.getDiagramResourceName())));
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) JsonNode(com.fasterxml.jackson.databind.JsonNode) Deployment(org.activiti.engine.test.Deployment)

Example 77 with JsonNode

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

the class ExecutionVariableResourceTest method testGetExecutionVariable.

/**
   * Test getting an execution variable. GET
   */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" })
public void testGetExecutionVariable() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne");
    runtimeService.setVariable(processInstance.getId(), "variable", "processValue");
    Execution childExecution = runtimeService.createExecutionQuery().parentId(processInstance.getId()).singleResult();
    assertNotNull(childExecution);
    runtimeService.setVariableLocal(childExecution.getId(), "variable", "childValue");
    // Get local scope variable
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, childExecution.getId(), "variable")), HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("local", responseNode.get("scope").asText());
    assertEquals("childValue", responseNode.get("value").asText());
    assertEquals("variable", responseNode.get("name").asText());
    assertEquals("string", responseNode.get("type").asText());
    // Get global scope variable
    response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, childExecution.getId(), "variable") + "?scope=global"), HttpStatus.SC_OK);
    responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("global", responseNode.get("scope").asText());
    assertEquals("processValue", responseNode.get("value").asText());
    assertEquals("variable", responseNode.get("name").asText());
    assertEquals("string", responseNode.get("type").asText());
    // Illegal scope
    response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, processInstance.getId(), "variable") + "?scope=illegal"), HttpStatus.SC_BAD_REQUEST);
    closeResponse(response);
    // Unexisting process
    response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, "unexisting", "variable")), HttpStatus.SC_NOT_FOUND);
    closeResponse(response);
    // Unexisting variable
    response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, processInstance.getId(), "unexistingVariable")), HttpStatus.SC_NOT_FOUND);
    closeResponse(response);
}
Also used : Execution(org.activiti.engine.runtime.Execution) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) Deployment(org.activiti.engine.test.Deployment)

Example 78 with JsonNode

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

the class ProcessInstanceCollectionResourceTest method testStartProcessWithVariables.

/**
   * Test starting a process instance passing in variables to set.
   */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testStartProcessWithVariables() throws Exception {
    ArrayNode variablesNode = objectMapper.createArrayNode();
    // String variable
    ObjectNode stringVarNode = variablesNode.addObject();
    stringVarNode.put("name", "stringVariable");
    stringVarNode.put("value", "simple string value");
    stringVarNode.put("type", "string");
    ObjectNode integerVarNode = variablesNode.addObject();
    integerVarNode.put("name", "integerVariable");
    integerVarNode.put("value", 1234);
    integerVarNode.put("type", "integer");
    ObjectNode shortVarNode = variablesNode.addObject();
    shortVarNode.put("name", "shortVariable");
    shortVarNode.put("value", 123);
    shortVarNode.put("type", "short");
    ObjectNode longVarNode = variablesNode.addObject();
    longVarNode.put("name", "longVariable");
    longVarNode.put("value", 4567890L);
    longVarNode.put("type", "long");
    ObjectNode doubleVarNode = variablesNode.addObject();
    doubleVarNode.put("name", "doubleVariable");
    doubleVarNode.put("value", 123.456);
    doubleVarNode.put("type", "double");
    ObjectNode booleanVarNode = variablesNode.addObject();
    booleanVarNode.put("name", "booleanVariable");
    booleanVarNode.put("value", Boolean.TRUE);
    booleanVarNode.put("type", "boolean");
    // Date
    Calendar varCal = Calendar.getInstance();
    String isoString = getISODateString(varCal.getTime());
    ObjectNode dateVarNode = variablesNode.addObject();
    dateVarNode.put("name", "dateVariable");
    dateVarNode.put("value", isoString);
    dateVarNode.put("type", "date");
    ObjectNode requestNode = objectMapper.createObjectNode();
    // Start using process definition key, passing in variables
    requestNode.put("processDefinitionKey", "processOne");
    requestNode.put("variables", variablesNode);
    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertEquals("processTask", responseNode.get("activityId").asText());
    assertEquals(false, responseNode.get("ended").asBoolean());
    JsonNode variablesArrayNode = responseNode.get("variables");
    assertEquals(0, variablesArrayNode.size());
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertNotNull(processInstance);
    // Check if engine has correct variables set
    Map<String, Object> processVariables = runtimeService.getVariables(processInstance.getId());
    assertEquals(7, processVariables.size());
    assertEquals("simple string value", processVariables.get("stringVariable"));
    assertEquals(1234, processVariables.get("integerVariable"));
    assertEquals((short) 123, processVariables.get("shortVariable"));
    assertEquals(4567890L, processVariables.get("longVariable"));
    assertEquals(123.456, processVariables.get("doubleVariable"));
    assertEquals(Boolean.TRUE, processVariables.get("booleanVariable"));
    assertEquals(dateFormat.parse(isoString), processVariables.get("dateVariable"));
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Calendar(java.util.Calendar) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Deployment(org.activiti.engine.test.Deployment)

Example 79 with JsonNode

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

the class TaskAttachmentResourceTest method testGetAttachmentForCompletedTask.

/**
   * Test getting a single attachments for a task.
   * GET runtime/tasks/{taskId}/attachments/{attachmentId}
   */
public void testGetAttachmentForCompletedTask() throws Exception {
    try {
        Task task = taskService.newTask();
        taskService.saveTask(task);
        // Create URL-attachment
        Attachment urlAttachment = taskService.createAttachment("simpleType", task.getId(), null, "Simple attachment", "Simple attachment description", "http://activiti.org");
        taskService.saveAttachment(urlAttachment);
        // Create Binary-attachment
        Attachment binaryAttachment = taskService.createAttachment("binaryType", task.getId(), null, "Binary attachment", "Binary attachment description", new ByteArrayInputStream("This is binary content".getBytes()));
        taskService.saveAttachment(binaryAttachment);
        taskService.complete(task.getId());
        // Get external url attachment
        CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT, task.getId(), urlAttachment.getId())), HttpStatus.SC_OK);
        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());
        // Get binary attachment
        response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT, task.getId(), binaryAttachment.getId())), HttpStatus.SC_OK);
        responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertEquals(binaryAttachment.getId(), responseNode.get("id").textValue());
        assertEquals("binaryType", responseNode.get("type").textValue());
        assertEquals("Binary attachment", responseNode.get("name").textValue());
        assertEquals("Binary attachment description", responseNode.get("description").textValue());
        assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT, task.getId(), binaryAttachment.getId())));
        assertTrue(responseNode.get("contentUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT_DATA, task.getId(), binaryAttachment.getId())));
        assertTrue(responseNode.get("taskUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, task.getId())));
        assertTrue(responseNode.get("externalUrl").isNull());
        assertTrue(responseNode.get("processInstanceUrl").isNull());
    } finally {
        // Clean adhoc-tasks even if test fails
        List<HistoricTaskInstance> tasks = historyService.createHistoricTaskInstanceQuery().list();
        for (HistoricTaskInstance task : tasks) {
            taskService.deleteTask(task.getId(), true);
        }
    }
}
Also used : Task(org.activiti.engine.task.Task) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) ByteArrayInputStream(java.io.ByteArrayInputStream) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Attachment(org.activiti.engine.task.Attachment) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 80 with JsonNode

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

the class TaskAttachmentResourceTest method testGetAttachments.

/**
   * Test getting all attachments for a task.
   * GET runtime/tasks/{taskId}/attachments
   */
public void testGetAttachments() throws Exception {
    try {
        Task task = taskService.newTask();
        taskService.saveTask(task);
        // Create URL-attachment
        Attachment urlAttachment = taskService.createAttachment("simpleType", task.getId(), null, "Simple attachment", "Simple attachment description", "http://activiti.org");
        taskService.saveAttachment(urlAttachment);
        // Create Binary-attachment
        Attachment binaryAttachment = taskService.createAttachment("binaryType", task.getId(), null, "Binary attachment", "Binary attachment description", new ByteArrayInputStream("This is binary content".getBytes()));
        taskService.saveAttachment(binaryAttachment);
        CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT_COLLECTION, task.getId())), HttpStatus.SC_OK);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertTrue(responseNode.isArray());
        assertEquals(2, responseNode.size());
    } 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) ByteArrayInputStream(java.io.ByteArrayInputStream) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Attachment(org.activiti.engine.task.Attachment) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)4090 Test (org.junit.Test)1257 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)802 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)544 IOException (java.io.IOException)532 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)384 ArrayList (java.util.ArrayList)315 Test (org.junit.jupiter.api.Test)276 HashMap (java.util.HashMap)249 Map (java.util.Map)201 DefaultSerializerProvider (com.fasterxml.jackson.databind.ser.DefaultSerializerProvider)174 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)127 List (java.util.List)122 InputStream (java.io.InputStream)116 KernelTest (com.twosigma.beakerx.KernelTest)114 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)84 Response (javax.ws.rs.core.Response)79 File (java.io.File)78 HttpGet (org.apache.http.client.methods.HttpGet)75 ByteArrayInputStream (java.io.ByteArrayInputStream)70