Code example for HttpCookie

Methods: setDomain

0
     *        java.net.HttpCookie). 
     *  
     * @since 1.6 
     */ 
    public void test_ShouldAccept_LURI_LHttpCookie() throws URISyntaxException { 
        HttpCookie cookie = new HttpCookie("Harmony_6", "ongoing");
        URI uri = new URI("");
        try { 
            CookiePolicy.ACCEPT_ORIGINAL_SERVER.shouldAccept(null, cookie);
            fail("Should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected 
        } 
 
        try { 
            CookiePolicy.ACCEPT_ORIGINAL_SERVER.shouldAccept(uri, null);
            fail("Should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected 
        } 
 
        try { 
            CookiePolicy.ACCEPT_ORIGINAL_SERVER.shouldAccept(null, null);
            fail("Should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected 
        } 
 
        // Policy: ACCEPT_ALL, always returns true 
        boolean accept = CookiePolicy.ACCEPT_ALL.shouldAccept(null, cookie);
        assertTrue(accept);
 
        accept = CookiePolicy.ACCEPT_ALL.shouldAccept(null, null);
        assertTrue(accept);
 
        accept = CookiePolicy.ACCEPT_ALL.shouldAccept(uri, null);
        assertTrue(accept);
 
        // Policy: ACCEPT_NONE, always returns false 
        accept = CookiePolicy.ACCEPT_NONE.shouldAccept(null, cookie);
        assertFalse(accept);
 
        accept = CookiePolicy.ACCEPT_NONE.shouldAccept(null, null);
        assertFalse(accept);
 
        accept = CookiePolicy.ACCEPT_NONE.shouldAccept(uri, null);
        assertFalse(accept);
 
        // Policy: ACCEPT_ORIGINAL_SERVER 
        accept = CookiePolicy.ACCEPT_ORIGINAL_SERVER.shouldAccept(uri, cookie);
        assertFalse(accept);
 
        cookie.setDomain(".b.c");
        accept = CookiePolicy.ACCEPT_ORIGINAL_SERVER.shouldAccept(new URI(
                "schema://a.b.c"), cookie);
        assertTrue(accept);
 
        cookie.setDomain(".b.c");
        accept = CookiePolicy.ACCEPT_ORIGINAL_SERVER.shouldAccept(new URI(
                "s://a.b.c.d"), cookie);
        assertFalse(accept);
 
        cookie.setDomain("b.c");
        accept = CookiePolicy.ACCEPT_ORIGINAL_SERVER.shouldAccept(new URI(
                "s://a.b.c.d"), cookie);
        assertFalse(accept);
 
        cookie.setDomain("a.b.c.d");
        accept = CookiePolicy.ACCEPT_ORIGINAL_SERVER.shouldAccept(new URI(
                "s://a.b.c.d"), cookie);
        assertTrue(accept);
 
        cookie.setDomain(".");
        accept = CookiePolicy.ACCEPT_ORIGINAL_SERVER.shouldAccept(new URI(
                "s://a.b.c.d"), cookie);
        assertFalse(accept);
 
        cookie.setDomain("");
        accept = CookiePolicy.ACCEPT_ORIGINAL_SERVER.shouldAccept(new URI(
                "s://a.b.c.d"), cookie);
        assertFalse(accept);
    } 
 
}