01 import org.apache.cactus.ServletTestCase;
02 import org.apache.cactus.WebRequest;
03 import org.apache.cactus.WebResponse;
04
05 import javax.servlet.http.Cookie;
06
07 public class TestCookieServlet extends ServletTestCase {
08
09 private CookieServlet servlet;
10
11 public TestCookieServlet(String name) {
12 super(name);
13 }
14
15 protected void setUp() throws Exception {
16 this.servlet = new CookieServlet();
17 }
18
19 public void testGetFirstCookie() throws Exception {
20 Cookie cookie = this.servlet.getCookie(this.request);
21 assertNotNull("Cookie.", cookie);
22 assertEquals("Cookie Name.",CookieServlet.TEST_COOKIE_NAME,cookie.getName());
23 assertEquals("Cookie Value.","0",cookie.getValue());
24 }
25
26 public void beginGetUpdatedCookie(WebRequest req) {
27 req.addCookie(CookieServlet.TEST_COOKIE_NAME, "3");
28 }
29
30 public void testGetUpdatedCookie() throws Exception {
31 this.servlet.doGet(this.request,this.response);
32 }
33
34 public void endGetUpdatedCookie(WebResponse res) throws Exception {
35 org.apache.cactus.Cookie cookie = res.getCookie(CookieServlet.TEST_COOKIE_NAME);
36 assertNotNull("Returned Cookie.",cookie);
37 assertEquals("Cookie Value.", "4",cookie.getValue());
38 }
39 }
|