httpunit-commit Mailing List for httpunit (Page 33)
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...> - 2003-03-19 03:45:17
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver
In directory sc8-pr-cvs1:/tmp/cvs-serv8325/src/com/meterware/pseudoserver
Modified Files:
HttpRequest.java PseudoServer.java WebResource.java
Log Message:
Continuing work towards persistent connection support
Index: HttpRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver/HttpRequest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HttpRequest.java 18 Mar 2003 19:35:33 -0000 1.1
+++ HttpRequest.java 19 Mar 2003 03:38:06 -0000 1.2
@@ -191,13 +191,14 @@
}
- boolean requestedCloseConnection() {
+ boolean wantsKeepAlive() {
+ return false;
// if ("Keep-alive".equalsIgnoreCase( getConnectionHeader() )) {
-// return false;
+// return true;
// } else if (_protocol.equals( "HTTP/1.1" )) {
-// return "Close".equalsIgnoreCase( getConnectionHeader() );
+// return !"Close".equalsIgnoreCase( getConnectionHeader() );
// } else {
- return true;
+// return false;
// }
}
Index: PseudoServer.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver/PseudoServer.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PseudoServer.java 18 Mar 2003 19:35:33 -0000 1.6
+++ PseudoServer.java 19 Mar 2003 03:38:06 -0000 1.7
@@ -4,12 +4,12 @@
*
* Copyright (c) 2000-2003, 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
@@ -213,23 +213,29 @@
final BufferedInputStream inputStream = new BufferedInputStream( socket.getInputStream() );
final HttpResponseStream outputStream = new HttpResponseStream( socket.getOutputStream() );
- HttpRequest request;
- do {
- request = new HttpRequest( inputStream );
- respondToRequest( request, outputStream );
- } while (!request.requestedCloseConnection() );
+ while (_active) {
+ HttpRequest request = new HttpRequest( inputStream );
+ boolean keepAlive = respondToRequest( request, outputStream );
+ if (!keepAlive) break;
+ while (_active && 0 == inputStream.available()) {
+ try { Thread.sleep(10); } catch (InterruptedException e) {}
+ }
+ }
outputStream.close();
socket.close();
}
- private void respondToRequest( HttpRequest request, HttpResponseStream response ) {
+ private boolean respondToRequest( HttpRequest request, HttpResponseStream response ) {
+ boolean keepAlive = request.wantsKeepAlive();
try {
+ response.restart();
response.setProtocol( request.getProtocol() );
WebResource resource = getResource( request );
if (resource == null) {
response.setResponse( HttpURLConnection.HTTP_NOT_FOUND, "unable to find " + request.getURI() );
} else {
+ if (resource.closesConnection()) keepAlive = false;
if (resource.getResponseCode() != HttpURLConnection.HTTP_OK) {
response.setResponse( resource.getResponseCode(), "" );
}
@@ -245,6 +251,7 @@
t.printStackTrace();
response.setResponse( HttpURLConnection.HTTP_INTERNAL_ERROR, t.toString() );
}
+ return keepAlive;
}
@@ -313,6 +320,11 @@
final private static String CRLF = "\r\n";
+ void restart() {
+ _headersWritten = false;
+ _headers.clear();
+ }
+
void close() throws IOException {
flushHeaders();
@@ -356,6 +368,7 @@
void write( WebResource resource ) throws IOException {
flushHeaders();
resource.writeTo( _stream );
+ _stream.flush();
}
@@ -371,7 +384,6 @@
for (Enumeration e = _headers.elements(); e.hasMoreElements();) {
sendLine( (String) e.nextElement() );
}
- sendLine( "Connection: close" ); // TODO get rid of this
sendText( CRLF );
_headersWritten = true;
_pw.flush();
Index: WebResource.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver/WebResource.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- WebResource.java 18 Mar 2003 19:35:33 -0000 1.4
+++ WebResource.java 19 Mar 2003 03:38:06 -0000 1.5
@@ -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
@@ -38,6 +38,7 @@
final static String DEFAULT_CONTENT_TYPE = "text/html";
final static String DEFAULT_CHARACTER_SET = "iso-8859-1";
+ private boolean _closesConnection;
public WebResource( String contents ) {
@@ -59,6 +60,8 @@
_headers.addElement( header );
if (header.toLowerCase().startsWith( "content-type" )) _hasExplicitContentTypeHeader = true;
if (header.toLowerCase().startsWith( "content-length" )) _hasExplicitContentLengthHeader = true;
+ if (header.trim().toLowerCase().startsWith( "connection" ) &&
+ header.trim().toLowerCase().endsWith( "close") ) _closesConnection = true;
}
@@ -108,6 +111,11 @@
}
+ boolean closesConnection() {
+ return _closesConnection;
+ }
+
+
void writeTo( OutputStream outputStream ) throws IOException {
if (_stream == null) {
outputStream.write( getContentsAsBytes() );
@@ -163,7 +171,7 @@
public String toString() {
- return "WebResource [code=" + _responseCode + "; type = " + _contentType
+ return "WebResource [code=" + _responseCode + "; type = " + _contentType
+ "; charset = " + _characterSet + "]\n" + getContentsAsString();
}
|
|
From: Russell G. <rus...@us...> - 2003-03-18 19:35:37
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/pseudoserver
In directory sc8-pr-cvs1:/tmp/cvs-serv12900/test/com/meterware/pseudoserver
Modified Files:
PseudoServerTest.java
Log Message:
refactoring to support persistent connections
Index: PseudoServerTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/pseudoserver/PseudoServerTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- PseudoServerTest.java 15 Nov 2002 00:07:34 -0000 1.7
+++ PseudoServerTest.java 18 Mar 2003 19:35:34 -0000 1.8
@@ -25,6 +25,11 @@
import java.net.HttpURLConnection;
import java.net.UnknownHostException;
+import java.net.Socket;
+import java.io.OutputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.BufferedInputStream;
public class PseudoServerTest extends HttpUserAgentTest {
@@ -131,6 +136,58 @@
WebResponse response = wc.getResponse( request );
assertEquals( "requested resource", resourceValue, response.getText().trim() );
assertEquals( "content type", "text/html", response.getContentType() );
+ }
+
+
+ /**
+ * This tests simple access to the server without using any client classes.
+ */
+ public void testGetViaSocket() throws Exception {
+ defineResource( "sample", "Get this", "text/plain" );
+ Socket socket = new Socket( "localhost", getHostPort() );
+ OutputStream os = socket.getOutputStream();
+ InputStream is = new BufferedInputStream( socket.getInputStream() );
+
+ sendHTTPLine( os, "GET /sample HTTP/1.0" );
+ sendHTTPLine( os, "Host: meterware.com" );
+ sendHTTPLine( os, "" );
+
+ StringBuffer sb = new StringBuffer();
+ int b;
+ while (-1 != (b = is.read())) sb.append( (char) b );
+ String result = sb.toString();
+ assertTrue( "Did not find matching protocol", result.startsWith( "HTTP/1.0" ) );
+ assertTrue( "Did not find expected text", result.indexOf( "Get this" ) > 0 );
+ }
+
+
+ private void sendHTTPLine( OutputStream os, final String line ) throws IOException {
+ os.write( line.getBytes() );
+ os.write( 13 );
+ os.write( 10 );
+ }
+
+
+ /**
+ * This verifies that the PseudoServer detects and echoes its protocol.
+ */
+ public void testProtocolMatching() throws Exception {
+ defineResource( "sample", "Get this", "text/plain" );
+ Socket socket = new Socket( "localhost", getHostPort() );
+ OutputStream os = socket.getOutputStream();
+ InputStream is = new BufferedInputStream( socket.getInputStream() );
+
+ sendHTTPLine( os, "GET /sample HTTP/1.1" );
+ sendHTTPLine( os, "Host: meterware.com" );
+ sendHTTPLine( os, "Connection: close" );
+ sendHTTPLine( os, "" );
+
+ StringBuffer sb = new StringBuffer();
+ int b;
+ while (-1 != (b = is.read())) sb.append( (char) b );
+ String result = sb.toString();
+ assertTrue( "Did not find matching protocol", result.startsWith( "HTTP/1.1" ) );
+ assertTrue( "Did not find expected text", result.indexOf( "Get this" ) > 0 );
}
|
|
From: Russell G. <rus...@us...> - 2003-03-18 19:35:37
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver
In directory sc8-pr-cvs1:/tmp/cvs-serv12900/src/com/meterware/pseudoserver
Modified Files:
PseudoServer.java PseudoServlet.java WebResource.java
Added Files:
HttpRequest.java
Removed Files:
HttpRequestStream.java
Log Message:
refactoring to support persistent connections
***** Error reading new file[Errno 2] No such file or directory: 'HttpRequest.java'
Index: PseudoServer.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver/PseudoServer.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- PseudoServer.java 22 Nov 2002 17:19:35 -0000 1.5
+++ PseudoServer.java 18 Mar 2003 19:35:33 -0000 1.6
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2002, Russell Gold
+* Copyright (c) 2000-2003, 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
@@ -40,8 +40,8 @@
public void run() {
while (_active) {
try {
- handleConnection();
- Thread.sleep( 50 );
+ handleNewConnection( getServerSocket().accept() );
+ Thread.sleep( 20 );
} catch (InterruptedIOException e) {
_active = false;
} catch (IOException e) {
@@ -192,15 +192,40 @@
}
- private void handleConnection() throws IOException {
- Socket socket = getServerSocket().accept();
+ private void handleNewConnection( final Socket socket ) {
+ Thread t = new Thread() {
+ public void run() {
+ try {
+ serveRequests( socket );
+ } catch (IOException e) {
+ e.printStackTrace(); //To change body of catch statement use Options | File Templates.
+ }
+ }
+ };
+ t.start();
+ }
+
+
+ private void serveRequests( Socket socket ) throws IOException {
socket.setSoTimeout( 1000 );
socket.setTcpNoDelay( true );
- HttpRequestStream request = new HttpRequestStream( socket.getInputStream() );
- HttpResponseStream response = new HttpResponseStream( socket.getOutputStream() );
+ final BufferedInputStream inputStream = new BufferedInputStream( socket.getInputStream() );
+ final HttpResponseStream outputStream = new HttpResponseStream( socket.getOutputStream() );
+
+ HttpRequest request;
+ do {
+ request = new HttpRequest( inputStream );
+ respondToRequest( request, outputStream );
+ } while (!request.requestedCloseConnection() );
+ outputStream.close();
+ socket.close();
+ }
+
+ private void respondToRequest( HttpRequest request, HttpResponseStream response ) {
try {
+ response.setProtocol( request.getProtocol() );
WebResource resource = getResource( request );
if (resource == null) {
response.setResponse( HttpURLConnection.HTTP_NOT_FOUND, "unable to find " + request.getURI() );
@@ -216,20 +241,14 @@
}
} catch (UnknownMethodException e) {
response.setResponse( HttpURLConnection.HTTP_BAD_METHOD, "unsupported method: " + e.getMethod() );
- } catch (IOException e) {
- e.fillInStackTrace();
- throw e;
} catch (Throwable t) {
t.printStackTrace();
response.setResponse( HttpURLConnection.HTTP_INTERNAL_ERROR, t.toString() );
- } finally {
- response.close();
- socket.close();
}
}
- private WebResource getResource( HttpRequestStream request ) throws IOException {
+ private WebResource getResource( HttpRequest request ) throws IOException {
Object resource = _resources.get( request.getURI() );
if (request.getCommand().equals( "GET" ) && resource instanceof WebResource) {
@@ -268,7 +287,7 @@
}
- private WebResource getResource( PseudoServlet servlet, HttpRequestStream request ) throws IOException {
+ private WebResource getResource( PseudoServlet servlet, HttpRequest request ) throws IOException {
servlet.init( request );
return servlet.getResponse( request.getCommand() );
}
@@ -311,6 +330,11 @@
}
+ void setProtocol( String protocol ) {
+ _protocol = protocol;
+ }
+
+
void setResponse( int responseCode, String responseText ) {
_responseCode = responseCode;
_responseText = responseText;
@@ -347,6 +371,7 @@
for (Enumeration e = _headers.elements(); e.hasMoreElements();) {
sendLine( (String) e.nextElement() );
}
+ sendLine( "Connection: close" ); // TODO get rid of this
sendText( CRLF );
_headersWritten = true;
_pw.flush();
@@ -355,7 +380,7 @@
private void sendResponse( int responseCode, String responseText ) {
- sendLine( "HTTP/1.0 " + responseCode + ' ' + responseText );
+ sendLine( _protocol + ' ' + responseCode + ' ' + responseText );
}
@@ -374,6 +399,7 @@
private PrintWriter _pw;
private Vector _headers = new Vector();
+ private String _protocol = "HTTP/1.0";
private int _responseCode = HttpURLConnection.HTTP_OK;
private String _responseText = "OK";
Index: PseudoServlet.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver/PseudoServlet.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PseudoServlet.java 24 Jul 2002 17:28:56 -0000 1.1
+++ PseudoServlet.java 18 Mar 2003 19:35:33 -0000 1.2
@@ -72,7 +72,7 @@
}
- void init( HttpRequestStream requestStream ) {
+ void init( HttpRequest requestStream ) {
_requestStream = requestStream;
}
@@ -107,7 +107,7 @@
}
- private HttpRequestStream _requestStream;
+ private HttpRequest _requestStream;
}
Index: WebResource.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver/WebResource.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- WebResource.java 15 Nov 2002 00:07:33 -0000 1.3
+++ WebResource.java 18 Mar 2003 19:35:33 -0000 1.4
@@ -24,6 +24,7 @@
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.util.Vector;
@@ -57,6 +58,7 @@
public void addHeader( String header ) {
_headers.addElement( header );
if (header.toLowerCase().startsWith( "content-type" )) _hasExplicitContentTypeHeader = true;
+ if (header.toLowerCase().startsWith( "content-length" )) _hasExplicitContentLengthHeader = true;
}
@@ -96,9 +98,10 @@
}
- String[] getHeaders() {
+ String[] getHeaders() throws UnsupportedEncodingException {
final Vector effectiveHeaders = (Vector) _headers.clone();
if (!_hasExplicitContentTypeHeader) effectiveHeaders.add( getContentTypeHeader() );
+ if (_stream == null && !_hasExplicitContentLengthHeader) effectiveHeaders.add( getContentLengthHeader() );
String[] headers = new String[ effectiveHeaders.size() ];
effectiveHeaders.copyInto( headers );
return headers;
@@ -106,10 +109,8 @@
void writeTo( OutputStream outputStream ) throws IOException {
- if (_string != null) {
- outputStream.write( _string.getBytes( getCharacterSet() ) );
- } else if (_contents != null) {
- outputStream.write( _contents );
+ if (_stream == null) {
+ outputStream.write( getContentsAsBytes() );
} else if (_stream != null) {
byte[] buffer = new byte[8 * 1024];
int count = 0;
@@ -121,8 +122,24 @@
}
+ private byte[] getContentsAsBytes() throws UnsupportedEncodingException {
+ if (_contents != null) {
+ return _contents;
+ } else if (_string != null) {
+ return _string.getBytes( getCharacterSet() );
+ } else {
+ throw new IllegalStateException( "Cannot get bytes from stream" );
+ }
+ }
+
+
private String getContentTypeHeader() {
- return "Content-type: " + _contentType + getCharacterSetParameter();
+ return "Content-Type: " + _contentType + getCharacterSetParameter();
+ }
+
+
+ private String getContentLengthHeader() throws UnsupportedEncodingException {
+ return "Content-Length: " + getContentsAsBytes().length;
}
@@ -168,6 +185,7 @@
private String _contentType = DEFAULT_CONTENT_TYPE;
private String _characterSet = DEFAULT_CHARACTER_SET;
private boolean _hasExplicitContentTypeHeader;
+ private boolean _hasExplicitContentLengthHeader;
private Vector _headers = new Vector();
}
|
|
From: Russell G. <rus...@us...> - 2003-03-17 17:37:40
|
Update of /cvsroot/httpunit/httpunit/doc
In directory sc8-pr-cvs1:/tmp/cvs-serv1827/doc
Modified Files:
release_notes.txt
Log Message:
Support Content-Length header
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.275
retrieving revision 1.276
diff -u -r1.275 -r1.276
--- release_notes.txt 17 Mar 2003 01:35:44 -0000 1.275
+++ release_notes.txt 17 Mar 2003 17:37:00 -0000 1.276
@@ -13,6 +13,11 @@
Revision History:
+ 17-Mar-2003
+Problems fixed:
+ 1. The Content-Length header was not being sent with requests in ServletUnit.
+ 2. ServletUnit's HttpServletRequest.getIntHeader() always returned -1.
+
16-Mar-2003
Acknowledgements:
Thanks to Brendan Boesen for adding a method to access session IDs in ServletUnitContext.
|
|
From: Russell G. <rus...@us...> - 2003-03-17 17:37:12
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory sc8-pr-cvs1:/tmp/cvs-serv1827/test/com/meterware/servletunit Modified Files: StatelessTest.java Log Message: Support Content-Length header Index: StatelessTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/StatelessTest.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- StatelessTest.java 3 Jan 2003 16:12:35 -0000 1.10 +++ StatelessTest.java 17 Mar 2003 17:37:05 -0000 1.11 @@ -19,16 +19,9 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ -import com.meterware.httpunit.GetMethodWebRequest; -import com.meterware.httpunit.HttpNotFoundException; -import com.meterware.httpunit.PostMethodWebRequest; -import com.meterware.httpunit.WebRequest; -import com.meterware.httpunit.WebResponse; -import com.meterware.httpunit.WebForm; - -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintWriter; +import com.meterware.httpunit.*; + +import java.io.*; import java.net.HttpURLConnection; import javax.servlet.ServletException; @@ -194,6 +187,21 @@ } + public void testStreamBasedPost() throws Exception { + ServletRunner sr = new ServletRunner(); + sr.registerServlet( "ReportData", BodyEcho.class.getName() ); + + String sourceData = "This is an interesting test\nWith two lines"; + InputStream source = new ByteArrayInputStream( sourceData.getBytes( "iso-8859-1" ) ); + + WebClient wc = sr.newClient(); + WebRequest wr = new PostMethodWebRequest( "http://localhost/ReportData", source, "text/sample" ); + WebResponse response = wc.getResponse( wr ); + assertEquals( "Body response", sourceData.length() + "\n" + sourceData, response.getText() ); + assertEquals( "Content-type", "text/sample", response.getContentType() ); + } + + public void testRequestInputStream() throws Exception { ServletRunner sr = new ServletRunner(); WebRequest request = new PostMethodWebRequest( "http://localhost/servlet/" + ParameterServlet.class.getName() ); @@ -280,6 +288,30 @@ } + + static class BodyEcho extends HttpServlet { + /** + * Returns a resource object as a result of a get request. + **/ + protected void doPost( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException { + int length = req.getIntHeader( "Content-length" ); + String contentType = req.getHeader( "Content-type" ); + resp.setContentType( contentType ); + + InputStreamReader isr = new InputStreamReader( req.getInputStream() ); + BufferedReader br = new BufferedReader( isr ); + resp.getWriter().print( length ); + + String line = br.readLine(); + while (line != null) { + resp.getWriter().print( "\n" ); + resp.getWriter().print( line ); + line = br.readLine(); + } + resp.getWriter().flush(); + resp.getWriter().close(); + } + } static class FormSubmissionServlet extends HttpServlet { |
|
From: Russell G. <rus...@us...> - 2003-03-17 17:37:12
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit
In directory sc8-pr-cvs1:/tmp/cvs-serv1827/src/com/meterware/servletunit
Modified Files:
ServletUnitHttpRequest.java
Log Message:
Support Content-Length header
Index: ServletUnitHttpRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpRequest.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- ServletUnitHttpRequest.java 17 Mar 2003 01:35:44 -0000 1.25
+++ ServletUnitHttpRequest.java 17 Mar 2003 17:37:04 -0000 1.26
@@ -65,6 +65,7 @@
_messageBody = messageBody;
_secure = request.getURL().getProtocol().equalsIgnoreCase( "https" );
_contentType = (String) _headers.get( "Content-Type" );
+ if (_headers.get( "Content-Length") == null) _headers.put( "Content-Length", Integer.toString( messageBody.length ) );
_requestContext = new RequestContext( request.getURL() );
if (_messageBody != null && (_contentType == null || _contentType.indexOf( "x-www-form-urlencoded" ) >= 0 )) {
@@ -114,7 +115,7 @@
* this method throws a NumberFormatException.
**/
public int getIntHeader( String name ) {
- return -1;
+ return Integer.parseInt( getHeader( name ) );
}
|
|
From: Russell G. <rus...@us...> - 2003-03-17 01:35:50
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit
In directory sc8-pr-cvs1:/tmp/cvs-serv23842/src/com/meterware/servletunit
Modified Files:
ServletUnitContext.java ServletUnitHttpRequest.java
Log Message:
Added support for HttpServletRequest.getRequestDispatcher()
Index: ServletUnitContext.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitContext.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ServletUnitContext.java 16 Mar 2003 14:14:39 -0000 1.4
+++ ServletUnitContext.java 17 Mar 2003 01:35:44 -0000 1.5
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000, Russell Gold
+* Copyright (c) 2000-2003, 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
@@ -30,9 +30,10 @@
this( null );
}
- ServletUnitContext(String contextPath) {
+ ServletUnitContext( String contextPath ) {
_contextPath = (contextPath != null ? contextPath : "");
}
+
Set getSessionIDs() {
return _sessions.keySet();
Index: ServletUnitHttpRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpRequest.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- ServletUnitHttpRequest.java 13 Feb 2003 20:25:56 -0000 1.24
+++ ServletUnitHttpRequest.java 17 Mar 2003 01:35:44 -0000 1.25
@@ -35,6 +35,7 @@
import javax.servlet.http.HttpSession;
import javax.servlet.ServletInputStream;
import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
/**
@@ -560,7 +561,18 @@
* is that this method can take a relative path.
**/
public RequestDispatcher getRequestDispatcher( String path ) {
- throw new RuntimeException( "getRequestDispatcher not implemented" );
+ try {
+ if (!path.startsWith( "/" )) path = combinedPath( getServletPath(), path );
+ return _servletRequest.getServlet().getServletConfig().getServletContext().getRequestDispatcher( path );
+ } catch (ServletException e) {
+ return null;
+ }
+ }
+
+
+ private String combinedPath( String basePath, String relativePath ) {
+ if (basePath.indexOf( '/' ) < 0) return relativePath;
+ return basePath.substring( 0, basePath.lastIndexOf( '/' ) ) + '/' + relativePath;
}
@@ -725,7 +737,7 @@
final static private String LOOPBACK_ADDRESS = "127.0.0.1";
private WebRequest _request;
- private ServletMetaData _servletRequest;
+ private ServletMetaData _servletRequest;
private WebClient.HeaderDictionary _headers;
private ServletUnitContext _context;
private ServletUnitHttpSession _session;
|
|
From: Russell G. <rus...@us...> - 2003-03-17 01:35:50
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit
In directory sc8-pr-cvs1:/tmp/cvs-serv23842/test/com/meterware/servletunit
Modified Files:
NavigationTest.java
Log Message:
Added support for HttpServletRequest.getRequestDispatcher()
Index: NavigationTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/NavigationTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- NavigationTest.java 13 Feb 2003 20:25:56 -0000 1.5
+++ NavigationTest.java 17 Mar 2003 01:35:45 -0000 1.6
@@ -92,6 +92,36 @@
}
+ public void testForwardViaHttpServletRequest() throws Exception {
+ WebXMLString wxs = new WebXMLString();
+ wxs.addServlet( "/target", TargetServlet.class );
+ wxs.addServlet( "/origin", FowarderServlet2.class );
+
+ ServletRunner sr = new ServletRunner( wxs.asInputStream(), "/context" );
+
+ WebClient wc = sr.newClient();
+ WebResponse response = wc.getResponse( "http://localhost/context/origin?color=green" );
+ assertNotNull( "No response received", response );
+ assertEquals( "Expected response", "color=green: path=/context/target", response.getText() );
+ assertEquals( "Returned cookie count", 0, response.getNewCookieNames().length );
+ }
+
+
+ public void testForwardViaRelativePath() throws Exception {
+ WebXMLString wxs = new WebXMLString();
+ wxs.addServlet( "/some/target", TargetServlet.class );
+ wxs.addServlet( "/some/origin", FowarderServlet3.class );
+
+ ServletRunner sr = new ServletRunner( wxs.asInputStream(), "/context" );
+
+ WebClient wc = sr.newClient();
+ WebResponse response = wc.getResponse( "http://localhost/context/some/origin?color=green" );
+ assertNotNull( "No response received", response );
+ assertEquals( "Expected response", "color=green: path=/context/some/target", response.getText() );
+ assertEquals( "Returned cookie count", 0, response.getNewCookieNames().length );
+ }
+
+
static class OriginServlet extends HttpServlet {
protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException,IOException {
@@ -111,6 +141,24 @@
}
+ static class FowarderServlet2 extends HttpServlet {
+
+ protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException,IOException {
+ req.getRequestDispatcher( "/target" ).forward( req, resp );
+ }
+
+ }
+
+
+ static class FowarderServlet3 extends HttpServlet {
+
+ protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException,IOException {
+ req.getRequestDispatcher( "target" ).forward( req, resp );
+ }
+
+ }
+
+
static class IncluderServlet extends HttpServlet {
static final String PREFIX = "expecting: ";
@@ -118,7 +166,6 @@
resp.getWriter().print( PREFIX );
getServletContext().getRequestDispatcher( "/target?color=blue" ).include( req, resp );
}
-
}
|
|
From: Russell G. <rus...@us...> - 2003-03-17 01:35:47
|
Update of /cvsroot/httpunit/httpunit/doc
In directory sc8-pr-cvs1:/tmp/cvs-serv23842/doc
Modified Files:
release_notes.txt
Log Message:
Added support for HttpServletRequest.getRequestDispatcher()
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.274
retrieving revision 1.275
diff -u -r1.274 -r1.275
--- release_notes.txt 16 Mar 2003 17:22:36 -0000 1.274
+++ release_notes.txt 17 Mar 2003 01:35:44 -0000 1.275
@@ -19,6 +19,7 @@
Additions:
1. You can now get at the stored session IDs in ServletUnitContext.
+ 2. ServletUnit now supports HttpServletRequest.getRequestDispatch()
Notes:
1. The acceptCookies, acceptGzip, autoRefresh and autoForward properties have been moved from HttpUnitOptions to ClientProperties,
|
|
From: Russell G. <rus...@us...> - 2003-03-16 18:55:38
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript
In directory sc8-pr-cvs1:/tmp/cvs-serv27465/test/com/meterware/httpunit/javascript
Modified Files:
DocumentScriptingTest.java
Log Message:
Remove forgotten temporary line
Index: DocumentScriptingTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/DocumentScriptingTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DocumentScriptingTest.java 12 Mar 2003 17:34:07 -0000 1.7
+++ DocumentScriptingTest.java 16 Mar 2003 18:55:34 -0000 1.8
@@ -22,7 +22,6 @@
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import com.meterware.httpunit.*;
-import com.meterware.httpunit.parsing.HTMLParserFactory;
public class DocumentScriptingTest extends HttpUnitTest {
@@ -51,7 +50,6 @@
public void testDocumentFindForms() throws Exception {
- HTMLParserFactory.useJTidyParser(); // TODO remove this line
defineResource( "OnCommand.html", "<html><head><script language='JavaScript'>" +
"function getFound( object ) {" +
" return (object == null) ? \"did not find \" : \"found \";" +
|
|
From: Russell G. <rus...@us...> - 2003-03-16 17:22:43
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv18420/test/com/meterware/httpunit
Modified Files:
WebClientTest.java WebPageTest.java
Log Message:
Moved properties from HttpUnitOptions to ClientProperties
Index: WebClientTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebClientTest.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- WebClientTest.java 24 Oct 2002 13:28:55 -0000 1.10
+++ WebClientTest.java 16 Mar 2003 17:22:38 -0000 1.11
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
- * Copyright (c) 2002, Russell Gold
+ * Copyright (c) 2002-2003, 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
@@ -36,7 +36,7 @@
/**
*
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
public class WebClientTest extends HttpUnitTest {
@@ -90,8 +90,8 @@
defineResource( resourceName, resourceValue );
addResourceHeader( resourceName, "Set-Cookie: age=12" );
- HttpUnitOptions.setAcceptCookies( false );
WebConversation wc = new WebConversation();
+ wc.getClientProperties().setAcceptCookies( false );
WebRequest request = new GetMethodWebRequest( getHostPath() + '/' + resourceName );
WebResponse response = wc.getResponse( request );
assertEquals( "requested resource", resourceValue, response.getText().trim() );
@@ -170,9 +170,9 @@
public void testGZIPDisabled() throws Exception {
String expectedResponse = "Here is my answer";
defineResource( "Compressed.html", new CompressedPseudoServlet( expectedResponse ) );
- HttpUnitOptions.setAcceptGzip( false );
WebConversation wc = new WebConversation();
+ wc.getClientProperties().setAcceptGzip( false );
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() );
@@ -248,7 +248,7 @@
ArrayList messageLog = new ArrayList();
wc.addClientListener( new ListenerExample( messageLog ) );
- WebResponse response = wc.getResponse( getHostPath() + "/Frames.html" );
+ wc.getResponse( getHostPath() + "/Frames.html" );
assertEquals( "Num logged items", 6, messageLog.size() );
for (int i = 0; i < 3; i++) {
verifyRequestResponsePair( messageLog, 2 * i );
@@ -333,8 +333,8 @@
defineResource( redirectName, redirectValue, HttpURLConnection.HTTP_MOVED_PERM );
addResourceHeader( redirectName, "Location: " + getHostPath() + '/' + resourceName );
- HttpUnitOptions.setAutoRedirect( false );
WebConversation wc = new WebConversation();
+ wc.getClientProperties().setAutoRedirect( false );
WebResponse response = wc.getResponse( getHostPath() + '/' + redirectName );
assertEquals( "requested resource", redirectValue, response.getText().trim() );
assertEquals( "content type", "text/html", response.getContentType() );
Index: WebPageTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebPageTest.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- WebPageTest.java 5 Feb 2003 05:15:51 -0000 1.28
+++ WebPageTest.java 16 Mar 2003 17:22:38 -0000 1.29
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2001, Russell Gold
+* Copyright (c) 2000-2003, 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
@@ -40,7 +40,7 @@
**/
public class WebPageTest extends HttpUnitTest {
- public static void main(String args[]) {
+ public static void main( String args[] ) {
junit.textui.TestRunner.run( suite() );
}
@@ -58,7 +58,6 @@
public void tearDown() throws Exception {
super.tearDown();
HttpUnitOptions.resetDefaultCharacterSet();
- HttpUnitOptions.setAutoRefresh( false );
}
@@ -335,8 +334,8 @@
defineResource( "SimplePage.html", page );
defineWebPage( "NextPage", "Not much here" );
- HttpUnitOptions.setAutoRefresh( true );
WebConversation wc = new WebConversation();
+ wc.getClientProperties().setAutoRefresh( true );
WebRequest request = new GetMethodWebRequest( getHostPath() + "/SimplePage.html" );
WebResponse simplePage = wc.getResponse( request );
|
|
From: Russell G. <rus...@us...> - 2003-03-16 17:22:43
|
Update of /cvsroot/httpunit/httpunit/doc
In directory sc8-pr-cvs1:/tmp/cvs-serv18420/doc
Modified Files:
release_notes.txt
Log Message:
Moved properties from HttpUnitOptions to ClientProperties
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.273
retrieving revision 1.274
diff -u -r1.273 -r1.274
--- release_notes.txt 16 Mar 2003 14:14:39 -0000 1.273
+++ release_notes.txt 16 Mar 2003 17:22:36 -0000 1.274
@@ -20,6 +20,12 @@
Additions:
1. You can now get at the stored session IDs in ServletUnitContext.
+Notes:
+ 1. The acceptCookies, acceptGzip, autoRefresh and autoForward properties have been moved from HttpUnitOptions to ClientProperties,
+ permitting them to be set per WebClient rather than just globally. The old properties have been deprecated,
+ and now access the defaults for ClientProperties. Tests which set the HttpUnitOptions properties before creating
+ their WebClients will be unaffected.
+
14-Mar-2003
Problems fixed:
1. When loading a page triggered a script function which redirected to a new page in the same frame,
|
|
From: Russell G. <rus...@us...> - 2003-03-16 17:22:43
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv18420/src/com/meterware/httpunit
Modified Files:
ClientProperties.java HttpUnitOptions.java WebClient.java
WebWindow.java
Log Message:
Moved properties from HttpUnitOptions to ClientProperties
Index: ClientProperties.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ClientProperties.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ClientProperties.java 4 Feb 2003 05:32:03 -0000 1.4
+++ ClientProperties.java 16 Mar 2003 17:22:38 -0000 1.5
@@ -129,6 +129,77 @@
}
+ /**
+ * Returns true if the client should accept and transmit cookies. The default is to accept them.
+ */
+ public boolean isAcceptCookies() {
+ return _acceptCookies;
+ }
+
+
+ /**
+ * Specifies whether the client should accept and send cookies.
+ */
+ public void setAcceptCookies( boolean acceptCookies ) {
+ _acceptCookies = acceptCookies;
+ }
+
+
+ /**
+ * Returns true if the client will accept GZIP encoding of responses. The default is to accept GZIP encoding.
+ **/
+ public boolean isAcceptGzip() {
+ return _acceptGzip;
+ }
+
+
+ /**
+ * Specifies whether the client will accept GZIP encoded responses. The default is true.
+ */
+ public void setAcceptGzip( boolean acceptGzip ) {
+ _acceptGzip = acceptGzip;
+ }
+
+
+ /**
+ * Returns true if the client should automatically follow page redirect requests (status 3xx).
+ * By default, this is true.
+ **/
+ public boolean isAutoRedirect() {
+ return _autoRedirect;
+ }
+
+
+ /**
+ * Determines whether the client should automatically follow page redirect requests (status 3xx).
+ * By default, this is true in order to simulate normal browser operation.
+ **/
+ public void setAutoRedirect( boolean autoRedirect ) {
+ _autoRedirect = autoRedirect;
+ }
+
+
+ /**
+ * Returns true if the client should automatically follow page refresh requests.
+ * By default, this is false, so that programs can verify the redirect page presented
+ * to users before the browser switches to the new page.
+ **/
+ public boolean isAutoRefresh() {
+ return _autoRefresh;
+ }
+
+
+ /**
+ * Specifies whether the client should automatically follow page refresh requests.
+ * By default, this is false, so that programs can verify the redirect page presented
+ * to users before the browser switches to the new page. Setting this to true can
+ * cause an infinite loop on pages that refresh themselves.
+ **/
+ public void setAutoRefresh( boolean autoRefresh ) {
+ _autoRefresh = autoRefresh;
+ }
+
+
public boolean isIframeSupported() {
return _iframeSupported;
}
@@ -146,13 +217,17 @@
private String _applicationCodeName = "httpunit";
private String _applicationName = "HttpUnit";
- private String _applicationVersion = "1.4";
+ private String _applicationVersion = "1.5";
private String _userAgent;
private String _platform = "Java";
private int _availWidth = 800;
private int _availHeight = 600;
private boolean _iframeSupported = true;
+ private boolean _acceptCookies = true;
+ private boolean _acceptGzip = true;
+ private boolean _autoRedirect = true;
+ private boolean _autoRefresh = false;
private static ClientProperties _defaultProperties = new ClientProperties();
@@ -168,5 +243,9 @@
_userAgent = source._userAgent;
_platform = source._platform;
_iframeSupported = source._iframeSupported;
+ _acceptCookies = source._acceptCookies;
+ _acceptGzip = source._acceptGzip;
+ _autoRedirect = source._autoRedirect;
+ _autoRefresh = source._autoRefresh;
}
}
Index: HttpUnitOptions.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- HttpUnitOptions.java 28 Feb 2003 17:30:26 -0000 1.37
+++ HttpUnitOptions.java 16 Mar 2003 17:22:38 -0000 1.38
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2002, Russell Gold
+* Copyright (c) 2000-2003, 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
@@ -47,15 +47,11 @@
_imagesTreatedAsAltText = false;
_loggingHttpHeaders = false;
_matchesIgnoreCase = true;
- _autoRefresh = false;
- _autoRedirect = true;
_checkContentLength = false;
_redirectDelay = 0;
_characterSet = HttpUnitUtils.DEFAULT_CHARACTER_SET;
_contentType = DEFAULT_CONTENT_TYPE;
_postIncludesCharset = false;
- _acceptGzip = true;
- _acceptCookies = true;
setScriptEngineClassName( DEFAULT_SCRIPT_ENGINE_FACTORY );
setScriptingEnabled( true );
setExceptionsThrownOnScriptError( true );
@@ -64,33 +60,37 @@
/**
* Returns true if HttpUnit is accepting and saving cookies. The default is to accept them.
+ * @deprecated as of 1.5.3, use ClientProperties#isAcceptCookies();
*/
public static boolean isAcceptCookies() {
- return _acceptCookies;
+ return ClientProperties.getDefaultProperties().isAcceptCookies();
}
/**
* Specifies whether HttpUnit should accept and send cookies.
+ * @deprecated as of 1.5.3, use ClientProperties#setAcceptCookies();
*/
public static void setAcceptCookies( boolean acceptCookies ) {
- _acceptCookies = acceptCookies;
+ ClientProperties.getDefaultProperties().setAcceptCookies( acceptCookies );
}
/**
* Returns true if any WebClient created will accept GZIP encoding of responses. The default is to accept GZIP encoding.
+ * @deprecated as of 1.5.3, use ClientProperties#isAcceptGzip();
**/
public static boolean isAcceptGzip() {
- return _acceptGzip;
+ return ClientProperties.getDefaultProperties().isAcceptGzip();
}
/**
* Specifies whether a WebClient will be initialized to accept GZIP encoded responses. The default is true.
+ * @deprecated as of 1.5.3, use ClientProperties#setAcceptGzip();
*/
public static void setAcceptGzip( boolean acceptGzip ) {
- _acceptGzip = acceptGzip;
+ ClientProperties.getDefaultProperties().setAcceptGzip( acceptGzip );
}
@@ -290,18 +290,20 @@
/**
* Returns true if HttpUnit should automatically follow page redirect requests (status 3xx).
* By default, this is true.
+ * @deprecated as of 1.5.3, use ClientProperties#isAutoRedirect();
**/
public static boolean getAutoRedirect() {
- return _autoRedirect;
+ return ClientProperties.getDefaultProperties().isAutoRedirect();
}
/**
* Determines whether HttpUnit should automatically follow page redirect requests (status 3xx).
* By default, this is true in order to simulate normal browser operation.
+ * @deprecated as of 1.5.3, use ClientProperties#setAutoRedirect();
**/
public static void setAutoRedirect( boolean autoRedirect ) {
- _autoRedirect = autoRedirect;
+ ClientProperties.getDefaultProperties().setAutoRedirect( autoRedirect );
}
@@ -328,9 +330,10 @@
* Returns true if HttpUnit should automatically follow page refresh requests.
* By default, this is false, so that programs can verify the redirect page presented
* to users before the browser switches to the new page.
+ * @deprecated as of 1.5.3, use ClientProperties#isAutoRefresh();
**/
public static boolean getAutoRefresh() {
- return _autoRefresh;
+ return ClientProperties.getDefaultProperties().isAutoRefresh();
}
@@ -339,9 +342,10 @@
* By default, this is false, so that programs can verify the redirect page presented
* to users before the browser switches to the new page. Setting this to true can
* cause an infinite loop on pages that refresh themselves.
+ * @deprecated as of 1.5.3, use ClientProperties#setAutoRefresh();
**/
public static void setAutoRefresh( boolean autoRefresh ) {
- _autoRefresh = autoRefresh;
+ ClientProperties.getDefaultProperties().setAutoRefresh( autoRefresh );
}
@@ -473,10 +477,6 @@
};
- private static boolean _acceptGzip = true;
-
- private static boolean _acceptCookies = true;
-
private static boolean _exceptionsOnErrorStatus = true;
private static boolean _parameterValuesValidated = true;
@@ -486,10 +486,6 @@
private static boolean _loggingHttpHeaders;
private static boolean _matchesIgnoreCase = true;
-
- private static boolean _autoRefresh;
-
- private static boolean _autoRedirect = true;
private static boolean _postIncludesCharset = false;
Index: WebClient.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- WebClient.java 27 Feb 2003 23:35:58 -0000 1.49
+++ WebClient.java 16 Mar 2003 17:22:38 -0000 1.50
@@ -345,9 +345,6 @@
protected WebClient() {
- if (HttpUnitOptions.isAcceptGzip()) {
- setHeaderField( "Accept-Encoding", "gzip" );
- }
_openWindows.add( _mainWindow );
}
@@ -373,6 +370,7 @@
protected Dictionary getHeaderFields( URL targetURL ) {
Hashtable result = (Hashtable) _headers.clone();
result.put( "User-Agent", getClientProperties().getUserAgent() );
+ if (getClientProperties().isAcceptGzip()) result.put( "Accept-Encoding", "gzip" );
AddHeaderIfNotNull( result, "Cookie", _cookieJar.getCookieHeaderField( targetURL ) );
AddHeaderIfNotNull( result, getAuthorizationHeaderName(), _authorizationString );
return result;
@@ -435,7 +433,7 @@
void updateClient( WebResponse response ) throws IOException {
- if (HttpUnitOptions.isAcceptCookies()) _cookieJar.updateCookies( response.getCookieJar() );
+ if (getClientProperties().isAcceptCookies()) _cookieJar.updateCookies( response.getCookieJar() );
validateHeaders( response );
}
Index: WebWindow.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebWindow.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- WebWindow.java 14 Mar 2003 17:41:30 -0000 1.10
+++ WebWindow.java 16 Mar 2003 17:22:38 -0000 1.11
@@ -126,7 +126,7 @@
**/
WebResponse updateWindow( String requestTarget, WebResponse response, RequestContext requestContext ) throws MalformedURLException, IOException, SAXException {
_client.updateClient( response );
- if (HttpUnitOptions.getAutoRefresh() && response.getRefreshRequest() != null) {
+ if (getClient().getClientProperties().isAutoRefresh() && response.getRefreshRequest() != null) {
return getResponse( response.getRefreshRequest() );
} else if (shouldFollowRedirect( response )) {
delay( HttpUnitOptions.getRedirectDelay() );
@@ -234,7 +234,7 @@
private boolean shouldFollowRedirect( WebResponse response ) {
- return HttpUnitOptions.getAutoRedirect()
+ return getClient().getClientProperties().isAutoRedirect()
&& response.getResponseCode() >= HttpURLConnection.HTTP_MOVED_PERM
&& response.getResponseCode() <= HttpURLConnection.HTTP_MOVED_TEMP
&& response.getHeaderField( "Location" ) != null;
|
|
From: Russell G. <rus...@us...> - 2003-03-16 14:14:42
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit
In directory sc8-pr-cvs1:/tmp/cvs-serv14591/test/com/meterware/servletunit
Modified Files:
HttpServletRequestTest.java
Log Message:
Brenden Boesen: added tests for session behavior
Index: HttpServletRequestTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/HttpServletRequestTest.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- HttpServletRequestTest.java 13 Feb 2003 20:25:56 -0000 1.14
+++ HttpServletRequestTest.java 16 Mar 2003 14:14:39 -0000 1.15
@@ -23,6 +23,7 @@
import java.util.Hashtable;
import java.util.Map;
import java.util.Locale;
+import java.net.MalformedURLException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
@@ -206,19 +207,6 @@
}
- public void testSessionCreation() throws Exception {
- WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
- HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
-
- HttpSession session = request.getSession( /* create */ false );
- assertNull( "Unexpected session found", session );
-
- session = request.getSession();
- assertNotNull( "No session created", session );
- assertTrue( "Session not marked as new", session.isNew() );
- }
-
-
public void testDefaultCookies() throws Exception {
WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
@@ -239,16 +227,42 @@
assertEquals( "Cookie value", "vanilla", cookies[0].getValue() );
}
+ public void testGetSessionForFirstTime() throws MalformedURLException {
+
+ WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
+ ServletUnitContext context = new ServletUnitContext();
+ assertEquals( "Initial number of sessions in context", 0, context.getSessionIDs().size() );
+
+ ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, context, new Hashtable(), NO_MESSAGE_BODY );
+ assertNull( "New request should not have a request session ID", request.getRequestedSessionId() );
+ assertNull( "New request should not have a session", request.getSession( /* create */ false ) );
+ assertEquals( "Number of sessions in the context after request.getSession(false)", 0, context.getSessionIDs().size() );
+
+ HttpSession session = request.getSession();
+ assertNotNull( "No session created", session );
+ assertTrue( "Session not marked as new", session.isNew() );
+ assertEquals( "Number of sessions in context after request.getSession()", 1, context.getSessionIDs().size() );
+ assertSame( "Session with ID", session, context.getSession( session.getId() ) );
+ assertNull( "New request should still not have a request session ID", request.getRequestedSessionId() );
+ }
+
+ /**
+ * Verifies that even when session creation is not explicitly requested, the inclusion of a session cookie
+ * will cause a session to be made available.
+ */
public void testRetrieveSession() throws Exception {
WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
ServletUnitContext context = new ServletUnitContext();
ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, context, new Hashtable(), NO_MESSAGE_BODY );
- request.addCookie( new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, context.newSession().getId() ) );
+ final ServletUnitHttpSession session = context.newSession();
+ final String sessionID = session.getId();
+ request.addCookie( new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, sessionID ) );
+ assertEquals( "Requested session ID defined in request", sessionID, request.getRequestedSessionId() );
- HttpSession session = request.getSession( /* create */ false );
- assertNotNull( "No session created", session );
+ assertSame( "Session returned when creation not requested", session, request.getSession( /* create */ false ) );
+ assertSame( "Session returned when creation requested", session, request.getSession( true ) );
}
@@ -282,6 +296,29 @@
}
+ /**
+ * Verifies that a request with a bad session ID causes a new session to be generated only when explicitly requested.
+ */
+ public void testGetSessionWithBadCookie() throws Exception {
+ WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
+ ServletUnitContext context = new ServletUnitContext();
+ ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, context, new Hashtable(), NO_MESSAGE_BODY );
+
+ HttpSession originalSession = context.newSession();
+ String originalID = originalSession.getId();
+ request.addCookie( new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, originalID ) );
+ request.getSession();
+
+ String badID = originalID + "BAD";
+ request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, context, new Hashtable(), NO_MESSAGE_BODY );
+ request.addCookie( new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, badID ) );
+
+ assertNull( "Unexpected session returned for bad cookie", request.getSession( false ) );
+ assertNotNull( "Should have returned session when asked", request.getSession( true ));
+ assertNotSame( "Created session", originalSession, request.getSession( true ) );
+ }
+
+
public void testGetRequestURI() throws Exception {
ServletUnitContext context = new ServletUnitContext();
WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
@@ -303,6 +340,7 @@
verifyLocales( request, expectedLocales );
}
+
public void testSecureProperty() throws Exception {
WebRequest wr = new GetMethodWebRequest( "http://localhost/simple");
|
|
From: Russell G. <rus...@us...> - 2003-03-16 14:14:42
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit
In directory sc8-pr-cvs1:/tmp/cvs-serv14591/src/com/meterware/servletunit
Modified Files:
ServletUnitContext.java
Log Message:
Brenden Boesen: added tests for session behavior
Index: ServletUnitContext.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitContext.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ServletUnitContext.java 23 Jun 2002 23:52:39 -0000 1.3
+++ ServletUnitContext.java 16 Mar 2003 14:14:39 -0000 1.4
@@ -21,6 +21,7 @@
*******************************************************************************************************************/
+import java.util.*;
import java.util.Hashtable;
class ServletUnitContext {
@@ -33,6 +34,10 @@
_contextPath = (contextPath != null ? contextPath : "");
}
+ Set getSessionIDs() {
+ return _sessions.keySet();
+ }
+
/**
* Returns the session with the specified ID, if any.
**/
|
|
From: Russell G. <rus...@us...> - 2003-03-16 14:14:42
|
Update of /cvsroot/httpunit/httpunit/doc
In directory sc8-pr-cvs1:/tmp/cvs-serv14591/doc
Modified Files:
release_notes.txt
Log Message:
Brenden Boesen: added tests for session behavior
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.272
retrieving revision 1.273
diff -u -r1.272 -r1.273
--- release_notes.txt 14 Mar 2003 17:41:26 -0000 1.272
+++ release_notes.txt 16 Mar 2003 14:14:39 -0000 1.273
@@ -13,6 +13,13 @@
Revision History:
+ 16-Mar-2003
+Acknowledgements:
+ Thanks to Brendan Boesen for adding a method to access session IDs in ServletUnitContext.
+
+Additions:
+ 1. You can now get at the stored session IDs in ServletUnitContext.
+
14-Mar-2003
Problems fixed:
1. When loading a page triggered a script function which redirected to a new page in the same frame,
|
|
From: Russell G. <rus...@us...> - 2003-03-16 14:10:29
|
Update of /cvsroot/httpunit/httpunit/doc In directory sc8-pr-cvs1:/tmp/cvs-serv12607/doc Modified Files: faq.html Log Message: Added FAQ entry regarding scripting and getText() Index: faq.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/faq.html,v retrieving revision 1.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- faq.html 9 Mar 2003 20:35:45 -0000 1.25 +++ faq.html 16 Mar 2003 14:10:24 -0000 1.26 @@ -26,8 +26,9 @@ <LI><A HREF="#javascript">How do I use HttpUnit to test my pages that use JavaScript?</A></LI> <LI><A HREF="#norhino">JavaScript is not being executed at all. Why not?</A></LI> <li><a href="#unsupported">How do I handle a page that uses JavaScript features that HttpUnit does not support?</a></li> +<li><a href="#text">I called document.write() in my page, but getText() does not show the results! Why not?</a></li> -</ol><ol start=13> +</ol><ol start=14> <LI><A HREF="#session">How can I see the servlet session between calls?</A></LI> <li><a href="#JSP">Can I use JSPs with ServletUnit?</a></li> </OL> @@ -130,6 +131,9 @@ recorded but will not throw exceptions. You can see the list of problems detected by calling<blockquote><code>HttpUnitOptions.getScriptErrorMessages();</code></blockquote> +<a name="#text">I called document.write() in my page, but getText() does not show the results! Why not?</a> +At present, the execution of scripts only affects the parsed result. WebResponse.getText() shows the <i>original</i> +text in the page. You will see the changed text only if you examine text inside a parsed item such as a form, link, or table. <h2>ServletUnit usage</h2> |
|
From: Russell G. <rus...@us...> - 2003-03-14 17:42:00
|
Update of /cvsroot/httpunit/httpunit/doc
In directory sc8-pr-cvs1:/tmp/cvs-serv754/doc
Modified Files:
release_notes.txt
Log Message:
Return resultant page from WebClient.getResponse
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.271
retrieving revision 1.272
diff -u -r1.271 -r1.272
--- release_notes.txt 13 Mar 2003 20:16:16 -0000 1.271
+++ release_notes.txt 14 Mar 2003 17:41:26 -0000 1.272
@@ -13,6 +13,11 @@
Revision History:
+ 14-Mar-2003
+Problems fixed:
+ 1. When loading a page triggered a script function which redirected to a new page in the same frame,
+ the WebResponse returned from getResponse was the triggering page. It is now the redirected page.
+
13-Mar-2003
Additions:
1. Select.value is now supported.
|
|
From: Russell G. <rus...@us...> - 2003-03-14 17:41:45
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript
In directory sc8-pr-cvs1:/tmp/cvs-serv754/test/com/meterware/httpunit/javascript
Modified Files:
FormScriptingTest.java ScriptingTest.java
Log Message:
Return resultant page from WebClient.getResponse
Index: FormScriptingTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- FormScriptingTest.java 13 Mar 2003 18:20:50 -0000 1.19
+++ FormScriptingTest.java 14 Mar 2003 17:41:30 -0000 1.20
@@ -728,6 +728,21 @@
}
+ public void testSubmitOnLoad() throws Exception {
+ defineResource( "test2.txt?Submit=Submit", "You made it!", "text/plain" );
+ defineResource( "OnCommand.html", "<html><body onload='document.myform.btn.click();'>" +
+ "<form name='myform' action='test2.txt'>" +
+ " <input type='submit' id='btn' name='Submit' value='Submit'/>" +
+ "</form></body></html>" );
+ WebConversation wc = new WebConversation();
+ WebResponse wr = wc.getResponse( getHostPath() + "/OnCommand.html" );
+ assertEquals( "current page URL", getHostPath() + "/test2.txt?Submit=Submit", wc.getCurrentPage().getURL().toExternalForm() );
+ assertEquals( "current page", "You made it!", wc.getCurrentPage().getText() );
+ assertEquals( "returned page URL", getHostPath() + "/test2.txt?Submit=Submit", wr.getURL().toExternalForm() );
+ assertEquals( "returned page", "You made it!", wr.getText() );
+ }
+
+
public void testSelectValueProperty() throws Exception {
defineResource( "OnCommand.html", "<html><head><script language='JavaScript'>" +
"function testProperty( form ) {\n" +
Index: ScriptingTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/ScriptingTest.java,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- ScriptingTest.java 12 Mar 2003 15:39:46 -0000 1.50
+++ ScriptingTest.java 14 Mar 2003 17:41:30 -0000 1.51
@@ -68,9 +68,10 @@
"</body></html>" );
WebConversation wc = new WebConversation();
WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" );
- response.getLinks()[0].click();
+ WebResponse myPage = response.getLinks()[0].click();
assertEquals( "Alert message", "Hi there!", wc.popNextAlert() );
assertEquals( "Current page URL", getHostPath() + "/OnCommand.html", wc.getCurrentPage().getURL().toExternalForm() );
+ assertEquals( "Returned page URL", getHostPath() + "/OnCommand.html", myPage.getURL().toExternalForm() );
}
@@ -422,6 +423,21 @@
response.getScriptableObject().doEvent( "window.location.href='" + getHostPath() + "/Target.html'" );
assertEquals( "5th page URL", getHostPath() + "/Target.html", wc.getCurrentPage().getURL().toExternalForm() );
assertEquals( "5th page", "You made it!", wc.getCurrentPage().getText() );
+ }
+
+
+ public void testLocationPropertyOnLoad() throws Exception {
+ defineResource( "Target.html", "You made it!" );
+ defineResource( "OnCommand.html", "<html><head><title>Amazing!</title>" +
+ "</head>" +
+ "<body onLoad=\"document.location='" + getHostPath() + "/Target.html';\">" +
+ "</body>" );
+ WebConversation wc = new WebConversation();
+ WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" );
+ assertEquals( "current page URL", getHostPath() + "/Target.html", wc.getCurrentPage().getURL().toExternalForm() );
+ assertEquals( "current page", "You made it!", wc.getCurrentPage().getText() );
+ assertEquals( "returned page URL", getHostPath() + "/Target.html", response.getURL().toExternalForm() );
+ assertEquals( "returned page", "You made it!", response.getText() );
}
|
|
From: Russell G. <rus...@us...> - 2003-03-14 17:41:34
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv754/src/com/meterware/httpunit
Modified Files:
WebForm.java WebLink.java WebRequestSource.java WebWindow.java
Log Message:
Return resultant page from WebClient.getResponse
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -r1.81 -r1.82
--- WebForm.java 13 Mar 2003 20:19:02 -0000 1.81
+++ WebForm.java 14 Mar 2003 17:41:27 -0000 1.82
@@ -61,9 +61,7 @@
* this will not run any event associated with the specified submit button. Use SubmitButton#click for that.
**/
public WebResponse submit( SubmitButton button ) throws IOException, SAXException {
- String event = getAttribute( "onsubmit" );
- if (event.length() == 0 || getScriptableObject().doEvent( event )) return submitRequest( getRequest( button ) );
- return getBaseResponse().getWindow().getFrameContents( getPageFrame() );
+ return submitRequest( getAttribute( "onsubmit" ), getRequest( button ) );
}
Index: WebLink.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- WebLink.java 27 Feb 2003 23:36:01 -0000 1.39
+++ WebLink.java 14 Mar 2003 17:41:28 -0000 1.40
@@ -84,11 +84,7 @@
* that frame will not be returned by this method.
**/
public WebResponse click() throws IOException, SAXException {
- WebResponse response = null;
- String event = getAttribute( "onclick" );
- if (event.length() == 0 || getScriptableObject().doEvent( event )) response = submitRequest();
- if (response == null) response = getBaseResponse().getWindow().getFrameContents( getPageFrame() );
- return response;
+ return submitRequest( getAttribute( "onclick" ), getRequest() );
}
Index: WebRequestSource.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequestSource.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- WebRequestSource.java 27 Feb 2003 23:36:01 -0000 1.24
+++ WebRequestSource.java 14 Mar 2003 17:41:29 -0000 1.25
@@ -201,12 +201,12 @@
}
- /**
- * Submits a request to the web client from which this request source was originally obtained.
- **/
- final
- protected WebResponse submitRequest() throws IOException, SAXException {
- return submitRequest( getRequest() );
+
+ protected WebResponse submitRequest( String event, final WebRequest request ) throws IOException, SAXException {
+ WebResponse response = null;
+ if (event.length() == 0 || getScriptableDelegate().doEvent( event )) response = submitRequest( request );
+ if (response == null) response = getBaseResponse().getWindow().getFrameContents( getPageFrame() );
+ return response;
}
Index: WebWindow.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebWindow.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- WebWindow.java 27 Feb 2003 23:36:02 -0000 1.9
+++ WebWindow.java 14 Mar 2003 17:41:30 -0000 1.10
@@ -109,7 +109,7 @@
final RequestContext requestContext = new RequestContext();
final WebResponse response = getSubframeResponse( request, requestContext );
requestContext.runScripts();
- return response;
+ return response == null ? null : getFrameContents( response.getFrameName() );
}
|
|
From: Russell G. <rus...@us...> - 2003-03-13 20:19:09
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv3375/src/com/meterware/httpunit
Modified Files:
Button.java WebForm.java
Log Message:
Renamed button predicates
Index: Button.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/Button.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Button.java 13 Mar 2003 20:16:17 -0000 1.6
+++ Button.java 13 Mar 2003 20:19:01 -0000 1.7
@@ -33,8 +33,8 @@
**/
public class Button extends FormControl {
- static final public HTMLElementPredicate HAS_ID;
- static final public HTMLElementPredicate HAS_LABEL;
+ static final public HTMLElementPredicate WITH_ID;
+ static final public HTMLElementPredicate WITH_LABEL;
private String _onClickEvent = "";
@@ -105,13 +105,13 @@
static {
- HAS_ID = new HTMLElementPredicate() {
+ WITH_ID = new HTMLElementPredicate() {
public boolean matchesCriteria( Object button, Object id ) {
return ((Button) button).getID().equals( id );
};
};
- HAS_LABEL = new HTMLElementPredicate() {
+ WITH_LABEL = new HTMLElementPredicate() {
public boolean matchesCriteria( Object button, Object label ) {
return ((Button) button).getValue().equals( label );
};
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -r1.80 -r1.81
--- WebForm.java 13 Mar 2003 20:16:17 -0000 1.80
+++ WebForm.java 13 Mar 2003 20:19:02 -0000 1.81
@@ -133,7 +133,7 @@
* Convenience method which returns the button with the specified ID.
*/
public Button getButtonWithID( String buttonID ) {
- return getButton( Button.HAS_ID, buttonID );
+ return getButton( Button.WITH_ID, buttonID );
}
|
|
From: Russell G. <rus...@us...> - 2003-03-13 20:16:28
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv2077/src/com/meterware/httpunit
Modified Files:
Button.java WebForm.java
Log Message:
Added WebForm.getButton method
Index: Button.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/Button.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Button.java 17 Feb 2003 23:54:40 -0000 1.5
+++ Button.java 13 Mar 2003 20:16:17 -0000 1.6
@@ -33,6 +33,9 @@
**/
public class Button extends FormControl {
+ static final public HTMLElementPredicate HAS_ID;
+ static final public HTMLElementPredicate HAS_LABEL;
+
private String _onClickEvent = "";
@@ -98,5 +101,21 @@
public void click() throws IOException, SAXException {
doButtonAction();
}
+ }
+
+
+ static {
+ HAS_ID = new HTMLElementPredicate() {
+ public boolean matchesCriteria( Object button, Object id ) {
+ return ((Button) button).getID().equals( id );
+ };
+ };
+
+ HAS_LABEL = new HTMLElementPredicate() {
+ public boolean matchesCriteria( Object button, Object label ) {
+ return ((Button) button).getValue().equals( label );
+ };
+ };
+
}
}
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -r1.79 -r1.80
--- WebForm.java 27 Feb 2003 23:35:59 -0000 1.79
+++ WebForm.java 13 Mar 2003 20:16:17 -0000 1.80
@@ -120,15 +120,20 @@
}
- /**
- * Returns the button with the specified ID
- */
- public Button getButtonWithID( String buttonID ) {
+ public Button getButton( HTMLElementPredicate predicate, Object criteria ) {
Button[] buttons = getButtons();
for (int i = 0; i < buttons.length; i++) {
- if (buttons[i].getID().equals( buttonID )) return buttons[i];
+ if (predicate.matchesCriteria( buttons[i], criteria )) return buttons[i];
}
return null;
+ }
+
+
+ /**
+ * Convenience method which returns the button with the specified ID.
+ */
+ public Button getButtonWithID( String buttonID ) {
+ return getButton( Button.HAS_ID, buttonID );
}
|
|
From: Russell G. <rus...@us...> - 2003-03-13 20:16:28
|
Update of /cvsroot/httpunit/httpunit/doc
In directory sc8-pr-cvs1:/tmp/cvs-serv2077/doc
Modified Files:
release_notes.txt
Log Message:
Added WebForm.getButton method
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.270
retrieving revision 1.271
diff -u -r1.270 -r1.271
--- release_notes.txt 13 Mar 2003 18:20:47 -0000 1.270
+++ release_notes.txt 13 Mar 2003 20:16:16 -0000 1.271
@@ -16,6 +16,7 @@
13-Mar-2003
Additions:
1. Select.value is now supported.
+ 2. Added WebForm.getButton() method using HTMLPredicate to permit more generalized button searches.
12-Mar-2003
Acknowledgements:
|
|
From: Russell G. <rus...@us...> - 2003-03-13 18:21:34
|
Update of /cvsroot/httpunit/httpunit/doc
In directory sc8-pr-cvs1:/tmp/cvs-serv16661/doc
Modified Files:
Javascript-support.html release_notes.txt
Log Message:
Added support for select.value
Index: Javascript-support.html
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/Javascript-support.html,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- Javascript-support.html 9 Jan 2003 18:02:23 -0000 1.34
+++ Javascript-support.html 13 Mar 2003 18:20:46 -0000 1.35
@@ -225,6 +225,7 @@
<li>selectedIndex - read-write - the index of the selected option</li>
<li>options - read-write - an array of the options associated with the control</li>
<li>options.length - read-write - the number of options associated with the control</li>
+<li>value - read-write - the value of the selected option</li>
</ul>
<h4>events</h4>
<ul>
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.269
retrieving revision 1.270
diff -u -r1.269 -r1.270
--- release_notes.txt 12 Mar 2003 17:34:06 -0000 1.269
+++ release_notes.txt 13 Mar 2003 18:20:47 -0000 1.270
@@ -13,7 +13,11 @@
Revision History:
- 12-Mar-2002
+ 13-Mar-2003
+Additions:
+ 1. Select.value is now supported.
+
+ 12-Mar-2003
Acknowledgements:
Thanks to Daniel Jasmin for fixing the handling of applet loading from archives.
|
|
From: Russell G. <rus...@us...> - 2003-03-13 18:21:30
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv16661/src/com/meterware/httpunit
Modified Files:
FormControl.java
Log Message:
Added support for select.value
Index: FormControl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- FormControl.java 17 Feb 2003 23:54:40 -0000 1.36
+++ FormControl.java 13 Mar 2003 18:20:49 -0000 1.37
@@ -855,6 +855,8 @@
return _selectionOptions;
} else if (propertyName.equalsIgnoreCase( "length" )) {
return new Integer( getOptionValues().length );
+ } else if (propertyName.equalsIgnoreCase( "value" )) {
+ return getSelectedValue();
} else if (propertyName.equalsIgnoreCase( "selectedIndex" )) {
return new Integer( _selectionOptions.getFirstSelectedIndex() );
} else {
@@ -863,8 +865,17 @@
}
+ private String getSelectedValue() {
+ String[] values = getValues();
+ return (values.length == 0 ? "" : values[0] );
+ }
+
+
public void set( String propertyName, Object value ) {
if (propertyName.equalsIgnoreCase( "value" )) {
+ ArrayList values = new ArrayList();
+ values.add( value );
+ _selectionOptions.claimUniqueValues( values );
} else if (propertyName.equalsIgnoreCase( "selectedIndex" )) {
if (!(value instanceof Number)) throw new RuntimeException( "selectedIndex must be set to an integer" );
_selectionOptions.setSelectedIndex( ((Number) value).intValue() );
|