Search in sources :

Example 21 with HttpCookie

use of java.net.HttpCookie in project robovm by robovm.

the class CookiesTest method testCookieStoreRemoveRequiresUri.

public void testCookieStoreRemoveRequiresUri() throws URISyntaxException {
    CookieStore cookieStore = new CookieManager().getCookieStore();
    HttpCookie cookieA = new HttpCookie("a", "android");
    cookieStore.add(new URI("http://android.com/source/"), cookieA);
    assertFalse(// RI6 fails this
    "Expected remove() to take the cookie URI into account.", cookieStore.remove(new URI("http://code.google.com/"), cookieA));
    assertEquals(Arrays.asList(cookieA), cookieStore.getCookies());
}
Also used : CookieStore(java.net.CookieStore) HttpCookie(java.net.HttpCookie) URI(java.net.URI) CookieManager(java.net.CookieManager)

Example 22 with HttpCookie

use of java.net.HttpCookie in project robovm by robovm.

the class CookiesTest method testResponseWithMultipleCookieHeaderLines.

public void testResponseWithMultipleCookieHeaderLines() throws Exception {
    TestCookieStore cookieStore = new TestCookieStore();
    CookieManager cookieManager = new CookieManager(cookieStore, ACCEPT_ORIGINAL_SERVER);
    cookieManager.put(new URI("http://android.com"), cookieHeaders("a=android", "b=banana"));
    List<HttpCookie> cookies = sortedCopy(cookieStore.cookies);
    assertEquals(2, cookies.size());
    HttpCookie cookieA = cookies.get(0);
    assertEquals("a", cookieA.getName());
    assertEquals("android", cookieA.getValue());
    HttpCookie cookieB = cookies.get(1);
    assertEquals("b", cookieB.getName());
    assertEquals("banana", cookieB.getValue());
}
Also used : URI(java.net.URI) HttpCookie(java.net.HttpCookie) CookieManager(java.net.CookieManager)

Example 23 with HttpCookie

use of java.net.HttpCookie in project robovm by robovm.

the class CookiesTest method testCookieStoreAddAcceptsConflictingUri.

public void testCookieStoreAddAcceptsConflictingUri() throws URISyntaxException {
    CookieStore cookieStore = new CookieManager().getCookieStore();
    HttpCookie cookieA = new HttpCookie("a", "android");
    cookieA.setDomain(".android.com");
    cookieA.setPath("/source/");
    cookieStore.add(new URI("http://google.com/source/"), cookieA);
    assertEquals(Arrays.asList(cookieA), cookieStore.getCookies());
}
Also used : CookieStore(java.net.CookieStore) HttpCookie(java.net.HttpCookie) URI(java.net.URI) CookieManager(java.net.CookieManager)

Example 24 with HttpCookie

use of java.net.HttpCookie in project robovm by robovm.

the class CookiesTest method testRfc2109Response.

public void testRfc2109Response() 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-Cookie: a=android; " + "Comment=this cookie is delicious; " + "Domain=" + server.getCookieDomain() + "; " + "Max-Age=60; " + "Path=/path; " + "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(null, cookie.getCommentURL());
        assertEquals(false, cookie.getDiscard());
        assertEquals(server.getCookieDomain(), cookie.getDomain());
        assertEquals(60, cookie.getMaxAge());
        assertEquals("/path", cookie.getPath());
        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 25 with HttpCookie

use of java.net.HttpCookie in project robovm by robovm.

the class CookiesTest method testCookieStoreUriUsesHttpSchemeAlways.

public void testCookieStoreUriUsesHttpSchemeAlways() throws URISyntaxException {
    CookieStore cookieStore = new CookieManager().getCookieStore();
    cookieStore.add(new URI("https://a.com/"), new HttpCookie("a", "android"));
    assertEquals(Arrays.asList(new URI("http://a.com")), cookieStore.getURIs());
}
Also used : CookieStore(java.net.CookieStore) URI(java.net.URI) HttpCookie(java.net.HttpCookie) CookieManager(java.net.CookieManager)

Aggregations

HttpCookie (java.net.HttpCookie)148 CookieManager (java.net.CookieManager)49 CookieStore (java.net.CookieStore)33 URI (java.net.URI)31 Test (org.junit.Test)31 IOException (java.io.IOException)14 Test (org.testng.annotations.Test)13 MockResponse (com.google.mockwebserver.MockResponse)11 MockWebServer (com.google.mockwebserver.MockWebServer)11 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Project (com.kickstarter.models.Project)5 RestResponse (com.linkedin.r2.message.rest.RestResponse)5 URL (java.net.URL)5 Cookie (javax.servlet.http.Cookie)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 MockResponse (okhttp3.mockwebserver.MockResponse)5 MockWebServer (okhttp3.mockwebserver.MockWebServer)5 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)5