1616 */
1717package com .optimizely .ab ;
1818
19- import org .apache .http .HttpResponse ;
20- import org .apache .http .client .ClientProtocolException ;
21- import org .apache .http .client .HttpClient ;
2219import org .apache .http .client .ResponseHandler ;
20+ import org .apache .http .client .methods .HttpGet ;
2321import org .apache .http .client .methods .HttpUriRequest ;
2422import org .apache .http .client .methods .RequestBuilder ;
23+ import org .apache .http .conn .HttpHostConnectException ;
2524import org .apache .http .impl .client .CloseableHttpClient ;
25+ import org .junit .After ;
26+ import org .junit .Before ;
2627import org .junit .Test ;
2728
2829import java .io .IOException ;
3334
3435public class OptimizelyHttpClientTest {
3536
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+
3647 @ Test
3748 public void testDefaultConfiguration () {
3849 OptimizelyHttpClient optimizelyHttpClient = OptimizelyHttpClient .builder ().build ();
@@ -50,6 +61,15 @@ public void testNonDefaultConfiguration() {
5061 assertTrue (optimizelyHttpClient .getHttpClient () instanceof CloseableHttpClient );
5162 }
5263
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+
5373 @ Test
5474 public void testExecute () throws IOException {
5575 HttpUriRequest httpUriRequest = RequestBuilder .get ().build ();
0 commit comments