/** * Enable logging of both the request and the response if REST Assureds test validation fails with the specified log detail. * <p/> * <p> * This is just a shortcut for: * </p> * <pre> * RestAssured.config = RestAssured.config().logConfig(logConfig().enableLoggingOfRequestAndResponseIfValidationFails(logDetail)); * </pre> * * @param logDetail The log detail to show in the log */ public static void enableLoggingOfRequestAndResponseIfValidationFails(LogDetail logDetail) { LogConfig logConfig = logConfig().enableLoggingOfRequestAndResponseIfValidationFails(logDetail); config = RestAssured.config().logConfig(logConfig); // Update request specification if already defined otherwise it'll override the configs. // Note that request spec also influence response spec when it comes to logging if validation fails due to the way filters work if (requestSpecification != null && requestSpecification instanceof RequestSpecificationImpl) { RestAssuredConfig restAssuredConfig = ((RequestSpecificationImpl) requestSpecification).getConfig(); if (restAssuredConfig == null) { restAssuredConfig = config; } else { LogConfig logConfigForRequestSpec = restAssuredConfig.getLogConfig().enableLoggingOfRequestAndResponseIfValidationFails(logDetail); restAssuredConfig = restAssuredConfig.logConfig(logConfigForRequestSpec); } requestSpecification.config(restAssuredConfig); } }
/** * 装载此次请求配置 * * @param path */ private RequestSpecification getRequestSpecification(String path) { return given().headers(HEADERS).cookies(COOKIES).config(restAssuredConfig).basePath(path); }
public void ignoreSSLCerts() { SSLContext sslContext = null; try { sslContext = SSLContext.getInstance("TLS"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } TrustManager[] trustManagerArray = { new NullX509TrustManager() }; try { sslContext.init(null, trustManagerArray, null); } catch (KeyManagementException e) { throw new RuntimeException(e); } SSLSocketFactory socketFactory = new SSLSocketFactory(sslContext, new NullHostnameVerifier()); SSLConfig sslConfig = new SSLConfig(); sslConfig = sslConfig.sslSocketFactory(socketFactory); sslConfig = sslConfig.x509HostnameVerifier(new NullHostnameVerifier()); RestAssuredConfig cfg = new RestAssuredConfig(); cfg = cfg.sslConfig(sslConfig); request = request.config(cfg); }
public void setSSLContext(SSLContext sslContext) { SSLSocketFactory socketFactory = new SSLSocketFactory(sslContext); SSLConfig sslConfig = new SSLConfig(); sslConfig = sslConfig.sslSocketFactory(socketFactory); RestAssuredConfig cfg = new RestAssuredConfig(); cfg = cfg.sslConfig(sslConfig); request = request.config(cfg); }
public Rest() { spec = given().config(RestAssured.config() .headerConfig(headerConfig() .overwriteHeadersWithName("Authorization") .overwriteHeadersWithName("Content-Type"))); }
@Override protected RequestSpecification buildBaseRequestSpecification() { RequestSpecification spec = RestAssured.given(); if (auth != null) { spec.auth().preemptive().basic(auth.get("username"), auth.get("password")); } if (httpLog != null) { spec.config(RestAssured .config() .logConfig(logConfig() .enableLoggingOfRequestAndResponseIfValidationFails() .defaultStream(new PrintStream(new WriterOutputStream(httpLog))) .enablePrettyPrinting(true))); } return spec; }
public boolean isServerStarted() { try { RestAssuredConfig config = RestAssured.config().httpClient(RestAssuredConfig.config().getHttpClientConfig().setParam("CONNECTION_MANAGER_TIMEOUT", 1000)); return RestAssured.given().config(config).baseUri(getBaseUri()).basePath("/mockserver").get("/").statusCode() == 200; } catch (Exception e) { return false; } }