Search in sources :

Example 11 with CookieManager

use of java.net.CookieManager 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 12 with CookieManager

use of java.net.CookieManager 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 13 with CookieManager

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

the class CookiesTest method testCookiesSentIgnoresCase.

public void testCookiesSentIgnoresCase() throws Exception {
    CookieHandler.setDefault(new CookieManager() {

        @Override
        public Map<String, List<String>> get(URI uri, Map<String, List<String>> requestHeaders) throws IOException {
            Map<String, List<String>> result = new HashMap<String, List<String>>();
            result.put("COOKIE", Collections.singletonList("Bar=bar"));
            result.put("cooKIE2", Collections.singletonList("Baz=baz"));
            return result;
        }
    });
    MockWebServer server = new MockWebServer();
    try {
        // RoboVM note: Modified to call server.shutdown() after test finishes.
        server.enqueue(new MockResponse());
        server.play();
        get(server, "/");
        RecordedRequest request = server.takeRequest();
        assertContainsAll(request.getHeaders(), "COOKIE: Bar=bar", "cooKIE2: Baz=baz");
        assertFalse(request.getHeaders().contains("Quux: quux"));
    } finally {
        server.shutdown();
    }
}
Also used : RecordedRequest(com.google.mockwebserver.RecordedRequest) MockResponse(com.google.mockwebserver.MockResponse) MockWebServer(com.google.mockwebserver.MockWebServer) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) URI(java.net.URI) HashMap(java.util.HashMap) Map(java.util.Map) CookieManager(java.net.CookieManager)

Example 14 with CookieManager

use of java.net.CookieManager 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)

Example 15 with CookieManager

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

the class CookiesTest method testCookieStoreUriDropsQuery.

public void testCookieStoreUriDropsQuery() throws URISyntaxException {
    CookieStore cookieStore = new CookieManager().getCookieStore();
    cookieStore.add(new URI("http://a.com/a/foo?query=value"), 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

CookieManager (java.net.CookieManager)162 URI (java.net.URI)89 HttpCookie (java.net.HttpCookie)82 CookieStore (java.net.CookieStore)49 MockResponse (com.google.mockwebserver.MockResponse)20 List (java.util.List)20 ArrayList (java.util.ArrayList)18 MockWebServer (com.google.mockwebserver.MockWebServer)15 IOException (java.io.IOException)13 HashMap (java.util.HashMap)12 Test (org.junit.jupiter.api.Test)12 Test (org.junit.Test)11 RecordedRequest (com.google.mockwebserver.RecordedRequest)8 MockResponse (mockwebserver3.MockResponse)8 LinkedHashMap (java.util.LinkedHashMap)7 Map (java.util.Map)7 HttpURLConnection (java.net.HttpURLConnection)6 URL (java.net.URL)6 RecordedRequest (mockwebserver3.RecordedRequest)5 JavaNetCookieJar (okhttp3.JavaNetCookieJar)4