Search in sources :

Example 11 with XmlPath

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

the class XmlPathTest method doesntNeedToEscapeListsWithHyphenWithoutBrackets.

@Test
public void doesntNeedToEscapeListsWithHyphenWithoutBrackets() throws Exception {
    // Given
    String xml = "<root><some-list>one</some-list><some-list>two</some-list></root>";
    // When
    XmlPath xmlPath = from(xml);
    // Then
    assertThat(xmlPath.getString("root.some-list[0]"), equalTo("one"));
}
Also used : XmlPath(io.restassured.path.xml.XmlPath) Test(org.junit.Test)

Example 12 with XmlPath

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

the class XmlPathTest method setting_feature_works.

@Test
public void setting_feature_works() throws Exception {
    // Given
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE LegacyService SYSTEM \"http://example.com/dtd/NonExistent.dtd\">\n" + "<LegacyService>Text</LegacyService>";
    // When
    final XmlPath xmlPath = new XmlPath(xml).using(XmlPathConfig.xmlPathConfig().with().feature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false).feature("http://apache.org/xml/features/disallow-doctype-decl", false));
    // Then
    assertThat(xmlPath.getString("LegacyService"), equalTo("Text"));
}
Also used : XmlPath(io.restassured.path.xml.XmlPath) Test(org.junit.Test)

Example 13 with XmlPath

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

the class XmlPathTest method xmlPathWorksWithSoap.

@Test
public void xmlPathWorksWithSoap() 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);
    // Then
    assertThat(xmlPath.getString("Envelope.Body.importProjectResponse.ProjectImportResultCode.code"), equalTo("1"));
}
Also used : XmlPath(io.restassured.path.xml.XmlPath) Test(org.junit.Test)

Example 14 with XmlPath

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

the class XmlPathTest method trying_to_get_an_attribute_that_doesnt_exists_returns_null.

@Test
public void trying_to_get_an_attribute_that_doesnt_exists_returns_null() {
    // Given
    String xml = // 
    "  <root>" + // 
    "   <item type=\"normal\">item_1_content</item>" + // 
    "   <item type=\"special\">item_1_content</item>" + // 
    "   <item type=\"\">item_1_content</item>" + // 
    "   <item>item_2_content</item>" + " </root>";
    // When
    XmlPath xmlPath = new XmlPath(xml).setRoot("root");
    // Then
    assertThat(xmlPath.getString("item[3].@type"), nullValue());
}
Also used : XmlPath(io.restassured.path.xml.XmlPath) Test(org.junit.Test)

Example 15 with XmlPath

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

the class XmlPathTest method disableDtdValidationWorks.

@Test
public void disableDtdValidationWorks() throws Exception {
    // Given
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE LegacyService SYSTEM \"http://example.com/dtd/NonExistent.dtd\">\n" + "<LegacyService>Text</LegacyService>";
    // When
    final XmlPath xmlPath = new XmlPath(xml).using(XmlPathConfig.xmlPathConfig().with().disableLoadingOfExternalDtd());
    // Then
    assertThat(xmlPath.getString("LegacyService"), equalTo("Text"));
}
Also used : XmlPath(io.restassured.path.xml.XmlPath) Test(org.junit.Test)

Aggregations

XmlPath (io.restassured.path.xml.XmlPath)21 Test (org.junit.Test)18 Node (io.restassured.path.xml.element.Node)2 HashMap (java.util.HashMap)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Call (com.xebialabs.restito.semantics.Call)1 XmlPathConfig (io.restassured.path.xml.config.XmlPathConfig)1 NodeChildren (io.restassured.path.xml.element.NodeChildren)1 ValidatableResponse (io.restassured.response.ValidatableResponse)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 FilterType (net.opengis.filter.v_1_1_0.FilterType)1 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)1 ConditionalIgnore (org.codice.ddf.itests.common.annotations.ConditionalIgnoreRule.ConditionalIgnore)1 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)1 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)1 HasXPath.hasXPath (org.hamcrest.xml.HasXPath.hasXPath)1 JSONObject (org.json.simple.JSONObject)1 Ignore (org.junit.Ignore)1