use of io.restassured.response.ValidatableResponse in project ranger by apache.
the class KnoxRangerTest method makeWebHDFSInvocation.
private void makeWebHDFSInvocation(int statusCode, String user, String password) throws IOException {
String basedir = System.getProperty("basedir");
if (basedir == null) {
basedir = new File(".").getCanonicalPath();
}
Path path = FileSystems.getDefault().getPath(basedir, "/src/test/resources/webhdfs-liststatus-test.json");
driver.getMock("WEBHDFS").expect().method("GET").pathInfo("/v1/hdfstest").queryParam("op", "LISTSTATUS").respond().status(HttpStatus.SC_OK).content(IOUtils.toByteArray(path.toUri())).contentType("application/json");
ValidatableResponse response = given().log().all().auth().preemptive().basic(user, password).header("X-XSRF-Header", "jksdhfkhdsf").queryParam("op", "LISTSTATUS").when().get(driver.getUrl("WEBHDFS") + "/v1/hdfstest").then().statusCode(statusCode).log().body();
if (statusCode == HttpStatus.SC_OK) {
response.body("FileStatuses.FileStatus[0].pathSuffix", is("dir"));
}
}
use of io.restassured.response.ValidatableResponse in project IPK-BrAPI-Validator by plantbreeding.
the class TestItemRunner method connect.
/**
* Connect to an endpoint and store the server response.
*
* @return server response
*/
private ValidatableResponse connect() {
LOGGER.info("New Request. URL: " + this.url);
RestAssured.useRelaxedHTTPSValidation();
try {
URL u = new URL(url);
if ((Config.get("advancedMode") != null && Config.get("advancedMode").equals("true")) && u.getPort() != 80 && u.getPort() != -1) {
throw new IllegalArgumentException();
}
RequestSpecification rs = given().contentType("application/json");
List<Param> params = this.item.getParameters();
if (this.method.equals("GET")) {
if (params != null) {
for (Param p : params) {
String value = RunnerService.replaceVariablesUrl(p.getValue(), this.variables);
rs.param(p.getParam(), value);
}
}
} else if (this.method.equals("POST") || this.method.equals("PUT")) {
ObjectNode bodyParams = (new ObjectMapper()).createObjectNode();
if (params != null) {
for (Param p : params) {
String value = RunnerService.replaceVariablesUrl(p.getValue(), this.variables);
bodyParams.put(p.getParam(), value);
}
}
rs.body(bodyParams.toString());
}
ValidatableResponse vr = rs.request(this.method, this.url).then();
return vr;
} catch (AssertionError e) {
LOGGER.info("Connection error");
LOGGER.info("== cause ==");
LOGGER.info(e.getMessage());
} catch (IllegalArgumentException e) {
LOGGER.info("Connection error. Invalid port");
LOGGER.info("== cause ==");
LOGGER.info(e.getMessage());
} catch (Exception e) {
if (e.getClass().equals(SSLHandshakeException.class)) {
LOGGER.info("Connection error");
LOGGER.info("== cause ==");
LOGGER.info(e.getMessage());
}
}
return null;
}
use of io.restassured.response.ValidatableResponse in project molgenis by molgenis.
the class RestControllerIT method getWithoutTokenNotAllowed.
@Test
public void getWithoutTokenNotAllowed() {
ValidatableResponse response;
response = getWithoutToken("sys_FreemarkerTemplate");
response.statusCode(UNAUTHORIZED).body("errors.message[0]", Matchers.equalTo("No read permission on entity type 'Freemarker template' with id 'sys_FreemarkerTemplate'"));
response = getWithoutToken("sys_scr_ScriptType");
response.statusCode(UNAUTHORIZED).body("errors.message[0]", Matchers.equalTo("No read permission on entity type 'Script type' with id 'sys_scr_ScriptType'"));
}
use of io.restassured.response.ValidatableResponse in project molgenis by molgenis.
the class RestControllerV1APIIT method testRetrieveEntity.
@Test
public void testRetrieveEntity() {
ValidatableResponse response = given().log().all().header(X_MOLGENIS_TOKEN, testUserToken).contentType(APPLICATION_JSON).when().get(API_V1 + "V1_API_TypeTestRefAPIV1/ref1").then().log().all();
validateRetrieveEntity(response);
}
use of io.restassured.response.ValidatableResponse in project molgenis by molgenis.
the class RestControllerV1APIIT method testRetrieveEntityCollectionResponsePost.
@Test
public void testRetrieveEntityCollectionResponsePost() {
ValidatableResponse response = given().log().all().header(X_MOLGENIS_TOKEN, testUserToken).contentType(APPLICATION_JSON).body(new EntityCollectionRequest()).when().post(API_V1 + "V1_API_Items?_method=GET").then().log().all();
validateRetrieveEntityCollectionResponse(response);
}
Aggregations