FileDocCategorySizeDatePackage
TestCookieServlet.javaAPI DocExample1572Sat Mar 15 19:39:50 GMT 2003com.oreilly.javaxp.cactus.servlet

TestCookieServlet.java

package com.oreilly.javaxp.cactus.servlet;

import org.apache.cactus.ServletTestCase;
import org.apache.cactus.WebRequest;
import org.apache.cactus.WebResponse;

import javax.servlet.http.Cookie;

/**
 * @author Brian M. Coyner
 * $version $Id: TestCookieServlet.java,v 1.4 2003/02/27 00:24:44 jepc Exp $
 */
public class TestCookieServlet extends ServletTestCase {

    private CookieServlet servlet;

    public TestCookieServlet(String name) {
        super(name);
    }

    protected void setUp() throws Exception {
        this.servlet = new CookieServlet();
    }

    public void testGetInitialCookie() throws Exception {

        Cookie cookie = this.servlet.getCookie(this.request);
        assertNotNull("Cookie.", cookie);
        assertEquals("Cookie Name.",
                     CookieServlet.TEST_COOKIE_NAME,
                     cookie.getName());
        assertEquals("Cookie Value.",
                     "0",
                     cookie.getValue());
    }

    public void beginGetUpdatedCookie(WebRequest req) {
        req.addCookie(CookieServlet.TEST_COOKIE_NAME, "3");
    }

    public void testGetUpdatedCookie() throws Exception {
        this.servlet.doGet(this.request, this.response);
    }

    public void endGetUpdatedCookie(WebResponse res) throws Exception {
        org.apache.cactus.Cookie cookie =
                res.getCookie(CookieServlet.TEST_COOKIE_NAME);
        assertNotNull("Returned Cookie.", cookie);
        assertEquals("Cookie Value.", "4", cookie.getValue());
    }
}