|
35 | 35 | import org.apache.http.util.EntityUtils; |
36 | 36 | import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement; |
37 | 37 | import org.elasticsearch.mocksocket.MockHttpServer; |
| 38 | +import org.junit.After; |
38 | 39 | import org.junit.AfterClass; |
| 40 | +import org.junit.Before; |
39 | 41 | import org.junit.BeforeClass; |
40 | 42 |
|
41 | 43 | import java.io.IOException; |
|
68 | 70 | @IgnoreJRERequirement |
69 | 71 | public class RestClientSingleHostIntegTests extends RestClientTestCase { |
70 | 72 |
|
71 | | - private static HttpServer httpServer; |
72 | | - private static RestClient restClient; |
73 | | - private static String pathPrefix; |
74 | | - private static Header[] defaultHeaders; |
| 73 | + private HttpServer httpServer; |
| 74 | + private RestClient restClient; |
| 75 | + private String pathPrefix; |
| 76 | + private Header[] defaultHeaders; |
75 | 77 |
|
76 | | - @BeforeClass |
77 | | - public static void startHttpServer() throws Exception { |
| 78 | + @Before |
| 79 | + public void startHttpServer() throws Exception { |
78 | 80 | pathPrefix = randomBoolean() ? "/testPathPrefix/" + randomAsciiLettersOfLengthBetween(1, 5) : ""; |
79 | 81 | httpServer = createHttpServer(); |
80 | 82 | defaultHeaders = RestClientTestUtil.randomHeaders(getRandom(), "Header-default"); |
81 | 83 | restClient = createRestClient(false, true); |
82 | 84 | } |
83 | 85 |
|
84 | | - private static HttpServer createHttpServer() throws Exception { |
| 86 | + private HttpServer createHttpServer() throws Exception { |
85 | 87 | HttpServer httpServer = MockHttpServer.createHttp(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0); |
86 | 88 | httpServer.start(); |
87 | 89 | //returns a different status code depending on the path |
@@ -128,7 +130,7 @@ public void handle(HttpExchange httpExchange) throws IOException { |
128 | 130 | } |
129 | 131 | } |
130 | 132 |
|
131 | | - private static RestClient createRestClient(final boolean useAuth, final boolean usePreemptiveAuth) { |
| 133 | + private RestClient createRestClient(final boolean useAuth, final boolean usePreemptiveAuth) { |
132 | 134 | // provide the username/password for every request |
133 | 135 | final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); |
134 | 136 | credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("user", "pass")); |
@@ -156,8 +158,8 @@ public HttpAsyncClientBuilder customizeHttpClient(final HttpAsyncClientBuilder h |
156 | 158 | return restClientBuilder.build(); |
157 | 159 | } |
158 | 160 |
|
159 | | - @AfterClass |
160 | | - public static void stopHttpServers() throws IOException { |
| 161 | + @After |
| 162 | + public void stopHttpServers() throws IOException { |
161 | 163 | restClient.close(); |
162 | 164 | restClient = null; |
163 | 165 | httpServer.stop(0); |
|
0 commit comments