Search in sources :

Example 16 with ValidatableResponse

use of com.jayway.restassured.response.ValidatableResponse in project ddf by codice.

the class TestCatalog method testCswUpdateByNewRecord.

@Test
public void testCswUpdateByNewRecord() {
    Response response = ingestCswRecord();
    String requestXml = getFileContent(CSW_REQUEST_RESOURCE_PATH + "/CswUpdateRecordRequest");
    String id;
    try {
        id = getMetacardIdFromCswInsertResponse(response);
    } catch (IOException | XPathExpressionException e) {
        fail("Could not retrieve the ingested record's ID from the response.");
        return;
    }
    requestXml = requestXml.replace("identifier placeholder", id);
    ValidatableResponse validatableResponse = given().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(requestXml).post(CSW_PATH.getUrl()).then();
    validatableResponse.body(hasXPath("//TransactionResponse/TransactionSummary/totalDeleted", is("0")), hasXPath("//TransactionResponse/TransactionSummary/totalInserted", is("0")), hasXPath("//TransactionResponse/TransactionSummary/totalUpdated", is("1")));
    String url = REST_PATH.getUrl() + id;
    when().get(url).then().log().all().assertThat().body(hasXPath("//metacard/dateTime[@name='modified']/value", startsWith("2015-08-10")), hasXPath("//metacard/string[@name='title']/value", is("Updated Title")), hasXPath("//metacard/string[@name='topic.category']/value", is("Updated Subject")), hasXPath("(//metacard/geometry[@name='location']/value/Polygon/exterior/LinearRing/pos)[1]", is("1.0 2.0")), hasXPath("(//metacard/geometry[@name='location']/value/Polygon/exterior/LinearRing/pos)[2]", is("3.0 2.0")), hasXPath("(//metacard/geometry[@name='location']/value/Polygon/exterior/LinearRing/pos)[3]", is("3.0 4.0")), hasXPath("(//metacard/geometry[@name='location']/value/Polygon/exterior/LinearRing/pos)[4]", is("1.0 4.0")), hasXPath("(//metacard/geometry[@name='location']/value/Polygon/exterior/LinearRing/pos)[5]", is("1.0 2.0")));
    deleteMetacard(id);
}
Also used : CswTestCommons.getMetacardIdFromCswInsertResponse(org.codice.ddf.itests.common.csw.CswTestCommons.getMetacardIdFromCswInsertResponse) ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) Response(com.jayway.restassured.response.Response) ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) XPathExpressionException(javax.xml.xpath.XPathExpressionException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IOException(java.io.IOException) SkipUnstableTest(org.codice.ddf.itests.common.annotations.SkipUnstableTest) Test(org.junit.Test) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest)

Example 17 with ValidatableResponse

use of com.jayway.restassured.response.ValidatableResponse in project ddf by codice.

the class TestCatalog method testOpenSearchQuery.

@Test
public void testOpenSearchQuery() throws IOException {
    String id1 = ingestXmlFromResource("/metacard1.xml");
    String id2 = ingestXmlFromResource("/metacard2.xml");
    String id3 = ingestXmlFromResource("/metacard3.xml");
    String id4 = ingestXmlFromResource("/metacard4.xml");
    // Test xml-format response for an all-query
    ValidatableResponse response = executeOpenSearch("xml", "q=*");
    response.body(hasXPath(format(METACARD_X_PATH, id1))).body(hasXPath(format(METACARD_X_PATH, id2))).body(hasXPath(format(METACARD_X_PATH, id3))).body(hasXPath(format(METACARD_X_PATH, id4)));
    // Execute a text search against a value in an indexed field (metadata)
    response = executeOpenSearch("xml", "q=dunder*");
    response.body(hasXPath(format(METACARD_X_PATH, id3))).body(not(hasXPath(format(METACARD_X_PATH, id1)))).body(not(hasXPath(format(METACARD_X_PATH, id2)))).body(not(hasXPath(format(METACARD_X_PATH, id4))));
    // Execute a text search against a value that isn't in any indexed fields
    response = executeOpenSearch("xml", "q=whatisthedealwithairlinefood");
    response.body("metacards.metacard.size()", equalTo(0));
    // Execute a geo search that should match a point card
    response = executeOpenSearch("xml", "lat=40.689", "lon=-74.045", "radius=250");
    response.body(hasXPath(format(METACARD_X_PATH, id1))).body(not(hasXPath(format(METACARD_X_PATH, id2)))).body(not(hasXPath(format(METACARD_X_PATH, id3)))).body(not(hasXPath(format(METACARD_X_PATH, id4))));
    // Execute a geo search...this should match two cards, both polygons around the Space Needle
    response = executeOpenSearch("xml", "lat=47.62", "lon=-122.356", "radius=500");
    response.body(hasXPath(format(METACARD_X_PATH, id2))).body(hasXPath(format(METACARD_X_PATH, id4))).body(not(hasXPath(format(METACARD_X_PATH, id1)))).body(not(hasXPath(format(METACARD_X_PATH, id3))));
    deleteMetacard(id1);
    deleteMetacard(id2);
    deleteMetacard(id3);
    deleteMetacard(id4);
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) SkipUnstableTest(org.codice.ddf.itests.common.annotations.SkipUnstableTest) Test(org.junit.Test) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest)

Example 18 with ValidatableResponse

use of com.jayway.restassured.response.ValidatableResponse in project ddf by codice.

the class TestCatalog method testCswUpdateByFilterConstraint.

@Test
public void testCswUpdateByFilterConstraint() {
    Response firstResponse = ingestCswRecord();
    Response secondResponse = ingestCswRecord();
    ValidatableResponse validatableResponse = given().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(getFileContent(CSW_REQUEST_RESOURCE_PATH + "/CswUpdateByFilterConstraintRequest")).post(CSW_PATH.getUrl()).then();
    validatableResponse.body(hasXPath("//TransactionResponse/TransactionSummary/totalDeleted", is("0")), hasXPath("//TransactionResponse/TransactionSummary/totalInserted", is("0")), hasXPath("//TransactionResponse/TransactionSummary/totalUpdated", is("2")));
    String firstId;
    String secondId;
    try {
        firstId = getMetacardIdFromCswInsertResponse(firstResponse);
        secondId = getMetacardIdFromCswInsertResponse(secondResponse);
    } catch (IOException | XPathExpressionException e) {
        fail("Could not retrieve the ingested record's ID from the response.");
        return;
    }
    String firstUrl = REST_PATH.getUrl() + firstId;
    when().get(firstUrl).then().log().all().assertThat().body(hasXPath("//metacard/dateTime[@name='modified']/value", startsWith("2015-08-25")), hasXPath("//metacard/string[@name='title']/value", is("Updated Title")), hasXPath("//metacard/string[@name='media.format']/value", is("")), // Check that an attribute that was not updated was not changed.
    hasXPath("//metacard/string[@name='topic.category']/value", is("Hydrography--Dictionaries")));
    String secondUrl = REST_PATH.getUrl() + secondId;
    when().get(secondUrl).then().log().all().assertThat().body(hasXPath("//metacard/dateTime[@name='modified']/value", startsWith("2015-08-25")), hasXPath("//metacard/string[@name='title']/value", is("Updated Title")), hasXPath("//metacard/string[@name='media.format']/value", is("")), // Check that an attribute that was not updated was not changed.
    hasXPath("//metacard/string[@name='topic.category']/value", is("Hydrography--Dictionaries")));
    deleteMetacard(firstId);
    deleteMetacard(secondId);
}
Also used : CswTestCommons.getMetacardIdFromCswInsertResponse(org.codice.ddf.itests.common.csw.CswTestCommons.getMetacardIdFromCswInsertResponse) ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) Response(com.jayway.restassured.response.Response) ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) XPathExpressionException(javax.xml.xpath.XPathExpressionException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IOException(java.io.IOException) SkipUnstableTest(org.codice.ddf.itests.common.annotations.SkipUnstableTest) Test(org.junit.Test) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest)

Example 19 with ValidatableResponse

use of com.jayway.restassured.response.ValidatableResponse in project ddf by codice.

the class TestCatalog method testCswXmlIngest.

@Test
public void testCswXmlIngest() {
    Response response = ingestXmlViaCsw();
    ValidatableResponse validatableResponse = response.then();
    validatableResponse.body(hasXPath("//TransactionResponse/TransactionSummary/totalInserted", is("1")), hasXPath("//TransactionResponse/TransactionSummary/totalUpdated", is("0")), hasXPath("//TransactionResponse/TransactionSummary/totalDeleted", is("0")), hasXPath("//TransactionResponse/InsertResult/BriefRecord/title", is("myXmlTitle")), hasXPath("//TransactionResponse/InsertResult/BriefRecord/BoundingBox"));
    try {
        CatalogTestCommons.deleteMetacardUsingCswResponseId(response);
    } catch (IOException | XPathExpressionException e) {
        fail("Could not retrieve the ingested record's ID from the response.");
    }
}
Also used : CswTestCommons.getMetacardIdFromCswInsertResponse(org.codice.ddf.itests.common.csw.CswTestCommons.getMetacardIdFromCswInsertResponse) ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) Response(com.jayway.restassured.response.Response) ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) XPathExpressionException(javax.xml.xpath.XPathExpressionException) IOException(java.io.IOException) SkipUnstableTest(org.codice.ddf.itests.common.annotations.SkipUnstableTest) Test(org.junit.Test) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest)

Example 20 with ValidatableResponse

use of com.jayway.restassured.response.ValidatableResponse in project ddf by codice.

the class TestCatalog method testCombinedCswIngestAndDelete.

@Test
public void testCombinedCswIngestAndDelete() {
    // This record will be deleted with the <Delete> in the next transaction request.
    ingestCswRecord();
    // The record being inserted in this transaction request will be deleted at the end of the
    // test.
    Response response = given().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(getFileContent(CSW_REQUEST_RESOURCE_PATH + "/CswInsertAndDeleteRequest")).post(CSW_PATH.getUrl());
    ValidatableResponse validatableResponse = response.then();
    validatableResponse.body(hasXPath("//TransactionResponse/TransactionSummary/totalDeleted", is("1")), hasXPath("//TransactionResponse/TransactionSummary/totalInserted", is("1")), hasXPath("//TransactionResponse/TransactionSummary/totalUpdated", is("0")));
    try {
        CatalogTestCommons.deleteMetacardUsingCswResponseId(response);
    } catch (IOException | XPathExpressionException e) {
        fail("Could not retrieve the ingested record's ID from the response.");
    }
}
Also used : CswTestCommons.getMetacardIdFromCswInsertResponse(org.codice.ddf.itests.common.csw.CswTestCommons.getMetacardIdFromCswInsertResponse) ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) Response(com.jayway.restassured.response.Response) ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) XPathExpressionException(javax.xml.xpath.XPathExpressionException) IOException(java.io.IOException) SkipUnstableTest(org.codice.ddf.itests.common.annotations.SkipUnstableTest) Test(org.junit.Test) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest)

Aggregations

ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)58 Test (org.junit.Test)51 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)42 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)27 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)24 Response (com.jayway.restassured.response.Response)17 CswQueryBuilder (org.codice.ddf.itests.common.csw.CswQueryBuilder)16 CswTestCommons.getMetacardIdFromCswInsertResponse (org.codice.ddf.itests.common.csw.CswTestCommons.getMetacardIdFromCswInsertResponse)13 IOException (java.io.IOException)11 XPathExpressionException (javax.xml.xpath.XPathExpressionException)11 JsonPath (com.jayway.restassured.path.json.JsonPath)6 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)5 BaseRestTest (integration.BaseRestTest)4 Configuration (org.osgi.service.cm.Configuration)4 Hashtable (java.util.Hashtable)3 JSONObject (org.json.simple.JSONObject)3 HashMap (java.util.HashMap)2 XmlPath (com.jayway.restassured.path.xml.XmlPath)1 File (java.io.File)1 InputStream (java.io.InputStream)1