Test for Garbage Requests

import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/** 
 * HttpUnit mechanism to test that the servlet manages to handle
 * many kinds of garbage without choking. This mechanism only works
 * when the servlet is running in the container and is reachable
 * under http://localhost:8080/refentry
 * <p>The test is then run by hand. Ideally, it would be integrated
 * into a framework such as Cactus.
 * @author <a href="mailto:mark@mcraig.org">Mark Craig</a>
 */
public class TestGarbageRequests extends TestCase {
    public static void main(String[] args) {
        junit.textui.TestRunner.run(suite());
    }
    public static TestSuite suite() {
        return new TestSuite(TestGarbageRequests.class);
    }
    public TestGarbageRequests(String str) {
        super(str);
    }
    public void testGarbageRequests() throws Exception {
        WebConversation wc = new WebConversation();

        WebRequest  request  =
            new GetMethodWebRequest(
                "http://localhost:8080/refentry");
        WebResponse response = wc.getResponse(request);
        String      title    = response.getTitle();

        // These garbage requests should return the default page.
        WebRequest  req1 =
            new GetMethodWebRequest(
                "http://localhost:8080/refentry?");     
        WebResponse res1 = wc.getResponse(req1);
        assertEquals(title, res1.getTitle());

        WebRequest  req2 =
            new GetMethodWebRequest(
                "http://localhost:8080/refentry?garbage");     
        WebResponse res2 = wc.getResponse(req2);
        assertEquals(title, res2.getTitle());

        WebRequest  req3 =
            new GetMethodWebRequest(
                "http://localhost:8080/refentry?grbg+in=grbg+out");
        WebResponse res3 = wc.getResponse(req3);
        assertEquals(title, res3.getTitle());

        WebRequest  req4 =
            new GetMethodWebRequest(
                "http://localhost:8080/refentry/path/to/garbage");
        WebResponse res4 = wc.getResponse(req4);
        assertEquals(title, res4.getTitle());

        // These garbage requests should return the search results page.
        WebRequest  req5 =
            new GetMethodWebRequest(
                "http://localhost:8080/refentry?SrchString");     
        WebResponse res5 = wc.getResponse(req5);
        assertEquals("Search Results", res5.getTitle());

        WebRequest  req6 =
            new GetMethodWebRequest(
                "http://localhost:8080/refentry?SrchString=");     
        WebResponse res6 = wc.getResponse(req6);
        assertEquals("Search Results", res6.getTitle());

        WebRequest  req7 =
            new GetMethodWebRequest(
                "http://localhost:8080/refentry?RefEntry");     
        WebResponse res7 = wc.getResponse(req7);
        assertEquals("Search Results", res7.getTitle());

        WebRequest  req8 =
            new GetMethodWebRequest(
                "http://localhost:8080/refentry?RefEntry=");     
        WebResponse res8 = wc.getResponse(req8);
        assertEquals("Search Results", res8.getTitle());

        WebRequest  req9 =
            new GetMethodWebRequest(
                "http://localhost:8080/refentry?RefEntry=garbage");
        WebResponse res9 = wc.getResponse(req9);
        assertEquals("Search Results", res9.getTitle());
    }
}