Package com.meterware.httpunit

Classes for testing http server systems.

See:
          Description

Class Summary
GetMethodWebRequest An HTTP request using the GET method.
PostMethodWebRequest An HTTP request using the POST method.
TableCell A single cell in an HTML table.
WebConversation The context for a series of HTTP requests.
WebForm This class represents a form in an HTML page.
WebLink This class represents a link in an HTML page.
WebRequest A request sent to a web server.
WebResponse A response from a web server to an Http request.
WebTable This class represents a table in an HTML page.
 

Exception Summary
AuthorizationRequiredException This exception is thrown when an unauthorized request is made for a page that requires authentication.
 

Package com.meterware.httpunit Description

Classes for testing http server systems. Each test session should begin by creating a WebConversation to which it should submit an initial http request using the getResponse method. With each subsequent step, it will typically examine the response either textually or as a DOM, and create new requests based on either submitting a form or clicking on a link.

Installation

The package depends on JTidy by Andy Quick. The jtidy.jar must be in the class path ahead of any other implementation of the DOM classes. In addition, unit tests will require JUnit as well.

Example

In the following code, a web conversation is started and an initial request sent. The program then prints out the response and extracts the first form (the login form) from it. After setting the name parameter to the desired value, it submits the form and prints the response.
import com.meterware.httpunit.*;

import java.io.IOException;
import java.net.MalformedURLException;

import org.xml.sax.*;

public class Example {


    public static void main( String[] params ) {
        try {
            WebRequest          request;
            WebResponse         response;
            WebConversation     conversation = new WebConversation();
            
            request = new GetMethodWebRequest( "http://www.meterware.com/servlet/TopSecret" );
            response = conversation.getResponse( request );
            System.out.println( response );

            WebForm loginForm = response.getForms()[0];

            request = loginForm.getRequest();
            request.setParameter( "name", "master" );
            response = conversation.getResponse( request );
            System.out.println( response );

        } catch (Exception e) {
            System.err.println( "Exception: " + e );
        }
    }
}
Please direct any questions to Russell Gold.