Package java.net

Examples of java.net.HttpCookie


    }
    TestHttpCookie d(String d) { return d(0, d); }

    // check max-age
    TestHttpCookie a(int index, long a) {
        HttpCookie cookie = cookies.get(index);
        if (cookie == null || (a != cookie.getMaxAge())) {
            raiseError("max-age", Long.toString(cookie.getMaxAge()), Long.toString(a));
        }

        return this;
    }
View Full Code Here


    }
    TestHttpCookie a(long a) { return a(0, a); }

    // check port list
    TestHttpCookie port(int index, String p) {
        HttpCookie cookie = cookies.get(index);
        if (cookie == null || !p.equals(cookie.getPortlist())) {
            raiseError("portlist", cookie.getPortlist(), p);
        }

        return this;
    }
View Full Code Here

    static void misc() {
        header("Test equals()");

        // test equals()
        HttpCookie c1 = new HttpCookie("Customer", "WILE_E_COYOTE");
        c1.setDomain(".coyote.org");
        c1.setPath("/acme");
        HttpCookie c2 = (HttpCookie)c1.clone();
        eq(c1, c2, true);

        // test equals() when domain and path are null
        c1 = new HttpCookie("Customer", "WILE_E_COYOTE");
        c2 = new HttpCookie("CUSTOMER", "WILE_E_COYOTE");
        eq(c1, c2, true);

        // path is case-sensitive
        c1 = new HttpCookie("Customer", "WILE_E_COYOTE");
        c2 = new HttpCookie("CUSTOMER", "WILE_E_COYOTE");
        c1.setPath("/acme");
        c2.setPath("/ACME");
        eq(c1, c2, false);

        header("Test domainMatches()");
        dm(".foo.com""y.x.foo.com",      false);
        dm(".foo.com""x.foo.com",        true);
        dm(".com",      "whatever.com",     false);
        dm(".com.",     "whatever.com",     false);
        dm(".ajax.com", "ajax.com",         true);
        dm(".local",    "example.local",    true);

        // bug 6277808
        testCount++;
        try {
            c1 = new HttpCookie("", "whatever");
        } catch (IllegalArgumentException ignored) {
            // expected exception; no-op
        }
    }
View Full Code Here

        return postParameters;
    }

    @Override
    public String cookieValue(String name) {
        HttpCookie cookie = cookie(name);
        return cookie == null ? null : cookie.getValue();
    }
View Full Code Here

        cookies.add(httpCookie);
        return this;
    }

    public StubHttpResponse cookie(String name, String value) {
        return cookie(new HttpCookie(name, value));
    }
View Full Code Here

        return new QueryParameters(body()).keys();
    }

    @Override
    public String cookieValue(String name) {
        HttpCookie cookie = cookie(name);
        return cookie == null ? null : cookie.getValue();
    }
View Full Code Here

        List<String> values = new ArrayList<String>();
        values.add("test=me");
        values.add("testing=\"now\"");

        List<HttpCookie> expected = new ArrayList<HttpCookie>();
        expected.add(new HttpCookie("test", "me"));
        expected.add(new HttpCookie("testing", "now"));

        assertEquals(expected, InboundCookieParser.parse(values));
    }
View Full Code Here

     * @tests java.net.HttpCookie(String, String).
     *
     * @since 1.6
     */
    public void test_HttpCookie_LString_LString() {
        assertNotNull(new HttpCookie("harmony_6", "test,sem"));
        assertNotNull(new HttpCookie("harmony_6", null));
        assertNotNull(new HttpCookie("harmony    ", null));
        assertEquals("harmony", new HttpCookie("harmony ", null).getName());

        constructHttpCookie("", null);

        String value = "value";
        constructHttpCookie("", value);

        constructHttpCookie("harmony,", value);
        constructHttpCookie("harmony;", value);
        constructHttpCookie("$harmony", value);
        constructHttpCookie("n\tame", value);
        constructHttpCookie("n\rame", value);
        constructHttpCookie("n\r\name", value);
        constructHttpCookie("Comment", value);
        constructHttpCookie("CommentURL", value);
        constructHttpCookie("Domain", value);
        constructHttpCookie("Discard", value);
        constructHttpCookie("Max-Age", value);
        constructHttpCookie("  Path     ", value);
        constructHttpCookie("Port  ", value);
        constructHttpCookie("SeCure", value);
        constructHttpCookie("VErsion", value);
        constructHttpCookie("expires", value);
        constructHttpCookie("na\u0085me", value);
        constructHttpCookie("\u2028me", value);
        constructHttpCookie("na\u2029me", value);

        try {
            new HttpCookie(null, value);
            fail("Should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }
       
        try {
            new HttpCookie("\u007f", value);
            fail("Should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // expected
        }

        HttpCookie cookie = new HttpCookie("harmony!", null);
        assertEquals("harmony!", cookie.getName());

        cookie = new HttpCookie("harmon$y", null);
        assertEquals("harmon$y", cookie.getName());

    }
View Full Code Here

    }

    private static void constructHttpCookie(String name, String value) {
        try {
            new HttpCookie(name, value);
            fail("Should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // expected
        }
    }
View Full Code Here

     * @tests java.net.HttpCookie#getVersion(), setVersion(int).
     *
     * @since 1.6
     */
    public void test_Get_SetVersion() {
        HttpCookie cookie = new HttpCookie("name", "value");
        assertEquals(1, cookie.getVersion());
        cookie.setVersion(0);
        assertEquals(0, cookie.getVersion());
        cookie.setVersion(1);
        assertEquals(1, cookie.getVersion());

        try {
            cookie.setVersion(-1);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // expected
        }

        try {
            cookie.setVersion(2);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // expected
        }
    }
View Full Code Here

TOP

Related Classes of java.net.HttpCookie

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.