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();
}
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;
}
}
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);
}
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);
}
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);
}
Aggregations