Ejemplo n.º 1
0
  @Test
  public void givenANode_whenRemovingFromATree_thenCorrect() throws IOException {
    final JsonNode rootNode = ExampleStructure.getExampleRoot();
    ((ObjectNode) rootNode).remove("company");

    assertTrue(rootNode.path("company").isMissingNode());
  }
Ejemplo n.º 2
0
  @Test
  public void givenANode_whenModifyingIt_thenCorrect() throws IOException {
    final String newString = "{\"nick\": \"cowtowncoder\"}";
    final JsonNode newNode = mapper.readTree(newString);

    final JsonNode rootNode = ExampleStructure.getExampleRoot();
    ((ObjectNode) rootNode).set("name", newNode);

    assertFalse(rootNode.path("name").path("nick").isMissingNode());
    assertEquals("cowtowncoder", rootNode.path("name").path("nick").textValue());
  }
Ejemplo n.º 3
0
  @Test
  public void givenANode_whenAddingIntoATree_thenCorrect() throws IOException {
    final JsonNode rootNode = ExampleStructure.getExampleRoot();
    final ObjectNode addedNode = ((ObjectNode) rootNode).putObject("address");
    addedNode.put("city", "Seattle").put("state", "Washington").put("country", "United States");

    assertFalse(rootNode.path("address").isMissingNode());
    assertEquals("Seattle", rootNode.path("address").path("city").textValue());
    assertEquals("Washington", rootNode.path("address").path("state").textValue());
    assertEquals("United States", rootNode.path("address").path("country").textValue());
  }