Skip to content

Commit 92392ce

Browse files
authored
Merge pull request #67 from Bandwidth/SWI-3111
SWI-3111
2 parents 716152f + 6d51775 commit 92392ce

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

src/main/java/com/bandwidth/iris/sdk/IrisClient.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import com.bandwidth.iris.sdk.utils.XmlUtils;
66
import org.apache.commons.lang3.StringUtils;
77
import org.apache.http.Header;
8+
import org.apache.http.HttpHost;
89
import org.apache.http.HttpResponse;
910
import org.apache.http.auth.AuthScope;
1011
import org.apache.http.auth.Credentials;
1112
import org.apache.http.auth.UsernamePasswordCredentials;
1213
import org.apache.http.client.methods.*;
1314
import org.apache.http.client.utils.URIBuilder;
15+
import org.apache.http.conn.params.ConnRoutePNames;
1416
import org.apache.http.entity.ContentType;
1517
import org.apache.http.entity.FileEntity;
1618
import org.apache.http.entity.StringEntity;
@@ -47,6 +49,17 @@ public IrisClient(String accountId, String userName, String password) {
4749
this(defaultUri, accountId, userName, password, defaultVersion);
4850
}
4951

52+
public IrisClient(DefaultHttpClient httpClient, String uri, String accountId, String username, String password) {
53+
this.uri = uri;
54+
this.baseUrl = "/" + defaultVersion + "/";
55+
this.baseAccountUrl = this.baseUrl + "accounts/" + accountId + "/";
56+
57+
Credentials credentials = new UsernamePasswordCredentials(username, password);
58+
httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);
59+
60+
this.httpClient = httpClient;
61+
}
62+
5063
private void initHttpClient(String userName, String password) {
5164
httpClient = new DefaultHttpClient();
5265
Credentials credentials = new UsernamePasswordCredentials(userName, password);

src/test/java/com/bandwidth/iris/sdk/BaseModelTests.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
package com.bandwidth.iris.sdk;
22

33
import com.github.tomakehurst.wiremock.junit.WireMockRule;
4+
import org.apache.http.HttpHost;
5+
import org.apache.http.auth.AuthScope;
6+
import org.apache.http.auth.Credentials;
7+
import org.apache.http.auth.UsernamePasswordCredentials;
8+
import org.apache.http.client.CredentialsProvider;
9+
import org.apache.http.conn.params.ConnRoutePNames;
10+
import org.apache.http.impl.client.BasicCredentialsProvider;
11+
import org.apache.http.impl.client.DefaultHttpClient;
12+
import org.apache.http.impl.client.ProxyAuthenticationStrategy;
413
import org.junit.Rule;
514
import org.junit.rules.ExpectedException;
615

@@ -16,6 +25,20 @@ protected IrisClient getDefaultClient() {
1625
return new IrisClient("http://localhost:8090", "accountId", "username", "password", "v1.0");
1726
}
1827

28+
protected IrisClient getCustomClient() {
29+
DefaultHttpClient client = new DefaultHttpClient();
30+
HttpHost proxy = new HttpHost("localhost",8090);
31+
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);
32+
33+
Credentials credentials = new UsernamePasswordCredentials("userName", "password");
34+
CredentialsProvider credsProvider = new BasicCredentialsProvider();
35+
credsProvider.setCredentials( new AuthScope("localhost",8080), credentials);
36+
37+
client.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());
38+
39+
return new IrisClient(client, "http://localhost:8090", "accountId", "username", "password");
40+
}
41+
1942
public void setMessage(String s) {
2043
this.message = s;
2144
}

src/test/java/com/bandwidth/iris/sdk/OrderTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ public void testGet() throws Exception {
4949

5050
}
5151

52+
@Test
53+
public void testGetWithCustomClient() throws Exception {
54+
String url = "/v1.0/accounts/accountId/orders/someid";
55+
stubFor(get(urlMatching(url))
56+
.willReturn(aResponse()
57+
.withStatus(200)
58+
.withBody(IrisClientTestUtils.validOrderResponseXml)));
59+
60+
OrderResponse orderResponse = Order.get(getCustomClient(), "someid");
61+
assertEquals(orderResponse.getOrder().getid(), "someid");
62+
assertEquals(orderResponse.getOrder().getExistingTelephoneNumberOrderType().getTelephoneNumberList().get(0),
63+
"2052865046");
64+
assertEquals(orderResponse.getOrder().getName(), "A New Order");
65+
}
66+
5267
@Test
5368
public void testGetError() throws Exception {
5469
String url = "/v1.0/accounts/accountId/orders/errorid";

0 commit comments

Comments
 (0)