Search in sources :

Example 1 with Response

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

the class GatewayBasicFuncTest method testHBaseQueryTableData.

@Test(timeout = TestUtils.MEDIUM_TIMEOUT)
public void testHBaseQueryTableData() throws IOException {
    LOG_ENTER();
    String username = "hbase";
    String password = "hbase-password";
    String resourceName = "hbase/table-data";
    String allRowsPath = "/table/*";
    String rowsStartsWithPath = "/table/row*";
    String rowsWithKeyPath = "/table/row";
    String rowsWithKeyAndColumnPath = "/table/row/family:col";
    driver.getMock("WEBHBASE").expect().method("GET").pathInfo(allRowsPath).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") + allRowsPath);
    MatcherAssert.assertThat(the(response.getBody().asString()), isEquivalentTo(the(driver.getResourceString(resourceName + ".xml", UTF8))));
    driver.assertComplete();
    driver.getMock("WEBHBASE").expect().method("GET").pathInfo(rowsStartsWithPath).header("Accept", ContentType.XML.toString()).respond().status(HttpStatus.SC_OK).content(driver.getResourceBytes(resourceName + ".xml")).contentType(ContentType.XML.toString());
    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") + rowsStartsWithPath);
    MatcherAssert.assertThat(the(response.getBody().asString()), isEquivalentTo(the(driver.getResourceString(resourceName + ".xml", UTF8))));
    driver.assertComplete();
    driver.getMock("WEBHBASE").expect().method("GET").pathInfo(rowsWithKeyPath).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") + rowsWithKeyPath);
    MatcherAssert.assertThat(response.getBody().asString(), sameJSONAs(driver.getResourceString(resourceName + ".json", UTF8)));
    driver.assertComplete();
    driver.getMock("WEBHBASE").expect().method("GET").pathInfo(rowsWithKeyAndColumnPath).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") + rowsWithKeyAndColumnPath);
    MatcherAssert.assertThat(response.getBody().asString(), sameJSONAs(driver.getResourceString(resourceName + ".json", UTF8)));
    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 2 with Response

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

the class GatewayBasicFuncTest method testGetStormResource.

private void testGetStormResource(String resourceName, String path) throws IOException {
    String username = "hdfs";
    String password = "hdfs-password";
    String gatewayPath = driver.getUrl("STORM") + path;
    driver.getMock("STORM").expect().method("GET").pathInfo(path).queryParam("user.name", username).respond().status(HttpStatus.SC_OK).content(driver.getResourceBytes(resourceName)).contentType(ContentType.JSON.toString());
    Response 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.toString()).when().get(gatewayPath);
    MatcherAssert.assertThat(response.getBody().asString(), sameJSONAs(driver.getResourceString(resourceName, UTF8)));
    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 3 with Response

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

the class GatewayBasicFuncTest method testBasicOutboundHeaderUseCase.

@Test(timeout = TestUtils.MEDIUM_TIMEOUT)
public void testBasicOutboundHeaderUseCase() throws IOException {
    LOG_ENTER();
    String root = "/tmp/GatewayBasicFuncTest/testBasicOutboundHeaderUseCase";
    String username = "hdfs";
    String password = "hdfs-password";
    InetSocketAddress gatewayAddress = driver.gateway.getAddresses()[0];
    String gatewayHostName = gatewayAddress.getHostName();
    String gatewayAddrName = InetAddress.getByName(gatewayHostName).getHostAddress();
    driver.getMock("WEBHDFS").expect().method("PUT").pathInfo("/v1" + root + "/dir/file").header("Host", driver.getRealAddr("WEBHDFS")).queryParam("op", "CREATE").queryParam("user.name", username).respond().status(HttpStatus.SC_TEMPORARY_REDIRECT).header("Location", driver.getRealUrl("DATANODE") + "/v1" + root + "/dir/file?op=CREATE&user.name=hdfs");
    Response response = given().auth().preemptive().basic(username, password).header("X-XSRF-Header", "jksdhfkhdsf").queryParam("op", "CREATE").then().statusCode(HttpStatus.SC_TEMPORARY_REDIRECT).when().put(driver.getUrl("WEBHDFS") + "/v1" + root + "/dir/file");
    String location = response.getHeader("Location");
    // System.out.println( location );
    log.debug("Redirect location: " + response.getHeader("Location"));
    if (driver.isUseGateway()) {
        MatcherAssert.assertThat(location, anyOf(startsWith("http://" + gatewayHostName + ":" + gatewayAddress.getPort() + "/"), startsWith("http://" + gatewayAddrName + ":" + gatewayAddress.getPort() + "/")));
        MatcherAssert.assertThat(location, containsString("?_="));
    }
    MatcherAssert.assertThat(location, not(containsString("host=")));
    MatcherAssert.assertThat(location, not(containsString("port=")));
    LOG_EXIT();
}
Also used : Response(io.restassured.response.Response) HttpResponse(org.apache.http.HttpResponse) InetSocketAddress(java.net.InetSocketAddress) 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 4 with Response

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

the class GatewayBasicFuncTest method testBasicOutboundEncodedHeaderUseCase.

@Test(timeout = TestUtils.MEDIUM_TIMEOUT)
public void testBasicOutboundEncodedHeaderUseCase() throws IOException {
    LOG_ENTER();
    String root = "/tmp/GatewayBasicFuncTest/testBasicOutboundHeaderUseCase";
    String username = "hdfs";
    String password = "hdfs-password";
    driver.getMock("WEBHDFS").expect().method("PUT").pathInfo("/v1" + root + "/dir/fileレポー").header("Host", driver.getRealAddr("WEBHDFS")).queryParam("op", "CREATE").queryParam("user.name", username).respond().status(HttpStatus.SC_TEMPORARY_REDIRECT).header("Location", driver.getRealUrl("DATANODE") + "/v1" + root + "/dir/file%E3%83%AC%E3%83%9D%E3%83%BC?op=CREATE&user.name=hdfs");
    Response response = given().auth().preemptive().basic(username, password).header("X-XSRF-Header", "jksdhfkhdsf").queryParam("op", "CREATE").then().statusCode(HttpStatus.SC_TEMPORARY_REDIRECT).when().put(driver.getUrl("WEBHDFS") + "/v1" + root + "/dir/fileレポー");
    // .when().put( driver.getUrl("WEBHDFS") + "/v1" + root + "/dir/file%E3%83%AC%E3%83%9D%E3%83%BC" );
    String location = response.getHeader("Location");
    // System.out.println( location );
    log.debug("Redirect location: " + response.getHeader("Location"));
    if (driver.isUseGateway()) {
        MatcherAssert.assertThat(location, containsString("/dir/file%E3%83%AC%E3%83%9D%E3%83%BC"));
    }
    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 5 with Response

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

the class GatewayBasicFuncTest method testGetFalconResource.

private void testGetFalconResource(String resourceName, String path, ContentType contentType) throws IOException {
    String username = "hdfs";
    String password = "hdfs-password";
    String gatewayPath = driver.getUrl("FALCON") + path;
    switch(contentType) {
        case JSON:
            resourceName += ".json";
            break;
        case XML:
            resourceName += ".xml";
            break;
        default:
            break;
    }
    driver.getMock("FALCON").expect().method("GET").pathInfo(path).queryParam("user.name", username).header("Accept", contentType.toString()).respond().status(HttpStatus.SC_OK).content(driver.getResourceBytes(resourceName)).contentType(contentType.toString());
    Response response = given().auth().preemptive().basic(username, password).header("X-XSRF-Header", "jksdhfkhdsf").header("Accept", contentType.toString()).then().statusCode(HttpStatus.SC_OK).contentType(contentType).when().get(gatewayPath);
    switch(contentType) {
        case JSON:
            MatcherAssert.assertThat(response.getBody().asString(), sameJSONAs(driver.getResourceString(resourceName, UTF8)));
            break;
        case XML:
            MatcherAssert.assertThat(the(response.getBody().asString()), isEquivalentTo(the(driver.getResourceString(resourceName, 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)

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