Search in sources :

Example 16 with MockResponse

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

the class CacheWrapperTest method shouldAffectCoreCache.

@Test
public void shouldAffectCoreCache() throws Exception {
    final String text = "ABC";
    getWebServer().enqueue(new MockResponse().setBody(text));
    InputStream stream = new UrlConnectionBuilder().setCacheManagerName("cacheWrapper").setUrl(getWebServer().getUrl("/")).create().getInputStream();
    IoUtils.consumeStream(stream, BeansManager.get(getApplication()).getContainer().getBean(BuffersPool.class));
    // cache entry has been written to the CORE cache
    assertThat(cache.getWriteSuccessCount()).isEqualTo(1);
    assertThat(cache.getHitCount()).isZero();
    // we can read from cache
    stream = new UrlConnectionBuilder().setCacheManagerName("cacheWrapper").setUrl(getWebServer().getUrl("/")).create().getInputStream();
    final String response = IoUtils.streamToString(stream, null);
    assertThat(response).isEqualTo(text);
    assertThat(cache.getWriteSuccessCount()).isEqualTo(1);
    assertThat(cache.getHitCount()).isEqualTo(1);
}
Also used : UrlConnectionBuilder(com.stanfy.enroscar.net.UrlConnectionBuilder) MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) BuffersPool(com.stanfy.enroscar.io.BuffersPool) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 17 with MockResponse

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

the class RequestDescriptionTest method makeGetConnectionShouldReceiveCorrectResponse.

@Test
public void makeGetConnectionShouldReceiveCorrectResponse() throws Exception {
    getWebServer().enqueue(new MockResponse().setBody("test response"));
    final URLConnection connection = makeConnection(new MyRequestBuilder<String>(Robolectric.application) {
    }.setUrl(getWebServer().getUrl("/r1").toString()));
    assertThat(ResponseCache.getDefault()).isNull();
    final String response = read(connection);
    getWebServer().takeRequest();
    final HttpURLConnection http = (HttpURLConnection) UrlConnectionWrapper.unwrap(connection);
    assertThat(http.getResponseCode()).isEqualTo(HttpURLConnection.HTTP_OK);
    assertThat(response).isEqualTo("test response");
}
Also used : MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) HttpURLConnection(java.net.HttpURLConnection) HttpURLConnection(java.net.HttpURLConnection) URLConnection(java.net.URLConnection) Test(org.junit.Test) AbstractMockServerTest(com.stanfy.enroscar.net.test.AbstractMockServerTest)

Example 18 with MockResponse

use of com.squareup.okhttp.mockwebserver.MockResponse 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)

Example 19 with MockResponse

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

the class TestGetFileStatus method getFileStatusReturnsAsExpected.

@Test
public void getFileStatusReturnsAsExpected() throws URISyntaxException, IOException {
    getMockServer().enqueue(new MockResponse().setResponseCode(200).setBody(TestADLResponseData.getGetFileStatusJSONResponse()));
    long startTime = Time.monotonicNow();
    FileStatus fileStatus = getMockAdlFileSystem().getFileStatus(new Path("/test1/test2"));
    long endTime = Time.monotonicNow();
    LOG.debug("Time : " + (endTime - startTime));
    Assert.assertTrue(fileStatus.isFile());
    Assert.assertEquals("adl://" + getMockServer().getHostName() + ":" + getMockServer().getPort() + "/test1/test2", fileStatus.getPath().toString());
    Assert.assertEquals(4194304, fileStatus.getLen());
    Assert.assertEquals(ADL_BLOCK_SIZE, fileStatus.getBlockSize());
    Assert.assertEquals(1, fileStatus.getReplication());
    Assert.assertEquals(new FsPermission("777"), fileStatus.getPermission());
    Assert.assertEquals("NotSupportYet", fileStatus.getOwner());
    Assert.assertEquals("NotSupportYet", fileStatus.getGroup());
}
Also used : Path(org.apache.hadoop.fs.Path) MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) FileStatus(org.apache.hadoop.fs.FileStatus) FsPermission(org.apache.hadoop.fs.permission.FsPermission) Test(org.junit.Test)

Example 20 with MockResponse

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

the class TestGetFileStatus method getFileStatusAclBit.

@Test
public void getFileStatusAclBit() throws URISyntaxException, IOException {
    // With ACLBIT set to true
    getMockServer().enqueue(new MockResponse().setResponseCode(200).setBody(TestADLResponseData.getGetFileStatusJSONResponse(true)));
    long startTime = Time.monotonicNow();
    FileStatus fileStatus = getMockAdlFileSystem().getFileStatus(new Path("/test1/test2"));
    long endTime = Time.monotonicNow();
    LOG.debug("Time : " + (endTime - startTime));
    Assert.assertTrue(fileStatus.isFile());
    Assert.assertEquals(true, fileStatus.getPermission().getAclBit());
    // With ACLBIT set to false
    getMockServer().enqueue(new MockResponse().setResponseCode(200).setBody(TestADLResponseData.getGetFileStatusJSONResponse(false)));
    startTime = Time.monotonicNow();
    fileStatus = getMockAdlFileSystem().getFileStatus(new Path("/test1/test2"));
    endTime = Time.monotonicNow();
    LOG.debug("Time : " + (endTime - startTime));
    Assert.assertTrue(fileStatus.isFile());
    Assert.assertEquals(false, fileStatus.getPermission().getAclBit());
}
Also used : Path(org.apache.hadoop.fs.Path) MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) FileStatus(org.apache.hadoop.fs.FileStatus) Test(org.junit.Test)

Aggregations

MockResponse (com.squareup.okhttp.mockwebserver.MockResponse)39 Test (org.junit.Test)34 Path (org.apache.hadoop.fs.Path)18 MockWebServer (com.squareup.okhttp.mockwebserver.MockWebServer)10 FileStatus (org.apache.hadoop.fs.FileStatus)6 AclEntry (org.apache.hadoop.fs.permission.AclEntry)5 RecordedRequest (com.squareup.okhttp.mockwebserver.RecordedRequest)4 AbstractMockServerTest (com.stanfy.enroscar.net.test.AbstractMockServerTest)4 ArrayList (java.util.ArrayList)4 Buffer (okio.Buffer)4 HttpUrl (com.squareup.okhttp.HttpUrl)3 URL (java.net.URL)3 URLConnection (java.net.URLConnection)3 Request (com.squareup.okhttp.Request)2 Response (com.squareup.okhttp.Response)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HttpURLConnection (java.net.HttpURLConnection)2 URI (java.net.URI)2