Exemplo n.º 1
0
 @Test
 public void gettingChildrenFromJava() throws Exception {
   Node category = with(XML).get("shopping.category[0]");
   final NodeChildren categoryChildren = category.children();
   assertThat(categoryChildren.size(), equalTo(2));
   for (Node item : categoryChildren.nodeIterable()) {
     assertThat(item.children().size(), equalTo(2));
     final Node name = item.get("name");
     final Node price = item.get("price");
     assertThat(name.value(), anyOf(equalTo("Chocolate"), equalTo("Coffee")));
     assertThat(price.value(), anyOf(equalTo("10"), equalTo("20")));
   }
 }
Exemplo n.º 2
0
  @Test
  public void itemsWithPriceBetweenTenAndTwenty() throws Exception {
    final List<Node> itemsBetweenTenAndTwenty =
        with(XML)
            .get(
                "shopping.category.item.findAll { item -> def price = item.price.toFloat(); price >= 10 && price <= 20 }");
    assertThat(itemsBetweenTenAndTwenty.size(), equalTo(3));

    final Node category1 = itemsBetweenTenAndTwenty.get(0);
    final NodeChildren categoryChildren = category1.children();
    assertThat(categoryChildren, hasItems("Chocolate", "10"));

    for (Node item : categoryChildren.nodeIterable()) {
      assertThat(item.name(), anyOf(equalTo("name"), equalTo("price")));
    }
  }