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.activiti.rest.api.history.HistoricDetailCollectionResourceTest.java

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

    // Do the actual call
    ClientResource client = getAuthenticatedClient(url);
    Representation response = client.get();

    // Check status and size
    assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());
    JsonNode dataNode = objectMapper.readTree(response.getStream()).get("data");
    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;//from   ww w  . j  a va2 s. c o m
                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);
    }

    client.release();
}

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

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

    // Do the actual call
    ClientResource client = getAuthenticatedClient(url);
    Representation response = client.get();

    // Check status and size
    assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());
    JsonNode dataNode = objectMapper.readTree(response.getStream()).get("data");
    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);
        }/*from  ww w  .  j  ava 2s .c  om*/
        assertTrue("Not all entries have been found in result, missing: " + StringUtils.join(toBeFound, ", "),
                toBeFound.isEmpty());
    }

    client.release();
}

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

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

    // Do the actual call
    ClientResource client = getAuthenticatedClient(url);
    Representation response = client.post(body);

    // Check status and size
    assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());
    JsonNode dataNode = objectMapper.readTree(response.getStream()).get("data");
    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);
        }/*w ww . j  av a2  s. c om*/
        assertTrue("Not all entries have been found in result, missing: " + StringUtils.join(toBeFound, ", "),
                toBeFound.isEmpty());
    }

    client.release();
}

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

/**
 * Test querying historic detail. /* ww w . ja  v a 2s  .  c  o  m*/
 * POST query/historic-detail
 */
@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());
    ClientResource client = getAuthenticatedClient(url);
    Representation response = client.post(requestNode);

    // Check status and size
    assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());
    JsonNode dataNode = objectMapper.readTree(response.getStream()).get("data");

    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();
            client.release();
            client = new ClientResource(valueUrl);
            client.setChallengeResponse(ChallengeScheme.HTTP_BASIC, "kermit", "kermit");
            response = client.get();
            assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());
            byte[] varInput = IOUtils.toByteArray(response.getStream());
            assertEquals("test", new String(varInput));
            break;
        }
    }
    assertTrue(byteVarFound);
}

From source file:org.activiti.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
    ClientResource client = getAuthenticatedClient(url);
    Representation response = client.post(body);

    // Check status and size
    assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());
    JsonNode dataNode = objectMapper.readTree(response.getStream()).get("data");
    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;/*from   www  .j  ava  2s.  c om*/
                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);
    }

    client.release();
}

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

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

    // Do the actual call
    ClientResource client = getAuthenticatedClient(url);
    Representation response = client.get();

    // Check status and size
    assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());
    JsonNode dataNode = objectMapper.readTree(response.getStream()).get("data");
    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);//from   w  ww  . j ava 2 s.co  m
    }
    assertTrue("Not all process instances have been found in result, missing: "
            + StringUtils.join(toBeFound, ", "), toBeFound.isEmpty());

    client.release();
}

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

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

    // Do the actual call
    ClientResource client = getAuthenticatedClient(url);
    Representation response = client.get();

    // Check status and size
    assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());
    JsonNode dataNode = objectMapper.readTree(response.getStream()).get("data");
    assertEquals(numberOfResultsExpected, dataNode.size());

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

    client.release();
}

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

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

    // Do the actual call
    ClientResource client = getAuthenticatedClient(url);
    Representation response = client.post(body);

    // Check status and size
    assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());
    JsonNode dataNode = objectMapper.readTree(response.getStream()).get("data");
    assertEquals(numberOfResultsExpected, dataNode.size());

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

    client.release();
}

From source file:org.flowable.app.rest.service.BaseSpringRestTestCase.java

/**
 * Checks if the returned "data" array (child-node of root-json node returned by invoking a GET on the given url) contains entries with the given ID's.
 *//* w w w  . ja va 2 s  . co  m*/
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), HttpStatus.SC_OK);

    // Check status and size
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);
    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 expected ids have been found in result, missing: " + StringUtils.join(toBeFound, ", "),
            toBeFound.isEmpty());
}

From source file:org.flowable.app.rest.service.BaseSpringRestTestCase.java

protected void assertResultsPresentInPostDataResponseWithStatusCheck(String url, ObjectNode body,
        int expectedStatusCode, String... expectedResourceIds) throws JsonProcessingException, IOException {
    int numberOfResultsExpected = 0;
    if (expectedResourceIds != null) {
        numberOfResultsExpected = expectedResourceIds.length;
    }//from  w  w  w . j  av  a2 s. com

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

    if (expectedStatusCode == HttpStatus.SC_OK) {
        // Check status and size
        JsonNode rootNode = objectMapper.readTree(response.getEntity().getContent());
        JsonNode dataNode = rootNode.get("data");
        assertEquals(numberOfResultsExpected, dataNode.size());

        // Check presence of ID's
        if (expectedResourceIds != null) {
            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 entries have been found in result, missing: " + StringUtils.join(toBeFound, ", "),
                    toBeFound.isEmpty());
        }
    }

    closeResponse(response);
}