@Test public void convertsNonRootObjectGraphToJavaObjects() throws Exception { NodeChildren categories = with(XML).get("shopping.category"); assertThat(categories.size(), equalTo(3)); assertThat( categories.toString(), equalTo("Chocolate10Coffee20Paper5Pens15.5Kathryn's Birthday200")); }
private void assertMetacardsIngested(int expectedumberOfMetacards) throws Exception { String queryUrl = OPENSEARCH_PATH.getUrl() + "?q=*&format=xml&src=local"; Response response = when().get(queryUrl); String bodyXml = response.body().asString(); NodeChildren metacards = new XmlPath(bodyXml).get("metacards.metacard"); assertThat(metacards.size(), is(expectedumberOfMetacards)); }
@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"))); } }
@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"))); } }
@Test public void initializeUsingWithAndGetList() throws Exception { final NodeChildren categories = with(XML).get("shopping.category"); assertThat(categories.size(), equalTo(3)); }