01: package com.mockrunner.example.servlet;
02:
03: import javax.servlet.http.HttpServletRequest;
04:
05: import com.mockrunner.servlet.BasicServletTestCaseAdapter;
06:
07: /**
08: * Example test for {@link LogoutServlet}.
09: * Demonstrates the usage of {@link com.mockrunner.servlet.ServletTestModule}
10: * and {@link com.mockrunner.servlet.BasicServletTestCaseAdapter}
11: * with and without a filter.
12: */
13: public class LogoutServletTest extends BasicServletTestCaseAdapter {
14: protected void setUp() throws Exception {
15: super .setUp();
16: createServlet(LogoutServlet.class);
17: }
18:
19: public void testDoLogout() throws Exception {
20: addRequestParameter("logout", "true");
21: doPost();
22: assertFalse(getWebMockObjectFactory().getMockSession()
23: .isValid());
24: }
25:
26: public void testDoLogoutWithFilteredImageButton() throws Exception {
27: addRequestParameter("logout.x", "11");
28: addRequestParameter("logout.y", "11");
29: doPost();
30: assertTrue(getWebMockObjectFactory().getMockSession().isValid());
31: createFilter(ImageButtonFilter.class);
32: setDoChain(true);
33: doPost();
34: assertFalse(getWebMockObjectFactory().getMockSession()
35: .isValid());
36: HttpServletRequest filteredRequest = (HttpServletRequest) getFilteredRequest();
37: assertEquals("11", filteredRequest.getParameter("logout"));
38: assertNull(filteredRequest.getParameter("logout.x"));
39: assertNull(filteredRequest.getParameter("logout.y"));
40: }
41: }
|