Search in sources :

Example 6 with ValidatableResponse

use of com.jayway.restassured.response.ValidatableResponse in project graylog2-server by Graylog2.

the class StreamsTest method creatingIncompleteStreamShouldFail.

@Test
public void creatingIncompleteStreamShouldFail() throws Exception {
    final int beforeCount = streamCount();
    final ValidatableResponse response = createStreamFromRequest(jsonResourceForMethod());
    response.statusCode(400);
    final int afterCount = streamCount();
    assertThat(afterCount).isEqualTo(beforeCount);
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) Test(org.junit.Test) BaseRestTest(integration.BaseRestTest)

Example 7 with ValidatableResponse

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

the class CatalogTestCommons method ingestCswRecord.

public static String ingestCswRecord(String cswRecord) {
    String transactionRequest = getCswInsertRequest("csw:Record", cswRecord);
    ValidatableResponse response = given().body(transactionRequest).header("Content-Type", MediaType.APPLICATION_XML).when().post(CSW_PATH.getUrl()).then().assertThat().statusCode(equalTo(HttpStatus.SC_OK));
    return response.extract().body().xmlPath().get("Transaction.InsertResult.BriefRecord.identifier").toString();
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse)

Example 8 with ValidatableResponse

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

the class CatalogTestCommons method doesMetacardExist.

/**
     * Does a wildcard search and verifies that one of the results is a metacard with the given id.
     * This doesn't query directly on the metacard id because that query can return the metacard
     * before it has been committed to the catalog. Metacards that have not been committed to the
     * catalog will not be returned in queries unless that query is a metacard id query.
     *
     * @param id The metacard id to look up
     * @return returns true if the metacard is in the catalog, false otherwise.
     */
public static boolean doesMetacardExist(String id) {
    try {
        String query = new CswQueryBuilder().addAttributeFilter(PROPERTY_IS_LIKE, "AnyText", "*").getQuery();
        ValidatableResponse response = given().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(query).post(CSW_PATH.getUrl()).then();
        response.body(hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id)));
        return true;
    } catch (AssertionError e) {
        return false;
    }
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) CswQueryBuilder(org.codice.ddf.itests.common.csw.CswQueryBuilder)

Example 9 with ValidatableResponse

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

the class TestCatalog method testCswUpdateRemoveAttributesByCqlConstraint.

@Test
public void testCswUpdateRemoveAttributesByCqlConstraint() {
    Response response = ingestCswRecord();
    String id;
    try {
        id = getMetacardIdFromCswInsertResponse(response);
    } catch (IOException | XPathExpressionException e) {
        fail("Could not retrieve the ingested record's ID from the response.");
        return;
    }
    String url = REST_PATH.getUrl() + id;
    when().get(url).then().log().all().assertThat().body(hasXPath("//metacard/dateTime[@name='modified']"), hasXPath("//metacard/string[@name='title']"), hasXPath("//metacard/geometry[@name='location']"));
    ValidatableResponse validatableResponse = given().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(getFileContent(CSW_REQUEST_RESOURCE_PATH + "/CswUpdateRemoveAttributesByCqlConstraintRequest")).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")));
    when().get(url).then().log().all().assertThat().body(not(hasXPath("//metacard/string[@name='title']")), not(hasXPath("//metacard/geometry[@name='location']")), // Check that an attribute that was not updated was not changed.
    hasXPath("//metacard/dateTime[@name='modified']"), hasXPath("//metacard/string[@name='topic.category']/value", is("Hydrography--Dictionaries")));
    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 10 with ValidatableResponse

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

the class TestCatalog method testCswGetRecordsWithHitsResultType.

@Test
public void testCswGetRecordsWithHitsResultType() {
    Response response = ingestCswRecord();
    String query = getCswQuery("AnyText", "*", "application/xml", "http://www.opengis.net/cat/csw/2.0.2");
    String id;
    try {
        id = getMetacardIdFromCswInsertResponse(response);
    } catch (IOException | XPathExpressionException e) {
        fail("Could not retrieve the ingested record's ID from the response.");
        return;
    }
    //test with resultType="results" first
    ValidatableResponse validatableResponse = given().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(query).post(CSW_PATH.getUrl()).then();
    validatableResponse.body(hasXPath("/GetRecordsResponse/SearchResults/Record"));
    //test with resultType="hits"
    query = query.replace("results", "hits");
    validatableResponse = given().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(query).post(CSW_PATH.getUrl()).then();
    //assert that no records have been returned
    validatableResponse.body(not(hasXPath("//Record")));
    //testing with resultType='validate' is not
    //possible due to DDF-1537, this test will need
    //to be updated to test this once it is fixed.
    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)

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