Package com.meterware.httpunit
Classes for testing http server systems.
See:
Description
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.