KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > groovy > servlet > GroovyServletTest


1 package groovy.servlet;
2
3 import javax.servlet.ServletConfig JavaDoc;
4 import javax.servlet.ServletContext JavaDoc;
5 import javax.servlet.http.HttpServletRequest JavaDoc;
6
7 import org.jmock.Mock;
8 import org.jmock.MockObjectTestCase;
9
10 public class GroovyServletTest extends MockObjectTestCase {
11
12     private ServletConfig JavaDoc config;
13     private ServletContext JavaDoc context;
14     private GroovyServlet servlet;
15
16     protected void setUp() throws Exception JavaDoc {
17         super.setUp();
18         //this.config = (ServletConfig) mock(ServletConfig.class).proxy();
19
//this.context = (ServletContext) mock(ServletContext.class).proxy();
20
this.servlet = new GroovyServlet();
21         //servlet.init(config);
22
}
23
24     protected void tearDown() throws Exception JavaDoc {
25         super.tearDown();
26     }
27
28     public void testRequestGetCommandOK() {
29         Mock requestMock = mock(HttpServletRequest JavaDoc.class);
30         requestMock.expects(once()).method("getParameter").with(eq("command")).will(returnValue("SELECT..."));
31         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) requestMock.proxy();
32         String JavaDoc command = request.getParameter("command");
33         assertEquals("SELECT...", command);
34     }
35
36     // public void testService() {
37
// Mock requestMock = mock(HttpServletRequest.class);
38
// Mock responseMock = mock(HttpServletResponse.class);
39
//
40
// HttpServletRequest request = (HttpServletRequest) requestMock.proxy();
41
// HttpServletResponse response = (HttpServletResponse) responseMock.proxy();
42
// try {
43
// servlet.service(request, response);
44
// } catch (Throwable t) {
45
// t.printStackTrace();
46
// fail(t.getMessage());
47
// }
48
// }
49

50 }
51
Popular Tags