httpunit-commit Mailing List for httpunit (Page 63)
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...> - 2002-03-21 15:44:08
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv26241/doc Modified Files: release_notes.txt Log Message: From Frank Carver: support character values > 127 in base 64 encoding Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.100 retrieving revision 1.101 diff -u -r1.100 -r1.101 --- release_notes.txt 15 Mar 2002 17:23:25 -0000 1.100 +++ release_notes.txt 21 Mar 2002 15:44:03 -0000 1.101 @@ -11,6 +11,14 @@ Revision History: +21-Mar-2002 +Acknowledgements: + Thanks to Frank Carver for extending base 64 encoding to handle character values > 127. + +Problems fixed: + 1. Passwords with character values > 127 are now handled. + + 15-Mar-2002 Acknowledgements: Thanks to Stefan Renz for finding the file control value bug and providing a fix. |
From: Russell G. <rus...@us...> - 2002-03-21 15:44:08
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv26241/test/com/meterware/httpunit Modified Files: HttpUnitTest.java Log Message: From Frank Carver: support character values > 127 in base 64 encoding Index: HttpUnitTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitTest.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- HttpUnitTest.java 28 Jan 2002 18:43:25 -0000 1.19 +++ HttpUnitTest.java 21 Mar 2002 15:44:03 -0000 1.20 @@ -36,7 +36,7 @@ * @author <a href="mailto:rus...@ac...">Russell Gold</a> **/ abstract -class HttpUnitTest extends TestCase { +public class HttpUnitTest extends TestCase { public HttpUnitTest( String name ) { super( name ); |
From: Russell G. <rus...@us...> - 2002-03-21 15:44:08
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv26241/src/com/meterware/httpunit Modified Files: Base64.java Log Message: From Frank Carver: support character values > 127 in base 64 encoding Index: Base64.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/Base64.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Base64.java 26 Nov 2001 14:20:12 -0000 1.2 +++ Base64.java 21 Mar 2002 15:44:03 -0000 1.3 @@ -24,9 +24,9 @@ final static String encodingChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; public static String encode( String source ) { - byte[] sourceBytes = getPaddedBytes( source ); + char[] sourceBytes = getPaddedBytes( source ); int numGroups = (sourceBytes.length + 2) / 3; - byte[] targetBytes = new byte[4]; + char[] targetBytes = new char[4]; char[] target = new char[ 4 * numGroups ]; for (int group = 0; group < numGroups; group++) { @@ -43,20 +43,20 @@ } - private static byte[] getPaddedBytes( String source ) { - byte[] converted = source.getBytes(); + private static char[] getPaddedBytes( String source ) { + char[] converted = source.toCharArray(); int requiredLength = 3 * ((converted.length+2) /3); - byte[] result = new byte[ requiredLength ]; + char[] result = new char[ requiredLength ]; System.arraycopy( converted, 0, result, 0, converted.length ); return result; } - private static void convert3To4( byte[] source, int sourceIndex, byte[] target ) { - target[0] = (byte) ( source[ sourceIndex ] >>> 2); - target[1] = (byte) (((source[ sourceIndex ] & 0x03) << 4) | (source[ sourceIndex+1 ] >>> 4)); - target[2] = (byte) (((source[ sourceIndex+1 ] & 0x0f) << 2) | (source[ sourceIndex+2 ] >>> 6)); - target[3] = (byte) ( source[ sourceIndex+2 ] & 0x3f); + private static void convert3To4( char[] source, int sourceIndex, char[] target ) { + target[0] = (char) ( source[ sourceIndex ] >>> 2); + target[1] = (char) (((source[ sourceIndex ] & 0x03) << 4) | (source[ sourceIndex+1 ] >>> 4)); + target[2] = (char) (((source[ sourceIndex+1 ] & 0x0f) << 2) | (source[ sourceIndex+2 ] >>> 6)); + target[3] = (char) ( source[ sourceIndex+2 ] & 0x3f); } @@ -82,5 +82,4 @@ target[ targetIndex+2 ] = (byte) (((source[2] & 0x03) << 6) | (source[3])); } -} - +} \ No newline at end of file |
From: Russell G. <rus...@us...> - 2002-03-15 17:23:28
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv30905/src/com/meterware/httpunit Modified Files: FormControl.java Log Message: The value of a file parameter is now defined as the name of the selected file Index: FormControl.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- FormControl.java 6 Feb 2002 18:38:13 -0000 1.8 +++ FormControl.java 15 Mar 2002 17:23:25 -0000 1.9 @@ -588,8 +588,11 @@ } + /** + * Returns the name of the selected file, if any. + */ public String[] getValues() { - return null; // XXX what should this really do? + return new String[] { _fileToUpload == null ? "" : _fileToUpload.getFileName() }; } |
From: Russell G. <rus...@us...> - 2002-03-15 17:23:28
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv30905/test/com/meterware/httpunit Modified Files: FormParametersTest.java Log Message: The value of a file parameter is now defined as the name of the selected file Index: FormParametersTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FormParametersTest.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- FormParametersTest.java 14 Jan 2002 18:13:45 -0000 1.10 +++ FormParametersTest.java 15 Mar 2002 17:23:25 -0000 1.11 @@ -26,6 +26,7 @@ import junit.framework.TestSuite; import java.util.Vector; +import java.io.File; /** @@ -248,6 +249,22 @@ request.setParameter( "age", "12" ); request.setParameter( "big", "stop me" ); } + + +public void testFileParameterValue() throws Exception { + defineWebPage( "Default", "<form method=POST action='/ask'>" + + "<Input type=file name=File>" + + "<Input type=submit value=Upload></form>" ); + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); + WebForm form = page.getForms()[0]; + String[] values = form.getParameterValues( "File" ); + assertEquals( "Number of file parameter values", 1, values.length ); + assertEquals( "Default selected filename", "", values[0] ); + + final File file = new File( "dummy.txt" ); + form.setParameter( "File", new UploadFileSpec[] { new UploadFileSpec( file ) } ); + assertEquals( "Selected filename", file.getAbsolutePath(), form.getParameterValue( "File" ) ); +} //---------------------------------------------- private members ------------------------------------------------ |
From: Russell G. <rus...@us...> - 2002-03-15 17:23:28
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv30905/doc Modified Files: release_notes.txt Log Message: The value of a file parameter is now defined as the name of the selected file Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.99 retrieving revision 1.100 diff -u -r1.99 -r1.100 --- release_notes.txt 14 Mar 2002 22:18:26 -0000 1.99 +++ release_notes.txt 15 Mar 2002 17:23:25 -0000 1.100 @@ -11,6 +11,13 @@ Revision History: +15-Mar-2002 +Acknowledgements: + Thanks to Stefan Renz for finding the file control value bug and providing a fix. + +Problems fixed: + 1. Trying to get the value of a file parameter no longer results in a null pointer exception. + 14-Mar-2002 Additions: 1. It is now possible to set the action on a form using a mechanism which will support scripting in the future: |
From: Russell G. <rus...@us...> - 2002-03-14 22:18:29
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv9348/test/com/meterware/httpunit Modified Files: FormSubmitTest.java Log Message: Added support for changing the action of a form Index: FormSubmitTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FormSubmitTest.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- FormSubmitTest.java 4 Mar 2002 02:10:50 -0000 1.15 +++ FormSubmitTest.java 14 Mar 2002 22:18:26 -0000 1.16 @@ -4,12 +4,12 @@ * * Copyright (c) 2000-2001, 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 +* 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 +* 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 @@ -38,8 +38,8 @@ public static void main(String args[]) { junit.textui.TestRunner.run( suite() ); } - - + + public static Test suite() { return new TestSuite( FormSubmitTest.class ); } @@ -54,8 +54,8 @@ super.setUp(); _wc = new WebConversation(); } - - + + public void testEmbeddedEquals() throws Exception { defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=text name=\"age=x\" value=12>" + @@ -91,6 +91,9 @@ WebForm form = page.getForms()[0]; assertEquals( "Form method", "GET", form.getMethod() ); assertEquals( "Form action", "/ask", form.getAction() ); + + form.getScriptableObject().setAction( "/tell" ); + assertEquals( "Form action", "/tell", form.getAction() ); } @@ -105,7 +108,7 @@ assertEquals( getHostPath() + "/ask?age=23", request.getURL().toExternalForm() ); } - + public void testNoNameSubmitString() throws Exception { defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=text value=dontSend>" + @@ -130,7 +133,7 @@ assertEquals( "num detected submit buttons", 2, buttons.length ); } - + public void testDisabledSubmitButtonDetection() throws Exception { defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=text name=age value=12>" + @@ -180,7 +183,7 @@ assertEquals( "num detected submit buttons", 2, buttons.length ); } - + public void testImageButtonDetection() throws Exception { defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=text name=age value=12>" + @@ -193,7 +196,7 @@ assertEquals( "num detected submit buttons", 2, buttons.length ); } - + public void testImageButtonDefaultSubmit() throws Exception { defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=text name=age value=12>" + @@ -205,7 +208,7 @@ assertEquals( "Query", getHostPath() + "/ask?age=12&update=name&update.x=0&update.y=0", request.getURL().toExternalForm() ); } - + public void testUnnamedImageButtonDefaultSubmit() throws Exception { defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=text name=age value=12>" + @@ -217,7 +220,7 @@ assertEquals( getHostPath() + "/ask?age=12", request.getURL().toExternalForm() ); } - + public void testImageButtonPositionalSubmit() throws Exception { defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=text name=age value=12>" + @@ -245,7 +248,7 @@ assertEquals( "submit button value", "age", buttons[0].getValue() ); } - + public void testSubmitButtonSelectionByName() throws Exception { defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=text name=age value=12>" + @@ -262,7 +265,7 @@ assertEquals( "submit button value", "age", button.getValue() ); } - + public void testSubmitButtonSelectionByNameAndValue() throws Exception { defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=text name=age value=12>" + @@ -281,7 +284,7 @@ assertEquals( "submit button value", "name", button.getValue() ); } - + public void testNamedButtonSubmitString() throws Exception { defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=text name=age value=12>" + @@ -306,7 +309,7 @@ } } - + public void testUnnamedButtonSubmit() throws Exception { defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=text name=age value=12>" + @@ -319,10 +322,10 @@ WebRequest request = form.getRequest(); fail( "Should not allow submit with unnamed button" ); } catch (IllegalRequestParameterException e) { - } + } } - + public void testForeignSubmitButtonDetection() throws Exception { defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Input type=text name=age value=12>" + |
From: Russell G. <rus...@us...> - 2002-03-14 22:18:29
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv9348/src/com/meterware/httpunit Modified Files: WebForm.java Log Message: Added support for changing the action of a form Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.47 retrieving revision 1.48 diff -u -r1.47 -r1.48 --- WebForm.java 21 Feb 2002 21:13:32 -0000 1.47 +++ WebForm.java 14 Mar 2002 22:18:26 -0000 1.48 @@ -19,13 +19,16 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ +import java.io.IOException; import java.net.URL; -import java.util.*; -import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Vector; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -51,7 +54,8 @@ * Returns the action defined for this form. **/ public String getAction() { - return getDestination(); + if (_action == null) _action = getDestination(); + return _action; } @@ -268,6 +272,14 @@ } } + + /** + * Returns an object which provides scripting access to this form. + **/ + public ScriptableObject getScriptableObject() { + return new ScriptableObject(); + } + //---------------------------------- WebRequestSource methods -------------------------------- /** @@ -388,6 +400,12 @@ } + public class ScriptableObject { + public String getAction() { return WebForm.this.getAction(); } + public void setAction( String newAction ) { _action = newAction; } + } + + //---------------------------------- package members -------------------------------- /** @@ -420,6 +438,8 @@ private FormControl[] _presetParameters; private ArrayList _presets; + + private String _action; private SubmitButton getDefaultButton() { |
From: Russell G. <rus...@us...> - 2002-03-14 22:18:28
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv9348/doc Modified Files: release_notes.txt Log Message: Added support for changing the action of a form Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.98 retrieving revision 1.99 diff -u -r1.98 -r1.99 --- release_notes.txt 11 Mar 2002 12:34:31 -0000 1.98 +++ release_notes.txt 14 Mar 2002 22:18:26 -0000 1.99 @@ -11,6 +11,11 @@ Revision History: +14-Mar-2002 +Additions: + 1. It is now possible to set the action on a form using a mechanism which will support scripting in the future: + form.getScriptableObject().setAction( newAction ) + 11-Mar-2002 Additions: |
From: Russell G. <rus...@us...> - 2002-03-11 12:34:35
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv5472/test/com/meterware/httpunit Modified Files: WebClientTest.java Log Message: Send accept-encoding header unless disabled Index: WebClientTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebClientTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- WebClientTest.java 6 Mar 2002 04:59:52 -0000 1.2 +++ WebClientTest.java 11 Mar 2002 12:34:32 -0000 1.3 @@ -53,6 +53,19 @@ } + public void testGZIPDisabled() throws Exception { + String expectedResponse = "Here is my answer"; + defineResource( "Compressed.html", new CompressedPseudoServlet( expectedResponse ) ); + HttpUnitOptions.setAcceptGzip( false ); + + WebConversation wc = new WebConversation(); + WebResponse wr = wc.getResponse( getHostPath() + "/Compressed.html" ); + assertNull( "Should not have received a Content-Encoding header", wr.getHeaderField( "Content-encoding" ) ); + assertEquals( "Content-Type", "text/plain", wr.getContentType() ); + assertEquals( "Content", expectedResponse, wr.getText().trim() ); + } + + public void testGZIPHandling() throws Exception { String expectedResponse = "Here is my answer"; defineResource( "Compressed.html", new CompressedPseudoServlet( expectedResponse ) ); @@ -76,9 +89,20 @@ public WebResource getGetResponse() throws IOException { - WebResource result = new WebResource( getCompressedContents(), "text/plain" ); - result.addHeader( "Content-Encoding: gzip" ); - return result; + if (!userAcceptsGZIP()) { + return new WebResource( _responseText.getBytes(), "text/plain" ); + } else { + WebResource result = new WebResource( getCompressedContents(), "text/plain" ); + result.addHeader( "Content-Encoding: gzip" ); + return result; + } + } + + + private boolean userAcceptsGZIP() { + String header = getHeader( "Accept-Encoding" ); + if (header == null) return false; + return header.toLowerCase().indexOf( "gzip" ) >= 0; } |
From: Russell G. <rus...@us...> - 2002-03-11 12:34:35
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv5472/src/com/meterware/httpunit Modified Files: HttpUnitOptions.java WebClient.java Log Message: Send accept-encoding header unless disabled Index: HttpUnitOptions.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- HttpUnitOptions.java 28 Jan 2002 21:37:05 -0000 1.17 +++ HttpUnitOptions.java 11 Mar 2002 12:34:31 -0000 1.18 @@ -47,6 +47,24 @@ _characterSet = HttpUnitUtils.DEFAULT_CHARACTER_SET; _contentType = DEFAULT_CONTENT_TYPE; _postIncludesCharset = false; + _acceptGzip = true; + } + + + + /** + * Returns true if any WebClient created will accept GZIP encoding of responses. The default is to accept GZIP encoding. + **/ + public static boolean isAcceptGzip() { + return _acceptGzip; + } + + + /** + * Specifies whether a WebClient will be initialized to accept GZIP encoded responses. The default is true. + */ + public static void setAcceptGzip( boolean acceptGzip ) { + _acceptGzip = acceptGzip; } @@ -303,6 +321,8 @@ private static final String DEFAULT_CONTENT_TYPE = "text/plain"; private static final String DEFAULT_CONTENT_HEADER = DEFAULT_CONTENT_TYPE; + + private static boolean _acceptGzip = true; private static boolean _parserWarningsEnabled; Index: WebClient.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- WebClient.java 28 Feb 2002 14:30:33 -0000 1.21 +++ WebClient.java 11 Mar 2002 12:34:31 -0000 1.22 @@ -247,6 +247,13 @@ //------------------------------------------ protected members ----------------------------------- + protected WebClient() { + if (HttpUnitOptions.isAcceptGzip()) { + setHeaderField( "Accept-Encoding", "gzip" ); + } + } + + /** * Creates a web response object which represents the response to the specified web request. **/ |
From: Russell G. <rus...@us...> - 2002-03-11 12:34:34
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv5472/doc Modified Files: release_notes.txt Log Message: Send accept-encoding header unless disabled Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.97 retrieving revision 1.98 diff -u -r1.97 -r1.98 --- release_notes.txt 6 Mar 2002 04:59:52 -0000 1.97 +++ release_notes.txt 11 Mar 2002 12:34:31 -0000 1.98 @@ -11,6 +11,15 @@ Revision History: +11-Mar-2002 + +Additions: + 1. HttpUnit now sends Accept-encoding: gzip unless disabled by a call to HttpUnitOptions.setAcceptGzip( false ) + +Notes: + 1. Hidden fields may not be modified if parameter validation is enabled, since they cannot be modified through + normal user interaction (in the absence of JavaScript). + 6-Mar-2002 1.4 Acknowledgements: |
From: Russell G. <rus...@us...> - 2002-03-06 04:59:55
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv9204/test/com/meterware/httpunit Modified Files: PseudoServer.java PseudoServerTest.java PseudoServlet.java WebClientTest.java Log Message: Added support for gzip-encoded responses Index: PseudoServer.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServer.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- PseudoServer.java 28 Jan 2002 05:06:37 -0000 1.17 +++ PseudoServer.java 6 Mar 2002 04:59:52 -0000 1.18 @@ -224,7 +224,7 @@ } - private WebResource getResource( PseudoServlet servlet, HttpRequestStream request ) { + private WebResource getResource( PseudoServlet servlet, HttpRequestStream request ) throws IOException { servlet.init( request ); return servlet.getResponse( request.getCommand() ); } Index: PseudoServerTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServerTest.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- PseudoServerTest.java 6 Mar 2002 03:45:57 -0000 1.23 +++ PseudoServerTest.java 6 Mar 2002 04:59:52 -0000 1.24 @@ -4,12 +4,12 @@ * * Copyright (c) 2000-2002, 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 +* 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 +* 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 @@ -34,8 +34,8 @@ public static void main(String args[]) { junit.textui.TestRunner.run( suite() ); } - - + + public static Test suite() { return new TestSuite( PseudoServerTest.class ); } @@ -164,60 +164,6 @@ } - public void testRedirect() throws Exception { - String resourceName = "something/redirected"; - String resourceValue = "the desired content"; - - String redirectName = "anOldOne"; - - defineResource( resourceName, resourceValue ); - defineResource( redirectName, "ignored content", HttpURLConnection.HTTP_MOVED_PERM ); - addResourceHeader( redirectName, "Location: " + getHostPath() + '/' + resourceName ); - - WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + '/' + redirectName ); - assertEquals( "requested resource", resourceValue, response.getText().trim() ); - assertEquals( "content type", "text/html", response.getContentType() ); - } - - - public void testDuplicateHeaderRedirect() throws Exception { - String resourceName = "something/redirected"; - String resourceValue = "the desired content"; - - String redirectName = "anOldOne"; - - defineResource( resourceName, resourceValue ); - defineResource( redirectName, "ignored content", HttpURLConnection.HTTP_MOVED_PERM ); - addResourceHeader( redirectName, "Location: " + getHostPath() + '/' + resourceName ); - addResourceHeader( redirectName, "Location: " + getHostPath() + '/' + resourceName ); - - WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + '/' + redirectName ); - assertEquals( "requested resource", resourceValue, response.getText().trim() ); - assertEquals( "content type", "text/html", response.getContentType() ); - } - - - public void testDisabledRedirect() throws Exception { - String resourceName = "something/redirected"; - String resourceValue = "the desired content"; - - String redirectName = "anOldOne"; - String redirectValue = "old content"; - - defineResource( resourceName, resourceValue ); - defineResource( redirectName, redirectValue, HttpURLConnection.HTTP_MOVED_PERM ); - addResourceHeader( redirectName, "Location: " + getHostPath() + '/' + resourceName ); - - HttpUnitOptions.setAutoRedirect( false ); - WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + '/' + redirectName ); - assertEquals( "requested resource", redirectValue, response.getText().trim() ); - assertEquals( "content type", "text/html", response.getContentType() ); - } - - public void testCookies() throws Exception { String resourceName = "something/baking"; String resourceValue = "the desired content"; @@ -281,7 +227,7 @@ String resourceName = "tellMe"; String name = "Charlie"; final String prefix = "Hello there, "; - String expectedResponse = prefix + name; + String expectedResponse = prefix + name; PseudoServer ps = new PseudoServer(); int port = ps.getConnectedPort(); @@ -292,7 +238,7 @@ return new WebResource( prefix + getParameter( "name" )[0], "text/plain" ); } } ); - + WebConversation wc = new WebConversation(); WebRequest request = new PostMethodWebRequest( "http://localhost:" + port + '/' + resourceName ); request.setParameter( "name", name ); @@ -309,14 +255,14 @@ String resourceName = "tellMe"; String linkSource = "fromLink"; String formSource = "fromForm"; - + PseudoServer ps = new PseudoServer(); int port = ps.getConnectedPort(); String page0 = "http://localhost:" + port + '/' + resourceName; String page1 = "http://localhost:" + port + '/' + linkSource; String page2 = "http://localhost:" + port + '/' + formSource; - + ps.setResource( linkSource, "<html><head></head><body><a href=\"tellMe\">Go</a></body></html>" ); ps.setResource( formSource, "<html><body><form action=\"tellMe\"><input type=submit></form></body></html>" ); @@ -327,7 +273,7 @@ return new WebResource( referer == null ? "null" : referer, "text/plain" ); } } ); - + WebConversation wc = new WebConversation(); WebResponse response = wc.getResponse( page0 ); assertEquals( "Content type", "text/plain", response.getContentType() ); @@ -336,7 +282,7 @@ response = wc.getResponse( page1 ); response = wc.getResponse( response.getLinks()[0].getRequest() ); assertEquals( "Link Referer header", page1, response.getText().trim() ); - + response = wc.getResponse( page2 ); response = wc.getResponse( response.getForms()[0].getRequest() ); assertEquals( "Form Referer header", page2, response.getText().trim() ); Index: PseudoServlet.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServlet.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- PseudoServlet.java 9 Nov 2001 18:35:14 -0000 1.6 +++ PseudoServlet.java 6 Mar 2002 04:59:52 -0000 1.7 @@ -20,6 +20,7 @@ * *******************************************************************************************************************/ import java.io.Reader; +import java.io.IOException; /** * A basic simulated servlet for testing the HttpUnit library. @@ -34,7 +35,7 @@ /** * Returns a resource object as a result of a get request. **/ - public WebResource getResponse( String methodType ) { + public WebResource getResponse( String methodType ) throws IOException { if (methodType.equalsIgnoreCase( "GET" )) { return getGetResponse(); } else if (methodType.equalsIgnoreCase( "PUT" )) { @@ -50,7 +51,7 @@ /** * Returns a resource object as a result of a get request. **/ - public WebResource getGetResponse() { + public WebResource getGetResponse() throws IOException { throw new RuntimeException( "get not implemented" ); } @@ -58,7 +59,7 @@ /* * Returns a resource object as a result of a post request. **/ - public WebResource getPostResponse() { + public WebResource getPostResponse() throws IOException { throw new RuntimeException( "post not implemented" ); } @@ -66,7 +67,7 @@ /* * Returns a resource object as a result of a put request. **/ - public WebResource getPutResponse() { + public WebResource getPutResponse() throws IOException { throw new RuntimeException( "put not implemented" ); } Index: WebClientTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebClientTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- WebClientTest.java 28 Feb 2002 14:30:34 -0000 1.1 +++ WebClientTest.java 6 Mar 2002 04:59:52 -0000 1.2 @@ -20,13 +20,17 @@ * *******************************************************************************************************************/ -import java.util.List; -import java.util.ArrayList; -import java.net.MalformedURLException; -import java.io.IOException; - import junit.framework.TestSuite; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.List; +import java.util.zip.GZIPOutputStream; + /** * @@ -34,7 +38,7 @@ **/ public class WebClientTest extends HttpUnitTest { - public static void main(String args[]) { + public static void main( String args[] ) { junit.textui.TestRunner.run( suite() ); } @@ -49,17 +53,58 @@ } + public void testGZIPHandling() throws Exception { + String expectedResponse = "Here is my answer"; + defineResource( "Compressed.html", new CompressedPseudoServlet( expectedResponse ) ); + + WebConversation wc = new WebConversation(); + WebResponse wr = wc.getResponse( getHostPath() + "/Compressed.html" ); + assertEquals( "Content-Encoding header", "gzip", wr.getHeaderField( "Content-encoding" ) ); + assertEquals( "Content-Type", "text/plain", wr.getContentType() ); + assertEquals( "Content", expectedResponse, wr.getText().trim() ); + } + + + private class CompressedPseudoServlet extends PseudoServlet { + + private String _responseText; + + + public CompressedPseudoServlet( String responseText ) { + _responseText = responseText; + } + + + public WebResource getGetResponse() throws IOException { + WebResource result = new WebResource( getCompressedContents(), "text/plain" ); + result.addHeader( "Content-Encoding: gzip" ); + return result; + } + + + private byte[] getCompressedContents() throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + GZIPOutputStream gzip = new GZIPOutputStream( baos ); + OutputStreamWriter out = new OutputStreamWriter( gzip ); + out.write( _responseText ); + out.flush(); + out.close(); + return baos.toByteArray(); + } + } + + public void testClientListener() throws Exception { - defineWebPage( "Target", "This is another page with <a href=Form.html target='_top'>one link</a>" ); - defineWebPage( "Form", "This is a page with a simple form: " + - "<form action=submit><input name=name><input type=submit></form>" + - "<a href=Target.html target=red>a link</a>"); + defineWebPage( "Target", "This is another page with <a href=Form.html target='_top'>one link</a>" ); + defineWebPage( "Form", "This is a page with a simple form: " + + "<form action=submit><input name=name><input type=submit></form>" + + "<a href=Target.html target=red>a link</a>" ); defineResource( "Frames.html", - "<HTML><HEAD><TITLE>Initial</TITLE></HEAD>" + - "<FRAMESET cols='20%,80%'>" + - " <FRAME src='Target.html' name='red'>" + - " <FRAME src=Form.html name=blue>" + - "</FRAMESET></HTML>" ); + "<HTML><HEAD><TITLE>Initial</TITLE></HEAD>" + + "<FRAMESET cols='20%,80%'>" + + " <FRAME src='Target.html' name='red'>" + + " <FRAME src=Form.html name=blue>" + + "</FRAMESET></HTML>" ); WebConversation wc = new WebConversation(); ArrayList messageLog = new ArrayList(); @@ -67,19 +112,19 @@ WebResponse response = wc.getResponse( getHostPath() + "/Frames.html" ); assertEquals( "Num logged items", 6, messageLog.size() ); - for (int i=0; i <3; i++) { - verifyRequestResponsePair( messageLog, 2*i ); + for (int i = 0; i < 3; i++) { + verifyRequestResponsePair( messageLog, 2 * i ); } } private void verifyRequestResponsePair( ArrayList messageLog, int i ) throws MalformedURLException { - assertTrue( "Logged item " + i + " is not a web request, but " + messageLog.get(i).getClass(), - messageLog.get(i) instanceof WebRequest ); - assertTrue( "Logged item " + (i+1) + " is not a web response, but " + messageLog.get(i+1).getClass(), - messageLog.get(i+1) instanceof WebResponse ); - assertEquals( "Response target", ((WebRequest) messageLog.get(i)).getTarget(), ((WebResponse) messageLog.get(i+1)).getTarget() ); - assertEquals( "Response URL", ((WebRequest) messageLog.get(i)).getURL(), ((WebResponse) messageLog.get(i+1)).getURL() ); + assertTrue( "Logged item " + i + " is not a web request, but " + messageLog.get( i ).getClass(), + messageLog.get( i ) instanceof WebRequest ); + assertTrue( "Logged item " + (i + 1) + " is not a web response, but " + messageLog.get( i + 1 ).getClass(), + messageLog.get( i + 1 ) instanceof WebResponse ); + assertEquals( "Response target", ((WebRequest) messageLog.get( i )).getTarget(), ((WebResponse) messageLog.get( i + 1 )).getTarget() ); + assertEquals( "Response URL", ((WebRequest) messageLog.get( i )).getURL(), ((WebResponse) messageLog.get( i + 1 )).getURL() ); } @@ -100,7 +145,61 @@ public void responseReceived( WebClient src, WebResponse resp ) { _messageLog.add( resp ); - } + } + } + + + public void testRedirect() throws Exception { + String resourceName = "something/redirected"; + String resourceValue = "the desired content"; + + String redirectName = "anOldOne"; + + defineResource( resourceName, resourceValue ); + defineResource( redirectName, "ignored content", HttpURLConnection.HTTP_MOVED_PERM ); + addResourceHeader( redirectName, "Location: " + getHostPath() + '/' + resourceName ); + + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + '/' + redirectName ); + assertEquals( "requested resource", resourceValue, response.getText().trim() ); + assertEquals( "content type", "text/html", response.getContentType() ); + } + + + public void testDuplicateHeaderRedirect() throws Exception { + String resourceName = "something/redirected"; + String resourceValue = "the desired content"; + + String redirectName = "anOldOne"; + + defineResource( resourceName, resourceValue ); + defineResource( redirectName, "ignored content", HttpURLConnection.HTTP_MOVED_PERM ); + addResourceHeader( redirectName, "Location: " + getHostPath() + '/' + resourceName ); + addResourceHeader( redirectName, "Location: " + getHostPath() + '/' + resourceName ); + + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + '/' + redirectName ); + assertEquals( "requested resource", resourceValue, response.getText().trim() ); + assertEquals( "content type", "text/html", response.getContentType() ); + } + + + public void testDisabledRedirect() throws Exception { + String resourceName = "something/redirected"; + String resourceValue = "the desired content"; + + String redirectName = "anOldOne"; + String redirectValue = "old content"; + + defineResource( resourceName, resourceValue ); + defineResource( redirectName, redirectValue, HttpURLConnection.HTTP_MOVED_PERM ); + addResourceHeader( redirectName, "Location: " + getHostPath() + '/' + resourceName ); + + HttpUnitOptions.setAutoRedirect( false ); + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + '/' + redirectName ); + assertEquals( "requested resource", redirectValue, response.getText().trim() ); + assertEquals( "content type", "text/html", response.getContentType() ); } |
From: Russell G. <rus...@us...> - 2002-03-06 04:59:55
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv9204/src/com/meterware/servletunit Modified Files: InvocationContext.java InvocationContextImpl.java ServletUnitWebResponse.java Log Message: Added support for gzip-encoded responses Index: InvocationContext.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/InvocationContext.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- InvocationContext.java 30 Nov 2001 15:27:35 -0000 1.4 +++ InvocationContext.java 6 Mar 2002 04:59:52 -0000 1.5 @@ -3,7 +3,7 @@ /******************************************************************************************************************** * $Id$ * - * Copyright (c) 2001, Russell Gold + * Copyright (c) 2001-2002, 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 @@ -26,9 +26,11 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.Servlet; import javax.servlet.ServletException; +import java.io.IOException; /** + * An interface which represents the invocation of a servlet. * * @author <a href="mailto:rus...@ac...">Russell Gold</a> **/ @@ -58,7 +60,7 @@ * Returns the final response from the servlet. Note that this method should * only be invoked after all processing has been done to the servlet response. **/ - WebResponse getServletResponse(); + WebResponse getServletResponse() throws IOException; /** Index: InvocationContextImpl.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/InvocationContextImpl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- InvocationContextImpl.java 4 Feb 2002 22:33:55 -0000 1.3 +++ InvocationContextImpl.java 6 Mar 2002 04:59:52 -0000 1.4 @@ -87,7 +87,7 @@ * Returns the final response from the servlet. Note that this method should * only be invoked after all processing has been done to the servlet response. **/ - public WebResponse getServletResponse() { + public WebResponse getServletResponse() throws IOException { if (_webResponse == null) { HttpSession session = _request.getSession( /* create */ false ); if (session != null && session.isNew()) { Index: ServletUnitWebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitWebResponse.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- ServletUnitWebResponse.java 6 Mar 2002 03:45:57 -0000 1.8 +++ ServletUnitWebResponse.java 6 Mar 2002 04:59:52 -0000 1.9 @@ -4,12 +4,12 @@ * * Copyright (c) 2000-2001, 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 +* 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 +* 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 @@ -38,7 +38,7 @@ import javax.servlet.http.HttpServletResponse; import com.meterware.httpunit.*; - + /** * A response from to a request from the simulated servlet environment. @@ -52,7 +52,7 @@ * @param url the url from which the response was received * @param response the response populated by the servlet **/ - ServletUnitWebResponse( String target, URL url, HttpServletResponse response ) { + ServletUnitWebResponse( String target, URL url, HttpServletResponse response ) throws IOException { super( target, url ); _response = (ServletUnitHttpResponse) response; defineRawInputStream( new ByteArrayInputStream( _response.getContents() ) ); @@ -97,8 +97,8 @@ public String toString() { return "[ _response = " + _response + "]"; } - - + + //-------------------------------------------- private members ------------------------------------------------ |
From: Russell G. <rus...@us...> - 2002-03-06 04:59:55
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv9204/src/com/meterware/httpunit Modified Files: HttpWebResponse.java WebResponse.java Log Message: Added support for gzip-encoded responses Index: HttpWebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpWebResponse.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- HttpWebResponse.java 6 Mar 2002 03:45:57 -0000 1.20 +++ HttpWebResponse.java 6 Mar 2002 04:59:52 -0000 1.21 @@ -2,14 +2,14 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000-2001, Russell Gold +* Copyright (c) 2000-2002, 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 +* 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 +* 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 @@ -31,7 +31,7 @@ import java.util.Hashtable; import java.util.StringTokenizer; import java.util.Vector; - + /** * A response from a web server to an Http request. @@ -118,7 +118,7 @@ private Hashtable _headers = new Hashtable(); - + private void readResponseHeader( URLConnection connection ) { if (connection.getHeaderField(0) == null) throw new HttpNotFoundException( connection.getURL() ); @@ -166,7 +166,7 @@ if (connection.getContentType() != null) { setContentTypeHeader( connection.getContentType() ); - } + } } Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.63 retrieving revision 1.64 diff -u -r1.63 -r1.64 --- WebResponse.java 6 Mar 2002 03:45:57 -0000 1.63 +++ WebResponse.java 6 Mar 2002 04:59:52 -0000 1.64 @@ -20,13 +20,7 @@ * *******************************************************************************************************************/ -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.InputStream; -import java.io.IOException; -import java.io.StreamTokenizer; -import java.io.StringReader; -import java.io.UnsupportedEncodingException; +import java.io.*; import java.lang.reflect.Constructor; @@ -40,6 +34,7 @@ import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; +import java.util.zip.GZIPInputStream; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -451,11 +446,22 @@ final - protected void defineRawInputStream( InputStream inputStream ) { + protected void defineRawInputStream( InputStream inputStream ) throws IOException { if (_inputStream != null || _responseText != null) { throw new IllegalStateException( "Must be called before response text is defined." ); } - _inputStream = inputStream; + + if (encodedUsingGZIP()) { + _inputStream = new GZIPInputStream( inputStream ); + } else { + _inputStream = inputStream; + } + } + + + private boolean encodedUsingGZIP() { + String encoding = getHeaderField( "Content-Encoding" ); + return encoding != null && encoding.indexOf( "gzip" ) >= 0; } |
From: Russell G. <rus...@us...> - 2002-03-06 04:59:55
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv9204/doc Modified Files: release_notes.txt Log Message: Added support for gzip-encoded responses Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.96 retrieving revision 1.97 diff -u -r1.96 -r1.97 --- release_notes.txt 6 Mar 2002 03:45:55 -0000 1.96 +++ release_notes.txt 6 Mar 2002 04:59:52 -0000 1.97 @@ -46,32 +46,33 @@ 2. HttpUnit now handles multiple file form controls with the same name. 3. WebResponse now has a getSubframeContents method which returns the contents of a subframe of the frame represented by the response. + 4. gzip-encoded responses are now handled ServletUnit enhancements - 4. ServletUnit now supports creating a RequestDispatcher from ServletContext to forward to other servlets. - Support for this is rudimentary at present: query parameters on the request dispatcher create are ignored. 5. ServletUnit now supports the web.xml <context-param> tag. 6. ServletUnit now supports the HttpServletRequest.getRequestURI method 7. ServletUnit now supports defining (and retrieving) a non-empty context path for a web application 8. ServletUnit now supports wild-cards in web.xml servlet mapping + 9. ServletUnit now supports creating a RequestDispatcher from ServletContext to forward to other servlets. + Support for this is rudimentary at present: query parameters on the request dispatcher create are ignored. Form manipulation enhancements: - 9. It is now possible to set values for a form directly into the WebForm object. All such changes will be validated. + 10. It is now possible to set values for a form directly into the WebForm object. All such changes will be validated. These will be used by any requests derived from the form. - 10. Parameters defined in form query strings are now included in the known parameters of a form and requests + 11. Parameters defined in form query strings are now included in the known parameters of a form and requests built from it. - 11. Form parameters can be reset to their initial values using WebForm.reset(). - 12. You can now change the position of an image button click in a request with WebRequest.setImageButtonClickPosition() + 12. Form parameters can be reset to their initial values using WebForm.reset(). + 13. You can now change the position of an image button click in a request with WebRequest.setImageButtonClickPosition() Test properties enhancements: - 12. You can now call HttpUnitOptions.setAutoRedirect( false ) to enable explicit testing of redirect requests. - 13. WebClient now has an exceptionsThrownOnErrorStatus property to control this behavior per client. + 14. You can now call HttpUnitOptions.setAutoRedirect( false ) to enable explicit testing of redirect requests. + 15. WebClient now has an exceptionsThrownOnErrorStatus property to control this behavior per client. Extensibility enhancements: - 14. HttpUnit can now use any jaxp-compliant parser, rather than just xerces. - 15. MessageBodyWebRequest's constructors and inner class are now public, allowing outside code to create new request classes. - 16. WebClient now exposes the protected method writeMessageBody to ease implementation of new subclasses - 17. WebClient can now accept a listener of type WebClientListener to report on each request sent and response received. + 16. HttpUnit can now use any jaxp-compliant parser, rather than just xerces. + 17. MessageBodyWebRequest's constructors and inner class are now public, allowing outside code to create new request classes. + 18. WebClient now exposes the protected method writeMessageBody to ease implementation of new subclasses + 19. WebClient can now accept a listener of type WebClientListener to report on each request sent and response received. Notes: 1. Parameter validation is now handled by the form. Requests created from the form while parameter validation is |
From: Russell G. <rus...@us...> - 2002-03-06 03:46:03
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv30932/test/com/meterware/httpunit Modified Files: PseudoServerTest.java Log Message: Corrected handling of multiple headers Index: PseudoServerTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServerTest.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- PseudoServerTest.java 28 Feb 2002 14:30:34 -0000 1.22 +++ PseudoServerTest.java 6 Mar 2002 03:45:57 -0000 1.23 @@ -170,21 +170,32 @@ String redirectName = "anOldOne"; - PseudoServer ps = new PseudoServer(); - int port = ps.getConnectedPort(); - ps.setResource( resourceName, resourceValue ); - ps.setErrorResource( redirectName, HttpURLConnection.HTTP_MOVED_PERM, "" ); - ps.addResourceHeader( redirectName, "Location: http://localhost:" + port + '/' + resourceName ); - - try { - WebConversation wc = new WebConversation(); - WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + '/' + redirectName ); - WebResponse response = wc.getResponse( request ); - assertEquals( "requested resource", resourceValue, response.getText().trim() ); - assertEquals( "content type", "text/html", response.getContentType() ); - } finally { - ps.shutDown(); - } + defineResource( resourceName, resourceValue ); + defineResource( redirectName, "ignored content", HttpURLConnection.HTTP_MOVED_PERM ); + addResourceHeader( redirectName, "Location: " + getHostPath() + '/' + resourceName ); + + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + '/' + redirectName ); + assertEquals( "requested resource", resourceValue, response.getText().trim() ); + assertEquals( "content type", "text/html", response.getContentType() ); + } + + + public void testDuplicateHeaderRedirect() throws Exception { + String resourceName = "something/redirected"; + String resourceValue = "the desired content"; + + String redirectName = "anOldOne"; + + defineResource( resourceName, resourceValue ); + defineResource( redirectName, "ignored content", HttpURLConnection.HTTP_MOVED_PERM ); + addResourceHeader( redirectName, "Location: " + getHostPath() + '/' + resourceName ); + addResourceHeader( redirectName, "Location: " + getHostPath() + '/' + resourceName ); + + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + '/' + redirectName ); + assertEquals( "requested resource", resourceValue, response.getText().trim() ); + assertEquals( "content type", "text/html", response.getContentType() ); } @@ -195,23 +206,15 @@ String redirectName = "anOldOne"; String redirectValue = "old content"; - PseudoServer ps = new PseudoServer(); - int port = ps.getConnectedPort(); - ps.setResource( resourceName, resourceValue ); - ps.setErrorResource( redirectName, HttpURLConnection.HTTP_MOVED_PERM, redirectValue ); - ps.addResourceHeader( redirectName, "Location: http://localhost:" + port + '/' + resourceName ); - - try { - HttpUnitOptions.setAutoRedirect( false ); - WebConversation wc = new WebConversation(); - WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + '/' + redirectName ); - WebResponse response = wc.getResponse( request ); - assertEquals( "requested resource", redirectValue, response.getText().trim() ); - assertEquals( "content type", "text/html", response.getContentType() ); - } finally { - HttpUnitOptions.setAutoRedirect( true ); - ps.shutDown(); - } + defineResource( resourceName, resourceValue ); + defineResource( redirectName, redirectValue, HttpURLConnection.HTTP_MOVED_PERM ); + addResourceHeader( redirectName, "Location: " + getHostPath() + '/' + resourceName ); + + HttpUnitOptions.setAutoRedirect( false ); + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + '/' + redirectName ); + assertEquals( "requested resource", redirectValue, response.getText().trim() ); + assertEquals( "content type", "text/html", response.getContentType() ); } |
From: Russell G. <rus...@us...> - 2002-03-06 03:46:02
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv30932/src/com/meterware/httpunit Modified Files: HttpUnitUtils.java HttpWebResponse.java WebLink.java WebResponse.java Log Message: Corrected handling of multiple headers Index: HttpUnitUtils.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitUtils.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- HttpUnitUtils.java 1 Feb 2002 14:21:35 -0000 1.7 +++ HttpUnitUtils.java 6 Mar 2002 03:45:57 -0000 1.8 @@ -100,4 +100,20 @@ throw new SAXException( ex ); } } + + + /** + * Returns a string array created by appending a string to an existing array. The existing array may be null. + **/ + static String[] withNewValue( String[] oldValue, String newValue ) { + String[] result; + if (oldValue == null) { + result = new String[] { newValue }; + } else { + result = new String[ oldValue.length+1 ]; + System.arraycopy( oldValue, 0, result, 0, oldValue.length ); + result[ oldValue.length ] = newValue; + } + return result; + } } Index: HttpWebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpWebResponse.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- HttpWebResponse.java 14 Feb 2002 14:33:49 -0000 1.19 +++ HttpWebResponse.java 6 Mar 2002 03:45:57 -0000 1.20 @@ -90,10 +90,17 @@ * Returns the value for the specified header field. If no such field is defined, will return null. **/ public String getHeaderField( String fieldName ) { - return (String) _headers.get( fieldName.toUpperCase() ); + String[] fields = (String[]) _headers.get( fieldName.toUpperCase()); + return fields == null ? null : fields[0]; } - - + + + public String[] getHeaderFields( String fieldName ) { + String[] fields = (String[]) _headers.get( fieldName.toUpperCase()); + return fields == null ? new String[0] : fields; + } + + public String toString() { return "HttpWebResponse [url=" + getURL() + "; headers=" + _headers + "]"; } @@ -165,11 +172,7 @@ private void addHeader( String key, String field ) { - if (_headers.get( key ) == null) { - _headers.put( key, field ); - } else { - _headers.put( key, _headers.get( key ) + ", " + field ); - } + _headers.put( key, HttpUnitUtils.withNewValue( (String[]) _headers.get( key ), field ) ); } } Index: WebLink.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- WebLink.java 4 Feb 2002 22:33:55 -0000 1.17 +++ WebLink.java 6 Mar 2002 03:45:57 -0000 1.18 @@ -238,25 +238,10 @@ protected void addPresetParameter( String name, String value ) { - _presetParameterMap.put( name, withNewValue( (String[]) _presetParameterMap.get( name ), value ) ); + _presetParameterMap.put( name, HttpUnitUtils.withNewValue( (String[]) _presetParameterMap.get( name ), value ) ); _presetParameterList.add( new LinkParameter( name, value ) ); } - - /** - * Returns a string array created by appending a string to an existing array. The existing array may be null. - **/ - private String[] withNewValue( String[] oldValue, String newValue ) { - String[] result; - if (oldValue == null) { - result = new String[] { newValue }; - } else { - result = new String[ oldValue.length+1 ]; - System.arraycopy( oldValue, 0, result, 0, oldValue.length ); - result[ oldValue.length ] = newValue; - } - return result; - } } Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.62 retrieving revision 1.63 diff -u -r1.62 -r1.63 --- WebResponse.java 14 Feb 2002 14:33:49 -0000 1.62 +++ WebResponse.java 6 Mar 2002 03:45:57 -0000 1.63 @@ -222,13 +222,20 @@ /** * Returns the value for the specified header field. If no such field is defined, will return null. - * No more than one header may be defined for each key. + * If more than one header is defined for the specified name, returns only the first found. **/ abstract public String getHeaderField( String fieldName ); /** + * Returns the values for the specified header field. If no such field is defined, will return an empty array. + **/ + abstract + public String[] getHeaderFields( String fieldName ); + + + /** * 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. **/ @@ -648,17 +655,20 @@ */ private Hashtable getNewCookies() { if (_newCookies == null) _newCookies = new Hashtable(); - processCookieHeader( getHeaderField( "Set-Cookie" ), IETF_RFC2109 ); - processCookieHeader( getHeaderField( "Set-Cookie2" ), IETF_RFC2965 ); + processCookieHeaders( getHeaderFields( "Set-Cookie" ), IETF_RFC2109 ); + processCookieHeaders( getHeaderFields( "Set-Cookie2" ), IETF_RFC2965 ); return _newCookies; } - /** - * - */ + private void processCookieHeaders( String cookieHeader[], int version ) { + for (int i = 0; i < cookieHeader.length; i++) { + processCookieHeader( cookieHeader[i], version ); + } + } + + private void processCookieHeader( String cookieHeader, int version ) { - if (cookieHeader == null) return; Vector tokens = getCookieTokens( cookieHeader ); String tokensToAdd = ""; for (int i = tokens.size() - 1; i >= 0; i--) { @@ -989,6 +999,10 @@ } } + public String[] getHeaderFields( String fieldName ) { + String value = getHeaderField( fieldName ); + return value == null ? new String[0] : new String[]{ value }; + } /** * Returns the text of the response (excluding headers) as a string. Use this method in preference to 'toString' |
From: Russell G. <rus...@us...> - 2002-03-06 03:46:01
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv30932/src/com/meterware/servletunit Modified Files: ServletUnitWebResponse.java Log Message: Corrected handling of multiple headers Index: ServletUnitWebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitWebResponse.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- ServletUnitWebResponse.java 8 Nov 2001 22:07:53 -0000 1.7 +++ ServletUnitWebResponse.java 6 Mar 2002 03:45:57 -0000 1.8 @@ -86,8 +86,14 @@ public String getHeaderField( String fieldName ) { return _response.getHeaderField( fieldName ); } - - + + + public String[] getHeaderFields( String fieldName ) { + String field = getHeaderField( fieldName ); + return field == null ? NO_HEADERS : new String[] { _response.getHeaderField( fieldName ) }; + } + + public String toString() { return "[ _response = " + _response + "]"; } @@ -98,6 +104,7 @@ private ServletUnitHttpResponse _response; + private static final String[] NO_HEADERS = new String[0]; } |
From: Russell G. <rus...@us...> - 2002-03-06 03:46:01
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv30932/doc Modified Files: release_notes.txt Log Message: Corrected handling of multiple headers Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.95 retrieving revision 1.96 diff -u -r1.95 -r1.96 --- release_notes.txt 4 Mar 2002 02:10:49 -0000 1.95 +++ release_notes.txt 6 Mar 2002 03:45:55 -0000 1.96 @@ -38,6 +38,7 @@ 10. Forms with query strings included in the action attribute now are submitted with that string intact. 11. (bug #490821) Javadoc generation no longer gives errors 12. (bug #524627) Null pointer exception in NodeUtils.convertNBSP + 13. (bug #513051) Multiple headers with the same name are now handled independantly Additions: Content and parsing enhancements: |
From: Russell G. <rus...@us...> - 2002-03-04 02:10:53
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv12045/src/com/meterware/httpunit Modified Files: NodeUtils.java WebRequest.java Log Message: Get ready for 1.4 release Index: NodeUtils.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/NodeUtils.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- NodeUtils.java 8 Jan 2002 23:21:53 -0000 1.10 +++ NodeUtils.java 4 Mar 2002 02:10:49 -0000 1.11 @@ -117,6 +117,7 @@ private static String convertNBSP( String text ) { + if (text == null) return ""; return text.replace( NBSP, ' ' ); } Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.39 retrieving revision 1.40 diff -u -r1.39 -r1.40 --- WebRequest.java 4 Feb 2002 22:33:55 -0000 1.39 +++ WebRequest.java 4 Mar 2002 02:10:50 -0000 1.40 @@ -47,6 +47,7 @@ **/ abstract public class WebRequest { + private SubmitButton _button; /** * Sets the value of a header to be sent with this request. A header set here will override any matching header set @@ -127,6 +128,19 @@ /** + * Specifies the click position for the submit button. When a user clioks on an image button, not only the name + * and value of the button, but also the position of the mouse at the time of the click is submitted with the form. + * This method allows the caller to override the position selected when this request was created. + * + * @exception IllegalRequestParameterException thrown if the request was not created from a form with an image button. + **/ + public void setImageButtonClickPosition( int x, int y ) throws IllegalRequestParameterException { + if (_button == null) throw new IllegalButtonPositionException(); + _parameterHolder.selectImageButtonPosition( _button, x, y ); + } + + + /** * Returns true if the specified parameter is a file field. **/ public boolean isFileParameter( String name ) { @@ -253,7 +267,8 @@ protected WebRequest( WebForm sourceForm, SubmitButton button, int x, int y ) { this( sourceForm ); if (button != null && button.isImageButton() && button.getName().length() > 0) { - _parameterHolder.selectImageButtonPosition( button, x, y ); + _button = button; + _parameterHolder.selectImageButtonPosition( _button, x, y ); } } @@ -574,6 +589,26 @@ public String getMessage() { return "The request does not use multipart/form-data encoding, and cannot be used to upload files "; + } + +} + + +//============================= exception class IllegalButtonPositionException ====================================== + + +/** + * This exception is thrown on an attempt to set a file parameter in a form that does not specify MIME encoding. + **/ +class IllegalButtonPositionException extends IllegalRequestParameterException { + + + IllegalButtonPositionException() { + } + + + public String getMessage() { + return "The request was not created with an image button, and cannot accept an image button click position"; } } |
From: Russell G. <rus...@us...> - 2002-03-04 02:10:53
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv12045/test/com/meterware/httpunit Modified Files: FormSubmitTest.java Log Message: Get ready for 1.4 release Index: FormSubmitTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FormSubmitTest.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- FormSubmitTest.java 1 Mar 2002 18:09:04 -0000 1.14 +++ FormSubmitTest.java 4 Mar 2002 02:10:50 -0000 1.15 @@ -227,6 +227,8 @@ WebForm form = page.getForms()[0]; WebRequest request = form.getRequest( form.getSubmitButton( "update" ), 10, 15 ); assertEquals( getHostPath() + "/ask?age=12&update=name&update.x=10&update.y=15", request.getURL().toExternalForm() ); + request.setImageButtonClickPosition( 5, 20 ); + assertEquals( getHostPath() + "/ask?age=12&update=name&update.x=5&update.y=20", request.getURL().toExternalForm() ); } @@ -296,6 +298,12 @@ request = form.getRequest( "update" ); assertEquals( getHostPath() + "/ask?age=12&update=age", request.getURL().toExternalForm() ); + + try { + request.setImageButtonClickPosition( 1, 2 ); + fail( "Should not allow set position with non-image button" ); + } catch (IllegalRequestParameterException e) { + } } |
From: Russell G. <rus...@us...> - 2002-03-04 02:10:52
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv12045/doc Modified Files: release_notes.txt Log Message: Get ready for 1.4 release Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.94 retrieving revision 1.95 diff -u -r1.94 -r1.95 --- release_notes.txt 3 Mar 2002 22:59:59 -0000 1.94 +++ release_notes.txt 4 Mar 2002 02:10:49 -0000 1.95 @@ -12,7 +12,7 @@ Revision History: - 1-Mar-2002 + 6-Mar-2002 1.4 Acknowledgements: Thanks to Didier Besset for correcting the WebForm methods: hasParameterNamed and hasParameterStartingWithPrefix Thanks to Stefan G. Renz for identifying the infinite loop bug in frame handling @@ -24,6 +24,7 @@ Thanks to Peter Royal for correcting handling of long line numbers in JTidyWriter, based on locale Thanks to Peter Rossbach for some documentation and build fixes + Problems fixed: 1. hasParameterNamed and hasParameterStartingWithPrefix now check all types of parameters, not just <INPUT> fields 2. (bug #492003) JTidyPrintWriter fails to parse columns @@ -36,6 +37,7 @@ 9. Control characters and spaces created by breaking HTML in the middle are now trimmed from link parameters. 10. Forms with query strings included in the action attribute now are submitted with that string intact. 11. (bug #490821) Javadoc generation no longer gives errors + 12. (bug #524627) Null pointer exception in NodeUtils.convertNBSP Additions: Content and parsing enhancements: @@ -58,6 +60,7 @@ 10. Parameters defined in form query strings are now included in the known parameters of a form and requests built from it. 11. Form parameters can be reset to their initial values using WebForm.reset(). + 12. You can now change the position of an image button click in a request with WebRequest.setImageButtonClickPosition() Test properties enhancements: 12. You can now call HttpUnitOptions.setAutoRedirect( false ) to enable explicit testing of redirect requests. |
From: Russell G. <rus...@us...> - 2002-03-04 02:10:52
|
Update of /cvsroot/httpunit/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv12045 Modified Files: build.xml Log Message: Get ready for 1.4 release Index: build.xml =================================================================== RCS file: /cvsroot/httpunit/httpunit/build.xml,v retrieving revision 1.41 retrieving revision 1.42 diff -u -r1.41 -r1.42 --- build.xml 3 Mar 2002 22:59:28 -0000 1.41 +++ build.xml 4 Mar 2002 02:10:49 -0000 1.42 @@ -5,7 +5,7 @@ <project name="httpunit" default="jar" basedir="."> <property name="name" value="httpunit" /> <property name="Name" value="HttpUnit" /> - <property name="version" value="1.3.5" /> + <property name="version" value="1.4" /> <property name="debug" value="on" /> <property name="deprecation" value="off" /> |
From: Russell G. <rus...@us...> - 2002-03-03 23:00:03
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv18648/test/com/meterware/servletunit Modified Files: HttpServletRequestTest.java WebXMLTest.java Log Message: from Donald Ball: ServletUnit enhancements Index: HttpServletRequestTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/HttpServletRequestTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- HttpServletRequestTest.java 4 Feb 2002 22:33:55 -0000 1.4 +++ HttpServletRequestTest.java 3 Mar 2002 23:00:00 -0000 1.5 @@ -4,12 +4,12 @@ * * Copyright (c) 2000-2001, 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 +* 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 +* 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 @@ -40,8 +40,8 @@ public static void main(String args[]) { junit.textui.TestRunner.run( suite() ); } - - + + public static Test suite() { return new TestSuite( HttpServletRequestTest.class ); } @@ -205,6 +205,20 @@ HttpSession session = request.getSession( /* create */ false ); assertNotNull( "No session created", session ); } + + + public void testGetRequestURI() throws Exception { + ServletUnitContext context = new ServletUnitContext(); + WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" ); + + ServletUnitHttpRequest request = new ServletUnitHttpRequest( wr, context, new Hashtable(), NO_MESSAGE_BODY ); + assertEquals("/simple", request.getRequestURI()); + + wr = new GetMethodWebRequest( "http://localhost/simple?foo=bar" ); + request = new ServletUnitHttpRequest( wr, context, new Hashtable(), NO_MESSAGE_BODY); + assertEquals("/simple", request.getRequestURI()); + } + private final static byte[] NO_MESSAGE_BODY = new byte[0]; } Index: WebXMLTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/WebXMLTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- WebXMLTest.java 30 Jan 2002 21:21:11 -0000 1.6 +++ WebXMLTest.java 3 Mar 2002 23:00:00 -0000 1.7 @@ -31,6 +31,7 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.servlet.Servlet; import javax.servlet.ServletException; import org.xml.sax.SAXException; @@ -222,6 +223,69 @@ } + public void testGetContextPath() throws Exception { + WebXMLString wxs = new WebXMLString(); + wxs.addServlet( "/SimpleServlet", SimpleGetServlet.class ); + + ServletRunner sr = new ServletRunner( toInputStream( wxs.asText() ), "/mount" ); + ServletUnitClient wc = sr.newClient(); + InvocationContext ic = wc.newInvocation( "http://localhost/mount/SimpleServlet" ); + assertEquals("/mount", ic.getRequest().getContextPath()); + + sr = new ServletRunner( toInputStream( wxs.asText() ) ); + wc = sr.newClient(); + ic = wc.newInvocation( "http://localhost/SimpleServlet" ); + assertEquals("", ic.getRequest().getContextPath()); + } + + + public void testMountContextPath() throws Exception { + WebXMLString wxs = new WebXMLString(); + wxs.addServlet( "/SimpleServlet", SimpleGetServlet.class ); + + ServletRunner sr = new ServletRunner( toInputStream( wxs.asText() ), "/mount" ); + ServletUnitClient wc = sr.newClient(); + InvocationContext ic = wc.newInvocation( "http://localhost/mount/SimpleServlet" ); + assertTrue(ic.getServlet() instanceof SimpleGetServlet); + assertEquals("/mount/SimpleServlet", ic.getRequest().getRequestURI()); + + try { + ic = wc.newInvocation( "http://localhost/SimpleServlet" ); + Servlet servlet = ic.getServlet(); + fail("Attempt to access url outside of the webapp context path should have thrown a 404"); + } catch (com.meterware.httpunit.HttpNotFoundException e) {} + } + + + public void testServletMapping() throws Exception { + WebXMLString wxs = new WebXMLString(); + wxs.addServlet("/foo/bar/*", Servlet1.class); + wxs.addServlet("/baz/*", Servlet2.class); + wxs.addServlet("/catalog", Servlet3.class); + wxs.addServlet("*.bop", Servlet4.class); + ServletRunner sr = new ServletRunner( toInputStream( wxs.asText() )); + ServletUnitClient wc = sr.newClient(); + InvocationContext ic = wc.newInvocation("http://localhost/foo/bar/index.html"); + assertTrue(ic.getServlet() instanceof Servlet1); + ic = wc.newInvocation("http://localhost/foo/bar/index.bop"); + assertTrue(ic.getServlet() instanceof Servlet1); + ic = wc.newInvocation("http://localhost/baz"); + assertTrue(ic.getServlet() instanceof Servlet2); + ic = wc.newInvocation("http://localhost/baz/index.html"); + assertTrue(ic.getServlet() instanceof Servlet2); + ic = wc.newInvocation("http://localhost/catalog"); + assertTrue(ic.getServlet() instanceof Servlet3); + try { + ic = wc.newInvocation("http://localhost/catalog/index.html"); + Servlet servlet = ic.getServlet(); + fail("Should have gotten a 404"); + } catch (HttpNotFoundException e) {} + ic = wc.newInvocation("http://localhost/catalog/racecar.bop"); + assertTrue(ic.getServlet() instanceof Servlet4); + ic = wc.newInvocation("http://localhost/index.bop"); + assertTrue(ic.getServlet() instanceof Servlet4); + } + private final static String DOCTYPE = "<!DOCTYPE web-app PUBLIC " + " \"-//Sun Microsystems, Inc.//DTD WebApplication 2.2//EN\" " + " \"http://java.sun/com/j2ee/dtds/web-app_2_2.dtd\">"; @@ -274,6 +338,11 @@ pw.close(); } } + + static class Servlet1 extends SimpleGetServlet {} + static class Servlet2 extends SimpleGetServlet {} + static class Servlet3 extends SimpleGetServlet {} + static class Servlet4 extends SimpleGetServlet {} } |