use of com.squareup.okhttp.mockwebserver.MockResponse in project enroscar by stanfy.
the class CacheSwitcherTest method testCacheSwitching.
@Test
public void testCacheSwitching() throws IOException {
final String response1 = "<response to be cached by the FIRST testCache>";
final String response2 = "<response to be cached by the SECOND testCache>";
final MockWebServer webServer = getWebServer();
// two responses
webServer.enqueue(new MockResponse().setBody(response1));
webServer.enqueue(new MockResponse().setBody(response2));
// first request, first cache => not cached
perform("/1/", cache1, response1, false);
// second request, first cache => cached
perform("/1/", cache1, response1, true);
// first request, second cache => not cached
perform("/2/", cache2, response2, false);
// second request, second cache => cached
perform("/2/", cache2, response2, true);
}
use of com.squareup.okhttp.mockwebserver.MockResponse in project enroscar by stanfy.
the class RequestDescriptionTest method makeGetConnectionShouldSendGoodParametersAndHeaders.
@Test
public void makeGetConnectionShouldSendGoodParametersAndHeaders() throws Exception {
getWebServer().enqueue(new MockResponse().setBody("test response"));
read(makeConnection(new MyRequestBuilder<String>(Robolectric.application) {
}.setUrl(getWebServer().getUrl("/r1").toString()).addParam("p1", "v1").addParam("p2", "v2")));
// check that request was as expected
final RecordedRequest request = getWebServer().takeRequest();
// url
assertThat(request.getPath()).isEqualTo("/r1?p1=v1&p2=v2");
// headers: language, gzip
final String lang = Robolectric.application.getResources().getConfiguration().locale.getLanguage();
assertThat(request.getHeaders().toMultimap()).containsEntry("Accept-Language: " + lang, Collections.singletonList("Accept-Encoding: gzip"));
}
use of com.squareup.okhttp.mockwebserver.MockResponse in project enroscar by stanfy.
the class ImageRequestTest method startServer.
@Override
public void startServer() throws IOException {
super.startServer();
server.enqueue(new MockResponse().setResponseCode(200).setBody(""));
defaultUrl = server.getUrl("/").toString();
}
use of com.squareup.okhttp.mockwebserver.MockResponse in project enroscar by stanfy.
the class ImageRequestAndroidTest method testRealRemoteImage.
public void testRealRemoteImage() throws IOException {
MockWebServer server = new MockWebServer();
server.start();
final InputStream imageStream = getContext().getResources().getAssets().open("mustard.jpg");
final byte[] imageBytes = new byte[imageStream.available()];
assertThat(imageBytes.length).isNotZero();
imageStream.read(imageBytes);
IoUtils.closeQuietly(imageStream);
server.enqueue(new MockResponse().setResponseCode(200).setBody(new Buffer().write(imageBytes)));
String url = server.getUrl("/image").toString();
ImageRequest request = new ImageRequest(imagesManager, url, 1);
ImageResult result = request.readImage();
assertThat(result.getType()).isSameAs(ImageSourceType.NETWORK);
final Bitmap resultBitmap = result.getBitmap();
assertThat(resultBitmap).isNotNull();
}
Aggregations