Search in sources :

Example 6 with XmlPath

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

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

the class SimplePathITest method simpleXmlValidationWithXmlPath.

@Test
public void simpleXmlValidationWithXmlPath() throws Exception {
    final String body = get("/greetXML?firstName=John&lastName=Doe").asString();
    final XmlPath xml = new XmlPath(body).setRoot("greeting");
    final String firstName = xml.getString("firstName");
    final String lastName = xml.getString("lastName");
    assertThat(firstName, equalTo("John"));
    assertThat(lastName, equalTo("Doe"));
}
Also used : XmlPath(io.restassured.path.xml.XmlPath) Test(org.junit.Test)

Example 8 with XmlPath

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

the class TestSpatial method assertMetacards.

private void assertMetacards(String responseXml, int expectedNumMetacards, String expectedSource, String expectedType) {
    XmlPath xmlPath = new XmlPath(responseXml);
    int numMetacards = xmlPath.get("metacards.metacard.size()");
    assertThat(numMetacards, equalTo(expectedNumMetacards));
    for (int i = 0; i < numMetacards; i++) {
        assertThat(xmlPath.get("metacards.metacard[" + i + "].type"), equalTo(expectedType));
        assertThat(xmlPath.get("metacards.metacard[" + i + "].source"), equalTo(expectedSource));
    }
}
Also used : XmlPath(io.restassured.path.xml.XmlPath)

Example 9 with XmlPath

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

the class TestFederation method getEvents.

private Set<String> getEvents(String subscriptionId) {
    HashSet<String> foundIds = new HashSet<>();
    List<Call> calls = new ArrayList<>(server.getCalls());
    if (CollectionUtils.isNotEmpty(calls)) {
        for (Call call : calls) {
            if (call.getMethod().matchesMethod(Method.POST.getMethodString()) && StringUtils.isNotEmpty(call.getPostBody())) {
                LOGGER.debug("Event received '{}'", call.getPostBody());
                XmlPath xmlPath = new XmlPath(call.getPostBody());
                String id;
                try {
                    String foundSubscriptionId = xmlPath.get("GetRecordsResponse.RequestId");
                    if (StringUtils.isNotBlank(foundSubscriptionId) && subscriptionId.equals(foundSubscriptionId)) {
                        id = xmlPath.get("GetRecordsResponse.SearchResults.Record.identifier");
                        if (StringUtils.isNotEmpty(id)) {
                            foundIds.add(StringUtils.trim(id));
                        }
                    } else {
                        LOGGER.info("event for id {} not found.", subscriptionId);
                    }
                } catch (ClassCastException e) {
                    // not necessarily a problem that an particular path (event) wasn't found
                    LOGGER.info("Unable to evaluate path for event {}", subscriptionId);
                }
            }
        }
        LOGGER.debug("Id {}, Event Found Ids: {}", subscriptionId, Arrays.toString(foundIds.toArray()));
    }
    return foundIds;
}
Also used : XmlPath(io.restassured.path.xml.XmlPath) Call(com.xebialabs.restito.semantics.Call) ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) HashSet(java.util.HashSet)

Example 10 with XmlPath

use of io.restassured.path.xml.XmlPath 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)

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