Search in sources :

Example 1 with Param

use of de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.config.Param 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)

Aggregations

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 Param (de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.config.Param)1 ValidatableResponse (io.restassured.response.ValidatableResponse)1 RequestSpecification (io.restassured.specification.RequestSpecification)1 IOException (java.io.IOException)1 URL (java.net.URL)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1 ConnectionClosedException (org.apache.http.ConnectionClosedException)1