Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWI-3111 #67

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading