forked from mttkay/signpost
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lots of improvements to provider flexibility, in terms of how request…
…s are sent to the server
- Loading branch information
Showing
18 changed files
with
447 additions
and
321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
signpost-commonshttp4/src/main/java/oauth/signpost/commonshttp/HttpResponseAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package oauth.signpost.commonshttp; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import oauth.signpost.http.HttpResponse; | ||
|
||
public class HttpResponseAdapter implements HttpResponse { | ||
|
||
private org.apache.http.HttpResponse response; | ||
|
||
public HttpResponseAdapter(org.apache.http.HttpResponse response) { | ||
this.response = response; | ||
} | ||
|
||
public InputStream getContent() throws IOException { | ||
return response.getEntity().getContent(); | ||
} | ||
|
||
public int getStatusCode() throws IOException { | ||
return response.getStatusLine().getStatusCode(); | ||
} | ||
|
||
public Object unwrap() { | ||
return response; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...st-commonshttp4/src/test/java/oauth/signpost/commonshttp/CommonHttpOAuthProviderMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package oauth.signpost.commonshttp; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.InputStream; | ||
|
||
import oauth.signpost.http.HttpRequest; | ||
import oauth.signpost.mocks.OAuthProviderMock; | ||
|
||
import org.apache.http.HttpResponse; | ||
import org.apache.http.ProtocolVersion; | ||
import org.apache.http.StatusLine; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.methods.HttpUriRequest; | ||
import org.apache.http.entity.InputStreamEntity; | ||
import org.apache.http.message.BasicStatusLine; | ||
import org.mockito.Mockito; | ||
|
||
@SuppressWarnings("serial") | ||
public class CommonHttpOAuthProviderMock extends CommonsHttpOAuthProvider implements | ||
OAuthProviderMock { | ||
|
||
private HttpClient httpClientMock; | ||
|
||
public CommonHttpOAuthProviderMock(String requestTokenUrl, String accessTokenUrl, | ||
String websiteUrl) { | ||
super(requestTokenUrl, accessTokenUrl, websiteUrl); | ||
} | ||
|
||
@Override | ||
protected oauth.signpost.http.HttpResponse sendRequest(HttpRequest request) throws Exception { | ||
HttpResponse resp = httpClientMock.execute((HttpUriRequest) request.unwrap()); | ||
return new HttpResponseAdapter(resp); | ||
} | ||
|
||
public void mockConnection(String responseBody) throws Exception { | ||
HttpResponse response = mock(HttpResponse.class); | ||
this.httpClientMock = mock(HttpClient.class); | ||
InputStream is = new ByteArrayInputStream(responseBody.getBytes()); | ||
InputStreamEntity entity = new InputStreamEntity(is, responseBody.length()); | ||
StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"); | ||
|
||
when(response.getStatusLine()).thenReturn(statusLine); | ||
when(response.getEntity()).thenReturn(entity); | ||
when(httpClientMock.execute(Mockito.any(HttpUriRequest.class))).thenReturn(response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.