use of io.restassured.response.Response in project knox by apache.
the class GatewayBasicFuncTest method readFile.
private void readFile(String user, String password, String file, String contentType, String resource, int status) throws IOException {
driver.getMock("WEBHDFS").expect().method("GET").pathInfo("/v1" + file).queryParam("user.name", user).queryParam("op", "OPEN").respond().status(HttpStatus.SC_TEMPORARY_REDIRECT).header("Location", driver.getRealUrl("DATANODE") + file + "?op=OPEN&user.name=" + user);
if (status == HttpStatus.SC_OK) {
driver.getMock("DATANODE").expect().method("GET").pathInfo(file).queryParam("user.name", user).queryParam("op", "OPEN").respond().status(status).contentType(contentType).content(driver.getResourceBytes(resource));
} else {
driver.getMock("DATANODE").expect().method("GET").pathInfo(file).queryParam("user.name", user).queryParam("op", "OPEN").respond().status(status);
}
Response response = given().auth().preemptive().basic(user, password).header("X-XSRF-Header", "jksdhfkhdsf").queryParam("op", "OPEN").then().statusCode(status).when().get(driver.getUrl("WEBHDFS") + "/v1" + file + (driver.isUseGateway() ? "" : "?user.name=" + user));
if (response.getStatusCode() == HttpStatus.SC_OK) {
String actualContent = response.asString();
String thenedContent = driver.getResourceString(resource, Charset.forName("UTF-8"));
assertThat(actualContent, Matchers.is(thenedContent));
}
driver.assertComplete();
}
use of io.restassured.response.Response in project knox by apache.
the class GatewayBasicFuncTest method createDir.
private String createDir(String user, String password, String dir, String permsOctal, int status) {
driver.getMock("WEBHDFS").expect().method("PUT").pathInfo("/v1" + dir).queryParam("op", "MKDIRS").queryParam("user.name", user).queryParam("permission", permsOctal).respond().status(HttpStatus.SC_OK).contentType("application/json").content("{\"boolean\": true}".getBytes());
Response response = given().auth().preemptive().basic(user, password).header("X-XSRF-Header", "jksdhfkhdsf").queryParam("op", "MKDIRS").queryParam("permission", permsOctal).then().statusCode(status).contentType("application/json").body("boolean", CoreMatchers.equalTo(true)).when().put(driver.getUrl("WEBHDFS") + "/v1" + dir + (driver.isUseGateway() ? "" : "?user.name=" + user));
String location = response.getHeader("Location");
return location;
}
use of io.restassured.response.Response in project knox by apache.
the class GatewayBasicFuncTest method testStormUiApi.
@Test(timeout = TestUtils.MEDIUM_TIMEOUT)
public void testStormUiApi() throws Exception {
LOG_ENTER();
String resourceName = "storm/cluster-configuration.json";
String path = "/api/v1/cluster/configuration";
testGetStormResource(resourceName, path);
resourceName = "storm/cluster-summary.json";
path = "/api/v1/cluster/summary";
testGetStormResource(resourceName, path);
resourceName = "storm/supervisor-summary.json";
path = "/api/v1/supervisor/summary";
testGetStormResource(resourceName, path);
resourceName = "storm/topology-summary.json";
path = "/api/v1/topology/summary";
testGetStormResource(resourceName, path);
String username = "hdfs";
String password = "hdfs-password";
InetSocketAddress gatewayAddress = driver.gateway.getAddresses()[0];
String gatewayHostName = gatewayAddress.getHostName();
String gatewayAddrName = InetAddress.getByName(gatewayHostName).getHostAddress();
resourceName = "storm/topology-id.json";
path = "/api/v1/topology/WordCount-1-1424792039";
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);
String link = response.getBody().jsonPath().getString("spouts[0].errorWorkerLogLink");
MatcherAssert.assertThat(link, anyOf(startsWith("http://" + gatewayHostName + ":" + gatewayAddress.getPort() + "/"), startsWith("http://" + gatewayAddrName + ":" + gatewayAddress.getPort() + "/")));
MatcherAssert.assertThat(link, containsString("/storm/logviewer"));
driver.assertComplete();
resourceName = "storm/topology-component-id.json";
path = "/api/v1/topology/WordCount-1-1424792039/component/spout";
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 = 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);
link = response.getBody().jsonPath().getString("executorStats[0].workerLogLink");
MatcherAssert.assertThat(link, anyOf(startsWith("http://" + gatewayHostName + ":" + gatewayAddress.getPort() + "/"), startsWith("http://" + gatewayAddrName + ":" + gatewayAddress.getPort() + "/")));
MatcherAssert.assertThat(link, containsString("/storm/logviewer"));
driver.assertComplete();
path = "/api/v1/topology/WordCount-1-1424792039/activate";
testPostStormResource(path);
path = "/api/v1/topology/WordCount-1-1424792039/deactivate";
testPostStormResource(path);
path = "/api/v1/topology/WordCount-1-1424792039/rebalance/20";
testPostStormResource(path);
path = "/api/v1/topology/WordCount-1-1424792039/kill/20";
testPostStormResource(path);
LOG_EXIT();
}
use of io.restassured.response.Response in project knox by apache.
the class GatewayBasicFuncTest method testHBaseUseScanner.
@Test(timeout = TestUtils.MEDIUM_TIMEOUT)
public void testHBaseUseScanner() throws IOException {
LOG_ENTER();
String username = "hbase";
String password = "hbase-password";
String scannerDefinitionResourceName = "hbase/scanner-definition";
String tableDataResourceName = "hbase/table-data";
String scannerPath = "/table/scanner";
String scannerId = "13705290446328cff5ed";
// Create scanner for table using PUT and POST requests
driver.getMock("WEBHBASE").expect().method("PUT").pathInfo(scannerPath).respond().status(HttpStatus.SC_CREATED);
given().auth().preemptive().basic(username, password).header("X-XSRF-Header", "jksdhfkhdsf").header("Content-Type", ContentType.XML.toString()).body(driver.getResourceBytes(scannerDefinitionResourceName + ".xml")).then().statusCode(HttpStatus.SC_CREATED).when().put(driver.getUrl("WEBHBASE") + scannerPath);
driver.assertComplete();
// Get the values of the next cells found by the scanner
driver.getMock("WEBHBASE").expect().method("GET").pathInfo(scannerPath + "/" + scannerId).header("Accept", ContentType.XML.toString()).respond().status(HttpStatus.SC_OK).content(driver.getResourceBytes(tableDataResourceName + ".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") + scannerPath + "/" + scannerId);
MatcherAssert.assertThat(the(response.getBody().asString()), isEquivalentTo(the(driver.getResourceString(tableDataResourceName + ".xml", UTF8))));
driver.assertComplete();
// Delete scanner
driver.getMock("WEBHBASE").expect().from("testHBaseUseScanner").method("DELETE").pathInfo(scannerPath + "/" + scannerId).respond().status(HttpStatus.SC_OK);
given().auth().preemptive().basic(username, password).header("X-XSRF-Header", "jksdhfkhdsf").then().statusCode(HttpStatus.SC_OK).when().delete(driver.getUrl("WEBHBASE") + scannerPath + "/" + scannerId);
driver.assertComplete();
LOG_EXIT();
}
use of io.restassured.response.Response in project knox by apache.
the class GatewayBasicFuncTest method testYarnApplicationLifecycle.
@Test(timeout = TestUtils.MEDIUM_TIMEOUT)
public void testYarnApplicationLifecycle() throws Exception {
LOG_ENTER();
String username = "hdfs";
String password = "hdfs-password";
String path = "/v1/cluster/apps/new-application";
String resource = "yarn/new-application.json";
driver.getMock("RESOURCEMANAGER").expect().method("POST").respond().status(HttpStatus.SC_OK).content(driver.getResourceBytes(resource)).contentType("application/json");
Response response = given().auth().preemptive().basic(username, password).header("X-XSRF-Header", "jksdhfkhdsf").then().statusCode(HttpStatus.SC_OK).contentType("application/json").when().post(driver.getUrl("RESOURCEMANAGER") + path + (driver.isUseGateway() ? "" : "?user.name=" + username));
assertThat(response.getBody().asString(), Matchers.containsString("application-id"));
path = "/v1/cluster/apps";
resource = "yarn/application-submit-request.json";
driver.getMock("RESOURCEMANAGER").expect().method("POST").content(driver.getResourceBytes(resource)).contentType("application/json").respond().status(HttpStatus.SC_OK).contentType("application/json");
given().auth().preemptive().basic(username, password).header("X-XSRF-Header", "jksdhfkhdsf").body(driver.getResourceBytes(resource)).contentType("application/json").then().statusCode(HttpStatus.SC_OK).contentType("application/json").when().post(driver.getUrl("RESOURCEMANAGER") + path + (driver.isUseGateway() ? "" : "?user.name=" + username));
driver.assertComplete();
path = "/v1/cluster/apps/application_1405356982244_0031/state";
resource = "yarn/application-killing.json";
driver.getMock("RESOURCEMANAGER").expect().method("PUT").content(driver.getResourceBytes(resource)).contentType("application/json").respond().status(HttpStatus.SC_OK).content(driver.getResourceBytes(resource)).contentType("application/json");
response = given().auth().preemptive().basic(username, password).header("X-XSRF-Header", "jksdhfkhdsf").body(driver.getResourceBytes(resource)).contentType("application/json").then().statusCode(HttpStatus.SC_OK).contentType("application/json").when().put(driver.getUrl("RESOURCEMANAGER") + path + (driver.isUseGateway() ? "" : "?user.name=" + username));
assertThat(response.getBody().asString(), Matchers.is("{\"state\":\"KILLING\"}"));
LOG_EXIT();
}
Aggregations