Search in sources :

Example 26 with ValidatableResponse

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

the class TestCatalog method testCreateStorageCannotOverrideResourceUri.

@Test
public void testCreateStorageCannotOverrideResourceUri() throws IOException {
    String fileName = testName.getMethodName() + ".jpg";
    String overrideResourceUri = "content:abc123";
    String overrideTitle = "overrideTitle";
    File tmpFile = createTemporaryFile(fileName, IOUtils.toInputStream(getFileContent(SAMPLE_IMAGE)));
    String id = given().multiPart("parse.resource", tmpFile).multiPart(Core.TITLE, overrideTitle).multiPart(Core.RESOURCE_URI, overrideResourceUri).expect().log().headers().statusCode(201).when().post(REST_PATH.getUrl()).getHeader("id");
    String metacardPath = format("/metacards/metacard[@id=\"%s\"]", id);
    ValidatableResponse response = executeOpenSearch("xml", "q=*").log().all();
    response.assertThat().body(hasXPath(metacardPath + "/string[@name=\"" + Core.RESOURCE_URI + "\"]/value", is(not(overrideResourceUri))));
    response.assertThat().body(hasXPath(metacardPath + "/string[@name=\"" + Core.TITLE + "\"]/value", is(overrideTitle)));
    deleteMetacard(id);
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) SkipUnstableTest(org.codice.ddf.itests.common.annotations.SkipUnstableTest) Test(org.junit.Test) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest)

Example 27 with ValidatableResponse

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

the class TestCatalogValidation method testNoEnforceValidityErrorsOrWarnings.

@Test
public void testNoEnforceValidityErrorsOrWarnings() throws Exception {
    //Configure to enforce validator
    configureEnforcedMetacardValidators(Collections.singletonList("sample-validator"), getAdminConfig());
    //Configure to enforce neither errors nor warnings
    configureEnforceValidityErrorsAndWarnings("false", "false", getAdminConfig());
    ingestXmlFromResourceAndWait(XML_RECORD_RESOURCE_PATH + "/sampleWarningMetacard.xml");
    ingestXmlFromResourceAndWait(XML_RECORD_RESOURCE_PATH + "/sampleCleanMetacard.xml");
    ingestXmlFromResourceAndWait(XML_RECORD_RESOURCE_PATH + "/sampleErrorMetacard.xml");
    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(containsString("warning metacard"));
    response.body(containsString("clean metacard"));
    response.body(containsString("error metacard"));
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) CswQueryBuilder(org.codice.ddf.itests.common.csw.CswQueryBuilder) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest) Test(org.junit.Test)

Example 28 with ValidatableResponse

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

the class TestCatalogValidation method testValidationEnforced.

@Test
public void testValidationEnforced() throws Exception {
    // Update metacardMarkerPlugin config with enforcedMetacardValidators
    configureEnforcedMetacardValidators(Collections.singletonList("sample-validator"), getAdminConfig());
    String id1 = ingestXmlFromResourceAndWait("/metacard1.xml");
    ingestXmlFromResourceWaitForFailure("/metacard2.xml");
    configureShowInvalidMetacards("false", "true", getAdminConfig());
    configureFilterInvalidMetacards("true", "false", getAdminConfig());
    // Search for all entries, implicit "validation-warnings is null" and "validation-errors is null"
    // should get added by ValidationQueryFactory
    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();
    // Assert Metacard1 is in results AND not Metacard2
    response.body(hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id1)));
    // Search for all entries that have no validation warnings or errors
    query = new CswQueryBuilder().addPropertyIsNullAttributeFilter(Validation.VALIDATION_WARNINGS).getQuery();
    response = given().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(query).post(CSW_PATH.getUrl()).then();
    // Assert Metacard1 is in results AND not Metacard2
    response.body(hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id1)));
    //Search for all entries that have validation-warnings from sample-validator or no validation warnings
    //Only search that will actually return all entries
    query = new CswQueryBuilder().addAttributeFilter(PROPERTY_IS_EQUAL_TO, Validation.VALIDATION_WARNINGS, "*").addPropertyIsNullAttributeFilter(Validation.VALIDATION_WARNINGS).addLogicalOperator(OR).getQuery();
    response = given().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(query).post(CSW_PATH.getUrl()).then();
    // Assert Metacard1 and NOT metacard2 is in results
    response.body(hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id1)));
    // Search for all metacards that have validation-warnings
    query = new CswQueryBuilder().addAttributeFilter(PROPERTY_IS_EQUAL_TO, Validation.VALIDATION_WARNINGS, "*").getQuery();
    response = given().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(query).post(CSW_PATH.getUrl()).then();
    // Assert Metacard1 and metacard2 are NOT in results
    response.body(not(hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id1))));
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) CswQueryBuilder(org.codice.ddf.itests.common.csw.CswQueryBuilder) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest) Test(org.junit.Test)

Example 29 with ValidatableResponse

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

the class TestCatalogValidation method testQueryByErrorFailedValidators.

@Test
public void testQueryByErrorFailedValidators() throws Exception {
    //Don't enforce the validator, so that it will be marked but ingested
    configureEnforcedMetacardValidators(Collections.singletonList(""), getAdminConfig());
    ingestXmlFromResourceAndWait(XML_RECORD_RESOURCE_PATH + "/sampleWarningMetacard.xml");
    ingestXmlFromResourceAndWait(XML_RECORD_RESOURCE_PATH + "/sampleCleanMetacard.xml");
    ingestXmlFromResourceAndWait(XML_RECORD_RESOURCE_PATH + "/sampleErrorMetacard.xml");
    String query = new CswQueryBuilder().addAttributeFilter(PROPERTY_IS_LIKE, Validation.FAILED_VALIDATORS_ERRORS, "sample-validator").getQuery();
    ValidatableResponse response = given().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(query).post(CSW_PATH.getUrl()).then();
    response.body(not(containsString("warning metacard")));
    response.body(not(containsString("clean metacard")));
    response.body(containsString("error metacard"));
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) CswQueryBuilder(org.codice.ddf.itests.common.csw.CswQueryBuilder) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest) Test(org.junit.Test)

Example 30 with ValidatableResponse

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

the class AbsoluteSearchResourceTest method searchForNonexistingKeyword.

@Test
@UsingDataSet(locations = "searchForExistingKeyword.json")
public void searchForNonexistingKeyword() {
    final ValidatableResponse result = doSearchFor("Nonexistent");
    final JsonPath response = result.statusCode(200).extract().jsonPath();
    assertThat(response.getInt("total_results")).isEqualTo(0);
    assertThat(response.getList("messages")).isEmpty();
    assertThat(response.getList("used_indices")).hasSize(1);
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) JsonPath(com.jayway.restassured.path.json.JsonPath) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

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