1   package net.trajano.webutil;
2   
3   import junit.framework.TestCase;
4   import com.meterware.httpunit.GetMethodWebRequest;
5   import com.meterware.httpunit.HttpUnitOptions;
6   import com.meterware.httpunit.WebRequest;
7   import com.meterware.httpunit.WebResponse;
8   import com.meterware.servletunit.ServletRunner;
9   import com.meterware.servletunit.ServletUnitClient;
10  
11  /***
12   * This is a simple JUnit test case to ensure that the environment is okay.
13   * 
14   * @author <a href="trajano@yahoo.com">Archimedes Trajano</a>
15   * @version $Id: SanityTest.java,v 1.2 2005/07/01 07:18:44 trajano Exp $
16   */
17  public class SanityTest extends TestCase {
18      /***
19       * This verifies that "test" is equivalent to "test".
20       */
21      public void testSanity() {
22          assertEquals("test", "test");
23      }
24  
25      /***
26       * This tests the HelloWorld servlet.
27       * 
28       * @throws Exception
29       *             problem with the test.
30       */
31      public void testHelloWorldServlet() throws Exception {
32          HttpUnitOptions.setScriptingEnabled(false);
33          ServletRunner servletRunner = new ServletRunner();
34          servletRunner.registerServlet("HelloWorldServlet", HelloWorldServlet.class.getName());
35          ServletUnitClient client = servletRunner.newClient();
36          WebRequest request = new GetMethodWebRequest("http://test/HelloWorldServlet");
37          WebResponse response = client.getResponse(request);
38          assertTrue(response.getText().startsWith("Hello world on "));
39      }
40  }