Search in sources :

Example 1 with XmlPathConfig

use of io.restassured.path.xml.config.XmlPathConfig in project ddf by codice.

the class WfsFilterDelegateTest method testPropertyIsRelative.

@Test
public void testPropertyIsRelative() throws JAXBException {
    final WfsFilterDelegate delegate = createSinglePropertyDelegate();
    final FilterType filter = delegate.relative(MOCK_PROPERTY, 100_000L);
    final String xml = marshal(filter);
    final XmlPathConfig config = new XmlPathConfig().declaredNamespace("ogc", "http://www.opengis.net/ogc");
    final XmlPath xmlPath = new XmlPath(xml).using(config);
    final String lowerBoundary = xmlPath.getString("ogc:Filter.ogc:PropertyIsBetween.ogc:LowerBoundary.ogc:Literal");
    assertThat("There was no lower boundary in the filter XML.", lowerBoundary, not(isEmptyOrNullString()));
    final String upperBoundary = xmlPath.getString("ogc:Filter.ogc:PropertyIsBetween.ogc:UpperBoundary.ogc:Literal");
    assertThat("There was no upper boundary in the filter XML.", upperBoundary, not(isEmptyOrNullString()));
    final long start = OffsetDateTime.parse(lowerBoundary).toInstant().toEpochMilli();
    final long end = OffsetDateTime.parse(upperBoundary).toInstant().toEpochMilli();
    assertThat("The dates were not 100 seconds apart.", end - start, is(100_000L));
}
Also used : XmlPath(io.restassured.path.xml.XmlPath) XmlPathConfig(io.restassured.path.xml.config.XmlPathConfig) FilterType(net.opengis.filter.v_1_1_0.FilterType) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Test(org.junit.Test)

Example 2 with XmlPathConfig

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

the class XmlPathCharsetTest method xml_path_cannot_correctly_deserialize_input_stream_using_wrong_charset.

@Test
public void xml_path_cannot_correctly_deserialize_input_stream_using_wrong_charset() throws UnsupportedEncodingException {
    // Given
    InputStream is = new ByteArrayInputStream(GREETING_WITH_STRANGE_CHARS.getBytes("US-ASCII"));
    XmlPath xmlPath = new XmlPath(is).using(new XmlPathConfig("ISO-8859-1"));
    // When
    final String firstName = xmlPath.getString("greeting.firstName");
    final String lastName = xmlPath.getString("greeting.lastName");
    // Then
    assertThat(firstName, containsString("?%#??"));
    assertThat(lastName, containsString("`?"));
}
Also used : XmlPathConfig(io.restassured.path.xml.config.XmlPathConfig) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 3 with XmlPathConfig

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

the class XmlPathCharsetTest method xml_path_supports_deserializing_input_stream_using_with_given_charset.

@Test
public void xml_path_supports_deserializing_input_stream_using_with_given_charset() throws UnsupportedEncodingException {
    // Given
    InputStream is = new ByteArrayInputStream(GREETING_WITH_STRANGE_CHARS.getBytes("UTF-16"));
    XmlPath xmlPath = new XmlPath(is).using(new XmlPathConfig("UTF-16"));
    // When
    final String firstName = xmlPath.getString("greeting.firstName");
    final String lastName = xmlPath.getString("greeting.lastName");
    // Then
    assertThat(firstName, equalTo("€%#åö"));
    assertThat(lastName, equalTo("`ü"));
}
Also used : XmlPathConfig(io.restassured.path.xml.config.XmlPathConfig) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

XmlPathConfig (io.restassured.path.xml.config.XmlPathConfig)3 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 XmlPath (io.restassured.path.xml.XmlPath)1 FilterType (net.opengis.filter.v_1_1_0.FilterType)1 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)1