FileDocCategorySizeDatePackage
TestSearchJSP.javaAPI DocExample3822Thu Dec 15 22:17:34 GMT 2005com.oreilly.jent.people.jsp

TestSearchJSP

public class TestSearchJSP extends org.apache.cactus.JspTestCase
Class: TestSearchPage Tests the search JSP from the People Finder sample application.
author
Jim Farley

Fields Summary
Constructors Summary
public TestSearchJSP()
Default constructor

        super();
    
public TestSearchJSP(String name)
Constructor with test name

        super(name);
    
public TestSearchJSP(String name, Test child)
Constructor used to wrap another test with a Cactus test

        super(name, child);
    
Methods Summary
public voidbeginValidSearch(org.apache.cactus.WebRequest request)
Invoked on the "client-side" (within the test runner) before running the badSearchArgument test.

        // Add a search parameter
        request.addParameter(PersonDAO.FIRST_NAME, "John");
    
public voidendValidSearch(org.apache.cactus.WebResponse response)
Invoked on the "client-side" (within the test runner) after the validSearch test completes and sends a response to the test runner.

        // There should be some response from the JSP
        assertNotNull("No response text received from JSP",
                      response.getText());
        // Since this was a valid search, there should be no "Error"
        // text in the response HTML
        assertTrue("Unexpected \"Error:\" indicator in response",
                   response.getText().indexOf("Error:") < 0);
        // In a valid search response, there should be a results header
        assertTrue("No results banner seen in response",
                   response.getText().indexOf("Search Results") >= 0);
    
private voidinvokePage()

        try {
            this.pageContext.forward("/search");
        }
        catch (ServletException se) {
            fail("Unexpected servlet exception: " + se.getMessage());
        }
        catch (IOException ioe) {
            fail("Unexpected I/O exception: " + ioe.getMessage());
        }
    
public voidtestValidSearch()
Ensure that a valid response is generated from a valid search

        // Simply invoke the servlet's doGet() method, using
        // the request constructed in the begin method
        invokePage();