Skip to content

Commit

Permalink
Migrations of proxy configuration to new API in the master
Browse files Browse the repository at this point in the history
- Migration to Apache HTTP Client 4.3
- FEST -> AssertJ
  • Loading branch information
arteam authored and Artem Prigoda committed Apr 10, 2015
1 parent 1740616 commit 816778a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Expand Up @@ -350,9 +350,11 @@ public void usesProxyWithAuth() throws Exception {
ProxyConfiguration proxy = new ProxyConfiguration("192.168.52.11", 8080, "http", auth);
config.setProxyConfiguration(proxy);

DefaultHttpClient httpClient = checkProxy(config, new HttpHost("192.168.52.11", 8080, "http"));
CloseableHttpClient httpClient = checkProxy(config, new HttpHost("192.168.52.11", 8080, "http"));

assertThat(httpClient.getCredentialsProvider().getCredentials(new AuthScope("192.168.52.11", 8080)))
CredentialsProvider credentialsProvider = (CredentialsProvider)
FieldUtils.getField(httpClient.getClass(), "credentialsProvider", true).get(httpClient);
assertThat(credentialsProvider.getCredentials(new AuthScope("192.168.52.11", 8080)))
.isEqualTo(new UsernamePasswordCredentials("secret", "stuff"));
}

Expand All @@ -361,11 +363,14 @@ public void usesNoProxy() throws Exception {
checkProxy(new HttpClientConfiguration(), null);
}

private DefaultHttpClient checkProxy(HttpClientConfiguration config, HttpHost proxyHost) throws HttpException {
DefaultHttpClient httpClient = (DefaultHttpClient) builder.using(config).build("test");
private CloseableHttpClient checkProxy(HttpClientConfiguration config, HttpHost proxyHost) throws Exception {
CloseableHttpClient httpClient = builder.using(config).build("test");

HttpRoutePlanner routePlanner = (HttpRoutePlanner)
FieldUtils.getField(httpClient.getClass(), "routePlanner", true).get(httpClient);

HttpHost target = new HttpHost("dropwizard.io", 80);
HttpRoute route = httpClient.getRoutePlanner().determineRoute(target, new HttpGet(target.toURI()),
HttpRoute route = routePlanner.determineRoute(target, new HttpGet(target.toURI()),
new BasicHttpContext());
assertThat(route.getProxyHost()).isEqualTo(proxyHost);
assertThat(route.getTargetHost()).isEqualTo(new HttpHost("dropwizard.io", 80, "http"));
Expand Down
Expand Up @@ -14,7 +14,8 @@
import javax.validation.Validation;
import java.io.File;

import static org.fest.assertions.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;


public class HttpClientConfigurationTest {

Expand Down

0 comments on commit 816778a

Please sign in to comment.