Search in sources :

Example 11 with MockWebServer

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

the class CookiesTest method testQuotedAttributeValues.

public void testQuotedAttributeValues() throws Exception {
    CookieManager cookieManager = new CookieManager(null, ACCEPT_ORIGINAL_SERVER);
    CookieHandler.setDefault(cookieManager);
    MockWebServer server = new MockWebServer();
    try {
        // RoboVM note: Modified to call server.shutdown() after test finishes.
        server.play();
        server.enqueue(new MockResponse().addHeader("Set-Cookie2: a=\"android\"; " + "Comment=\"this cookie is delicious\"; " + "CommentURL=\"http://google.com/\"; " + "Discard; " + "Domain=\"" + server.getCookieDomain() + "\"; " + "Max-Age=\"60\"; " + "Path=\"/path\"; " + "Port=\"80,443," + server.getPort() + "\"; " + "Secure; " + "Version=\"1\""));
        get(server, "/path/foo");
        List<HttpCookie> cookies = cookieManager.getCookieStore().getCookies();
        assertEquals(1, cookies.size());
        HttpCookie cookie = cookies.get(0);
        assertEquals("a", cookie.getName());
        assertEquals("android", cookie.getValue());
        assertEquals("this cookie is delicious", cookie.getComment());
        assertEquals("http://google.com/", cookie.getCommentURL());
        assertEquals(true, cookie.getDiscard());
        assertEquals(server.getCookieDomain(), cookie.getDomain());
        assertEquals(60, cookie.getMaxAge());
        assertEquals("/path", cookie.getPath());
        assertEquals("80,443," + server.getPort(), cookie.getPortlist());
        assertEquals(true, cookie.getSecure());
        assertEquals(1, cookie.getVersion());
    } finally {
        server.shutdown();
    }
}
Also used : MockResponse(com.google.mockwebserver.MockResponse) MockWebServer(com.google.mockwebserver.MockWebServer) HttpCookie(java.net.HttpCookie) CookieManager(java.net.CookieManager)

Example 12 with MockWebServer

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

the class URLConnectionTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    server = new MockWebServer();
    hostName = server.getHostName();
}
Also used : MockWebServer(com.google.mockwebserver.MockWebServer)

Example 13 with MockWebServer

use of com.google.mockwebserver.MockWebServer in project platform_frameworks_base by android.

the class DownloadManagerBaseTest method setUp.

/**
     * {@inheritDoc}
     */
@Override
public void setUp() throws Exception {
    mContext = getInstrumentation().getContext();
    mDownloadManager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
    mServer = new MockWebServer();
    mServer.play();
    mReceiver = registerNewMultipleDownloadsReceiver();
// Note: callers overriding this should call mServer.play() with the desired port #
}
Also used : MockWebServer(com.google.mockwebserver.MockWebServer)

Example 14 with MockWebServer

use of com.google.mockwebserver.MockWebServer in project platform_frameworks_base by android.

the class DefaultHttpClientTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    server = new MockWebServer();
}
Also used : MockWebServer(com.google.mockwebserver.MockWebServer)

Example 15 with MockWebServer

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

the class CookiesTest method testNetscapeResponse.

public void testNetscapeResponse() throws Exception {
    CookieManager cookieManager = new CookieManager(null, ACCEPT_ORIGINAL_SERVER);
    CookieHandler.setDefault(cookieManager);
    MockWebServer server = new MockWebServer();
    server.play();
    server.enqueue(new MockResponse().addHeader("Set-Cookie: a=android; " + "expires=Fri, 31-Dec-9999 23:59:59 GMT; " + "path=/path; " + "domain=" + server.getCookieDomain() + "; " + "secure"));
    get(server, "/path/foo");
    List<HttpCookie> cookies = cookieManager.getCookieStore().getCookies();
    assertEquals(1, cookies.size());
    HttpCookie cookie = cookies.get(0);
    assertEquals("a", cookie.getName());
    assertEquals("android", cookie.getValue());
    assertEquals(null, cookie.getComment());
    assertEquals(null, cookie.getCommentURL());
    assertEquals(false, cookie.getDiscard());
    assertEquals(server.getCookieDomain(), cookie.getDomain());
    assertTrue(cookie.getMaxAge() > 100000000000L);
    assertEquals("/path", cookie.getPath());
    assertEquals(true, cookie.getSecure());
    assertEquals(0, cookie.getVersion());
}
Also used : MockResponse(com.google.mockwebserver.MockResponse) MockWebServer(com.google.mockwebserver.MockWebServer) HttpCookie(java.net.HttpCookie) CookieManager(java.net.CookieManager)

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