Search in sources :

Example 1 with Node

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

the class XmlPathErrorMessageTest method error_messages_on_invalid_subpath_looks_ok_when_received_node_is_not_root.

@Test
public void error_messages_on_invalid_subpath_looks_ok_when_received_node_is_not_root() {
    exception.expect(IllegalArgumentException.class);
    exception.expectMessage("Invalid path:\n" + "unexpected token: [ @ line 1, column 37.\n" + "   item.price.[0]\n" + "              ^\n" + "\n" + "1 error");
    Node firstCategory = with(XML).get("shopping.category[0]");
    firstCategory.getPath("item.price.[0]", float.class);
}
Also used : Node(io.restassured.path.xml.element.Node) Test(org.junit.Test)

Example 2 with Node

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

the class XmlPathTest method xmlPathCanExtractNodeFromSoap.

@Test
public void xmlPathCanExtractNodeFromSoap() throws Exception {
    // Given
    String soap = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<env:Envelope \n" + "    xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" \n" + "    xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n" + "    xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\" \n" + "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + "    <env:Header/>\n" + "\n" + "<env:Body>\n" + "    <n1:importProjectResponse \n" + "        xmlns:n1=\"n1\" \n" + "        xmlns:n2=\"n2\" \n" + "        xsi:type=\"n2:ArrayOfProjectImportResultCode\">\n" + "        <n2:ProjectImportResultCode>\n" + "            <n2:code>1</n2:code>\n" + "            <n2:message>Project 'test1' import was successful.</n2:message>\n" + "        </n2:ProjectImportResultCode>\n" + "    </n1:importProjectResponse>\n" + "</env:Body></env:Envelope>";
    // When
    XmlPath xmlPath = new XmlPath(soap);
    Node node = xmlPath.getNode("Envelope");
    // Then
    assertThat(node.<String>getPath("Body.importProjectResponse.ProjectImportResultCode.code"), equalTo("1"));
}
Also used : XmlPath(io.restassured.path.xml.XmlPath) Node(io.restassured.path.xml.element.Node) Test(org.junit.Test)

Example 3 with Node

use of io.restassured.path.xml.element.Node 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 4 with Node

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

the class XmlPathTest method getNodeChildrenAsListWithTypeNodeReturnsAListOfNodes.

@Test
public void getNodeChildrenAsListWithTypeNodeReturnsAListOfNodes() throws Exception {
    final List<Node> categories = new XmlPath(XML).getList("shopping.category", Node.class);
    assertThat(categories.size(), equalTo(3));
}
Also used : XmlPath(io.restassured.path.xml.XmlPath) Node(io.restassured.path.xml.element.Node) Test(org.junit.Test)

Example 5 with Node

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

the class XmlPathTest method getEntireObjectGraph.

@Test
public void getEntireObjectGraph() throws Exception {
    final Node node = with(XML).get();
    assertThat(node.name(), is("shopping"));
}
Also used : Node(io.restassured.path.xml.element.Node) Test(org.junit.Test)

Aggregations

Node (io.restassured.path.xml.element.Node)12 Test (org.junit.Test)12 NodeChildren (io.restassured.path.xml.element.NodeChildren)3 XmlPath (io.restassured.path.xml.XmlPath)2