Search in sources :

Example 41 with ValidatableResponse

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

the class TestCatalogValidation method testFilterPluginWarningsAndErrors.

@Test
public void testFilterPluginWarningsAndErrors() throws Exception {
    //Configure not enforcing validators so invalid metacards can ingest
    configureEnforcedMetacardValidators(Collections.singletonList(""), getAdminConfig());
    ingestXmlFromResourceAndWait(XML_RECORD_RESOURCE_PATH + "/sampleErrorMetacard.xml");
    ingestXmlFromResourceAndWait(XML_RECORD_RESOURCE_PATH + "/sampleCleanMetacard.xml");
    ingestXmlFromResourceAndWait(XML_RECORD_RESOURCE_PATH + "/sampleWarningMetacard.xml");
    // Configure invalid filtering
    configureMetacardValidityFilterPlugin(Arrays.asList("invalid-state=system-admin"), getAdminConfig());
    //configure to filter both metacards with validation errors and validation warnings
    configureFilterInvalidMetacards("true", "true", getAdminConfig());
    testWithRetry(() -> {
        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();
        //clean metacard should be in results but not invalid one
        response.body(not(containsString("error metacard")));
        response.body(not(containsString("warning metacard")));
        response.body(containsString("clean 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 42 with ValidatableResponse

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

the class TestCatalogValidation method testValidationChecker.

@Test
public void testValidationChecker() throws Exception {
    configureEnforcedMetacardValidators(Arrays.asList(""), getAdminConfig());
    String id1 = ingestXmlFromResourceAndWait("/metacard1.xml");
    String id2 = ingestXmlFromResourceAndWait("/metacard2.xml");
    configureShowInvalidMetacards("true", "true", 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 Metacard2 because showInvalidMetacards is true
    response.body(hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id1)));
    response.body((hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id2))));
    // 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)));
    response.body(not(hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id2))));
    //Search for all entries that have validation-warnings from sample-validator or no validation warnings
    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)));
    response.body(not(hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id2))));
    // 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))));
    response.body(not(hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id2))));
}
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 43 with ValidatableResponse

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

the class TestCatalogValidation method testFilterPluginWarningsOnly.

@Test
public void testFilterPluginWarningsOnly() throws Exception {
    //Configure not enforcing validators so invalid metacards can ingest
    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");
    // Configure invalid filtering
    configureMetacardValidityFilterPlugin(Arrays.asList("invalid-state=system-admin"), getAdminConfig());
    //Configure to filter metacards with validation warnings but not validation errors
    configureFilterInvalidMetacards("false", "true", getAdminConfig());
    testWithRetry(() -> {
        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();
        //clean metacard should be in results but not invalid one
        response.body(not(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 44 with ValidatableResponse

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

the class TestCatalogValidation method testEnforceValidityErrorsOnly.

@Test
public void testEnforceValidityErrorsOnly() throws Exception {
    //Configure to enforce validator
    configureEnforcedMetacardValidators(Collections.singletonList("sample-validator"), getAdminConfig());
    //Configure to enforce errors but not warnings
    configureEnforceValidityErrorsAndWarnings("true", "false", getAdminConfig());
    ingestXmlFromResourceAndWait(XML_RECORD_RESOURCE_PATH + "/sampleWarningMetacard.xml");
    ingestXmlFromResourceAndWait(XML_RECORD_RESOURCE_PATH + "/sampleCleanMetacard.xml");
    ingestXmlFromResourceWaitForFailure(XML_RECORD_RESOURCE_PATH + "/sampleErrorMetacard.xml");
    configureFilterInvalidMetacards("true", "false", getAdminConfig());
    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();
    //clean metacard and warning metacard should be in results but not error one
    response.body(containsString("warning metacard"));
    response.body(containsString("clean metacard"));
    response.body(not(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 45 with ValidatableResponse

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

the class TestCatalogValidation method testEnforceValidityWarningsOnly.

@Test
public void testEnforceValidityWarningsOnly() throws Exception {
    //Configure to enforce validator
    configureEnforcedMetacardValidators(Collections.singletonList("sample-validator"), getAdminConfig());
    //Configure to enforce warnings but not errors
    configureEnforceValidityErrorsAndWarnings("false", "true", getAdminConfig());
    ingestXmlFromResourceWaitForFailure(XML_RECORD_RESOURCE_PATH + "/sampleWarningMetacard.xml");
    ingestXmlFromResourceAndWait(XML_RECORD_RESOURCE_PATH + "/sampleCleanMetacard.xml");
    ingestXmlFromResourceAndWait(XML_RECORD_RESOURCE_PATH + "/sampleErrorMetacard.xml");
    configureFilterInvalidMetacards("true", "false", getAdminConfig());
    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();
    //clean metacard and error metacard should be in results but not warning one
    response.body(not(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)

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