httpunit-commit Mailing List for httpunit (Page 80)
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-10-02 16:31:40
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv619/src/com/meterware/httpunit Modified Files: WebRequest.java Log Message: Correct https support Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- WebRequest.java 2000/09/28 18:27:39 1.6 +++ WebRequest.java 2000/10/02 16:31:36 1.7 @@ -70,12 +70,20 @@ * Returns the final URL associated with this web request. **/ public URL getURL() throws MalformedURLException { - if (getURLBase() == null) validateProtocol( getURLString() ); + if (getURLBase() == null || getURLString().indexOf( ':' ) > 0) validateProtocol( getURLString() ); return new URL( getURLBase(), getURLString() ); } + /** + * Returns the target for this web request. + **/ + public String getTarget() { + return _target; + } + + //------------------------------------- protected members ------------------------------------ @@ -91,17 +99,34 @@ * Constructs a web request using a base URL and a relative URL string. **/ protected WebRequest( URL urlBase, String urlString ) { - this( urlBase, urlString, null ); + this( urlBase, urlString, (WebForm) null ); } /** + * Constructs a web request using a base URL, a relative URL string, and a target. + **/ + protected WebRequest( URL urlBase, String urlString, String target ) { + this( urlBase, urlString, target, null ); + } + + + /** * Constructs a web request using a base URL and a relative URL string. **/ protected WebRequest( URL urlBase, String urlString, WebForm sourceForm ) { + this( urlBase, urlString, TOP_FRAME, sourceForm ); + } + + + /** + * Constructs a web request using a base URL and a relative URL string. + **/ + protected WebRequest( URL urlBase, String urlString, String target, WebForm sourceForm ) { _urlBase = urlBase; _urlString = urlString; _sourceForm = sourceForm; + _target = target; } @@ -109,7 +134,7 @@ * Constructs a web request using a base request and a relative URL string. **/ protected WebRequest( WebRequest baseRequest, String urlString ) throws MalformedURLException { - this( baseRequest.getURL(), urlString, null ); + this( baseRequest.getURL(), urlString, (WebForm) null ); } @@ -153,14 +178,29 @@ } +//---------------------------------- package members -------------------------------- + + /** The name of the topmost frame. **/ + final static String TOP_FRAME = "_top"; + + //--------------------------------------- private members ------------------------------------ + + /** The name of the system parameter used by java.net to locate protocol handlers. **/ + private final static String PROTOCOL_HANDLER_PKGS = "java.protocol.handler.pkgs"; + + /** The name of the JSSE class which provides support for SSL. **/ + private final static String SunJSSE_PROVIDER_CLASS = "com.sun.net.ssl.internal.ssl.Provider"; + + /** The name of the JSSE class which supports the https protocol. **/ + private final static String SSL_PROTOCOL_HANDLER = "com.sun.net.ssl.internal.www.protocol"; - private final static String PROTOCOL_HANDLER_PKGS = "java.protocol.handler.pkgs"; private URL _urlBase; private String _urlString; private Hashtable _parameters = new Hashtable(); private WebForm _sourceForm; + private String _target = TOP_FRAME; private boolean _httpsProtocolSupportEnabled; @@ -233,32 +273,24 @@ } - private static boolean hasSSLProvider() { + private static boolean hasProvider( Class providerClass ) { Provider[] list = Security.getProviders(); for (int i = 0; i < list.length; i++) { - if (list[i].getClass().getName().equals( SunJSSE_PROVIDER_CLASS )) return true; + if (list[i].getClass().equals( providerClass )) return true; } return false; } - private static String SunJSSE_PROVIDER_CLASS = "com.sun.net.ssl.internal.ssl.Provider"; - private static RuntimeException _httpsProblem; - - - static void verifyHttpsSupport() { + private static void verifyHttpsSupport() { if (System.getProperty( "java.version" ).startsWith( "1.1" )) { throw new RuntimeException( "https support requires Java 2" ); - } else if (System.getProperty( PROTOCOL_HANDLER_PKGS ) == null) { + } else { try { - Class.forName( "com.sun.net.ssl.HttpsURLConnection" ); - Method setMethod = System.class.getMethod( "setProperty", new Class[] { String.class, String.class } ); - setMethod.invoke( null, new String[] { PROTOCOL_HANDLER_PKGS, "com.sun.net.ssl.internal.www.protocol" } ); - if (!hasSSLProvider()) { - throw new RuntimeException( "https support not enabled. Please edit <java-home>/lib/security/java.security to add the line: " + - "security.provider.2=com.sun.net.ssl.internal.ssl.Provider" ); - } + Class providerClass = Class.forName( SunJSSE_PROVIDER_CLASS ); + if (!hasProvider( providerClass )) Security.addProvider( (Provider) providerClass.newInstance() ); + registerSSLProtocolHandler(); } catch (ClassNotFoundException e) { - throw new RuntimeException( "https support requires the Java Secure Sockets Extension. See http://java.sun.com/products/jsse/install.html" ); + throw new RuntimeException( "https support requires the Java Secure Sockets Extension. See http://java.sun.com/products/jsse" ); } catch (Throwable e) { throw new RuntimeException( "Unable to enable https support. Make sure that you have installed JSSE " + "as described in http://java.sun.com/products/jsse/install.html: " + e ); @@ -267,18 +299,18 @@ } - // this does not work for some reason - static void unusedSetProviderDynamically() throws ClassNotFoundException, InstantiationException, IllegalAccessException { - Security.addProvider( (Provider) Class.forName( SunJSSE_PROVIDER_CLASS ).newInstance() ); + private static void registerSSLProtocolHandler() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + String list = System.getProperty( PROTOCOL_HANDLER_PKGS ); + Method setMethod = System.class.getMethod( "setProperty", new Class[] { String.class, String.class } ); + if (list == null || list.length() == 0) { + setMethod.invoke( null, new String[] { PROTOCOL_HANDLER_PKGS, SSL_PROTOCOL_HANDLER } ); + } else if (list.indexOf( SSL_PROTOCOL_HANDLER ) < 0) { + setMethod.invoke( null, new String[] { PROTOCOL_HANDLER_PKGS, SSL_PROTOCOL_HANDLER + " | " + list } ); + } } } - - - - - //================================ exception class NoSuchParameterException ========================================= |
From: Russell G. <rus...@us...> - 2000-09-28 18:27:42
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv13592/src/com/meterware/httpunit Modified Files: GetMethodWebRequest.java PostMethodWebRequest.java WebConversation.java WebRequest.java Log Message: Added https support Index: GetMethodWebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/GetMethodWebRequest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- GetMethodWebRequest.java 2000/09/15 16:38:44 1.3 +++ GetMethodWebRequest.java 2000/09/28 18:27:39 1.4 @@ -44,15 +44,6 @@ } - public URL getURL() throws MalformedURLException { - if (hasNoParameters()) { - return new URL( getURLBase(), getURLString() ); - } else { - return new URL( getURLBase(), getURLString() + "?" + getParameterString() ); - } - } - - //--------------------------------------- package members --------------------------------------------- @@ -61,6 +52,18 @@ **/ GetMethodWebRequest( URL urlBase, String urlString, WebForm sourceForm ) { super( urlBase, urlString, sourceForm ); + } + + +//------------------------------------- protected members --------------------------------------------- + + + protected String getURLString() { + if (hasNoParameters()) { + return super.getURLString(); + } else { + return super.getURLString() + "?" + getParameterString(); + } } Index: PostMethodWebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/PostMethodWebRequest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- PostMethodWebRequest.java 2000/09/15 16:38:44 1.4 +++ PostMethodWebRequest.java 2000/09/28 18:27:39 1.5 @@ -43,11 +43,6 @@ //---------------------------------- WebRequest methods -------------------------------- - public URL getURL() throws MalformedURLException { - return new URL( getURLBase(), getURLString() ); - } - - protected void completeRequest( URLConnection connection ) throws IOException { connection.setDoInput( true ); connection.setDoOutput( true ); Index: WebConversation.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- WebConversation.java 2000/09/27 18:04:04 1.9 +++ WebConversation.java 2000/09/28 18:27:39 1.10 @@ -200,12 +200,6 @@ RedirectWebRequest( WebRequest baseRequest, String relativeURL ) throws MalformedURLException { super( baseRequest, relativeURL ); - } - - - public URL getURL() throws MalformedURLException { - return new URL( getURLBase(), getURLString() ); - } - + } } Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- WebRequest.java 2000/09/15 16:38:44 1.5 +++ WebRequest.java 2000/09/28 18:27:39 1.6 @@ -3,6 +3,9 @@ import java.io.*; import java.net.*; import java.util.*; +import java.lang.reflect.*; +import java.security.Provider; +import java.security.Security; /** * A request sent to a web server. @@ -66,8 +69,10 @@ /** * Returns the final URL associated with this web request. **/ - abstract - public URL getURL() throws MalformedURLException; + public URL getURL() throws MalformedURLException { + if (getURLBase() == null) validateProtocol( getURLString() ); + return new URL( getURLBase(), getURLString() ); + } @@ -121,7 +126,6 @@ } - final protected String getURLString() { return _urlString; } @@ -151,12 +155,16 @@ //--------------------------------------- private members ------------------------------------ + private final static String PROTOCOL_HANDLER_PKGS = "java.protocol.handler.pkgs"; + private URL _urlBase; private String _urlString; private Hashtable _parameters = new Hashtable(); private WebForm _sourceForm; + private boolean _httpsProtocolSupportEnabled; + private void appendParameters( StringBuffer sb, String name, String[] values, boolean moreToCome ) { for (int i = 0; i < values.length; i++) { appendParameter( sb, name, values[i], (i < values.length-1 || moreToCome ) ); @@ -197,7 +205,80 @@ } + private void validateProtocol( String urlString ) { + String protocol = urlString.substring( 0, urlString.indexOf( ':' ) ); + if (protocol.length() == 0) { + throw new RuntimeException( "No protocol specified in URL '" + urlString + "'" ); + } else if (protocol.equalsIgnoreCase( "http" )) { + return; + } else if (protocol.equalsIgnoreCase( "https" )) { + validateHttpsProtocolSupport(); + } + } + + + void validateHttpsProtocolSupport() { + if (!_httpsProtocolSupportEnabled) { + verifyHttpsSupport(); + _httpsProtocolSupportEnabled = true; + } + } + + + private static void listProviders() { + Provider[] list = Security.getProviders(); + for (int i = 0; i < list.length; i++) { + System.out.println( "provider" + i + "=" + list[i] ); + } + } + + + private static boolean hasSSLProvider() { + Provider[] list = Security.getProviders(); + for (int i = 0; i < list.length; i++) { + if (list[i].getClass().getName().equals( SunJSSE_PROVIDER_CLASS )) return true; + } + return false; + } + + private static String SunJSSE_PROVIDER_CLASS = "com.sun.net.ssl.internal.ssl.Provider"; + private static RuntimeException _httpsProblem; + + + static void verifyHttpsSupport() { + if (System.getProperty( "java.version" ).startsWith( "1.1" )) { + throw new RuntimeException( "https support requires Java 2" ); + } else if (System.getProperty( PROTOCOL_HANDLER_PKGS ) == null) { + try { + Class.forName( "com.sun.net.ssl.HttpsURLConnection" ); + Method setMethod = System.class.getMethod( "setProperty", new Class[] { String.class, String.class } ); + setMethod.invoke( null, new String[] { PROTOCOL_HANDLER_PKGS, "com.sun.net.ssl.internal.www.protocol" } ); + if (!hasSSLProvider()) { + throw new RuntimeException( "https support not enabled. Please edit <java-home>/lib/security/java.security to add the line: " + + "security.provider.2=com.sun.net.ssl.internal.ssl.Provider" ); + } + } catch (ClassNotFoundException e) { + throw new RuntimeException( "https support requires the Java Secure Sockets Extension. See http://java.sun.com/products/jsse/install.html" ); + } catch (Throwable e) { + throw new RuntimeException( "Unable to enable https support. Make sure that you have installed JSSE " + + "as described in http://java.sun.com/products/jsse/install.html: " + e ); + } + } + } + + + // this does not work for some reason + static void unusedSetProviderDynamically() throws ClassNotFoundException, InstantiationException, IllegalAccessException { + Security.addProvider( (Provider) Class.forName( SunJSSE_PROVIDER_CLASS ).newInstance() ); + } + + } + + + + + //================================ exception class NoSuchParameterException ========================================= |
From: Russell G. <rus...@us...> - 2000-09-28 18:27:42
|
Update of /cvsroot/httpunit/httpunit/doc In directory slayer.i.sourceforge.net:/tmp/cvs-serv13592/doc Modified Files: release notes.txt todo.txt Log Message: Added https support ***** Bogus filespec: release Index: todo.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/todo.txt,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- todo.txt 2000/09/01 14:54:01 1.2 +++ todo.txt 2000/09/28 18:27:39 1.3 @@ -1,5 +1,4 @@ -o Add simulated http server for unit testing o Support Frames -o Support digest HTTP Authentication +o Support digest HTTP Authentication (?) o Documentation, Documentation |
From: Russell G. <rus...@us...> - 2000-09-28 18:27:42
|
Update of /cvsroot/httpunit/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv13592 Modified Files: build.xml Log Message: Added https support Index: build.xml =================================================================== RCS file: /cvsroot/httpunit/httpunit/build.xml,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- build.xml 2000/09/11 14:23:46 1.11 +++ build.xml 2000/09/28 18:27:39 1.12 @@ -10,7 +10,8 @@ <property name="src.dir" value="src" /> <property name="tstsrc.dir" value="test" /> <property name="examples.dir" value="examples" /> - <property name="lib.dir" value="lib" /> + <property name="lib.dir" value="lib" /> + <property name="jars.dir" value="" /> <property name="docs.dir" value="doc" /> <property name="build.dir" value="build" /> <property name="build.classes" value="${build.dir}/classes" /> @@ -98,7 +99,8 @@ <copydir src="${src.dir}" dest="${dist.dir}/src" /> <copydir src="${tstsrc.dir}" dest="${dist.dir}/test" includes="**/httpunit/*" /> <copydir src="${examples.dir}" dest="${dist.dir}/examples" /> - <copydir src="${lib.dir}" dest="${dist.dir}/lib" /> + <copydir src="${lib.dir}" dest="${dist.dir}/lib" /> + <copydir src="${jars.dir}" dest="${dist.dir}/lib" includes="Tidy.jar" /> <copyfile src="build.xml" dest="${dist.dir}/build.xml" /> <copydir src="${docs.dir}" dest="${dist.dir}/doc" /> <copyfile src="readme.txt" dest="${dist.dir}/readme.txt" /> |
From: Russell G. <rus...@us...> - 2000-09-27 18:04:10
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv4362/test/com/meterware/httpunit Modified Files: FormParametersTest.java HtmlTablesTest.java HttpUnitTest.java WebFormTest.java WebLinkTest.java WebPageTest.java Added Files: PseudoServer.java PseudoServerTest.java Log Message: Added pseudo-server to test server-response handling ***** Error reading new file(2, 'No such file or directory') ***** Error reading new file(2, 'No such file or directory') Index: FormParametersTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FormParametersTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- FormParametersTest.java 2000/09/25 21:28:45 1.2 +++ FormParametersTest.java 2000/09/27 18:04:04 1.3 @@ -49,15 +49,18 @@ public void setUp() throws Exception { + super.setUp(); + _wc = new WebConversation(); } public void testDisabledChoiceParameterValidation() throws Exception { - ReceivedPage page = new ReceivedPage( _baseURL, HEADER + "<body><form method=GET action = \"/ask\">" + + defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<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>" ); + "</form>" ); + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); WebRequest request = page.getForms()[0].getRequest(); HttpUnitOptions.setParameterValuesValidated( false ); request.setParameter( "noSuchControl", "green" ); @@ -70,11 +73,12 @@ public void testEnabledChoiceParameterValidation() throws Exception { - ReceivedPage page = new ReceivedPage( _baseURL, HEADER + "<body><form method=GET action = \"/ask\">" + + defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<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>" ); + "</form>" ); + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); WebRequest request = page.getForms()[0].getRequest(); HttpUnitOptions.setParameterValuesValidated( true ); validateSetParameterRejected( request, "noSuchControl", "green", "setting of non-existent control" ); @@ -94,11 +98,12 @@ public void testDisabledTextParameterValidation() throws Exception { - ReceivedPage page = new ReceivedPage( _baseURL, HEADER + "<body><form method=GET action = \"/ask\">" + + defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=text name=color>" + "<Input type=password name=password>" + "<Input type=hidden name=secret>" + - "</form></body></html>" ); + "</form>" ); + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); WebRequest request = page.getForms()[0].getRequest(); HttpUnitOptions.setParameterValuesValidated( false ); request.setParameter( "color", "green" ); @@ -111,11 +116,12 @@ public void testEnabledTextParameterValidation() throws Exception { - ReceivedPage page = new ReceivedPage( _baseURL, HEADER + "<body><form method=GET action = \"/ask\">" + + defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=text name=color>" + "<Input type=password name=password>" + "<Input type=hidden name=secret>" + - "</form></body></html>" ); + "</form>" ); + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); WebRequest request = page.getForms()[0].getRequest(); HttpUnitOptions.setParameterValuesValidated( true ); request.setParameter( "color", "green" ); @@ -128,11 +134,12 @@ public void testDisabledRadioButtonValidation() throws Exception { - ReceivedPage page = new ReceivedPage( _baseURL, HEADER + "<body><form method=GET action = \"/ask\">" + + defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=radio name=color value=red>" + "<Input type=radio name=color value=blue>" + "<Input type=radio name=color value=green>" + - "</form></body></html>" ); + "</form>" ); + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); WebRequest request = page.getForms()[0].getRequest(); HttpUnitOptions.setParameterValuesValidated( false ); request.setParameter( "color", "black" ); @@ -141,11 +148,12 @@ public void testEnabledRadioButtonValidation() throws Exception { - ReceivedPage page = new ReceivedPage( _baseURL, HEADER + "<body><form method=GET action = \"/ask\">" + + defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=radio name=color value=red>" + "<Input type=radio name=color value=blue>" + "<Input type=radio name=color value=green>" + - "</form></body></html>" ); + "</form>" ); + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); WebRequest request = page.getForms()[0].getRequest(); HttpUnitOptions.setParameterValuesValidated( true ); request.setParameter( "color", "red" ); @@ -156,11 +164,12 @@ public void testCheckboxValidation() throws Exception { - ReceivedPage page = new ReceivedPage( _baseURL, HEADER + "<body><form method=GET action = \"/ask\">" + + defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=checkbox name=use_color>" + "<Input type=checkbox name=color value=red>" + "<Input type=checkbox name=color value=blue>" + - "</form></body></html>" ); + "</form>" ); + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); WebRequest request = page.getForms()[0].getRequest(); HttpUnitOptions.setParameterValuesValidated( false ); request.setParameter( "use_color", "red" ); @@ -180,6 +189,9 @@ //---------------------------------------------- private members ------------------------------------------------ + private WebConversation _wc; + + private void validateSetParameterRejected( WebRequest request, String parameterName, String value, String comment ) throws Exception { try { request.setParameter( parameterName, value ); @@ -196,16 +208,4 @@ } catch (IllegalRequestParameterException e) { } } - - - private static URL _baseURL; - - static { - try { - _baseURL = new URL( "http://www.meterware.com" ); - } catch (java.net.MalformedURLException e ) {} // ignore - } - - private final static String HEADER = "<html><head><title>A Sample Page</title></head>"; - } Index: HtmlTablesTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HtmlTablesTest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- HtmlTablesTest.java 2000/09/25 21:30:24 1.8 +++ HtmlTablesTest.java 2000/09/27 18:04:04 1.9 @@ -29,76 +29,64 @@ /** * A unit test of the httpunit parsing classes. **/ -public class HtmlTablesTest extends TestCase { +public class HtmlTablesTest extends HttpUnitTest { - public static void main(String args[]) { + public static void main(String args[]) { junit.textui.TestRunner.run( suite() ); - } + } - public static Test suite() { - return new TestSuite( HtmlTablesTest.class ); - } + public static Test suite() { + return new TestSuite( HtmlTablesTest.class ); + } - public HtmlTablesTest( String name ) { - super( name ); - } + public HtmlTablesTest( String name ) { + super( name ); + } public void setUp() throws Exception { - _baseURL = new URL( "http://www.meterware.com" ); - _noTables = new ReceivedPage( _baseURL, HEADER + "<body>This has no tables but it does" + - "have <a href=\"/other.html\">an active link</A>" + - " and <a name=here>an anchor</a>" + - "</body></html>" ); - _oneTable = new ReceivedPage( _baseURL, HEADER + "<body><h2>Interesting data</h2>" + - "<table summary=\"tough luck\">" + - "<tr><td>One</td><td> </td><td>1</td></tr>" + - "<tr><td colspan=3><IMG SRC=\"/images/spacer.gif\" ALT=\"\" WIDTH=1 HEIGHT=1></td></tr>" + - "<tr><td>Two</td><td> </td><td>2</td></tr>" + - "<tr><td colspan=3><IMG SRC=\"/images/spacer.gif\" ALT=\"\" WIDTH=1 HEIGHT=1></td></tr>" + - "<tr><td>Three</td><td> </td><td>3</td></tr>" + - "</table></body></html>" ); - _nestTable = new ReceivedPage( _baseURL, HEADER + "<body><h2>Interesting data</h2>" + - "<table summary=\"outer one\">" + - "<tr><td>" + - "Inner Table<br>" + - "<table summary=\"inner one\">" + - " <tr><td>Red</td><td>1</td></tr>" + - " <tr><td>Blue</td><td>2</td></tr>" + - "</table></td></tr>" + - "</table></body></html>" ); - _spanTable = new ReceivedPage( _baseURL, HEADER + "<body><h2>Interesting data</h2>" + - "<table summary=\"tough luck\">" + - "<tr><th colspan=2>Colors</th><th>Names</th></tr>" + - "<tr><td>Red</td><td rowspan=\"2\"><b>gules</b></td><td>rot</td></tr>" + - "<tr><td>Green</td><td><a href=\"nowhere\">vert</a></td></tr>" + - "</table></body></html>" ); - _badTable = new ReceivedPage( _baseURL, HEADER + "<body><h2>Interesting data</h2>" + - "<table summary=\"tough luck\">" + - "<tr><th colspan=2>Colors</th><th>Names</th></tr>" + - "<tr><td>Red</td><td rowspan=\"2\"><b>gules</b></td></tr>" + - "<tr><td>Green</td><td><a href=\"nowhere\">vert</a></td></tr>" + - "</table></body></html>" ); + super.setUp(); + _wc = new WebConversation(); + + defineWebPage( "OneTable", "<h2>Interesting data</h2>" + + "<table summary=\"tough luck\">" + + "<tr><td>One</td><td> </td><td>1</td></tr>" + + "<tr><td colspan=3><IMG SRC=\"/images/spacer.gif\" ALT=\"\" WIDTH=1 HEIGHT=1></td></tr>" + + "<tr><td>Two</td><td> </td><td>2</td></tr>" + + "<tr><td colspan=3><IMG SRC=\"/images/spacer.gif\" ALT=\"\" WIDTH=1 HEIGHT=1></td></tr>" + + "<tr><td>Three</td><td> </td><td>3</td></tr>" + + "</table>" ); + defineWebPage( "SpanTable", "<h2>Interesting data</h2>" + + "<table summary=\"tough luck\">" + + "<tr><th colspan=2>Colors</th><th>Names</th></tr>" + + "<tr><td>Red</td><td rowspan=\"2\"><b>gules</b></td><td>rot</td></tr>" + + "<tr><td>Green</td><td><a href=\"nowhere\">vert</a></td></tr>" + + "</table>" ); } - public void testFindNoTables() { - WebTable[] tables = _noTables.getTables(); + public void testFindNoTables() throws Exception { + defineWebPage( "Default", "This has no tables but it does" + + "have <a href=\"/other.html\">an active link</A>" + + " and <a name=here>an anchor</a>" ); + + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); + WebTable[] tables = page.getTables(); assertNotNull( tables ); assertEquals( 0, tables.length ); } - public void testFindOneTable() { - WebTable[] tables = _oneTable.getTables(); + public void testFindOneTable() throws Exception { + WebTable[] tables = _wc.getResponse( getHostPath() + "/OneTable.html" ).getTables(); assertEquals( 1, tables.length ); } - public void testFindTableSize() { - WebTable table = _oneTable.getTables()[0]; + public void testFindTableSize() throws Exception { + WebTable table = _wc.getResponse( getHostPath() + "/OneTable.html" ).getTables()[0]; assertEquals( 5, table.getRowCount() ); assertEquals( 3, table.getColumnCount() ); try { @@ -114,15 +102,15 @@ } - public void testFindTableCell() { - WebTable table = _oneTable.getTables()[0]; + public void testFindTableCell() throws Exception { + WebTable table = _wc.getResponse( getHostPath() + "/OneTable.html" ).getTables()[0]; assertEquals( "Two", table.getCellAsText( 2, 0 ) ); assertEquals( "3", table.getCellAsText( 4, 2 ) ); } - public void testTableAsText() { - WebTable table = _oneTable.getTables()[0]; + public void testTableAsText() throws Exception { + WebTable table = _wc.getResponse( getHostPath() + "/OneTable.html" ).getTables()[0]; table.purgeEmptyCells(); String[][] text = table.asText(); assertEquals( "rows with text", 3, text.length ); @@ -133,8 +121,19 @@ - public void testNestedTable() { - WebTable[] tables = _nestTable.getTables(); + public void testNestedTable() throws Exception { + defineWebPage( "Default", "<h2>Interesting data</h2>" + + "<table summary=\"outer one\">" + + "<tr><td>" + + "Inner Table<br>" + + "<table summary=\"inner one\">" + + " <tr><td>Red</td><td>1</td></tr>" + + " <tr><td>Blue</td><td>2</td></tr>" + + "</table></td></tr>" + + "</table>" ); + + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); + WebTable[] tables = page.getTables(); assertEquals( "top level tables count", 1, tables.length ); assertEquals( "rows", 1, tables[0].getRowCount() ); assertEquals( "columns", 1, tables[0].getColumnCount() ); @@ -149,24 +148,36 @@ } - public void testColumnSpan() { - WebTable table = _spanTable.getTables()[0]; + public void testColumnSpan() throws Exception { + WebResponse page = _wc.getResponse( getHostPath() + "/SpanTable.html" ); + WebTable table = page.getTables()[0]; assertEquals( "Colors", table.getCellAsText( 0, 0 ) ); assertEquals( "Colors", table.getCellAsText( 0, 1 ) ); assertEquals( "Names", table.getCellAsText( 0, 2 ) ); } + - public void testRowSpan() { - WebTable table = _spanTable.getTables()[0]; + public void testRowSpan() throws Exception { + WebResponse page = _wc.getResponse( getHostPath() + "/SpanTable.html" ); + WebTable table = page.getTables()[0]; assertEquals( 3, table.getRowCount() ); assertEquals( 3, table.getColumnCount() ); assertEquals( "gules", table.getCellAsText( 1, 1 ) ); assertEquals( "gules", table.getCellAsText( 2, 1 ) ); assertEquals( "vert", table.getCellAsText( 2, 2 ) ); } + - public void testMissingColumns() { - WebTable table = _badTable.getTables()[0]; + public void testMissingColumns() throws Exception { + defineWebPage( "Default", "<h2>Interesting data</h2>" + + "<table summary=\"tough luck\">" + + "<tr><th colspan=2>Colors</th><th>Names</th></tr>" + + "<tr><td>Red</td><td rowspan=\"2\"><b>gules</b></td></tr>" + + "<tr><td>Green</td><td><a href=\"nowhere\">vert</a></td></tr>" + + "</table>" ); + + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); + WebTable table = page.getTables()[0]; table.purgeEmptyCells(); assertEquals( 3, table.getRowCount() ); assertEquals( 3, table.getColumnCount() ); @@ -174,25 +185,26 @@ public void testInnerTableSeek() throws Exception { - ReceivedPage rp = new ReceivedPage( _baseURL, HEADER + "<body><h2>Interesting data</h2>" + - "<table summary=\"outer one\">" + - "<tr><td>Here we are</td><td>" + - "Inner Table<br>" + - "<table summary=\"inner one\">" + - " <tr><td colspan=2> </td></tr>" + - " <tr><td>Red</td><td>1</td></tr>" + - " <tr><td>Blue</td><td>2</td></tr>" + - "</table></td></tr>" + - "</table></body></html>" ); + defineWebPage( "Default", "<h2>Interesting data</h2>" + + "<table summary=\"outer one\">" + + "<tr><td>Here we are</td><td>" + + "Inner Table<br>" + + "<table summary=\"inner one\">" + + " <tr><td colspan=2> </td></tr>" + + " <tr><td>Red</td><td>1</td></tr>" + + " <tr><td>Blue</td><td>2</td></tr>" + + "</table></td></tr>" + + "</table>" ); - WebTable wt = rp.getTableStartingWith( "Red" ); + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); + WebTable wt = page.getTableStartingWith( "Red" ); assertNotNull( "Did not find table starting with 'Red'", wt ); String[][] cells = wt.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] ); - wt = rp.getTableStartingWithPrefix( "Re" ); + wt = page.getTableStartingWithPrefix( "Re" ); assertNotNull( "Did not find table starting with prefix 'Re'", wt ); cells = wt.asText(); assertEquals( "Non-blank rows", 2, cells.length ); @@ -202,14 +214,15 @@ public void testSpanOverEmptyColumns() throws Exception { - ReceivedPage rp = new ReceivedPage( _baseURL, HEADER + "<body><h2>Interesting data</h2>" + - "<table summary=little>" + - "<tr><td colspan=2>Title</td><td>Data</td></tr>" + - "<tr><td>Name</td><td> </td><td>Value</td></tr>" + - "<tr><td>Name</td><td> </td><td>Value</td></tr>" + - "</table></body></html>" ); + defineWebPage( "Default", "<h2>Interesting data</h2>" + + "<table summary=little>" + + "<tr><td colspan=2>Title</td><td>Data</td></tr>" + + "<tr><td>Name</td><td> </td><td>Value</td></tr>" + + "<tr><td>Name</td><td> </td><td>Value</td></tr>" + + "</table>" ); - String[][] cells = rp.getTableStartingWith( "Title" ).asText(); + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); + String[][] cells = page.getTableStartingWith( "Title" ).asText(); assertEquals( "Non-blank rows", 3, cells.length ); assertEquals( "Non-blank columns", 2, cells[0].length ); assertEquals( "cell at 1,1", "Value", cells[1][1] ); @@ -217,26 +230,20 @@ public void testSpanOverAllEmptyColumns() throws Exception { - ReceivedPage rp = new ReceivedPage( _baseURL, HEADER + "<body><h2>Interesting data</h2>" + - "<table summary=little>" + - "<tr><td colspan=2>Title</td><td>Data</td></tr>" + - "<tr><td> </td><td> </td><td>Value</td></tr>" + - "<tr><td> </td><td> </td><td>Value</td></tr>" + - "</table></body></html>" ); + defineWebPage( "Default", "<h2>Interesting data</h2>" + + "<table summary=little>" + + "<tr><td colspan=2>Title</td><td>Data</td></tr>" + + "<tr><td> </td><td> </td><td>Value</td></tr>" + + "<tr><td> </td><td> </td><td>Value</td></tr>" + + "</table>" ); - String[][] cells = rp.getTableStartingWith( "Title" ).asText(); + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); + String[][] cells = page.getTableStartingWith( "Title" ).asText(); assertEquals( "Non-blank rows", 3, cells.length ); assertEquals( "Non-blank columns", 2, cells[0].length ); assertEquals( "cell at 1,1", "Value", cells[1][1] ); } - - private final static String HEADER = "<html><head><title>A Sample Page</title></head>"; - private ReceivedPage _noTables; - private ReceivedPage _oneTable; - private ReceivedPage _nestTable; - private ReceivedPage _spanTable; - private ReceivedPage _badTable; - private URL _baseURL; + private WebConversation _wc; } Index: HttpUnitTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- HttpUnitTest.java 2000/08/08 20:10:49 1.5 +++ HttpUnitTest.java 2000/09/27 18:04:04 1.6 @@ -20,6 +20,36 @@ } + public void setUp() throws Exception { + _server = new PseudoServer(); + _hostPath = "http://localhost:" + _server.getConnectedPort(); + } + + + public void tearDown() { + if (_server != null) _server.shutDown(); + } + + +//--------------------------------- protected members ---------------------------------------------- + + + protected void defineResource( String resourceName, String value ) { + _server.setResource( resourceName, value ); + } + + + protected void defineWebPage( String pageName, String body ) { + defineResource( pageName + ".html", "<html><head><title>" + pageName + "</title></head>\n" + + "<body>" + body + "</body></html>" ); + } + + + protected String getHostPath() { + return _hostPath; + } + + protected void assertMatchingSet( String comment, Object[] expected, Object[] found ) { Vector expectedItems = new Vector(); Vector foundItems = new Vector(); @@ -56,5 +86,12 @@ sb.append( "}" ); return sb.toString(); } + + +//---------------------------------------- private members ----------------------------------------- + + private String _hostPath; + + private PseudoServer _server; } Index: WebFormTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFormTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- WebFormTest.java 2000/09/25 21:28:45 1.4 +++ WebFormTest.java 2000/09/27 18:04:04 1.5 @@ -30,58 +30,39 @@ public void setUp() throws Exception { - _noForms = new ReceivedPage( _baseURL, HEADER + "<body>This has no forms but it does" + - "have <a href=\"/other.html\">an active link</A>" + - " and <a name=here>an anchor</a>" + - "</body></html>" ); - _oneForm = new ReceivedPage( _baseURL, HEADER + "<body><h2>Login required</h2>" + - "<form method=POST action = \"/servlet/Login\"><B>" + - "Enter the name 'master': <Input type=TEXT Name=name></B>" + - "<input type=\"checkbox\" name=first>Disabled" + - "<input type=\"checkbox\" name=second checked>Enabled" + - "<br><Input type=submit value = \"Log in\">" + - "</form></body></html>" ); - _hidden = new ReceivedPage( _baseURL, HEADER + "<body><h2>Login required</h2>" + - "<form method=POST action = \"/servlet/Login\">" + - "<Input name=\"secret\" type=\"hidden\" value=\"surprise\">" + - "<br><Input name=typeless>" + - "<B>Enter the name 'master': <Input type=TEXT Name=name></B>" + - "<br><Input type=submit value = \"Log in\">" + - "</form></body></html>" ); - _tableForm = new ReceivedPage( _baseURL, HEADER + "<body><h2>Login required</h2>" + - "<form method=POST action = \"/servlet/Login\">" + - "<table summary=\"\"><tr><td>" + - "<B>Enter the name 'master': <Input type=TEXT Name=name></B>" + - "</td><td><Input type=Radio name=sex value=male>Masculine" + - "</td><td><Input type=Radio name=sex value=female checked>Feminine" + - "</td><td><Input type=Radio name=sex value=neuter>Neither" + - "<Input type=submit value = \"Log in\"></tr></table>" + - "</form></body></html>" ); - _selectForm = new ReceivedPage( _baseURL, HEADER + "<body><h2>Login required</h2>" + - "<form method=POST action = \"/servlet/Login\">" + - "<Select name=color><Option>blue<Option selected>red \n" + - "<Option>green</select>" + - "<TextArea name=\"text\">Sample text</TextArea>" + - "</form></body></html>" ); + super.setUp(); + _wc = new WebConversation(); + + defineWebPage( "OneForm", "<h2>Login required</h2>" + + "<form method=POST action = \"/servlet/Login\"><B>" + + "Enter the name 'master': <Input type=TEXT Name=name></B>" + + "<input type=\"checkbox\" name=first>Disabled" + + "<input type=\"checkbox\" name=second checked>Enabled" + + "<br><Input type=submit value = \"Log in\">" + + "</form>" ); } - public void testFindNoForm() { - WebForm[] forms = _noForms.getForms(); + public void testFindNoForm() throws Exception { + defineWebPage( "NoForms", "This has no forms but it does" + + "have <a href=\"/other.html\">an active link</A>" + + " and <a name=here>an anchor</a>" ); + + WebForm[] forms = _wc.getResponse( getHostPath() + "/NoForms.html" ).getForms(); assertNotNull( forms ); assertEquals( 0, forms.length ); } - public void testFindOneForm() { - WebForm[] forms = _oneForm.getForms(); + public void testFindOneForm() throws Exception { + WebForm[] forms = _wc.getResponse( getHostPath() + "/OneForm.html" ).getForms(); assertNotNull( forms ); assertEquals( 1, forms.length ); } - public void testFormParameters() { - WebForm form = _oneForm.getForms()[0]; + public void testFormParameters() throws Exception { + WebForm form = _wc.getResponse( getHostPath() + "/OneForm.html" ).getForms()[0]; String[] parameters = form.getParameterNames(); assertNotNull( parameters ); assertEquals( 3, parameters.length ); @@ -93,29 +74,44 @@ public void testFormRequest() throws Exception { - WebForm form = _oneForm.getForms()[0]; + WebForm form = _wc.getResponse( getHostPath() + "/OneForm.html" ).getForms()[0]; WebRequest request = form.getRequest(); request.setParameter( "name", "master" ); assert( "Should be a post request", !(request instanceof GetMethodWebRequest) ); - assertEquals( "http://www.meterware.com/servlet/Login", request.getURL().toExternalForm() ); + assertEquals( getHostPath() + "/servlet/Login", request.getURL().toExternalForm() ); } - public void testDefaultParameterType() throws Exception { - WebForm form = _hidden.getForms()[0]; + public void testHiddenParameters() throws Exception { + defineWebPage( "Default", "<form method=POST action = \"/servlet/Login\">" + + "<Input name=\"secret\" type=\"hidden\" value=\"surprise\">" + + "<br><Input name=typeless>" + + "<B>Enter the name 'master': <Input type=TEXT Name=name></B>" + + "<br><Input type=submit value = \"Log in\">" + + "</form>" ); + + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); + WebForm form = page.getForms()[0]; assertEquals( 3, form.getParameterNames().length ); - } - - public void testHiddenParameters() throws Exception { - WebForm form = _hidden.getForms()[0]; WebRequest request = form.getRequest(); assertEquals( "surprise", request.getParameter( "secret" ) ); } public void testTableForm() throws Exception { - WebForm form = _tableForm.getForms()[0]; + defineWebPage( "Default", "<form method=POST action = \"/servlet/Login\">" + + "<table summary=\"\"><tr><td>" + + "<B>Enter the name 'master': <Input type=TEXT Name=name></B>" + + "</td><td><Input type=Radio name=sex value=male>Masculine" + + "</td><td><Input type=Radio name=sex value=female checked>Feminine" + + "</td><td><Input type=Radio name=sex value=neuter>Neither" + + "<Input type=submit value = \"Log in\"></tr></table>" + + "</form>" ); + + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); + + WebForm form = page.getForms()[0]; String[] parameterNames = form.getParameterNames(); assertEquals( "Number of parameters", 2, parameterNames.length ); assertEquals( "First parameter name", "name", parameterNames[0] ); @@ -126,7 +122,15 @@ public void testSelect() throws Exception { - WebForm form = _selectForm.getForms()[0]; + defineWebPage( "Default", "<form method=POST action = \"/servlet/Login\">" + + "<Select name=color><Option>blue<Option selected>red \n" + + "<Option>green</select>" + + "<TextArea name=\"text\">Sample text</TextArea>" + + "</form>" ); + + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); + + WebForm form = page.getForms()[0]; String[] parameterNames = form.getParameterNames(); assertEquals( "Number of parameters", 2, parameterNames.length ); assertEquals( "Default color", "red", form.getParameterValue( "color" ) ); @@ -138,11 +142,13 @@ public void testMultiSelect() throws Exception { - ReceivedPage page = new ReceivedPage( _baseURL, HEADER + "<body><form method=GET action = \"/ask\">" + - "<Select multiple size=4 name=colors>" + - "<Option>blue<Option selected>red \n" + - "<Option>green<Option value=\"pink\" selected>salmon</select>" + - "</form></body></html>" ); + defineWebPage( "Default", "<form method=GET action = \"/ask\">" + + "<Select multiple size=4 name=colors>" + + "<Option>blue<Option selected>red \n" + + "<Option>green<Option value=\"pink\" selected>salmon</select>" + + "</form>" ); + + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); WebForm form = page.getForms()[0]; String[] parameterNames = form.getParameterNames(); assertEquals( "num parameters", 1, parameterNames.length ); @@ -152,16 +158,19 @@ assertMatchingSet( "Select values", new String[] { "blue", "red", "green", "pink" }, form.getOptionValues( "colors" ) ); WebRequest request = form.getRequest(); assertMatchingSet( "Request defaults", new String[] { "red", "pink" }, request.getParameterValues( "colors" ) ); - assertEquals( "URL", "http://www.meterware.com/ask?colors=red&colors=pink", request.getURL().toExternalForm() ); + assertEquals( "URL", getHostPath() + "/ask?colors=red&colors=pink", request.getURL().toExternalForm() ); } public void testUnspecifiedDefaults() throws Exception { - ReceivedPage page = new ReceivedPage( _baseURL, HEADER + "<body><form method=GET action = \"/ask\">" + - "<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>" ); + defineWebPage( "Default", "<form method=GET action = \"/ask\">" + + "<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>" ); + + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); + WebForm form = page.getForms()[0]; String[] parameterNames = form.getParameterNames(); assertEquals( "inferred color default", "blue", form.getParameterValue( "colors" ) ); @@ -176,34 +185,23 @@ public void testCheckboxDefaults() throws Exception { - ReceivedPage page = new ReceivedPage( _baseURL, HEADER + "<body><form method=GET action = \"/ask\">" + - "<Input type=checkbox name=ready value=yes checked>" + - "<Input type=checkbox name=color value=red checked>" + - "<Input type=checkbox name=color value=blue checked>" + - "<Input type=checkbox name=gender value=male checked>" + - "<Input type=checkbox name=gender value=female>" + - "</form></body></html>" ); - WebForm form = page.getForms()[0]; + defineWebPage( "Default", "<form method=GET action = \"/ask\">" + + "<Input type=checkbox name=ready value=yes checked>" + + "<Input type=checkbox name=color value=red checked>" + + "<Input type=checkbox name=color value=blue checked>" + + "<Input type=checkbox name=gender value=male checked>" + + "<Input type=checkbox name=gender value=female>" + + "</form>" ); + + WebResponse response = _wc.getResponse( getHostPath() + "/Default.html" ); + assertNotNull( response.getForms() ); + assertEquals( "Num forms in page", 1, response.getForms().length ); + WebForm form = response.getForms()[0]; assertEquals( "ready state", "yes", form.getParameterValue( "ready" ) ); assertMatchingSet( "default genders allowed", new String[] { "male" }, form.getParameterValues( "gender" ) ); assertMatchingSet( "default colors", new String[] { "red", "blue" }, form.getParameterValues( "color" ) ); } - - private static URL _baseURL; - - static { - try { - _baseURL = new URL( "http://www.meterware.com" ); - } catch (java.net.MalformedURLException e ) {} // ignore - } - - private final static String HEADER = "<html><head><title>A Sample Page</title></head>"; - private ReceivedPage _noForms; - private ReceivedPage _oneForm; - private ReceivedPage _hidden; - private ReceivedPage _tableForm; - private ReceivedPage _selectForm; - + private WebConversation _wc; } Index: WebLinkTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebLinkTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- WebLinkTest.java 2000/09/11 14:23:48 1.4 +++ WebLinkTest.java 2000/09/27 18:04:04 1.5 @@ -50,18 +50,27 @@ public void setUp() throws Exception { - _simplePage = new ReceivedPage( _baseURL, HEADER + "<body>This has no forms but it does" + - "have <a href=\"/other.html\">an <b>active</b> link</A>" + - " and <a name=here>an anchor</a>" + - "<a href=\"basic.html\"><IMG SRC=\"/images/arrow.gif\" ALT=\"Next -->\" WIDTH=1 HEIGHT=4></a>" + - "</body></html>" ); + super.setUp(); + defineResource( "SimplePage.html", + "<html><head><title>A Sample Page</title></head>\n" + + "<body>This has no forms but it does\n" + + "have <a href=\"/other.html\">an <b>active</b> link</A>\n" + + " and <a name=here>an anchor</a>\n" + + "<a href=\"basic.html\"><IMG SRC=\"/images/arrow.gif\" ALT=\"Next -->\" WIDTH=1 HEIGHT=4></a>\n" + + "</body></html>\n" ); + + WebConversation wc = new WebConversation(); + _simplePage = wc.getResponse( getHostPath() + "/SimplePage.html" ); } - public void testFindNoLinks() { - WebForm[] forms = _simplePage.getForms(); - assertNotNull( forms ); - assertEquals( 0, forms.length ); + public void testFindNoLinks() throws Exception { + defineResource( "NoLinks.html", "<html><head><title>NoLinks</title></head><body>No links at all</body></html>" ); + WebConversation wc = new WebConversation(); + + WebLink[] links = wc.getResponse( getHostPath() + "/NoLinks.html" ).getLinks(); + assertNotNull( links ); + assertEquals( 0, links.length ); } @@ -76,7 +85,7 @@ WebLink link = _simplePage.getLinks()[0]; WebRequest request = link.getRequest(); assert( "Should be a get request", request instanceof GetMethodWebRequest ); - assertEquals( "http://www.meterware.com/other.html", request.getURL().toExternalForm() ); + assertEquals( getHostPath() + "/other.html", request.getURL().toExternalForm() ); } @@ -91,11 +100,11 @@ assertNull( "Non-existent link should not have been found", link ); link = _simplePage.getLinkWith( "an active link" ); assertNotNull( "an active link was not found", link ); - assertEquals( "active link URL", "http://www.meterware.com/other.html", link.getRequest().getURL().toExternalForm() ); + assertEquals( "active link URL", getHostPath() + "/other.html", link.getRequest().getURL().toExternalForm() ); link = _simplePage.getLinkWithImageText( "Next -->" ); assertNotNull( "the image link was not found", link ); - assertEquals( "image link URL", "http://www.meterware.com/basic.html", link.getRequest().getURL().toExternalForm() ); + assertEquals( "image link URL", getHostPath() + "/basic.html", link.getRequest().getURL().toExternalForm() ); } @@ -105,16 +114,7 @@ } - private static URL _baseURL; - - static { - try { - _baseURL = new URL( "http://www.meterware.com" ); - } catch (java.net.MalformedURLException e ) {} // ignore - } - - private final static String HEADER = "<html><head><title>A Sample Page</title></head>"; - private ReceivedPage _simplePage; + private WebResponse _simplePage; } Index: WebPageTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebPageTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- WebPageTest.java 2000/09/11 14:23:48 1.1 +++ WebPageTest.java 2000/09/27 18:04:04 1.2 @@ -50,12 +50,18 @@ public void setUp() throws Exception { - _simplePage = new ReceivedPage( _baseURL, HEADER + - "<body>This has no forms but it does" + - "have <a href=\"/other.html\">an <b>active</b> link</A>" + - " and <a name=here>an anchor</a>" + - "<a href=\"basic.html\"><IMG SRC=\"/images/arrow.gif\" ALT=\"Next -->\" WIDTH=1 HEIGHT=4></a>" + - "</body></html>" ); + super.setUp(); + defineResource( "SimplePage.html", + "<html><head><title>A Sample Page</title></head>\n" + + "<body>This has no forms but it does\n" + + "have <a href=\"/other.html\">an <b>active</b> link</A>\n" + + " and <a name=here>an anchor</a>\n" + + "<a href=\"basic.html\"><IMG SRC=\"/images/arrow.gif\" ALT=\"Next -->\" WIDTH=1 HEIGHT=4></a>\n" + + "</body></html>\n" ); + + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest( getHostPath() + "/SimplePage.html" ); + _simplePage = wc.getResponse( request ); } @@ -65,16 +71,7 @@ - private static URL _baseURL; - - static { - try { - _baseURL = new URL( "http://www.meterware.com" ); - } catch (java.net.MalformedURLException e ) {} // ignore - } - - private final static String HEADER = "<html><head><title>A Sample Page</title></head>"; - private ReceivedPage _simplePage; + private WebResponse _simplePage; } |
From: Russell G. <rus...@us...> - 2000-09-27 18:04:10
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv4362/src/com/meterware/httpunit Modified Files: WebConversation.java WebResponse.java Log Message: Added pseudo-server to test server-response handling Index: WebConversation.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- WebConversation.java 2000/09/25 21:31:01 1.8 +++ WebConversation.java 2000/09/27 18:04:04 1.9 @@ -43,6 +43,13 @@ public WebConversation() { } + /** + * Submits a GET method request and returns a response. + **/ + public WebResponse getResponse( String urlString ) throws MalformedURLException, IOException { + return getResponse( new GetMethodWebRequest( urlString ) ); + } + /** * Submits a web request and returns a response, using all state developed so far as stored in Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- WebResponse.java 2000/09/15 16:44:44 1.13 +++ WebResponse.java 2000/09/27 18:04:04 1.14 @@ -179,7 +179,7 @@ _responseText = sb.toString(); readHeaders( connection ); } catch (IOException e) { - throw new RuntimeException( "Unable to retrieve data from URL: " + _url.toExternalForm() ); + throw new RuntimeException( "Unable to retrieve data from URL: " + _url.toExternalForm() + " (" + e + ")" ); } } |
From: Russell G. <rus...@us...> - 2000-09-26 13:38:13
|
Update of /cvsroot/httpunit/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv18628 Modified Files: index.html Log Message: Correct published version of home page Index: index.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/index.html,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- index.html 2000/09/26 04:37:54 1.6 +++ index.html 2000/09/26 13:38:09 1.7 @@ -33,8 +33,8 @@ <blockquote>The latest release of HttpUnit is available <var:dist> from the <a href="http://httpunit.sourceforge.net"><var:dist> HttpUnit home page</A> <var:publish as a <a href="http://httpunit.sourceforge.net/httpunit_<version>.zip"><var:publish zip file</A> -.<var:dist><br><var:dist>Other builds are available by <a href="ftp://httpunit.sourceforge.net/pub/httpunit"><var:dist> -anonymous ftp</a>.</blockquote> +.<var:publish <br><var:publish Other builds are available by <a href="ftp://httpunit.sourceforge.net/pub/httpunit"> +<var:publish anonymous ftp</a>.</blockquote> <h2>How do I contribute, give feedback, fix bugs and so on?</h2> <ul> |
From: Russell G. <rus...@us...> - 2000-09-26 04:37:59
|
Update of /cvsroot/httpunit/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv31183 Modified Files: index.html Log Message: Added links for anonymous ftp Index: index.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/index.html,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- index.html 2000/09/11 14:23:46 1.5 +++ index.html 2000/09/26 04:37:54 1.6 @@ -33,7 +33,8 @@ <blockquote>The latest release of HttpUnit is available <var:dist> from the <a href="http://httpunit.sourceforge.net"><var:dist> HttpUnit home page</A> <var:publish as a <a href="http://httpunit.sourceforge.net/httpunit_<version>.zip"><var:publish zip file</A> -.</blockquote> +.<var:dist><br><var:dist>Other builds are available by <a href="ftp://httpunit.sourceforge.net/pub/httpunit"><var:dist> +anonymous ftp</a>.</blockquote> <h2>How do I contribute, give feedback, fix bugs and so on?</h2> <ul> |
From: Russell G. <rus...@us...> - 2000-09-25 21:31:04
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv24063/src/com/meterware/httpunit Modified Files: WebConversation.java Log Message: Support methods to check current cookies Index: WebConversation.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- WebConversation.java 2000/09/13 20:42:36 1.7 +++ WebConversation.java 2000/09/25 21:31:01 1.8 @@ -75,6 +75,27 @@ _cookies.put( name, value ); } + + /** + * Returns the name of all the active cookies which will be sent to the server. + **/ + public String[] getCookieNames() { + String[] names = new String[ _cookies.size() ]; + int i = 0; + for (Enumeration e = _cookies.keys(); e.hasMoreElements();) { + names[i++] = (String) e.nextElement(); + } + return names; + } + + + /** + * Returns the value of the specified cookie. + **/ + public String getCookieValue( String name ) { + return (String) _cookies.get( name ); + } + /** * Specifies the user agent identification. Used to trigger browser-specific server behavior. |
From: Russell G. <rus...@us...> - 2000-09-25 21:31:04
|
Update of /cvsroot/httpunit/httpunit/doc In directory slayer.i.sourceforge.net:/tmp/cvs-serv24063/doc Modified Files: release notes.txt Log Message: Support methods to check current cookies ***** Bogus filespec: release |
From: Russell G. <rus...@us...> - 2000-09-25 21:30:28
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv23558/src/com/meterware/httpunit Modified Files: WebTable.java Log Message: Allow searching for nested tables in any position Index: WebTable.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebTable.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- WebTable.java 2000/09/11 14:23:47 1.8 +++ WebTable.java 2000/09/25 21:30:25 1.9 @@ -213,7 +213,6 @@ private URL _url; - private int[] _columnsRequired; private TableCell[][] _cells; @@ -226,28 +225,28 @@ private void readTable() { TableRow[] rows = getRows(); - _columnsRequired = new int[ rows.length ]; + int[] columnsRequired = new int[ rows.length ]; for (int i = 0; i < rows.length; i++) { TableCell[] cells = rows[i].getCells(); for (int j = 0; j < cells.length; j++) { - int spannedRows = Math.min( _columnsRequired.length-i, cells[j].getRowSpan() ); + int spannedRows = Math.min( columnsRequired.length-i, cells[j].getRowSpan() ); for (int k = 0; k < spannedRows; k++) { - _columnsRequired[ i+k ]+= cells[j].getColSpan(); + columnsRequired[ i+k ]+= cells[j].getColSpan(); } } } int numColumns = 0; - for (int i = 0; i < _columnsRequired.length; i++) { - numColumns = Math.max( numColumns, _columnsRequired[i] ); + for (int i = 0; i < columnsRequired.length; i++) { + numColumns = Math.max( numColumns, columnsRequired[i] ); } - _cells = new TableCell[ _columnsRequired.length ][ numColumns ]; + _cells = new TableCell[ columnsRequired.length ][ numColumns ]; for (int i = 0; i < rows.length; i++) { TableCell[] cells = rows[i].getCells(); for (int j = 0; j < cells.length; j++) { - int spannedRows = Math.min( _columnsRequired.length-i, cells[j].getRowSpan() ); + int spannedRows = Math.min( columnsRequired.length-i, cells[j].getRowSpan() ); for (int k = 0; k < spannedRows; k++) { for (int l = 0; l < cells[j].getColSpan(); l++) { placeCell( i+k, j+l, cells[j] ); |
From: Russell G. <rus...@us...> - 2000-09-25 21:30:28
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv23558/test/com/meterware/httpunit Modified Files: HtmlTablesTest.java Log Message: Allow searching for nested tables in any position Index: HtmlTablesTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HtmlTablesTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- HtmlTablesTest.java 2000/09/01 14:54:07 1.7 +++ HtmlTablesTest.java 2000/09/25 21:30:24 1.8 @@ -176,7 +176,7 @@ public void testInnerTableSeek() throws Exception { ReceivedPage rp = new ReceivedPage( _baseURL, HEADER + "<body><h2>Interesting data</h2>" + "<table summary=\"outer one\">" + - "<tr><td> </td><td>" + + "<tr><td>Here we are</td><td>" + "Inner Table<br>" + "<table summary=\"inner one\">" + " <tr><td colspan=2> </td></tr>" + @@ -185,11 +185,16 @@ "</table></td></tr>" + "</table></body></html>" ); - String[][] cells = rp.getTableStartingWith( "Red" ).asText(); + WebTable wt = rp.getTableStartingWith( "Red" ); + assertNotNull( "Did not find table starting with 'Red'", wt ); + String[][] cells = wt.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] ); - cells = rp.getTableStartingWithPrefix( "Re" ).asText(); + + wt = rp.getTableStartingWithPrefix( "Re" ); + assertNotNull( "Did not find table starting with prefix 'Re'", wt ); + cells = wt.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] ); |
From: Russell G. <rus...@us...> - 2000-09-25 21:28:49
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv21823/test/com/meterware/httpunit Modified Files: FormParametersTest.java WebFormTest.java Log Message: Support the checkbox value parameter Index: FormParametersTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FormParametersTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- FormParametersTest.java 2000/09/15 16:38:44 1.1 +++ FormParametersTest.java 2000/09/25 21:28:45 1.2 @@ -158,15 +158,22 @@ public void testCheckboxValidation() throws Exception { ReceivedPage page = new ReceivedPage( _baseURL, HEADER + "<body><form method=GET action = \"/ask\">" + "<Input type=checkbox name=use_color>" + + "<Input type=checkbox name=color value=red>" + + "<Input type=checkbox name=color value=blue>" + "</form></body></html>" ); WebRequest request = page.getForms()[0].getRequest(); HttpUnitOptions.setParameterValuesValidated( false ); request.setParameter( "use_color", "red" ); + request.setParameter( "color", "green" ); HttpUnitOptions.setParameterValuesValidated( true ); request.setParameter( "use_color", "on" ); request.removeParameter( "use_color" ); validateSetParameterRejected( request, "use_color", "red", "setting checkbox to a string value" ); + request.setParameter( "color", "red" ); + request.setParameter( "color", new String[] { "red", "blue" } ); + validateSetParameterRejected( request, "color", "on", "setting checkbox to an incorrect value" ); + validateSetParameterRejected( request, "color", new String[] { "green", "red" }, "setting checkbox to an incorrect value" ); } Index: WebFormTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFormTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- WebFormTest.java 2000/08/09 17:28:40 1.3 +++ WebFormTest.java 2000/09/25 21:28:45 1.4 @@ -174,6 +174,21 @@ assertMatchingSet( "inferred media default", new String[0], request.getParameterValues( "media" ) ); } + + public void testCheckboxDefaults() throws Exception { + ReceivedPage page = new ReceivedPage( _baseURL, HEADER + "<body><form method=GET action = \"/ask\">" + + "<Input type=checkbox name=ready value=yes checked>" + + "<Input type=checkbox name=color value=red checked>" + + "<Input type=checkbox name=color value=blue checked>" + + "<Input type=checkbox name=gender value=male checked>" + + "<Input type=checkbox name=gender value=female>" + + "</form></body></html>" ); + WebForm form = page.getForms()[0]; + assertEquals( "ready state", "yes", form.getParameterValue( "ready" ) ); + assertMatchingSet( "default genders allowed", new String[] { "male" }, form.getParameterValues( "gender" ) ); + assertMatchingSet( "default colors", new String[] { "red", "blue" }, form.getParameterValues( "color" ) ); + } + private static URL _baseURL; |
From: Russell G. <rus...@us...> - 2000-09-25 21:28:48
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv21823/src/com/meterware/httpunit Modified Files: ParsedHTML.java ReceivedPage.java WebForm.java Log Message: Support the checkbox value parameter Index: ParsedHTML.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ParsedHTML.java 2000/09/01 14:54:03 1.4 +++ ParsedHTML.java 2000/09/25 21:28:44 1.5 @@ -198,10 +198,14 @@ if (tables[i].getCellAsText(0,0).equalsIgnoreCase( text )) { return tables[i]; } else { - WebTable[] innerTables = tables[i].getTableCell(0,0).getTables(); - if (innerTables.length != 0) { - WebTable result = getTableStartingWith( text, innerTables ); - if (result != null) return result; + for (int j = 0; j < tables[i].getRowCount(); j++) { + for (int k = 0; k < tables[i].getColumnCount(); k++) { + WebTable[] innerTables = tables[i].getTableCell(j,k).getTables(); + if (innerTables.length != 0) { + WebTable result = getTableStartingWith( text, innerTables ); + if (result != null) return result; + } + } } } } @@ -220,10 +224,14 @@ 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; + for (int j = 0; j < tables[i].getRowCount(); j++) { + for (int k = 0; k < tables[i].getColumnCount(); k++) { + WebTable[] innerTables = tables[i].getTableCell(j,k).getTables(); + if (innerTables.length != 0) { + WebTable result = getTableStartingWithPrefix( text, innerTables ); + if (result != null) return result; + } + } } } } Index: ReceivedPage.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ReceivedPage.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ReceivedPage.java 2000/09/15 16:38:44 1.5 +++ ReceivedPage.java 2000/09/25 21:28:44 1.6 @@ -48,6 +48,8 @@ **/ public String getTitle() throws SAXException { NodeList nl = ((Document) getDOM()).getElementsByTagName( "title" ); + if (nl.getLength() == 0) return ""; + if (!nl.item(0).hasChildNodes()) return ""; return nl.item(0).getFirstChild().getNodeValue(); } Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- WebForm.java 2000/09/15 16:38:44 1.7 +++ WebForm.java 2000/09/25 21:28:44 1.8 @@ -231,7 +231,13 @@ } else if (type.equals( "RADIO" ) && parameters[i].getNamedItem( "checked" ) != null) { defaults.put( name, value ); } else if (type.equals( "CHECKBOX" ) && parameters[i].getNamedItem( "checked" ) != null) { - defaults.put( name, "on" ); + if (value.length() == 0) value = "on"; + String[] currentDefaults = (String[]) defaults.get( name ); + if (currentDefaults == null) { + defaults.put( name, new String[] { value } ); + } else { + defaults.put( name, withNewValue( currentDefaults, value ) ); + } } } HTMLSelectElement[] selections = getSelections(); @@ -265,22 +271,20 @@ if (_optionValues == null) { Hashtable options = new Hashtable(); NamedNodeMap[] parameters = getParameters(); - Hashtable types = new Hashtable(); for (int i = 0; i < parameters.length; i++) { String name = getValue( parameters[i].getNamedItem( "name" ) ); String value = getValue( parameters[i].getNamedItem( "value" ) ); String type = getValue( parameters[i].getNamedItem( "type" ) ).toUpperCase(); if (type == null) type = "TEXT"; - if (type.equals( "RADIO" )) { + if (type.equals( "RADIO" ) || type.equals( "CHECKBOX" )) { + if (value.length() == 0 && type.equals( "CHECKBOX" )) value = "on"; String[] radioOptions = (String[]) options.get( name ); if (radioOptions == null) { options.put( name, new String[] { value } ); } else { options.put( name, withNewValue( radioOptions, value ) ); } - } else if (type.equals( "CHECKBOX" )) { - options.put( name, new String[] { "on" } ); } } HTMLSelectElement[] selections = getSelections(); @@ -307,7 +311,6 @@ Hashtable types = new Hashtable(); for (int i = 0; i < parameters.length; i++) { String name = getValue( parameters[i].getNamedItem( "name" ) ); - String value = getValue( parameters[i].getNamedItem( "value" ) ); String type = getValue( parameters[i].getNamedItem( "type" ) ).toUpperCase(); if (type == null) type = "TEXT"; @@ -316,7 +319,7 @@ } else if (type.equals( "RADIO" )) { types.put( name, TYPE_SCALAR ); } else if (type.equals( "CHECKBOX" )) { - types.put( name, TYPE_SCALAR ); + types.put( name, TYPE_MULTI_VALUED ); } } HTMLSelectElement[] selections = getSelections(); |
From: Russell G. <rus...@us...> - 2000-09-15 16:44:48
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv16269/src/com/meterware/httpunit Modified Files: WebResponse.java Log Message: Added convenience methods Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- WebResponse.java 2000/09/13 20:42:37 1.12 +++ WebResponse.java 2000/09/15 16:44:44 1.13 @@ -33,6 +33,14 @@ /** + * Returns the URL which invoked this response. + **/ + public URL getURL() { + return _url; + } + + + /** * Returns the content type of this response. **/ public String getContentType() { |
From: Russell G. <rus...@us...> - 2000-09-15 16:38:47
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv15102/src/com/meterware/httpunit Modified Files: GetMethodWebRequest.java PostMethodWebRequest.java ReceivedPage.java WebForm.java WebRequest.java Added Files: HttpUnitOptions.java IllegalRequestParameterException.java Log Message: Added parameter validation and convenience methods ***** Error reading new file(2, 'No such file or directory') ***** Error reading new file(2, 'No such file or directory') Index: GetMethodWebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/GetMethodWebRequest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- GetMethodWebRequest.java 2000/07/13 14:55:49 1.2 +++ GetMethodWebRequest.java 2000/09/15 16:38:44 1.3 @@ -53,6 +53,17 @@ } +//--------------------------------------- package members --------------------------------------------- + + + /** + * Constructs a web request for a form. + **/ + GetMethodWebRequest( URL urlBase, String urlString, WebForm sourceForm ) { + super( urlBase, urlString, sourceForm ); + } + + } Index: PostMethodWebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/PostMethodWebRequest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- PostMethodWebRequest.java 2000/07/13 14:55:49 1.3 +++ PostMethodWebRequest.java 2000/09/15 16:38:44 1.4 @@ -63,8 +63,8 @@ /** * Constructs a web request using a base URL and a relative url string. **/ - PostMethodWebRequest( URL urlBase, String urlString ) { - super( urlBase, urlString ); + PostMethodWebRequest( URL urlBase, String urlString, WebForm sourceForm ) { + super( urlBase, urlString, sourceForm ); } Index: ReceivedPage.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ReceivedPage.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ReceivedPage.java 2000/09/11 14:23:47 1.4 +++ ReceivedPage.java 2000/09/15 16:38:44 1.5 @@ -58,6 +58,7 @@ private static Tidy getParser() { Tidy tidy = new Tidy(); tidy.setQuiet( true ); + tidy.setShowWarnings( HttpUnitOptions.getParserWarningsEnabled() ); return tidy; } Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- WebForm.java 2000/08/09 17:28:40 1.6 +++ WebForm.java 2000/09/15 16:38:44 1.7 @@ -71,9 +71,9 @@ WebRequest result; if (getValue( nnm.getNamedItem( "method" ) ).equalsIgnoreCase( "post" )) { - result = new PostMethodWebRequest( _baseURL, action ); + result = new PostMethodWebRequest( _baseURL, action, this ); } else { - result = new GetMethodWebRequest( _baseURL, action ); + result = new GetMethodWebRequest( _baseURL, action, this ); } String[] parameterNames = getParameterNames(); @@ -135,6 +135,22 @@ /** + * Returns true if the named parameter accepts multiple values. + **/ + public boolean isMultiValuedParameter( String name ) { + return TYPE_MULTI_VALUED.equals( getParameterTypes().get( name ) ); + } + + + /** + * Returns true if the named parameter accepts free-form text. + **/ + public boolean isTextParameter( String name ) { + return TYPE_TEXT.equals( getParameterTypes().get( name ) ); + } + + + /** * Returns a copy of the domain object model subtree associated with this form. **/ public Node getDOMSubtree() { @@ -156,7 +172,16 @@ //---------------------------------- private members -------------------------------- + /** The type of a parameter which accepts any text. **/ + private final static Integer TYPE_TEXT = new Integer(1); + + /** The type of a parameter which accepts single predefined values. **/ + private final static Integer TYPE_SCALAR = new Integer(2); + + /** The type of a parameter which accepts multiple predefined values. **/ + private final static Integer TYPE_MULTI_VALUED = new Integer(3); + /** The URL of the page containing this form. **/ private URL _baseURL; @@ -175,6 +200,9 @@ /** The parameters with their options. **/ private Hashtable _optionValues; + /** The parameters mapped to the type of data which they accept. **/ + private Hashtable _dataTypes; + /** The selections in this form. **/ private HTMLSelectElement[] _selections; @@ -236,6 +264,25 @@ private Hashtable getParameterOptionValues() { if (_optionValues == null) { Hashtable options = new Hashtable(); + NamedNodeMap[] parameters = getParameters(); + Hashtable types = new Hashtable(); + for (int i = 0; i < parameters.length; i++) { + String name = getValue( parameters[i].getNamedItem( "name" ) ); + String value = getValue( parameters[i].getNamedItem( "value" ) ); + String type = getValue( parameters[i].getNamedItem( "type" ) ).toUpperCase(); + if (type == null) type = "TEXT"; + + if (type.equals( "RADIO" )) { + String[] radioOptions = (String[]) options.get( name ); + if (radioOptions == null) { + options.put( name, new String[] { value } ); + } else { + options.put( name, withNewValue( radioOptions, value ) ); + } + } else if (type.equals( "CHECKBOX" )) { + options.put( name, new String[] { "on" } ); + } + } HTMLSelectElement[] selections = getSelections(); for (int i = 0; i < selections.length; i++) { options.put( selections[i].getName(), selections[i].getOptionValues() ); @@ -246,6 +293,46 @@ } + private String[] withNewValue( String[] group, String value ) { + String[] result = new String[ group.length+1 ]; + System.arraycopy( group, 0, result, 1, group.length ); + result[0] = value; + return result; + } + + + private Hashtable getParameterTypes() { + if (_dataTypes == null) { + NamedNodeMap[] parameters = getParameters(); + Hashtable types = new Hashtable(); + for (int i = 0; i < parameters.length; i++) { + String name = getValue( parameters[i].getNamedItem( "name" ) ); + String value = getValue( parameters[i].getNamedItem( "value" ) ); + String type = getValue( parameters[i].getNamedItem( "type" ) ).toUpperCase(); + if (type == null) type = "TEXT"; + + if (type.equals( "TEXT" ) | type.equals( "HIDDEN" ) | type.equals( "PASSWORD" )) { + types.put( name, TYPE_TEXT ); + } else if (type.equals( "RADIO" )) { + types.put( name, TYPE_SCALAR ); + } else if (type.equals( "CHECKBOX" )) { + types.put( name, TYPE_SCALAR ); + } + } + HTMLSelectElement[] selections = getSelections(); + for (int i = 0; i < selections.length; i++) { + types.put( selections[i].getName(), selections[i].isMultiSelect() ? TYPE_MULTI_VALUED : TYPE_SCALAR ); + } + HTMLTextAreaElement[] textAreas = getTextAreas(); + for (int i = 0; i < textAreas.length; i++) { + types.put( textAreas[i].getName(), TYPE_TEXT ); + } + _dataTypes = types; + } + return _dataTypes; + } + + /** * Returns an array of select control descriptors for this form. **/ @@ -389,7 +476,7 @@ } - private boolean isMultiSelect() { + boolean isMultiSelect() { return _node.getAttributes().getNamedItem( "multiple" ) != null; } Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- WebRequest.java 2000/09/12 19:27:45 1.4 +++ WebRequest.java 2000/09/15 16:38:44 1.5 @@ -15,6 +15,7 @@ * Sets the value of a parameter in a web request. **/ public void setParameter( String name, String value ) { + if (HttpUnitOptions.getParameterValuesValidated()) validateParameterValue( name, value ); _parameters.put( name, value ); } @@ -23,6 +24,7 @@ * Sets the multiple values of a parameter in a web request. **/ public void setParameter( String name, String[] values ) { + if (HttpUnitOptions.getParameterValuesValidated()) validateParameterValues( name, values ); _parameters.put( name, values ); } @@ -79,13 +81,22 @@ this( (URL) null, urlString ); } - + /** * Constructs a web request using a base URL and a relative URL string. **/ protected WebRequest( URL urlBase, String urlString ) { + this( urlBase, urlString, null ); + } + + + /** + * Constructs a web request using a base URL and a relative URL string. + **/ + protected WebRequest( URL urlBase, String urlString, WebForm sourceForm ) { _urlBase = urlBase; _urlString = urlString; + _sourceForm = sourceForm; } @@ -93,7 +104,7 @@ * Constructs a web request using a base request and a relative URL string. **/ protected WebRequest( WebRequest baseRequest, String urlString ) throws MalformedURLException { - this( baseRequest.getURL(), urlString ); + this( baseRequest.getURL(), urlString, null ); } @@ -143,6 +154,7 @@ private URL _urlBase; private String _urlString; private Hashtable _parameters = new Hashtable(); + private WebForm _sourceForm; private void appendParameters( StringBuffer sb, String name, String[] values, boolean moreToCome ) { @@ -159,4 +171,102 @@ } + private void validateParameterValue( String name, String value ) { + if (_sourceForm == null) return; + if (_sourceForm.isTextParameter( name )) return; + if (!inArray( name, _sourceForm.getParameterNames() )) throw new NoSuchParameterException( name ); + if (!inArray( value, _sourceForm.getOptionValues( name ) )) throw new IllegalParameterValueException( name, value ); + } + + + private void validateParameterValues( String name, String[] values ) { + if (_sourceForm == null) return; + if (values.length != 1 && !_sourceForm.isMultiValuedParameter( name )) { + throw new SingleValuedParameterException( name ); + } + + for (int i = 0; i < values.length; i++) validateParameterValue( name, values[i] ); + } + + + private boolean inArray( String candidate, String[] values ) { + for (int i = 0; i < values.length; i++) { + if (candidate.equals( values[i] )) return true; + } + return false; + } + + } + + +//================================ exception class NoSuchParameterException ========================================= + + +/** + * This exception is thrown on an attempt to set a parameter to a value not permitted to it by the form. + **/ +class NoSuchParameterException extends IllegalRequestParameterException { + + + NoSuchParameterException( String parameterName ) { + _parameterName = parameterName; + } + + + public String getMessage() { + return "No parameter named '" + _parameterName + "' is defined in the form"; + } + + + private String _parameterName; + +} + + +//============================= exception class IllegalParameterValueException ====================================== + + +/** + * This exception is thrown on an attempt to set a parameter to a value not permitted to it by the form. + **/ +class IllegalParameterValueException extends IllegalRequestParameterException { + + + IllegalParameterValueException( String parameterName, String badValue ) { + _parameterName = parameterName; + _badValue = badValue; + } + + public String getMessage() { + return "May not set parameter '" + _parameterName + "' to '" + _badValue + "'"; + } + + private String _parameterName; + private String _badValue; +} + + +//============================= exception class SingleValuedParameterException ====================================== + + +/** + * This exception is thrown on an attempt to set a single-valued parameter to multiple values. + **/ +class SingleValuedParameterException extends IllegalRequestParameterException { + + + SingleValuedParameterException( String parameterName ) { + _parameterName = parameterName; + } + + + public String getMessage() { + return "Parameter '" + _parameterName + "' may only have one value."; + } + + + private String _parameterName; + +} + |
From: Russell G. <rus...@us...> - 2000-09-15 16:38:47
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv15102/test/com/meterware/httpunit Modified Files: HttpUnitSuite.java Added Files: FormParametersTest.java Log Message: Added parameter validation and convenience methods ***** Error reading new file(2, 'No such file or directory') Index: HttpUnitSuite.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitSuite.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- HttpUnitSuite.java 2000/09/11 14:23:48 1.5 +++ HttpUnitSuite.java 2000/09/15 16:38:44 1.6 @@ -40,6 +40,7 @@ suite.addTest( WebLinkTest.suite() ); suite.addTest( HtmlTablesTest.suite() ); suite.addTest( WebFormTest.suite() ); + suite.addTest( FormParametersTest.suite() ); suite.addTest( Base64Test.suite() ); return suite; } |
From: Russell G. <rus...@us...> - 2000-09-15 16:38:47
|
Update of /cvsroot/httpunit/httpunit/doc In directory slayer.i.sourceforge.net:/tmp/cvs-serv15102/doc Modified Files: release notes.txt Log Message: Added parameter validation and convenience methods ***** Bogus filespec: release |
From: Russell G. <rus...@us...> - 2000-09-13 20:42:40
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv29791/src/com/meterware/httpunit Modified Files: WebConversation.java WebResponse.java Added Files: HttpInternalErrorException.java HttpNotFoundException.java Log Message: Added exceptions for URL problems. Submitted by Seth Ladd ***** Error reading new file(2, 'No such file or directory') ***** Error reading new file(2, 'No such file or directory') Index: WebConversation.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- WebConversation.java 2000/09/12 19:27:45 1.6 +++ WebConversation.java 2000/09/13 20:42:36 1.7 @@ -31,7 +31,8 @@ * needed to build an automated test of a web site. * * @author Russell Gold - * @author Jan Ohrstrom + * @author Jan Ohrstrom + * @author Seth Ladd **/ public class WebConversation { @@ -48,7 +49,7 @@ * cookies as requested by the server. **/ public WebResponse getResponse( WebRequest request ) throws MalformedURLException, IOException { - URLConnection connection = openConnection( request.getURL() ); + HttpURLConnection connection = (HttpURLConnection) openConnection( request.getURL() ); request.completeRequest( connection ); updateCookies( connection ); @@ -56,6 +57,10 @@ return getResponse( new RedirectWebRequest( request, connection.getHeaderField( "Location" ) ) ); } else if (connection.getHeaderField( "WWW-Authenticate" ) != null) { throw new AuthorizationRequiredException( connection.getHeaderField( "WWW-Authenticate" ) ); + } else if (connection.getResponseCode() == HttpURLConnection.HTTP_INTERNAL_ERROR) { + throw new HttpInternalErrorException( request.getURLString() ); + } else if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { + throw new HttpNotFoundException( request.getURLString() ); } else { WebResponse result = new WebResponse( this, request.getURL(), connection ); return result; @@ -113,8 +118,8 @@ HttpURLConnection.setFollowRedirects( false ); } - private URLConnection openConnection( URL url ) throws MalformedURLException, IOException { - URLConnection connection = url.openConnection(); + private HttpURLConnection openConnection( URL url ) throws MalformedURLException, IOException { + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setUseCaches( false ); sendAuthorization( connection ); sendUserAgent( connection ); Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- WebResponse.java 2000/09/12 18:47:38 1.11 +++ WebResponse.java 2000/09/13 20:42:37 1.12 @@ -171,7 +171,7 @@ _responseText = sb.toString(); readHeaders( connection ); } catch (IOException e) { - throw new RuntimeException( "Unable to retrieve URL: " + _url.toExternalForm() ); + throw new RuntimeException( "Unable to retrieve data from URL: " + _url.toExternalForm() ); } } |
From: Russell G. <rus...@us...> - 2000-09-12 19:27:48
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv27577/src/com/meterware/httpunit Modified Files: WebConversation.java WebRequest.java Log Message: converting line-endings file format Index: WebConversation.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- WebConversation.java 2000/09/11 14:23:47 1.5 +++ WebConversation.java 2000/09/12 19:27:45 1.6 @@ -1 +1,178 @@ -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 W! ebResponse 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 ); 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, IOException { URLConn! ection 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 +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 ); + 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, IOException { + 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() ); + } + + +} Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- WebRequest.java 2000/08/07 21:39:35 1.3 +++ WebRequest.java 2000/09/12 19:27:45 1.4 @@ -1 +1,162 @@ -package com.meterware.httpunit; import java.io.*; import java.net.*; import java.util.*; /** * A request sent to a web server. **/ abstract public class WebRequest { /** * Sets the value of a parameter in a web request. **/ public void setParameter( String name, String value ) { _parameters.put( name, value ); } /** * Sets the multiple values of a parameter in a web request. **/ public void setParameter( String name, String[] values ) { _parameters.put( name, values ); } /** * Returns the value of a parameter in this web request. * @return the value of the named parameter, or null if it is not set. **/ public String getParameter( String name ) { Object value = _parameters.get( name ); if (value instanceof String[]) { return ((String[]) value)[0]; } else { return (String) value; } } /** * Returns the multiple default values of the named parameter. **/ public String[] getParameterValues( String name ) { Object result = _parameters.get( name ); if (result instanceof String) return new String[] { (String) result }; if (result instanceof String[]) return (String[]) result; return new String[0]; } /** * Removes a parameter from this web request. **/ public void removeParameter( String name ) { _parameters.remove( name ); } /** * Returns the final URL associated with this web request. **/ abstract public URL getURL() throws MalformedURLException; //------------------------------------- protected members ------------------------------------ /** * Constructs a web request using an absolute URL string. **/ protected WebRequest( String urlString ) { this( (URL) null, urlString ); } /** * Constructs a web request using a base URL and a relative URL string. **/ protected WebRequest( URL urlBase,! String urlString ) { _urlBase = urlBase; _urlString = urlString; } /** * Constructs a web request using a base request and a relative URL string. **/ protected WebRequest( WebRequest baseRequest, String urlString ) throws MalformedURLException { this( baseRequest.getURL(), urlString ); } /** * Performs any additional processing necessary to complete the request. **/ protected void completeRequest( URLConnection connection ) throws IOException { } final protected URL getURLBase() { return _urlBase; } final protected String getURLString() { return _urlString; } final protected boolean hasNoParameters() { return _parameters.size() == 0; } final protected String getParameterString() { StringBuffer sb = new StringBuffer(); for (Enumeration e = _parameters.keys(); e.hasMoreElements();) { String name = (String) e.nextElement(); Object value = _parameters.get( name ); if (value instanceof String) { appendParameter( sb, name, (String) value, e.hasMoreElements() ); } else { appendParameters( sb, name, (String[]) value, e.hasMoreElements() ); } } return sb.toString(); } //--------------------------------------- private members ------------------------------------ private URL _urlBase; private String _urlString; private Hashtable _parameters = new Hashtable(); private void appendParameters( StringBuffer sb, String name, String[] values, boolean moreToCome ) { for (int i = 0; i < values.length; i++) { appendParameter( sb, name, values[i], (i < values.length-1 || moreToCome ) ); } } private void appendParameter( StringBuffer sb, String name, String value, boolean moreToCome ) { sb.append( name ).append( '=' ); sb.append( URLEncoder.encode( value ) ! ); if (moreToCome) sb.append( '&' ); } } \ No newline at end of file +package com.meterware.httpunit; + +import java.io.*; +import java.net.*; +import java.util.*; + +/** + * A request sent to a web server. + **/ +abstract +public class WebRequest { + + + /** + * Sets the value of a parameter in a web request. + **/ + public void setParameter( String name, String value ) { + _parameters.put( name, value ); + } + + + /** + * Sets the multiple values of a parameter in a web request. + **/ + public void setParameter( String name, String[] values ) { + _parameters.put( name, values ); + } + + + /** + * Returns the value of a parameter in this web request. + * @return the value of the named parameter, or null if it is not set. + **/ + public String getParameter( String name ) { + Object value = _parameters.get( name ); + if (value instanceof String[]) { + return ((String[]) value)[0]; + } else { + return (String) value; + } + } + + + /** + * Returns the multiple default values of the named parameter. + **/ + public String[] getParameterValues( String name ) { + Object result = _parameters.get( name ); + if (result instanceof String) return new String[] { (String) result }; + if (result instanceof String[]) return (String[]) result; + return new String[0]; + } + + + /** + * Removes a parameter from this web request. + **/ + public void removeParameter( String name ) { + _parameters.remove( name ); + } + + + + /** + * Returns the final URL associated with this web request. + **/ + abstract + public URL getURL() throws MalformedURLException; + + + +//------------------------------------- protected members ------------------------------------ + + + /** + * Constructs a web request using an absolute URL string. + **/ + protected WebRequest( String urlString ) { + this( (URL) null, urlString ); + } + + + /** + * Constructs a web request using a base URL and a relative URL string. + **/ + protected WebRequest( URL urlBase, String urlString ) { + _urlBase = urlBase; + _urlString = urlString; + } + + + /** + * Constructs a web request using a base request and a relative URL string. + **/ + protected WebRequest( WebRequest baseRequest, String urlString ) throws MalformedURLException { + this( baseRequest.getURL(), urlString ); + } + + + /** + * Performs any additional processing necessary to complete the request. + **/ + protected void completeRequest( URLConnection connection ) throws IOException { + } + + + final + protected URL getURLBase() { + return _urlBase; + } + + + final + protected String getURLString() { + return _urlString; + } + + + final + protected boolean hasNoParameters() { + return _parameters.size() == 0; + } + + + final + protected String getParameterString() { + StringBuffer sb = new StringBuffer(); + for (Enumeration e = _parameters.keys(); e.hasMoreElements();) { + String name = (String) e.nextElement(); + Object value = _parameters.get( name ); + if (value instanceof String) { + appendParameter( sb, name, (String) value, e.hasMoreElements() ); + } else { + appendParameters( sb, name, (String[]) value, e.hasMoreElements() ); + } + } + return sb.toString(); + } + + +//--------------------------------------- private members ------------------------------------ + + private URL _urlBase; + private String _urlString; + private Hashtable _parameters = new Hashtable(); + + + private void appendParameters( StringBuffer sb, String name, String[] values, boolean moreToCome ) { + for (int i = 0; i < values.length; i++) { + appendParameter( sb, name, values[i], (i < values.length-1 || moreToCome ) ); + } + } + + + private void appendParameter( StringBuffer sb, String name, String value, boolean moreToCome ) { + sb.append( name ).append( '=' ); + sb.append( URLEncoder.encode( value ) ); + if (moreToCome) sb.append( '&' ); + } + + +} |
From: Russell G. <rus...@us...> - 2000-09-12 18:47:44
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv17488/src/com/meterware/httpunit Modified Files: WebResponse.java Log Message: Experiment: converting WebResponse.java file format Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- WebResponse.java 2000/09/11 14:23:47 1.10 +++ WebResponse.java 2000/09/12 18:47:38 1.11 @@ -1 +1,236 @@ -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.StringTokenizer; import org.xml.sax.*; import org.w3c.dom.*; /** * A response from a web server to an Http request. **/ public class WebResponse { /** * Returns the content type of this response. **/ public String getContentType() { return _contentType; } /** * Returns the character set used in this response. **/ public String getCharacterSet() { return _characterSet; } /** * Returns the title of the page. **/ public String getTitle() throws SAXException { return getReceivedPage().getTitle(); } /** * Retu! rns 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 SAXException { 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 getTableStartin! gWith( 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 ); } /** * Returns the text of the response (excluding headers) as a string. Use this method in preference to 'toString' * which may be used to represent internal state of this object. **/ public String getText() { return _responseText; } 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, URLConnection connection ) { _conversation = conversation; _url = url; StringBuffer sb = new StringBuffer(); try { BufferedReader input = new BufferedReader( new InputStreamReader( connection.getInputStream() ) ); String str; while (null != ((str = input.readLine()))) { sb.append( str ).append( endOfLine ); } input.close (); _responseText = sb.toString(); readHeaders( connection ); } catch (IOException e) { throw new RuntimeExcept! ion( "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 String _contentType = "text/plain"; private String _characterSet = "us-ascii"; private ReceivedPage getReceivedPage() throws SAXException { if (_page == null) { if (!_contentType.equals( "text/html" )) throw new RuntimeException( "Response is not HTML" ); _page = new ReceivedPage( _url, _responseText ); } return _page; } private void readHeaders( URLConnection connection ) { readContentTypeHeader( connection ); } private void readContentTypeHeader( URLConnection connection ) { String contentHeader = connection.getContentType(); if (contentHeader != null) { StringTokenizer st = new StringTokenizer( contentHeader, ";=" ); _contentType = st.nextToken(); while (st.hasMoreTokens()) { String parameter = st.nextToken(); if (st.hasMoreTokens()) { String value = st.nextToken(); if (parameter.equalsIgnoreCase( "charset" )) _characterSet = value; } } } } } \ No newline at end of file +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.StringTokenizer; +import org.xml.sax.*; +import org.w3c.dom.*; + +/** + * A response from a web server to an Http request. + **/ +public class WebResponse { + + + /** + * Returns the content type of this response. + **/ + public String getContentType() { + return _contentType; + } + + + /** + * Returns the character set used in this response. + **/ + public String getCharacterSet() { + return _characterSet; + } + + + /** + * Returns the title of the page. + **/ + public String getTitle() throws SAXException { + return getReceivedPage().getTitle(); + } + + + /** + * 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 SAXException { + 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 ); + } + + + /** + * Returns the text of the response (excluding headers) as a string. Use this method in preference to 'toString' + * which may be used to represent internal state of this object. + **/ + public String getText() { + return _responseText; + } + + + 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, URLConnection connection ) { + _conversation = conversation; + _url = url; + StringBuffer sb = new StringBuffer(); + try { + BufferedReader input = new BufferedReader( new InputStreamReader( connection.getInputStream() ) ); + + String str; + while (null != ((str = input.readLine()))) { + sb.append( str ).append( endOfLine ); + } + input.close (); + _responseText = sb.toString(); + readHeaders( connection ); + } 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 String _contentType = "text/plain"; + + private String _characterSet = "us-ascii"; + + + private ReceivedPage getReceivedPage() throws SAXException { + if (_page == null) { + if (!_contentType.equals( "text/html" )) throw new RuntimeException( "Response is not HTML" ); + _page = new ReceivedPage( _url, _responseText ); + } + return _page; + } + + + private void readHeaders( URLConnection connection ) { + readContentTypeHeader( connection ); + } + + + private void readContentTypeHeader( URLConnection connection ) { + String contentHeader = connection.getContentType(); + if (contentHeader != null) { + StringTokenizer st = new StringTokenizer( contentHeader, ";=" ); + _contentType = st.nextToken(); + while (st.hasMoreTokens()) { + String parameter = st.nextToken(); + if (st.hasMoreTokens()) { + String value = st.nextToken(); + if (parameter.equalsIgnoreCase( "charset" )) _characterSet = value; + } + } + } + } + +} + |
From: Russell G. <rus...@us...> - 2000-09-11 14:23:52
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv27382/src/com/meterware/httpunit Modified Files: NodeUtils.java ReceivedPage.java WebConversation.java WebLink.java WebResponse.java WebTable.java Log Message: Added getTitle, getURLString Index: NodeUtils.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/NodeUtils.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- NodeUtils.java 2000/09/01 14:54:03 1.2 +++ NodeUtils.java 2000/09/11 14:23:47 1.3 @@ -71,7 +71,7 @@ Node node = (Node) pending; if (node.getNodeType() == Node.TEXT_NODE) { - sb.append( node.getNodeValue() ); + sb.append( convertNBSP( node.getNodeValue() ) ); } else if (node.getNodeType() != Node.ELEMENT_NODE) { continue; } else if (node.getNodeName().equalsIgnoreCase( "p" )) { @@ -89,6 +89,14 @@ } } return sb.toString(); + } + + + final static private char NBSP = (char) 160; // non-breaking space, defined by JTidy + + + private static String convertNBSP( String text ) { + return text.replace( NBSP, ' ' ); } Index: ReceivedPage.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ReceivedPage.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ReceivedPage.java 2000/07/13 13:56:34 1.3 +++ ReceivedPage.java 2000/09/11 14:23:47 1.4 @@ -43,6 +43,15 @@ } + /** + * Returns the title of the page. + **/ + public String getTitle() throws SAXException { + NodeList nl = ((Document) getDOM()).getElementsByTagName( "title" ); + return nl.item(0).getFirstChild().getNodeValue(); + } + + //---------------------------------- private members -------------------------------- Index: WebConversation.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- WebConversation.java 2000/09/01 14:54:03 1.4 +++ WebConversation.java 2000/09/11 14:23:47 1.5 @@ -1 +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 W! ebResponse 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, IOEx! ception { 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 +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 W! ebResponse 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 ); 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, IOException { URLConn! ection 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.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- WebLink.java 2000/09/01 14:54:03 1.2 +++ WebLink.java 2000/09/11 14:23:47 1.3 @@ -20,13 +20,19 @@ * Creates and returns a web request which will simulate clicking on this link. **/ public WebRequest getRequest() { - NamedNodeMap nnm = _node.getAttributes(); - String action = getValue( nnm.getNamedItem( "href" ) ); - return new GetMethodWebRequest( _baseURL, action ); + return new GetMethodWebRequest( _baseURL, getURLString() ); } /** + * Returns the URL referenced by this link. This may be a relative URL. + **/ + public String getURLString() { + return getValue( _node.getAttributes().getNamedItem( "href" ) ); + } + + + /** * Returns a copy of the domain object model subtree associated with this link. **/ public Node getDOMSubtree() { @@ -38,9 +44,7 @@ * Returns the text value of this link. **/ public String asText() { - if (_node == null) { - return ""; - } else if (!_node.hasChildNodes()) { + if (!_node.hasChildNodes()) { return ""; } else { return NodeUtils.asText( _node.getChildNodes() ); @@ -56,6 +60,7 @@ * from that page. **/ WebLink( URL baseURL, Node node ) { + if (node == null) throw new IllegalArgumentException( "node must not be null" ); _node = node; _baseURL = baseURL; } Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- WebResponse.java 2000/09/01 14:54:04 1.9 +++ WebResponse.java 2000/09/11 14:23:47 1.10 @@ -1 +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 SAXE! xception { 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 i! f 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 +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.StringTokenizer; import org.xml.sax.*; import org.w3c.dom.*; /** * A response from a web server to an Http request. **/ public class WebResponse { /** * Returns the content type of this response. **/ public String getContentType() { return _contentType; } /** * Returns the character set used in this response. **/ public String getCharacterSet() { return _characterSet; } /** * Returns the title of the page. **/ public String getTitle() throws SAXException { return getReceivedPage().getTitle(); } /** * Retu! rns 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 SAXException { 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 getTableStartin! gWith( 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 ); } /** * Returns the text of the response (excluding headers) as a string. Use this method in preference to 'toString' * which may be used to represent internal state of this object. **/ public String getText() { return _responseText; } 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, URLConnection connection ) { _conversation = conversation; _url = url; StringBuffer sb = new StringBuffer(); try { BufferedReader input = new BufferedReader( new InputStreamReader( connection.getInputStream() ) ); String str; while (null != ((str = input.readLine()))) { sb.append( str ).append( endOfLine ); } input.close (); _responseText = sb.toString(); readHeaders( connection ); } catch (IOException e) { throw new RuntimeExcept! ion( "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 String _contentType = "text/plain"; private String _characterSet = "us-ascii"; private ReceivedPage getReceivedPage() throws SAXException { if (_page == null) { if (!_contentType.equals( "text/html" )) throw new RuntimeException( "Response is not HTML" ); _page = new ReceivedPage( _url, _responseText ); } return _page; } private void readHeaders( URLConnection connection ) { readContentTypeHeader( connection ); } private void readContentTypeHeader( URLConnection connection ) { String contentHeader = connection.getContentType(); if (contentHeader != null) { StringTokenizer st = new StringTokenizer( contentHeader, ";=" ); _contentType = st.nextToken(); while (st.hasMoreTokens()) { String parameter = st.nextToken(); if (st.hasMoreTokens()) { String value = st.nextToken(); if (parameter.equalsIgnoreCase( "charset" )) _characterSet = value; } } } } } \ No newline at end of file Index: WebTable.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebTable.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- WebTable.java 2000/08/08 20:10:49 1.7 +++ WebTable.java 2000/09/11 14:23:47 1.8 @@ -97,7 +97,7 @@ // look for rows and columns with any text in a non-spanning cell for (int i = 0; i < rowHasText.length; i++) { for (int j = 0; j < columnHasText.length; j++) { - if (getTrimmedText( getCellAsText(i,j) ).length() == 0) continue; + if (getCellAsText(i,j).trim().length() == 0) continue; if (getTableCell(i,j).getColSpan() == 1 && getTableCell(i,j).getRowSpan() == 1) { if (!rowHasText[i]) numRowsWithText++; if (!columnHasText[j]) numColumnsWithText++; @@ -149,12 +149,6 @@ } - private static String getTrimmedText( String text ) { - text = text.replace( NBSP, ' ' ); - return text.trim(); - } - - /** * Returns a rendering of the table with all cells converted to text. **/ @@ -361,9 +355,6 @@ } } } - - - final static private char NBSP = (char) 160; // non-breaking space, defined by JTidy } |
From: Russell G. <rus...@us...> - 2000-09-11 14:23:52
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv27382/test/com/meterware/httpunit Modified Files: HttpUnitSuite.java WebLinkTest.java Added Files: WebPageTest.java Log Message: Added getTitle, getURLString ***** Error reading new file(2, 'No such file or directory') Index: HttpUnitSuite.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitSuite.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- HttpUnitSuite.java 2000/09/01 14:54:07 1.4 +++ HttpUnitSuite.java 2000/09/11 14:23:48 1.5 @@ -36,6 +36,7 @@ public static Test suite() { TestSuite suite = new TestSuite(); + suite.addTest( WebPageTest.suite() ); suite.addTest( WebLinkTest.suite() ); suite.addTest( HtmlTablesTest.suite() ); suite.addTest( WebFormTest.suite() ); Index: WebLinkTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebLinkTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- WebLinkTest.java 2000/09/01 14:54:07 1.3 +++ WebLinkTest.java 2000/09/11 14:23:48 1.4 @@ -1,4 +1,24 @@ 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.net.URL; @@ -57,6 +77,12 @@ WebRequest request = link.getRequest(); assert( "Should be a get request", request instanceof GetMethodWebRequest ); assertEquals( "http://www.meterware.com/other.html", request.getURL().toExternalForm() ); + } + + + public void testLinkReference() throws Exception { + WebLink link = _simplePage.getLinks()[0]; + assertEquals( "URLString", "/other.html", link.getURLString() ); } |
From: Russell G. <rus...@us...> - 2000-09-11 14:23:51
|
Update of /cvsroot/httpunit/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv27382 Modified Files: build.xml index.html Log Message: Added getTitle, getURLString Index: build.xml =================================================================== RCS file: /cvsroot/httpunit/httpunit/build.xml,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- build.xml 2000/09/01 15:38:31 1.10 +++ build.xml 2000/09/11 14:23:46 1.11 @@ -80,7 +80,7 @@ <javadoc packagenames="${packages}" sourcepath="${basedir}/${src.dir}" destdir="${javadoc.dir}" author="true" version="true" windowtitle="${Name} ${version} API" doctitle="${Name}" - footer="Copyright © 2000 Russell Gold and meterware.com. All Rights Reserved." /> + footer="Copyright &copy; 2000 Russell Gold. See <a href="http://httpunit.sourceforge.net/doc/license.html">license agreement</A> for rights granted." /> </target> @@ -93,11 +93,10 @@ <mkdir dir="${dist.dir}/doc" /> <mkdir dir="${dist.dir}/doc/api" /> <mkdir dir="${dist.dir}/src" /> - <mkdir dir="${dist.dir}/src/test" /> <mkdir dir="${dist.dir}/test" /> <mkdir dir="${dist.dir}/examples" /> <copydir src="${src.dir}" dest="${dist.dir}/src" /> - <copydir src="${tstsrc.dir}" dest="${dist.dir}/test" /> + <copydir src="${tstsrc.dir}" dest="${dist.dir}/test" includes="**/httpunit/*" /> <copydir src="${examples.dir}" dest="${dist.dir}/examples" /> <copydir src="${lib.dir}" dest="${dist.dir}/lib" /> <copyfile src="build.xml" dest="${dist.dir}/build.xml" /> Index: index.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/index.html,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- index.html 2000/09/01 15:38:31 1.4 +++ index.html 2000/09/11 14:23:46 1.5 @@ -7,7 +7,7 @@ <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> +<UL><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, @@ -19,7 +19,7 @@ <h2>What is it?</h2> <blockquote> -<strong>HttpUnit</strong> is a Java API for accessing web sites without a browser, +<strong>HttpUnit</strong> is a free, <A HREF="doc/license.html">open source</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> |
From: Russell G. <rus...@us...> - 2000-09-11 14:23:51
|
Update of /cvsroot/httpunit/httpunit/doc In directory slayer.i.sourceforge.net:/tmp/cvs-serv27382/doc Modified Files: release notes.txt Added Files: license.html Log Message: Added getTitle, getURLString --- NEW FILE --- <HTML><HEAD><TITLE>HttpUnit License Agreement</TITLE></HEAD> <BODY> <P> 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:</P> <P> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</P> <P> 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. </P> </BODY></HTML> ***** Bogus filespec: release |