From c184aa4bdf80107bcd949acd39e319ac2090d7de Mon Sep 17 00:00:00 2001 From: dzieciou Date: Mon, 2 Nov 2020 08:09:21 +0100 Subject: [PATCH] Do not reuse HTTP client instance (bug fix for #37) --- .../curl/CurlRestAssuredConfigFactory.java | 2 +- .../CurlRestAssuredConfigFactoryTest.java | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/github/dzieciou/testing/curl/CurlRestAssuredConfigFactory.java b/src/main/java/com/github/dzieciou/testing/curl/CurlRestAssuredConfigFactory.java index e15e8b2..b761935 100644 --- a/src/main/java/com/github/dzieciou/testing/curl/CurlRestAssuredConfigFactory.java +++ b/src/main/java/com/github/dzieciou/testing/curl/CurlRestAssuredConfigFactory.java @@ -110,7 +110,7 @@ public static RestAssuredConfig updateConfig(RestAssuredConfig config, Options o handlers); return config .httpClient(config.getHttpClientConfig() - .reuseHttpClientInstance() + .dontReuseHttpClientInstance() .httpClientFactory(new MyHttpClientFactory(originalFactory, interceptor))); } diff --git a/src/test/java/com/github/dzieciou/testing/curl/CurlRestAssuredConfigFactoryTest.java b/src/test/java/com/github/dzieciou/testing/curl/CurlRestAssuredConfigFactoryTest.java index dc28e5a..432ba04 100644 --- a/src/test/java/com/github/dzieciou/testing/curl/CurlRestAssuredConfigFactoryTest.java +++ b/src/test/java/com/github/dzieciou/testing/curl/CurlRestAssuredConfigFactoryTest.java @@ -1,6 +1,7 @@ package com.github.dzieciou.testing.curl; +import io.restassured.specification.RequestSpecification; import org.apache.http.HttpException; import org.apache.http.HttpRequest; import org.apache.http.HttpRequestInterceptor; @@ -21,6 +22,7 @@ import io.restassured.config.HttpClientConfig; import io.restassured.config.RestAssuredConfig; +import static io.restassured.RestAssured.config; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.not; @@ -101,6 +103,24 @@ public void shouldSentRequestWhenUsingConfigurationFactory() { .statusCode(200); } + @Test + public void shouldSentSameRequestTwice() { + // Verifying fix for https://github.com/dzieciou/curl-logger/issues/37 + + //@formatter:off + RequestSpecification request = RestAssured.given() + .baseUri(MOCK_BASE_URI) + .port(MOCK_PORT) + .config(CurlRestAssuredConfigFactory.createConfig()) + .body("anything") + .when(); + + request.post("/"); + + request.post("/"); + //@formatter:on + } + @AfterClass public void closeMock() { mockServer.stop();