// requires path of cookie is the prefix of uri
// domain of cookie must match that of uri
Map<String, List<String>> responseHeaders = addCookie(new String[][] {
cookies[0], cookies[1] });
CookieManager manager = store(
new String[][] { cookies[0], cookies[1] }, responseHeaders,
null);
HashMap<String, List<String>> dummyMap = new HashMap<String, List<String>>();
Map<String, List<String>> map = manager.get(new URI("http://a.b.c/"),
dummyMap);
assertEquals(1, map.size());
List<String> list = map.get("Cookie");
assertEquals(1, list.size());
// requires path of cookie is the prefix of uri
map = manager.get(new URI("http://a.b.c/te"), dummyMap);
list = map.get("Cookie");
assertEquals(2, list.size());
// If all cookies are of version 1, then $version=1 will be added
// ,no matter the value cookie-key
responseHeaders = addCookie(new String[][] { cookies[2] });
manager = store(new String[][] { cookies[2] }, responseHeaders, null);
map = manager.get(new URI("http://a.beg.com/test"), dummyMap);
list = map.get("Cookie");
assertEquals("$Version=\"1\"", list.get(0));
assertEquals(3, list.size());
// cookie-key will not have effect on determining cookie version
responseHeaders = addCookie(new String[][] { cookies[3] });
manager = store(new String[][] { cookies[3] }, responseHeaders, null);
map = manager.get(new URI("http://a.test.org/"), responseHeaders);
list = map.get("Cookie");
assertEquals(1, list.size());
assertEquals("Set-cookie3:NAME=VALUE", list.get(0));
// When key is null, no cookie can be stored/retrieved, even if policy =
// ACCEPT_ALL
responseHeaders = addCookie(new String[][] { cookies[4] });
manager = store(new String[][] { cookies[4] }, responseHeaders,
CookiePolicy.ACCEPT_ALL);
map = manager.get(new URI("http://a.test.org/"), responseHeaders);
list = map.get("Cookie");
assertEquals(0, list.size());
// All cookies will be rejected if policy == ACCEPT_NONE
responseHeaders = addCookie(new String[][] { cookies[3] });
manager = store(new String[][] { cookies[3] }, responseHeaders,
CookiePolicy.ACCEPT_NONE);
map = manager.get(new URI("http://a.test.org/"), responseHeaders);
list = map.get("Cookie");
assertEquals(0, list.size());
responseHeaders = addCookie(new String[][] { cookies[5] });
manager = store(new String[][] { cookies[5] }, responseHeaders,