Package org.apache.http.cookie

Examples of org.apache.http.cookie.Cookie


            // expected
        }
    }

    public void testRFC2109VersionValidate() throws Exception {
        Cookie cookie = new Cookie("name", "value");
        CookieOrigin origin = new CookieOrigin("somedomain.com", 80, "/", false);
        CookieAttributeHandler h = new RFC2109VersionHandler();

        cookie.setVersion(12);
        h.validate(cookie, origin);
       
        cookie.setVersion(-12);
        try {
            h.validate(cookie, origin);
            fail("MalformedCookieException must have been thrown");
        } catch (MalformedCookieException ex) {
            // expected
View Full Code Here


        String[] testCaseName = { TestBasicCookieAttribHandlers.class.getName() };
        junit.textui.TestRunner.main(testCaseName);
    }

    public void testBasicDomainParse() throws Exception {
        Cookie cookie = new Cookie("name", "value");
        CookieAttributeHandler h = new BasicDomainHandler();
        h.parse(cookie, "www.somedomain.com");
        assertEquals("www.somedomain.com", cookie.getDomain());
        assertTrue(cookie.isDomainAttributeSpecified());
    }
View Full Code Here

        assertEquals("www.somedomain.com", cookie.getDomain());
        assertTrue(cookie.isDomainAttributeSpecified());
    }

    public void testBasicDomainParseInvalid() throws Exception {
        Cookie cookie = new Cookie("name", "value");
        CookieAttributeHandler h = new BasicDomainHandler();
        try {
            h.parse(cookie, "");
            fail("MalformedCookieException should have been thrown");
        } catch (MalformedCookieException ex) {
View Full Code Here

            // expected
        }
    }

    public void testBasicDomainValidate1() throws Exception {
        Cookie cookie = new Cookie("name", "value");
        CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false);
        CookieAttributeHandler h = new BasicDomainHandler();
       
        cookie.setDomain(".somedomain.com");
        h.validate(cookie, origin);

        cookie.setDomain(".otherdomain.com");
        try {
            h.validate(cookie, origin);
            fail("MalformedCookieException should have been thrown");
        } catch (MalformedCookieException ex) {
            // expected
        }
        cookie.setDomain("www.otherdomain.com");
        try {
            h.validate(cookie, origin);
            fail("MalformedCookieException should have been thrown");
        } catch (MalformedCookieException ex) {
            // expected
View Full Code Here

            // expected
        }
    }

    public void testBasicDomainValidate2() throws Exception {
        Cookie cookie = new Cookie("name", "value");
        CookieOrigin origin = new CookieOrigin("somehost", 80, "/", false);
        CookieAttributeHandler h = new BasicDomainHandler();
       
        cookie.setDomain("somehost");
        h.validate(cookie, origin);

        cookie.setDomain("otherhost");
        try {
            h.validate(cookie, origin);
            fail("MalformedCookieException should have been thrown");
        } catch (MalformedCookieException ex) {
            // expected
View Full Code Here

            // expected
        }
    }

    public void testBasicDomainValidate3() throws Exception {
        Cookie cookie = new Cookie("name", "value");
        CookieOrigin origin = new CookieOrigin("somedomain.com", 80, "/", false);
        CookieAttributeHandler h = new BasicDomainHandler();
       
        cookie.setDomain(".somedomain.com");
        h.validate(cookie, origin);
    }
View Full Code Here

        cookie.setDomain(".somedomain.com");
        h.validate(cookie, origin);
    }

    public void testBasicDomainValidate4() throws Exception {
        Cookie cookie = new Cookie("name", "value");
        CookieOrigin origin = new CookieOrigin("somedomain.com", 80, "/", false);
        CookieAttributeHandler h = new BasicDomainHandler();
       
        cookie.setDomain(null);
        try {
            h.validate(cookie, origin);
            fail("MalformedCookieException should have been thrown");
        } catch (MalformedCookieException ex) {
            // expected
View Full Code Here

            // expected
        }
    }
   
    public void testBasicDomainMatch1() throws Exception {
        Cookie cookie = new Cookie("name", "value");
        CookieOrigin origin = new CookieOrigin("somedomain.com", 80, "/", false);
        CookieAttributeHandler h = new BasicDomainHandler();

        cookie.setDomain("somedomain.com");
        assertTrue(h.match(cookie, origin));
       
        cookie.setDomain(".somedomain.com");
        assertTrue(h.match(cookie, origin));
    }
View Full Code Here

        cookie.setDomain(".somedomain.com");
        assertTrue(h.match(cookie, origin));
    }

    public void testBasicDomainMatch2() throws Exception {
        Cookie cookie = new Cookie("name", "value");
        CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false);
        CookieAttributeHandler h = new BasicDomainHandler();

        cookie.setDomain("somedomain.com");
        assertTrue(h.match(cookie, origin));
       
        cookie.setDomain(".somedomain.com");
        assertTrue(h.match(cookie, origin));

        cookie.setDomain(null);
        assertFalse(h.match(cookie, origin));
    }
View Full Code Here

            fail("IllegalArgumentException must have been thrown");
        } catch (IllegalArgumentException ex) {
            // expected
        }
        try {
            h.validate(new Cookie("name", "value"), null);
            fail("IllegalArgumentException must have been thrown");
        } catch (IllegalArgumentException ex) {
            // expected
        }
        try {
            h.match(null, null);
            fail("IllegalArgumentException must have been thrown");
        } catch (IllegalArgumentException ex) {
            // expected
        }
        try {
            h.match(new Cookie("name", "value"), null);
            fail("IllegalArgumentException must have been thrown");
        } catch (IllegalArgumentException ex) {
            // expected
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.http.cookie.Cookie

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.