@@ -77,7 +77,8 @@ private HttpClientConfig getMockHttpClientConfigWithTrueIgnoreSSLCerts() {
77
77
@ Test
78
78
public void testApacheHttpClientConstructorFalseIgnoreSSLCerts () throws ClientException , IOException {
79
79
HttpClientConfig config = this .getMockHttpClientConfigWithFalseIgnoreSSLCerts ();
80
- ApacheHttpClient httpClient = ApacheHttpClient .getInstance (config );
80
+ ApacheHttpClient httpClient = ApacheHttpClient .getInstance ();
81
+ httpClient .init (config );
81
82
Assert .assertTrue (httpClient instanceof ApacheHttpClient );
82
83
httpClient .close ();
83
84
}
@@ -90,7 +91,8 @@ public void testApacheHttpClientFalseIgnoreSSLCertsNotNullSslSocketFactory() thr
90
91
Mockito .when (config .getSslSocketFactory ()).thenReturn (sslSocketFactory );
91
92
Mockito .when (config .getHostnameVerifier ()).thenReturn (hostnameVerifier );
92
93
93
- ApacheHttpClient httpClient = ApacheHttpClient .getInstance (config );
94
+ ApacheHttpClient httpClient = ApacheHttpClient .getInstance ();
95
+ httpClient .init (config );
94
96
Assert .assertTrue (httpClient instanceof ApacheHttpClient );
95
97
httpClient .close ();
96
98
}
@@ -101,7 +103,8 @@ public void testApacheHttpClientFalseIgnoreSSLCertsNotNullKeyManagers() throws C
101
103
SecureRandom secureRandom = Mockito .mock (SecureRandom .class );
102
104
Mockito .when (config .getSecureRandom ()).thenReturn (secureRandom );
103
105
104
- ApacheHttpClient httpClient = ApacheHttpClient .getInstance (config );
106
+ ApacheHttpClient httpClient = ApacheHttpClient .getInstance ();
107
+ httpClient .init (config );
105
108
Assert .assertTrue (httpClient instanceof ApacheHttpClient );
106
109
httpClient .close ();
107
110
}
@@ -114,23 +117,26 @@ public void testApacheHttpClientNotNullExecutorService() throws ClientException,
114
117
115
118
Mockito .when (config .getKeepAliveDurationMillis ()).thenReturn (0L );
116
119
117
- ApacheHttpClient httpClient = ApacheHttpClient .getInstance (config );
120
+ ApacheHttpClient httpClient = ApacheHttpClient .getInstance ();
121
+ httpClient .init (config );
118
122
Assert .assertTrue (httpClient instanceof ApacheHttpClient );
119
123
httpClient .close ();
120
124
}
121
125
122
126
@ Test
123
127
public void testApacheHttpClientConstructorIgnoreSSLCerts () throws ClientException , IOException {
124
128
HttpClientConfig config = this .getMockHttpClientConfigWithTrueIgnoreSSLCerts ();
125
- ApacheHttpClient httpClient = ApacheHttpClient .getInstance (config );
129
+ ApacheHttpClient httpClient = ApacheHttpClient .getInstance ();
130
+ httpClient .init (config );
126
131
Assert .assertTrue (httpClient instanceof ApacheHttpClient );
127
132
httpClient .close ();
128
133
}
129
134
130
135
@ Test
131
136
public void testRestoreSSLCertificate () throws ClientException , IOException {
132
137
HttpClientConfig config = this .getMockHttpClientConfigWithFalseIgnoreSSLCerts ();
133
- ApacheHttpClient httpClient = ApacheHttpClient .getInstance (config );
138
+ ApacheHttpClient httpClient = ApacheHttpClient .getInstance ();
139
+ httpClient .init (config );
134
140
thrown .expect (IllegalStateException .class );
135
141
thrown .expectMessage ("Apache httpclient does not support modify sslFactory after inited, "
136
142
+ "use HttpClientConfig.setIgnoreSSLCerts(true) while building client" );
@@ -141,7 +147,8 @@ public void testRestoreSSLCertificate() throws ClientException, IOException {
141
147
@ Test
142
148
public void testIgnoreSSLCertificate () throws ClientException , IOException {
143
149
HttpClientConfig config = this .getMockHttpClientConfigWithFalseIgnoreSSLCerts ();
144
- ApacheHttpClient httpClient = ApacheHttpClient .getInstance (config );
150
+ ApacheHttpClient httpClient = ApacheHttpClient .getInstance ();
151
+ httpClient .init (config );
145
152
thrown .expect (IllegalStateException .class );
146
153
thrown .expectMessage ("Apache httpclient does not support modify sslFactory after inited, "
147
154
+ "use HttpClientConfig.setIgnoreSSLCerts(true) while building client" );
@@ -192,7 +199,8 @@ private CloseableHttpResponse getMockHttpResponse() {
192
199
public void testSyncInvoke () throws ClientException , IOException , NoSuchFieldException , SecurityException ,
193
200
IllegalArgumentException , IllegalAccessException {
194
201
HttpClientConfig config = this .getMockHttpClientConfigWithFalseIgnoreSSLCerts ();
195
- ApacheHttpClient apacheHttpClient = ApacheHttpClient .getInstance (config );
202
+ ApacheHttpClient apacheHttpClient = ApacheHttpClient .getInstance ();
203
+ apacheHttpClient .init (config );
196
204
HttpRequest apiRequest = this .getMockHttpRequest ();
197
205
CloseableHttpResponse closeableHttpResponse = this .getMockHttpResponse ();
198
206
Field httpClientReflect = ApacheHttpClient .class .getDeclaredField ("httpClient" );
@@ -208,7 +216,8 @@ public void testSyncInvoke() throws ClientException, IOException, NoSuchFieldExc
208
216
public void testAsyncInvoke () throws ClientException , IOException , NoSuchFieldException , SecurityException ,
209
217
IllegalArgumentException , IllegalAccessException {
210
218
HttpClientConfig config = this .getMockHttpClientConfigWithFalseIgnoreSSLCerts ();
211
- ApacheHttpClient apacheHttpClient = ApacheHttpClient .getInstance (config );
219
+ ApacheHttpClient apacheHttpClient = ApacheHttpClient .getInstance ();
220
+ apacheHttpClient .init (config );
212
221
HttpRequest apiRequest = this .getMockHttpRequest ();
213
222
214
223
CloseableHttpResponse closeableHttpResponse = this .getMockHttpResponse ();
@@ -227,7 +236,8 @@ public void testAsyncInvoke() throws ClientException, IOException, NoSuchFieldEx
227
236
public void testSyncInvokeNullContentType () throws ClientException , IOException , NoSuchFieldException ,
228
237
SecurityException , IllegalArgumentException , IllegalAccessException {
229
238
HttpClientConfig config = this .getMockHttpClientConfigWithFalseIgnoreSSLCerts ();
230
- ApacheHttpClient apacheHttpClient = ApacheHttpClient .getInstance (config );
239
+ ApacheHttpClient apacheHttpClient = ApacheHttpClient .getInstance ();
240
+ apacheHttpClient .init (config );
231
241
HttpRequest apiRequest = this .getMockHttpRequest ();
232
242
CloseableHttpResponse closeableHttpResponse = this .getMockHttpResponse ();
233
243
@@ -249,7 +259,8 @@ public void testSyncInvokeNullContentType() throws ClientException, IOException,
249
259
public void testSyncInvokeNullHttpResponseEntity () throws ClientException , IOException , NoSuchFieldException ,
250
260
SecurityException , IllegalArgumentException , IllegalAccessException {
251
261
HttpClientConfig config = this .getMockHttpClientConfigWithFalseIgnoreSSLCerts ();
252
- ApacheHttpClient apacheHttpClient = ApacheHttpClient .getInstance (config );
262
+ ApacheHttpClient apacheHttpClient = ApacheHttpClient .getInstance ();
263
+ apacheHttpClient .init (config );
253
264
HttpRequest apiRequest = this .getMockHttpRequest ();
254
265
Mockito .when (apiRequest .getSysMethod ()).thenReturn (MethodType .PUT );
255
266
Mockito .when (apiRequest .getHeaderValue (Mockito .anyString ())).thenReturn ("contentType" );
@@ -276,7 +287,8 @@ public void testSyncInvokeNullHttpResponseEntity() throws ClientException, IOExc
276
287
public void testSyncInvokeNotNullHttpResponseEntityIsChunked () throws ClientException , IOException , NoSuchFieldException ,
277
288
SecurityException , IllegalArgumentException , IllegalAccessException {
278
289
HttpClientConfig config = this .getMockHttpClientConfigWithFalseIgnoreSSLCerts ();
279
- ApacheHttpClient apacheHttpClient = ApacheHttpClient .getInstance (config );
290
+ ApacheHttpClient apacheHttpClient = ApacheHttpClient .getInstance ();
291
+ apacheHttpClient .init (config );
280
292
HttpRequest apiRequest = this .getMockHttpRequest ();
281
293
Mockito .when (apiRequest .getSysMethod ()).thenReturn (MethodType .PUT );
282
294
Mockito .when (apiRequest .getHeaderValue (Mockito .anyString ())).thenReturn ("contentType" );
@@ -303,7 +315,8 @@ public void testSyncInvokeNotNullHttpResponseEntityIsChunked() throws ClientExce
303
315
public void testSyncInvokeNotNullHttpResponseEntity () throws ClientException , IOException , NoSuchFieldException ,
304
316
SecurityException , IllegalArgumentException , IllegalAccessException {
305
317
HttpClientConfig config = this .getMockHttpClientConfigWithFalseIgnoreSSLCerts ();
306
- ApacheHttpClient apacheHttpClient = ApacheHttpClient .getInstance (config );
318
+ ApacheHttpClient apacheHttpClient = ApacheHttpClient .getInstance ();
319
+ apacheHttpClient .init (config );
307
320
HttpRequest apiRequest = this .getMockHttpRequest ();
308
321
Mockito .when (apiRequest .getSysMethod ()).thenReturn (MethodType .PUT );
309
322
Mockito .when (apiRequest .getHeaderValue (Mockito .anyString ())).thenReturn ("contentType" );
@@ -332,9 +345,10 @@ public void testSyncInvokeNotNullHttpResponseEntity() throws ClientException, IO
332
345
@ Test
333
346
public void testClientTimeout () throws ClientException , IOException , NoSuchFieldException , SecurityException ,
334
347
IllegalArgumentException , IllegalAccessException , NoSuchMethodException , InvocationTargetException {
335
- ApacheHttpClient .getInstance (HttpClientConfig . getDefault () ).close ();
348
+ ApacheHttpClient .getInstance ().close ();
336
349
HttpClientConfig config = HttpClientConfig .getDefault ();
337
- ApacheHttpClient apacheHttpClient = ApacheHttpClient .getInstance (config );
350
+ ApacheHttpClient apacheHttpClient = ApacheHttpClient .getInstance ();
351
+ apacheHttpClient .init (config );
338
352
Method declaredMethod = ApacheHttpClient .class .getDeclaredMethod ("parseToHttpRequest" , HttpRequest .class );
339
353
declaredMethod .setAccessible (true );
340
354
HttpRequest apiReq = new HttpRequest ("http://test.com" );
@@ -346,7 +360,8 @@ public void testClientTimeout() throws ClientException, IOException, NoSuchField
346
360
347
361
config .setConnectionTimeoutMillis (5010 );
348
362
config .setReadTimeoutMillis (10010 );
349
- apacheHttpClient = ApacheHttpClient .getInstance (config );
363
+ apacheHttpClient = ApacheHttpClient .getInstance ();
364
+ apacheHttpClient .init (config );
350
365
httpRequest = (HttpRequestBase ) declaredMethod .invoke (apacheHttpClient , apiReq );
351
366
Assert .assertEquals (5010 , httpRequest .getConfig ().getConnectTimeout ());
352
367
Assert .assertEquals (10010 , httpRequest .getConfig ().getSocketTimeout ());
@@ -356,11 +371,12 @@ public void testClientTimeout() throws ClientException, IOException, NoSuchField
356
371
@ Test
357
372
public void testRequestTimeout () throws ClientException , IOException , NoSuchFieldException , SecurityException ,
358
373
IllegalArgumentException , IllegalAccessException , NoSuchMethodException , InvocationTargetException {
359
- ApacheHttpClient .getInstance (HttpClientConfig . getDefault () ).close ();
374
+ ApacheHttpClient .getInstance ().close ();
360
375
HttpClientConfig config = HttpClientConfig .getDefault ();
361
376
config .setConnectionTimeoutMillis (5020 );
362
377
config .setReadTimeoutMillis (10020 );
363
- ApacheHttpClient apacheHttpClient = ApacheHttpClient .getInstance (config );
378
+ ApacheHttpClient apacheHttpClient = ApacheHttpClient .getInstance ();
379
+ apacheHttpClient .init (config );
364
380
Method declaredMethod = ApacheHttpClient .class .getDeclaredMethod ("parseToHttpRequest" , HttpRequest .class );
365
381
declaredMethod .setAccessible (true );
366
382
HttpRequest apiReq = new HttpRequest ("http://test.com" );
0 commit comments