Search in sources :

Example 1 with MockWebServer

use of com.squareup.okhttp.mockwebserver.MockWebServer in project hadoop by apache.

the class AdlMockWebServer method preTestSetup.

@Before
public void preTestSetup() throws IOException, URISyntaxException {
    server = new MockWebServer();
    // Start the server.
    server.start();
    // Ask the server for its URL. You'll need this to make HTTP requests.
    URL baseUrl = server.getUrl("");
    port = baseUrl.getPort();
    // Exercise your application code, which should make those HTTP requests.
    // Responses are returned in the same order that they are enqueued.
    fs = new TestableAdlFileSystem();
    conf.setClass(AZURE_AD_TOKEN_PROVIDER_CLASS_KEY, CustomMockTokenProvider.class, AzureADTokenProvider.class);
    URI uri = new URI("adl://localhost:" + port);
    fs.initialize(uri, conf);
}
Also used : MockWebServer(com.squareup.okhttp.mockwebserver.MockWebServer) URI(java.net.URI) URL(java.net.URL) Before(org.junit.Before)

Example 2 with MockWebServer

use of com.squareup.okhttp.mockwebserver.MockWebServer in project Avengers by saulmm.

the class CharacterListActivityInstrumentationTest method setUp.

@Before
public void setUp() throws Exception {
    mMockWebServer = new MockWebServer();
    mMockWebServer.start();
    RestDataSource.END_POINT = mMockWebServer.getUrl("/").toString();
}
Also used : MockWebServer(com.squareup.okhttp.mockwebserver.MockWebServer) Before(org.junit.Before)

Example 3 with MockWebServer

use of com.squareup.okhttp.mockwebserver.MockWebServer in project enroscar by stanfy.

the class ImageRequestAndroidTest method prepareServer.

private MockWebServer prepareServer() throws IOException {
    MockWebServer server = new MockWebServer();
    server.start();
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    testBitmap.compress(Bitmap.CompressFormat.PNG, 100, bytes);
    server.enqueue(new MockResponse().setResponseCode(200).setBody(new Buffer().write(bytes.toByteArray())));
    return server;
}
Also used : Buffer(okio.Buffer) MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) MockWebServer(com.squareup.okhttp.mockwebserver.MockWebServer) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 4 with MockWebServer

use of com.squareup.okhttp.mockwebserver.MockWebServer in project enroscar by stanfy.

the class ImageRequestAndroidTest method testStoreToDiskSmallRatio.

public void testStoreToDiskSmallRatio() throws IOException {
    MockWebServer server = prepareServer();
    String url = server.getUrl("/image").toString();
    //noinspection ConstantConditions
    float smallRatio = (float) testBitmap.getWidth() / getContext().getResources().getDisplayMetrics().widthPixels;
    ImageRequest request = new ImageRequest(imagesManager, url, smallRatio / 2);
    assertThat(imagesManager.isPresentOnDisk(url)).isFalse();
    request.storeToDisk();
    assertThat(imagesManager.isPresentOnDisk(url)).isTrue();
    server.shutdown();
}
Also used : MockWebServer(com.squareup.okhttp.mockwebserver.MockWebServer)

Example 5 with MockWebServer

use of com.squareup.okhttp.mockwebserver.MockWebServer in project enroscar by stanfy.

the class RetrofitClientTest method shouldWorkForHttpScheme.

// http
@Test
public void shouldWorkForHttpScheme() throws Exception {
    MockWebServer server = new MockWebServer();
    server.play();
    server.enqueue(new MockResponse().setResponseCode(200).setBody(mockResponse));
    RestAdapter adapter = getRestAdapter(server.getUrl("/").toString());
    fetchAndTest(adapter);
    server.shutdown();
}
Also used : MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) MockWebServer(com.squareup.okhttp.mockwebserver.MockWebServer) RestAdapter(retrofit.RestAdapter) Test(org.junit.Test)

Aggregations

MockWebServer (com.squareup.okhttp.mockwebserver.MockWebServer)13 MockResponse (com.squareup.okhttp.mockwebserver.MockResponse)6 Before (org.junit.Before)4 Test (org.junit.Test)4 Buffer (okio.Buffer)3 Request (com.squareup.okhttp.Request)2 Response (com.squareup.okhttp.Response)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Bitmap (android.graphics.Bitmap)1 RequestBody (com.squareup.okhttp.RequestBody)1 AbstractMockServerTest (com.stanfy.enroscar.net.test.AbstractMockServerTest)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 URL (java.net.URL)1 RestAdapter (retrofit.RestAdapter)1