|
1 | 1 | package com.github.scribejava.httpclient.okhttp; |
2 | 2 |
|
3 | | -import com.github.scribejava.core.model.*; |
| 3 | +import com.github.scribejava.core.model.HttpClient; |
| 4 | +import com.github.scribejava.core.model.OAuthConfig; |
| 5 | +import com.github.scribejava.core.model.OAuthRequestAsync; |
| 6 | +import com.github.scribejava.core.model.Response; |
| 7 | +import com.github.scribejava.core.model.Verb; |
4 | 8 | import com.github.scribejava.core.oauth.OAuth20Service; |
5 | 9 | import com.github.scribejava.core.oauth.OAuthService; |
| 10 | +import com.github.scribejava.core.utils.StreamUtils; |
6 | 11 | import okhttp3.HttpUrl; |
7 | 12 | import okhttp3.OkHttpClient; |
8 | 13 | import okhttp3.mockwebserver.MockResponse; |
@@ -84,4 +89,25 @@ public void shouldSendPostRequest() throws Exception { |
84 | 89 |
|
85 | 90 | server.shutdown(); |
86 | 91 | } |
| 92 | + |
| 93 | + @Test |
| 94 | + public void shouldReadResponseStream() throws Exception { |
| 95 | + String expectedResponseBody = "response body"; |
| 96 | + |
| 97 | + MockWebServer server = new MockWebServer(); |
| 98 | + server.enqueue(new MockResponse().setBody(expectedResponseBody)); |
| 99 | + server.start(); |
| 100 | + |
| 101 | + HttpUrl baseUrl = server.url("/testUrl"); |
| 102 | + |
| 103 | + OAuthRequestAsync request = new OAuthRequestAsync(Verb.GET, baseUrl.toString(), oAuthService); |
| 104 | + Response response = request.sendAsync(null).get(30, TimeUnit.SECONDS); |
| 105 | + |
| 106 | + assertEquals(expectedResponseBody, StreamUtils.getStreamContents(response.getStream())); |
| 107 | + |
| 108 | + RecordedRequest recordedRequest = server.takeRequest(); |
| 109 | + assertEquals("GET", recordedRequest.getMethod()); |
| 110 | + |
| 111 | + server.shutdown(); |
| 112 | + } |
87 | 113 | } |
0 commit comments