Search in sources :

Example 11 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 12 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 13 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 14 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)

Example 15 with ValidatableResponse

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

the class TestCatalog method testIngestPlugin.

@Test
public void testIngestPlugin() throws Exception {
    //ingest a data set to make sure we don't have any issues initially
    String id1 = ingestGeoJson(getFileContent(JSON_RECORD_RESOURCE_PATH + "/SimpleGeoJsonRecord"));
    String xPath1 = format(METACARD_X_PATH, id1);
    //verify ingest by querying
    ValidatableResponse response = executeOpenSearch("xml", "q=*");
    response.body(hasXPath(xPath1));
    //change ingest plugin role to ingest
    CatalogPolicyProperties catalogPolicyProperties = new CatalogPolicyProperties();
    catalogPolicyProperties.put("createPermissions", new String[] { "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role=ingest" });
    Configuration config = configAdmin.getConfiguration("org.codice.ddf.catalog.security.CatalogPolicy", null);
    Dictionary<String, Object> configProps = new Hashtable<>(catalogPolicyProperties);
    config.update(configProps);
    getServiceManager().waitForAllBundles();
    //try ingesting again - it should fail this time
    given().body(getFileContent(JSON_RECORD_RESOURCE_PATH + "/SimpleGeoJsonRecord")).header(HttpHeaders.CONTENT_TYPE, "application/json").expect().log().all().statusCode(400).when().post(REST_PATH.getUrl());
    //verify query for first id works
    response = executeOpenSearch("xml", "q=*");
    response.body(hasXPath(xPath1));
    //revert to original configuration
    configProps.put("createPermissions", new String[] { "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role=guest" });
    config.update(configProps);
    getServiceManager().waitForAllBundles();
    deleteMetacard(id1);
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) JSONObject(org.json.simple.JSONObject) 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)

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