16
16
*/
17
17
package com .optimizely .ab ;
18
18
19
- import org .apache .http .HttpResponse ;
20
- import org .apache .http .client .ClientProtocolException ;
21
- import org .apache .http .client .HttpClient ;
22
19
import org .apache .http .client .ResponseHandler ;
20
+ import org .apache .http .client .methods .HttpGet ;
23
21
import org .apache .http .client .methods .HttpUriRequest ;
24
22
import org .apache .http .client .methods .RequestBuilder ;
23
+ import org .apache .http .conn .HttpHostConnectException ;
25
24
import org .apache .http .impl .client .CloseableHttpClient ;
25
+ import org .junit .After ;
26
+ import org .junit .Before ;
26
27
import org .junit .Test ;
27
28
28
29
import java .io .IOException ;
33
34
34
35
public class OptimizelyHttpClientTest {
35
36
37
+ @ Before
38
+ public void setUp () {
39
+ System .setProperty ("https.proxyHost" , "localhost" );
40
+ }
41
+
42
+ @ After
43
+ public void tearDown () {
44
+ System .clearProperty ("https.proxyHost" );
45
+ }
46
+
36
47
@ Test
37
48
public void testDefaultConfiguration () {
38
49
OptimizelyHttpClient optimizelyHttpClient = OptimizelyHttpClient .builder ().build ();
@@ -50,6 +61,15 @@ public void testNonDefaultConfiguration() {
50
61
assertTrue (optimizelyHttpClient .getHttpClient () instanceof CloseableHttpClient );
51
62
}
52
63
64
+ @ Test (expected = HttpHostConnectException .class )
65
+ public void testProxySettings () throws IOException {
66
+ OptimizelyHttpClient optimizelyHttpClient = OptimizelyHttpClient .builder ().build ();
67
+
68
+ // If this request succeeds then the proxy config was not picked up.
69
+ HttpGet get = new HttpGet ("https://www.optimizely.com" );
70
+ optimizelyHttpClient .execute (get );
71
+ }
72
+
53
73
@ Test
54
74
public void testExecute () throws IOException {
55
75
HttpUriRequest httpUriRequest = RequestBuilder .get ().build ();
0 commit comments