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