httpunit-commit Mailing List for httpunit (Page 3)
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: <wol...@us...> - 2011-01-10 13:39:54
|
Revision: 1069
http://httpunit.svn.sourceforge.net/httpunit/?rev=1069&view=rev
Author: wolfgang_fahl
Date: 2011-01-10 13:39:48 +0000 (Mon, 10 Jan 2011)
Log Message:
-----------
improved documentation and changed proxy settings to constants. Added System.out message to explain how to modify this example
Modified Paths:
--------------
trunk/httpunit/examples/ProxySample.java
Modified: trunk/httpunit/examples/ProxySample.java
===================================================================
--- trunk/httpunit/examples/ProxySample.java 2010-05-07 12:39:04 UTC (rev 1068)
+++ trunk/httpunit/examples/ProxySample.java 2011-01-10 13:39:48 UTC (rev 1069)
@@ -32,16 +32,36 @@
public class ProxySample extends TestCase {
+ // modify proxyURL and proxyPort to your personal preferences
+ // e.g. a proxy server that is accessible from your network
+ public static String proxyURL="www-proxy.us.oracle.com";
+ public static int proxyPort=80;
+
+ /**
+ * main routine to test
+ * @param args
+ */
public static void main(String args[]) {
+ System.out.println("Will run this sample JUnit Testcase with proxy URL set to "+proxyURL+" port "+proxyPort);
+ System.out.println("You might want to modify the proxy server URL (see proxyURL,proxyPort fields in ProxySample.java) to one that you may use at your location for quicker response time");
+ // run this example as a Unit test
junit.textui.TestRunner.run( suite() );
}
+ /**
+ * create a Testsuite containing this ProxySample class
+ * @return the testsuite
+ */
public static TestSuite suite() {
return new TestSuite( ProxySample.class );
}
+ /**
+ * constructor which just calls the super constructor
+ * @param name
+ */
public ProxySample( String name ) {
super( name );
}
@@ -54,10 +74,11 @@
*/
public void testProxyAccess() throws Exception {
WebConversation wc = new WebConversation();
- wc.setProxyServer( "www-proxy.us.oracle.com", 80 );
+ wc.setProxyServer( proxyURL, proxyPort );
wc.getResponse( "http://www.meterware.com" );
}
}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2010-05-07 12:39:10
|
Revision: 1068
http://httpunit.svn.sourceforge.net/httpunit/?rev=1068&view=rev
Author: wolfgang_fahl
Date: 2010-05-07 12:39:04 +0000 (Fri, 07 May 2010)
Log Message:
-----------
patch by Serge Maslyukov for Triple dotted path handling
Modified Paths:
--------------
trunk/httpunit/src/com/meterware/httpunit/WebRequest.java
trunk/httpunit/test/com/meterware/httpunit/NormalizeURLTest.java
Modified: trunk/httpunit/src/com/meterware/httpunit/WebRequest.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/WebRequest.java 2010-05-07 12:12:22 UTC (rev 1067)
+++ trunk/httpunit/src/com/meterware/httpunit/WebRequest.java 2010-05-07 12:39:04 UTC (rev 1068)
@@ -142,7 +142,7 @@
private String getNormalizedPath( String path ) {
if (path.lastIndexOf( "//" ) > path.lastIndexOf( "://" ) + 1) return getNormalizedPath( stripDoubleSlashes( path ) );
- if (path.indexOf( "/.." ) > 0) return getNormalizedPath( stripUpNavigation( path ) );
+ if (path.indexOf( "/../" )>0 || path.endsWith("/..")) return getNormalizedPath( stripUpNavigation( path ) );
if (path.indexOf( "/./" ) > 0) return getNormalizedPath( stripInPlaceNavigation( path ) );
return path;
}
Modified: trunk/httpunit/test/com/meterware/httpunit/NormalizeURLTest.java
===================================================================
--- trunk/httpunit/test/com/meterware/httpunit/NormalizeURLTest.java 2010-05-07 12:12:22 UTC (rev 1067)
+++ trunk/httpunit/test/com/meterware/httpunit/NormalizeURLTest.java 2010-05-07 12:39:04 UTC (rev 1068)
@@ -238,6 +238,15 @@
WebRequest request = new GetMethodWebRequest( "http://host.name/directory1/directory2/../../file.html" );
assertEquals( "URL", request.getURL().toExternalForm(), "http://host.name/file.html" );
}
+
+ /**
+ * patch by Serge Maslyukov
+ * @throws Exception
+ */
+ public void testTripleDottedPath() throws Exception {
+ WebRequest request = new GetMethodWebRequest( "http://en.wikipedia.org/wiki/...And_Found" );
+ assertEquals( "URL", request.getURL().toExternalForm(), "http://en.wikipedia.org/wiki/...And_Found" );
+ }
/*
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2010-05-07 12:13:02
|
Revision: 1067
http://httpunit.svn.sourceforge.net/httpunit/?rev=1067&view=rev
Author: wolfgang_fahl
Date: 2010-05-07 12:12:22 +0000 (Fri, 07 May 2010)
Log Message:
-----------
patch for parseContentTypeHeader by Serge Maslyukov
Modified Paths:
--------------
trunk/httpunit/src/com/meterware/httpunit/HttpUnitUtils.java
trunk/httpunit/test/com/meterware/httpunit/EncodingTest.java
Modified: trunk/httpunit/src/com/meterware/httpunit/HttpUnitUtils.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/HttpUnitUtils.java 2010-05-07 11:58:36 UTC (rev 1066)
+++ trunk/httpunit/src/com/meterware/httpunit/HttpUnitUtils.java 2010-05-07 12:12:22 UTC (rev 1067)
@@ -71,12 +71,12 @@
* Returns the content type and encoding as a pair of strings.
* If no character set is specified, the second entry will be null.
* @param header the header to parse
- * @return a string array with the content type and the content charset
+ * @return a string array with the content type and the content char set
**/
public static String[] parseContentTypeHeader( String header ) {
String[] result = new String[] { "text/plain", null };
if (header.trim().length()>0){
- StringTokenizer st = new StringTokenizer( header, ";=" );
+ StringTokenizer st = new StringTokenizer( header, ";= " );
result[0] = st.nextToken();
while (st.hasMoreTokens()) {
String parameter = st.nextToken();
Modified: trunk/httpunit/test/com/meterware/httpunit/EncodingTest.java
===================================================================
--- trunk/httpunit/test/com/meterware/httpunit/EncodingTest.java 2010-05-07 11:58:36 UTC (rev 1066)
+++ trunk/httpunit/test/com/meterware/httpunit/EncodingTest.java 2010-05-07 12:12:22 UTC (rev 1067)
@@ -66,23 +66,31 @@
"text/plain",
"text/html; charset=Cp1252",
"text/html; charset=iso-8859-8",
- "text/html; charset=EUC-JP"
+ "text/html; charset=EUC-JP",
+ "text/html charset=windows-1251",
+ "text/html; charset=utf-8",
+ "text/html; charset = utf-8",
+ "text/html; charset=\"iso-8859-8\""
};
String expected[][]={
{"text/plain",null},
{"text/plain",null},
{"text/html","Cp1252"},
{"text/html","iso-8859-8"},
- {"text/html","EUC-JP"}
+ {"text/html","EUC-JP"},
+ {"text/html","windows-1251"},
+ {"text/html","utf-8"},
+ {"text/html","utf-8"},
+ {"text/html","iso-8859-8"}
};
for (int i=0;i<headers.length;i++) {
String result[]=HttpUnitUtils.parseContentTypeHeader(headers[i]);
+ assertEquals(2, result.length);
assertEquals( "header "+i , expected[i][0] , result[0]);
assertEquals( "header "+i , expected[i][1] , result[1]);
} // for
}
-
public void testSpecifiedEncoding() throws Exception {
String hebrewTitle = "\u05d0\u05d1\u05d2\u05d3";
String page = "<html><head><title>" + hebrewTitle + "</title></head>\n" +
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2010-05-07 11:15:40
|
Revision: 1065
http://httpunit.svn.sourceforge.net/httpunit/?rev=1065&view=rev
Author: wolfgang_fahl
Date: 2010-05-07 11:15:34 +0000 (Fri, 07 May 2010)
Log Message:
-----------
comment typo fixed
Modified Paths:
--------------
trunk/httpunit/test/com/meterware/servletunit/WebXMLString.java
Modified: trunk/httpunit/test/com/meterware/servletunit/WebXMLString.java
===================================================================
--- trunk/httpunit/test/com/meterware/servletunit/WebXMLString.java 2010-05-06 17:11:54 UTC (rev 1064)
+++ trunk/httpunit/test/com/meterware/servletunit/WebXMLString.java 2010-05-07 11:15:34 UTC (rev 1065)
@@ -80,9 +80,9 @@
}
/**
- * return me as a Text/String containing the XML descriptor accoding
+ * return me as a Text/String containing the XML descriptor according
* to the Sun Microsystems's specification
- * if running on Eclipse shorten the DOCTYPE spec as a work-around for a
+ * if running on Eclipse shorten the DOCTYPE specification as a work-around for a
* bogus java.net.MalformedURLException (that is in fact caused by a null-pointer exception in handling the dtd part)
* @return
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2009-12-22 15:34:37
|
Revision: 1062
http://httpunit.svn.sourceforge.net/httpunit/?rev=1062&view=rev
Author: wolfgang_fahl
Date: 2009-12-22 15:34:27 +0000 (Tue, 22 Dec 2009)
Log Message:
-----------
Patch for issue when server returns empty content type value + workaround for regression
problem - do not try to redefine resources
Modified Paths:
--------------
trunk/httpunit/src/com/meterware/httpunit/HttpUnitUtils.java
trunk/httpunit/src/com/meterware/pseudoserver/PseudoServer.java
trunk/httpunit/test/com/meterware/httpunit/EncodingTest.java
trunk/httpunit/test/com/meterware/httpunit/MessageBodyRequestTest.java
trunk/httpunit/test/com/meterware/httpunit/WebClientTest.java
trunk/httpunit/test/com/meterware/httpunit/javascript/NekoEnhancedScriptingTest.java
Modified: trunk/httpunit/src/com/meterware/httpunit/HttpUnitUtils.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/HttpUnitUtils.java 2009-09-10 05:23:52 UTC (rev 1061)
+++ trunk/httpunit/src/com/meterware/httpunit/HttpUnitUtils.java 2009-12-22 15:34:27 UTC (rev 1062)
@@ -75,16 +75,18 @@
**/
public static String[] parseContentTypeHeader( String header ) {
String[] result = new String[] { "text/plain", null };
- StringTokenizer st = new StringTokenizer( header, ";=" );
- result[0] = st.nextToken();
- while (st.hasMoreTokens()) {
- String parameter = st.nextToken();
- if (st.hasMoreTokens()) {
- String value = stripQuotes( st.nextToken() );
- if (parameter.trim().equalsIgnoreCase( "charset" )) {
- result[1] = value;
- }
- }
+ if (header.trim().length()>0){
+ StringTokenizer st = new StringTokenizer( header, ";=" );
+ result[0] = st.nextToken();
+ while (st.hasMoreTokens()) {
+ String parameter = st.nextToken();
+ if (st.hasMoreTokens()) {
+ String value = stripQuotes( st.nextToken() );
+ if (parameter.trim().equalsIgnoreCase( "charset" )) {
+ result[1] = value;
+ }
+ }
+ }
}
return result;
}
Modified: trunk/httpunit/src/com/meterware/pseudoserver/PseudoServer.java
===================================================================
--- trunk/httpunit/src/com/meterware/pseudoserver/PseudoServer.java 2009-09-10 05:23:52 UTC (rev 1061)
+++ trunk/httpunit/src/com/meterware/pseudoserver/PseudoServer.java 2009-12-22 15:34:27 UTC (rev 1062)
@@ -266,7 +266,7 @@
private boolean _active = true;
- private boolean _debug;
+ private boolean _debug=true;
private String asResourceName( String rawName ) {
Modified: trunk/httpunit/test/com/meterware/httpunit/EncodingTest.java
===================================================================
--- trunk/httpunit/test/com/meterware/httpunit/EncodingTest.java 2009-09-10 05:23:52 UTC (rev 1061)
+++ trunk/httpunit/test/com/meterware/httpunit/EncodingTest.java 2009-12-22 15:34:27 UTC (rev 1062)
@@ -62,6 +62,7 @@
*/
public void testParseContentHeader() throws Exception {
String headers[]={
+ "",
"text/plain",
"text/html; charset=Cp1252",
"text/html; charset=iso-8859-8",
@@ -69,6 +70,7 @@
};
String expected[][]={
{"text/plain",null},
+ {"text/plain",null},
{"text/html","Cp1252"},
{"text/html","iso-8859-8"},
{"text/html","EUC-JP"}
Modified: trunk/httpunit/test/com/meterware/httpunit/MessageBodyRequestTest.java
===================================================================
--- trunk/httpunit/test/com/meterware/httpunit/MessageBodyRequestTest.java 2009-09-10 05:23:52 UTC (rev 1061)
+++ trunk/httpunit/test/com/meterware/httpunit/MessageBodyRequestTest.java 2009-12-22 15:34:27 UTC (rev 1062)
@@ -27,6 +27,7 @@
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -51,21 +52,49 @@
public void setUp() throws Exception {
super.setUp();
}
-
- public void testGenericPostRequest() throws Exception {
- defineResource("ReportData", new BodyEcho());
- String sourceData = "This is an interesting test\nWith two lines";
+
+ /**
+ * make a Request from the given parameters
+ * @param resourceName
+ * @param sourceData
+ * @param contentType
+ * @return the new WebRequest
+ * @throws UnsupportedEncodingException
+ */
+ public WebRequest makeRequest(String resourceName,String sourceData, String contentType) throws UnsupportedEncodingException{
+ defineResource(resourceName, new BodyEcho());
InputStream source = new ByteArrayInputStream(sourceData
.getBytes("iso-8859-1"));
+ WebRequest wr = new PostMethodWebRequest(getHostPath() + "/"+resourceName,
+ source, contentType);
+ return wr;
+ }
+ /**
+ * test a generic Post request
+ * @throws Exception
+ */
+ public void testGenericPostRequest() throws Exception {
WebConversation wc = new WebConversation();
- WebRequest wr = new PostMethodWebRequest(getHostPath() + "/ReportData",
- source, "text/sample");
+ String sourceData="This is an interesting test\nWith two lines";
+ WebRequest wr = makeRequest("ReportData",sourceData, "text/sample");
WebResponse response = wc.getResponse(wr);
assertEquals("Body response", "\nPOST\n" + sourceData, response
.getText());
assertEquals("Content-type", "text/sample", response.getContentType());
}
+
+ /**
+ * test for Patch by Serge Maslyukov for empty content Types
+ * @throws Exception
+ */
+ public void testEmptyContentType() throws Exception {
+ WebConversation wc = new WebConversation();
+ String emptyContentType=""; // this is an emptyContentType
+ WebRequest wr = makeRequest("something","some data",emptyContentType);
+ WebResponse response = wc.getResponse(wr);
+ assertEquals("Content-type", "",wr.getContentType());
+ }
public void testPutRequest() throws Exception {
defineResource("ReportData", new BodyEcho());
Modified: trunk/httpunit/test/com/meterware/httpunit/WebClientTest.java
===================================================================
--- trunk/httpunit/test/com/meterware/httpunit/WebClientTest.java 2009-09-10 05:23:52 UTC (rev 1061)
+++ trunk/httpunit/test/com/meterware/httpunit/WebClientTest.java 2009-12-22 15:34:27 UTC (rev 1062)
@@ -643,7 +643,7 @@
* @throws Exception
*/
public void dotestRefererHeader(boolean refererEnabled) throws Exception {
- String resourceName = "tellMe";
+ String resourceName = "tellMe"+refererEnabled;
String linkSource = "fromLink";
String formSource = "fromForm";
@@ -651,8 +651,8 @@
String page1 = getHostPath() + '/' + linkSource;
String page2 = getHostPath() + '/' + formSource;
- defineResource( linkSource, "<html><head></head><body><a href=\"tellMe\">Go</a></body></html>" );
- defineResource( formSource, "<html><body><form action=\"tellMe\"><input type=submit></form></body></html>" );
+ defineResource( linkSource, "<html><head></head><body><a href=\""+resourceName+"\">Go</a></body></html>" );
+ defineResource( formSource, "<html><body><form action=\""+resourceName+"\"><input type=submit></form></body></html>" );
defineResource( resourceName, new PseudoServlet() {
public WebResource getGetResponse() {
String referer = getHeader( "Referer" );
Modified: trunk/httpunit/test/com/meterware/httpunit/javascript/NekoEnhancedScriptingTest.java
===================================================================
--- trunk/httpunit/test/com/meterware/httpunit/javascript/NekoEnhancedScriptingTest.java 2009-09-10 05:23:52 UTC (rev 1061)
+++ trunk/httpunit/test/com/meterware/httpunit/javascript/NekoEnhancedScriptingTest.java 2009-12-22 15:34:27 UTC (rev 1062)
@@ -49,7 +49,7 @@
public void testEmbeddedDocumentWrite() throws Exception {
- defineResource( "OnCommand.html", "<html><head><title>something</title></head>" +
+ defineResource( "OnCommandWrite.html", "<html><head><title>something</title></head>" +
"<body>" +
"<script language='JavaScript'>" +
"document.write( '<a id=here href=about:blank>' );" +
@@ -58,7 +58,7 @@
"</script>" +
"</body></html>" );
WebConversation wc = new WebConversation();
- WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" );
+ WebResponse response = wc.getResponse( getHostPath() + "/OnCommandWrite.html" );
WebLink link = response.getLinkWithID( "here" );
assertNotNull( "The link was not found", link );
assertEquals( "Link contents", "something", link.getText() );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2009-09-10 05:24:00
|
Revision: 1061
http://httpunit.svn.sourceforge.net/httpunit/?rev=1061&view=rev
Author: wolfgang_fahl
Date: 2009-09-10 05:23:52 +0000 (Thu, 10 Sep 2009)
Log Message:
-----------
This patch adds support for creating and testing HTTP DELETE requests. - by Matthew M. Boedicker
Modified Paths:
--------------
trunk/httpunit/src/com/meterware/pseudoserver/PseudoServlet.java
trunk/httpunit/test/com/meterware/httpunit/WebClientTest.java
Added Paths:
-----------
trunk/httpunit/src/com/meterware/httpunit/DeleteMethodWebRequest.java
Added: trunk/httpunit/src/com/meterware/httpunit/DeleteMethodWebRequest.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/DeleteMethodWebRequest.java (rev 0)
+++ trunk/httpunit/src/com/meterware/httpunit/DeleteMethodWebRequest.java 2009-09-10 05:23:52 UTC (rev 1061)
@@ -0,0 +1,142 @@
+package com.meterware.httpunit;
+/********************************************************************************************************************
+* $Id$
+*
+* Copyright (c) 2009, Matthew M. Boedicker
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
+* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in all copies or substantial portions
+* of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+* DEALINGS IN THE SOFTWARE.
+*
+*******************************************************************************************************************/
+import org.w3c.dom.Element;
+
+import java.net.URL;
+
+/**
+ * An HTTP request using the DELETE method.
+ * RFC 2616 http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html defines:
+ *
+ * 9.7 DELETE
+ *
+ * The DELETE method requests that the origin server delete the resource identified
+ * by the Request-URI. This method MAY be overridden by human intervention (or other
+ * means) on the origin server. The client cannot be guaranteed that the operation
+ * has been carried out, even if the status code returned from the origin server
+ * indicates that the action has been completed successfully. However, the server
+ * SHOULD NOT indicate success unless, at the time the response is given, it
+ * intends to delete the resource or move it to an inaccessible location.
+ *
+ * A successful response SHOULD be 200 (OK) if the response includes an entity
+ * describing the status, 202 (Accepted) if the action has not yet been enacted, or
+ * 204 (No Content) if the action has been enacted but the response does not include
+ * an entity.
+ *
+ * If the request passes through a cache and the Request-URI identifies one or more
+ * currently cached entities, those entries SHOULD be treated as stale. Responses to
+ * this method are not cacheable.
+**/
+public class DeleteMethodWebRequest extends HeaderOnlyWebRequest {
+
+ /**
+ * initialize me - set method to DELETE
+ */
+ private void init() {
+ super.setMethod("DELETE");
+ }
+
+ /**
+ * Constructs a web request using a specific absolute url string.
+ **/
+ public DeleteMethodWebRequest( String urlString ) {
+ super( urlString );
+ init();
+ }
+
+
+ /**
+ * Constructs a web request using a base URL and a relative url string.
+ **/
+ public DeleteMethodWebRequest( URL urlBase, String urlString ) {
+ super( urlBase, urlString );
+ init();
+ }
+
+
+ /**
+ * Constructs a web request with a specific target.
+ **/
+ public DeleteMethodWebRequest( URL urlBase, String urlString, String target ) {
+ super( urlBase, urlString, target );
+ init();
+ }
+
+
+//--------------------------------------- package members ---------------------------------------------
+
+
+ /**
+ * Constructs a web request for a form submitted from JavaScript.
+ **/
+ DeleteMethodWebRequest( WebForm sourceForm ) {
+ super( sourceForm );
+ init();
+ }
+
+
+ /**
+ * Constructs a web request for a link or image.
+ **/
+ DeleteMethodWebRequest( FixedURLWebRequestSource source ) {
+ super( source );
+ init();
+ }
+
+
+ /**
+ * Constructs a web request with a specific target.
+ **/
+ DeleteMethodWebRequest( WebResponse referer, Element sourceElement, URL urlBase, String urlString, String target ) {
+ super( referer, sourceElement, urlBase, urlString, target );
+ init();
+ }
+
+
+ /**
+ * Constructs an initial web request for a frame.
+ **/
+ DeleteMethodWebRequest( URL urlBase, String urlString, FrameSelector frame ) {
+ super( urlBase, urlString, frame );
+ init();
+ }
+
+
+ /**
+ * Constructs a web request for a javascript open call.
+ **/
+ DeleteMethodWebRequest( URL urlBase, String urlString, FrameSelector frame, String target ) {
+ super( urlBase, urlString, frame, target );
+ init();
+ }
+
+
+ /**
+ * Constructs a web request for a form.
+ **/
+ DeleteMethodWebRequest( WebForm sourceForm, ParameterHolder parameterHolder, SubmitButton button, int x, int y ) {
+ super( sourceForm, parameterHolder, button, x, y );
+ init();
+ }
+
+
+}
Property changes on: trunk/httpunit/src/com/meterware/httpunit/DeleteMethodWebRequest.java
___________________________________________________________________
Added: svn:keywords
+ Id Author HeadURL
Modified: trunk/httpunit/src/com/meterware/pseudoserver/PseudoServlet.java
===================================================================
--- trunk/httpunit/src/com/meterware/pseudoserver/PseudoServlet.java 2009-08-26 06:20:18 UTC (rev 1060)
+++ trunk/httpunit/src/com/meterware/pseudoserver/PseudoServlet.java 2009-09-10 05:23:52 UTC (rev 1061)
@@ -42,6 +42,8 @@
return getPutResponse();
} else if (methodType.equalsIgnoreCase( "POST" )) {
return getPostResponse();
+ } else if (methodType.equalsIgnoreCase( "DELETE" )) {
+ return getDeleteResponse();
} else {
throw new UnknownMethodException( methodType );
}
@@ -72,6 +74,14 @@
}
+ /*
+ * Returns a resource object as a result of a delete request.
+ **/
+ public WebResource getDeleteResponse() throws IOException {
+ throw new UnknownMethodException( "DELETE" );
+ }
+
+
void init( HttpRequest requestStream ) {
_request = requestStream;
}
Modified: trunk/httpunit/test/com/meterware/httpunit/WebClientTest.java
===================================================================
--- trunk/httpunit/test/com/meterware/httpunit/WebClientTest.java 2009-08-26 06:20:18 UTC (rev 1060)
+++ trunk/httpunit/test/com/meterware/httpunit/WebClientTest.java 2009-09-10 05:23:52 UTC (rev 1061)
@@ -1121,4 +1121,28 @@
assertEquals( "Submitted cookie header", "found cookies: type=short", wr.getText() );
}
+
+ /**
+ * test for Delete Response patch by Matthew M. Boedicker"
+ * @throws Exception
+ */
+ public void testDelete() throws Exception {
+ String resourceName = "something/to/delete";
+ final String responseBody = "deleted";
+ final String contentType = "text/plain";
+
+ defineResource( resourceName, new PseudoServlet() {
+ public WebResource getDeleteResponse() {
+ return new WebResource( responseBody, contentType );
+ }
+ } );
+
+ WebConversation wc = new WebConversation();
+ WebRequest request = new DeleteMethodWebRequest( getHostPath() + '/' + resourceName );
+ WebResponse response = wc.getResponse( request );
+
+ assertEquals( "requested resource", responseBody, response.getText().trim() );
+ assertEquals( "content type", contentType, response.getContentType() );
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2009-08-26 06:20:27
|
Revision: 1060
http://httpunit.svn.sourceforge.net/httpunit/?rev=1060&view=rev
Author: wolfgang_fahl
Date: 2009-08-26 06:20:18 +0000 (Wed, 26 Aug 2009)
Log Message:
-----------
not for release notes: classpath fixed for unix environment
Modified Paths:
--------------
trunk/httpunit/.classpath
Modified: trunk/httpunit/.classpath
===================================================================
--- trunk/httpunit/.classpath 2009-08-26 05:57:16 UTC (rev 1059)
+++ trunk/httpunit/.classpath 2009-08-26 06:20:18 UTC (rev 1060)
@@ -1,22 +1,21 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="test"/>
- <classpathentry kind="src" path="pending-tests"/>
- <classpathentry kind="src" path="examples"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="lib" path="jars/quicksite.jar"/>
- <classpathentry kind="var" path="MAVEN_REPOSITORY/jtidy/jtidy/4aug2000r7-dev/jtidy-4aug2000r7-dev.jar"/>
- <classpathentry kind="var" path="MAVEN_REPOSITORY/junit/junit/3.8.1/junit-3.8.1.jar"/>
- <classpathentry kind="var" path="MAVEN_REPOSITORY/nekohtml/nekohtml/0.9.5/nekohtml-0.9.5.jar"/>
- <classpathentry kind="var" path="MAVEN_REPOSITORY/rhino/js/1.6R5/js-1.6R5.jar" sourcepath="/pub/2008/rhino1_6R5.zip"/>
- <classpathentry kind="var" path="MAVEN_REPOSITORY/javax/servlet/servlet-api/2.4/servlet-api-2.4.jar"/>
- <classpathentry kind="var" path="MAVEN_REPOSITORY/xerces/xmlParserAPIs/2.6.1/xmlParserAPIs-2.6.1.jar" sourcepath="/pub/2008/Xerces-J-src.2.6.1.zip"/>
- <classpathentry kind="var" path="MAVEN_REPOSITORY/xerces/xercesImpl/2.6.1/xercesImpl-2.6.1.jar"/>
- <classpathentry kind="lib" path="META-INF"/>
- <classpathentry kind="var" path="MAVEN_REPOSITORY/javax/activation/activation/1.1/activation-1.1.jar"/>
- <classpathentry kind="var" path="MAVEN_REPOSITORY/javax/mail/mail/1.4/mail-1.4.jar"/>
- <classpathentry kind="lib" path="jars/maven-ant-tasks-2.0.9.jar"/>
- <classpathentry kind="var" path="MAVEN_REPOSITORY"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="test"/>
+ <classpathentry kind="src" path="pending-tests"/>
+ <classpathentry kind="src" path="examples"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="lib" path="jars/quicksite.jar"/>
+ <classpathentry kind="var" path="MAVEN_REPOSITORY/jtidy/jtidy/4aug2000r7-dev/jtidy-4aug2000r7-dev.jar"/>
+ <classpathentry kind="var" path="MAVEN_REPOSITORY/junit/junit/3.8.1/junit-3.8.1.jar"/>
+ <classpathentry kind="var" path="MAVEN_REPOSITORY/nekohtml/nekohtml/0.9.5/nekohtml-0.9.5.jar"/>
+ <classpathentry kind="var" path="MAVEN_REPOSITORY/rhino/js/1.6R5/js-1.6R5.jar" sourcepath="/pub/2008/rhino1_6R5.zip"/>
+ <classpathentry kind="var" path="MAVEN_REPOSITORY/javax/servlet/servlet-api/2.4/servlet-api-2.4.jar"/>
+ <classpathentry kind="var" path="MAVEN_REPOSITORY/xerces/xmlParserAPIs/2.6.1/xmlParserAPIs-2.6.1.jar" sourcepath="/pub/2008/Xerces-J-src.2.6.1.zip"/>
+ <classpathentry kind="var" path="MAVEN_REPOSITORY/xerces/xercesImpl/2.6.1/xercesImpl-2.6.1.jar"/>
+ <classpathentry kind="lib" path="META-INF"/>
+ <classpathentry kind="var" path="MAVEN_REPOSITORY/javax/activation/activation/1.1/activation-1.1.jar"/>
+ <classpathentry kind="var" path="MAVEN_REPOSITORY/javax/mail/mail/1.4/mail-1.4.jar"/>
+ <classpathentry kind="lib" path="jars/maven-ant-tasks-2.0.9.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2009-08-26 05:57:30
|
Revision: 1059
http://httpunit.svn.sourceforge.net/httpunit/?rev=1059&view=rev
Author: wolfgang_fahl
Date: 2009-08-26 05:57:16 +0000 (Wed, 26 Aug 2009)
Log Message:
-----------
not for release notes. added svn ignore for target directory that is used by maven
Property Changed:
----------------
trunk/httpunit/
Property changes on: trunk/httpunit
___________________________________________________________________
Modified: svn:ignore
- build
*.ipr
*.iml
*.iws
savejars
dist
lib
bin
web
.project
.classpath
*.zip
+ build
*.ipr
*.iml
*.iws
savejars
dist
lib
bin
web
.project
.classpath
*.zip
target
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2009-08-21 17:59:22
|
Revision: 1058
http://httpunit.svn.sourceforge.net/httpunit/?rev=1058&view=rev
Author: wolfgang_fahl
Date: 2009-08-21 17:59:16 +0000 (Fri, 21 Aug 2009)
Log Message:
-----------
Svn Keywords set
Modified Paths:
--------------
trunk/httpunit/test/com/meterware/httpunit/javascript/EventHandlingTest.java
Property Changed:
----------------
trunk/httpunit/test/com/meterware/httpunit/javascript/EventHandlingTest.java
Modified: trunk/httpunit/test/com/meterware/httpunit/javascript/EventHandlingTest.java
===================================================================
--- trunk/httpunit/test/com/meterware/httpunit/javascript/EventHandlingTest.java 2009-08-21 17:58:40 UTC (rev 1057)
+++ trunk/httpunit/test/com/meterware/httpunit/javascript/EventHandlingTest.java 2009-08-21 17:59:16 UTC (rev 1058)
@@ -1,7 +1,7 @@
package com.meterware.httpunit.javascript;
/********************************************************************************************************************
- * $Id: FormScriptingTest.java 1031 2009-08-17 12:15:24Z wolfgang_fahl $
- * $URL: https://httpunit.svn.sourceforge.net/svnroot/httpunit/trunk/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java $
+ * $Id$
+ * $URL$
*
* Copyright (c) 2009, Wolfgang Fahl
*
Property changes on: trunk/httpunit/test/com/meterware/httpunit/javascript/EventHandlingTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Id URL
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2009-08-21 17:58:47
|
Revision: 1057
http://httpunit.svn.sourceforge.net/httpunit/?rev=1057&view=rev
Author: wolfgang_fahl
Date: 2009-08-21 17:58:40 +0000 (Fri, 21 Aug 2009)
Log Message:
-----------
Testcase for patch
Added Paths:
-----------
trunk/httpunit/test/com/meterware/httpunit/javascript/EventHandlingTest.java
Added: trunk/httpunit/test/com/meterware/httpunit/javascript/EventHandlingTest.java
===================================================================
--- trunk/httpunit/test/com/meterware/httpunit/javascript/EventHandlingTest.java (rev 0)
+++ trunk/httpunit/test/com/meterware/httpunit/javascript/EventHandlingTest.java 2009-08-21 17:58:40 UTC (rev 1057)
@@ -0,0 +1,135 @@
+package com.meterware.httpunit.javascript;
+/********************************************************************************************************************
+ * $Id: FormScriptingTest.java 1031 2009-08-17 12:15:24Z wolfgang_fahl $
+ * $URL: https://httpunit.svn.sourceforge.net/svnroot/httpunit/trunk/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java $
+ *
+ * Copyright (c) 2009, Wolfgang Fahl
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
+ * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+ * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ *******************************************************************************************************************/
+import com.meterware.httpunit.*;
+import com.meterware.httpunit.controls.SelectionFormControl;
+import com.meterware.httpunit.protocol.UploadFileSpec;
+import com.meterware.pseudoserver.PseudoServlet;
+import com.meterware.pseudoserver.WebResource;
+
+import java.io.IOException;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.textui.TestRunner;
+import junit.framework.TestSuite;
+import org.xml.sax.SAXException;
+
+
+/**
+ * @author Wolfgang Fahl
+ **/
+public class EventHandlingTest extends HttpUnitTest {
+
+ /***
+ * allow start as Java application
+ * @param args
+ */
+ public static void main( String args[] ) {
+ TestRunner.run( suite() );
+ }
+
+
+ /**
+ * return this Testcase as a TestSuite containg this test
+ * @return
+ */
+ public static TestSuite suite() {
+ return new TestSuite( EventHandlingTest.class );
+ }
+
+
+ /**
+ * constructor for this testcase
+ * @param name
+ */
+ public EventHandlingTest( String name ) {
+ super( name );
+ }
+
+ private WebConversation _wc;
+
+ public void setUp() throws Exception {
+ super.setUp();
+ _wc = new WebConversation();
+ }
+
+ /**
+ * add a resource with the given name and title defining the given javaScript and content
+ * @param name
+ * @param title
+ * @param javaScript
+ * @param content
+ */
+ public void addResource(String name,String title, String onLoad,String javaScript,String content){
+ if (onLoad==null) {
+ onLoad="";
+ }
+ if (!onLoad.equals("")) {
+ onLoad=" onload='"+onLoad+"'";
+ }
+ defineResource(name+".html",
+ "<html>\n\t<head>\n\t\t<title>"+title+"</title>\n"+
+ "\t\t<script type='text/javascript'>\n" +
+ javaScript+
+ "\t\t</script>\n\t</head>\n" +
+ "\t<body"+onLoad+">\n\t\t"+content+"\n\t</body>\n</html>");
+ }
+
+ /**
+ * get the response for the resource with the given name
+ * @param name
+ * @throws SAXException
+ * @throws IOException
+ * @return the response
+ */
+ public WebResponse getResponse(String name) throws IOException, SAXException {
+ WebResponse response = _wc.getResponse( getHostPath() + "/"+name+".html");
+ return response;
+ }
+
+ /**
+ * test for [ 1163753 ] partial patch for bug 771335 (DOM2 Events support) by Rafael Krzewski
+ * @throws SAXException
+ * @throws IOException
+ */
+ public void testSimpleEventHandler() throws IOException, SAXException {
+ String javaScript=
+ " function testEventHandler() {\n" +
+ " if (document.addEventListener) {\n"+
+ " alert('found addEventListener');\n"+
+ " }\n"+
+ " }\n";
+ String onLoad="testEventHandler()";
+ String content="";
+ String name="simple1";
+ addResource(name,"only check addEventListener function available",onLoad,javaScript,content);
+ WebResponse response =getResponse(name);
+ // System.out.println(response.getText());
+ String alert=_wc.popNextAlert();
+ assertEquals("found addEventListener",alert);
+ }
+
+ // FIXME need more tests for event handling
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2009-08-21 17:55:48
|
Revision: 1056
http://httpunit.svn.sourceforge.net/httpunit/?rev=1056&view=rev
Author: wolfgang_fahl
Date: 2009-08-21 17:55:42 +0000 (Fri, 21 Aug 2009)
Log Message:
-----------
Svn Keywords set
Modified Paths:
--------------
trunk/httpunit/src/com/meterware/httpunit/javascript/events/Event.java
trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventException.java
trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventListener.java
trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventTarget.java
Property Changed:
----------------
trunk/httpunit/src/com/meterware/httpunit/javascript/events/Event.java
trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventException.java
trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventListener.java
trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventTarget.java
Modified: trunk/httpunit/src/com/meterware/httpunit/javascript/events/Event.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/javascript/events/Event.java 2009-08-21 17:54:02 UTC (rev 1055)
+++ trunk/httpunit/src/com/meterware/httpunit/javascript/events/Event.java 2009-08-21 17:55:42 UTC (rev 1056)
@@ -1,6 +1,6 @@
/********************************************************************************************************************
- * $Id: FormScriptingTest.java 1031 2009-08-17 12:15:24Z wolfgang_fahl $
- * $URL: https://httpunit.svn.sourceforge.net/svnroot/httpunit/trunk/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java $
+ * $Id$
+ * $URL$
*
* Copyright (c) 2005, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.,
* Copyright (c) 2009, Wolfgang Fahl
Property changes on: trunk/httpunit/src/com/meterware/httpunit/javascript/events/Event.java
___________________________________________________________________
Added: svn:keywords
+ Id Author URL
Modified: trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventException.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventException.java 2009-08-21 17:54:02 UTC (rev 1055)
+++ trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventException.java 2009-08-21 17:55:42 UTC (rev 1056)
@@ -1,6 +1,6 @@
/********************************************************************************************************************
- * $Id: FormScriptingTest.java 1031 2009-08-17 12:15:24Z wolfgang_fahl $
- * $URL: https://httpunit.svn.sourceforge.net/svnroot/httpunit/trunk/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java $
+ * $Id$
+ * $URL$
*
* Copyright (c) 2005, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.,
* Copyright (c) 2009, Wolfgang Fahl
Property changes on: trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventException.java
___________________________________________________________________
Added: svn:keywords
+ Id Author URL
Modified: trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventListener.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventListener.java 2009-08-21 17:54:02 UTC (rev 1055)
+++ trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventListener.java 2009-08-21 17:55:42 UTC (rev 1056)
@@ -1,6 +1,6 @@
/********************************************************************************************************************
- * $Id: FormScriptingTest.java 1031 2009-08-17 12:15:24Z wolfgang_fahl $
- * $URL: https://httpunit.svn.sourceforge.net/svnroot/httpunit/trunk/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java $
+ * $Id$
+ * $URL$
*
* Copyright (c) 2005, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.,
* Copyright (c) 2009, Wolfgang Fahl
Property changes on: trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventListener.java
___________________________________________________________________
Added: svn:keywords
+ Id Author URL
Modified: trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventTarget.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventTarget.java 2009-08-21 17:54:02 UTC (rev 1055)
+++ trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventTarget.java 2009-08-21 17:55:42 UTC (rev 1056)
@@ -1,6 +1,6 @@
/********************************************************************************************************************
- * $Id: FormScriptingTest.java 1031 2009-08-17 12:15:24Z wolfgang_fahl $
- * $URL: https://httpunit.svn.sourceforge.net/svnroot/httpunit/trunk/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java $
+ * $Id$
+ * $URL$
*
* Copyright (c) 2005, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.,
* Copyright (c) 2009, Wolfgang Fahl
Property changes on: trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventTarget.java
___________________________________________________________________
Added: svn:keywords
+ Id Author URL
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2009-08-21 17:54:09
|
Revision: 1055
http://httpunit.svn.sourceforge.net/httpunit/?rev=1055&view=rev
Author: wolfgang_fahl
Date: 2009-08-21 17:54:02 +0000 (Fri, 21 Aug 2009)
Log Message:
-----------
[ 1163753 ] partial patch for bug 771335 (DOM2 Events support) by
Rafal Krzewski
Modified Paths:
--------------
trunk/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java
trunk/httpunit/test/com/meterware/httpunit/javascript/JavaScriptTestSuite.java
Added Paths:
-----------
trunk/httpunit/src/com/meterware/httpunit/javascript/events/
trunk/httpunit/src/com/meterware/httpunit/javascript/events/Event.java
trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventException.java
trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventListener.java
trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventTarget.java
Modified: trunk/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java 2009-08-21 14:00:15 UTC (rev 1054)
+++ trunk/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java 2009-08-21 17:54:02 UTC (rev 1055)
@@ -21,11 +21,17 @@
*******************************************************************************************************************/
import com.meterware.httpunit.*;
+import com.meterware.httpunit.javascript.events.EventException;
+import com.meterware.httpunit.javascript.events.EventTarget;
import com.meterware.httpunit.scripting.*;
import java.lang.reflect.InvocationTargetException;
import java.io.IOException;
import java.net.URL;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
import org.mozilla.javascript.*;
import org.xml.sax.SAXException;
@@ -104,10 +110,12 @@
/**
* abstract Engine for JavaScript
*/
- abstract static class JavaScriptEngine extends ScriptingEngineImpl {
+ abstract static class JavaScriptEngine extends ScriptingEngineImpl implements EventTarget {
protected ScriptableDelegate _scriptable;
protected JavaScriptEngine _parent;
+ protected Map _eventListeners = new HashMap(); // Map<String,Set<EventListener>>
+ protected Map _eventCaptureListeners = new HashMap(); // Map<String,Set<EventListener>>
/**
* initialize JavaScript for the given ScriptEngine
@@ -270,6 +278,57 @@
result.initialize( elements );
return result;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public void jsFunction_addEventListener(String type, Scriptable listener, boolean useCapture) {
+ if(useCapture) {
+ Set set = (Set)_eventCaptureListeners.get(type); //Set<Scriptable>
+ if(set == null) {
+ set = new HashSet();
+ _eventCaptureListeners.put(type, set);
+ }
+ set.add(listener);
+ } else {
+ Set set = (Set)_eventListeners.get(type); //Set<Scriptable>
+ if(set == null) {
+ set = new HashSet();
+ _eventListeners.put(type, set);
+ }
+ set.add(listener);
+ }
+ //System.out.println(getClassName()+".addEventListener("+type+")");
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean jsFunction_dispatchEvent(Scriptable evt) throws EventException {
+ // TODO implement event dispatching & listener invocation
+ //System.out.println(getClassName()+".dispatchEvent("+evt.get("type",evt)+")");
+ return true;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void jsFunction_removeEventListener(String type, Scriptable listener, boolean useCapture) {
+ if(useCapture) {
+ Set set = (Set)_eventCaptureListeners.get(type); //Set<EventListener>
+ if(set != null) {
+ set.remove(listener);
+ }
+ } else {
+ Set set = (Set)_eventListeners.get(type); //Set<EventListener>
+ if(set != null) {
+ set.remove(listener);
+ }
+ }
+ //System.out.println(getClassName()+".removeEventListener("+type+")");
+ }
}
@@ -415,6 +474,7 @@
}
+
public Window jsFunction_open( Object url, String name, String features, boolean replace )
throws PropertyException, JavaScriptException, NotAFunctionException, IOException, SAXException {
WebResponse.Scriptable delegate = getDelegate().open( toStringIfNotUndefined( url ), name, features, replace );
@@ -576,6 +636,27 @@
return (HTMLPage.Scriptable) _scriptable;
}
+
+ public void jsFunction_addEventListener(String type,
+ Scriptable listener, boolean useCapture) {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ public boolean jsFunction_dispatchEvent(Scriptable evt)
+ throws EventException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+
+ public void jsFunction_removeEventListener(String type,
+ Scriptable listener, boolean useCapture) {
+ // TODO Auto-generated method stub
+
+ }
+
}
Added: trunk/httpunit/src/com/meterware/httpunit/javascript/events/Event.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/javascript/events/Event.java (rev 0)
+++ trunk/httpunit/src/com/meterware/httpunit/javascript/events/Event.java 2009-08-21 17:54:02 UTC (rev 1055)
@@ -0,0 +1,190 @@
+/********************************************************************************************************************
+ * $Id: FormScriptingTest.java 1031 2009-08-17 12:15:24Z wolfgang_fahl $
+ * $URL: https://httpunit.svn.sourceforge.net/svnroot/httpunit/trunk/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java $
+ *
+ * Copyright (c) 2005, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.,
+ * Copyright (c) 2009, Wolfgang Fahl
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
+ * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+ * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ *******************************************************************************************************************/
+package com.meterware.httpunit.javascript.events;
+
+import org.mozilla.javascript.ScriptableObject;
+
+/**
+ * @author <a href="mailto:ra...@ca...">Rafal Krzewski</a>
+ * @version $Id$
+ */
+public abstract class Event
+ extends ScriptableObject
+{
+ // -- Scriptable interface ------------------------------------------------------------------
+
+ /** JavaScript class name. */
+ private static final String JS_CLASS_NAME = "Event";
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getClassName()
+ {
+ return JS_CLASS_NAME;
+ }
+
+ // -- DOM2 Events specification -------------------------------------------------------------
+
+ /**
+ * The current event phase is the capturing phase.
+ */
+ public static final short CAPTURING_PHASE = 1;
+
+ /**
+ * The event is currently being evaluated at the target EventTarget.
+ */
+ public static final short AT_TARGET = 2;
+
+ /**
+ * The current event phase is the bubbling phase.
+ */
+ public static final short BUBBLING_PHASE = 3;
+
+ /**
+ * The name of the event (case-insensitive). The name must be an XML name.
+ */
+ private String type;
+
+ /**
+ * Used to indicate whether or not an event is a bubbling event. If the event can bubble the
+ * value is true, else the value is false.
+ */
+ private boolean bubbles;
+
+ /**
+ * Used to indicate whether or not an event can have its default action prevented. If the
+ * default action can be prevented the value is true, else the value is false.
+ */
+ private boolean cancelable;
+
+ /**
+ * Used to specify the time (in milliseconds relative to the epoch) at which the event was
+ * created. Due to the fact that some systems may not provide this information the value of
+ * timeStamp may be not available for all events. When not available, a value of 0 will be
+ * returned. Examples of epoch time are the time of the system start or 0:0:0 UTC 1st January
+ * 1970.
+ */
+ private long timeStamp;
+
+ /**
+ * The name of the event (case-insensitive). The name must be an XML name.
+ */
+ public String jsGet_type()
+ {
+ return type;
+ }
+
+ /**
+ * Used to indicate whether or not an event is a bubbling event. If the event can bubble the
+ * value is true, else the value is false.
+ */
+ public boolean jsGet_bubbles()
+ {
+ return bubbles;
+ }
+
+ /**
+ * Used to specify the time (in milliseconds relative to the epoch) at which the event was
+ * created. Due to the fact that some systems may not provide this information the value of
+ * timeStamp may be not available for all events. When not available, a value of 0 will be
+ * returned. Examples of epoch time are the time of the system start or 0:0:0 UTC 1st January
+ * 1970.
+ */
+ public boolean jsGet_cancelable()
+ {
+ return cancelable;
+ }
+
+ /**
+ * Used to specify the time (in milliseconds relative to the epoch) at which the event was
+ * created. Due to the fact that some systems may not provide this information the value of
+ * timeStamp may be not available for all events. When not available, a value of 0 will be
+ * returned. Examples of epoch time are the time of the system start or 0:0:0 UTC 1st January
+ * 1970.
+ */
+ public long jsGet_timeStamp()
+ {
+ return timeStamp;
+ }
+
+ /**
+ * Used to indicate the EventTarget to which the event was originally dispatched.
+ */
+ public abstract EventTarget jsGet_target();
+
+ /**
+ * Used to indicate the EventTarget whose EventListeners are currently being processed. This is
+ * particularly useful during capturing and bubbling.
+ */
+ public abstract EventTarget jsGet_currentTarget();
+
+ /**
+ * Used to indicate which phase of event flow is currently being evaluated.
+ */
+ public abstract short jsGet_eventPhase();
+
+ /**
+ * The stopPropagation method is used prevent further propagation of an event during event flow.
+ * If this method is called by any EventListener the event will cease propagating through the
+ * tree. The event will complete dispatch to all listeners on the current EventTarget before
+ * event flow stops. This method may be used during any stage of event flow.
+ */
+ public abstract void jsFunction_stopPropagation();
+
+ /**
+ * If an event is cancelable, the preventDefault method is used to signify that the event is to
+ * be canceled, meaning any default action normally taken by the implementation as a result of
+ * the event will not occur. If, during any stage of event flow, the preventDefault method is
+ * called the event is canceled. Any default action associated with the event will not occur.
+ * Calling this method for a non-cancelable event has no effect. Once preventDefault has been
+ * called it will remain in effect throughout the remainder of the event's propagation. This
+ * method may be used during any stage of event flow.
+ */
+ public abstract void jsFunction_preventDefault();
+
+ /**
+ * The initEvent method is used to initialize the value of an Event created through the
+ * DocumentEvent interface. This method may only be called before the Event has been dispatched
+ * via the dispatchEvent method, though it may be called multiple times during that phase if
+ * necessary. If called multiple times the final invocation takes precedence. If called from a
+ * subclass of Event interface only the values specified in the initEvent method are modified,
+ * all other attributes are left unchanged.
+ *
+ * @param eventTypeArg Specifies the event type. This type may be any event type currently
+ * defined in this specification or a new event type.. The string must be an XML name.
+ * Any new event type must not begin with any upper, lower, or mixed case version of the
+ * string "DOM". This prefix is reserved for future DOM event sets. It is also strongly
+ * recommended that third parties adding their own events use their own prefix to avoid
+ * confusion and lessen the probability of conflicts with other new events.
+ * @param canBubbleArg Specifies whether or not the event can bubble.
+ * @param cancelableArg Specifies whether or not the event's default action can be prevented.
+ */
+ public void jsFunction_initEvent(String eventTypeArg, boolean canBubbleArg,
+ boolean cancelableArg)
+ {
+ type = eventTypeArg;
+ bubbles = canBubbleArg;
+ cancelable = cancelableArg;
+ }
+}
Added: trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventException.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventException.java (rev 0)
+++ trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventException.java 2009-08-21 17:54:02 UTC (rev 1055)
@@ -0,0 +1,68 @@
+/********************************************************************************************************************
+ * $Id: FormScriptingTest.java 1031 2009-08-17 12:15:24Z wolfgang_fahl $
+ * $URL: https://httpunit.svn.sourceforge.net/svnroot/httpunit/trunk/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java $
+ *
+ * Copyright (c) 2005, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.,
+ * Copyright (c) 2009, Wolfgang Fahl
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
+ * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+ * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ *******************************************************************************************************************/
+package com.meterware.httpunit.javascript.events;
+
+/**
+ * Event operations may throw an EventException as specified in their method descriptions.
+ *
+ * @author <a href="mailto:ra...@ca...">Rafal Krzewski</a>
+ * @version $Id$
+ */
+public class EventException
+ extends Exception
+{
+ /**
+ * If the Event's type was not specified by initializing the event before the method was called.
+ * Specification of the Event's type as null or an empty string will also trigger this
+ * exception.
+ */
+ private static final short UNSPECIFIED_EVENT_TYPE_ERR = 0;
+
+ /**
+ * An integer indicating the type of error generated.
+ */
+ private final short code;
+
+ /**
+ * Creates new EventException instance.
+ *
+ * @param codeArg An integer indicating the type of error generated.
+ */
+ public EventException(short codeArg) {
+ this.code = codeArg;
+ }
+
+ /**
+ * An integer indicating the type of error generated.
+ */
+ public short getCode() {
+ return code;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getMessage() {
+ return Short.toString(code);
+ }
+}
Added: trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventListener.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventListener.java (rev 0)
+++ trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventListener.java 2009-08-21 17:54:02 UTC (rev 1055)
@@ -0,0 +1,50 @@
+/********************************************************************************************************************
+ * $Id: FormScriptingTest.java 1031 2009-08-17 12:15:24Z wolfgang_fahl $
+ * $URL: https://httpunit.svn.sourceforge.net/svnroot/httpunit/trunk/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java $
+ *
+ * Copyright (c) 2005, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.,
+ * Copyright (c) 2009, Wolfgang Fahl
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
+ * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+ * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ *******************************************************************************************************************/
+package com.meterware.httpunit.javascript.events;
+
+import org.mozilla.javascript.Scriptable;
+
+/**
+ * The EventListener interface is the primary method for handling events. Users implement the
+ * EventListener interface and register their listener on an EventTarget using the AddEventListener
+ * method. The users should also remove their EventListener from its EventTarget after they have
+ * completed using the listener. When a Node is copied using the cloneNode method the EventListeners
+ * attached to the source Node are not attached to the copied Node. If the user wishes the same
+ * EventListeners to be added to the newly created copy the user must add them manually.
+ *
+ * @author <a href="mailto:ra...@ca...">Rafal Krzewski</a>
+ * @version $Id$
+ */
+public interface EventListener
+ extends Scriptable
+{
+ /**
+ * This method is called whenever an event occurs of the type for which the EventListener
+ * interface was registered.
+ *
+ * @param evt The Event contains contextual information about the event. It also contains the
+ * stopPropagation and preventDefault methods which are used in determining the event's
+ * flow and default action.
+ */
+ public void jsFunction_handleEvent(Scriptable evt);
+}
Added: trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventTarget.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventTarget.java (rev 0)
+++ trunk/httpunit/src/com/meterware/httpunit/javascript/events/EventTarget.java 2009-08-21 17:54:02 UTC (rev 1055)
@@ -0,0 +1,91 @@
+/********************************************************************************************************************
+ * $Id: FormScriptingTest.java 1031 2009-08-17 12:15:24Z wolfgang_fahl $
+ * $URL: https://httpunit.svn.sourceforge.net/svnroot/httpunit/trunk/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java $
+ *
+ * Copyright (c) 2005, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.,
+ * Copyright (c) 2009, Wolfgang Fahl
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
+ * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+ * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ *******************************************************************************************************************/
+package com.meterware.httpunit.javascript.events;
+
+import org.mozilla.javascript.Scriptable;
+
+/**
+ * The EventTarget interface is implemented by all Nodes in an implementation which supports the DOM
+ * Event Model. Therefore, this interface can be obtained by using binding-specific casting methods
+ * on an instance of the Node interface. The interface allows registration and removal of
+ * EventListeners on an EventTarget and dispatch of events to that EventTarget.
+ *
+ * @author W3C
+ * @version $Id$
+ */
+public interface EventTarget
+ extends Scriptable
+{
+ /**
+ * This method allows the registration of event listeners on the event target. If an
+ * EventListener is added to an EventTarget while it is processing an event, it will not be
+ * triggered by the current actions but may be triggered during a later stage of event flow,
+ * such as the bubbling phase. If multiple identical EventListeners are registered on the same
+ * EventTarget with the same parameters the duplicate instances are discarded. They do not cause
+ * the EventListener to be called twice and since they are discarded they do not need to be
+ * removed with the removeEventListener method.
+ *
+ * @param type The event type for which the user is registering.
+ * @param listener The listener parameter takes an interface implemented by the user which
+ * contains the methods to be called when the event occurs.
+ * @param useCapture If true, useCapture indicates that the user wishes to initiate capture.
+ * After initiating capture, all events of the specified type will be dispatched to the
+ * registered EventListener before being dispatched to any EventTargets beneath them in
+ * the tree. Events which are bubbling upward through the tree will not trigger an
+ * EventListener designated to use capture.
+ */
+ public void jsFunction_addEventListener(String type, Scriptable listener, boolean useCapture);
+
+ /**
+ * This method allows the removal of event listeners from the event target. If an EventListener
+ * is removed from an EventTarget while it is processing an event, it will not be triggered by
+ * the current actions. EventListeners can never be invoked after being removed. Calling
+ * removeEventListener with arguments which do not identify any currently registered
+ * EventListener on the EventTarget has no effect.
+ *
+ * @param type Specifies the event type of the EventListener being removed.
+ * @param listener The EventListener parameter indicates the EventListener to be removed.
+ * @param useCapture Specifies whether the EventListener being removed was registered as a
+ * capturing listener or not. If a listener was registered twice, one with capture and
+ * one without, each must be removed separately. Removal of a capturing listener does not
+ * affect a non-capturing version of the same listener, and vice versa.
+ */
+ public void jsFunction_removeEventListener(String type, Scriptable listener, boolean useCapture);
+
+ /**
+ * This method allows the dispatch of events into the implementations event model. Events
+ * dispatched in this manner will have the same capturing and bubbling behavior as events
+ * dispatched directly by the implementation. The target of the event is the EventTarget on
+ * which dispatchEvent is called.
+ *
+ * @param evt Specifies the event type, behavior, and contextual information to be used in
+ * processing the event.
+ * @return The return value of dispatchEvent indicates whether any of the listeners which
+ * handled the event called preventDefault. If preventDefault was called the value is
+ * false, else the value is true.
+ * @throws EventException UNSPECIFIED_EVENT_TYPE_ERR: Raised if the Event's type was not
+ * specified by initializing the event before dispatchEvent was called. Specification of
+ * the Event's type as null or an empty string will also trigger this exception.
+ */
+ public boolean jsFunction_dispatchEvent(Scriptable evt) throws EventException;
+}
Modified: trunk/httpunit/test/com/meterware/httpunit/javascript/JavaScriptTestSuite.java
===================================================================
--- trunk/httpunit/test/com/meterware/httpunit/javascript/JavaScriptTestSuite.java 2009-08-21 14:00:15 UTC (rev 1054)
+++ trunk/httpunit/test/com/meterware/httpunit/javascript/JavaScriptTestSuite.java 2009-08-21 17:54:02 UTC (rev 1055)
@@ -50,6 +50,7 @@
result.addTest( FormScriptingTest.suite() );
result.addTest( FrameScriptingTest.suite() );
result.addTest( HTMLElementTest.suite() );
+ result.addTest( EventHandlingTest.suite());
return result;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2009-08-21 14:00:23
|
Revision: 1054
http://httpunit.svn.sourceforge.net/httpunit/?rev=1054&view=rev
Author: wolfgang_fahl
Date: 2009-08-21 14:00:15 +0000 (Fri, 21 Aug 2009)
Log Message:
-----------
fixed examples (e.g. for changed behaviour of target web sites)
Modified Paths:
--------------
trunk/httpunit/examples/Example.java
trunk/httpunit/examples/GoogleMapsExample.java
trunk/httpunit/examples/NearWords.java
trunk/httpunit/examples/ProxySample.java
Modified: trunk/httpunit/examples/Example.java
===================================================================
--- trunk/httpunit/examples/Example.java 2009-08-21 12:41:31 UTC (rev 1053)
+++ trunk/httpunit/examples/Example.java 2009-08-21 14:00:15 UTC (rev 1054)
@@ -5,6 +5,10 @@
public class Example {
+ /**
+ * starting point of this Example
+ * @param params
+ */
public static void main( String[] params ) {
try {
// create the conversation object which will maintain state for us
@@ -24,6 +28,7 @@
} catch (Exception e) {
System.err.println( "Exception: " + e );
+ e.printStackTrace();
}
}
}
Modified: trunk/httpunit/examples/GoogleMapsExample.java
===================================================================
--- trunk/httpunit/examples/GoogleMapsExample.java 2009-08-21 12:41:31 UTC (rev 1053)
+++ trunk/httpunit/examples/GoogleMapsExample.java 2009-08-21 14:00:15 UTC (rev 1054)
@@ -38,271 +38,313 @@
import org.xml.sax.InputSource;
import com.meterware.httpunit.*;
+
/**
- * get a Route from Google Maps and convert it as a GPX file
- * useable by Garmin tracking devices - can be imported in MapSource software then ...
- *
+ * get a Route from Google Maps and convert it as a GPX file useable by Garmin
+ * tracking devices - can be imported in MapSource software then ...
+ *
*/
public class GoogleMapsExample {
-
+
/**
- * shall we show debug information?
+ * shall we show debug information?
*/
- private boolean DEBUG=true;
-
+ private boolean DEBUG = true;
+
/**
* get a Route description as a Garmin compatible GPX file
+ *
* @param startPoint
* @param destPoint
*/
- public void getRouteAsGPX(String startPoint,String destPoint, String filename,boolean withDisplay) throws Exception {
- String kml=getRouteFromGoogleMaps(startPoint,destPoint,withDisplay,false);
+ public void getRouteAsGPX(String startPoint, String destPoint,
+ String filename, boolean withDisplay) throws Exception {
+ String kml = getRouteFromGoogleMaps(startPoint, destPoint, withDisplay,
+ false);
if (DEBUG) {
System.out.println(kml);
}
// http://wiki.openstreetmap.org/index.php/JOSM
// here is a so called open source kml to gpx converter
// http://www.fish-track.com/?page_id=3
- Document gpxdoc=convertKMLtoGPX(kml);
+ Document gpxdoc = convertKMLtoGPX(kml);
// output the result
- xmlSerialize(gpxdoc,filename);
+ xmlSerialize(gpxdoc, filename);
}
-
+
/**
- * create the xml output for the given document
+ * create the xml output for the given document
+ *
* @param document
* @param filename
* @throws Exception
*/
- public void xmlSerialize(Document document,String filename) throws Exception {
- OutputFormat outputOptions = new OutputFormat();
- // outputOptions.setOmitXMLDeclaration(true);
- outputOptions.setIndent( 4 );
- outputOptions.setMethod( "xml" );
- //if (System.getProperty("os.name").startsWith("Windows")) {
- outputOptions.setEncoding("ISO-8859-1");
- Writer writer = new BufferedWriter(new FileWriter(new File(filename)));
- DOMSerializer serializer = new XMLSerializer( writer,outputOptions );
- serializer.serialize( document );
- writer.close();
- }
+ public void xmlSerialize(Document document, String filename)
+ throws Exception {
+ OutputFormat outputOptions = new OutputFormat();
+ // outputOptions.setOmitXMLDeclaration(true);
+ outputOptions.setIndent(4);
+ outputOptions.setMethod("xml");
+ // if (System.getProperty("os.name").startsWith("Windows")) {
+ outputOptions.setEncoding("ISO-8859-1");
+ Writer writer = new BufferedWriter(new FileWriter(new File(filename)));
+ DOMSerializer serializer = new XMLSerializer(writer, outputOptions);
+ serializer.serialize(document);
+ writer.close();
+ }
/**
* get the subnode with the given tagname
+ *
* @param parent
* @param tagName
* @return
*/
- public Element getSubNode(Element parent,String tagName, boolean throwException) {
- NodeList subNodes=parent.getElementsByTagName(tagName);
- if (subNodes.getLength()!=1) {
- if (throwException)
- throw new RuntimeException("getSubNode failed for "+parent+" expected 1 child with tag name '"+tagName+"' but got "+subNodes.getLength());
- else
- return null;
- }
- return (Element)subNodes.item(0);
+ public Element getSubNode(Element parent, String tagName,
+ boolean throwException) {
+ NodeList subNodes = parent.getElementsByTagName(tagName);
+ if (subNodes.getLength() != 1) {
+ if (throwException)
+ throw new RuntimeException("getSubNode failed for " + parent
+ + " expected 1 child with tag name '" + tagName
+ + "' but got " + subNodes.getLength());
+ else
+ return null;
+ }
+ return (Element) subNodes.item(0);
}
-
+
/**
* get the latitude and longitude from a route point
+ *
* @param kmlRoutePoint
* @return
*/
public String[] extractCoordinates(Element kmlRoutePoint) {
- String[] result=new String[2];
- Element point=getSubNode(kmlRoutePoint,"Point",false);
- if (point==null)
+ String[] result = new String[2];
+ Element point = getSubNode(kmlRoutePoint, "Point", false);
+ if (point == null)
return null;
- Element coordNode=getSubNode(point,"coordinates",true);
- String coords=coordNode.getTextContent();
- StringTokenizer coordSplitter=new StringTokenizer(coords,",",false);
- if (coordSplitter.countTokens()<=2) {
- throw new RuntimeException("extract coordinates failed for "+kmlRoutePoint+" expected at least two coordinates but got "+coordSplitter.countTokens()+" '"+coords+"'");
+ Element coordNode = getSubNode(point, "coordinates", true);
+ String coords = coordNode.getTextContent();
+ StringTokenizer coordSplitter = new StringTokenizer(coords, ",", false);
+ if (coordSplitter.countTokens() <= 2) {
+ throw new RuntimeException("extract coordinates failed for "
+ + kmlRoutePoint
+ + " expected at least two coordinates but got "
+ + coordSplitter.countTokens() + " '" + coords + "'");
}
- result[0]=coordSplitter.nextToken();
- result[1]=coordSplitter.nextToken();
+ result[0] = coordSplitter.nextToken();
+ result[1] = coordSplitter.nextToken();
return result;
}
-
+
/**
* convert the given kml file to gpx format
- * @param kml - the kml version of the file
+ *
+ * @param kml
+ * - the kml version of the file
* @return
*/
public Document convertKMLtoGPX(String kml) throws Exception {
- DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance();
- DocumentBuilder builder= factory.newDocumentBuilder();
- Document kmldoc = builder.parse(new InputSource(new StringReader(kml)) );
- Document gpxdoc = builder.newDocument();
- String comment="Converted by httpunit GoogleMapsExample";
- gpxdoc.appendChild(gpxdoc.createComment(comment));
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document kmldoc = builder.parse(new InputSource(new StringReader(kml)));
+ Document gpxdoc = builder.newDocument();
+ String comment = "Converted by httpunit GoogleMapsExample";
+ gpxdoc.appendChild(gpxdoc.createComment(comment));
- org.w3c.dom.Element root = gpxdoc.createElement("gpx");
- root.setAttribute("xmlns", "http://www.topografix.com/GPX/1/1");
- root.setAttribute("creator","KML2GPX Example by BITPlan");
- root.setAttribute("version","1.1");
- gpxdoc.appendChild(root);
-
- org.w3c.dom.Element metadata = gpxdoc.createElement("metadata");
- org.w3c.dom.Element metadatalink = gpxdoc.createElement("link");
- metadatalink.setAttribute("href","http://www.bitplan.com");
- metadata.appendChild(metadatalink);
- org.w3c.dom.Element metadatatext = gpxdoc.createElement("text");
- metadatatext.setTextContent("BITPlan GmbH, Willich, Germany");
- metadatalink.appendChild(metadatatext);
- root.appendChild(metadata);
-
- org.w3c.dom.Element route = gpxdoc.createElement("rte");
- root.appendChild(route);
- NodeList routePoints=kmldoc.getElementsByTagName("Placemark");
- for (int i=0;i<routePoints.getLength();i++) {
- Element kmlRoutePoint=(Element)routePoints.item(i);
- String name=getSubNode(kmlRoutePoint,"name",true).getTextContent();
- if (DEBUG)
- System.out.println("found route point "+i+": "+name);
-
- String coords[]=extractCoordinates(kmlRoutePoint);
- if (coords!=null) {
- org.w3c.dom.Element routePoint = gpxdoc.createElement("rtept");
- routePoint.setAttribute("lon", coords[0] );
- routePoint.setAttribute("lat", coords[1] );
- org.w3c.dom.Element routePointName=gpxdoc.createElement("name");
- routePointName.setTextContent(name);
- routePoint.appendChild(routePointName);
- route.appendChild(routePoint);
- }
- }
- return gpxdoc;
+ org.w3c.dom.Element root = gpxdoc.createElement("gpx");
+ root.setAttribute("xmlns", "http://www.topografix.com/GPX/1/1");
+ root.setAttribute("creator", "KML2GPX Example by BITPlan");
+ root.setAttribute("version", "1.1");
+ gpxdoc.appendChild(root);
+
+ org.w3c.dom.Element metadata = gpxdoc.createElement("metadata");
+ org.w3c.dom.Element metadatalink = gpxdoc.createElement("link");
+ metadatalink.setAttribute("href", "http://www.bitplan.com");
+ metadata.appendChild(metadatalink);
+ org.w3c.dom.Element metadatatext = gpxdoc.createElement("text");
+ metadatatext.setTextContent("BITPlan GmbH, Willich, Germany");
+ metadatalink.appendChild(metadatatext);
+ root.appendChild(metadata);
+
+ org.w3c.dom.Element route = gpxdoc.createElement("rte");
+ root.appendChild(route);
+ NodeList routePoints = kmldoc.getElementsByTagName("Placemark");
+ for (int i = 0; i < routePoints.getLength(); i++) {
+ Element kmlRoutePoint = (Element) routePoints.item(i);
+ String name = getSubNode(kmlRoutePoint, "name", true)
+ .getTextContent();
+ if (DEBUG)
+ System.out.println("found route point " + i + ": " + name);
+
+ String coords[] = extractCoordinates(kmlRoutePoint);
+ if (coords != null) {
+ org.w3c.dom.Element routePoint = gpxdoc.createElement("rtept");
+ routePoint.setAttribute("lon", coords[0]);
+ routePoint.setAttribute("lat", coords[1]);
+ org.w3c.dom.Element routePointName = gpxdoc
+ .createElement("name");
+ routePointName.setTextContent(name);
+ routePoint.appendChild(routePointName);
+ route.appendChild(routePoint);
+ }
+ }
+ return gpxdoc;
}
+
/**
* the url to use
*/
- public static String url="http://maps.google.com/maps";
- /**
- * the directions string to look for
- */
- public static String directions="directions";
-
- /**
- This is how to use the example in germany:
-
- GoogleMapsExample.url="http://maps.google.de/maps";
- GoogleMapsExample.directions="Route berechnen";
- */
+ public static String url = "http://maps.google.com/maps";
+ /**
+ * the directions string to look for
+ */
+ public static String directions = "directions";
-
/**
* get a route from google maps with the given start and destination points
+ *
* @param startPoint
* @param destPoint
* @param withDisplay
* @param asKML
*/
- public String getRouteFromGoogleMaps(String startPoint,String destPoint, boolean withDisplay, boolean asKML) throws Exception {
- // and now indirectly
- // create the conversation object which will maintain state for us
- WebConversation wc = new WebConversation();
+ public String getRouteFromGoogleMaps(String startPoint, String destPoint,
+ boolean withDisplay, boolean asKML) throws Exception {
+ // and now indirectly
+ // create the conversation object which will maintain state for us
+ WebConversation wc = new WebConversation();
- // Obtain the main page on the google maps web site
- WebRequest request = new GetMethodWebRequest(url);
- request.setParameter("output", "html");
- WebResponse response = wc.getResponse( request );
- if (withDisplay && DEBUG)
- BrowserDisplayer.showResponseInBrowser(response);
-
- // find the link which contains the string for directions and click it
- WebLink directionsLink = response.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, directions);
- if (directionsLink==null) {
- System.err.println("could not find "+directions+" in response");
- if (DEBUG)
- BrowserDisplayer.showResponseInBrowser(response);
- System.exit(1);
- }
- response = directionsLink.click();
- if (withDisplay && DEBUG)
- BrowserDisplayer.showResponseInBrowser(response);
- WebForm lookupForm = response.getFormWithID("d_form");
- request = lookupForm.getRequest();
- request.setParameter( "saddr", startPoint );
- request.setParameter( "daddr", destPoint );
- response = wc.getResponse( request );
- if (withDisplay)
- BrowserDisplayer.showResponseInBrowser(response);
- if (asKML) {
- // request.setParameter("output", "kml");
- FormParameter parameter = lookupForm.getParameter( "output" );
- FormControl outputControl=parameter.getControl();
- outputControl.setAttribute("value", "kml");
- response = wc.getResponse( request );
- if (withDisplay && DEBUG)
- BrowserDisplayer.showResponseInBrowser(response);
- }
- return (response.getText());
+ // Obtain the main page on the google maps web site
+ WebRequest request = new GetMethodWebRequest(url);
+ request.setParameter("output", "html");
+ WebResponse response = wc.getResponse(request);
+ if (withDisplay && DEBUG)
+ BrowserDisplayer.showResponseInBrowser(response);
+
+ // find the link which contains the string for directions and click it
+ WebLink directionsLink = response.getFirstMatchingLink(
+ WebLink.MATCH_CONTAINED_TEXT, directions);
+ if (directionsLink == null) {
+ System.err.println("could not find " + directions + " in response");
+ if (DEBUG)
+ BrowserDisplayer.showResponseInBrowser(response);
+ System.exit(1);
+ }
+ response = directionsLink.click();
+ if (withDisplay && DEBUG)
+ BrowserDisplayer.showResponseInBrowser(response);
+ WebForm lookupForm = response.getFormWithID("q_form");
+ if (lookupForm == null) {
+ throw new Exception(
+ "GoogleMaps lookupForm at "
+ + request.toString()
+ + "\n has changed - please notify the author if this example via the httpunit-develop mailing list");
+ }
+ request = lookupForm.getRequest();
+ request.setParameter("saddr", startPoint);
+ request.setParameter("daddr", destPoint);
+ response = wc.getResponse(request);
+ if (withDisplay)
+ BrowserDisplayer.showResponseInBrowser(response);
+ if (asKML) {
+ // request.setParameter("output", "kml");
+ FormParameter parameter = lookupForm.getParameter("output");
+ FormControl outputControl = parameter.getControl();
+ outputControl.setAttribute("value", "kml");
+ response = wc.getResponse(request);
+ if (withDisplay && DEBUG)
+ BrowserDisplayer.showResponseInBrowser(response);
+ }
+ return (response.getText());
}
-
+
/**
- * get the distance between to given Zip codes
- * @param
+ * get the distance between two given locations
+ *
+ * @param
*/
- public String getDistance(String startPoint, String endPoint, boolean withDisplay) throws Exception {
- String route=getRouteFromGoogleMaps(startPoint,endPoint,withDisplay,false);
- String [] driveLocale={"Drive:","Fahrt:"};
- String [] unitLocale ={"mi","km"};
- for (int i=0;i<driveLocale.length;i++) {
- int drivePos=route.indexOf(driveLocale[i]);
- if (drivePos>0) {
- String driveString=route.substring(drivePos);
- int unitPos=driveString.indexOf(unitLocale[i]);
- if (unitPos>0) {
- String distanceString=driveString.substring(1, unitPos+unitLocale[i].length());
+ public String getDistance(String startPoint, String endPoint,
+ boolean withDisplay) throws Exception {
+ String route = getRouteFromGoogleMaps(startPoint, endPoint,
+ withDisplay, false);
+ String[] driveLocale = { "Driving directions", "Route" };
+ String[] unitLocale = { "mi", "km" };
+ for (int i = 0; i < driveLocale.length; i++) {
+ int drivePos = route.indexOf(driveLocale[i]);
+ if (drivePos > 0) {
+ String driveString = route.substring(drivePos);
+ int unitPos = driveString.indexOf(unitLocale[i]);
+ if (unitPos > 0) {
+ String distanceString = driveString.substring(1, unitPos
+ + unitLocale[i].length());
int divPos;
- while ((divPos=distanceString.indexOf("<div>"))>0) {
- distanceString=distanceString.substring(divPos+5);
+ while ((divPos = distanceString.indexOf("<div>")) > 0) {
+ distanceString = distanceString.substring(divPos + 5);
}
- distanceString=distanceString.replace(" "," ");
+ distanceString = distanceString.replace(" ", " ");
+ distanceString = distanceString.replace("<b>", "");
return distanceString;
}
}
- }
+ }
return "?";
}
-
- /**
- * Start the Route as GPX converter with the given command line parameters
- * display usage with and example if no parameters are given
- * @param params
- */
- public static void main( String[] params ) {
- try {
- if (params.length < 3) {
- System.out.println( "Usage: java RouteAsGPX [from] [to] ([filename]|'distance') [nodisplay]" );
- System.out.println( " e.g. java RouteAsGPX sfo 94526 sfoexample.gpx");
- System.out.println( " to get the route as a Garmin compatible GPX file");
- System.out.println( " e.g. java RouteAsGPX sfo 94526 distance");
- System.out.println( " to calculate the distance");
- String[] defaultParams={"sfo","94526","distance"};
- // defaultParams={"sfo","94526","sfoexample.gpx"};
- params=defaultParams;
- System.out.println( "will demonstrate usage with the route "+defaultParams[0]+" - "+defaultParams[1]+" and store to "+defaultParams[2]);
- }
- GoogleMapsExample routeAsGPX=new GoogleMapsExample();
- boolean withDisplay=true;
- if (params.length>=4)
- withDisplay=false;
- String startPoint=params[0];
- String endPoint =params[1];
- String filename =params[2];
- if (filename.equals("distance")) {
- String distanceS=routeAsGPX.getDistance(startPoint, endPoint, withDisplay);
- // String distanceS=NumberFormat.getInstance().format(distance);
- System.out.println("The distance between "+startPoint+" and "+endPoint+" is "+distanceS);
- } else {
- routeAsGPX.getRouteAsGPX(startPoint, endPoint, filename,withDisplay);
- }
- } catch (Exception e) {
- System.err.println( "Exception: " + e );
- e.printStackTrace();
- }
- }
+
+ /**
+ * Start the Route as GPX converter with the given command line parameters
+ * display usage with and example if no parameters are given
+ *
+ * @param params
+ */
+ public static void main(String[] params) {
+ try {
+ if (params.length < 3) {
+ System.out
+ .println("Usage: java RouteAsGPX [from] [to] ([filename]|'distance') [nodisplay]");
+ System.out
+ .println(" e.g. java RouteAsGPX sfo CA-94526 sfoexample.gpx");
+ System.out
+ .println(" to get the route as a Garmin compatible GPX file");
+ System.out
+ .println(" e.g. java RouteAsGPX sfo CA-94526 distance");
+ System.out.println(" to calculate the distance");
+ String[] defaultParams = { "sfo", "CA-94526", "distance" };
+ // defaultParams={"sfo","CA-94526","sfoexample.gpx"};
+ params = defaultParams;
+ System.out.println("will demonstrate usage with the route "
+ + defaultParams[0] + " - " + defaultParams[1]
+ + " and store to " + defaultParams[2]);
+ }
+ /**
+ * This is how to use the example in germany:
+ * GoogleMapsExample.url="http://maps.google.de/maps";
+ * GoogleMapsExample.directions="Route berechnen";
+ */
+ GoogleMapsExample routeAsGPX = new GoogleMapsExample();
+ HttpUnitOptions.setScriptingEnabled(false);
+
+ boolean withDisplay = true;
+ if (params.length >= 4)
+ withDisplay = false;
+ String startPoint = params[0];
+ String endPoint = params[1];
+ String filename = params[2];
+ if (filename.equals("distance")) {
+ String distanceS = routeAsGPX.getDistance(startPoint, endPoint,
+ withDisplay);
+ // String distanceS=NumberFormat.getInstance().format(distance);
+ System.out.println("The distance between " + startPoint
+ + " and " + endPoint + " is " + distanceS);
+ } else {
+ routeAsGPX.getRouteAsGPX(startPoint, endPoint, filename,
+ withDisplay);
+ }
+ } catch (Exception e) {
+ System.err.println("Exception: " + e);
+ e.printStackTrace();
+ }
+ }
}
Modified: trunk/httpunit/examples/NearWords.java
===================================================================
--- trunk/httpunit/examples/NearWords.java 2009-08-21 12:41:31 UTC (rev 1053)
+++ trunk/httpunit/examples/NearWords.java 2009-08-21 14:00:15 UTC (rev 1054)
@@ -1,95 +1,116 @@
import com.meterware.httpunit.*;
+
import java.io.*;
+import java.util.ArrayList;
+
import org.w3c.dom.*;
import org.xml.sax.SAXException;
/**
- * This class demonstrates using httpunit to use the functionality of a web set from a command
- * line. To use it, specify a single word with one or more characters replaced by '?'. The
- * program will use the Merriam-Webster web site to find all words which match the pattern.
- *
- * Note: this program is not robust, but should work is used properly.
+ * This class demonstrates using httpunit to use the functionality of a web set
+ * from a command line. To use it, specify a single word to be searched.
+ * The program will use the Wiktionary web site to find all links which match the pattern.
+ *
+ * Note: this program is not robust, but should work if used properly.
**/
public class NearWords {
+ /***
+ * start a search for the given word
+ * @param params
+ */
+ public static void main(String[] params) {
+ try {
+ if (params.length < 1) {
+ System.out.println("Usage: java NearWords [pattern]");
+ System.out
+ .println("will demonstrate usage with the pattern 'test' now ...");
+ String[] defaultParams = { "test" };
+ params = defaultParams;
+ }
+ WordSeeker seeker = new WordSeeker();
- public static void main( String[] params ) {
- try {
- if (params.length < 1) {
- System.out.println( "Usage: java NearWords [pattern]" );
- System.out.println( "where [pattern] may contain '?' to match any character" );
- System.out.println( "");
- System.out.println( "will demonstrate usage with the pattern 'test' now ...");
- String[] defaultParams={"test"};
- params=defaultParams;
- }
- WordSeeker seeker = new WordSeeker();
-
- PrintStream err = new PrintStream( new FileOutputStream( "null.txt" ) );
- System.setErr( err );
+ String[] words = seeker.getWordsMatching(params[0]);
+ for (int i = 0; i < words.length; i++) {
+ System.out.println((i + 1) + ". " + words[i]);
+ }
+ } catch (Exception e) {
+ System.err.println("Exception: " + e);
+ e.printStackTrace();
+ }
+ }
- String[] words = seeker.getWordsMatching( params[0] );
- for (int i=0; i < words.length; i++) {
- System.out.println( (i+1) + ". " + words[i] );
- }
- } catch (Exception e) {
- System.err.println( "Exception: " + e );
- }
- }
-
}
/**
- * subclass to seek words from the Merriam-Webster Online search
- * as of 2008-05-02
- *
+ * subclass to seek words from the Wiktionary as of 2009-08-21
+ *
*/
class WordSeeker {
- public WordSeeker() {
- try {
- HttpUnitOptions.setScriptingEnabled(false);
- String url="http://www.m-w.com/";
- System.out.println("visiting "+url);
- WebRequest request = new GetMethodWebRequest( url );
- response = conversation.getResponse( request );
- } catch (Exception e) {
- throw new RuntimeException( "Error retrieving form: " + e );
- }
- }
+ /**
+ * create a word seeker that visits wiktionary.org
+ */
+ public WordSeeker() {
+ try {
+ HttpUnitOptions.setScriptingEnabled(false);
+ String url = "http://simple.wiktionary.org/";
+ System.out.println("visiting " + url);
+ WebRequest request = new GetMethodWebRequest(url);
+ response = conversation.getResponse(request);
+ } catch (Exception e) {
+ throw new RuntimeException("Error retrieving form: " + e);
+ }
+ }
+ /**
+ * get word matching the given pattern
+ *
+ * @param pattern
+ * @return
+ * @throws Exception
+ */
+ public String[] getWordsMatching(String pattern) throws Exception {
+ System.out.println("getting Words matching '" + pattern + "'");
+ WebForm lookupForm = response.getFormWithID("searchform");
+ SubmitButton fulltextButton = lookupForm.getSubmitButton("fulltext");
+ System.out.println("Clicking " + fulltextButton.getName());
+ WebRequest request = lookupForm.getRequest(fulltextButton);
+ request.setParameter("search", pattern);
+ response = lookupForm.submit(fulltextButton);
+ // alternative: goButton.click();
+ return getOptionsFromResponse();
+ }
- public String[] getWordsMatching( String pattern ) throws SAXException, IOException, java.net.MalformedURLException {
- System.out.println("getting Words matching '"+pattern+"'");
- WebForm lookupForm = response.getFormWithID("search_form");
- WebRequest request = lookupForm.getRequest();
- request.setParameter( "va", pattern );
- request.setParameter( "book", "Dictionary" );
- response = conversation.getResponse( request );
- return getOptionsFromResponse();
- }
+ private WebConversation conversation = new WebConversation();
+ private WebResponse response;
- private WebConversation conversation = new WebConversation();
-
- private WebResponse response;
-
-
- private String[] getOptionsFromResponse() throws SAXException {
- String[] words;
- WebForm[] forms = response.getForms();
- for (int i=0; i < forms.length; i++) {
- Element form = (Element) forms[i].getDOMSubtree();
- NodeList nl = form.getElementsByTagName( "option" );
- if (nl.getLength() == 0) continue;
-
- words = new String[ nl.getLength() ];
- for (int j = 0; j < nl.getLength(); j++) {
- words[j] = nl.item(j).getFirstChild().getNodeValue();
- }
- return words;
- }
- return new String[0];
- }
-
+ /**
+ *
+ * @return
+ * @throws Exception
+ */
+ private String[] getOptionsFromResponse() throws Exception {
+ String[] words;
+ BrowserDisplayer.showResponseInBrowser(response);
+ WebLink[] links = response.getLinks();
+ ArrayList result=new ArrayList();
+ // start from the "Advanced" link section
+ boolean start=false;
+ for (int i = 0; i < links.length; i++) {
+ WebLink link = links[i];
+ if (link.getText().startsWith("Advanced"))
+ start=true;
+ else if (link.getText().startsWith("next 20"))
+ break;
+ else if (start && !link.getText().startsWith("(more"))
+ result.add(link);
+ }
+ words = new String[result.size()];
+ for (int i=0;i<result.size();i++) {
+ WebLink link=(WebLink) result.get(i);
+ words[i]=link.getText()+" => "+link.getURLString();
+ }
+ return words;
+ }
}
-
Modified: trunk/httpunit/examples/ProxySample.java
===================================================================
--- trunk/httpunit/examples/ProxySample.java 2009-08-21 12:41:31 UTC (rev 1053)
+++ trunk/httpunit/examples/ProxySample.java 2009-08-21 14:00:15 UTC (rev 1054)
@@ -47,6 +47,11 @@
}
+ /**
+ * test the proxy access
+ * - set the proxy server to one that you may use at your location for quicker response time
+ * @throws Exception
+ */
public void testProxyAccess() throws Exception {
WebConversation wc = new WebConversation();
wc.setProxyServer( "www-proxy.us.oracle.com", 80 );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2009-08-21 12:41:41
|
Revision: 1053
http://httpunit.svn.sourceforge.net/httpunit/?rev=1053&view=rev
Author: wolfgang_fahl
Date: 2009-08-21 12:41:31 +0000 (Fri, 21 Aug 2009)
Log Message:
-----------
add getSocketFactory convenience method as proposed by Florian Weimar
Modified Paths:
--------------
trunk/httpunit/src/com/meterware/httpunit/HttpsProtocolSupport.java
trunk/httpunit/test/com/meterware/httpunit/ssl/HttpsProtocolSupportTest.java
Modified: trunk/httpunit/src/com/meterware/httpunit/HttpsProtocolSupport.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/HttpsProtocolSupport.java 2009-08-21 12:33:21 UTC (rev 1052)
+++ trunk/httpunit/src/com/meterware/httpunit/HttpsProtocolSupport.java 2009-08-21 12:41:31 UTC (rev 1053)
@@ -22,8 +22,14 @@
*******************************************************************************************************************/
import java.security.Provider;
import java.security.Security;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.X509TrustManager;
+
/**
* Encapsulates support for the HTTPS protocol.
*
@@ -154,8 +160,36 @@
}
return false;
}
+
+ /**
+ * convenience function: create a socket factory which
+ * uses an anything-goes trust manager.
+ * proposed by Florian Weimar
+ */
+ public static SSLSocketFactory getSocketFactory() throws Exception {
+ final SSLContext context = SSLContext.getInstance("TLS");
+ context.init(null, new X509TrustManager[] {
+ new X509TrustManager() {
+ //@Override
+ public void checkClientTrusted(X509Certificate[] arg0,
+ String arg1) throws CertificateException {
+ }
+ //@Override
+ public void checkServerTrusted(X509Certificate[] arg0,
+ String arg1) throws CertificateException {
+ }
+ //@Override
+ public X509Certificate[] getAcceptedIssuers() {
+ return null;
+ }
+
+ }}, null);
+ return context.getSocketFactory();
+ }
+
+
/**
* register the Secure Socket Layer Protocol Handler
*/
Modified: trunk/httpunit/test/com/meterware/httpunit/ssl/HttpsProtocolSupportTest.java
===================================================================
--- trunk/httpunit/test/com/meterware/httpunit/ssl/HttpsProtocolSupportTest.java 2009-08-21 12:33:21 UTC (rev 1052)
+++ trunk/httpunit/test/com/meterware/httpunit/ssl/HttpsProtocolSupportTest.java 2009-08-21 12:41:31 UTC (rev 1053)
@@ -22,6 +22,8 @@
import java.security.Provider;
import java.security.Security;
+import javax.net.ssl.SSLSocketFactory;
+
import com.meterware.httpunit.HttpsProtocolSupport;
import junit.framework.Test;
@@ -77,4 +79,13 @@
expected= sslProviders[0].getClass().getName();
assertEquals( "provider",expected, provider.getName() );
}
+
+ /**
+ * test the socket Factory convenience method as proposed by Florian Weimar
+ * @throws Exception
+ */
+ public void testSocketFactory() throws Exception {
+ SSLSocketFactory factory = HttpsProtocolSupport.getSocketFactory();
+ assertTrue(factory!=null);
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2009-08-21 12:33:31
|
Revision: 1052
http://httpunit.svn.sourceforge.net/httpunit/?rev=1052&view=rev
Author: wolfgang_fahl
Date: 2009-08-21 12:33:21 +0000 (Fri, 21 Aug 2009)
Log Message:
-----------
not for release notes: comment out - System.out stuff
Modified Paths:
--------------
trunk/httpunit/test/com/meterware/httpunit/WebLinkTest.java
Modified: trunk/httpunit/test/com/meterware/httpunit/WebLinkTest.java
===================================================================
--- trunk/httpunit/test/com/meterware/httpunit/WebLinkTest.java 2009-08-21 11:08:14 UTC (rev 1051)
+++ trunk/httpunit/test/com/meterware/httpunit/WebLinkTest.java 2009-08-21 12:33:21 UTC (rev 1052)
@@ -159,10 +159,10 @@
assertTrue(elements[0] instanceof TableCell);
TableCell aCell=(TableCell)elements[0];
WebLink[] cellLinks = aCell.getLinks();
- for (int i=0;i<cellLinks.length;i++) {
+ /*for (int i=0;i<cellLinks.length;i++) {
WebLink link=cellLinks[i];
System.out.println("link "+i+"="+link.getName());
- }
+ }*/
assertEquals(1,cellLinks.length);
assertEquals("acelllink",cellLinks[0].getName());
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2009-08-21 11:08:20
|
Revision: 1051
http://httpunit.svn.sourceforge.net/httpunit/?rev=1051&view=rev
Author: wolfgang_fahl
Date: 2009-08-21 11:08:14 +0000 (Fri, 21 Aug 2009)
Log Message:
-----------
fix for BR 2534057 by Igor Kanshin
Modified Paths:
--------------
trunk/httpunit/src/com/meterware/httpunit/dom/HTMLContainerDelegate.java
trunk/httpunit/src/com/meterware/httpunit/dom/NodeImpl.java
trunk/httpunit/test/com/meterware/httpunit/WebLinkTest.java
trunk/httpunit/test/com/meterware/httpunit/dom/NodeTest.java
Modified: trunk/httpunit/src/com/meterware/httpunit/dom/HTMLContainerDelegate.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/dom/HTMLContainerDelegate.java 2009-08-21 09:43:42 UTC (rev 1050)
+++ trunk/httpunit/src/com/meterware/httpunit/dom/HTMLContainerDelegate.java 2009-08-21 11:08:14 UTC (rev 1051)
@@ -44,12 +44,12 @@
/**
* get Links for a given Node
- * @param rootNode
+ * @param rootNode - an array of forms
* @return
*/
HTMLCollection getLinks( NodeImpl rootNode ) {
ArrayList elements = new ArrayList();
- for (Iterator each = rootNode.preOrderIteratorAfterNode( _iteratorMask ); each.hasNext();) {
+ for (Iterator each = rootNode.preOrderIteratorWithinNode( _iteratorMask ); each.hasNext();) {
Node node = (Node) each.next();
if (node.getNodeType() != Node.ELEMENT_NODE) continue;
@@ -61,9 +61,14 @@
}
+ /**
+ * get forms for a given Node
+ * @param rootNode - the node to start from
+ * @return - an array of forms
+ */
HTMLCollection getForms( NodeImpl rootNode ) {
ArrayList elements = new ArrayList();
- for (Iterator each = rootNode.preOrderIteratorAfterNode( _iteratorMask ); each.hasNext();) {
+ for (Iterator each = rootNode.preOrderIteratorWithinNode( _iteratorMask ); each.hasNext();) {
Node node = (Node) each.next();
if (node.getNodeType() != Node.ELEMENT_NODE) continue;
Modified: trunk/httpunit/src/com/meterware/httpunit/dom/NodeImpl.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/dom/NodeImpl.java 2009-08-21 09:43:42 UTC (rev 1050)
+++ trunk/httpunit/src/com/meterware/httpunit/dom/NodeImpl.java 2009-08-21 11:08:14 UTC (rev 1051)
@@ -352,7 +352,23 @@
return new PreOrderIterator( PreOrderIterator.nextNode( this ) );
}
+ /**
+ *
+ * @return
+ */
+ public Iterator preOrderIteratorWithinNode() {
+ PreOrderIterator result = new PreOrderIterator( PreOrderIterator.nextNode( this ) );
+ result.setDoNotLeaveNode(this);
+ return result;
+ }
+
+ public Iterator preOrderIteratorWithinNode(IteratorMask mask) {
+ PreOrderIterator result = new PreOrderIterator( PreOrderIterator.nextNode( this ),mask );
+ result.setDoNotLeaveNode(this);
+ return result;
+ }
+
public Iterator preOrderIteratorAfterNode( IteratorMask mask ) {
return new PreOrderIterator( PreOrderIterator.nextNode( this ), mask );
}
@@ -367,36 +383,105 @@
}
+ /**
+ * allow masking of the iteration
+ */
interface IteratorMask {
+ // skip a given subtree
boolean skipSubtree( Node subtreeRoot );
}
-
+ /**
+ * iterator for Nodetrees that can be influenced with an Iterator mask to skip
+ * specific parts
+ */
static class PreOrderIterator implements Iterator {
private NodeImpl _nextNode;
+ private NodeImpl _startNode;
private IteratorMask _mask;
+ private NodeImpl _doNotLeaveNode=null;
+ /**
+ * get the limit node
+ * @return
+ */
+ public NodeImpl getDoNotLeaveNode() {
+ return _doNotLeaveNode;
+ }
+ /**
+ * limit the PreOrderIterator not to leave the given node
+ * @param doNotLeaveNode
+ */
+ public void setDoNotLeaveNode(NodeImpl doNotLeaveNode) {
+ _doNotLeaveNode = doNotLeaveNode;
+ }
+
+ /**
+ * check whether the node is a child of the doNotLeaveNode (if one is set)
+ * @param node
+ * @return
+ */
+ private boolean isChild(Node node) {
+ if (node==null) {
+ return false;
+ } if (_doNotLeaveNode==null) {
+ return true;
+ } else {
+ Node parent = node.getParentNode();
+ if (parent==null) {
+ return false;
+ } else {
+ if (parent.isSameNode(_doNotLeaveNode)) {
+ return true;
+ } else {
+ return isChild(parent);
+ }
+ }
+ }
+ }
+
+ /**
+ * create a PreOrderIterator starting at a given currentNode
+ * @param currentNode
+ */
PreOrderIterator( NodeImpl currentNode ) {
_nextNode = currentNode;
+ _startNode= currentNode;
}
+ /**
+ * create a PreOrderIterator starting at a given currentNode and setting
+ * the iterator mask to the given mask
+ * @param currentNode
+ * @param mask
+ */
PreOrderIterator( NodeImpl currentNode, IteratorMask mask ) {
this( currentNode );
_mask = mask;
}
+ /**
+ * is there still a next node?
+ */
public boolean hasNext() {
return null != _nextNode;
}
+ /**
+ * move one step in the tree
+ */
public Object next() {
NodeImpl currentNode = _nextNode;
_nextNode = nextNode( _nextNode );
- while (_mask != null && _nextNode != null && _mask.skipSubtree( _nextNode )) _nextNode = nextSubtree( _nextNode );
+ while (_mask != null && _nextNode != null && _mask.skipSubtree( _nextNode ))
+ _nextNode = nextSubtree( _nextNode );
+ // check that we fit the doNotLeaveNode condition in case there is one
+ if (!isChild(_nextNode))
+ _nextNode=null;
return currentNode;
}
@@ -421,4 +506,5 @@
return null;
}
}
+
}
Modified: trunk/httpunit/test/com/meterware/httpunit/WebLinkTest.java
===================================================================
--- trunk/httpunit/test/com/meterware/httpunit/WebLinkTest.java 2009-08-21 09:43:42 UTC (rev 1050)
+++ trunk/httpunit/test/com/meterware/httpunit/WebLinkTest.java 2009-08-21 11:08:14 UTC (rev 1051)
@@ -19,6 +19,8 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
+import org.xml.sax.SAXException;
+
import junit.framework.TestSuite;
@@ -52,6 +54,7 @@
"<body>This has no forms but it does\n" +
"have <a href='/other.html#middle' id='activeID'>an <b>active</b> link</A>\n" +
" and <a name=here>an anchor</a>\n" +
+ "<table><tr><td name='acell'><a href='basic.html' name='acelllink'>a link in a cell</a></td></tr></table>"+
"<a href='basic.html' name=\"nextLink\"><IMG SRC=\"/images/arrow.gif\" ALT=\"Next -->\" WIDTH=1 HEIGHT=4></a>\n" +
"<a href='another.html' name='myLink'>some text</a>\n" +
"</body></html>\n" );
@@ -107,11 +110,14 @@
assertTrue("the blank %20 in the link2 should not be converted but we got '"+link2.getURLString()+"'",link2.getURLString().equals(blankLink2));
}
-
+ /**
+ * check the number of links in the sample page
+ * @throws Exception
+ */
public void testLinks() throws Exception {
WebLink[] links = _simplePage.getLinks();
assertNotNull( "Found no links", links );
- assertEquals( "number of links in page", 3, links.length );
+ assertEquals( "number of links in page", 4, links.length );
}
@@ -141,6 +147,25 @@
assertEquals( "URLString", "/other.html", link.getURLString() );
}
+
+ /**
+ * test for BR 2534057
+ * getLinks() for a Cell return all page links
+ * @throws SAXException
+ */
+ public void testGetLinksForCell() throws SAXException {
+ HTMLElement[] elements = _simplePage.getElementsWithName("acell");
+ assertTrue(elements.length==1);
+ assertTrue(elements[0] instanceof TableCell);
+ TableCell aCell=(TableCell)elements[0];
+ WebLink[] cellLinks = aCell.getLinks();
+ for (int i=0;i<cellLinks.length;i++) {
+ WebLink link=cellLinks[i];
+ System.out.println("link "+i+"="+link.getName());
+ }
+ assertEquals(1,cellLinks.length);
+ assertEquals("acelllink",cellLinks[0].getName());
+ }
public void testGetLinkByText() throws Exception {
WebLink link = _simplePage.getLinkWith( "no link" );
Modified: trunk/httpunit/test/com/meterware/httpunit/dom/NodeTest.java
===================================================================
--- trunk/httpunit/test/com/meterware/httpunit/dom/NodeTest.java 2009-08-21 09:43:42 UTC (rev 1050)
+++ trunk/httpunit/test/com/meterware/httpunit/dom/NodeTest.java 2009-08-21 11:08:14 UTC (rev 1051)
@@ -372,6 +372,19 @@
assertFalse( "Iterator should have terminated after " + expectedNodes.length + " nodes", each.hasNext() );
}
+ /**
+ * Verifies that we can iterate through nodes in order, starting after a specific node.
+ */
+ public void testPreOrderIteratorWithinNode() throws Exception {
+ Iterator each = ((NodeImpl)_foo1).preOrderIteratorWithinNode();
+ Node[] expectedNodes = { _bar1, _text, _foo2};
+ for (int i = 0; i < expectedNodes.length; i++) {
+ assertTrue( "Iterator prematurely terminated after " + i + " nodes", each.hasNext() );
+ Object node = each.next();
+ assertSame( "Node " + (1 + i) + ":", expectedNodes[i], node );
+ }
+ assertFalse( "Iterator should have terminated after " + expectedNodes.length + " nodes", each.hasNext() );
+ }
/**
* Verifies that we can iterate through nodes in order skipping a specified subtree.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2009-08-21 09:43:49
|
Revision: 1050
http://httpunit.svn.sourceforge.net/httpunit/?rev=1050&view=rev
Author: wolfgang_fahl
Date: 2009-08-21 09:43:42 +0000 (Fri, 21 Aug 2009)
Log Message:
-----------
Patch by Dan Lipofsky - reset Listeners and allow switching off parsing. Switch off parsing for Head method.
Modified Paths:
--------------
trunk/httpunit/src/com/meterware/httpunit/HttpWebResponse.java
trunk/httpunit/src/com/meterware/httpunit/WebResponse.java
trunk/httpunit/src/com/meterware/httpunit/parsing/HTMLParserFactory.java
trunk/httpunit/test/com/meterware/httpunit/parsing/HTMLParserListenerTest.java
Modified: trunk/httpunit/src/com/meterware/httpunit/HttpWebResponse.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/HttpWebResponse.java 2009-08-21 09:03:44 UTC (rev 1049)
+++ trunk/httpunit/src/com/meterware/httpunit/HttpWebResponse.java 2009-08-21 09:43:42 UTC (rev 1050)
@@ -70,6 +70,7 @@
HttpWebResponse( WebConversation client, FrameSelector frame, WebRequest request, URLConnection connection, boolean throwExceptionOnError ) throws IOException {
this( client, frame, request.getURL(), connection, throwExceptionOnError );
+ super.setWithParse(!request.getMethod().equals("HEAD"));
_referer = request.getReferer();
}
Modified: trunk/httpunit/src/com/meterware/httpunit/WebResponse.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/WebResponse.java 2009-08-21 09:03:44 UTC (rev 1049)
+++ trunk/httpunit/src/com/meterware/httpunit/WebResponse.java 2009-08-21 09:43:42 UTC (rev 1050)
@@ -74,12 +74,29 @@
private static final int UNKNOWN_LENGTH_RETRY_INTERVAL = 10;
private FrameSelector _frame;
-
+ // allow to switch off parsing e.g. for method="HEAD"
+ private boolean _withParse=true;
private String _baseTarget;
private String _refreshHeader;
private URL _baseURL;
private boolean _parsingPage;
+ /**
+ * is parsing on?
+ * @return
+ */
+ public boolean isWithParse() {
+ return _withParse;
+ }
+
+ /**
+ * set the parsing switch
+ * @param doparse
+ * @return
+ */
+ public void setWithParse(boolean doParse) {
+ _withParse=doParse;
+ }
/**
* Returns a web response built from a URL connection. Provided to allow
@@ -832,7 +849,7 @@
public void load() throws SAXException {
- if (isHTML()) {
+ if (isHTML() && isWithParse()) {
getReceivedPage().getForms(); // TODO be more explicit here - don't care about forms, after all
doEventScript( getReceivedPage().getOnLoadEvent() );
}
@@ -1308,8 +1325,10 @@
private WebFrame[] getFrames() throws SAXException {
- return getReceivedPage().getFrames();
-
+ if (isWithParse())
+ return getReceivedPage().getFrames();
+ else
+ return new WebFrame[0];
}
@@ -1324,10 +1343,11 @@
_parsingPage = true;
if (!isHTML()) throw new NotHTMLException( getContentType() );
_page = new HTMLPage( this, _frame, _baseURL, _baseTarget, getCharacterSet() );
- _page.parse( getText(), _pageURL );
- if (_page == null) throw new IllegalStateException( "replaceText called in the middle of getReceivedPage()" );
-
- ((HTMLDocumentImpl) _page.getRootNode()).getWindow().setProxy( this );
+ if (_withParse) {
+ _page.parse( getText(), _pageURL );
+ if (_page == null) throw new IllegalStateException( "replaceText called in the middle of getReceivedPage()" );
+ ((HTMLDocumentImpl) _page.getRootNode()).getWindow().setProxy( this );
+ }
} catch (IOException e) {
HttpUnitUtils.handleException(e);
throw new RuntimeException( e.toString() );
Modified: trunk/httpunit/src/com/meterware/httpunit/parsing/HTMLParserFactory.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/parsing/HTMLParserFactory.java 2009-08-21 09:03:44 UTC (rev 1049)
+++ trunk/httpunit/src/com/meterware/httpunit/parsing/HTMLParserFactory.java 2009-08-21 09:43:42 UTC (rev 1050)
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
- * Copyright (c) 2002-2008, Russell Gold
+ * Copyright (c) 2002-2009, 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
@@ -54,7 +54,8 @@
_parserWarningsEnabled = false;
_htmlParser = null;
_forceUpper = false;
- _forceLower = false;
+ _forceLower = false;
+ _listeners.clear();
}
Modified: trunk/httpunit/test/com/meterware/httpunit/parsing/HTMLParserListenerTest.java
===================================================================
--- trunk/httpunit/test/com/meterware/httpunit/parsing/HTMLParserListenerTest.java 2009-08-21 09:03:44 UTC (rev 1049)
+++ trunk/httpunit/test/com/meterware/httpunit/parsing/HTMLParserListenerTest.java 2009-08-21 09:43:42 UTC (rev 1050)
@@ -1,24 +1,25 @@
package com.meterware.httpunit.parsing;
+
/********************************************************************************************************************
-* $Id$
-*
-* Copyright (c) 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
-* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
-* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-*
-* The above copyright notice and this permission notice shall be included in all copies or substantial portions
-* of the Software.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
-* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
-* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-* DEALINGS IN THE SOFTWARE.
-*
-*******************************************************************************************************************/
+ * $Id$
+ *
+ * Copyright (c) 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
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
+ * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+ * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ *******************************************************************************************************************/
import com.meterware.httpunit.*;
import java.net.URL;
@@ -26,109 +27,159 @@
import junit.framework.TestSuite;
-
/**
- *
+ *
* @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
public class HTMLParserListenerTest extends HttpUnitTest {
- public static void main(String[] args) {
- junit.textui.TestRunner.run( suite() );
- }
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(suite());
+ }
+ public static TestSuite suite() {
+ return new TestSuite(HTMLParserListenerTest.class);
+ }
- public static TestSuite suite() {
- return new TestSuite( HTMLParserListenerTest.class );
- }
+ public HTMLParserListenerTest(String name) {
+ super(name);
+ }
- public HTMLParserListenerTest( String name ) {
- super( name );
- }
+ public void testBadHTMLPage() throws Exception {
+ defineResource("BadPage.html", "<html>"
+ + "<head><title>A Sample Page</head>\n"
+ + "<body><p><b>Wrong embedded tags</p></b>\n"
+ + "have <a blef=\"other.html?a=1&b=2\">an invalid link</A>\n"
+ + "<IMG SRC=\"/images/arrow.gif\" WIDTH=1 HEIGHT=4>\n"
+ + "<unknownTag>bla</unknownTag>" + "</body></html>\n");
+ final ErrorHandler errorHandler = new ErrorHandler(
+ /* expectProblems */true);
+ try {
+ WebConversation wc = new WebConversation();
+ HTMLParserFactory.addHTMLParserListener(errorHandler);
+ WebRequest request = new GetMethodWebRequest(getHostPath()
+ + "/BadPage.html");
+ wc.getResponse(request);
+ assertTrue("Should have found problems", errorHandler
+ .foundProblems());
+ assertEquals("Expected URL", request.getURL(), errorHandler
+ .getBadURL());
+ } finally {
+ HTMLParserFactory.removeHTMLParserListener(errorHandler);
+ }
+ }
- public void testBadHTMLPage() throws Exception {
- defineResource( "BadPage.html",
- "<html>" +
- "<head><title>A Sample Page</head>\n" +
- "<body><p><b>Wrong embedded tags</p></b>\n" +
- "have <a blef=\"other.html?a=1&b=2\">an invalid link</A>\n" +
- "<IMG SRC=\"/images/arrow.gif\" WIDTH=1 HEIGHT=4>\n" +
- "<unknownTag>bla</unknownTag>" +
- "</body></html>\n" );
+ public void testGoodHTMLPage() throws Exception {
+ final ErrorHandler errorHandler = new ErrorHandler(
+ /* expectProblems */false);
+ try {
+ defineResource(
+ "SimplePage.html",
+ "<html>\n"
+ + "<head><title>A Sample Page</title></head>\n"
+ + "<body><p><b>OK embedded tags</b></p>\n"
+ + "have <a href=\"other.html?a=1&b=2\">an OK link</A>\n"
+ + "<IMG SRC=\"/images/arrow.gif\" alt=\"\" WIDTH=1 HEIGHT=4>\n"
+ + "</body></html>\n");
- final ErrorHandler errorHandler = new ErrorHandler( /* expectProblems */ true );
- try {
- WebConversation wc = new WebConversation();
- HTMLParserFactory.addHTMLParserListener( errorHandler );
- WebRequest request = new GetMethodWebRequest( getHostPath() + "/BadPage.html" );
- wc.getResponse( request );
- assertTrue( "Should have found problems", errorHandler.foundProblems() );
- assertEquals( "Expected URL", request.getURL(), errorHandler.getBadURL() );
- } finally {
- HTMLParserFactory.removeHTMLParserListener( errorHandler );
- }
- }
+ WebConversation wc = new WebConversation();
+ HTMLParserFactory.addHTMLParserListener(errorHandler);
+ WebRequest request = new GetMethodWebRequest(getHostPath()
+ + "/SimplePage.html");
+ wc.getResponse(request);
+ } finally {
+ HTMLParserFactory.removeHTMLParserListener(errorHandler);
+ }
+ }
+ public void testJTidyPrintWriterParsing() throws Exception {
+ URL url = new URL("http://localhost/blank.html");
+ PrintWriter p = new JTidyPrintWriter(url);
+ p.print("line 1234 column 1234");
+ p.print("line 1,234 column 1,234");
+ p.print("line 1,234,567 column 1,234,567");
+ p.print("line 1,2,34 column 12,34");
+ p.print("line 123,,4 column 12,,34");
+ }
- public void testGoodHTMLPage() throws Exception {
- final ErrorHandler errorHandler = new ErrorHandler( /* expectProblems */ false );
- try {
- defineResource( "SimplePage.html",
- "<html>\n" +
- "<head><title>A Sample Page</title></head>\n" +
- "<body><p><b>OK embedded tags</b></p>\n" +
- "have <a href=\"other.html?a=1&b=2\">an OK link</A>\n" +
- "<IMG SRC=\"/images/arrow.gif\" alt=\"\" WIDTH=1 HEIGHT=4>\n" +
- "</body></html>\n" );
+ /**
+ * test by Dan Lipofsky
+ *
+ * @throws Exception
+ */
+ public void testHeadMethodWebRequest2() throws Exception {
+ defineResource("SimplePage.html",
+ "<html><head><title>A Sample Page</title></head>\n"
+ + "<body>Hello</body></html>\n");
+ HttpUnitOptions.setExceptionsThrownOnErrorStatus(true);
+ try {
+ HTMLParserFactory.setParserWarningsEnabled(true);
+ HTMLParserFactory.setHTMLParser(new NekoHTMLParser() {
+ // @Override
+ public void parse(URL pageURL, String pageText,
+ DocumentAdapter adapter) {
+ System.err.println("Parsing URL=" + pageURL + "\n"
+ + pageText);
+ fail("Should not be parsing a HEAD request");
+ }
+ });
+ HTMLParserFactory.addHTMLParserListener(new HTMLParserListener() {
+ public void error(URL url, String msg, int line, int column) {
+ System.err.println("ERROR @url=" + url + ": (" + line
+ + ", " + column + "):" + msg);
+ }
- WebConversation wc = new WebConversation();
- HTMLParserFactory.addHTMLParserListener( errorHandler );
- WebRequest request = new GetMethodWebRequest( getHostPath() + "/SimplePage.html" );
- wc.getResponse( request );
- } finally {
- HTMLParserFactory.removeHTMLParserListener( errorHandler );
- }
- }
+ public void warning(URL url, String msg, int line, int column) {
+ System.err.println("WARN @url=" + url + ": (" + line + ", "
+ + column + "):" + msg);
+ }
+ });
+ WebConversation wc = new WebConversation();
+ // create a HeadMethodWebRequest
+ // see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html for
+ // definition
+ WebRequest request = new HeadMethodWebRequest(getHostPath()
+ + "/SimplePage.html");
+ WebResponse simplePage = wc.getResponse(request);
+ String text = simplePage.getText();
+ // no body should be returned
+ assertEquals("", text);
+ } finally {
+ HTMLParserFactory.reset();
+ }
+ }
- public void testJTidyPrintWriterParsing() throws Exception {
- URL url = new URL("http://localhost/blank.html");
- PrintWriter p = new JTidyPrintWriter(url);
- p.print("line 1234 column 1234");
- p.print("line 1,234 column 1,234");
- p.print("line 1,234,567 column 1,234,567");
- p.print("line 1,2,34 column 12,34");
- p.print("line 123,,4 column 12,,34");
- }
+ static private class ErrorHandler implements HTMLParserListener {
+ private boolean _expectProblems;
+ private boolean _foundProblems;
+ private URL _badURL;
- static private class ErrorHandler implements HTMLParserListener {
+ public ErrorHandler(boolean expectProblems) {
+ _expectProblems = expectProblems;
+ }
- private boolean _expectProblems;
- private boolean _foundProblems;
- private URL _badURL;
+ public void warning(URL url, String msg, int line, int column) {
+ _foundProblems = true;
+ _badURL = url;
+ }
+ public void error(URL url, String msg, int line, int column) {
+ assertTrue(msg + " at line " + line + ", column " + column,
+ _expectProblems);
+ _foundProblems = true;
+ _badURL = url;
+ }
- public ErrorHandler( boolean expectProblems ) {
- _expectProblems = expectProblems;
- }
+ public URL getBadURL() {
+ return _badURL;
+ }
+ public boolean foundProblems() {
+ return _foundProblems;
+ }
+ }
- public void warning( URL url, String msg, int line, int column ) {
- _foundProblems = true;
- _badURL = url;
- }
-
- public void error( URL url, String msg, int line, int column ) {
- assertTrue( msg + " at line " + line + ", column " + column, _expectProblems );
- _foundProblems = true;
- _badURL = url;
- }
-
- public URL getBadURL() { return _badURL; }
-
- public boolean foundProblems() { return _foundProblems; }
- }
-
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2009-08-21 09:03:55
|
Revision: 1049
http://httpunit.svn.sourceforge.net/httpunit/?rev=1049&view=rev
Author: wolfgang_fahl
Date: 2009-08-21 09:03:44 +0000 (Fri, 21 Aug 2009)
Log Message:
-----------
Patch by Matthew Boedicker: post with authentication using inputstream
Modified Paths:
--------------
trunk/httpunit/src/com/meterware/httpunit/MessageBodyWebRequest.java
trunk/httpunit/test/com/meterware/httpunit/WebClientTest.java
Modified: trunk/httpunit/src/com/meterware/httpunit/MessageBodyWebRequest.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/MessageBodyWebRequest.java 2009-08-20 12:14:08 UTC (rev 1048)
+++ trunk/httpunit/src/com/meterware/httpunit/MessageBodyWebRequest.java 2009-08-21 09:03:44 UTC (rev 1049)
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2001-2004,2007 Russell Gold
+* Copyright (c) 2001-2009 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
@@ -157,8 +157,14 @@
/**
* Transmits the body of this request as a sequence of bytes.
- **/
+ * @param outputStream
+ * @param parameters
+ * @throws IOException if the tranmission fails
+ */
public void writeTo( OutputStream outputStream, ParameterCollection parameters ) throws IOException {
+ if (_source.markSupported()) {
+ mark();
+ }
byte[] buffer = new byte[8 * 1024];
int count = 0;
do {
@@ -166,10 +172,27 @@
count = _source.read( buffer, 0, buffer.length );
} while (count != -1);
- _source.close();
+ written = true;
}
+ /**
+ *
+ * @throws IOException
+ */
+ public void mark() throws IOException {
+ if (written) {
+ _source.reset();
+ } else {
+ // amount of bytes to be read after mark gets invalid
+ int readlimit=1024*1024; // ! MByte
+ // Marks the current position in this input stream.
+ // A subsequent call to the reset method repositions
+ // this stream at the last marked position so that subsequent reads re-read the same bytes.
+ _source.mark(readlimit);
+ }
+ }
+ private boolean written = false;
private InputStream _source;
private String _contentType;
}
Modified: trunk/httpunit/test/com/meterware/httpunit/WebClientTest.java
===================================================================
--- trunk/httpunit/test/com/meterware/httpunit/WebClientTest.java 2009-08-20 12:14:08 UTC (rev 1048)
+++ trunk/httpunit/test/com/meterware/httpunit/WebClientTest.java 2009-08-21 09:03:44 UTC (rev 1049)
@@ -26,8 +26,10 @@
import junit.framework.TestSuite;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.*;
import java.util.*;
@@ -403,7 +405,39 @@
assertEquals( "authorization", "Basic dXNlcjpwYXNzd29yZA==", wr.getText() );
}
+ /**
+ * test on demand Basic Authentication with InputStream
+ *
+ * @throws Exception
+ */
+ public void testOnDemandBasicAuthenticationInputStream() throws Exception {
+ defineResource("postRequiringAuthentication", new PseudoServlet() {
+ public WebResource getPostResponse() {
+ String header = getHeader("Authorization");
+ if (header == null) {
+ WebResource webResource = new WebResource("unauthorized");
+ webResource
+ .addHeader("WWW-Authenticate: Basic realm=\"testrealm\"");
+ return webResource;
+ } else {
+ return new WebResource(getBody(), "text/plain");
+ }
+ }
+ });
+ String body = "something";
+ InputStream bodyStream = new ByteArrayInputStream(body.getBytes("UTF-8"));
+ PostMethodWebRequest request = new PostMethodWebRequest(getHostPath()
+ + "/postRequiringAuthentication", bodyStream, "text/plain");
+
+ WebConversation wc = new WebConversation();
+ wc.setAuthentication("testrealm", "user", "password");
+
+ WebResponse wr = wc.getResponse(request);
+ assertEquals(body, wr.getText());
+ bodyStream.close();
+ }
+
/**
* Verifies that even though we have specified username and password for a realm,
* a request for a different realm will still result in an exception.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2009-08-20 13:22:37
|
Revision: 1048
http://httpunit.svn.sourceforge.net/httpunit/?rev=1048&view=rev
Author: wolfgang_fahl
Date: 2009-08-20 12:14:08 +0000 (Thu, 20 Aug 2009)
Log Message:
-----------
Patch by Rick Huff: to implement the
getElementsWithClassName() method. This method returns those nodes
where there are more than one class name on the element.
Modified Paths:
--------------
trunk/httpunit/src/com/meterware/httpunit/ParsedHTML.java
trunk/httpunit/src/com/meterware/httpunit/WebResponse.java
trunk/httpunit/test/com/meterware/httpunit/WebPageTest.java
Modified: trunk/httpunit/src/com/meterware/httpunit/ParsedHTML.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/ParsedHTML.java 2009-08-20 12:02:21 UTC (rev 1047)
+++ trunk/httpunit/src/com/meterware/httpunit/ParsedHTML.java 2009-08-20 12:14:08 UTC (rev 1048)
@@ -66,6 +66,9 @@
/** map of element names to lists of elements. **/
private HashMap _elementsByName = new HashMap();
+
+ /** map of element class to elements. **/
+ private HashMap _elementsByClass = new HashMap();
/** map of DOM elements to HTML elements **/
private ElementRegistry _registry = new ElementRegistry();
@@ -237,7 +240,16 @@
return elements == null ? NO_ELEMENTS : (HTMLElement[]) elements.toArray( new HTMLElement[ elements.size() ] );
}
+ /**
+ * Returns the HTML elements with the specified class.
+ */
+ public HTMLElement[] getElementsWithClassName( String className ) {
+ loadElements();
+ ArrayList elements = (ArrayList) _elementsByClass.get( className );
+ return elements == null ? NO_ELEMENTS : (HTMLElement[]) elements.toArray( new HTMLElement[ elements.size() ] );
+ }
+
/**
* Returns the HTML elements with an attribute with the specified name and value.
* @param name - the name of the attribute to check
@@ -889,6 +901,22 @@
_registry.registerElement( node, htmlElement );
if (htmlElement.getID() != null) _elementsByID.put( htmlElement.getID(), htmlElement );
if (htmlElement.getName() != null) addNamedElement( htmlElement.getName(), htmlElement );
+ if (htmlElement.getClassName() != null) {
+ StringTokenizer tokenizer = new StringTokenizer(htmlElement.getClassName());
+ String token;
+
+ while(tokenizer.hasMoreElements()) {
+ token = tokenizer.nextToken();
+
+ if ( _elementsByClass.containsKey( token )) {
+ ((ArrayList) _elementsByClass.get( token )).add( htmlElement );
+ } else {
+ ArrayList arrayList = new ArrayList();
+ arrayList.add(htmlElement);
+ _elementsByClass.put( token, arrayList );
+ }
+ }
+ }
}
Modified: trunk/httpunit/src/com/meterware/httpunit/WebResponse.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/WebResponse.java 2009-08-20 12:02:21 UTC (rev 1047)
+++ trunk/httpunit/src/com/meterware/httpunit/WebResponse.java 2009-08-20 12:14:08 UTC (rev 1048)
@@ -387,8 +387,14 @@
return getReceivedPage().getElementsWithName( name );
}
-
/**
+ * Returns the HTMLElements found in this segment with the specified class.
+ */
+ public HTMLElement[] getElementsWithClassName( String className ) throws SAXException {
+ return getReceivedPage().getElementsWithClassName( className );
+ }
+
+ /**
* Returns the HTMLElements found with the specified attribute value.
* @since 1.6
*/
Modified: trunk/httpunit/test/com/meterware/httpunit/WebPageTest.java
===================================================================
--- trunk/httpunit/test/com/meterware/httpunit/WebPageTest.java 2009-08-20 12:02:21 UTC (rev 1047)
+++ trunk/httpunit/test/com/meterware/httpunit/WebPageTest.java 2009-08-20 12:14:08 UTC (rev 1048)
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2007, Russell Gold
+* Copyright (c) 2000-2009, 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
@@ -459,6 +459,26 @@
}
/**
+ * test for getElementsWithClassName supplied by Rick Huff
+ * @throws Exception
+ */
+ public void testGetElementsWithClassName() throws Exception {
+ defineResource( "SimplePage.html",
+ "<html><head><title>A Sample Page</title></head>\n" +
+ "<body><form class='first colorsample' name='aForm'><input name=color></form>" +
+ "have <a id='link1' href='/other.html'>an <b>active</b> link</A>\n" +
+ "<img id='23' src='/images/arrow.gif' ALT='Next -->' WIDTH=1 HEIGHT=4>\n" +
+ "</body></html>\n" );
+ WebConversation wc = new WebConversation();
+ WebRequest request = new GetMethodWebRequest( getHostPath() + "/SimplePage.html" );
+ WebResponse simplePage = wc.getResponse( request );
+ assertImplement( "elements with class attribute 'first colorsample'", simplePage.getElementsWithAttribute( "class", "first colorsample" ), WebForm.class );
+ assertImplement( "elements with class 'first'", simplePage.getElementsWithClassName( "first" ), WebForm.class );
+ assertImplement( "elements with class 'colorsample'", simplePage.getElementsWithClassName( "colorsample" ), WebForm.class );
+ }
+
+
+ /**
* Test the {@link WebResponse.ByteTagParser} to ensure that embedded JavaScript is skipped.
*/
public void testByteTagParser() throws Exception {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2009-08-20 12:02:34
|
Revision: 1047
http://httpunit.svn.sourceforge.net/httpunit/?rev=1047&view=rev
Author: wolfgang_fahl
Date: 2009-08-20 12:02:21 +0000 (Thu, 20 Aug 2009)
Log Message:
-----------
Patch by Antoine Vernois: it implements getServerName() and getServerPort of ServletUnitHttpRequest. ServerName and ServerPort are extracted from request's URL instead of always returning localhost and 0.
Modified Paths:
--------------
trunk/httpunit/src/com/meterware/servletunit/ServletUnitHttpRequest.java
trunk/httpunit/test/com/meterware/servletunit/HttpServletRequestTest.java
Modified: trunk/httpunit/src/com/meterware/servletunit/ServletUnitHttpRequest.java
===================================================================
--- trunk/httpunit/src/com/meterware/servletunit/ServletUnitHttpRequest.java 2009-08-20 11:31:40 UTC (rev 1046)
+++ trunk/httpunit/src/com/meterware/servletunit/ServletUnitHttpRequest.java 2009-08-20 12:02:21 UTC (rev 1047)
@@ -56,7 +56,8 @@
private boolean _gotReader;
private boolean _gotInputStream;
private BufferedReader _reader;
-
+ private int _serverPort;
+ private String _serverName;
/**
@@ -75,6 +76,11 @@
_messageBody = messageBody;
_protocol=request.getURL().getProtocol().toLowerCase();
_secure = _protocol.endsWith("s" );
+ _serverName = request.getURL().getHost();
+ _serverPort = request.getURL().getPort();
+ if ( _serverPort == -1 ) {
+ _serverPort = request.getURL().getDefaultPort();
+ }
_requestContext = new RequestContext( request.getURL() );
String contentTypeHeader = (String) _headers.get( "Content-Type" );
@@ -472,7 +478,7 @@
* Returns the host name of the server that received the request.
**/
public String getServerName() {
- return "localhost";
+ return _serverName;
}
@@ -480,7 +486,7 @@
* Returns the port number on which this request was received.
**/
public int getServerPort() {
- return 0;
+ return _serverPort;
}
Modified: trunk/httpunit/test/com/meterware/servletunit/HttpServletRequestTest.java
===================================================================
--- trunk/httpunit/test/com/meterware/servletunit/HttpServletRequestTest.java 2009-08-20 11:31:40 UTC (rev 1046)
+++ trunk/httpunit/test/com/meterware/servletunit/HttpServletRequestTest.java 2009-08-20 12:02:21 UTC (rev 1047)
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2008 by Russell Gold
+* Copyright (c) 2000-2009 by 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
@@ -714,10 +714,9 @@
/**
* test the reader with a Specific Character set (here UTF-8)
* @throws Exception
- * TODO make work an switch back on
+ * FIXME make work an switch back on
*/
public void xtestGetReaderSpecificCharset() throws Exception {
- //String body = "東京";
String body = "\u05d0\u05d1\u05d2\u05d3";
InputStream stream = new ByteArrayInputStream( body.getBytes( "UTF-8" ) );
WebRequest wr = new PostMethodWebRequest( "http://localhost/simple", stream, "text/plain; charset=UTF-8" );
@@ -771,7 +770,40 @@
assertEquals( "param2 value", hebrewValue, request.getParameter( "param2") );
}
+ /**
+ * test for getServerPort and getServerName by Antoine Vernois
+ * @throws Exception
+ */
+ public void testDefaultHttpServerPort() throws Exception {
+ WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
+ HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, _context, new Hashtable(), NO_MESSAGE_BODY );
+ int serverPort = request.getServerPort();
+ assertEquals( "default http server port", serverPort, 80 );
+ }
+ /**
+ * test for getServerPort and getServerName by Antoine Vernois
+ * @throws Exception
+ */
+ public void testSuppliedHttpServerPort() throws Exception {
+ WebRequest wr = new GetMethodWebRequest( "http://localhost:8080/simple" );
+ HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, _context, new Hashtable(), NO_MESSAGE_BODY );
+ int serverPort = request.getServerPort();
+ assertEquals( "supplied http server port", serverPort, 8080 );
+ }
+
+ /**
+ * test for getServerPort and getServerName by Antoine Vernois
+ * @throws Exception
+ */
+ public void testServerName() throws Exception {
+ WebRequest wr = new GetMethodWebRequest( "http://myhost:8080/simple" );
+ HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, _context, new Hashtable(), NO_MESSAGE_BODY );
+ String serverName = request.getServerName();
+ assertEquals( "server name", serverName, "myhost" );
+ }
+
+
private final static byte[] NO_MESSAGE_BODY = new byte[0];
private final static ServletMetaData NULL_SERVLET_REQUEST = new ServletMetaData() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2009-08-20 11:31:47
|
Revision: 1046
http://httpunit.svn.sourceforge.net/httpunit/?rev=1046&view=rev
Author: wolfgang_fahl
Date: 2009-08-20 11:31:40 +0000 (Thu, 20 Aug 2009)
Log Message:
-----------
test case for double quoted cookie problem pointed out by Mario V
Modified Paths:
--------------
trunk/httpunit/test/com/meterware/httpunit/cookies/CookieTest.java
Modified: trunk/httpunit/test/com/meterware/httpunit/cookies/CookieTest.java
===================================================================
--- trunk/httpunit/test/com/meterware/httpunit/cookies/CookieTest.java 2009-08-20 10:44:14 UTC (rev 1045)
+++ trunk/httpunit/test/com/meterware/httpunit/cookies/CookieTest.java 2009-08-20 11:31:40 UTC (rev 1046)
@@ -22,6 +22,7 @@
*******************************************************************************************************************/
import java.net.URL;
import java.net.MalformedURLException;
+import java.util.Collection;
import java.util.HashMap;
import junit.framework.TestCase;
@@ -76,6 +77,20 @@
assertEquals( "cookie 'PORTAL30_SSO_TEST' value", "X", jar.getCookieValue( "PORTAL30_SSO_TEST" ) );
assertEquals( "cookie 'SESSION_ID' value", "17585,Dzm5LzbRPnb95QkUyIX+7w5RDT7p6OLuOVZ91AMl4hsDATyZ1ej+FA==", jar.getCookieValue( "SESSION_ID" ) );
}
+
+ /***
+ * test for double quoted cookies suggested by Mario V
+ * disabled since it indeed fails - FIXME - we need a patch here
+ * @throws Exception
+ */
+ public void xtestDoubleQuoteCookies() throws Exception {
+ CookieJar jar = new CookieJar(
+ new TestSource( new URL( "http://www.meterware.com" ),
+ new String[] { "NewUniversalCookie=\"mmmmmmmmmmmmmmm==mmmmmmm mmmmmmm\"; Path=/"} ) );
+ Collection cookies = jar.getCookies();
+ assertTrue("There should only be one cookie but there are "+cookies.size(),cookies.size()==1);
+ assertEquals( "cookie 'NewUniversalCookie' value", "mmmmmmmmmmmmmmm==mmmmmmm mmmmmmm", jar.getCookieValue( "NewUniversalCookie" ) );
+ }
public void testCookieMatching() throws Exception {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2009-08-20 10:44:24
|
Revision: 1045
http://httpunit.svn.sourceforge.net/httpunit/?rev=1045&view=rev
Author: wolfgang_fahl
Date: 2009-08-20 10:44:14 +0000 (Thu, 20 Aug 2009)
Log Message:
-----------
svn keywords set
Modified Paths:
--------------
trunk/httpunit/doc/release_notes.html
Property Changed:
----------------
trunk/httpunit/doc/release_notes.html
Modified: trunk/httpunit/doc/release_notes.html
===================================================================
--- trunk/httpunit/doc/release_notes.html 2009-08-20 10:40:52 UTC (rev 1044)
+++ trunk/httpunit/doc/release_notes.html 2009-08-20 10:44:14 UTC (rev 1045)
@@ -2,7 +2,10 @@
<head><title>httpunit 1.7 release notes</title></head>
<body>
<h1>HttpUnit release notes</h1>
-
+<pre>
+$Id$
+$URL$
+</pre>
<h3>Known problems:</h3>
<ol>
<li>The "accept-charset" attribute for forms is ignored; the page content character set is used to encode any response.
Property changes on: trunk/httpunit/doc/release_notes.html
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Id Author URL
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2009-08-20 10:41:00
|
Revision: 1044
http://httpunit.svn.sourceforge.net/httpunit/?rev=1044&view=rev
Author: wolfgang_fahl
Date: 2009-08-20 10:40:52 +0000 (Thu, 20 Aug 2009)
Log Message:
-----------
added svn log results from 2008-04 to 2009-08
Modified Paths:
--------------
trunk/httpunit/doc/release_notes.html
Modified: trunk/httpunit/doc/release_notes.html
===================================================================
--- trunk/httpunit/doc/release_notes.html 2009-08-20 08:43:55 UTC (rev 1043)
+++ trunk/httpunit/doc/release_notes.html 2009-08-20 10:40:52 UTC (rev 1044)
@@ -20,15 +20,64 @@
<h2>Revision History:</h2>
-<h3>Version 1.7.x to be Released some time in the future</h3>
+<h3>Version 1.7.x to be Released some time in the future after 2009-08-20</h3>
<h4>Acknowledgements:</h4>
<ul>
<li>Marc Guillemot for his change request to add the response to a HttpException</li>
<li>Robert Wadura for showing that trying to load included scripts that do not exist might abort entire requests - was already fixed in 1.7 but not mentioned in the release notes</li>
<li>Dan Lipofsky for pointing out some problems with JavaScript handling</li>
+ <li>James Abley for making the Abstract base class of the TestCases abstract</li>
+ <li>Tiago Luchini for a fix to avoid that forms are submitted twice</li>
+ <li>Martin Burchell for supplying a testCase for the forms are submitted twice problem</li>
+ <li>Hugh Winkler for pointing out that setAuthorization(user, password should not be deprecated</li>
+ <li>Peter De Bruycker for asking to make form.name property mutable</li>
+ <li>Dawn Lambeth for helping to fix a NullPointerException in MimeEncodedMessageBody</li>
+ <li>Matthew O. Smith for finding a but that BlockElement is not checking null</li>
+ <li>Markus Gaisbauer for correcting an issue with Cookie handling </li>
+ <li>Malcolm Robbins for helping to fix isHiddenParameter which return true for non existing parameters</li>
+ <li>Stephen Cresswell for suggesting to modify CookieTest</li>
+ <li>Stephen Mikaty for an addition to so that the XPath Predicate handling may work again</li>
+ <li>Mattias Jiderhamn for helping to avoid 'event is not defined' problems</li>
+ <li>Brendan Boesen for revisiting BR 2264431</li>
+ <li>James Courtney for proposing a new test case and providing a fix</li>
+ <li>Serge Maslyukov for a path to solve issue with drupal's cookie</li>
+ <li>Chris Wilson for supplying a fix for Rhino JavaScript errors to show up when ScriptError handling is switched off</li>
+ <li>redsonic and Adam Heath for proposing a patch to solve problems with getFormWithId()</li>
+ <li>Oliver Wahlen for asking for a solution to get the bytes for a download result - WebResponse.getBytes() is now available for this purpose</li>
</ul>
<h4>Problems fixed:</h4>
- <li>bug #<a href="http://sourceforge.net/tracker/index.php?func=detail&aid=1055450&group_id=6550&atid=106550">1055450</a> - Error loading included script aborts entire request</li>
+ <li>BR [<a href="http://sourceforge.net/tracker/index.php?func=detail&aid=1055450&group_id=6550&atid=106550">1055450</a> ] Error loading included script aborts entire request</li>
+ <li>BR [<a href="http://sourceforge.net/tracker/index.php?func=detail&aid=2034998&group_id=6550&atid=106550">2034998</a> ] by Tiago Luchini + fix of another bug (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=991">r991</a>) </li>
+ <li>BR [<a href="http://sourceforge.net/tracker/index.php?func=detail&aid=2212706&group_id=6550&atid=106550">2212706</a> ] NullPointerException in MimeEncodedMessageBody by Dawn Lambeth (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=997">r997</a>)</li>
+ <li>BR [ <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=1963211&group_id=6550&atid=106550">1963211</a> ] FindBug: BlockElement not checking null by Matthew O. Smith (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1008">r1008</a>) </li>
+ <li>BR [ <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=2076028&group_id=6550&atid=106550">2076028</a> ] Cookies are handeled incorrectly by Markus Gaisbauer (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1006">r1006</a>) </li>
+ <li>BR [ <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=2099277&group_id=6550&atid=106550">2099277</a> ] isHiddenParameter() returns true when non existent by Malcolm Robbins (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1007">r1007</a>)
+ <li>BR [ <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=2100376&group_id=6550&atid=106550">2100376</a> ] Unable to implement an XPath Predicate (which used to work) by Stephane Mikaty (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1010">r1010</a>) </li>
+ <li>BR [ <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=2100376&group_id=6550&atid=106550">2100376</a> ] Unable to implement an XPath Predicate (which used to work) by Stephane Mikaty (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1012">r1012</a>) </li>
+ <li>Patch [ <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=1968504&group_id=6550&atid=306550">1968504</a> ] Avoid '"event" is not defined' by Mattias Jiderhamn (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1013">r1013</a>) </li>
+ <li>BR[<a href="http://sourceforge.net/tracker/index.php?func=detail&aid=2264431&group_id=6550&atid=106550">2264431</a>] Revisited by Brendan Boesen (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1014">r1014</a>)</li>
+ <li>fix by James Courtney (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1033">r1033</a>) </li>
+<h5>Other modifications</h5>
+<ol>
+ <li>made abstract on recommendation of James Abley (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=990">r990</a>)</li>
+ <li>test case for BR<a href="http://sourceforge.net/tracker/index.php?func=detail&aid=2034998&group_id=6550&atid=106550">2034998</a> by Martin Burchell, Aptivate (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=992">r992</a>)</li>
+ <li>removed deprecated as asked for in BR <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=2034206&group_id=6550&atid=106550">2034206</a> by Hugh Winkler (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=993">r993</a>) </li>
+ <li>FR [ <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=2163079&group_id=6550&atid=106550">2163079</a> ] make form.name property mutable by Peter De Bruycker (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=995">r995</a>)</li>
+ <li>follow up on BR [ <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=1518901&group_id=6550&atid=106550">1518901</a> ] (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=998">r998</a>) </li>
+ <li>Test for [ <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=2264431&group_id=6550&atid=106550">2264431</a> ] form.submit() sends multiple HTTP POSTS (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=999">r999</a>) </li>
+ <li>modified according to suggestion by Stephen Cresswell (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1005">r1005</a>)</li>
+ <li>added test case for discussing <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=2373755&group_id=6550&atid=106550">2373755</a>(<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1015">r1015</a>)</li>
+ <li>new testcase according to discussion with James Courtney (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1017">r1017</a>)</li>
+ <li>Negotiate Header should not spoil Authentication -- null pointer problem removed (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1019">r1019</a>)</li>
+ <li>patch by Serge Maslyukov to solve issue with drupal's cookie (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1020">r1020</a>) </li>
+ <li>fix problems in german locale (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1032">r1032</a>) </li>
+ <li>check behaviour of undefined resources (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1035">r1035</a>) </li>
+ <li>modify message on failure of getIncludes Scripts via src attributes<br />to make sure the message is the same on all setting of Exception and ScriptError status flags (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1039">r1039</a>) </li>
+ <li>add test for HeadMethodWebRequest by Dan Lipofsky and fix the PseudoServer accordingly. Make sure GetMethodWebRequest sets the method attribute in the superClass. (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1040">r1040</a>) </li>
+ <li>fixed BR <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=2637824&group_id=6550&atid=106550">2637824</a> by Chris Wilson <br />JavaScriptException still fatal with script exceptions off (Rhino)(<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1041">r1041</a>) </li>
+ <li>proposed fix for BR <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=2407470&group_id=6550&atid=306550">2407470</a> Regression in httpUnit-1.7 by redsonic with Patch from Adam Heath (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1042">r1042</a>) </li>
+</ol>
+
<h4>Additions:</h4>
<h5>Debugging</h5>
Whenever some code was changed it was made more debug and test-friendly.
@@ -38,8 +87,29 @@
</ul>
<h5>Error handling</h5>
<ol>
- <li>change request #<a href="http://sourceforge.net/tracker/index.php?func=detail&aid=914314&group_id=6550&atid=356550">914314</a>Add HttpException.getResponse for better reporting</li>
+ <li>change request #<a href="http://sourceforge.net/tracker/index.php?func=detail&aid=914314&group_id=6550&atid=356550">914314</a>Add HttpException.getResponse for better reporting - comment added only</li>
+ <li>implemented CR [ <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=914314&group_id=6550&atid=106550">914314</a> ] to add getResponse to HttpException<br />improved handling of undefined resources in PseudoServer<br />getIncludedScript now handles 404 errors according to the HttpUnit Options settings for script error and exception handling (thanks to Dan Lipofsky for pointing this out) (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1036">r1036</a>) </li>
+</ol>
+<h5>Content and Parsing</h5>
+<ol>
+ <li>Test added for BR [ <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=1964665&group_id=6550&atid=106550">1964665</a> ] HeaderOnlyRequest cannot be constructed (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1009">r1009</a>) </li>
+ <li>getBytes added to WebResponse according to a CR by Oliver Wahlen<br />getDownload helper function is superfluous now (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1043">r1043</a>) </li>
</ol>
+<h5>Java Script</h5>
+<ol>
+ <li>FR [ <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=2025598&group_id=6550&atid=106550">2025598</a> ] support javascript window.scrollTo() (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=994">r994</a>) </li>
+ <li>toLowerCase built in function added (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1021">r1021</a>) </li>
+ <li>patch <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=1152036&group_id=6550&atid=306550">1152036</a>: don't request javascript when not enabled (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1022">r1022</a>) </li>
+</ol>
+<h5>IDE Support</h5>
+<ol>
+ <li>updated for new maven2 repository (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=987">r987</a>)</li>
+ <li>Eclipse settings added (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=988">r988</a>) </li>
+ <li>Eclipse setting modified for lesser warnings (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1023">r1023</a>) </li>
+ <li>more settings changed (<a href="http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1024">r1024</a>)</li>
+</ol>
+<h4>Improvements</h4>
+<h5>Javadoc</h5>
<h3>Version 1.7 Released 2008-05-20</h3>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2009-08-20 08:44:07
|
Revision: 1043
http://httpunit.svn.sourceforge.net/httpunit/?rev=1043&view=rev
Author: wolfgang_fahl
Date: 2009-08-20 08:43:55 +0000 (Thu, 20 Aug 2009)
Log Message:
-----------
getBytes added to WebResponse according to a CR by Oliver Wahlen
getDownload helper function is superfluous now
Modified Paths:
--------------
trunk/httpunit/src/com/meterware/httpunit/WebResponse.java
trunk/httpunit/src/com/meterware/pseudoserver/HttpUserAgentTest.java
trunk/httpunit/test/com/meterware/httpunit/MessageBodyRequestTest.java
Modified: trunk/httpunit/src/com/meterware/httpunit/WebResponse.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/WebResponse.java 2009-08-20 07:07:28 UTC (rev 1042)
+++ trunk/httpunit/src/com/meterware/httpunit/WebResponse.java 2009-08-20 08:43:55 UTC (rev 1043)
@@ -276,10 +276,21 @@
abstract
public String getHeaderField( String fieldName );
-
/**
+ * Returns the actual byte stream of the response e.g. for download results
+ * @return the byte array read for this response
+ * @throws IOException
+ */
+ public byte[] getBytes() throws IOException {
+ if (_responseText == null)
+ loadResponseText();
+ return _bytes;
+ }
+
+ /**
* 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.
+ * @return the response text
**/
public String getText() throws IOException {
if (_responseText == null)
@@ -1055,7 +1066,15 @@
private int _refreshDelay = -1; // initialized to invalid value
+ /**
+ * the response as a String
+ */
private String _responseText;
+
+ /**
+ * the response as a byte array
+ */
+ private byte[] _bytes;
private InputStream _inputStream;
@@ -1082,15 +1101,15 @@
try {
final int contentLength = this.encodedUsingGZIP() ? -1 : getContentLength();
int bytesRemaining = contentLength < 0 ? Integer.MAX_VALUE : contentLength;
- byte[] bytes = readFromStream( inputStream, bytesRemaining );
+ _bytes = readFromStream( inputStream, bytesRemaining );
- readTags( bytes );
- _responseText = new String( bytes, getCharacterSet() );
- _inputStream = new ByteArrayInputStream( bytes );
+ readTags( _bytes );
+ _responseText = new String( _bytes, getCharacterSet() );
+ _inputStream = new ByteArrayInputStream( _bytes );
- if (HttpUnitOptions.isCheckContentLength() && contentLength >= 0 && bytes.length != contentLength) {
+ if (HttpUnitOptions.isCheckContentLength() && contentLength >= 0 && _bytes.length != contentLength) {
throw new IOException("Truncated message. Expected length: " + contentLength +
- ", Actual length: " + bytes.length);
+ ", Actual length: " + _bytes.length);
}
} finally {
inputStream.close();
Modified: trunk/httpunit/src/com/meterware/pseudoserver/HttpUserAgentTest.java
===================================================================
--- trunk/httpunit/src/com/meterware/pseudoserver/HttpUserAgentTest.java 2009-08-20 07:07:28 UTC (rev 1042)
+++ trunk/httpunit/src/com/meterware/pseudoserver/HttpUserAgentTest.java 2009-08-20 08:43:55 UTC (rev 1043)
@@ -255,9 +255,7 @@
protected void assertEquals( String comment, byte[] expected, byte[] actual ) {
- if (!equals( expected, actual )) {
- fail( comment + " expected:\n" + toString( expected ) + ", but was:\n" + toString( actual ) );
- }
+ assertEquals(comment,toString(expected),toString(actual));
}
Modified: trunk/httpunit/test/com/meterware/httpunit/MessageBodyRequestTest.java
===================================================================
--- trunk/httpunit/test/com/meterware/httpunit/MessageBodyRequestTest.java 2009-08-20 07:07:28 UTC (rev 1042)
+++ trunk/httpunit/test/com/meterware/httpunit/MessageBodyRequestTest.java 2009-08-20 08:43:55 UTC (rev 1043)
@@ -1,24 +1,25 @@
package com.meterware.httpunit;
+
/********************************************************************************************************************
-* $Id$
-*
-* 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
-* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
-* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-*
-* The above copyright notice and this permission notice shall be included in all copies or substantial portions
-* of the Software.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
-* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
-* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-* DEALINGS IN THE SOFTWARE.
-*
-*******************************************************************************************************************/
+ * $Id$
+ *
+ * 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
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
+ * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+ * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ *******************************************************************************************************************/
import com.meterware.pseudoserver.PseudoServlet;
import com.meterware.pseudoserver.WebResource;
@@ -30,109 +31,142 @@
import junit.framework.Test;
import junit.framework.TestSuite;
-
/**
* A unit test to verify miscellaneous requests with message bodies.
**/
public class MessageBodyRequestTest extends HttpUnitTest {
- public static void main(String args[]) {
- junit.textui.TestRunner.run( suite() );
- }
-
-
- public static Test suite() {
- return new TestSuite( MessageBodyRequestTest.class );
- }
+ public static void main(String args[]) {
+ junit.textui.TestRunner.run(suite());
+ }
+ public static Test suite() {
+ return new TestSuite(MessageBodyRequestTest.class);
+ }
- public MessageBodyRequestTest( String name ) {
- super( name );
- }
+ public MessageBodyRequestTest(String name) {
+ super(name);
+ }
+ public void setUp() throws Exception {
+ super.setUp();
+ }
- public void setUp() throws Exception {
- super.setUp();
- }
-
-
- public void testGenericPostRequest() throws Exception {
- defineResource( "ReportData", new BodyEcho() );
- String sourceData = "This is an interesting test\nWith two lines";
- InputStream source = new ByteArrayInputStream( sourceData.getBytes( "iso-8859-1" ) );
+ public void testGenericPostRequest() throws Exception {
+ defineResource("ReportData", new BodyEcho());
+ String sourceData = "This is an interesting test\nWith two lines";
+ InputStream source = new ByteArrayInputStream(sourceData
+ .getBytes("iso-8859-1"));
- WebConversation wc = new WebConversation();
- WebRequest wr = new PostMethodWebRequest( getHostPath() + "/ReportData", source, "text/sample" );
- WebResponse response = wc.getResponse( wr );
- assertEquals( "Body response", "\nPOST\n" + sourceData, response.getText() );
- assertEquals( "Content-type", "text/sample", response.getContentType() );
- }
+ WebConversation wc = new WebConversation();
+ WebRequest wr = new PostMethodWebRequest(getHostPath() + "/ReportData",
+ source, "text/sample");
+ WebResponse response = wc.getResponse(wr);
+ assertEquals("Body response", "\nPOST\n" + sourceData, response
+ .getText());
+ assertEquals("Content-type", "text/sample", response.getContentType());
+ }
+ public void testPutRequest() throws Exception {
+ defineResource("ReportData", new BodyEcho());
+ String sourceData = "This is an interesting test\nWith two lines";
+ InputStream source = new ByteArrayInputStream(sourceData
+ .getBytes("iso-8859-1"));
- public void testPutRequest() throws Exception {
- defineResource( "ReportData", new BodyEcho() );
- String sourceData = "This is an interesting test\nWith two lines";
- InputStream source = new ByteArrayInputStream( sourceData.getBytes( "iso-8859-1" ) );
+ WebConversation wc = new WebConversation();
+ WebRequest wr = new PutMethodWebRequest(getHostPath() + "/ReportData",
+ source, "text/plain");
+ WebResponse response = wc.getResponse(wr);
+ assertEquals("Body response", "\nPUT\n" + sourceData, response
+ .getText());
+ }
- WebConversation wc = new WebConversation();
- WebRequest wr = new PutMethodWebRequest( getHostPath() + "/ReportData", source, "text/plain" );
- WebResponse response = wc.getResponse( wr );
- assertEquals( "Body response", "\nPUT\n" + sourceData, response.getText() );
- }
+ /**
+ * test for download problem described by Oliver Wahlen
+ */
+ public void testDownloadRequestUsingGetText() throws Exception {
+ defineResource( "ReportData", new BodyEcho() );
+ byte[] binaryData = new byte[256];
+ for(int i=0;i<=255;i++) {
+ binaryData[i] = (byte)i;
+ }
+ InputStream source = new ByteArrayInputStream( binaryData );
- public void testDownloadRequest() throws Exception {
- defineResource( "ReportData", new BodyEcho() );
- byte[] binaryData = new byte[] { 0x01, 0x05, 0x0d, 0x0a, 0x02 };
+ WebConversation wc = new WebConversation();
+ WebRequest wr = new PutMethodWebRequest( getHostPath() + "/ReportData", source, "application/random" );
+ WebResponse response = wc.getResponse( wr );
+ // currently the following line does not work:
+ byte[] download = response.getText().getBytes();
+ // currently the following line works:
+ // byte[] download = getDownload( response );
+ // and this one is now available ...
+ download=response.getBytes();
+ assertEquals("Body response", binaryData, download);
+ }
+
+ public void testDownloadRequest() throws Exception {
+ defineResource("ReportData", new BodyEcho());
+ byte[] binaryData = new byte[] { 0x01, 0x05, 0x0d, 0x0a, 0x02 };
- InputStream source = new ByteArrayInputStream( binaryData );
+ InputStream source = new ByteArrayInputStream(binaryData);
- WebConversation wc = new WebConversation();
- WebRequest wr = new PutMethodWebRequest( getHostPath() + "/ReportData", source, "application/random" );
- WebResponse response = wc.getResponse( wr );
+ WebConversation wc = new WebConversation();
+ WebRequest wr = new PutMethodWebRequest(getHostPath() + "/ReportData",
+ source, "application/random");
+ WebResponse response = wc.getResponse(wr);
+ byte[] download = response.getBytes();
+ assertEquals("Body response", binaryData, download);
- byte[] download = getDownload( response );
- assertEquals( "Body response", binaryData, download );
- }
-
- /**
- * test for BR [ 1964665 ] HeaderOnlyRequest cannot be constructed
- */
- public void testHeaderOnlyWebRequest() throws Exception {
- HeaderOnlyWebRequest r = new HeaderOnlyWebRequest("http://www.google.com");
- }
+ download = getDownload(response);
+ assertEquals("Body response", binaryData, download);
+
+ download = response.getBytes();
+ assertEquals("Body response", binaryData, download);
+ }
+ /**
+ * test for BR [ 1964665 ] HeaderOnlyRequest cannot be constructed
+ */
+ public void testHeaderOnlyWebRequest() throws Exception {
+ HeaderOnlyWebRequest r = new HeaderOnlyWebRequest(
+ "http://www.google.com");
+ }
- private byte[] getDownload( WebResponse response ) throws IOException {
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- InputStream inputStream = response.getInputStream();
+ /**
+ * please do not copy this function any more - use getBytes instead ...
+ * @param response
+ * @return
+ * @throws IOException
+ */
+ private byte[] getDownload(WebResponse response) throws IOException {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ InputStream inputStream = response.getInputStream();
- byte[] buffer = new byte[8 * 1024];
- int count = 0;
- do {
- outputStream.write( buffer, 0, count );
- count = inputStream.read( buffer, 0, buffer.length );
- } while (count != -1);
+ byte[] buffer = new byte[8 * 1024];
+ int count = 0;
+ do {
+ outputStream.write(buffer, 0, count);
+ count = inputStream.read(buffer, 0, buffer.length);
+ } while (count != -1);
- inputStream.close();
- return outputStream.toByteArray();
- }
+ inputStream.close();
+ return outputStream.toByteArray();
+ }
-
}
-
class BodyEcho extends PseudoServlet {
- /**
- * Returns a resource object as a result of a get request.
- **/
- public WebResource getResponse( String method ) {
- String contentType = getHeader( "Content-type" );
- if (contentType.startsWith( "text" )) {
- return new WebResource( "\n" + method + "\n" + new String( getBody() ), contentType );
- } else {
- return new WebResource( getBody(), contentType );
- }
- }
+ /**
+ * Returns a resource object as a result of a get request.
+ **/
+ public WebResource getResponse(String method) {
+ String contentType = getHeader("Content-type");
+ if (contentType.startsWith("text")) {
+ return new WebResource(
+ "\n" + method + "\n" + new String(getBody()), contentType);
+ } else {
+ return new WebResource(getBody(), contentType);
+ }
+ }
}
-
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wol...@us...> - 2009-08-20 07:07:36
|
Revision: 1042
http://httpunit.svn.sourceforge.net/httpunit/?rev=1042&view=rev
Author: wolfgang_fahl
Date: 2009-08-20 07:07:28 +0000 (Thu, 20 Aug 2009)
Log Message:
-----------
proposed fix for BR 2407470 Regression in httpUnit-1.7 by redsonic with Patch from Adam Heath
Modified Paths:
--------------
trunk/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java
trunk/httpunit/src/com/meterware/httpunit/ParsedHTML.java
trunk/httpunit/test/com/meterware/httpunit/WebFormTest.java
Modified: trunk/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java 2009-08-19 10:08:00 UTC (rev 1041)
+++ trunk/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java 2009-08-20 07:07:28 UTC (rev 1042)
@@ -450,10 +450,13 @@
/**
* Determines whether script errors result in exceptions or warning messages.
+ * @return the current state
*/
- public static void setExceptionsThrownOnScriptError( boolean throwExceptions ) {
+ public static boolean setExceptionsThrownOnScriptError( boolean throwExceptions ) {
+ boolean current=_exceptionsThrownOnScriptError;
_exceptionsThrownOnScriptError = throwExceptions;
getScriptingEngine().setThrowExceptionsOnError( throwExceptions );
+ return current;
}
Modified: trunk/httpunit/src/com/meterware/httpunit/ParsedHTML.java
===================================================================
--- trunk/httpunit/src/com/meterware/httpunit/ParsedHTML.java 2009-08-19 10:08:00 UTC (rev 1041)
+++ trunk/httpunit/src/com/meterware/httpunit/ParsedHTML.java 2009-08-20 07:07:28 UTC (rev 1042)
@@ -97,6 +97,7 @@
* @return an array of objects representing the forms in the page or portion of a page.
**/
public WebForm[] getForms() {
+ loadElements();
HTMLCollection forms = ((HTMLContainerElement) _rootNode).getForms();
WebForm[] result = new WebForm[ forms.getLength() ];
for (int i = 0; i < result.length; i++) {
@@ -116,6 +117,7 @@
* Returns the links found in the page in the order in which they appear.
**/
public WebLink[] getLinks() {
+ loadElements();
HTMLCollection links = ((HTMLContainerElement) _rootNode).getLinks();
WebLink[] result = new WebLink[ links.getLength() ];
for (int i = 0; i < result.length; i++) {
@@ -133,6 +135,7 @@
* Returns a proxy for each applet found embedded in this page.
*/
public WebApplet[] getApplets() {
+ loadElements();
HTMLCollection applets = ((HTMLContainerElement) _rootNode).getApplets();
WebApplet[] result = new WebApplet[ applets.getLength() ];
for (int i = 0; i < result.length; i++) {
@@ -150,6 +153,7 @@
* Returns the images found in the page in the order in which they appear.
*/
public WebImage[] getImages() {
+ loadElements();
HTMLCollection images = ((HTMLContainerElement) _rootNode).getImages();
WebImage[] result = new WebImage[ images.getLength() ];
for (int i = 0; i < result.length; i++) {
@@ -167,6 +171,7 @@
* Returns the top-level block elements found in the page in the order in which they appear.
*/
public TextBlock[] getTextBlocks() {
+ loadElements();
if (_blocks == null) {
loadElements();
_blocks = (TextBlock[]) _blocksList.toArray( new TextBlock[ _blocksList.size() ] );
@@ -179,6 +184,7 @@
* Returns the first text block found in the page which matches the specified predicate and value.
*/
public TextBlock getFirstMatchingTextBlock( HTMLElementPredicate predicate, Object criteria ) {
+ loadElements();
TextBlock[] blocks = getTextBlocks();
for (int i = 0; i < blocks.length; i++) {
if (predicate.matchesCriteria( blocks[i], criteria )) return blocks[i];
@@ -187,7 +193,13 @@
}
+ /**
+ * get the next text block based on the given block
+ * @param block
+ * @return - the next text block
+ */
public TextBlock getNextTextBlock( TextBlock block ) {
+ loadElements();
int index = _blocksList.indexOf( block );
if (index < 0 || index == _blocksList.size() - 1) return null;
return (TextBlock) _blocksList.get( index+1 );
@@ -196,8 +208,10 @@
/**
* Returns the top-level tables found in the page in the order in which they appear.
+ * @return an array of tables
**/
public WebTable[] getTables() {
+ loadElements();
if (_tables == null) {
loadElements();
_tables = (WebTable[]) _tableList.toArray( new WebTable[ _tableList.size() ] );
Modified: trunk/httpunit/test/com/meterware/httpunit/WebFormTest.java
===================================================================
--- trunk/httpunit/test/com/meterware/httpunit/WebFormTest.java 2009-08-19 10:08:00 UTC (rev 1041)
+++ trunk/httpunit/test/com/meterware/httpunit/WebFormTest.java 2009-08-20 07:07:28 UTC (rev 1042)
@@ -65,6 +65,38 @@
"</form>" );
}
+ /**
+ * placeholder for test for BR 2407470 by redsonic with comment and patch by Adam Heath
+ *
+ */
+ public void testGetFormWithID() throws Exception {
+ defineWebPage( "OnCommand",
+ "<html>\n"+
+ " <head>\n"+
+ " <script type='JavaScript'>\n" +
+ " function function1() {\n"+
+ " alert( document.forms[0].name );\n" +
+ " }\n"+
+ " </script>\n" +
+ " </head>\n" +
+ " <body>\n"+
+ " <form id='form1' name='form1name'/>\n" +
+ " <form id='form2' name='form2name'/>\n" +
+ " <form id='form3' name='form3name'/>\n" +
+ " <body>\n"+
+ "</html>\n");
+ boolean oldstate = HttpUnitOptions.setExceptionsThrownOnScriptError(false);
+ try {
+ WebConversation wc = new WebConversation();
+ WebResponse wr=wc.getResponse( getHostPath() + "/OnCommand.html" );
+ WebForm form = wr.getFormWithID( "form3" );
+ assertTrue(form!=null);
+ } catch (Exception ex) {
+ throw ex;
+ } finally {
+ HttpUnitOptions.setExceptionsThrownOnScriptError(oldstate);
+ }
+ }
public void testSubmitFromForm() throws Exception {
defineWebPage( "Form", "<form method=GET id=main action = 'tryMe'>" +
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|