Search in sources :

Example 11 with Response

use of io.restassured.response.Response in project knox by apache.

the class GatewayBasicFuncTest method testHBaseGetTableSchema.

@Test(timeout = TestUtils.MEDIUM_TIMEOUT)
public void testHBaseGetTableSchema() throws IOException {
    LOG_ENTER();
    String username = "hbase";
    String password = "hbase-password";
    String resourceName = "hbase/table-metadata";
    String path = "/table/schema";
    driver.getMock("WEBHBASE").expect().method("GET").pathInfo(path).header("Accept", ContentType.XML.toString()).respond().status(HttpStatus.SC_OK).content(driver.getResourceBytes(resourceName + ".xml")).contentType(ContentType.XML.toString());
    Response response = given().auth().preemptive().basic(username, password).header("X-XSRF-Header", "jksdhfkhdsf").header("Accept", ContentType.XML.toString()).then().statusCode(HttpStatus.SC_OK).contentType(ContentType.XML).when().get(driver.getUrl("WEBHBASE") + path);
    MatcherAssert.assertThat(the(response.getBody().asString()), isEquivalentTo(the(driver.getResourceString(resourceName + ".xml", UTF8))));
    driver.assertComplete();
    driver.getMock("WEBHBASE").expect().method("GET").pathInfo(path).header("Accept", ContentType.JSON.toString()).respond().status(HttpStatus.SC_OK).content(driver.getResourceBytes(resourceName + ".json")).contentType(ContentType.JSON.toString());
    response = given().auth().preemptive().basic(username, password).header("X-XSRF-Header", "jksdhfkhdsf").header("Accept", ContentType.JSON.toString()).then().statusCode(HttpStatus.SC_OK).contentType(ContentType.JSON).when().get(driver.getUrl("WEBHBASE") + path);
    MatcherAssert.assertThat(response.getBody().asString(), sameJSONAs(driver.getResourceString(resourceName + ".json", UTF8)));
    driver.assertComplete();
    driver.getMock("WEBHBASE").expect().method("GET").pathInfo(path).header("Accept", "application/x-protobuf").respond().status(HttpStatus.SC_OK).content(driver.getResourceBytes(resourceName + ".protobuf")).contentType("application/x-protobuf");
    response = given().auth().preemptive().basic(username, password).header("X-XSRF-Header", "jksdhfkhdsf").header("Accept", "application/x-protobuf").then().statusCode(HttpStatus.SC_OK).contentType("application/x-protobuf").when().get(driver.getUrl("WEBHBASE") + path);
    // RestAssured seems to be screwing up the binary comparison so do it explicitly.
    assertThat(driver.getResourceBytes(resourceName + ".protobuf"), is(response.body().asByteArray()));
    driver.assertComplete();
    LOG_EXIT();
}
Also used : Response(io.restassured.response.Response) HttpResponse(org.apache.http.HttpResponse) IsEmptyString.isEmptyString(org.hamcrest.text.IsEmptyString.isEmptyString) Matchers.containsString(org.hamcrest.Matchers.containsString) VerifyTest(org.apache.knox.test.category.VerifyTest) Test(org.junit.Test)

Example 12 with Response

use of io.restassured.response.Response in project knox by apache.

the class GatewayBasicFuncTest method updateFileNN.

private String updateFileNN(String user, String password, String file, String resource, int status) throws IOException {
    if (status == HttpStatus.SC_TEMPORARY_REDIRECT) {
        driver.getMock("WEBHDFS").expect().method("PUT").pathInfo("/v1" + file).queryParam("op", "CREATE").queryParam("user.name", user).queryParam("overwrite", "true").respond().status(status).header("Location", driver.getRealUrl("DATANODE") + file + "?op=CREATE&user.name=" + user);
    } else {
        driver.getMock("WEBHDFS").expect().method("PUT").pathInfo("v1" + file).queryParam("user.name", user).queryParam("op", "CREATE").respond().status(status);
    }
    Response response = given().auth().preemptive().basic(user, password).header("X-XSRF-Header", "jksdhfkhdsf").queryParam("op", "CREATE").queryParam("overwrite", "true").body(driver.getResourceBytes(resource)).then().statusCode(status).when().put(driver.getUrl("WEBHDFS") + "/v1" + file + (driver.isUseGateway() ? "" : "?user.name=" + user));
    String location = response.getHeader("Location");
    log.trace("Redirect location: " + response.getHeader("Location"));
    return location;
}
Also used : Response(io.restassured.response.Response) HttpResponse(org.apache.http.HttpResponse) IsEmptyString.isEmptyString(org.hamcrest.text.IsEmptyString.isEmptyString) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 13 with Response

use of io.restassured.response.Response in project knox by apache.

the class GatewayBasicFuncTest method createFileNN.

private String createFileNN(String user, String password, String file, String permsOctal, int status) throws IOException {
    if (status == HttpStatus.SC_TEMPORARY_REDIRECT) {
        driver.getMock("WEBHDFS").expect().method("PUT").pathInfo("/v1" + file).queryParam("user.name", user).queryParam("op", "CREATE").respond().status(status).header("Location", driver.getRealUrl("DATANODE") + file + "?op=CREATE&user.name=" + user);
    } else {
        driver.getMock("WEBHDFS").expect().method("PUT").pathInfo("/v1" + file).queryParam("user.name", user).queryParam("op", "CREATE").respond().status(status);
    }
    Response response = given().auth().preemptive().basic(user, password).header("X-XSRF-Header", "jksdhfkhdsf").queryParam("op", "CREATE").queryParam("permission", permsOctal).then().statusCode(status).when().put(driver.getUrl("WEBHDFS") + "/v1" + file + (driver.isUseGateway() ? "" : "?user.name=" + user));
    String location = response.getHeader("Location");
    log.trace("Redirect location: " + response.getHeader("Location"));
    return location;
}
Also used : Response(io.restassured.response.Response) HttpResponse(org.apache.http.HttpResponse) IsEmptyString.isEmptyString(org.hamcrest.text.IsEmptyString.isEmptyString) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 14 with Response

use of io.restassured.response.Response in project knox by apache.

the class GatewayBasicFuncTest method getYarnRmResource.

private void getYarnRmResource(String path, ContentType contentType, String resource) throws Exception {
    String username = "hdfs";
    String password = "hdfs-password";
    switch(contentType) {
        case JSON:
            resource += ".json";
            break;
        case XML:
            resource += ".xml";
            break;
        default:
            break;
    }
    driver.getMock("RESOURCEMANAGER").expect().method("GET").pathInfo(path).queryParam("user.name", username).respond().status(HttpStatus.SC_OK).content(driver.getResourceBytes(resource)).contentType(contentType.toString());
    Response response = given().auth().preemptive().basic(username, password).header("X-XSRF-Header", "jksdhfkhdsf").then().statusCode(HttpStatus.SC_OK).contentType(contentType).when().get(driver.getUrl("RESOURCEMANAGER") + path + (driver.isUseGateway() ? "" : "?user.name=" + username));
    switch(contentType) {
        case JSON:
            MatcherAssert.assertThat(response.getBody().asString(), sameJSONAs(driver.getResourceString(resource, UTF8)));
            break;
        case XML:
            MatcherAssert.assertThat(the(response.getBody().asString()), isEquivalentTo(the(driver.getResourceString(resource, UTF8))));
            break;
        default:
            break;
    }
    driver.assertComplete();
}
Also used : Response(io.restassured.response.Response) HttpResponse(org.apache.http.HttpResponse) IsEmptyString.isEmptyString(org.hamcrest.text.IsEmptyString.isEmptyString) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 15 with Response

use of io.restassured.response.Response in project knox by apache.

the class GatewayBasicFuncTest method testSolrRESTAPI.

@Test(timeout = TestUtils.MEDIUM_TIMEOUT)
public void testSolrRESTAPI() throws Exception {
    LOG_ENTER();
    String resourceName = "solr/query_response.xml";
    String username = "hdfs";
    String password = "hdfs-password";
    String gatewayPath = driver.getUrl("SOLR") + "/gettingstarted/select?q=author_s:William+Shakespeare";
    driver.getMock("SOLR").expect().method("GET").pathInfo("/gettingstarted/select").queryParam("q", "author_s:William+Shakespeare").respond().status(HttpStatus.SC_OK).content(driver.getResourceBytes(resourceName)).contentType(ContentType.XML.toString());
    Response response = given().auth().preemptive().basic(username, password).header("X-XSRF-Header", "jksdhfkhdsf").header("Accept", ContentType.XML.toString()).then().statusCode(HttpStatus.SC_OK).contentType(ContentType.XML.toString()).when().get(gatewayPath);
    assertTrue(response.getBody().asString().contains("The Merchant of Venice"));
    driver.assertComplete();
    LOG_EXIT();
}
Also used : Response(io.restassured.response.Response) HttpResponse(org.apache.http.HttpResponse) IsEmptyString.isEmptyString(org.hamcrest.text.IsEmptyString.isEmptyString) Matchers.containsString(org.hamcrest.Matchers.containsString) VerifyTest(org.apache.knox.test.category.VerifyTest) Test(org.junit.Test)

Aggregations

Response (io.restassured.response.Response)262 Test (org.junit.Test)209 Matchers.containsString (org.hamcrest.Matchers.containsString)44 ValidatableResponse (io.restassured.response.ValidatableResponse)32 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)31 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)29 RestAssuredClient (guru.nidi.ramltester.restassured3.RestAssuredClient)25 HttpResponse (org.apache.http.HttpResponse)25 IsEmptyString.isEmptyString (org.hamcrest.text.IsEmptyString.isEmptyString)25 FilterContext (io.restassured.filter.FilterContext)17 FilterableRequestSpecification (io.restassured.specification.FilterableRequestSpecification)17 FilterableResponseSpecification (io.restassured.specification.FilterableResponseSpecification)17 CswTestCommons.getMetacardIdFromCswInsertResponse (org.codice.ddf.itests.common.csw.CswTestCommons.getMetacardIdFromCswInsertResponse)17 Filter (io.restassured.filter.Filter)16 VerifyTest (org.apache.knox.test.category.VerifyTest)15 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)14 Book (org.baeldung.persistence.model.Book)13 JSONObject (org.json.simple.JSONObject)13 ResponseBuilder (io.restassured.builder.ResponseBuilder)11 IOException (java.io.IOException)11