use of okhttp3.mockwebserver.MockWebServer in project glide by bumptech.
the class VolleyStreamFetcherServerTest method setUp.
@Before
public void setUp() throws IOException {
MockitoAnnotations.initMocks(this);
waitForResponseLatch = new CountDownLatch(1);
doAnswer(new CountDown()).when(callback).onDataReady(any(InputStream.class));
doAnswer(new CountDown()).when(callback).onLoadFailed(any(Exception.class));
requestQueue = Volley.newRequestQueue(RuntimeEnvironment.application);
mockWebServer = new MockWebServer();
mockWebServer.start();
streamCaptor = ArgumentCaptor.forClass(InputStream.class);
}
use of okhttp3.mockwebserver.MockWebServer in project stetho by facebook.
the class StethoInterceptorTest method testWithRequestCompression.
@Test
public void testWithRequestCompression() throws IOException {
AtomicReference<NetworkEventReporter.InspectorRequest> capturedRequest = hookAlmostRealRequestWillBeSent(mMockEventReporter);
MockWebServer server = new MockWebServer();
server.start();
server.enqueue(new MockResponse().setBody("Success!"));
final byte[] decompressed = "Request text".getBytes();
final byte[] compressed = compress(decompressed);
assertNotEquals("Bogus test: decompressed and compressed lengths match", compressed.length, decompressed.length);
RequestBody compressedBody = RequestBody.create(MediaType.parse("text/plain"), compress(decompressed));
Request request = new Request.Builder().url(server.url("/")).addHeader("Content-Encoding", "gzip").post(compressedBody).build();
Response response = mClientWithInterceptor.newCall(request).execute();
// Force a read to complete the flow.
response.body().string();
assertArrayEquals(decompressed, capturedRequest.get().body());
Mockito.verify(mMockEventReporter).dataSent(anyString(), eq(decompressed.length), eq(compressed.length));
server.shutdown();
}
use of okhttp3.mockwebserver.MockWebServer in project stetho by facebook.
the class StethoInterceptorTest method testWithResponseCompression.
@Test
public void testWithResponseCompression() throws IOException {
ByteArrayOutputStream capturedOutput = hookAlmostRealInterpretResponseStream(mMockEventReporter);
byte[] uncompressedData = repeat(".", 1024).getBytes();
byte[] compressedData = compress(uncompressedData);
MockWebServer server = new MockWebServer();
server.start();
server.enqueue(new MockResponse().setBody(new Buffer().write(compressedData)).addHeader("Content-Encoding: gzip"));
Request request = new Request.Builder().url(server.url("/")).build();
Response response = mClientWithInterceptor.newCall(request).execute();
// Verify that the final output and the caller both saw the uncompressed stream.
assertArrayEquals(uncompressedData, response.body().bytes());
assertArrayEquals(uncompressedData, capturedOutput.toByteArray());
// And verify that the StethoInterceptor was able to see both.
Mockito.verify(mMockEventReporter).dataReceived(anyString(), eq(compressedData.length), eq(uncompressedData.length));
server.shutdown();
}
use of okhttp3.mockwebserver.MockWebServer in project sonarqube by SonarSource.
the class HttpConnectorTest method setUp.
@Before
public void setUp() throws Exception {
server = new MockWebServer();
server.start();
serverUrl = server.url("").url().toString();
}
use of okhttp3.mockwebserver.MockWebServer in project scribejava by scribejava.
the class OkHttpHttpClientTest method shouldReadResponseStream.
@Test
public void shouldReadResponseStream() throws Exception {
final String expectedResponseBody = "response body";
final MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse().setBody(expectedResponseBody));
server.start();
final HttpUrl baseUrl = server.url("/testUrl");
final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString());
final Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS);
assertEquals(expectedResponseBody, StreamUtils.getStreamContents(response.getStream()));
final RecordedRequest recordedRequest = server.takeRequest();
assertEquals("GET", recordedRequest.getMethod());
server.shutdown();
}
Aggregations