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