Search in sources :

Example 1 with ValidatableResponse

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"));
    }
}
Also used : Path(java.nio.file.Path) ValidatableResponse(io.restassured.response.ValidatableResponse) File(java.io.File)

Example 2 with ValidatableResponse

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;
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RequestSpecification(io.restassured.specification.RequestSpecification) Param(de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.config.Param) URL(java.net.URL) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) ProcessingException(com.github.fge.jsonschema.core.exceptions.ProcessingException) IOException(java.io.IOException) ConnectionClosedException(org.apache.http.ConnectionClosedException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Example 3 with ValidatableResponse

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'"));
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) Test(org.testng.annotations.Test)

Example 4 with ValidatableResponse

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);
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) Test(org.testng.annotations.Test)

Example 5 with ValidatableResponse

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);
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) EntityCollectionRequest(org.molgenis.data.rest.EntityCollectionRequest) Test(org.testng.annotations.Test)

Aggregations

ValidatableResponse (io.restassured.response.ValidatableResponse)33 Test (org.testng.annotations.Test)24 File (java.io.File)4 Path (java.nio.file.Path)3 EntityTypeRequest (org.molgenis.data.rest.EntityTypeRequest)3 Gson (com.google.gson.Gson)2 Response (io.restassured.response.Response)2 URL (java.net.URL)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Test (org.junit.Test)2 EntityCollectionRequest (org.molgenis.data.rest.EntityCollectionRequest)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ProcessingException (com.github.fge.jsonschema.core.exceptions.ProcessingException)1 JsonArray (com.google.gson.JsonArray)1 Param (de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.config.Param)1 RestAssured.baseURI (io.restassured.RestAssured.baseURI)1 RequestSpecification (io.restassured.specification.RequestSpecification)1 IOException (java.io.IOException)1