Search in sources :

Example 1 with NodeChildren

use of io.restassured.path.xml.element.NodeChildren in project rest-assured by rest-assured.

the class XmlPathTest method initializeUsingCtorAndGetList.

@Test
public void initializeUsingCtorAndGetList() throws Exception {
    final NodeChildren categories = new XmlPath(XML).get("shopping.category");
    assertThat(categories.size(), equalTo(3));
}
Also used : XmlPath(io.restassured.path.xml.XmlPath) NodeChildren(io.restassured.path.xml.element.NodeChildren) Test(org.junit.Test)

Example 2 with NodeChildren

use of io.restassured.path.xml.element.NodeChildren in project rest-assured by rest-assured.

the class XmlPathTest method gettingChildrenFromJava.

@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")));
    }
}
Also used : Node(io.restassured.path.xml.element.Node) NodeChildren(io.restassured.path.xml.element.NodeChildren) Test(org.junit.Test)

Example 3 with NodeChildren

use of io.restassured.path.xml.element.NodeChildren in project rest-assured by rest-assured.

the class XmlPathTest method initializeUsingWithAndGetList.

@Test
public void initializeUsingWithAndGetList() throws Exception {
    final NodeChildren categories = with(XML).get("shopping.category");
    assertThat(categories.size(), equalTo(3));
}
Also used : NodeChildren(io.restassured.path.xml.element.NodeChildren) Test(org.junit.Test)

Example 4 with NodeChildren

use of io.restassured.path.xml.element.NodeChildren in project rest-assured by rest-assured.

the class XmlPathSubPathTest method subpath_works_for_lists.

@Test
public void subpath_works_for_lists() {
    Node category = with(XML).get("shopping");
    final NodeChildren names = category.getPath("category[0].item.name");
    assertThat(names, hasItems("Chocolate", "Coffee"));
}
Also used : Node(io.restassured.path.xml.element.Node) NodeChildren(io.restassured.path.xml.element.NodeChildren) Test(org.junit.Test)

Example 5 with NodeChildren

use of io.restassured.path.xml.element.NodeChildren in project rest-assured by rest-assured.

the class XmlPath method getAsList.

private <T> List<T> getAsList(String path, final Class<?> explicitType) {
    Object returnObject = get(path);
    if (returnObject instanceof NodeChildren) {
        final NodeChildren nodeChildren = (NodeChildren) returnObject;
        returnObject = convertElementsListTo(nodeChildren.list(), explicitType);
    } else if (!(returnObject instanceof List)) {
        final List<T> asList = new ArrayList<T>();
        if (returnObject != null) {
            final T e;
            if (explicitType == null) {
                e = (T) returnObject.toString();
            } else {
                e = (T) convertObjectTo(returnObject, explicitType);
            }
            asList.add(e);
        }
        returnObject = asList;
    } else if (explicitType != null) {
        final List<?> returnObjectAsList = (List<?>) returnObject;
        final List<T> convertedList = new ArrayList<T>();
        for (Object o : returnObjectAsList) {
            convertedList.add((T) convertObjectTo(o, explicitType));
        }
        returnObject = convertedList;
    }
    return returnObject == null ? null : Collections.unmodifiableList((List<T>) returnObject);
}
Also used : NodeChildren(io.restassured.path.xml.element.NodeChildren)

Aggregations

NodeChildren (io.restassured.path.xml.element.NodeChildren)7 Test (org.junit.Test)6 Node (io.restassured.path.xml.element.Node)3 XmlPath (io.restassured.path.xml.XmlPath)1