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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations