Search in sources :

Example 56 with MockWebServer

use of com.google.mockwebserver.MockWebServer in project j2objc by google.

the class URLConnectionTest method testRedirectToAnotherOriginServer.

public void testRedirectToAnotherOriginServer() throws Exception {
    MockWebServer server2 = new MockWebServer();
    server2.enqueue(new MockResponse().setBody("This is the 2nd server!"));
    server2.play();
    server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_MOVED_TEMP).addHeader("Location: " + server2.getUrl("/").toString()).setBody("This page has moved!"));
    server.enqueue(new MockResponse().setBody("This is the first server again!"));
    server.play();
    URLConnection connection = server.getUrl("/").openConnection();
    assertEquals("This is the 2nd server!", readAscii(connection.getInputStream(), Integer.MAX_VALUE));
    assertEquals(server2.getUrl("/"), connection.getURL());
    // make sure the first server was careful to recycle the connection
    assertEquals("This is the first server again!", readAscii(server.getUrl("/").openStream(), Integer.MAX_VALUE));
    RecordedRequest first = server.takeRequest();
    assertContains(first.getHeaders(), "Host: " + hostName + ":" + server.getPort());
    RecordedRequest second = server2.takeRequest();
    assertContains(second.getHeaders(), "Host: " + hostName + ":" + server2.getPort());
    RecordedRequest third = server.takeRequest();
    // assertEquals("Expected connection reuse", 1, third.getSequenceNumber()); // JVM failure
    server2.shutdown();
}
Also used : RecordedRequest(com.google.mockwebserver.RecordedRequest) MockResponse(com.google.mockwebserver.MockResponse) MockWebServer(com.google.mockwebserver.MockWebServer) HttpURLConnection(java.net.HttpURLConnection) URLConnection(java.net.URLConnection) HttpsURLConnection(javax.net.ssl.HttpsURLConnection)

Aggregations

MockWebServer (com.google.mockwebserver.MockWebServer)56 MockResponse (com.google.mockwebserver.MockResponse)39 CookieManager (java.net.CookieManager)15 RecordedRequest (com.google.mockwebserver.RecordedRequest)14 Test (org.junit.Test)14 ByteBuf (io.netty.buffer.ByteBuf)13 HttpCookie (java.net.HttpCookie)11 BaseLoadBalancer (com.netflix.loadbalancer.BaseLoadBalancer)7 Server (com.netflix.loadbalancer.Server)7 IClientConfig (com.netflix.client.config.IClientConfig)6 AvailabilityFilteringRule (com.netflix.loadbalancer.AvailabilityFilteringRule)6 DummyPing (com.netflix.loadbalancer.DummyPing)6 HttpResourceGroup (com.netflix.ribbon.http.HttpResourceGroup)6 IOException (java.io.IOException)6 HttpHost (org.apache.http.HttpHost)6 HttpResponse (org.apache.http.HttpResponse)6 HttpClient (org.apache.http.client.HttpClient)6 HttpGet (org.apache.http.client.methods.HttpGet)6 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)6 Map (java.util.Map)5