From 7f4d253579f7252dbd610eca5bfb9c12ac94a8d5 Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Mon, 6 May 2013 16:53:17 -0700 Subject: [PATCH 1/3] Add some tests for the Apache wrapper. --- okhttp-apache/pom.xml | 11 +++ .../okhttp/apache/OkApacheClientTest.java | 71 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 okhttp-apache/src/test/java/com/squareup/okhttp/apache/OkApacheClientTest.java diff --git a/okhttp-apache/pom.xml b/okhttp-apache/pom.xml index d6df7ab40416..712fb5e9e609 100644 --- a/okhttp-apache/pom.xml +++ b/okhttp-apache/pom.xml @@ -23,5 +23,16 @@ httpclient provided + + + junit + junit + test + + + com.google.mockwebserver + mockwebserver + test + diff --git a/okhttp-apache/src/test/java/com/squareup/okhttp/apache/OkApacheClientTest.java b/okhttp-apache/src/test/java/com/squareup/okhttp/apache/OkApacheClientTest.java new file mode 100644 index 000000000000..4356d5eec572 --- /dev/null +++ b/okhttp-apache/src/test/java/com/squareup/okhttp/apache/OkApacheClientTest.java @@ -0,0 +1,71 @@ +package com.squareup.okhttp.apache; + +import com.google.mockwebserver.MockResponse; +import com.google.mockwebserver.MockWebServer; +import java.io.IOException; +import org.apache.http.Header; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.util.EntityUtils; +import org.junit.After; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class OkApacheClientTest { + private MockWebServer server = new MockWebServer(); + private OkApacheClient client = new OkApacheClient(); + + @After public void tearDown() throws IOException { + server.shutdown(); + } + + @Test public void success() throws Exception { + server.enqueue(new MockResponse().setBody("Hello, World!")); + server.play(); + + HttpGet request = new HttpGet(server.getUrl("/").toURI()); + HttpResponse response = client.execute(request); + String actual = EntityUtils.toString(response.getEntity()); + assertEquals("Hello, World!", actual); + } + + @Test public void redirect() throws Exception { + server.enqueue(new MockResponse().setResponseCode(302).addHeader("Location", "/foo")); + server.enqueue(new MockResponse().setBody("Hello, Redirect!")); + server.play(); + + HttpGet request = new HttpGet(server.getUrl("/").toURI()); + HttpResponse response = client.execute(request); + String actual = EntityUtils.toString(response.getEntity()); + assertEquals("Hello, Redirect!", actual); + } + + @Test public void sessionExpired() throws Exception { + server.enqueue(new MockResponse().setResponseCode(422)); + server.play(); + + HttpGet request = new HttpGet(server.getUrl("/").toURI()); + HttpResponse response = client.execute(request); + assertEquals(422, response.getStatusLine().getStatusCode()); + } + + @Test public void headers() throws Exception { + server.enqueue(new MockResponse().addHeader("Foo", "Bar")); + server.enqueue(new MockResponse().addHeader("Foo", "Bar").addHeader("Foo", "Baz")); + server.play(); + + HttpGet request1 = new HttpGet(server.getUrl("/").toURI()); + HttpResponse response1 = client.execute(request1); + Header[] headers1 = response1.getHeaders("Foo"); + assertEquals(1, headers1.length); + assertEquals("Bar", headers1[0].getValue()); + + HttpGet request2 = new HttpGet(server.getUrl("/").toURI()); + HttpResponse response2 = client.execute(request2); + Header[] headers2 = response2.getHeaders("Foo"); + assertEquals(2, headers2.length); + assertEquals("Bar", headers2[0].getValue()); + assertEquals("Baz", headers2[1].getValue()); + } +} From fcf3264d4d35a97990881e1f0918be284168077a Mon Sep 17 00:00:00 2001 From: jwilson Date: Tue, 7 May 2013 01:13:17 -0400 Subject: [PATCH 2/3] Link to the new OkHttp website. --- README.md | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index e7210539a902..e206f237ecd2 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,16 @@ OkHttp ====== -An HTTP+SPDY client for Android and Java applications. +An HTTP & SPDY client for Android and Java applications. + +For more information please see [the website][1]. + Download -------- -Download [the latest JAR][1] or grab via Maven: +Download [the latest JAR][2] or grab via Maven: ```xml @@ -18,18 +21,6 @@ Download [the latest JAR][1] or grab via Maven: ``` -Known Issues ------------- - -OkHttp uses the platform's [ProxySelector][2]. Prior to Android 4.0, `ProxySelector` didn't honor -the `proxyHost` and `proxyPort` system properties for HTTPS connections. Work around this by -specifying the `https.proxyHost` and `https.proxyPort` system properties when using a proxy with -HTTPS. - -OkHttp's test suite creates an in-process HTTPS server. Prior to Android 2.3, SSL server sockets -were broken, and so HTTPS tests will time out when run on such devices. - - Building -------- @@ -44,6 +35,9 @@ mvn clean test ### On a Device +OkHttp's test suite creates an in-process HTTPS server. Prior to Android 2.3, SSL server sockets +were broken, and so HTTPS tests will time out when run on such devices. + Test on a USB-attached Android using [Vogar][4]. Unfortunately `dx` requires that you build with Java 6, otherwise the test class will be silently omitted from the `.dex` file. @@ -76,7 +70,7 @@ License - [1]: http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=com.squareup.okhttp&a=okhttp&v=LATEST - [2]: http://developer.android.com/reference/java/net/ProxySelector.html + [1]: http://square.github.io/okhttp + [2]: http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=com.squareup.okhttp&a=okhttp&v=LATEST [3]: http://wiki.eclipse.org/Jetty/Feature/NPN [4]: https://code.google.com/p/vogar/ From 5345c1ab20add48e164b893f833a95c76ab5da9d Mon Sep 17 00:00:00 2001 From: jwilson Date: Tue, 7 May 2013 11:20:02 -0400 Subject: [PATCH 3/3] Hide internal from Javadocs --- pom.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pom.xml b/pom.xml index 159b7128c453..92e262f7884c 100644 --- a/pom.xml +++ b/pom.xml @@ -146,6 +146,14 @@ + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9 + + com.squareup.okhttp.internal:com.squareup.okhttp.internal.* + +