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

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

Introduction

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

Prototype

public int size() 

Source Link

Usage

From source file:com.infinities.keystone4j.admin.v3.domain.DomainResourceTest.java

@Test
public void testListGrantByGroup() throws JsonProcessingException, IOException {
    final List<Role> roles = new ArrayList<Role>();
    roles.add(role1);//from  w  w  w  .  java2 s  .c om

    Response response = target("/v3/domains").path(domain.getId()).path("groups").path(group.getId())
            .path("roles").register(JacksonFeature.class).register(ObjectMapperResolver.class).request()
            .header("X-Auth-Token", Config.Instance.getOpt(Config.Type.DEFAULT, "admin_token").asText()).get();
    assertEquals(200, response.getStatus());
    String ret = response.readEntity(String.class);
    System.err.println(ret);
    JsonNode node = JsonUtils.convertToJsonNode(ret);
    JsonNode roleJ = node.get("roles");
    assertEquals(1, roleJ.size());
}

From source file:com.infinities.keystone4j.admin.v3.user.UserV3ResourceTest.java

@Test
public void testListUsers() throws JsonProcessingException, IOException {
    final List<User> users = new ArrayList<User>();
    users.add(user);/*ww w . j a  v  a  2 s. c o  m*/

    Response response = target("/v3/users").register(JacksonFeature.class).register(ObjectMapperResolver.class)
            .request()
            .header("X-Auth-Token", Config.Instance.getOpt(Config.Type.DEFAULT, "admin_token").asText()).get();
    assertEquals(200, response.getStatus());
    JsonNode node = JsonUtils.convertToJsonNode(response.readEntity(String.class));
    System.err.println(node.toString());
    JsonNode usersJ = node.get("users");
    assertEquals(2, usersJ.size());
    JsonNode userJ = usersJ.get(0);
    assertNotNull(userJ.get("id").asText());
    assertNotNull(userJ.get("name").asText());
    assertNotNull(userJ.get("description").asText());
    assertNotNull(userJ.get("domain_id").asText());
    assertNotNull(userJ.get("default_project_id").asText());
    assertNotNull(userJ.get("enabled").asText());
    assertNotNull(userJ.get("links"));
    assertNotNull(userJ.get("links").get("self").asText());
    assertNull(userJ.get("password"));
}

From source file:com.infinities.keystone4j.admin.v3.user.UserV3ResourceTest.java

@Test
public void testListUserProjects() throws JsonProcessingException, IOException {
    final List<Project> projects = new ArrayList<Project>();
    projects.add(project);/*from   w w  w. ja  v  a  2s .c om*/

    Response response = target("/v3/users").path(user.getId()).path("projects").register(JacksonFeature.class)
            .register(ObjectMapperResolver.class).request()
            .header("X-Auth-Token", Config.Instance.getOpt(Config.Type.DEFAULT, "admin_token").asText()).get();
    assertEquals(200, response.getStatus());
    JsonNode node = JsonUtils.convertToJsonNode(response.readEntity(String.class));
    System.err.println(node.toString());
    JsonNode projectsJ = node.get("projects");
    assertEquals(1, projectsJ.size());
    JsonNode projectJ = projectsJ.get(0);
    assertEquals(project.getId(), projectJ.get("id").asText());
    assertEquals(project.getName(), projectJ.get("name").asText());
    assertEquals(project.getDomain().getId(), projectJ.get("domain_id").asText());
}

From source file:com.googlecode.batchfb.test.QueryResultSizeTest.java

/**
 * Run the query through BatchFB and by hand and ensure the result set is same size.
 *///from  ww  w. ja  v a2s .  c om
private void ensureQueryIsCorrectSize(String query) throws Exception {
    String url = "https://api.facebook.com/method/fql.query?format=json&query="
            + URLEncoder.encode(query, "utf-8") + "&access_token=" + ACCESS_TOKEN;
    URL manual = new URL(url);
    System.out.println("Manual URL is: " + url);
    JsonNode manualNodes = new ObjectMapper().readTree(manual.openStream());
    assert manualNodes instanceof ArrayNode;

    Later<ArrayNode> nodes = this.authBatcher.query(query);
    System.out.println("Query obtained " + nodes.get().size() + " items");

    assert manualNodes.size() == nodes.get().size();
}

From source file:org.activiti.rest.service.api.history.HistoricVariableInstanceQueryResourceTest.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, HttpStatus.SC_OK);

    // Check status and size
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);//from   w  ww  . ja v  a  2  s.co 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 dataElementNode = it.next();
            JsonNode variableNode = dataElementNode.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.HistoricVariableInstanceQueryResourceTest.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, HttpStatus.SC_OK);

    // Check status and size
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);/*www  . j  a  va 2 s  .  co 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 dataElementNode = it.next();
            JsonNode variableNode = dataElementNode.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) {
                    assertEquals("Variable value is not equal", variableNode.get("value").asInt(),
                            (int) (Integer) variableValue);
                } else {
                    assertEquals("Variable value is not equal", variableNode.get("value").asText(),
                            (String) variableValue);
                }
            }
        }
        assertTrue("Variable " + variableName + " is missing", variableFound);
    }
}

From source file:cf.spring.servicebroker.CatalogTest.java

@Test
public void emptyCatalog() throws Exception {
    final SpringApplication application = new SpringApplication(EmptyServiceBrokerCatalog.class);
    try (ConfigurableApplicationContext context = application.run();
            CloseableHttpClient client = buildAuthenticatingClient()) {
        JsonNode catalog = loadCatalog(client);
        assertNotNull(catalog);/*from w  w  w. j a  v  a  2s.c  om*/
        assertTrue(catalog.has("services"));
        final JsonNode services = catalog.get("services");
        assertTrue(services.isArray());
        assertEquals(services.size(), 0);
    }
}

From source file:com.infinities.keystone4j.admin.v3.domain.DomainResourceTest.java

@Test
public void testListDomain() throws JsonProcessingException, IOException {
    final List<Domain> domains = new ArrayList<Domain>();
    domains.add(domain);/*from   w  w w . j  av  a2 s.c  om*/

    Response response = target("/v3/domains").register(JacksonFeature.class)
            .register(ObjectMapperResolver.class).request()
            .header("X-Auth-Token", Config.Instance.getOpt(Config.Type.DEFAULT, "admin_token").asText()).get();
    assertEquals(200, response.getStatus());
    String ret = response.readEntity(String.class);
    System.err.println(ret);
    JsonNode node = JsonUtils.convertToJsonNode(ret);
    JsonNode domainsJ = node.get("domains");
    assertEquals(1, domainsJ.size());
    JsonNode domainJ = domainsJ.get(0);
    assertEquals(domain.getId(), domainJ.get("id").asText());
    assertEquals(domain.getName(), domainJ.get("name").asText());
    assertEquals(domain.getDescription(), domainJ.get("description").asText());
}

From source file:com.infinities.keystone4j.admin.v3.project.ProjectResourceTest.java

@Test
public void testListGrantByUser() throws JsonProcessingException, IOException {
    final List<Role> roles = new ArrayList<Role>();
    roles.add(role1);// w ww  .  j  a v  a  2  s .  co m

    Response response = target("/v3/projects").path(project.getId()).path("users").path(user.getId())
            .path("roles").register(JacksonFeature.class).register(ObjectMapperResolver.class).request()
            .header("X-Auth-Token", Config.Instance.getOpt(Config.Type.DEFAULT, "admin_token").asText()).get();
    assertEquals(200, response.getStatus());
    String ret = response.readEntity(String.class);
    System.err.println(ret);
    JsonNode node = JsonUtils.convertToJsonNode(ret);
    JsonNode roleList = node.get("roles");
    assertEquals(1, roleList.size());
    JsonNode roleJ = roleList.get(0);
    assertEquals(role1.getId(), roleJ.get("id").asText());
    assertEquals(role1.getName(), roleJ.get("name").asText());
    assertEquals(role1.getDescription(), roleJ.get("description").asText());
}

From source file:com.infinities.keystone4j.admin.v3.project.ProjectResourceTest.java

@Test
public void testListGrantByGroup() throws JsonProcessingException, IOException {
    final List<Role> roles = new ArrayList<Role>();
    roles.add(role1);//from   www  .j  a va  2s  .co m

    Response response = target("/v3/projects").path(project.getId()).path("groups").path(group.getId())
            .path("roles").register(JacksonFeature.class).register(ObjectMapperResolver.class).request()
            .header("X-Auth-Token", Config.Instance.getOpt(Config.Type.DEFAULT, "admin_token").asText()).get();
    assertEquals(200, response.getStatus());
    String ret = response.readEntity(String.class);
    System.err.println(ret);
    JsonNode node = JsonUtils.convertToJsonNode(ret);
    JsonNode roleList = node.get("roles");
    assertEquals(1, roleList.size());
    JsonNode roleJ = roleList.get(0);
    assertEquals(role1.getId(), roleJ.get("id").asText());
    assertEquals(role1.getName(), roleJ.get("name").asText());
    assertEquals(role1.getDescription(), roleJ.get("description").asText());
}