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