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);
}
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");
}
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();
}
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());
}
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());
}
Aggregations