Search in sources :

Example 1 with CswQueryBuilder

use of org.codice.ddf.itests.common.csw.CswQueryBuilder 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 2 with CswQueryBuilder

use of org.codice.ddf.itests.common.csw.CswQueryBuilder 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 3 with CswQueryBuilder

use of org.codice.ddf.itests.common.csw.CswQueryBuilder 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 4 with CswQueryBuilder

use of org.codice.ddf.itests.common.csw.CswQueryBuilder 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 5 with CswQueryBuilder

use of org.codice.ddf.itests.common.csw.CswQueryBuilder in project ddf by codice.

the class TestFederation method testCswQueryWithValidationCheckerPlugin.

@Test
public void testCswQueryWithValidationCheckerPlugin() throws Exception {
    // Construct a query to search for all metacards
    String query = new CswQueryBuilder().addAttributeFilter(CswQueryBuilder.PROPERTY_IS_LIKE, "AnyText", "*").getQuery();
    // Declare array of matchers so we can be sure we use the same matchers in each assertion
    Matcher[] assertion = new Matcher[] { hasXPath("/GetRecordsResponse/SearchResults/Record/identifier[text()='" + metacardIds[GEOJSON_RECORD_INDEX] + "']"), hasXPath("/GetRecordsResponse/SearchResults/Record/identifier[text()='" + metacardIds[XML_RECORD_INDEX] + "']"), hasXPath("/GetRecordsResponse/SearchResults/@numberOfRecordsReturned", is("2")), hasXPath("/GetRecordsResponse/SearchResults/Record/relation", containsString("/services/catalog/sources/")) };
    // Run a normal federated query to the CSW source and assert response
    given().contentType(ContentType.XML).body(query).when().post(CSW_PATH.getUrl()).then().assertThat().body(assertion[0], assertion);
    // Assert that response is the same as without the plugin
    given().contentType(ContentType.XML).body(query).when().post(CSW_PATH.getUrl()).then().assertThat().body(assertion[0], assertion);
}
Also used : CswQueryBuilder(org.codice.ddf.itests.common.csw.CswQueryBuilder) Matcher(org.hamcrest.Matcher) Matchers.containsString(org.hamcrest.Matchers.containsString) SkipUnstableTest(org.codice.ddf.itests.common.annotations.SkipUnstableTest) Test(org.junit.Test) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest)

Aggregations

CswQueryBuilder (org.codice.ddf.itests.common.csw.CswQueryBuilder)17 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)16 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)15 Test (org.junit.Test)15 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)14 Hashtable (java.util.Hashtable)1 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)1 Matcher (org.hamcrest.Matcher)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Configuration (org.osgi.service.cm.Configuration)1