    1   package groovy.servlet;
    2
    3   import javax.servlet.ServletConfig;
    4   import javax.servlet.ServletContext;
    5   import javax.servlet.http.HttpServletRequest;
    6
    7   import org.jmock.Mock;
    8   import org.jmock.MockObjectTestCase;
    9
    10  public class GroovyServletTest extends MockObjectTestCase {
    11
    12      private ServletConfig config;
    13      private ServletContext context;
    14      private GroovyServlet servlet;
    15
    16      protected void setUp() throws Exception {
    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 {
    25          super.tearDown();
    26      }
    27
    28      public void testRequestGetCommandOK() {
    29          Mock requestMock = mock(HttpServletRequest.class);
    30          requestMock.expects(once()).method("getParameter").with(eq("command")).will(returnValue("SELECT..."));
    31          HttpServletRequest request = (HttpServletRequest) requestMock.proxy();
    32          String 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  }