Package com.gargoylesoftware.htmlunit.util

Examples of com.gargoylesoftware.htmlunit.util.Cookie


    public void ShouldparseCookieWithExpiryAndAValueCorrectly() {
        Date testDate = getTestDate(2010, 8, 3, 9, 25, 3);
        final String rawCookie = "USER=bob; expires=Tue, 03-Aug-2010 09:25:03 GMT; path=/";

        CookieParser cookieParser = new CookieParser();
        Cookie cookie = cookieParser.parseCookie("localhost", rawCookie);

        assertThat(cookie.getName(), is("USER"));
        assertThat(cookie.getValue(), is("bob"));
        assertThat(cookie.getExpires(), is(testDate));
    }
View Full Code Here


    @Test
    public void ShouldparseCookieWithoutExpiryAndNoValueCorrectly() {
        final String rawCookie = "USER=; path=/";

        CookieParser cookieParser = new CookieParser();
        Cookie cookie = cookieParser.parseCookie("localhost", rawCookie);

        assertThat(cookie.getName(), is("USER"));
        assertThat(cookie.getValue(), is(""));
        assertThat(cookie.getExpires(), is(nullValue()));
    }
View Full Code Here

    @Test
    public void ShouldparseCookieWithEqualsInTheValue() {
        final String rawCookie = "DATA=USER=bob&FullName=Bob The Builder; path=/";

        CookieParser cookieParser = new CookieParser();
        Cookie cookie = cookieParser.parseCookie("localhost", rawCookie);

        assertThat(cookie.getName(), is("DATA"));
        assertThat(cookie.getValue(), is("USER=bob&FullName=Bob The Builder"));
        assertThat(cookie.getExpires(), is(nullValue()));
    }
View Full Code Here

            }
        }
    }

    private void storeCookie(String hostName, String rawCookie) {
        Cookie cookie = cookieParser.parseCookie(hostName, rawCookie);
        Date now = new Date();
        if (cookie.getExpires() != null && now.after(cookie.getExpires())) {
            removeCookie(this.cookieManager, cookie.getName());
        } else {
            this.cookieManager.addCookie(cookie);
        }
    }
View Full Code Here

            this.cookieManager.addCookie(cookie);
        }
    }

    private void removeCookie(CookieManager cookieManager, String cookieName) {
        Cookie existingCookie = cookieManager.getCookie(cookieName);
        if (existingCookie != null) {
            cookieManager.removeCookie(existingCookie);
        }
    }
View Full Code Here

                } catch (ParseException ignored) {
                }
            }
        }

        return new Cookie(hostName, cookieName, cookieValue, "/", expiresDate, false);
    }
View Full Code Here

TOP

Related Classes of com.gargoylesoftware.htmlunit.util.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.