use of okhttp3.mockwebserver.MockResponse in project okhttp by square.
the class OkApacheClientTest method postOverrideContentType.
@Test
public void postOverrideContentType() throws Exception {
server.enqueue(new MockResponse());
HttpPost httpPost = new HttpPost();
httpPost.setURI(server.url("/").url().toURI());
httpPost.addHeader("Content-Type", "application/xml");
httpPost.setEntity(new StringEntity("<yo/>"));
client.execute(httpPost);
RecordedRequest request = server.takeRequest();
assertEquals(request.getHeader("Content-Type"), "application/xml");
}
use of okhttp3.mockwebserver.MockResponse in project okhttp by square.
the class ResponseCacheTest method clientSuppliedIfModifiedSinceWithCachedResult.
@Test
public void clientSuppliedIfModifiedSinceWithCachedResult() throws Exception {
MockResponse response = new MockResponse().addHeader("ETag: v3").addHeader("Cache-Control: max-age=0");
String ifModifiedSinceDate = formatDate(-24, TimeUnit.HOURS);
RecordedRequest request = assertClientSuppliedCondition(response, "If-Modified-Since", ifModifiedSinceDate);
assertEquals(ifModifiedSinceDate, request.getHeader("If-Modified-Since"));
assertNull(request.getHeader("If-None-Match"));
}
use of okhttp3.mockwebserver.MockResponse in project okhttp by square.
the class ResponseCacheTest method clientSuppliedIfNoneMatchSinceWithCachedResult.
@Test
public void clientSuppliedIfNoneMatchSinceWithCachedResult() throws Exception {
String lastModifiedDate = formatDate(-3, TimeUnit.MINUTES);
MockResponse response = new MockResponse().addHeader("Last-Modified: " + lastModifiedDate).addHeader("Date: " + formatDate(-2, TimeUnit.MINUTES)).addHeader("Cache-Control: max-age=0");
RecordedRequest request = assertClientSuppliedCondition(response, "If-None-Match", "v1");
assertEquals("v1", request.getHeader("If-None-Match"));
assertNull(request.getHeader("If-Modified-Since"));
}
use of okhttp3.mockwebserver.MockResponse in project okhttp by square.
the class ResponseCacheTest method varyMatchesAddedRequestHeaderField.
@Test
public void varyMatchesAddedRequestHeaderField() throws Exception {
server.enqueue(new MockResponse().addHeader("Cache-Control: max-age=60").addHeader("Vary: Foo").setBody("A"));
server.enqueue(new MockResponse().setBody("B"));
assertEquals("A", readAscii(openConnection(server.url("/").url())));
HttpURLConnection connection2 = openConnection(server.url("/").url());
connection2.setRequestProperty("Foo", "bar");
assertEquals("B", readAscii(connection2));
}
use of okhttp3.mockwebserver.MockResponse in project okhttp by square.
the class ResponseCacheTest method useCachesFalseDoesNotWriteToCache.
@Test
public void useCachesFalseDoesNotWriteToCache() throws Exception {
server.enqueue(new MockResponse().addHeader("Cache-Control: max-age=60").setBody("A"));
server.enqueue(new MockResponse().setBody("B"));
URLConnection connection = openConnection(server.url("/").url());
connection.setUseCaches(false);
assertEquals("A", readAscii(connection));
assertEquals("B", readAscii(openConnection(server.url("/").url())));
}
Aggregations