Example usage for com.fasterxml.jackson.databind JsonNode iterator

List of usage examples for com.fasterxml.jackson.databind JsonNode iterator

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonNode iterator.

Prototype

public final Iterator<JsonNode> iterator() 

Source Link

Usage

From source file:org.flowable.cmmn.rest.service.api.history.HistoricCaseInstanceCollectionResourceTest.java

@Override
protected void assertResultsPresentInDataResponse(String url, String... expectedResourceIds)
        throws JsonProcessingException, IOException {
    int numberOfResultsExpected = expectedResourceIds.length;

    // Do the actual call
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), 200);

    // Check status and size
    assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);//from w  w  w.j a v  a  2  s . c  o  m
    assertEquals(numberOfResultsExpected, dataNode.size());

    // Check presence of ID's
    List<String> toBeFound = new ArrayList<>(Arrays.asList(expectedResourceIds));
    Iterator<JsonNode> it = dataNode.iterator();
    while (it.hasNext()) {
        String id = it.next().get("id").textValue();
        toBeFound.remove(id);
    }
    assertTrue("Not all process instances have been found in result, missing: "
            + StringUtils.join(toBeFound, ", "), toBeFound.isEmpty());
}

From source file:org.flowable.cmmn.rest.service.api.history.HistoricTaskInstanceCollectionResourceTest.java

protected void assertResultsPresentInDataResponse(String url, int numberOfResultsExpected,
        String... expectedTaskIds) throws JsonProcessingException, IOException {

    // Do the actual call
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK);

    // Check status and size
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);// w  w  w.j  a v a2  s.  c  om
    assertEquals(numberOfResultsExpected, dataNode.size());

    // Check presence of ID's
    if (expectedTaskIds != null) {
        List<String> toBeFound = new ArrayList<>(Arrays.asList(expectedTaskIds));
        Iterator<JsonNode> it = dataNode.iterator();
        while (it.hasNext()) {
            String id = it.next().get("id").textValue();
            toBeFound.remove(id);
        }
        assertTrue("Not all entries have been found in result, missing: " + StringUtils.join(toBeFound, ", "),
                toBeFound.isEmpty());
    }
}

From source file:org.flowable.cmmn.rest.service.api.history.HistoricTaskInstanceQueryResourceTest.java

protected void assertResultsPresentInPostDataResponse(String url, ObjectNode body, int numberOfResultsExpected,
        String... expectedTaskIds) throws JsonProcessingException, IOException {
    // Do the actual call
    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + url);
    httpPost.setEntity(new StringEntity(body.toString()));
    CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_OK);
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);// w  w  w  .  ja v  a 2  s . com
    assertEquals(numberOfResultsExpected, dataNode.size());

    // Check presence of ID's
    if (expectedTaskIds != null) {
        List<String> toBeFound = new ArrayList<>(Arrays.asList(expectedTaskIds));
        Iterator<JsonNode> it = dataNode.iterator();
        while (it.hasNext()) {
            String id = it.next().get("id").textValue();
            toBeFound.remove(id);
        }
        assertTrue("Not all entries have been found in result, missing: " + StringUtils.join(toBeFound, ", "),
                toBeFound.isEmpty());
    }
}

From source file:org.flowable.rest.api.history.HistoricDetailCollectionResourceTest.java

/**
 * Test querying historic detail. GET history/historic-detail
 *//*from  w w w .  j a va2  s.co m*/
@Deployment
public void testQueryDetail() throws Exception {
    HashMap<String, Object> processVariables = new HashMap<String, Object>();
    processVariables.put("stringVar", "Azerty");
    processVariables.put("intVar", 67890);
    processVariables.put("booleanVar", false);
    processVariables.put("byteVar", "test".getBytes());

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess",
            processVariables);
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task.getId());
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.setVariableLocal(task.getId(), "taskVariable", "test");

    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess",
            processVariables);

    String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_DETAIL);

    assertResultsPresentInDataResponse(url + "?processInstanceId=" + processInstance.getId(), 5, "stringVar",
            "Azerty");
    assertResultsPresentInDataResponse(url + "?taskId=" + task.getId(), 1, "taskVariable", "test");
    assertResultsPresentInDataResponse(url + "?processInstanceId=" + processInstance2.getId(), 4, "intVar",
            67890);
    assertResultsPresentInDataResponse(
            url + "?processInstanceId=" + processInstance2.getId() + "&selectOnlyVariableUpdates=true", 4,
            "booleanVar", false);

    CloseableHttpResponse response = executeRequest(
            new HttpGet(SERVER_URL_PREFIX + url + "?processInstanceId=" + processInstance2.getId()),
            HttpStatus.SC_OK);

    // Check status and size
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);

    boolean byteVarFound = false;
    Iterator<JsonNode> it = dataNode.iterator();
    while (it.hasNext()) {
        JsonNode variableNode = it.next().get("variable");
        String name = variableNode.get("name").textValue();
        if ("byteVar".equals(name)) {
            byteVarFound = true;
            String valueUrl = variableNode.get("valueUrl").textValue();

            response = executeRequest(new HttpGet(valueUrl), HttpStatus.SC_OK);
            byte[] varInput = IOUtils.toByteArray(response.getEntity().getContent());
            closeResponse(response);
            assertEquals("test", new String(varInput));
            break;
        }
    }
    assertTrue(byteVarFound);
}

From source file:org.flowable.rest.api.history.HistoricDetailCollectionResourceTest.java

protected void assertResultsPresentInDataResponse(String url, int numberOfResultsExpected, String variableName,
        Object variableValue) throws JsonProcessingException, IOException {

    // Do the actual call
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK);

    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);//w  ww . j a  v  a 2s  . c  o  m

    assertEquals(numberOfResultsExpected, dataNode.size());

    // Check presence of ID's
    if (variableName != null) {
        boolean variableFound = false;
        Iterator<JsonNode> it = dataNode.iterator();
        while (it.hasNext()) {
            JsonNode variableNode = it.next().get("variable");
            String name = variableNode.get("name").textValue();
            if (variableName.equals(name)) {
                variableFound = true;
                if (variableValue instanceof Boolean) {
                    assertTrue("Variable value is not equal",
                            variableNode.get("value").asBoolean() == (Boolean) variableValue);
                } else if (variableValue instanceof Integer) {
                    assertTrue("Variable value is not equal",
                            variableNode.get("value").asInt() == (Integer) variableValue);
                } else {
                    assertTrue("Variable value is not equal",
                            variableNode.get("value").asText().equals((String) variableValue));
                }
            }
        }
        assertTrue("Variable " + variableName + " is missing", variableFound);
    }
}

From source file:org.flowable.rest.service.api.history.HistoricActivityInstanceCollectionResourceTest.java

protected void assertResultsPresentInDataResponse(String url, int numberOfResultsExpected,
        String... expectedActivityIds) throws JsonProcessingException, IOException {
    // Do the actual call
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK);
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);/*  w ww.java  2s  .  c  om*/
    Assert.assertEquals(numberOfResultsExpected, dataNode.size());

    // Check presence of ID's
    if (expectedActivityIds != null) {
        List<String> toBeFound = new ArrayList<String>(Arrays.asList(expectedActivityIds));
        Iterator<JsonNode> it = dataNode.iterator();
        while (it.hasNext()) {
            String activityId = it.next().get("activityId").textValue();
            toBeFound.remove(activityId);
        }
        Assert.assertTrue(
                "Not all entries have been found in result, missing: " + StringUtils.join(toBeFound, ", "),
                toBeFound.isEmpty());
    }
}

From source file:org.flowable.rest.service.api.history.HistoricActivityInstanceQueryResourceTest.java

protected void assertResultsPresentInDataResponse(String url, ObjectNode body, int numberOfResultsExpected,
        String... expectedActivityIds) throws JsonProcessingException, IOException {

    // Do the actual call
    HttpPost post = new HttpPost(SERVER_URL_PREFIX + url);
    post.setEntity(new StringEntity(body.toString()));
    CloseableHttpResponse response = executeRequest(post, 200);

    // Check status and size
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);/* www .  ja v a2  s  . c  o m*/
    assertEquals(numberOfResultsExpected, dataNode.size());

    // Check presence of ID's
    if (expectedActivityIds != null) {
        List<String> toBeFound = new ArrayList<String>(Arrays.asList(expectedActivityIds));
        Iterator<JsonNode> it = dataNode.iterator();
        while (it.hasNext()) {
            String activityId = it.next().get("activityId").textValue();
            toBeFound.remove(activityId);
        }
        assertTrue("Not all entries have been found in result, missing: " + StringUtils.join(toBeFound, ", "),
                toBeFound.isEmpty());
    }
}

From source file:org.flowable.rest.service.api.history.HistoricDetailQueryResourceTest.java

/**
 * Test querying historic detail. POST query/historic-detail
 *//*  ww  w.j  a v  a  2s . c  o m*/
@Deployment
public void testQueryDetail() throws Exception {
    HashMap<String, Object> processVariables = new HashMap<String, Object>();
    processVariables.put("stringVar", "Azerty");
    processVariables.put("intVar", 67890);
    processVariables.put("booleanVar", false);
    processVariables.put("byteVar", "test".getBytes());

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess",
            processVariables);
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task.getId());
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.setVariableLocal(task.getId(), "taskVariable", "test");

    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess",
            processVariables);

    String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_DETAIL_QUERY);

    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("processInstanceId", processInstance.getId());
    assertResultsPresentInDataResponse(url, requestNode, 5, "stringVar", "Azerty");

    requestNode = objectMapper.createObjectNode();
    requestNode.put("taskId", task.getId());
    assertResultsPresentInDataResponse(url, requestNode, 1, "taskVariable", "test");

    requestNode = objectMapper.createObjectNode();
    requestNode.put("processInstanceId", processInstance2.getId());
    assertResultsPresentInDataResponse(url, requestNode, 4, "intVar", 67890);

    requestNode = objectMapper.createObjectNode();
    requestNode.put("processInstanceId", processInstance2.getId());
    requestNode.put("selectOnlyFormProperties", true);
    assertResultsPresentInDataResponse(url, requestNode, 0, null, null);

    requestNode = objectMapper.createObjectNode();
    requestNode.put("processInstanceId", processInstance2.getId());
    requestNode.put("selectOnlyVariableUpdates", true);
    assertResultsPresentInDataResponse(url, requestNode, 4, "booleanVar", false);

    requestNode = objectMapper.createObjectNode();
    requestNode.put("processInstanceId", processInstance2.getId());
    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + url);
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPost, 200);

    // Check status and size
    assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);

    boolean byteVarFound = false;
    Iterator<JsonNode> it = dataNode.iterator();
    while (it.hasNext()) {
        JsonNode variableNode = it.next().get("variable");
        String name = variableNode.get("name").textValue();
        if ("byteVar".equals(name)) {
            byteVarFound = true;
            String valueUrl = variableNode.get("valueUrl").textValue();
            response = executeRequest(new HttpGet(valueUrl), 200);
            assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
            byte[] varInput = IOUtils.toByteArray(response.getEntity().getContent());
            closeResponse(response);
            assertEquals("test", new String(varInput));
            break;
        }
    }
    assertTrue(byteVarFound);
}

From source file:org.flowable.rest.service.api.history.HistoricDetailQueryResourceTest.java

protected void assertResultsPresentInDataResponse(String url, ObjectNode body, int numberOfResultsExpected,
        String variableName, Object variableValue) throws JsonProcessingException, IOException {

    // Do the actual call
    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + url);
    httpPost.setEntity(new StringEntity(body.toString()));
    CloseableHttpResponse response = executeRequest(httpPost, 200);

    // Check status and size
    assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);//from w  ww .j a  v a  2  s .com
    assertEquals(numberOfResultsExpected, dataNode.size());

    // Check presence of ID's
    if (variableName != null) {
        boolean variableFound = false;
        Iterator<JsonNode> it = dataNode.iterator();
        while (it.hasNext()) {
            JsonNode variableNode = it.next().get("variable");
            String name = variableNode.get("name").textValue();
            if (variableName.equals(name)) {
                variableFound = true;
                if (variableValue instanceof Boolean) {
                    assertTrue("Variable value is not equal",
                            variableNode.get("value").asBoolean() == (Boolean) variableValue);
                } else if (variableValue instanceof Integer) {
                    assertTrue("Variable value is not equal",
                            variableNode.get("value").asInt() == (Integer) variableValue);
                } else {
                    assertTrue("Variable value is not equal",
                            variableNode.get("value").asText().equals((String) variableValue));
                }
            }
        }
        assertTrue("Variable " + variableName + " is missing", variableFound);
    }
}

From source file:org.flowable.rest.service.api.history.HistoricProcessInstanceCollectionResourceTest.java

protected void assertResultsPresentInDataResponse(String url, String... expectedResourceIds)
        throws JsonProcessingException, IOException {
    int numberOfResultsExpected = expectedResourceIds.length;

    // Do the actual call
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), 200);

    // Check status and size
    assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);/*from w ww.  j  av a2  s  . co m*/
    assertEquals(numberOfResultsExpected, dataNode.size());

    // Check presence of ID's
    List<String> toBeFound = new ArrayList<String>(Arrays.asList(expectedResourceIds));
    Iterator<JsonNode> it = dataNode.iterator();
    while (it.hasNext()) {
        String id = it.next().get("id").textValue();
        toBeFound.remove(id);
    }
    assertTrue("Not all process instances have been found in result, missing: "
            + StringUtils.join(toBeFound, ", "), toBeFound.isEmpty());
}