Search in sources :

Example 6 with CookieManager

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

the class CookiesTest method testNoCookieHeaderSentIfNoCookiesMatch.

public void testNoCookieHeaderSentIfNoCookiesMatch() throws IOException, URISyntaxException {
    CookieManager cookieManager = new CookieManager(null, ACCEPT_ORIGINAL_SERVER);
    Map<String, List<String>> cookieHeaders = cookieManager.get(new URI("http://android.com/foo/bar/"), EMPTY_COOKIES_MAP);
    assertTrue(cookieHeaders.toString(), cookieHeaders.isEmpty() || (cookieHeaders.size() == 1 && cookieHeaders.get("Cookie").isEmpty()));
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) URI(java.net.URI) CookieManager(java.net.CookieManager)

Example 7 with CookieManager

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

the class CookiesTest method testNonMatchingPathsRejected.

public void testNonMatchingPathsRejected() throws Exception {
    TestCookieStore cookieStore = new TestCookieStore();
    CookieManager cookieManager = new CookieManager(cookieStore, ACCEPT_ORIGINAL_SERVER);
    cookieManager.put(new URI("http://android.com/foo/bar"), cookieHeaders("a=android;path=/baz/bar"));
    assertEquals("Expected to reject cookies whose path is not a prefix of the request path", Collections.<HttpCookie>emptyList(), // RI6 fails this
    cookieStore.cookies);
}
Also used : URI(java.net.URI) CookieManager(java.net.CookieManager)

Example 8 with CookieManager

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

the class CookiesTest method testMatchingPathsAccepted.

public void testMatchingPathsAccepted() throws Exception {
    TestCookieStore cookieStore = new TestCookieStore();
    CookieManager cookieManager = new CookieManager(cookieStore, ACCEPT_ORIGINAL_SERVER);
    cookieManager.put(new URI("http://android.com/foo/bar/"), cookieHeaders("a=android;path=/foo"));
    assertEquals("/foo", cookieStore.getCookie("a").getPath());
}
Also used : URI(java.net.URI) CookieManager(java.net.CookieManager)

Example 9 with CookieManager

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

the class CookiesTest method testDomainDefaulting.

public void testDomainDefaulting() throws Exception {
    TestCookieStore cookieStore = new TestCookieStore();
    CookieManager cookieManager = new CookieManager(cookieStore, ACCEPT_ORIGINAL_SERVER);
    cookieManager.put(new URI("http://android.com/"), cookieHeaders("a=android"));
    assertEquals("android.com", cookieStore.getCookie("a").getDomain());
}
Also used : URI(java.net.URI) CookieManager(java.net.CookieManager)

Example 10 with CookieManager

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

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