use of com.google.mockwebserver.MockResponse in project j2objc by google.
the class URLConnectionTest method testConnectViaProxy.
// JVM failure.
// public void testGetResponseCodeNoResponseBody() throws Exception {
// server.enqueue(new MockResponse()
// .addHeader("abc: def"));
// server.play();
//
// URL url = server.getUrl("/");
// HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// conn.setDoInput(false);
// assertEquals("def", conn.getHeaderField("abc"));
// assertEquals(200, conn.getResponseCode());
// try {
// conn.getInputStream();
// fail();
// } catch (ProtocolException expected) {
// }
// }
// TODO(tball): b/28067294
// public void testConnectViaProxyUsingProxyArg() throws Exception {
// testConnectViaProxy(ProxyConfig.CREATE_ARG);
// }
// TODO(tball): b/28067294
// public void testConnectViaProxyUsingProxySystemProperty() throws Exception {
// testConnectViaProxy(ProxyConfig.PROXY_SYSTEM_PROPERTY);
// }
private void testConnectViaProxy(ProxyConfig proxyConfig) throws Exception {
MockResponse mockResponse = new MockResponse().setBody("this response comes via a proxy");
server.enqueue(mockResponse);
server.play();
URL url = new URL("http://android.com/foo");
HttpURLConnection connection = proxyConfig.connect(server, url);
assertContent("this response comes via a proxy", connection);
RecordedRequest request = server.takeRequest();
assertEquals("GET http://android.com/foo HTTP/1.1", request.getRequestLine());
assertContains(request.getHeaders(), "Host: android.com");
}
use of com.google.mockwebserver.MockResponse in project j2objc by google.
the class URLConnectionTest method testMarkAndReset.
// JVM failure.
// public void testMarkAndResetWithNoLengthHeaders() throws IOException {
// testMarkAndReset(TransferKind.END_OF_STREAM);
// }
private void testMarkAndReset(TransferKind transferKind) throws IOException {
MockResponse response = new MockResponse();
transferKind.setBody(response, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1024);
server.enqueue(response);
server.enqueue(response);
server.play();
InputStream in = server.getUrl("/").openConnection().getInputStream();
assertFalse("This implementation claims to support mark().", in.markSupported());
in.mark(5);
assertEquals("ABCDE", readAscii(in, 5));
try {
in.reset();
fail();
} catch (IOException expected) {
}
assertEquals("FGHIJKLMNOPQRSTUVWXYZ", readAscii(in, Integer.MAX_VALUE));
assertContent("ABCDEFGHIJKLMNOPQRSTUVWXYZ", server.getUrl("/").openConnection());
}
use of com.google.mockwebserver.MockResponse in project j2objc by google.
the class URLConnectionTest method testInputStreamAvailable.
private void testInputStreamAvailable(TransferKind transferKind) throws IOException {
String body = "ABCDEFGH";
MockResponse response = new MockResponse();
transferKind.setBody(response, body, 4);
server.enqueue(response);
server.play();
URLConnection connection = server.getUrl("/").openConnection();
InputStream in = connection.getInputStream();
for (int i = 0; i < body.length(); i++) {
assertTrue(in.available() >= 0);
assertEquals(body.charAt(i), in.read());
}
assertEquals(0, in.available());
assertEquals(-1, in.read());
}
use of com.google.mockwebserver.MockResponse in project j2objc by google.
the class URLConnectionTest method testGetContentLengthConnects.
public void testGetContentLengthConnects() throws Exception {
server.enqueue(new MockResponse().setBody("ABC"));
server.play();
HttpURLConnection connection = (HttpURLConnection) server.getUrl("/").openConnection();
assertEquals(3, connection.getContentLength());
connection.disconnect();
}
use of com.google.mockwebserver.MockResponse in project j2objc by google.
the class URLConnectionTest method testNotRedirectedFromHttpToHttps.
public void testNotRedirectedFromHttpToHttps() throws IOException, InterruptedException {
server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_MOVED_TEMP).addHeader("Location: https://anyhost/foo").setBody("This page has moved!"));
server.play();
HttpURLConnection connection = (HttpURLConnection) server.getUrl("/").openConnection();
assertEquals("This page has moved!", readAscii(connection.getInputStream(), Integer.MAX_VALUE));
}
Aggregations