HttpUnit

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » HttpUnit 
HttpUnit Web Testing
License:
URL:http://httpunit.sourceforge.net/
Description:Open source Java API for testing web sites without a browser.
Package NameComment
com.meterware.httpunit Classes for testing http server systems. Each test session should begin by creating a {@link com.meterware.httpunit.WebConversation WebConversation} to which it should submit an initial {@link com.meterware.httpunit.GetMethodWebRequest http request} using the {@link com.meterware.httpunit.WebConversation#getResponse 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 a number of external jar files, provided in the jar directory:
nekohtml.jar
The NekoHTML parser, used to convert raw HTML into an XML DOM. This is required for handling HTML.
js.jar
The Rhino JavaScript interpreter, required for any JavaScript processing.
xmlParserAPIs.jar
The interfaces for a W3-compliant XML parser. Required for interpreting either HTML or XML pages.
xercesImpl.jar
The Xerces 2 implementation of an XML parser. NekoHTML requires this implementation.
servlet.jar
The APIs and common classes for the Java Servlet 1.3 standard. Required for use with ServletUnit.
junit.jar
JUnit, the unit test framework. Used to test HttpUnit and recommended for writing tests that use HttpUnit.
tidy.jar
JTidy, an alternate HTML parser/validator. JTidy is a lot pickier about HTML structure than NekoHTML, and uses its own implementation of the DOM classes, rather than using those found in the xerces jar. Some JavaScript features, such as document.write() will only work with NekoHTML.

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 {
            WebConversation     conversation = new WebConversation();
            
            WebResponse response = conversation.getResponse( "http://www.meterware.com/servlet/TopSecret" );
            System.out.println( response );

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

            loginForm.setParameter( "name", "master" );
            response = loginForm.submit();
            System.out.println( response );

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

Classes to support cookie handling. Supports the HTTP state mechanism. The central class of this package is the {@link com.meterware.httpunit.cookies.CookieJar}, which acts as a repository of {@link com.meterware.httpunit.cookies.Cookie} objects. There are two main ways to get cookies into the CookieJar. The first is to construct the CookieJar, passing a {@link com.meterware.httpunit.cookies.CookieSource} to its constructor. This will cause the CookieJar to parse the Set-Cookie headers from the source object. The second is to copy them from another CookieJar through use of the {@link com.meterware.httpunit.cookies.CookieJar#updateCookies updateCookies(CookieJar)} method.

The CookieJar can also produce a Cookie header to be sent as part of a request. The {@link com.meterware.httpunit.cookies.CookieJar#getCookieHeaderField} method will select any cookies that it has which can be sent to the specified URL and assemble them into an appropriate header.

com.meterware.httpunit.javascript
com.meterware.httpunit.parsing

Classes to control HTML parsing. The primary access to this package is through {@link com.meterware.httpunit.parsing.HTMLParserFactory}, which allows a user to select the HTML parser that will be used to parse HTML pages returned by a {@link com.meterware.httpunit.WebClient}. In addition to selecting the actual class, the factory also permits various options to be set on whichever parser is chosen - with the caveat that not every parser supports every property. If the current parser does not in fact support a property, setting it on the factory will have no effect.

com.meterware.httpunit.scripting
com.meterware.pseudoserver A test framework for HTTP clients, using a simplified HTTP server. The {@link com.meterware.pseudoserver.PseudoServer} class is a simple HTTP server which can be programmed with the results required by a test. Results may either be staticly defined or dynamically created, using the {@link com.meterware.pseudoserver.PseudoServlet} class.
com.meterware.servletunit Classes for unit testing servlets, providing internal access to running servlets using a simulated servlet container. Each test session should begin by creating a {@link com.meterware.servletunit.ServletRunner ServletRunner} which will act as a servlet application context. The definition of application context may be supplied in one of two ways. The {@link com.meterware.servletunit.ServletRunner#registerServlet(String,String) registerServlet} method allows the association of a servlet with a url path. Alternately, an entire servlet application may be defined by passing the name of the desired web.xml file. The {@link com.meterware.servletunit.ServletRunner#newClient newClient} method will return a {@link com.meterware.servletunit.ServletUnitClient ServletUnitClient} object which can be used to invoke the defined servlets, just as any subclass of {@link com.meterware.httpunit.WebClient WebClient}. In addition, this client object defines methods which allow access to the fully initializated servlet itself, as well as the request, response, and servlet session. A tutorial is available. Please direct any questions to Russell Gold.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.