Code example for CookieManager

Methods: getputsetCookiePolicy

0
     */ 
    public void test_SetCookiePolicy_LCookiePolicy() throws URISyntaxException, 
            IOException { 
 
        // Policy = ACCEPT_NONE 
        CookieManager manager = new CookieManager();
        manager.setCookiePolicy(CookiePolicy.ACCEPT_NONE);
        Map<String, List<String>> responseHeaders = new TreeMap<String, List<String>>();        
        URI uri = new URI("http://a.b.c");
        manager.put(uri, responseHeaders);
        Map<String, List<String>> map = manager.get(uri,
                new HashMap<String, List<String>>());
 
        assertEquals(1, map.size());
        assertTrue(map.get("Cookie").isEmpty());
        Object key = map.keySet().toArray()[0];
        assertNotNull(key);
        assertEquals("Cookie", key);
 
        // Policy = ACCEPT_ALL 
        manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
        responseHeaders = new TreeMap<String, List<String>>();    
        ArrayList<String> list = new ArrayList<String>();
        list.add("test=null");
        responseHeaders.put("Set-cookie", list);
        manager.put(new URI("http://b.c.d"), responseHeaders);
        map = manager.get(uri, new HashMap<String, List<String>>());
        assertEquals(1, map.size());        
    } 
 
    /** 
     * @tests {@link java.net.CookieManager#getCookieStore()} 
Connect your IDE to all the code out there  Get Codota for Java