Package java.net

Examples of java.net.HttpCookie$CookieAttributeAssignor


     *
     * @since 1.6
     */
    public void test_add_LURI_LHttpCookie() throws URISyntaxException {
        URI uri = new URI("http://harmony.test.unit.org");
        HttpCookie cookie = new HttpCookie("name1", "value1");
        cookie.setDiscard(true);
        try {
            cookieStore.add(null, cookie);
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }

        try {
            cookieStore.add(uri, null);
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }

        try {
            cookieStore.add(null, null);
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }
       
        cookieStore.add(uri, cookie);
        List<HttpCookie> list = cookieStore.get(uri);
        assertEquals(1, list.size());
        assertTrue(list.contains(cookie));

        HttpCookie cookie2 = new HttpCookie("  NaME1   ", "  TESTVALUE1   ");
        cookieStore.add(uri, cookie2);
        list = cookieStore.get(uri);
        assertEquals(1, list.size());
        assertEquals("  TESTVALUE1   ", list.get(0).getValue());
        assertTrue(list.contains(cookie2));       
       
        // domain and path attributes works
        HttpCookie anotherCookie = new HttpCookie("name1", "value1");
        anotherCookie.setDomain("domain");
        anotherCookie.setPath("Path");
        cookieStore.add(uri, anotherCookie);
        list = cookieStore.get(uri);
        assertEquals(2, list.size());
        assertNull(list.get(0).getDomain());
        assertEquals("domain", list.get(1).getDomain());
        assertEquals("Path", list.get(1).getPath());

        URI uri2 = new URI("http://.test.unit.org");
        HttpCookie cookie3 = new HttpCookie("NaME2", "VALUE2");
        cookieStore.add(uri2, cookie3);
        list = cookieStore.get(uri2);
        assertEquals(1, list.size());
        assertEquals("VALUE2", list.get(0).getValue());
        list = cookieStore.getCookies();
        assertEquals(3, list.size());
       
        // expired cookie won't be selected.
        HttpCookie cookie4 = new HttpCookie("cookie4", "value4");
        cookie4.setMaxAge(-2);
        assertTrue(cookie4.hasExpired());
        cookieStore.add(uri2, cookie4);
        list = cookieStore.getCookies();
        assertEquals(3, list.size());
        assertFalse(cookieStore.remove(uri2, cookie4));

        cookie4.setMaxAge(3000);
        cookie4.setDomain("domain");
        cookie4.setPath("path");
        cookieStore.add(uri2, cookie4);
        list = cookieStore.get(uri2);
        assertEquals(2, list.size());
       
        cookieStore.add(uri, cookie4);
        list = cookieStore.get(uri);
        assertEquals(3, list.size());
        list = cookieStore.get(uri2);
        assertEquals(2, list.size());
        list = cookieStore.getCookies();
        assertEquals(4, list.size());
               
        URI baduri = new URI("bad_url");
        HttpCookie cookie6 = new HttpCookie("cookie5", "value5");
        cookieStore.add(baduri, cookie6);
        list = cookieStore.get(baduri);
        assertTrue(list.contains(cookie6));
    }
View Full Code Here


        URI uri1 = new URI("http://get.uri1.test.org");
        List<HttpCookie> list = cookieStore.get(uri1);
        assertTrue(list.isEmpty());
        assertTrue(list instanceof ArrayList);

        HttpCookie cookie1 = new HttpCookie("cookie_name1", "cookie_value1");
        HttpCookie cookie2 = new HttpCookie("cookie_name2", "cookie_value2");
        cookieStore.add(uri1, cookie1);
        cookieStore.add(uri1, cookie2);
        URI uri2 = new URI("http://get.uri2.test.org");
        HttpCookie cookie3 = new HttpCookie("cookie_name3", "cookie_value3");
        cookieStore.add(uri2, cookie3);
        list = cookieStore.get(uri1);
        assertEquals(2, list.size());
        list = cookieStore.get(uri2);
        assertEquals(1, list.size());       

        // domain-match cookies also be selected.
        HttpCookie cookie4 = new HttpCookie("cookie_name4", "cookie_value4");
        cookie4.setDomain(".uri1.test.org");
        cookieStore.add(uri2, cookie4);
        list = cookieStore.get(uri1);
        assertEquals(3, list.size());
       
        cookieStore.add(uri1, cookie4);
        list = cookieStore.get(uri1);
        assertEquals(3, list.size());
        list = cookieStore.get(uri2);
        assertEquals(2, list.size());

        // expired cookie won't be selected.
        HttpCookie cookie5 = new HttpCookie("cookie_name5", "cookie_value5");
        cookie5.setMaxAge(-333);
        assertTrue(cookie5.hasExpired());
        cookieStore.add(uri1, cookie5);
        list = cookieStore.get(uri1);
        assertEquals(3, list.size());
        assertFalse(cookieStore.remove(uri1, cookie5));
        list = cookieStore.getCookies();
        assertEquals(4, list.size());
       
        cookie4.setMaxAge(-123);
        list = cookieStore.get(uri1);
        assertEquals(2, list.size());
        list = cookieStore.getCookies();
        assertEquals(3, list.size());
        // expired cookies are also deleted even if it domain-matches the URI
        HttpCookie cookie6 = new HttpCookie("cookie_name6", "cookie_value6");
        cookie6.setMaxAge(-2);
        cookie6.setDomain(".uri1.test.org");
        cookieStore.add(uri2, cookie6);
        list = cookieStore.get(uri1);
        assertEquals(2, list.size());
        assertFalse(cookieStore.remove(null, cookie6));
View Full Code Here

    public void test_getCookies() throws URISyntaxException {
        List<HttpCookie> list = cookieStore.getCookies();
        assertTrue(list.isEmpty());
        assertTrue(list instanceof RandomAccess);

        HttpCookie cookie1 = new HttpCookie("cookie_name", "cookie_value");
        URI uri1 = new URI("http://getcookies1.test.org");
        cookieStore.add(uri1, cookie1);
        list = cookieStore.getCookies();
        assertTrue(list.contains(cookie1));

        HttpCookie cookie2 = new HttpCookie("cookie_name2", "cookie_value2");
        URI uri2 = new URI("http://getcookies2.test.org");
        cookieStore.add(uri2, cookie2);
        list = cookieStore.getCookies();
        assertEquals(2, list.size());
        assertTrue(list.contains(cookie1));
        assertTrue(list.contains(cookie2));

        // duplicated cookie won't be selected.
        cookieStore.add(uri2, cookie1);
        list = cookieStore.getCookies();
        assertEquals(2, list.size());
        // expired cookie won't be selected.
        HttpCookie cookie3 = new HttpCookie("cookie_name3", "cookie_value3");
        cookie3.setMaxAge(-1357);
        cookieStore.add(uri1, cookie3);
        list = cookieStore.getCookies();
        assertEquals(2, list.size());

        try {
            list.add(new HttpCookie("readOnlyName", "readOnlyValue"));
            fail("should throw UnsupportedOperationException");
        } catch (UnsupportedOperationException e) {
            // expected
        }

        try {
            list.remove(new HttpCookie("readOnlyName", "readOnlyValue"));
            fail("should throw UnsupportedOperationException");
        } catch (UnsupportedOperationException e) {
            // expected
        }
    }
View Full Code Here

        List<URI> list = cookieStore.getURIs();
        assertTrue(list.isEmpty());
        assertTrue(list instanceof ArrayList);

        URI uri1 = new URI("http://geturis1.test.com");
        HttpCookie cookie1 = new HttpCookie("cookie_name1", "cookie_value1");
        cookieStore.add(uri1, cookie1);
        list = cookieStore.getURIs();
        assertEquals("geturis1.test.com", list.get(0).getHost());

        HttpCookie cookie2 = new HttpCookie("cookie_name2", "cookie_value2");
        cookieStore.add(uri1, cookie2);
        list = cookieStore.getURIs();
        assertEquals(1, list.size());

        URI uri2 = new URI("http://geturis2.test.com");
View Full Code Here

     *
     * @since 1.6
     */
    public void test_remove_LURI_LHttpCookie() throws URISyntaxException {
        URI uri1 = new URI("http://remove1.test.com");
        HttpCookie cookie1 = new HttpCookie("cookie_name1", "cookie_value1");
        try {
            cookieStore.remove(uri1, null);
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }
        assertFalse(cookieStore.remove(uri1, cookie1));
        assertFalse(cookieStore.remove(null, cookie1));

        cookieStore.add(uri1, cookie1);
        URI uri2 = new URI("http://remove2.test.com");
        HttpCookie cookie2 = new HttpCookie("cookie_name2", "cookie_value2");
        cookieStore.add(uri2, cookie2);
        assertTrue(cookieStore.remove(uri1, cookie1));
        assertFalse(cookieStore.remove(uri1, cookie1));
        assertEquals(2, cookieStore.getURIs().size());
        assertEquals(1, cookieStore.getCookies().size());
        assertTrue(cookieStore.remove(uri2, cookie2));
        assertFalse(cookieStore.remove(uri2, cookie2));
        assertEquals(2, cookieStore.getURIs().size());
        assertEquals(0, cookieStore.getCookies().size());
       
        assertTrue(cookieStore.removeAll());
        cookieStore.add(uri1, cookie1);
        cookieStore.add(uri2, cookie2);
        HttpCookie cookie3 = new HttpCookie("cookie_name3", "cookie_value3");
        assertFalse(cookieStore.remove(null, cookie3));
        assertTrue(cookieStore.remove(null, cookie1));
        assertFalse(cookieStore.remove(null, cookie1));
        assertEquals(2, cookieStore.getURIs().size());
        assertEquals(1, cookieStore.getCookies().size());
        assertTrue(cookieStore.remove(null, cookie2));
        assertFalse(cookieStore.remove(null, cookie2));
        assertEquals(2, cookieStore.getURIs().size());
        assertEquals(0, cookieStore.getCookies().size());

        cookieStore.removeAll();
        // expired cookies can also be deleted.
        cookie2.setMaxAge(-34857);
        cookieStore.add(uri2, cookie2);
        assertTrue(cookieStore.remove(uri2, cookie2));
        assertFalse(cookieStore.remove(uri2, cookie2));
        assertEquals(0, cookieStore.getCookies().size());

        cookie2.setMaxAge(34857);
        cookieStore.add(uri1, cookie1);
        cookieStore.add(uri2, cookie1);
        cookieStore.add(uri2, cookie2);
        assertTrue(cookieStore.remove(uri1, cookie1));
        assertFalse(cookieStore.remove(uri1, cookie1));
        assertFalse(cookieStore.get(uri2).contains(cookie1));
        assertTrue(cookieStore.get(uri2).contains(cookie2));
        assertEquals(0, cookieStore.get(uri1).size());
        cookieStore.remove(uri2, cookie2);

        cookieStore.removeAll();
        cookieStore.add(uri2, cookie2);
        cookieStore.add(uri1, cookie1);
        assertEquals(2, cookieStore.getCookies().size());
        assertTrue(cookieStore.remove(uri2, cookie1));
        assertFalse(cookieStore.remove(uri2, cookie1));
        assertEquals(2, cookieStore.getURIs().size());
        assertEquals(1, cookieStore.getCookies().size());
        assertTrue(cookieStore.getCookies().contains(cookie2));
       
        cookieStore.removeAll();
        URI uri3 = new URI("http://remove3.test.com");
        URI uri4 = new URI("http://test.com");
        HttpCookie cookie4 = new HttpCookie("cookie_name4", "cookie_value4");
        cookie4.setDomain(".test.com");
        cookie2.setMaxAge(-34857);
        cookie3.setMaxAge(-22);
        cookie4.setMaxAge(-45);
        cookieStore.add(uri1, cookie1);
        cookieStore.add(uri2, cookie2);
        cookieStore.add(uri3, cookie3);
        cookieStore.add(uri4, cookie4);
        assertEquals(0, cookieStore.get(uri2).size());
View Full Code Here

        // Spec says returns true if this store changed as a result of the call.
        // But RI always return true.
        assertTrue(cookieStore.removeAll());

        URI uri1 = new URI("http://removeAll1.test.com");
        HttpCookie cookie1 = new HttpCookie("cookie_name1", "cookie_value1");
        cookieStore.add(uri1, cookie1);
        URI uri2 = new URI("http://removeAll2.test.com");
        HttpCookie cookie2 = new HttpCookie("cookie_name2", "cookie_value2");
        cookieStore.add(uri2, cookie2);

        assertTrue(cookieStore.removeAll());
        assertTrue(cookieStore.getURIs().isEmpty());
        assertTrue(cookieStore.getCookies().isEmpty());
View Full Code Here

     *        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);
    }
View Full Code Here

     * @tests java.net.HttpCookie#getValue(), setValue(String)
     *
     * @since 1.6
     */
    public void test_Get_SetValue() {
        HttpCookie cookie = new HttpCookie("name", "value");
        assertEquals("value", cookie.getValue());
        cookie.setValue("newValue");
        assertEquals("newValue", cookie.getValue());

        cookie.setValue(null);
        assertNull(cookie.getValue());

        cookie.setValue("na\u64DEme");
        assertEquals("na\u64DEme", cookie.getValue());
        cookie.setVersion(0);
        cookie.setValue("{(new value, 11)}");
        assertEquals("{(new value, 11)}", cookie.getValue());
    }
View Full Code Here

     * @tests java.net.HttpCookie#getName()
     *
     * @since 1.6
     */
    public void test_GetName() {
        HttpCookie cookie = new HttpCookie("testName", "value");
        assertEquals("testName", cookie.getName());
    }
View Full Code Here

     * @tests java.net.HttpCookie#getSecure(), setSecure(boolean)
     *
     * @since 1.6
     */
    public void test_Get_SetSecure() {
        HttpCookie cookie = new HttpCookie("testName", "value");
        assertFalse(cookie.getSecure());
        cookie.setVersion(0);
        assertFalse(cookie.getSecure());

        cookie.setSecure(true);
        assertTrue(cookie.getSecure());
        cookie.setSecure(false);
        cookie.setVersion(1);
        assertFalse(cookie.getSecure());
    }
View Full Code Here

TOP

Related Classes of java.net.HttpCookie$CookieAttributeAssignor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.