Skip to content

Commit

Permalink
Merge pull request #67 from Bandwidth/SWI-3111
Browse files Browse the repository at this point in the history
SWI-3111
  • Loading branch information
ajrice6713 authored Jul 18, 2024
2 parents 716152f + 6d51775 commit 92392ce
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/com/bandwidth/iris/sdk/IrisClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import com.bandwidth.iris.sdk.utils.XmlUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.methods.*;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.FileEntity;
import org.apache.http.entity.StringEntity;
Expand Down Expand Up @@ -47,6 +49,17 @@ public IrisClient(String accountId, String userName, String password) {
this(defaultUri, accountId, userName, password, defaultVersion);
}

public IrisClient(DefaultHttpClient httpClient, String uri, String accountId, String username, String password) {
this.uri = uri;
this.baseUrl = "/" + defaultVersion + "/";
this.baseAccountUrl = this.baseUrl + "accounts/" + accountId + "/";

Credentials credentials = new UsernamePasswordCredentials(username, password);
httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);

this.httpClient = httpClient;
}

private void initHttpClient(String userName, String password) {
httpClient = new DefaultHttpClient();
Credentials credentials = new UsernamePasswordCredentials(userName, password);
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/com/bandwidth/iris/sdk/BaseModelTests.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
package com.bandwidth.iris.sdk;

import com.github.tomakehurst.wiremock.junit.WireMockRule;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.ProxyAuthenticationStrategy;
import org.junit.Rule;
import org.junit.rules.ExpectedException;

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

protected IrisClient getCustomClient() {
DefaultHttpClient client = new DefaultHttpClient();
HttpHost proxy = new HttpHost("localhost",8090);
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);

Credentials credentials = new UsernamePasswordCredentials("userName", "password");
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials( new AuthScope("localhost",8080), credentials);

client.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());

return new IrisClient(client, "http://localhost:8090", "accountId", "username", "password");
}

public void setMessage(String s) {
this.message = s;
}
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/com/bandwidth/iris/sdk/OrderTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ public void testGet() throws Exception {

}

@Test
public void testGetWithCustomClient() throws Exception {
String url = "/v1.0/accounts/accountId/orders/someid";
stubFor(get(urlMatching(url))
.willReturn(aResponse()
.withStatus(200)
.withBody(IrisClientTestUtils.validOrderResponseXml)));

OrderResponse orderResponse = Order.get(getCustomClient(), "someid");
assertEquals(orderResponse.getOrder().getid(), "someid");
assertEquals(orderResponse.getOrder().getExistingTelephoneNumberOrderType().getTelephoneNumberList().get(0),
"2052865046");
assertEquals(orderResponse.getOrder().getName(), "A New Order");
}

@Test
public void testGetError() throws Exception {
String url = "/v1.0/accounts/accountId/orders/errorid";
Expand Down

0 comments on commit 92392ce

Please sign in to comment.