Search in sources :

Example 46 with ValidatableResponse

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

the class TestCatalogValidation method testValidationFiltering.

@Test
public void testValidationFiltering() throws Exception {
    // Update metacardMarkerPlugin config with no enforcedMetacardValidators
    configureEnforcedMetacardValidators(Arrays.asList(""), getAdminConfig());
    // Configure the PDP
    PdpProperties pdpProperties = new PdpProperties();
    pdpProperties.put("matchOneMappings", Arrays.asList("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role=invalid-state"));
    Configuration config = configAdmin.getConfiguration("ddf.security.pdp.realm.AuthzRealm", null);
    Dictionary<String, ?> configProps = new Hashtable<>(pdpProperties);
    config.update(configProps);
    String id1 = ingestXmlFromResourceAndWait("/metacard1.xml");
    String id2 = ingestXmlFromResourceAndWait("/metacard2.xml");
    // Configure invalid filtering
    configureMetacardValidityFilterPlugin(Arrays.asList("invalid-state=system-admin"), getAdminConfig());
    configureShowInvalidMetacards("false", "true", getAdminConfig());
    configureFilterInvalidMetacards("true", "false", getAdminConfig());
    try {
        String query = new CswQueryBuilder().addAttributeFilter(PROPERTY_IS_LIKE, Validation.VALIDATION_WARNINGS, "*").addPropertyIsNullAttributeFilter(Validation.VALIDATION_WARNINGS).addLogicalOperator(OR).getQuery();
        ValidatableResponse response = given().auth().preemptive().basic("admin", "admin").header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(query).post(CSW_PATH.getUrl()).then();
        // Assert Metacard2 is in results AND Metacard1
        response.body(hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id1)));
        response.body(hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id2)));
        response = given().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(query).post(CSW_PATH.getUrl()).then();
        // Assert Metacard2 is in results Metacard1
        response.body(hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id1)));
        response.body(not(hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id2))));
        // Configure invalid filtering
        configureMetacardValidityFilterPlugin(Arrays.asList("invalid-state=system-admin,guest"), getAdminConfig());
        response = given().auth().preemptive().basic("admin", "admin").header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(query).post(CSW_PATH.getUrl()).then();
        // Assert Metacard2 is in results AND Metacard1
        response.body(hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id1)));
        response.body(hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id2)));
        response = given().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(query).post(CSW_PATH.getUrl()).then();
        // Assert Metacard2 is in results Metacard1
        response.body(hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id1)));
        response.body(hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id2)));
    } finally {
        config = configAdmin.getConfiguration("ddf.security.pdp.realm.AuthzRealm", null);
        configProps = new Hashtable<>(new PdpProperties());
        config.update(configProps);
    }
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) Configuration(org.osgi.service.cm.Configuration) CswQueryBuilder(org.codice.ddf.itests.common.csw.CswQueryBuilder) Hashtable(java.util.Hashtable) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest) Test(org.junit.Test)

Example 47 with ValidatableResponse

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

the class TestCatalogValidation method testValidationUnenforced.

@Test
public void testValidationUnenforced() throws Exception {
    getServiceManager().stopFeature(true, "catalog-security-filter");
    configureEnforcedMetacardValidators(Collections.singletonList(""), getAdminConfig());
    String id1 = ingestXmlFromResourceAndWait("/metacard1.xml");
    String id2 = ingestXmlFromResourceAndWait("/metacard2.xml");
    configureShowInvalidMetacards("false", "true", getAdminConfig());
    configureFilterInvalidMetacards("true", "false", getAdminConfig());
    try {
        // metacardMarkerPlugin has no enforcedMetacardValidators
        // 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)));
        response.body(not(hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id2))));
        // Search for all entries that have no validation warnings
        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 or no validation warnings
        //Only search that will actually return all entries
        query = new CswQueryBuilder().addAttributeFilter(PROPERTY_IS_LIKE, Validation.VALIDATION_WARNINGS, "sampleWarnings").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 Metacard2 are in results
        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 are invalid
        query = new CswQueryBuilder().addAttributeFilter(PROPERTY_IS_LIKE, Validation.VALIDATION_WARNINGS, "*").getQuery();
        response = given().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(query).post(CSW_PATH.getUrl()).then();
        // Assert Metacard2 is in results AND not Metacard1
        response.body(hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id2)));
        response.body(not(hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id1))));
        query = new CswQueryBuilder().addPropertyIsNullAttributeFilter(Validation.VALIDATION_WARNINGS).addLogicalOperator(NOT).getQuery();
        response = given().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(query).post(CSW_PATH.getUrl()).then();
        // Assert Metacard2 is in results AND not Metacard1
        response.body(hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id2)));
        response.body(not(hasXPath(format("/GetRecordsResponse/SearchResults/Record[identifier=\"%s\"]", id1))));
    } finally {
        getServiceManager().startFeature(true, "catalog-security-filter");
    }
}
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 48 with ValidatableResponse

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

the class TestCatalogValidation method testEnforceValidityErrorsAndWarnings.

@Test
public void testEnforceValidityErrorsAndWarnings() throws Exception {
    //Configure to enforce validator
    configureEnforcedMetacardValidators(Collections.singletonList("sample-validator"), getAdminConfig());
    //Configure to enforce errors and warnings
    configureEnforceValidityErrorsAndWarnings("true", "true", getAdminConfig());
    ingestXmlFromResourceWaitForFailure(XML_RECORD_RESOURCE_PATH + "/sampleWarningMetacard.xml");
    ingestXmlFromResourceAndWait(XML_RECORD_RESOURCE_PATH + "/sampleCleanMetacard.xml");
    ingestXmlFromResourceWaitForFailure(XML_RECORD_RESOURCE_PATH + "/sampleErrorMetacard.xml");
    configureFilterInvalidMetacards("true", "false", 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 ones
        response.body(not(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 49 with ValidatableResponse

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

the class TestCatalog method testCswDeleteMultiple.

@Test
public void testCswDeleteMultiple() {
    ingestCswRecord();
    ingestCswRecord();
    ValidatableResponse response = given().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(getFileContent(CSW_REQUEST_RESOURCE_PATH + "/CswFilterDeleteRequest")).post(CSW_PATH.getUrl()).then();
    response.body(hasXPath("//TransactionResponse/TransactionSummary/totalDeleted", is("2")), hasXPath("//TransactionResponse/TransactionSummary/totalInserted", is("0")), hasXPath("//TransactionResponse/TransactionSummary/totalUpdated", is("0")));
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) SkipUnstableTest(org.codice.ddf.itests.common.annotations.SkipUnstableTest) Test(org.junit.Test) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest)

Example 50 with ValidatableResponse

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

the class TestCatalog method testCswDeleteOneWithCQL.

@Test
public void testCswDeleteOneWithCQL() {
    ingestCswRecord();
    ValidatableResponse response = given().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(getFileContent(CSW_REQUEST_RESOURCE_PATH + "/CswCqlDeleteRequest", ImmutableMap.of("title", "Aliquam fermentum purus quis arcu"))).post(CSW_PATH.getUrl()).then();
    response.body(hasXPath("//TransactionResponse/TransactionSummary/totalDeleted", is("1")), hasXPath("//TransactionResponse/TransactionSummary/totalInserted", is("0")), hasXPath("//TransactionResponse/TransactionSummary/totalUpdated", is("0")));
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) 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