KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > SearchServletTest


1 package org.roller.presentation;
2
3 import javax.servlet.http.HttpServletRequest JavaDoc;
4 import javax.servlet.http.HttpServletRequestWrapper JavaDoc;
5
6 import junit.framework.Test;
7 import junit.framework.TestSuite;
8
9 import org.roller.presentation.filters.PersistenceSessionFilter;
10 import org.roller.presentation.filters.RequestFilter;
11 import org.roller.presentation.velocity.SearchServlet;
12
13 import com.mockrunner.mock.web.MockHttpServletRequest;
14 import com.mockrunner.mock.web.MockServletConfig;
15
16
17 /**
18  * @author Dave Johnson
19  */

20 public class SearchServletTest extends VelocityServletTestBase
21 {
22     public void testSearch() throws Exception JavaDoc
23     {
24         servletModule.setServlet(
25             servletModule.createServlet(SearchServlet.class));
26         MockHttpServletRequest mockRequest = getMockFactory().getMockRequest();
27
28         mockRequest.setContextPath("/search");
29         mockRequest.setQueryString("q=test");
30  
31         servletModule.createFilter(PersistenceSessionFilter.class);
32         servletModule.createFilter(RequestFilter.class);
33         servletModule.setDoChain(true);
34         
35         servletModule.doFilter();
36         getMockFactory().addRequestWrapper(new HttpServletRequestWrapper JavaDoc(
37             (HttpServletRequest JavaDoc)servletModule.getFilteredRequest()));
38         servletModule.doGet();
39         assertNotNull(
40             servletModule.getRequestAttribute("zzz_VelocityContext_zzz"));
41     }
42     public static Test suite()
43     {
44         return new TestSuite(SearchServletTest.class);
45     }
46     public static void main(String JavaDoc[] args)
47     {
48         junit.textui.TestRunner.run(SearchServletTest.class);
49     }
50 }
51
Popular Tags