httpunit-commit Mailing List for httpunit (Page 81)
Brought to you by:
russgold
You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(5) |
Sep
(31) |
Oct
(39) |
Nov
(18) |
Dec
(6) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(8) |
Feb
(5) |
Mar
(8) |
Apr
(25) |
May
(20) |
Jun
(23) |
Jul
(28) |
Aug
(10) |
Sep
(3) |
Oct
(32) |
Nov
(61) |
Dec
(24) |
2002 |
Jan
(50) |
Feb
(34) |
Mar
(35) |
Apr
(3) |
May
(25) |
Jun
(25) |
Jul
(30) |
Aug
(146) |
Sep
(49) |
Oct
(156) |
Nov
(121) |
Dec
(54) |
2003 |
Jan
(12) |
Feb
(79) |
Mar
(88) |
Apr
(26) |
May
(67) |
Jun
(29) |
Jul
(8) |
Aug
(16) |
Sep
(20) |
Oct
(17) |
Nov
|
Dec
(5) |
2004 |
Jan
|
Feb
(40) |
Mar
(30) |
Apr
(5) |
May
|
Jun
(83) |
Jul
(34) |
Aug
(20) |
Sep
(44) |
Oct
(46) |
Nov
|
Dec
(14) |
2005 |
Jan
(4) |
Feb
|
Mar
(5) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(4) |
Oct
|
Nov
|
Dec
(1) |
2006 |
Jan
|
Feb
|
Mar
(26) |
Apr
(8) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(5) |
Nov
|
Dec
|
2008 |
Jan
|
Feb
|
Mar
|
Apr
(36) |
May
(38) |
Jun
(1) |
Jul
(1) |
Aug
|
Sep
(4) |
Oct
|
Nov
(18) |
Dec
(4) |
2009 |
Jan
|
Feb
(2) |
Mar
(3) |
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
(35) |
Sep
(1) |
Oct
|
Nov
|
Dec
(1) |
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
(9) |
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(21) |
Oct
(18) |
Nov
(1) |
Dec
|
From: Russell G. <rus...@us...> - 2000-09-05 00:47:24
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv12269/test/com/meterware/httpunit Removed Files: AuthenticationTest.java Log Message: Removed private test |
From: Russell G. <rus...@us...> - 2000-09-01 15:38:34
|
Update of /cvsroot/httpunit/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv28827 Modified Files: build.xml index.html Log Message: Corrected typos Index: build.xml =================================================================== RCS file: /cvsroot/httpunit/httpunit/build.xml,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -r1.9 -r1.10 *** build.xml 2000/09/01 14:53:58 1.9 --- build.xml 2000/09/01 15:38:31 1.10 *************** *** 144,147 **** --- 144,148 ---- <deltree dir="${build.dir}" /> <deltree dir="${dist.dir}" /> + <deltree dir="${web.dir}" /> </target> *************** *** 152,155 **** --- 153,157 ---- <target name="total-clean" depends="clean"> <delete file="${name}_${zip_version}.zip" /> + <delete file="${name}_website_${zip_version}.zip" /> <deltree dir="${docs.dir}/api" /> <deltree dir="${lib.dir}" /> Index: index.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/index.html,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** index.html 2000/09/01 14:53:58 1.3 --- index.html 2000/09/01 15:38:31 1.4 *************** *** 8,12 **** <P>The normal way to access web sites is via a browser; however, there are times when it is desirable to bypass the browser and access a site from a program, including: ! <DL><LI><A HREF="doc/automated testing.html">automated web site testing</A> <LI>using a web-site as part of a distributed application</UL> --- 8,12 ---- <P>The normal way to access web sites is via a browser; however, there are times when it is desirable to bypass the browser and access a site from a program, including: ! <DL><LI><A HREF="doc/automated-testing.html">automated web site testing</A> <LI>using a web-site as part of a distributed application</UL> *************** *** 20,27 **** <blockquote> ! <strong>HttpUnit</strong> is a Java API for accessing web sites without a browser, and is thus intended either for automated ! unit testing of web sites when combined with a Java unit test framework such as <A HREF="http://www.xprogramming.com/software.htm">JUnit</a>. ! It is designed ! and implemented by <a href="mailto:rus...@us...">Russell Gold.</a></blockquote> <h2>Documentation</h2> --- 20,27 ---- <blockquote> ! <strong>HttpUnit</strong> is a Java API for accessing web sites without a browser, ! and is ideally suited for automated unit testing of web sites when combined with a ! Java unit test framework such as <A HREF="http://www.junit.org">JUnit</a>. ! It was designed and implemented by <a href="mailto:rus...@us...">Russell Gold.</a></blockquote> <h2>Documentation</h2> |
From: Russell G. <rus...@us...> - 2000-09-01 15:25:13
|
Update of /cvsroot/httpunit/httpunit/doc In directory slayer.i.sourceforge.net:/tmp/cvs-serv23020/doc Added Files: automated-testing.html Removed Files: automated testing.html Log Message: Corrected typos --- NEW FILE --- <HTML><HEAD><TITLE>Automated testing</TITLE></HEAD> <BODY> Automated unit testing is a great way to ensure that code being maintained works and continues to work. The <A HREF="http://www.XProgramming.com/">Extreme Programming</A> (XP) methodology relies heavily on it, and practitioners have available to them a range of <A HREF="http://www.xprogramming.com/software.htm">unit testing frameworks</A>, which work by making direct calls to the code being tested. But what if you want to test a web application? HttpUnit is a library which makes this possible. </BODY></HTML> ***** Bogus filespec: automated |
From: Russell G. <rus...@us...> - 2000-09-01 14:54:38
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv1776/src/com/meterware/httpunit Modified Files: NodeUtils.java ParsedHTML.java TableCell.java WebConversation.java WebLink.java WebResponse.java Added Files: AuthorizationRequiredException.java Base64.java Log Message: Added basic authentication ***** Error reading new file(2, 'No such file or directory') ***** Error reading new file(2, 'No such file or directory') Index: NodeUtils.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/NodeUtils.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** NodeUtils.java 2000/07/13 13:56:34 1.1 --- NodeUtils.java 2000/09/01 14:54:03 1.2 *************** *** 83,87 **** sb.append( " | " ); } else if (node.getNodeName().equalsIgnoreCase( "th")) { ! sb.append( " | " ); } --- 83,87 ---- sb.append( " | " ); } else if (node.getNodeName().equalsIgnoreCase( "th")) { ! sb.append( " | " ); } Index: ParsedHTML.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** ParsedHTML.java 2000/08/08 20:10:49 1.3 --- ParsedHTML.java 2000/09/01 14:54:03 1.4 *************** *** 115,120 **** /** ! * Returns the first table in the response which has the specified text in its first non-blank row and ! * non-blank column. Will recurse into any nested tables, as needed. * @return the selected table, or null if none is found **/ --- 115,120 ---- /** ! * Returns the first table in the response which has the specified text as the full text of ! * its first non-blank row and non-blank column. Will recurse into any nested tables, as needed. * @return the selected table, or null if none is found **/ *************** *** 125,128 **** --- 125,138 ---- /** + * Returns the first table in the response which has the specified text as a prefix of the text + * in its first non-blank row and non-blank column. Will recurse into any nested tables, as needed. + * @return the selected table, or null if none is found + **/ + public WebTable getTableStartingWithPrefix( String text ) { + return getTableStartingWithPrefix( text.toUpperCase(), getTables() ); + } + + + /** * Returns a copy of the domain object model associated with this page. **/ *************** *** 192,195 **** --- 202,227 ---- if (innerTables.length != 0) { WebTable result = getTableStartingWith( text, innerTables ); + if (result != null) return result; + } + } + } + return null; + } + + + + /** + * Returns the table with the specified text in its first non-blank row and column. + **/ + private WebTable getTableStartingWithPrefix( String text, WebTable[] tables ) { + for (int i = 0; i < tables.length; i++) { + tables[i].purgeEmptyCells(); + if (tables[i].getRowCount() == 0) continue; + if (tables[i].getCellAsText(0,0).toUpperCase().startsWith( text )) { + return tables[i]; + } else { + WebTable[] innerTables = tables[i].getTableCell(0,0).getTables(); + if (innerTables.length != 0) { + WebTable result = getTableStartingWithPrefix( text, innerTables ); if (result != null) return result; } Index: TableCell.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/TableCell.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** TableCell.java 2000/08/03 13:19:19 1.2 --- TableCell.java 2000/09/01 14:54:03 1.3 *************** *** 50,53 **** --- 50,61 ---- + /** + * Returns the text value of this cell. + **/ + public String asText() { + return getCellContentsAsText( _element ); + } + + //---------------------------------------- package methods ----------------------------------------- *************** *** 61,69 **** - String asText() { - return getCellContentsAsText( _element ); - } - - //----------------------------------- private fields and methods ----------------------------------- --- 69,72 ---- Index: WebConversation.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** WebConversation.java 2000/08/21 21:36:22 1.3 --- WebConversation.java 2000/09/01 14:54:03 1.4 *************** *** 1 **** ! package com.meterware.httpunit; /******************************************************************************************************************** * $Id$ * * Copyright (c) 2000, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ import java.io.*; import java.net.*; import java.util.*; import org.xml.sax.*; /** * The context for a series of HTTP requests. This class manages cookies used to maintain * session context, computes relative URLs, and generally emulates the browser behavior * needed to build an automated test of a web site. * * @author Russell Gold * @author Jan Ohrstrom **/ public class WebConversation { /** * Creates a new web conversation. **/ public WebConversation() { } /** * Submits a web request and returns a response, using all state developed so far as stored in * cookies as requested by the server. **/ public ! WebResponse getResponse( WebRequest request ) throws MalformedURLException, IOException { URLConnection connection = openConnection( request.getURL() ); request.completeRequest( connection ); updateCookies( connection ); if (connection.getHeaderField( "Location" ) != null) { return getResponse( new RedirectWebRequest( request, connection.getHeaderField( "Location" ) ) ); } else { WebResponse result = new WebResponse( this, request.getURL(), connection.getInputStream() ); return result; } } /** * Defines a cookie to be sent to the server on every request. **/ public void addCookie(String name, String value) { _cookies.put( name, value ); } /** * Specifies the user agent identification. Used to trigger browser-specific server behavior. **/ public void setUserAgent(String userAgent) { _userAgent = userAgent; } /** * Returns the current user agent setting. **/ public String getUserAgent() { return _userAgent; } //---------------------------------- private members -------------------------------- /** The currently defined cookies. **/ private Hashtable _cookies = new Hashtable(); /** The current user agent. **/ private String _userAgent; static { HttpURLConnection.setFollowRedirects( false ); } private URLConnection openConnection( URL url ) throws MalformedURLException, IOException { URLConnection connection = url.openConnection(); connection.setUseCaches( false ); sendUserAgent( connection ); sendCookies( connection ); return connection; } private void sendUserAgent ( URLConnection connection ) { if (getUserAgent() == null) return; connection.setRequestProperty( "User-Agent" , getUserAgent() ); } private void sendCookies( URLConnection connection ) { if (_cookies.size() == 0) return; StringBuffer! sb = new StringBuffer(); for (Enumeration e = _cookies.keys(); e.hasMoreElements();) { String name = (String) e.nextElement(); sb.append( name ).append( '=' ).append( _cookies.get( name ) ); if (e.hasMoreElements()) sb.append( ';' ); } connection.setRequestProperty( "Cookie", sb.toString() ); } private void updateCookies( URLConnection connection ) { for (int i = 1; true; i++) { String key = connection.getHeaderFieldKey( i ); if (key == null) break; if (!key.equalsIgnoreCase( "Set-Cookie" )) continue; StringTokenizer st = new StringTokenizer( connection.getHeaderField( i ), "=;" ); String name = st.nextToken(); String value = st.nextToken(); _cookies.put( name, value ); }; } } class RedirectWebRequest extends WebRequest { RedirectWebRequest( WebRequest baseRequest, String relativeURL ) throws MalformedURLException { super( baseRequest, relativeURL ); } public URL getURL() throws MalformedURLException { return new URL( getURLBase(), getURLString() ); } } \ No newline at end of file --- 1 ---- ! package com.meterware.httpunit; /******************************************************************************************************************** * $Id$ * * Copyright (c) 2000, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ import java.io.*; import java.net.*; import java.util.*; import org.xml.sax.*; /** * The context for a series of HTTP requests. This class manages cookies used to maintain * session context, computes relative URLs, and generally emulates the browser behavior * needed to build an automated test of a web site. * * @author Russell Gold * @author Jan Ohrstrom **/ public class WebConversation { /** * Creates a new web conversation. **/ public WebConversation() { } /** * Submits a web request and returns a response, using all state developed so far as stored in * cookies as requested by the server. **/ public ! WebResponse getResponse( WebRequest request ) throws MalformedURLException, IOException { URLConnection connection = openConnection( request.getURL() ); request.completeRequest( connection ); updateCookies( connection ); if (connection.getHeaderField( "Location" ) != null) { return getResponse( new RedirectWebRequest( request, connection.getHeaderField( "Location" ) ) ); } else if (connection.getHeaderField( "WWW-Authenticate" ) != null) { throw new AuthorizationRequiredException( connection.getHeaderField( "WWW-Authenticate" ) ); } else { WebResponse result = new WebResponse( this, request.getURL(), connection.getInputStream() ); return result; } } /** * Defines a cookie to be sent to the server on every request. **/ public void addCookie(String name, String value) { _cookies.put( name, value ); } /** * Specifies the user agent identification. Used to trigger browser-specific server behavior. **/ public void setUserAgent(String userAgent) { _userAgent = userAgent; } /** * Returns the current user agent setting. **/ public String getUserAgent() { return _userAgent; } /** * Sets a username and password for a basic authentication scheme. **/ public void setAuthorization( String userName, String password ) { _authorization = "Basic " + Base64.encode( userName + ':' + password ); } //---------------------------------- private members -------------------------------- /** The currently defined cookies. **/ private Hashtable _cookies = new Hashtable(); /** The current user agent. **/ private String _userAgent; /** The authorization header value. **/ private String _authorization; static { HttpURLConnection.setFollowRedirects( false ); } private URLConnection openConnection( URL url ) throws MalformedURLException, IOE! xception { URLConnection connection = url.openConnection(); connection.setUseCaches( false ); sendAuthorization( connection ); sendUserAgent( connection ); sendCookies( connection ); return connection; } private void sendAuthorization( URLConnection connection ) { if (_authorization == null) return; connection.setRequestProperty( "Authorization", _authorization ); } private void sendUserAgent ( URLConnection connection ) { if (getUserAgent() == null) return; connection.setRequestProperty( "User-Agent" , getUserAgent() ); } private void sendCookies( URLConnection connection ) { if (_cookies.size() == 0) return; StringBuffer sb = new StringBuffer(); for (Enumeration e = _cookies.keys(); e.hasMoreElements();) { String name = (String) e.nextElement(); sb.append( name ).append( '=' ).append( _cookies.get( name ) ); if (e.hasMoreElements()) sb.append( ';' ); } connection.setRequestProperty( "Cookie", sb.toString() ); } private void updateCookies( URLConnection connection ) { for (int i = 1; true; i++) { String key = connection.getHeaderFieldKey( i ); if (key == null) break; if (!key.equalsIgnoreCase( "Set-Cookie" )) continue; StringTokenizer st = new StringTokenizer( connection.getHeaderField( i ), "=;" ); String name = st.nextToken(); String value = st.nextToken(); _cookies.put( name, value ); }; } } class RedirectWebRequest extends WebRequest { RedirectWebRequest( WebRequest baseRequest, String relativeURL ) throws MalformedURLException { super( baseRequest, relativeURL ); } public URL getURL() throws MalformedURLException { return new URL( getURLBase(), getURLString() ); } } \ No newline at end of file Index: WebLink.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -r1.1.1.1 -r1.2 *** WebLink.java 2000/06/12 13:09:26 1.1.1.1 --- WebLink.java 2000/09/01 14:54:03 1.2 *************** *** 35,38 **** --- 35,52 ---- + /** + * Returns the text value of this link. + **/ + public String asText() { + if (_node == null) { + return ""; + } else if (!_node.hasChildNodes()) { + return ""; + } else { + return NodeUtils.asText( _node.getChildNodes() ); + } + } + + //---------------------------------- package members -------------------------------- Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -r1.8 -r1.9 *** WebResponse.java 2000/08/09 17:19:18 1.8 --- WebResponse.java 2000/09/01 14:54:04 1.9 *************** *** 1 **** ! package com.meterware.httpunit; /******************************************************************************************************************** * $Id$ * * Copyright (c) 2000, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ import java.io.*; import java.net.*; import org.xml.sax.*; import org.w3c.dom.*; /** * A response from a web server to an Http request. **/ public class WebResponse { /** * Returns the forms found in the page in the order in which they appear. * @exception SAXException thrown if there is an error parsing the response. **/ public WebForm[] getForms() throws SAXException { return getReceivedPage().getForms(); } /** * Returns the links found in the page in the order in which they appear. * @exception SAXException thrown if there is an error parsing the response. **/ public WebLink[] getLinks() throws SAX! Exception { return getReceivedPage().getLinks(); } /** * Returns the first link which contains the specified text. **/ public WebLink getLinkWith( String text ) throws SAXException { return getReceivedPage().getLinkWith( text ); } /** * Returns the first link which contains an image with the specified text as its 'alt' attribute. **/ public WebLink getLinkWithImageText( String text ) throws SAXException { return getReceivedPage().getLinkWithImageText( text ); } /** * Returns the top-level tables found in this page in the order in which * they appear. * @exception SAXException thrown if there is an error parsing the response. **/ public WebTable[] getTables() throws SAXException { return getReceivedPage().getTables(); } /** * Returns a copy of the domain object model tree associated with this response. * @exception SAXException thrown if there is an error parsing the response. **/ public Document getDOM() throws SAXException { return (Document) getReceivedPage().getDOM(); } /** * Returns the first table in the response which has the specified text in its first non-blank row and * non-blank column. Will recurse into any nested tables, as needed. * @exception SAXException thrown if there is an error parsing the response. * @return the selected table, or null if none is found **/ public WebTable getTableStartingWith( String text ) throws SAXException { return getReceivedPage().getTableStartingWith( text ); } public String toString() { return _responseText; } //---------------------------------- package members -------------------------------- /** * Constructs a response object from an input stream. * @param conversation the web conversation which received the response * @param url the url from which the response was received * @param inputStream the input str! eam from which the response can be read **/ WebResponse( WebConversation conversation, URL url, InputStream inputStream ) { _conversation = conversation; _url = url; StringBuffer sb = new StringBuffer(); try { BufferedReader input = new BufferedReader( new InputStreamReader( inputStream ) ); String str; while (null != ((str = input.readLine()))) { sb.append( str ).append( endOfLine ); } input.close (); _responseText = sb.toString(); } catch (IOException e) { throw new RuntimeException( "Unable to retrieve URL: " + _url.toExternalForm() ); } } /** * Returns the web conversation of which this response is a part, and which contains the session * context information required for further requests. **/ WebConversation getWebConversation() { return _conversation; } //--------------------------------- private members -------------------------------------- final private static String endOfLine = System.getProperty( "line.separator" ); private ReceivedPage _page; private String _responseText; private URL _url; private WebConversation _conversation; private ReceivedPage getReceivedPage() throws SAXException { if (_page == null) { _page = new ReceivedPage( _url, _responseText ); } return _page; } } \ No newline at end of file --- 1 ---- ! package com.meterware.httpunit; /******************************************************************************************************************** * $Id$ * * Copyright (c) 2000, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ import java.io.*; import java.net.*; import org.xml.sax.*; import org.w3c.dom.*; /** * A response from a web server to an Http request. **/ public class WebResponse { /** * Returns the forms found in the page in the order in which they appear. * @exception SAXException thrown if there is an error parsing the response. **/ public WebForm[] getForms() throws SAXException { return getReceivedPage().getForms(); } /** * Returns the links found in the page in the order in which they appear. * @exception SAXException thrown if there is an error parsing the response. **/ public WebLink[] getLinks() throws SAX! Exception { return getReceivedPage().getLinks(); } /** * Returns the first link which contains the specified text. **/ public WebLink getLinkWith( String text ) throws SAXException { return getReceivedPage().getLinkWith( text ); } /** * Returns the first link which contains an image with the specified text as its 'alt' attribute. **/ public WebLink getLinkWithImageText( String text ) throws SAXException { return getReceivedPage().getLinkWithImageText( text ); } /** * Returns the top-level tables found in this page in the order in which * they appear. * @exception SAXException thrown if there is an error parsing the response. **/ public WebTable[] getTables() throws SAXException { return getReceivedPage().getTables(); } /** * Returns a copy of the domain object model tree associated with this response. * @exception SAXException thrown if there is an error parsing the response. **/ public Document getDOM() throws SAXException { return (Document) getReceivedPage().getDOM(); } /** * Returns the first table in the response which has the specified text as the full text of * its first non-blank row and non-blank column. Will recurse into any nested tables, as needed. * Case is ignored. * @exception SAXException thrown if there is an error parsing the response. * @return the selected table, or null if none is found **/ public WebTable getTableStartingWith( String text ) throws SAXException { return getReceivedPage().getTableStartingWith( text ); } /** * Returns the first table in the response which has the specified text as a prefix of the text of * its first non-blank row and non-blank column. Will recurse into any nested tables, as needed. * Case is ignored. * @exception SAXException thrown if there is an error parsing the response. * @return the selected table, or null ! if none is found **/ public WebTable getTableStartingWithPrefix( String text ) throws SAXException { return getReceivedPage().getTableStartingWithPrefix( text ); } public String toString() { return _responseText; } //---------------------------------- package members -------------------------------- /** * Constructs a response object from an input stream. * @param conversation the web conversation which received the response * @param url the url from which the response was received * @param inputStream the input stream from which the response can be read **/ WebResponse( WebConversation conversation, URL url, InputStream inputStream ) { _conversation = conversation; _url = url; StringBuffer sb = new StringBuffer(); try { BufferedReader input = new BufferedReader( new InputStreamReader( inputStream ) ); String str; while (null != ((str = input.readLine()))) { sb.append( str ).append( endOfLine ); } input.close (); _responseText = sb.toString(); } catch (IOException e) { throw new RuntimeException( "Unable to retrieve URL: " + _url.toExternalForm() ); } } /** * Returns the web conversation of which this response is a part, and which contains the session * context information required for further requests. **/ WebConversation getWebConversation() { return _conversation; } //--------------------------------- private members -------------------------------------- final private static String endOfLine = System.getProperty( "line.separator" ); private ReceivedPage _page; private String _responseText; private URL _url; private WebConversation _conversation; private ReceivedPage getReceivedPage() throws SAXException { if (_page == null) { _page = new ReceivedPage( _url, _responseText ); ! } return _page; } } \ No newline at end of file |
From: Russell G. <rus...@us...> - 2000-09-01 14:54:34
|
Update of /cvsroot/httpunit/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv1776 Modified Files: build.xml index.html Log Message: Added basic authentication Index: build.xml =================================================================== RCS file: /cvsroot/httpunit/httpunit/build.xml,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -r1.8 -r1.9 *** build.xml 2000/08/03 13:19:19 1.8 --- build.xml 2000/09/01 14:53:58 1.9 *************** *** 6,11 **** <property name="name" value="httpunit" /> <property name="Name" value="HttpUnit" /> ! <property name="version" value="0.9.5" /> ! <property name="zip_version" value="0_9_5" /> <property name="src.dir" value="src" /> <property name="tstsrc.dir" value="test" /> --- 6,11 ---- <property name="name" value="httpunit" /> <property name="Name" value="HttpUnit" /> ! <property name="version" value="1.0" /> ! <property name="zip_version" value="1_0" /> <property name="src.dir" value="src" /> <property name="tstsrc.dir" value="test" /> *************** *** 20,24 **** <property name="web.dir" value="web" /> <property name="packages" value="com.meterware.*" /> ! <property name="build.compiler" value="classic" /> --- 20,25 ---- <property name="web.dir" value="web" /> <property name="packages" value="com.meterware.*" /> ! <property name="build.compiler" value="classic" /> ! <property name="test.class" value="com.meterware.httpunit.HttpUnitSuite" /> *************** *** 57,61 **** <!-- =================================================================== --> <target name="test" depends="testcompile"> ! <java classname="com.meterware.httpunit.HttpUnitSuite" fork="yes" classpath="${build.classes};${classpath}" > </java> --- 58,62 ---- <!-- =================================================================== --> <target name="test" depends="testcompile"> ! <java classname="${test.class}" fork="yes" classpath="${build.classes};${classpath}" > </java> *************** *** 126,129 **** --- 127,138 ---- <replace file="${web.dir}/index.html" token="var:publish " value="var:publish>" /> <replace file="${web.dir}/index.html" token="<version>" value="${zip_version}" /> + </target> + + + <!-- =================================================================== --> + <!-- Packages the web site with ZIP --> + <!-- =================================================================== --> + <target name="publish-zip" depends="publish"> + <zip zipfile="${name}_website_${zip_version}.zip" basedir="${web.dir}" includes="**" /> </target> Index: index.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/index.html,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** index.html 2000/08/07 21:39:35 1.2 --- index.html 2000/09/01 14:53:58 1.3 *************** *** 6,23 **** <H1>HttpUnit</H1> ! <P>Automated unit testing is a great way to ensure that code being ! maintained works and continues to work. The <A HREF="http://www.XProgramming.com/">Extreme ! Programming</A> (XP) methodology relies heavily on it, and practitioners ! have available to them a range of <A HREF="http://www.xprogramming.com/software.htm">unit ! testing frameworks</A>, which work by making direct calls to the ! code being tested. But what if you want to test a web application? ! HttpUnit is a library which makes this possible. Written in Java, HttpUnit emulates the relevant portions of browser behavior, including ! form submission, cookies and automatic page forwarding, and allows ! Java test code to examine returned pages as either text or an ! XML DOM.</P> <h2>What is it?</h2> ! <blockquote><strong>HttpUnit</strong> is a Java API for accessing web sites without a browser, and is thus intended either for automated unit testing of web sites when combined with a Java unit test framework such as <A HREF="http://www.xprogramming.com/software.htm">JUnit</a>. It is designed --- 6,24 ---- <H1>HttpUnit</H1> ! <P>The normal way to access web sites is via a browser; however, there are times when it is desirable to ! bypass the browser and access a site from a program, including: ! <DL><LI><A HREF="doc/automated testing.html">automated web site testing</A> ! <LI>using a web-site as part of a distributed application</UL> ! ! HttpUnit makes this easy. Written in Java, HttpUnit emulates the relevant portions of browser behavior, including ! form submission, basic <A HREF="ftp://ftp.isi.edu/in-notes/rfc2617.txt">http authentication</A>, ! cookies and automatic page redirection, and allows ! Java test code to examine returned pages as text, an XML DOM, or containers of forms, tables, and links.</P> <h2>What is it?</h2> ! <blockquote> ! ! <strong>HttpUnit</strong> is a Java API for accessing web sites without a browser, and is thus intended either for automated unit testing of web sites when combined with a Java unit test framework such as <A HREF="http://www.xprogramming.com/software.htm">JUnit</a>. It is designed |
From: Russell G. <rus...@us...> - 2000-09-01 14:54:34
|
Update of /cvsroot/httpunit/httpunit/doc In directory slayer.i.sourceforge.net:/tmp/cvs-serv1776/doc Modified Files: release notes.txt todo.txt Added Files: automated testing.html Log Message: Added basic authentication ***** Bogus filespec: automated ***** Error reading new file(2, 'No such file or directory') ***** Bogus filespec: release Index: todo.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/todo.txt,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** todo.txt 2000/07/31 12:32:35 1.1 --- todo.txt 2000/09/01 14:54:01 1.2 *************** *** 1,6 **** ! 1. Add "User agent" to request (suggested by Jan Öhrström) ! ! 2. Add methods to retrieve the possible choices for a set of radio buttons or pull-down ! ! 3. Documentation, Documentation --- 1,5 ---- ! o Add simulated http server for unit testing ! o Support Frames ! o Support digest HTTP Authentication ! o Documentation, Documentation |
From: Russell G. <rus...@us...> - 2000-09-01 14:54:11
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv1776/test/com/meterware/httpunit Modified Files: HtmlTablesTest.java HttpUnitSuite.java WebLinkTest.java Added Files: AuthenticationTest.java Base64Test.java Log Message: Added basic authentication ***** Error reading new file(2, 'No such file or directory') ***** Error reading new file(2, 'No such file or directory') Index: HtmlTablesTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HtmlTablesTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -r1.6 -r1.7 *** HtmlTablesTest.java 2000/08/08 20:10:49 1.6 --- HtmlTablesTest.java 2000/09/01 14:54:07 1.7 *************** *** 190,193 **** --- 190,197 ---- assertEquals( "Non-blank columns", 2, cells[0].length ); assertEquals( "cell at 1,0", "Blue", cells[1][0] ); + cells = rp.getTableStartingWithPrefix( "Re" ).asText(); + assertEquals( "Non-blank rows", 2, cells.length ); + assertEquals( "Non-blank columns", 2, cells[0].length ); + assertEquals( "cell at 1,0", "Blue", cells[1][0] ); } Index: HttpUnitSuite.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitSuite.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** HttpUnitSuite.java 2000/08/08 20:10:49 1.3 --- HttpUnitSuite.java 2000/09/01 14:54:07 1.4 *************** *** 40,43 **** --- 40,44 ---- suite.addTest( HtmlTablesTest.suite() ); suite.addTest( WebFormTest.suite() ); + suite.addTest( Base64Test.suite() ); return suite; } Index: WebLinkTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebLinkTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** WebLinkTest.java 2000/08/08 20:23:40 1.2 --- WebLinkTest.java 2000/09/01 14:54:07 1.3 *************** *** 73,76 **** --- 73,82 ---- } + + public void testLinkText() throws Exception { + WebLink link = _simplePage.getLinks()[0]; + assertEquals( "Link text", "an active link", link.asText() ); + } + private static URL _baseURL; |
From: Russell G. <rus...@us...> - 2000-08-21 21:36:24
|
Update of /cvsroot/httpunit/httpunit/doc In directory slayer.i.sourceforge.net:/tmp/cvs-serv14793/doc Modified Files: release notes.txt Log Message: Added addCookie, setUserAgent ***** Bogus filespec: release |
From: Russell G. <rus...@us...> - 2000-08-21 21:36:24
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv14793/src/com/meterware/httpunit Modified Files: WebConversation.java Log Message: Added addCookie, setUserAgent Index: WebConversation.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** WebConversation.java 2000/08/09 17:28:40 1.2 --- WebConversation.java 2000/08/21 21:36:22 1.3 *************** *** 1 **** ! package com.meterware.httpunit; /******************************************************************************************************************** * $Id$ * * Copyright (c) 2000, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ import java.io.*; import java.net.*; import java.util.*; import org.xml.sax.*; /** * The context for a series of HTTP requests. This class manages cookies used to maintain * session context, computes relative URLs, and generally emulates the browser behavior * needed to build an automated test of a web site. **/ public class WebConversation { /** * Creates a new web conversation. **/ public WebConversation() { } /** * Submits a web request and returns a response, using all state developed so far as stored in * cookies as requested by the server. **/ public WebResponse getResponse( WebRequest request ) throws! MalformedURLException, IOException { URLConnection connection = openConnection( request.getURL() ); request.completeRequest( connection ); updateCookies( connection ); if (connection.getHeaderField( "Location" ) != null) { return getResponse( new RedirectWebRequest( request, connection.getHeaderField( "Location" ) ) ); } else { WebResponse result = new WebResponse( this, request.getURL(), connection.getInputStream() ); return result; } } //---------------------------------- private members -------------------------------- private Hashtable _cookies = new Hashtable(); static { HttpURLConnection.setFollowRedirects( false ); } private URLConnection openConnection( URL url ) throws MalformedURLException, IOException { URLConnection connection = url.openConnection(); connection.setUseCaches( false ); sendCookies( connection ); return connection; } private void sendCookies( URLConnection connection ) { if (_cookies.size() == 0) return; StringBuffer sb = new StringBuffer(); for (Enumeration e = _cookies.keys(); e.hasMoreElements();) { String name = (String) e.nextElement(); sb.append( name ).append( '=' ).append( _cookies.get( name ) ); if (e.hasMoreElements()) sb.append( ';' ); } connection.setRequestProperty( "Cookie", sb.toString() ); } private void updateCookies( URLConnection connection ) { for (int i = 1; true; i++) { String key = connection.getHeaderFieldKey( i ); if (key == null) break; if (!key.equalsIgnoreCase( "Set-Cookie" )) continue; StringTokenizer st = new StringTokenizer( connection.getHeaderField( i ), "=;" ); String name = st.nextToken(); String value = st.nextToken(); _cookies.put( name, value ); }; } } class RedirectWebRequest extends WebRequest { ! RedirectWebRequest( WebRequest baseRequest, String relativeURL ) throws MalformedURLException { super( baseRequest, relativeURL ); } public URL getURL() throws MalformedURLException { return new URL( getURLBase(), getURLString() ); } } \ No newline at end of file --- 1 ---- ! package com.meterware.httpunit; /******************************************************************************************************************** * $Id$ * * Copyright (c) 2000, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ import java.io.*; import java.net.*; import java.util.*; import org.xml.sax.*; /** * The context for a series of HTTP requests. This class manages cookies used to maintain * session context, computes relative URLs, and generally emulates the browser behavior * needed to build an automated test of a web site. * * @author Russell Gold * @author Jan Ohrstrom **/ public class WebConversation { /** * Creates a new web conversation. **/ public WebConversation() { } /** * Submits a web request and returns a response, using all state developed so far as stored in * cookies as requested by the server. **/ public ! WebResponse getResponse( WebRequest request ) throws MalformedURLException, IOException { URLConnection connection = openConnection( request.getURL() ); request.completeRequest( connection ); updateCookies( connection ); if (connection.getHeaderField( "Location" ) != null) { return getResponse( new RedirectWebRequest( request, connection.getHeaderField( "Location" ) ) ); } else { WebResponse result = new WebResponse( this, request.getURL(), connection.getInputStream() ); return result; } } /** * Defines a cookie to be sent to the server on every request. **/ public void addCookie(String name, String value) { _cookies.put( name, value ); } /** * Specifies the user agent identification. Used to trigger browser-specific server behavior. **/ public void setUserAgent(String userAgent) { _userAgent = userAgent; } /** * Returns the current user agent setting. **/ public String getUserAgent() { return _userAgent; } //---------------------------------- private members -------------------------------- /** The currently defined cookies. **/ private Hashtable _cookies = new Hashtable(); /** The current user agent. **/ private String _userAgent; static { HttpURLConnection.setFollowRedirects( false ); } private URLConnection openConnection( URL url ) throws MalformedURLException, IOException { URLConnection connection = url.openConnection(); connection.setUseCaches( false ); sendUserAgent( connection ); sendCookies( connection ); return connection; } private void sendUserAgent ( URLConnection connection ) { if (getUserAgent() == null) return; connection.setRequestProperty( "User-Agent" , getUserAgent() ); } private void sendCookies( URLConnection connection ) { if (_cookies.size() == 0) return; StringBuffer! sb = new StringBuffer(); for (Enumeration e = _cookies.keys(); e.hasMoreElements();) { String name = (String) e.nextElement(); sb.append( name ).append( '=' ).append( _cookies.get( name ) ); if (e.hasMoreElements()) sb.append( ';' ); } connection.setRequestProperty( "Cookie", sb.toString() ); } private void updateCookies( URLConnection connection ) { for (int i = 1; true; i++) { String key = connection.getHeaderFieldKey( i ); if (key == null) break; if (!key.equalsIgnoreCase( "Set-Cookie" )) continue; StringTokenizer st = new StringTokenizer( connection.getHeaderField( i ), "=;" ); String name = st.nextToken(); String value = st.nextToken(); _cookies.put( name, value ); }; } } class RedirectWebRequest extends WebRequest { RedirectWebRequest( WebRequest baseRequest, String relativeURL ) throws MalformedURLException { super( baseRequest, relativeURL ); } public URL getURL() throws MalformedURLException { return new URL( getURLBase(), getURLString() ); } } \ No newline at end of file |
From: Russell G. <rus...@us...> - 2000-08-09 17:28:43
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv10855/test/com/meterware/httpunit Modified Files: WebFormTest.java Log Message: Allow multiselect lists to have nothing selected Index: WebFormTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFormTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** WebFormTest.java 2000/08/09 15:13:59 1.2 --- WebFormTest.java 2000/08/09 17:28:40 1.3 *************** *** 161,174 **** "<Select name=colors><Option>blue<Option>red</Select>" + "<Select name=fish><Option value=red>snapper<Option value=pink>salmon</select>" + "</form></body></html>" ); WebForm form = page.getForms()[0]; String[] parameterNames = form.getParameterNames(); - assertEquals( "num parameters", 2, parameterNames.length ); assertEquals( "inferred color default", "blue", form.getParameterValue( "colors" ) ); assertEquals( "inferred fish default", "red", form.getParameterValue( "fish" ) ); WebRequest request = form.getRequest(); assertEquals( "inferred color request", "blue", request.getParameter( "colors" ) ); assertEquals( "inferred fish request", "red", request.getParameter( "fish" ) ); } --- 161,176 ---- "<Select name=colors><Option>blue<Option>red</Select>" + "<Select name=fish><Option value=red>snapper<Option value=pink>salmon</select>" + + "<Select name=media multiple size=2><Option>TV<Option>Radio</select>" + "</form></body></html>" ); WebForm form = page.getForms()[0]; String[] parameterNames = form.getParameterNames(); assertEquals( "inferred color default", "blue", form.getParameterValue( "colors" ) ); assertEquals( "inferred fish default", "red", form.getParameterValue( "fish" ) ); + assertMatchingSet( "inferred media default", new String[0], form.getParameterValues( "media" ) ); WebRequest request = form.getRequest(); assertEquals( "inferred color request", "blue", request.getParameter( "colors" ) ); assertEquals( "inferred fish request", "red", request.getParameter( "fish" ) ); + assertMatchingSet( "inferred media default", new String[0], request.getParameterValues( "media" ) ); } |
From: Russell G. <rus...@us...> - 2000-08-09 17:28:43
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv10855/src/com/meterware/httpunit Modified Files: WebConversation.java WebForm.java Log Message: Allow multiselect lists to have nothing selected Index: WebConversation.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -r1.1.1.1 -r1.2 *** WebConversation.java 2000/06/12 13:09:26 1.1.1.1 --- WebConversation.java 2000/08/09 17:28:40 1.2 *************** *** 1,3 **** ! package com.meterware.httpunit; import java.io.*; import java.net.*; import java.util.*; import org.xml.sax.*; /** * The context for a series of HTTP requests. This class manages cookies used to maintain * session context, computes relative URLs, and generally emulates the browser behavior * needed to build an automated test of a web site. **/ public class WebConversation { /** * Creates a new web conversation. **/ public WebConversation() { } /** * Submits a web request and returns a response, using all state developed so far as stored in * cookies as requested by the server. **/ public WebResponse getResponse( WebRequest request ) throws MalformedURLException, IOException { URLConnection connection = openConnection( request.getURL() ); request.completeRequest( connection ); updateCookies( connection ); if (connection.getHeaderField( "Location" ) != null) { return getResponse( new RedirectWebRequest( request, connection.getHeaderField( "Location" ) ) ); } else { WebResponse result = new WebResponse( this, request.getURL(), connection.getInputStream() ); return result; } } //---------------------------------- private members -------------------------------- private Hashtable _cookies = new Hashtable(); static { HttpURLConnection.setFollowRedirects( false ); } private URLConnection openConnection( URL url ) throws MalformedURLException, IOException { URLConnection connection = url.openConnection(); connection.setUseCaches( false ); sendCookies( connection ); return connection; } private void sendCookies( URLConnection connection ) { if (_cookies.size() == 0) return; StringBuffer sb = new StringBuffer(); for (Enumeration e = _cookies.keys(); e.hasMoreElements();) { String name = (String) e.nextElement(); sb.append( name ).append( '=' ).append( _cooki! es.get( name ) ); if (e.hasMoreElements()) sb.append( ';' ); } connection.setRequestProperty( "Cookie", sb.toString() ); } private void updateCookies( URLConnection connection ) { for (int i = 1; true; i++) { String key = connection.getHeaderFieldKey( i ); if (key == null) break; if (!key.equalsIgnoreCase( "Set-Cookie" )) continue; StringTokenizer st = new StringTokenizer( connection.getHeaderField( i ), "=;" ); String name = st.nextToken(); String value = st.nextToken(); _cookies.put( name, value ); }; } } class RedirectWebRequest extends WebRequest { RedirectWebRequest( WebRequest baseRequest, String relativeURL ) throws MalformedURLException { super( baseRequest, relativeURL ); } public URL getURL() throws MalformedURLException { return new URL( getURLBase(), getURLString() ); } } ! ! --- 1 ---- ! package com.meterware.httpunit; /******************************************************************************************************************** * $Id$ * * Copyright (c) 2000, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ import java.io.*; import java.net.*; import java.util.*; import org.xml.sax.*; /** * The context for a series of HTTP requests. This class manages cookies used to maintain * session context, computes relative URLs, and generally emulates the browser behavior * needed to build an automated test of a web site. **/ public class WebConversation { /** * Creates a new web conversation. **/ public WebConversation() { } /** * Submits a web request and returns a response, using all state developed so far as stored in * cookies as requested by the server. **/ public WebResponse getResponse( WebRequest request ) throws! MalformedURLException, IOException { URLConnection connection = openConnection( request.getURL() ); request.completeRequest( connection ); updateCookies( connection ); if (connection.getHeaderField( "Location" ) != null) { return getResponse( new RedirectWebRequest( request, connection.getHeaderField( "Location" ) ) ); } else { WebResponse result = new WebResponse( this, request.getURL(), connection.getInputStream() ); return result; } } //---------------------------------- private members -------------------------------- private Hashtable _cookies = new Hashtable(); static { HttpURLConnection.setFollowRedirects( false ); } private URLConnection openConnection( URL url ) throws MalformedURLException, IOException { URLConnection connection = url.openConnection(); connection.setUseCaches( false ); sendCookies( connection ); return connection; } private void sendCookies( URLConnection connection ) { if (_cookies.size() == 0) return; StringBuffer sb = new StringBuffer(); for (Enumeration e = _cookies.keys(); e.hasMoreElements();) { String name = (String) e.nextElement(); sb.append( name ).append( '=' ).append( _cookies.get( name ) ); if (e.hasMoreElements()) sb.append( ';' ); } connection.setRequestProperty( "Cookie", sb.toString() ); } private void updateCookies( URLConnection connection ) { for (int i = 1; true; i++) { String key = connection.getHeaderFieldKey( i ); if (key == null) break; if (!key.equalsIgnoreCase( "Set-Cookie" )) continue; StringTokenizer st = new StringTokenizer( connection.getHeaderField( i ), "=;" ); String name = st.nextToken(); String value = st.nextToken(); _cookies.put( name, value ); }; } } class RedirectWebRequest extends WebRequest { ! RedirectWebRequest( WebRequest baseRequest, String relativeURL ) throws MalformedURLException { super( baseRequest, relativeURL ); } public URL getURL() throws MalformedURLException { return new URL( getURLBase(), getURLString() ); } } \ No newline at end of file Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -r1.5 -r1.6 *** WebForm.java 2000/08/09 15:13:59 1.5 --- WebForm.java 2000/08/09 17:28:40 1.6 *************** *** 355,359 **** } } ! if (selected.size() == 0 && nl.getLength() > 0) selected.addElement( getOptionValue( nl.item(0) ) ); String[] result = new String[ selected.size() ]; selected.copyInto( result ); --- 355,363 ---- } } ! ! if (!isMultiSelect() && selected.size() == 0 && nl.getLength() > 0) { ! selected.addElement( getOptionValue( nl.item(0) ) ); ! } ! String[] result = new String[ selected.size() ]; selected.copyInto( result ); *************** *** 383,386 **** --- 387,395 ---- options.copyInto( result ); return result; + } + + + private boolean isMultiSelect() { + return _node.getAttributes().getNamedItem( "multiple" ) != null; } |
From: Russell G. <rus...@us...> - 2000-08-09 17:19:21
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv9506/src/com/meterware/httpunit Modified Files: WebResponse.java Log Message: Report bad URL on read failure Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** WebResponse.java 2000/08/08 20:10:49 1.7 --- WebResponse.java 2000/08/09 17:19:18 1.8 *************** *** 1 **** ! package com.meterware.httpunit; /******************************************************************************************************************** * $Id$ * * Copyright (c) 2000, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ import java.io.*; import java.net.*; import org.xml.sax.*; import org.w3c.dom.*; /** * A response from a web server to an Http request. **/ public class WebResponse { /** * Returns the forms found in the page in the order in which they appear. * @exception SAXException thrown if there is an error parsing the response. **/ public WebForm[] getForms() throws SAXException { return getReceivedPage().getForms(); } /** * Returns the links found in the page in the order in which they appear. * @exception SAXException thrown if there is an error parsing the response. **/ public WebLink[] getLinks() throws SAX! Exception { return getReceivedPage().getLinks(); } /** * Returns the first link which contains the specified text. **/ public WebLink getLinkWith( String text ) throws SAXException { return getReceivedPage().getLinkWith( text ); } /** * Returns the first link which contains an image with the specified text as its 'alt' attribute. **/ public WebLink getLinkWithImageText( String text ) throws SAXException { return getReceivedPage().getLinkWithImageText( text ); } /** * Returns the top-level tables found in this page in the order in which * they appear. * @exception SAXException thrown if there is an error parsing the response. **/ public WebTable[] getTables() throws SAXException { return getReceivedPage().getTables(); } /** * Returns a copy of the domain object model tree associated with this response. * @exception SAXException thrown if there is an error parsing the response. **/ public Document getDOM() throws SAXException { return (Document) getReceivedPage().getDOM(); } /** * Returns the first table in the response which has the specified text in its first non-blank row and * non-blank column. Will recurse into any nested tables, as needed. * @exception SAXException thrown if there is an error parsing the response. * @return the selected table, or null if none is found **/ public WebTable getTableStartingWith( String text ) throws SAXException { return getReceivedPage().getTableStartingWith( text ); } public String toString() { return _responseText; } //---------------------------------- package members -------------------------------- /** * Constructs a response object from an input stream. * @param conversation the web conversation which received the response * @param url the url from which the response was received * @param inputStream the input str! eam from which the response can be read **/ WebResponse( WebConversation conversation, URL url, InputStream inputStream ) throws IOException { _conversation = conversation; _url = url; StringBuffer sb = new StringBuffer(); BufferedReader input = new BufferedReader( new InputStreamReader( inputStream ) ); String str; while (null != ((str = input.readLine()))) { sb.append( str ).append( endOfLine ); } input.close (); _responseText = sb.toString(); } /** * Returns the web conversation of which this response is a part, and which contains the session * context information required for further requests. **/ WebConversation getWebConversation() { return _conversation; } //--------------------------------- private members -------------------------------------- final private static String endOfLine = System.getProperty( "line.separator" ); private ReceivedPage _page; private String _responseText; private URL _url; private WebConversation _conversation; private ReceivedPage getReceivedPage() throws SAXException { if (_page == null) { _page = new ReceivedPage( _url, _responseText ); } return _page; } } \ No newline at end of file --- 1 ---- ! package com.meterware.httpunit; /******************************************************************************************************************** * $Id$ * * Copyright (c) 2000, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ import java.io.*; import java.net.*; import org.xml.sax.*; import org.w3c.dom.*; /** * A response from a web server to an Http request. **/ public class WebResponse { /** * Returns the forms found in the page in the order in which they appear. * @exception SAXException thrown if there is an error parsing the response. **/ public WebForm[] getForms() throws SAXException { return getReceivedPage().getForms(); } /** * Returns the links found in the page in the order in which they appear. * @exception SAXException thrown if there is an error parsing the response. **/ public WebLink[] getLinks() throws SAX! Exception { return getReceivedPage().getLinks(); } /** * Returns the first link which contains the specified text. **/ public WebLink getLinkWith( String text ) throws SAXException { return getReceivedPage().getLinkWith( text ); } /** * Returns the first link which contains an image with the specified text as its 'alt' attribute. **/ public WebLink getLinkWithImageText( String text ) throws SAXException { return getReceivedPage().getLinkWithImageText( text ); } /** * Returns the top-level tables found in this page in the order in which * they appear. * @exception SAXException thrown if there is an error parsing the response. **/ public WebTable[] getTables() throws SAXException { return getReceivedPage().getTables(); } /** * Returns a copy of the domain object model tree associated with this response. * @exception SAXException thrown if there is an error parsing the response. **/ public Document getDOM() throws SAXException { return (Document) getReceivedPage().getDOM(); } /** * Returns the first table in the response which has the specified text in its first non-blank row and * non-blank column. Will recurse into any nested tables, as needed. * @exception SAXException thrown if there is an error parsing the response. * @return the selected table, or null if none is found **/ public WebTable getTableStartingWith( String text ) throws SAXException { return getReceivedPage().getTableStartingWith( text ); } public String toString() { return _responseText; } //---------------------------------- package members -------------------------------- /** * Constructs a response object from an input stream. * @param conversation the web conversation which received the response * @param url the url from which the response was received * @param inputStream the input str! eam from which the response can be read **/ WebResponse( WebConversation conversation, URL url, InputStream inputStream ) { _conversation = conversation; _url = url; StringBuffer sb = new StringBuffer(); try { BufferedReader input = new BufferedReader( new InputStreamReader( inputStream ) ); String str; while (null != ((str = input.readLine()))) { sb.append( str ).append( endOfLine ); } input.close (); _responseText = sb.toString(); } catch (IOException e) { throw new RuntimeException( "Unable to retrieve URL: " + _url.toExternalForm() ); } } /** * Returns the web conversation of which this response is a part, and which contains the session * context information required for further requests. **/ WebConversation getWebConversation() { return _conversation; } //--------------------------------- private members -------------------------------------- final private static String endOfLine = System.getProperty( "line.separator" ); private ReceivedPage _page; private String _responseText; private URL _url; private WebConversation _conversation; private ReceivedPage getReceivedPage() throws SAXException { if (_page == null) { _page = new ReceivedPage( _url, _responseText ); } return _page; } } \ No newline at end of file |