httpunit-commit Mailing List for httpunit (Page 46)
Brought to you by:
russgold
You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(5) |
Sep
(31) |
Oct
(39) |
Nov
(18) |
Dec
(6) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(8) |
Feb
(5) |
Mar
(8) |
Apr
(25) |
May
(20) |
Jun
(23) |
Jul
(28) |
Aug
(10) |
Sep
(3) |
Oct
(32) |
Nov
(61) |
Dec
(24) |
2002 |
Jan
(50) |
Feb
(34) |
Mar
(35) |
Apr
(3) |
May
(25) |
Jun
(25) |
Jul
(30) |
Aug
(146) |
Sep
(49) |
Oct
(156) |
Nov
(121) |
Dec
(54) |
2003 |
Jan
(12) |
Feb
(79) |
Mar
(88) |
Apr
(26) |
May
(67) |
Jun
(29) |
Jul
(8) |
Aug
(16) |
Sep
(20) |
Oct
(17) |
Nov
|
Dec
(5) |
2004 |
Jan
|
Feb
(40) |
Mar
(30) |
Apr
(5) |
May
|
Jun
(83) |
Jul
(34) |
Aug
(20) |
Sep
(44) |
Oct
(46) |
Nov
|
Dec
(14) |
2005 |
Jan
(4) |
Feb
|
Mar
(5) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(4) |
Oct
|
Nov
|
Dec
(1) |
2006 |
Jan
|
Feb
|
Mar
(26) |
Apr
(8) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(5) |
Nov
|
Dec
|
2008 |
Jan
|
Feb
|
Mar
|
Apr
(36) |
May
(38) |
Jun
(1) |
Jul
(1) |
Aug
|
Sep
(4) |
Oct
|
Nov
(18) |
Dec
(4) |
2009 |
Jan
|
Feb
(2) |
Mar
(3) |
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
(35) |
Sep
(1) |
Oct
|
Nov
|
Dec
(1) |
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
(9) |
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(21) |
Oct
(18) |
Nov
(1) |
Dec
|
From: Russell G. <rus...@us...> - 2002-10-25 09:44:46
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv7703/doc Modified Files: Javascript-support.html release_notes.txt Log Message: Support locales in servlet unit Index: Javascript-support.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/Javascript-support.html,v retrieving revision 1.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- Javascript-support.html 11 Oct 2002 01:26:22 -0000 1.25 +++ Javascript-support.html 25 Oct 2002 00:19:25 -0000 1.26 @@ -72,6 +72,11 @@ <li>location - a synonym for window.location</li> <li><name> - the name of a form, image, or link</li> </ul> +<h4>methods</h4> +<ul> +<li>write - writes a string to the contents of the current open document</li> +<li>writeln - writes a line with carriage-return to the contents of the current open document</li> +</ul> <h3>Form</h3> <h4>properties</h4> Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.201 retrieving revision 1.202 diff -u -r1.201 -r1.202 --- release_notes.txt 24 Oct 2002 13:28:52 -0000 1.201 +++ release_notes.txt 25 Oct 2002 00:19:25 -0000 1.202 @@ -16,6 +16,7 @@ Additions: 1. document.write and writeln are now supported for embedded uses + 2. ServletUnit now implements HttpServletRequest.getLocale() and getLocales() 22-Oct-2002 Acknowledgements: |
From: Russell G. <rus...@us...> - 2002-10-25 00:55:01
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv7703/src/com/meterware/servletunit Modified Files: ServletUnitHttpRequest.java Log Message: Support locales in servlet unit Index: ServletUnitHttpRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpRequest.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- ServletUnitHttpRequest.java 24 Oct 2002 13:28:54 -0000 1.16 +++ ServletUnitHttpRequest.java 25 Oct 2002 00:19:25 -0000 1.17 @@ -29,12 +29,7 @@ import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Vector; -import java.util.StringTokenizer; -import java.util.Map; -import java.util.Dictionary; +import java.util.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.Cookie; @@ -50,6 +45,7 @@ private ServletInputStreamImpl _inputStream; private String _contentType; + private Vector _locales; /** @@ -504,8 +500,8 @@ * Returns the preferred Locale that the client will accept content in, based on the Accept-Language header. * If the client request doesn't provide an Accept-Language header, this method returns the default locale for the server. **/ - public java.util.Locale getLocale() { - throw new RuntimeException( "getLocale not implemented" ); + public Locale getLocale() { + return (Locale) getPreferredLocales().firstElement(); } @@ -516,7 +512,34 @@ * method returns an Enumeration containing one Locale, the default locale for the server. **/ public java.util.Enumeration getLocales() { - throw new RuntimeException( "getLocales not implemented" ); + return getPreferredLocales().elements(); + } + + + /** + * Parses the accept-language header to obtain a vector of preferred locales + * @return the preferred locales, sorted by qvalue + */ + private Vector getPreferredLocales() { + if (_locales == null) { + _locales = new Vector(); + String languages = getHeader( "accept-language" ); + if (languages == null) { + _locales.add( Locale.getDefault() ); + } else { + StringTokenizer st = new StringTokenizer( languages, "," ); + ArrayList al = new ArrayList(); + while (st.hasMoreTokens()) { + String token = st.nextToken(); + al.add( new PrioritizedLocale( token ) ); + } + Collections.sort( al ); + for (Iterator iterator = al.iterator(); iterator.hasNext();) { + _locales.add( ((PrioritizedLocale) iterator.next()).getLocale() ); + } + } + } + return _locales; } @@ -800,5 +823,49 @@ private void throwNotImplementedYet() { throw new RuntimeException( "Not implemented yet" ); + } + + + static class PrioritizedLocale implements Comparable { + + private Locale _locale; + private float _priority; + + + PrioritizedLocale( String languageSpec ) { + int semiIndex = languageSpec.indexOf( ';' ); + if (semiIndex < 0) { + _priority = 1; + _locale = parseLocale( languageSpec ); + } else { + _priority = Float.parseFloat( languageSpec.substring( languageSpec.indexOf( '=', semiIndex )+1 ) ); + _locale = parseLocale( languageSpec.substring( 0, semiIndex ) ); + } + } + + + private Locale parseLocale( String range ) { + range = range.trim(); + int dashIndex = range.indexOf( '-' ); + if (dashIndex < 0) { + return new Locale( range ); + } else { + return new Locale( range.substring( 0, dashIndex ), range.substring( dashIndex+1 ) ); + } + } + + + public Locale getLocale() { + return _locale; + } + + + public int compareTo( Object o ) { + if (!(o instanceof PrioritizedLocale)) throw new IllegalArgumentException( "may only combine with other prioritized locales" ); + PrioritizedLocale other = (PrioritizedLocale) o; + return _priority == other._priority ? _locale.getLanguage().compareTo( other._locale.getLanguage() ) + : (_priority < other._priority ? +1 : -1 ); + } + } } |
From: Russell G. <rus...@us...> - 2002-10-25 00:55:00
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv7703/test/com/meterware/servletunit Modified Files: HttpServletRequestTest.java Log Message: Support locales in servlet unit Index: HttpServletRequestTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/HttpServletRequestTest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- HttpServletRequestTest.java 28 Aug 2002 15:05:08 -0000 1.8 +++ HttpServletRequestTest.java 25 Oct 2002 00:19:25 -0000 1.9 @@ -22,6 +22,7 @@ import java.util.Enumeration; import java.util.Hashtable; import java.util.Map; +import java.util.Locale; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; @@ -234,6 +235,38 @@ wr = new GetMethodWebRequest( "http://localhost/simple?foo=bar" ); request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, context, new Hashtable(), NO_MESSAGE_BODY ); assertEquals("/simple", request.getRequestURI()); + } + + + public void testDefaultLocale() throws Exception { + WebRequest wr = new GetMethodWebRequest( "http://localhost/simple"); + + ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY ); + Locale[] expectedLocales = new Locale[] { Locale.getDefault() }; + verifyLocales( request, expectedLocales ); + + } + + private void verifyLocales(ServletUnitHttpRequest request, Locale[] expectedLocales) { + assertNotNull( "No default locale found", request.getLocale() ); + assertEquals( "default locale", expectedLocales[0], request.getLocale() ); + + final Enumeration locales = request.getLocales(); + assertNotNull( "local enumeration not returned", locales ); + for (int i = 0; i < expectedLocales.length; i++) { + assertTrue( "Expected " + expectedLocales.length + " locales, only found " + i, locales.hasMoreElements() ); + assertEquals( "Locale #" + (i+1), expectedLocales[i], locales.nextElement() ); + } + assertFalse( "Too many locales returned", locales.hasMoreElements() ); + } + + + public void testSpecifiedLocales() throws Exception { + WebRequest wr = new GetMethodWebRequest( "http://localhost/simple"); + wr.setHeaderField( "Accept-language", "fr, en;q=0.6, en-us;q=0.7" ); + + ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY ); + verifyLocales( request, new Locale[] { Locale.FRENCH, Locale.US, Locale.ENGLISH } ); } |
From: Russell G. <rus...@us...> - 2002-10-24 13:29:27
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv28243/doc Modified Files: release_notes.txt Log Message: Added support for document.write Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.200 retrieving revision 1.201 diff -u -r1.200 -r1.201 --- release_notes.txt 22 Oct 2002 22:59:24 -0000 1.200 +++ release_notes.txt 24 Oct 2002 13:28:52 -0000 1.201 @@ -10,7 +10,14 @@ Revision History: -22-Oct-22 +24-Oct-2002 +Acknowledgements: + Thanks to Andy Clark for help using the NekoHTML filter capability. + +Additions: + 1. document.write and writeln are now supported for embedded uses + +22-Oct-2002 Acknowledgements: Thanks to Troy Waldrep for help with the new handling of response statuses and messages. |
From: Russell G. <rus...@us...> - 2002-10-24 13:29:00
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv28243/test/com/meterware/httpunit/javascript Modified Files: DocumentScriptingTest.java ScriptingTest.java Log Message: Added support for document.write Index: DocumentScriptingTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/DocumentScriptingTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- DocumentScriptingTest.java 9 Oct 2002 13:50:10 -0000 1.2 +++ DocumentScriptingTest.java 24 Oct 2002 13:28:55 -0000 1.3 @@ -44,7 +44,7 @@ defineResource( "OnCommand.html", "<html><head><title>Amazing!</title></head>" + "<body onLoad='alert(\"Window title is \" + document.title)'></body>" ); WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + wc.getResponse( getHostPath() + "/OnCommand.html" ); assertEquals( "Alert message", "Window title is Amazing!", wc.popNextAlert() ); } @@ -64,7 +64,7 @@ "<form name='realform'></form>" + "</body></html>" ); WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + wc.getResponse( getHostPath() + "/OnCommand.html" ); assertEquals( "Alert message", "found 1 form(s)", wc.popNextAlert() ); assertEquals( "Alert message", "found form 'realform'", wc.popNextAlert() ); assertEquals( "Alert message", "found form 'forms[\'realform\']'", wc.popNextAlert() ); @@ -90,7 +90,7 @@ "<a href='else'>second</a>" + "</body></html>" ); WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + wc.getResponse( getHostPath() + "/OnCommand.html" ); assertEquals( "Alert message", "found 2 link(s)", wc.popNextAlert() ); assertEquals( "Alert message", "found link 'reallink'", wc.popNextAlert() ); assertEquals( "Alert message", "found link 'links[reallink]'", wc.popNextAlert() ); @@ -99,6 +99,23 @@ } + public void testEmbeddedDocumentWrite() throws Exception { + defineResource( "OnCommand.html", "<html><head><title>something</title></head>" + + "<body>" + + "<script language='JavaScript'>" + + "document.write( '<a id=here href=about:blank>' );" + + "document.write( document.title );" + + "document.write( '</a>' );" + + "</script>" + + "</body></html>" ); + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + WebLink link = response.getLinkWithID( "here" ); + assertNotNull( "The link was not found", link ); + assertEquals( "Link contents", "something", link.asText() ); + } + + public void testJavaScriptObjectIdentity() throws Exception { defineResource( "OnCommand.html", "<html><head><script language='JavaScript'>" + "function compareLinks() { " + @@ -114,7 +131,7 @@ "<a href='else'>second</a>" + "</body></html>" ); WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + wc.getResponse( getHostPath() + "/OnCommand.html" ); assertEquals( "Alert message", "they are the same", wc.popNextAlert() ); } @@ -129,7 +146,6 @@ "</body></html>" ); WebConversation wc = new WebConversation(); WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); - WebForm form = response.getFormWithName( "realform" ); response.getLinkWithName( "first" ).mouseOver(); assertEquals( "form action", "run", wc.popNextAlert() ); response.getLinkWithName( "second" ).mouseOver(); @@ -220,7 +236,7 @@ "<a href='sample.html'>green</a>" + "</body></html>" ); WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + wc.getResponse( getHostPath() + "/OnCommand.html" ); assertEquals( "Alert message", getHostPath() + "/demo.html", wc.popNextAlert() ); assertEquals( "Alert message", getHostPath() + "/guide.html", wc.popNextAlert() ); assertEquals( "Alert message", getHostPath() + "/search.html", wc.popNextAlert() ); @@ -246,7 +262,7 @@ "<img name='2ndimage' src='pict2.gif'>\n" + "</body></html>" ); WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + wc.getResponse( getHostPath() + "/OnCommand.html" ); assertEquals( "Alert message", "found 2 images(s)", wc.popNextAlert() ); assertEquals( "Alert message", "found image 'realimage'", wc.popNextAlert() ); assertEquals( "Alert message", "found image 'images[realimage]'", wc.popNextAlert() ); Index: ScriptingTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/ScriptingTest.java,v retrieving revision 1.40 retrieving revision 1.41 diff -u -r1.40 -r1.41 --- ScriptingTest.java 13 Oct 2002 01:09:32 -0000 1.40 +++ ScriptingTest.java 24 Oct 2002 13:28:55 -0000 1.41 @@ -78,7 +78,7 @@ WebConversation wc = new WebConversation(); GetMethodWebRequest request = new GetMethodWebRequest( "javascript:alert( 'Hi there!' )" ); assertEquals( "Javascript URL", "javascript:alert( 'Hi there!' )", request.getURL().toExternalForm() ); - WebResponse response = wc.getResponse( request ); + wc.getResponse( request ); assertEquals( "Alert message", "Hi there!", wc.popNextAlert() ); } @@ -131,7 +131,7 @@ defineResource( "OnCommand.html", "<html><head></head>" + "<body onLoad='alert(\"Ouch!\")'></body>" ); WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + wc.getResponse( getHostPath() + "/OnCommand.html" ); assertNotNull( "No alert detected", wc.getNextAlert() ); assertEquals( "Alert message", "Ouch!", wc.popNextAlert() ); assertNull( "Alert should have been removed", wc.getNextAlert() ); @@ -206,7 +206,7 @@ "// end hiding -->" + "</script></body></html>" ); WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + wc.getResponse( getHostPath() + "/OnCommand.html" ); assertEquals( "Alert message", "Cheese!", wc.popNextAlert() ); } @@ -218,7 +218,7 @@ "parseInt(n,32);" + "</script></head></html>" ); WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + wc.getResponse( getHostPath() + "/OnCommand.html" ); } @@ -228,7 +228,7 @@ "</script></head>" + "<body onLoad='sayCheese()'></body>" ); WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + wc.getResponse( getHostPath() + "/OnCommand.html" ); assertEquals( "Alert message", "Cheese!", wc.popNextAlert() ); } @@ -321,7 +321,6 @@ "<body onload=\"window.name='main'; alert ('opener ' + (window.opener ? 'found' : 'not defined') );\">" + "<a href='#' onClick=\"window.open( '" + getHostPath() + "/Target.html', 'sample' );\">go</a>" + "</body></html>" ); - final ArrayList windowsOpened = new ArrayList(); WebConversation wc = new WebConversation(); WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); assertEquals( "main window name", "main", wc.getMainWindow().getName() ); @@ -357,7 +356,7 @@ "</frameset></html>" ); WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + "/Frames.html" ); + wc.getResponse( getHostPath() + "/Frames.html" ); WebResponse blue = wc.getFrameContents( "blue" ); blue.getLinkWith( "show" ).click(); @@ -427,7 +426,7 @@ WebConversation wc = new WebConversation(); wc.getClientProperties().setApplicationID( "Internet Explorer", "Mozilla", "4.0" ); wc.getClientProperties().setPlatform( "JVM" ); - WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + wc.getResponse( getHostPath() + "/OnCommand.html" ); assertEquals( "Alert message 1", "appName=Internet Explorer", wc.popNextAlert() ); assertEquals( "Alert message 2", "appCodeName=Mozilla", wc.popNextAlert() ); assertEquals( "Alert message 3", "appVersion=4.0", wc.popNextAlert() ); @@ -450,7 +449,7 @@ HttpUnitOptions.setExceptionsThrownOnScriptError( true ); WebConversation wc = new WebConversation(); wc.getClientProperties().setAvailableScreenSize( 1024, 752 ); - WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + wc.getResponse( getHostPath() + "/OnCommand.html" ); assertEquals( "Alert message 1", "dimensions=1024x752", wc.popNextAlert() ); assertNull( "Alert should have been removed", wc.getNextAlert() ); } |
From: Russell G. <rus...@us...> - 2002-10-24 13:28:59
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv28243/test/com/meterware/httpunit Modified Files: WebClientTest.java WebFormTest.java Log Message: Added support for document.write Index: WebClientTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebClientTest.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- WebClientTest.java 17 Oct 2002 23:50:51 -0000 1.9 +++ WebClientTest.java 24 Oct 2002 13:28:55 -0000 1.10 @@ -54,11 +54,6 @@ super( name ); } - public void testNothing() { - new WebConversation(); // XXX delete me!!! - } - - public void testCookies() throws Exception { String resourceName = "something/baking"; String resourceValue = "the desired content"; Index: WebFormTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFormTest.java,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- WebFormTest.java 15 Oct 2002 01:07:29 -0000 1.27 +++ WebFormTest.java 24 Oct 2002 13:28:55 -0000 1.28 @@ -22,15 +22,11 @@ import com.meterware.pseudoserver.PseudoServlet; import com.meterware.pseudoserver.WebResource; -import java.net.URL; import java.net.HttpURLConnection; import junit.framework.Test; -import junit.framework.TestCase; import junit.framework.TestSuite; -import java.util.Vector; - /** * A test of the web form functionality. @@ -214,7 +210,7 @@ } - // XXX turn this back on when Tidy handles it properly + // XXX turn this back on when the parser handles it properly public void notestNullTextValues() throws Exception { defineWebPage( "Default", "<form method=POST action = \"/servlet/Login\">" + "<Input name=\"secret\" type=\"hidden\" value=>" + @@ -251,7 +247,6 @@ assertMatchingSet( "parameter names", new String[] { "name","sex" }, parameterNames ); assertEquals( "Default name", "", form.getParameterValue( "name" ) ); assertEquals( "Default sex", "female", form.getParameterValue( "sex" ) ); - WebRequest request = form.getRequest(); form.setParameter( "sex", "neuter" ); assertEquals( "New value for sex", "neuter", form.getParameterValue( "sex" ) ); @@ -363,8 +358,7 @@ WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); WebForm form = page.getForms()[0]; - String[] parameterNames = form.getParameterNames(); - assertEquals( "inferred color default", "blue", form.getParameterValue( "colors" ) ); + assertEquals( "inferred color default", "blue", form.getParameterValue( "colors" ) ); assertEquals( "inferred fish default", "red", form.getParameterValue( "fish" ) ); assertMatchingSet( "inferred media default", new String[0], form.getParameterValues( "media" ) ); @@ -439,7 +433,6 @@ "<input type=text name=name><input type=submit></form></body></html>" ); defineResource( "SayHello?speed=fast", new PseudoServlet() { public WebResource getPostResponse() { - String name = getParameter( "name" )[0]; WebResource result = new WebResource( "<html><body><table><tr><td>Hello, there" + "</td></tr></table></body></html>" ); return result; @@ -470,10 +463,7 @@ "<input type=text name=name><input type=submit></form></body></html>" ); defineResource( sessionID + "/SayHello", new PseudoServlet() { public WebResource getPostResponse() { - String name = getParameter( "name" )[0]; - WebResource result = new WebResource( "<html><body><table><tr><td>Hello, there" + - "</td></tr></table></body></html>" ); - return result; + return new WebResource( "<html><body><table><tr><td>Hello, there</td></tr></table></body></html>" ); } } ); |
From: Russell G. <rus...@us...> - 2002-10-24 13:28:59
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/scripting In directory usw-pr-cvs1:/tmp/cvs-serv28243/src/com/meterware/httpunit/scripting Modified Files: ScriptableDelegate.java ScriptingEngine.java Log Message: Added support for document.write Index: ScriptableDelegate.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/scripting/ScriptableDelegate.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ScriptableDelegate.java 13 Oct 2002 23:53:48 -0000 1.5 +++ ScriptableDelegate.java 24 Oct 2002 13:28:54 -0000 1.6 @@ -29,8 +29,9 @@ private ScriptingEngine _scriptEngine; + private static final ScriptingEngine NULL_SCRIPT_ENGINE = new ScriptingEngine() { - public void executeScript( String script ) {} + public String executeScript( String script ) { return ""; } public boolean performEvent( String eventScript ) { return true; } public String getURLContents( String urlString ) { return null; } public ScriptingEngine newScriptingEngine( ScriptableDelegate child ) { return this; } @@ -47,10 +48,11 @@ /** - * Executes the specified script. + * Executes the specified script, returning any intended replacement text. + * @return the replacement text, which may be empty. **/ - public void runScript( String script ) { - if (script.length() != 0) getScriptEngine().executeScript( script ); + public String runScript( String script ) { + return (script.length() == 0) ? "" : getScriptEngine().executeScript( script ); } Index: ScriptingEngine.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/scripting/ScriptingEngine.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ScriptingEngine.java 13 Oct 2002 23:53:48 -0000 1.3 +++ ScriptingEngine.java 24 Oct 2002 13:28:54 -0000 1.4 @@ -31,7 +31,7 @@ /** * Interprets the specified script, which may include global function definitions. */ - public void executeScript( String script ); + public String executeScript( String script ); /** |
From: Russell G. <rus...@us...> - 2002-10-24 13:28:59
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv28243/src/com/meterware/httpunit/javascript Modified Files: JavaScript.java Log Message: Added support for document.write Index: JavaScript.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- JavaScript.java 22 Oct 2002 20:15:34 -0000 1.33 +++ JavaScript.java 24 Oct 2002 13:28:54 -0000 1.34 @@ -102,16 +102,30 @@ protected ScriptableDelegate _scriptable; - public void executeScript( String script ) { + public String executeScript( String script ) { try { script = script.trim(); if (script.startsWith( "<!--" )) script = withoutFirstLine( script ); Context.getCurrentContext().evaluateString( this, script, "httpunit", 0, null ); + StringBuffer buffer = getDocumentWriteBuffer(); + return buffer.toString(); } catch (Exception e) { handleScriptException( e, "Script '" + script + "'" ); + return ""; + } finally { + Context.getCurrentContext().removeThreadLocal( "stream" ); } } + protected StringBuffer getDocumentWriteBuffer() { + StringBuffer buffer = (StringBuffer) Context.getCurrentContext().getThreadLocal( "stream" ); + if (buffer == null) { + buffer = new StringBuffer(); + Context.getCurrentContext().putThreadLocal( "stream", buffer ); + } + return buffer; + } + private String withoutFirstLine( String script ) { for (int i=0; i < script.length(); i++) { @@ -139,6 +153,7 @@ } } + /** * Evaluates the specified string as JavaScript. Will return null if the script has no return value. */ @@ -237,7 +252,6 @@ public ScriptingEngine newScriptingEngine( ScriptableDelegate child ) { try { -// return (JavaScriptEngine) Context.getCurrentContext().newObject( this, getScriptableClassName( child ) ); return (ScriptingEngine) toScriptable( child ); } catch (Exception e) { e.printStackTrace(); @@ -432,6 +446,18 @@ public Scriptable jsGet_forms() throws SAXException { if (_forms == null) initializeForms(); return _forms; + } + + + public void jsFunction_write( String string ) { + final StringBuffer documentWriteBuffer = getDocumentWriteBuffer(); + documentWriteBuffer.append( string ); + } + + + public void jsFunction_writeln( String string ) { + final StringBuffer documentWriteBuffer = getDocumentWriteBuffer(); + documentWriteBuffer.append( string ).append( 0x0D ); } |
From: Russell G. <rus...@us...> - 2002-10-24 13:28:59
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv28243/src/com/meterware/servletunit Modified Files: ServletUnitHttpRequest.java Log Message: Added support for document.write Index: ServletUnitHttpRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpRequest.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- ServletUnitHttpRequest.java 28 Aug 2002 15:05:07 -0000 1.15 +++ ServletUnitHttpRequest.java 24 Oct 2002 13:28:54 -0000 1.16 @@ -27,8 +27,6 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.UnsupportedEncodingException; -import java.io.ByteArrayOutputStream; -import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.Enumeration; @@ -449,7 +447,7 @@ /** * * @deprecated As of Version 2.1 of the Java Servlet API, - * use {@link ServletContext#getRealPath} instead. + * use {@link javax.servlet.ServletContext#getRealPath} instead. * */ public String getRealPath( String path ) { |
From: Russell G. <rus...@us...> - 2002-10-24 13:28:59
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv28243/src/com/meterware/httpunit Modified Files: FrameHolder.java HTMLPage.java HTMLParser.java JTidyHTMLParser.java MimeEncodedMessageBody.java NekoHTMLParser.java ParsedHTML.java WebResponse.java Added Files: ScriptFilter.java Log Message: Added support for document.write ***** Error reading new file[Errno 2] No such file or directory: 'ScriptFilter.java' Index: FrameHolder.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FrameHolder.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- FrameHolder.java 10 Oct 2002 22:44:34 -0000 1.5 +++ FrameHolder.java 24 Oct 2002 13:28:53 -0000 1.6 @@ -79,10 +79,10 @@ _contents.put( target, response ); if (response.isHTML()) { + HttpUnitOptions.getScriptingEngine().associate( response ); createSubFrames( target, response.getFrameNames() ); WebRequest[] requests = response.getFrameRequests(); for (int i = 0; i < requests.length; i++) response.getWindow().getResponse( requests[ i ] ); - HttpUnitOptions.getScriptingEngine().associate( response ); } } Index: HTMLPage.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HTMLPage.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- HTMLPage.java 14 Oct 2002 04:19:06 -0000 1.13 +++ HTMLPage.java 24 Oct 2002 13:28:53 -0000 1.14 @@ -45,9 +45,8 @@ private Scriptable _scriptable; - HTMLPage( WebResponse response, URL url, String parentTarget, String pageText, String characterSet ) throws IOException, SAXException { - super( response, url, parentTarget, getDOM( url, pageText ), characterSet ); - setBaseAttributes(); + HTMLPage( WebResponse response, URL url, String parentTarget, String characterSet ) throws IOException, SAXException { + super( response, url, parentTarget, null, characterSet ); } @@ -80,13 +79,12 @@ ArrayList scripts = new ArrayList(); for (int i = 0; i < nl.getLength(); i++) { Node scriptNode = nl.item(i); - String src = NodeUtils.getNodeAttribute( scriptNode, "src", null ); - if (src == null) { + String scriptLocation = NodeUtils.getNodeAttribute( scriptNode, "src", null ); + if (scriptLocation == null) { scripts.add( NodeUtils.asText( scriptNode.getChildNodes() ) ); } else { try { - WebRequest req = new GetMethodWebRequest( getBaseURL(), src ); - scripts.add( getResponse().getWindow().getResource( req ).getText() ); + scripts.add( getIncludedScript( scriptLocation ) ); } catch (IOException e) { throw new RuntimeException( "Error loading included script: " + e ); } @@ -97,6 +95,18 @@ /** + * Returns the contents of an included script, given its src attribute. + * @param srcAttribute + * @return the contents of the script. + * @throws IOException if there is a problem retrieving the script + */ + String getIncludedScript( String srcAttribute ) throws IOException { + WebRequest req = new GetMethodWebRequest( getBaseURL(), srcAttribute ); + return getResponse().getWindow().getResource( req ).getText(); + } + + + /** * Returns the location of the linked stylesheet in the head * <code> * <link type="text/css" rel="stylesheet" href="/mystyle.css" /> @@ -182,7 +192,12 @@ } else { super.set( propertyName, value ); } - } + } + + + public WebResponse.Scriptable getParent() { + return getResponse().getScriptableObject(); + } public String getTitle() throws SAXException { @@ -232,15 +247,18 @@ return _scriptable; } -//---------------------------------- private members -------------------------------- - private static Node getDOM( URL url, String pageText ) throws IOException, SAXException { - return HttpUnitOptions.getHTMLParser().getDocument( url, pageText ); + public void parse( String text ) throws SAXException, IOException { + HttpUnitOptions.getHTMLParser().parse( this, getBaseURL(), text ); + setBaseAttributes(); } - private void setBaseAttributes() throws SAXException { +//---------------------------------- private members -------------------------------- + + + private void setBaseAttributes() { NodeList nl = ((Document) getOriginalDOM()).getElementsByTagName( "base" ); if (nl.getLength() == 0) return; try { Index: HTMLParser.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HTMLParser.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- HTMLParser.java 14 Oct 2002 04:19:06 -0000 1.1 +++ HTMLParser.java 24 Oct 2002 13:28:53 -0000 1.2 @@ -32,10 +32,10 @@ interface HTMLParser { /** - * Converts an HTML text string to a Document. Any error reporting will be annotated with the - * specified URL. + * Parses the specified text string as a Document, registering it in the HTMLPage. + * Any error reporting will be annotated with the specified URL. */ - public Node getDocument( URL url, String pageText ) throws IOException, SAXException; + public void parse( HTMLPage page, URL baseURL, String pageText ) throws IOException, SAXException; /** Index: JTidyHTMLParser.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/JTidyHTMLParser.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- JTidyHTMLParser.java 14 Oct 2002 04:19:06 -0000 1.1 +++ JTidyHTMLParser.java 24 Oct 2002 13:28:53 -0000 1.2 @@ -33,11 +33,12 @@ * * @author <a href="mailto:rus...@ht...">Russell Gold</a> **/ -public class JTidyHTMLParser implements HTMLParser { +class JTidyHTMLParser implements HTMLParser { - public Node getDocument( URL url, String pageText ) throws IOException, SAXException { + + public void parse( HTMLPage page, URL baseURL, String pageText ) throws IOException, SAXException { try { - return getParser( url ).parseDOM( new ByteArrayInputStream( pageText.getBytes( UTF_ENCODING ) ), null ); + page.setRootNode( getParser( baseURL ).parseDOM( new ByteArrayInputStream( pageText.getBytes( UTF_ENCODING ) ), null ) ); } catch (UnsupportedEncodingException e) { throw new RuntimeException( "UTF-8 encoding failed" ); } Index: MimeEncodedMessageBody.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/MimeEncodedMessageBody.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- MimeEncodedMessageBody.java 20 May 2002 16:00:43 -0000 1.12 +++ MimeEncodedMessageBody.java 24 Oct 2002 13:28:53 -0000 1.13 @@ -70,7 +70,7 @@ StringBuffer sb = new StringBuffer(chars.length+20); for (int i = 0; i < chars.length; i++ ) { if (chars[i] == '\\') { - sb.append( "\\\\" ); // accomodate MS-DOS file paths XXX is this safe?? + sb.append( "\\\\" ); // accomodate MS-DOS file paths ??? is this safe?? } else { sb.append( chars[i] ); } Index: NekoHTMLParser.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/NekoHTMLParser.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- NekoHTMLParser.java 14 Oct 2002 04:19:06 -0000 1.1 +++ NekoHTMLParser.java 24 Oct 2002 13:28:53 -0000 1.2 @@ -19,25 +19,38 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ -import org.w3c.dom.Node; +import org.apache.xerces.xni.parser.XMLDocumentFilter; + +import org.cyberneko.html.HTMLConfiguration; + import org.xml.sax.SAXException; import org.xml.sax.InputSource; -import org.cyberneko.html.parsers.DOMParser; +import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.SAXNotSupportedException; +import org.w3c.dom.Node; +import org.w3c.dom.Document; import java.net.URL; import java.io.IOException; import java.io.StringReader; +import com.meterware.httpunit.scripting.ScriptableDelegate; + /** * * @author <a href="mailto:rus...@ht...">Russell Gold</a> **/ -public class NekoHTMLParser implements HTMLParser { +class NekoHTMLParser implements HTMLParser { + - public Node getDocument( URL url, String pageText ) throws IOException, SAXException { - DOMParser parser = new DOMParser(); - parser.parse( new InputSource( new StringReader( pageText ) ) ); - return parser.getDocument(); + public void parse( HTMLPage page, URL baseURL, String pageText ) throws IOException, SAXException { + try { + DOMParser parser = DOMParser.newParser(page); + parser.parse( new InputSource( new StringReader( pageText ) ) ); + page.setRootNode( parser.getDocument() ); + } catch (DOMParser.ScriptException e) { + throw e.getException(); + } } @@ -46,4 +59,92 @@ } final private static char NBSP = (char) 160; // non-breaking space, defined by nekoHTML +} + + +class DOMParser extends org.apache.xerces.parsers.DOMParser { + + private static final String HTML_DOCUMENT_CLASS_NAME = "org.apache.html.dom.HTMLDocumentImpl"; + + /** Augmentations feature identifier. */ + protected static final String AUGMENTATIONS = "http://cyberneko.org/html/features/augmentations"; + + /** Filters property identifier. */ + protected static final String FILTERS = "http://cyberneko.org/html/properties/filters"; + + + private HTMLPage _htmlPage; + private ScriptableDelegate _scriptableObject; + + + static DOMParser newParser( HTMLPage page ) { + final HTMLConfiguration configuration = new HTMLConfiguration(); + configuration.setFeature( AUGMENTATIONS, true ); + final ScriptFilter javaScriptFilter = new ScriptFilter( configuration ); + configuration.setProperty( FILTERS, new XMLDocumentFilter[] { javaScriptFilter } ); + final DOMParser domParser = new DOMParser( configuration, page ); + javaScriptFilter.setParser( domParser ); + return domParser; + } + + + ScriptableDelegate getScriptableDelegate() { + if (_scriptableObject == null) { + Node node = getCurrentElementNode(); + while (!(node instanceof Document)) node = node.getParentNode(); + _htmlPage.setRootNode( node ); + _scriptableObject = _htmlPage.getScriptableObject().getParent(); + } + return _scriptableObject; + } + + + private Node getCurrentElementNode() { + try { + final Node node = (Node) getProperty( CURRENT_ELEMENT_NODE ); + return node; + } catch (SAXNotRecognizedException e) { + throw new RuntimeException( CURRENT_ELEMENT_NODE + " property not recognized" ); + } catch (SAXNotSupportedException e) { + e.printStackTrace(); + throw new RuntimeException( CURRENT_ELEMENT_NODE + " property not supported" ); + } + } + + + String getIncludedScript( String srcAttribute ) { + try { + return _htmlPage.getIncludedScript( srcAttribute ); + } catch (IOException e) { + throw new ScriptException( e ); + } + } + + + DOMParser( HTMLConfiguration configuration, HTMLPage page ) { + super( configuration ); + _htmlPage = page; + + try { + setFeature( DEFER_NODE_EXPANSION, false ); + setProperty( DOCUMENT_CLASS_NAME, HTML_DOCUMENT_CLASS_NAME ); + } catch (SAXNotRecognizedException e) { + throw new RuntimeException( e.toString() ); + } catch (SAXNotSupportedException e) { + throw new RuntimeException( e.toString() ); + } + } + + + static class ScriptException extends RuntimeException { + private IOException _cause; + + public ScriptException( IOException cause ) { + _cause = cause; + } + + public IOException getException() { + return _cause; + } + } } Index: ParsedHTML.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v retrieving revision 1.32 retrieving revision 1.33 diff -u -r1.32 -r1.33 --- ParsedHTML.java 22 Oct 2002 22:59:25 -0000 1.32 +++ ParsedHTML.java 24 Oct 2002 13:28:53 -0000 1.33 @@ -60,7 +60,7 @@ **/ public WebForm[] getForms() { if (_forms == null) { - NodeList forms = NodeUtils.getElementsByTagName( _rootNode, "form" ); + NodeList forms = NodeUtils.getElementsByTagName( getRootNode(), "form" ); _forms = new WebForm[ forms.getLength() ]; for (int i = 0; i < _forms.length; i++) { @@ -103,7 +103,7 @@ public WebLink[] getLinks() { if (_links == null) { final ArrayList list = new ArrayList(); - NodeUtils.processNodes( _rootNode.getChildNodes(), new NodeUtils.NodeAction() { + NodeUtils.processNodes( getRootNode().getChildNodes(), new NodeUtils.NodeAction() { public boolean processElement( Element element ) { if (element.getNodeName().equalsIgnoreCase( "a" )) addLinkAnchor( list, element ); else if (element.getNodeName().equalsIgnoreCase( "area" )) addLinkAnchor( list, element ); @@ -189,7 +189,7 @@ **/ public WebImage[] getImages() { if (_images == null) { - NodeList images = NodeUtils.getElementsByTagName( _rootNode, "img" ); + NodeList images = NodeUtils.getElementsByTagName( getRootNode(), "img" ); _images = new WebImage[ images.getLength() ]; for (int i = 0; i < _images.length; i++) { @@ -302,17 +302,9 @@ * Returns a copy of the domain object model associated with this page. **/ public Node getDOM() { - return _rootNode.cloneNode( /* deep */ true ); + return getRootNode().cloneNode( /* deep */ true ); } - /** - * Returns the domain object model associated with this page, to be used internally. - **/ - Node getOriginalDOM() { - return _rootNode; - } - - //---------------------------------- Object methods -------------------------------- @@ -341,10 +333,31 @@ } + + protected Node getRootNode() { + if (_rootNode == null) throw new IllegalStateException( "The root node has not been specified" ); + return _rootNode; + } + + //---------------------------------- package members -------------------------------- /** + * Specifies the root node for this HTML fragment. + */ + protected void setRootNode( Node rootNode ) { + if (_rootNode != null && rootNode != _rootNode ) + throw new IllegalStateException( "The root node has already been defined as " + _rootNode + " and cannot be redefined as " + rootNode ); + _rootNode = rootNode; + + _links = null; + _forms = null; + _images = null; + } + + + /** * Returns the base URL for this HTML segment. **/ URL getBaseURL() { @@ -354,6 +367,14 @@ WebResponse getResponse() { return _response; + } + + + /** + * Returns the domain object model associated with this page, to be used internally. + **/ + Node getOriginalDOM() { + return getRootNode(); } Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.93 retrieving revision 1.94 diff -u -r1.93 -r1.94 --- WebResponse.java 17 Oct 2002 23:50:49 -0000 1.93 +++ WebResponse.java 24 Oct 2002 13:28:53 -0000 1.94 @@ -21,14 +21,12 @@ *******************************************************************************************************************/ import com.meterware.httpunit.scripting.ScriptableDelegate; import com.meterware.httpunit.cookies.CookieJar; -import com.meterware.httpunit.cookies.Cookie; import com.meterware.httpunit.cookies.CookieSource; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; -import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; import java.util.zip.GZIPInputStream; @@ -916,7 +914,8 @@ if (_page == null) { try { if (!isHTML()) throw new NotHTMLException( getContentType() ); - _page = new HTMLPage( this, _url, _frameName, getText(), getCharacterSet() ); + _page = new HTMLPage( this, _url, _frameName, getCharacterSet() ); + _page.parse( getText() ); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException( e.toString() ); |
From: Russell G. <rus...@us...> - 2002-10-22 22:59:29
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv12991/src/com/meterware/httpunit Modified Files: HttpWebResponse.java ParsedHTML.java Log Message: Corrected logic of response status workaround logic Index: HttpWebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpWebResponse.java,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- HttpWebResponse.java 22 Oct 2002 15:12:54 -0000 1.27 +++ HttpWebResponse.java 22 Oct 2002 22:59:25 -0000 1.28 @@ -133,7 +133,7 @@ private void readResponseHeader( HttpURLConnection connection ) throws IOException { - if (needStatusWorkaround()) { + if (!needStatusWorkaround()) { _responseCode = connection.getResponseCode(); _responseMessage = connection.getResponseMessage(); } else { Index: ParsedHTML.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v retrieving revision 1.31 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- ParsedHTML.java 14 Oct 2002 04:19:06 -0000 1.31 +++ ParsedHTML.java 22 Oct 2002 22:59:25 -0000 1.32 @@ -19,21 +19,30 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ -import java.net.URL; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; -import java.util.Vector; +import java.net.URL; import java.util.ArrayList; -import org.w3c.dom.*; - /** * @author <a href="mailto:rus...@ht...">Russell Gold</a> * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a> **/ class ParsedHTML { + private Node _rootNode; + + private URL _baseURL; + + private String _baseTarget; + + private String _characterSet; + private WebForm[] _forms; private WebImage[] _images; + private WebLink[] _links; private WebResponse _response; @@ -64,7 +73,6 @@ /** * Returns the form found in the page with the specified ID. - * @exception SAXException thrown if there is an error parsing the response. **/ public WebForm getFormWithID( String ID ) { WebForm[] forms = getForms(); @@ -78,8 +86,7 @@ /** * Returns the form found in the page with the specified name. - * @exception SAXException thrown if there is an error parsing the response. - **/ + **/ public WebForm getFormWithName( String name ) { WebForm[] forms = getForms(); for (int i = 0; i < forms.length; i++) { @@ -300,7 +307,6 @@ /** * Returns the domain object model associated with this page, to be used internally. - * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a> **/ Node getOriginalDOM() { return _rootNode; @@ -352,22 +358,6 @@ //---------------------------------- private members -------------------------------- - - private Node _rootNode; - - private WebLink[] _links; - - private URL _baseURL; - - private String _baseTarget; - - private String _characterSet; - - - private String getValue( Node node ) { - return (node == null) ? "" : node.getNodeValue(); - } - /** * Returns true if the node is a link anchor node. |
From: Russell G. <rus...@us...> - 2002-10-22 22:59:29
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv12991/doc Modified Files: release_notes.txt Log Message: Corrected logic of response status workaround logic Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.199 retrieving revision 1.200 diff -u -r1.199 -r1.200 --- release_notes.txt 22 Oct 2002 20:15:33 -0000 1.199 +++ release_notes.txt 22 Oct 2002 22:59:24 -0000 1.200 @@ -11,6 +11,9 @@ Revision History: 22-Oct-22 +Acknowledgements: + Thanks to Troy Waldrep for help with the new handling of response statuses and messages. + Problems fixed: 1. A bad certificate on an https connection was incorrectly being flagged as a no-such-server exception. This is fixed on JDK 1.4, due to a correct in the JDK. On previous versions of the JDK, HttpUnit is using a |
From: Russell G. <rus...@us...> - 2002-10-22 20:15:40
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv7196/doc Modified Files: release_notes.txt Log Message: Slight cleanup, added jars to distribution Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.198 retrieving revision 1.199 diff -u -r1.198 -r1.199 --- release_notes.txt 22 Oct 2002 15:12:54 -0000 1.198 +++ release_notes.txt 22 Oct 2002 20:15:33 -0000 1.199 @@ -19,6 +19,8 @@ Notes: 1. The exception HttpServerNotFoundException has been removed. When no server is found, HttpUnit now throws the standard exception: java.net.UnknownHostException + 2. The required jars are now included in the distribution, so it is not necessary to download them separately. + This was an oversight. 21-Oct-2002 Problems fixed: |
From: Russell G. <rus...@us...> - 2002-10-22 20:15:40
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv7196/src/com/meterware/httpunit/javascript Modified Files: JavaScript.java Log Message: Slight cleanup, added jars to distribution Index: JavaScript.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java,v retrieving revision 1.32 retrieving revision 1.33 diff -u -r1.32 -r1.33 --- JavaScript.java 13 Oct 2002 23:53:48 -0000 1.32 +++ JavaScript.java 22 Oct 2002 20:15:34 -0000 1.33 @@ -24,7 +24,6 @@ import com.meterware.httpunit.scripting.*; import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; import java.util.ArrayList; import java.io.IOException; @@ -33,6 +32,7 @@ /** + * This class is the Rhino-compatible implementation of the JavaScript DOM objects. * * @author <a href="mailto:rus...@ht...">Russell Gold</a> **/ @@ -206,24 +206,13 @@ private Object convertIfNeeded( final Object property ) { if (property == null) return NOT_FOUND; - try { - if (property instanceof ScriptableDelegate[]) return toScriptable( (ScriptableDelegate[]) property ); - if (!(property instanceof ScriptableDelegate)) return property; - return toScriptable( (ScriptableDelegate) property ); - } catch (PropertyException e) { - throw new RuntimeException( e.toString() ); - } catch (NotAFunctionException e) { - throw new RuntimeException( e.toString() ); - } catch (JavaScriptException e) { - throw new RuntimeException( e.toString() ); - } catch (SAXException e) { - throw new RuntimeException( e.toString() ); - } + if (property instanceof ScriptableDelegate[]) return toScriptable( (ScriptableDelegate[]) property ); + if (!(property instanceof ScriptableDelegate)) return property; + return toScriptable( (ScriptableDelegate) property ); } - private Object toScriptable( ScriptableDelegate[] list ) - throws PropertyException, NotAFunctionException, JavaScriptException, SAXException { + private Object toScriptable( ScriptableDelegate[] list ) { Object[] delegates = new Object[ list.length ]; for (int i = 0; i < delegates.length; i++) { delegates[i] = toScriptable( list[i] ); @@ -446,7 +435,7 @@ } - private void initializeImages() throws SAXException { + private void initializeImages() { WebImage.Scriptable scriptables[] = getDelegate().getImages(); Image[] images = new Image[ scriptables.length ]; for (int i = 0; i < images.length; i++) { @@ -457,7 +446,7 @@ } - private void initializeLinks() throws SAXException { + private void initializeLinks() { WebLink.Scriptable scriptables[] = getDelegate().getLinks(); Link[] links = new Link[ scriptables.length ]; for (int i = 0; i < links.length; i++) { @@ -468,7 +457,7 @@ } - private void initializeForms() throws SAXException { + private void initializeForms() { WebForm.Scriptable scriptables[] = getDelegate().getForms(); Form[] forms = new Form[ scriptables.length ]; for (int i = 0; i < forms.length; i++) { @@ -681,7 +670,10 @@ } - public Scriptable jsGet_elements() { + public Scriptable jsGet_elements() throws PropertyException, NotAFunctionException, JavaScriptException { + if (_controls == null) { + initializeControls(); + } return _controls; } @@ -696,14 +688,7 @@ } - void initialize( JavaScriptEngine parent, ScriptableDelegate scriptable ) - throws JavaScriptException, NotAFunctionException, PropertyException, SAXException { - super.initialize( parent, scriptable ); - initializeControls(); - } - - - private void initializeControls() throws PropertyException, NotAFunctionException, JavaScriptException, SAXException { + private void initializeControls() throws PropertyException, NotAFunctionException, JavaScriptException { ScriptableDelegate scriptables[] = getDelegate().getElementDelegates(); Control[] controls = new Control[ scriptables.length ]; for (int i = 0; i < controls.length; i++) { |
From: Russell G. <rus...@us...> - 2002-10-22 20:15:40
|
Update of /cvsroot/httpunit/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv7196 Modified Files: build.xml Log Message: Slight cleanup, added jars to distribution Index: build.xml =================================================================== RCS file: /cvsroot/httpunit/httpunit/build.xml,v retrieving revision 1.50 retrieving revision 1.51 diff -u -r1.50 -r1.51 --- build.xml 14 Oct 2002 04:19:05 -0000 1.50 +++ build.xml 22 Oct 2002 20:15:32 -0000 1.51 @@ -191,10 +191,13 @@ <include name="test/**" /> <include name="examples/**" /> <include name="lib/*.*" /> + <include name="jars/*.*" /> + <exclude name="**/Tidy.jar"/> + <exclude name="**/activation.jar"/> + <exclude name="**/mailapi.jar" /> <include name="doc/**/*.*" /> </fileset> </copy> - <copy todir="${archive.dir}/lib" file="${jars.dir}/Tidy.jar" /> <replace file="${archive.dir}/index.html" token="var:dist " value="var:dist>" /> <replace file="${archive.dir}/index.html" token="var:publish>" value="var:publish " /> </target> |
From: Russell G. <rus...@us...> - 2002-10-22 20:15:40
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv7196/src/com/meterware/httpunit Modified Files: FormControl.java Log Message: Slight cleanup, added jars to distribution Index: FormControl.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- FormControl.java 14 Oct 2002 04:19:06 -0000 1.29 +++ FormControl.java 22 Oct 2002 20:15:34 -0000 1.30 @@ -27,7 +27,6 @@ import org.w3c.dom.NodeList; import java.util.Hashtable; -import java.util.Vector; import java.util.ArrayList; import java.util.List; import java.util.Arrays; @@ -591,27 +590,7 @@ } - private void addValue( Hashtable valueMap, String name, String value ) { - String[] currentValues = (String[]) valueMap.get( name ); - if (currentValues == null) { - valueMap.put( name, new String[] { value } ); - } else { - valueMap.put( name, withNewValue( currentValues, value ) ); - } - } - - - /** - * Adds a string to an array of strings and returns the result. - **/ - private String[] withNewValue( String[] group, String value ) { - String[] result = new String[ group.length+1 ]; - System.arraycopy( group, 0, result, 0, group.length ); - result[ group.length ] = value; - return result; - } - -} + } class TextFormControl extends FormControl { |
From: Russell G. <rus...@us...> - 2002-10-22 20:15:40
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv7196/test/com/meterware/httpunit Modified Files: HttpUnitSuite.java Log Message: Slight cleanup, added jars to distribution Index: HttpUnitSuite.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitSuite.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- HttpUnitSuite.java 17 Oct 2002 23:50:50 -0000 1.24 +++ HttpUnitSuite.java 22 Oct 2002 20:15:35 -0000 1.25 @@ -82,7 +82,7 @@ System.out.println( "Note: test suite " + testCaseName + " not a TestClass and has no suite() method" ); } } catch (ClassNotFoundException e) { - System.out.println( "Note: test suite " + testCaseName + " not found; skipping." ); + System.out.println( "Note: skipping optional test suite " + testCaseName + " since it was not build." ); } catch (Exception e) { System.out.println( "Note: unable to add " + testCaseName + ": " + e ); } |
From: Russell G. <rus...@us...> - 2002-10-22 15:12:58
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv28743/doc Modified Files: release_notes.txt Log Message: Use UnknownHostException instead of HttpServerNotFoundException Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.197 retrieving revision 1.198 diff -u -r1.197 -r1.198 --- release_notes.txt 21 Oct 2002 18:03:58 -0000 1.197 +++ release_notes.txt 22 Oct 2002 15:12:54 -0000 1.198 @@ -10,6 +10,16 @@ Revision History: +22-Oct-22 +Problems fixed: + 1. A bad certificate on an https connection was incorrectly being flagged as a no-such-server exception. This + is fixed on JDK 1.4, due to a correct in the JDK. On previous versions of the JDK, HttpUnit is using a + workaround, which cannot detect the difference. + +Notes: + 1. The exception HttpServerNotFoundException has been removed. When no server is found, HttpUnit now throws the + standard exception: java.net.UnknownHostException + 21-Oct-2002 Problems fixed: 1. The cookie fixes of 17-Oct had caused ServletUnit to see multiple servlets in an application with varying paths |
From: Russell G. <rus...@us...> - 2002-10-22 15:12:57
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver In directory usw-pr-cvs1:/tmp/cvs-serv28743/src/com/meterware/pseudoserver Modified Files: HttpUserAgentTest.java Log Message: Use UnknownHostException instead of HttpServerNotFoundException Index: HttpUserAgentTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver/HttpUserAgentTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- HttpUserAgentTest.java 29 Aug 2002 18:39:11 -0000 1.2 +++ HttpUserAgentTest.java 22 Oct 2002 15:12:54 -0000 1.3 @@ -27,8 +27,8 @@ /** - * - * @author <a href="mailto:rus...@ac...">Russell Gold</a> + * A base class for test cases that use the pseudo server. + * @author <a href="mailto:rus...@ht...">Russell Gold</a> **/ public class HttpUserAgentTest extends TestCase { @@ -150,6 +150,16 @@ sb.append( '"' ).append( args[ i ] ).append( '"' ); } sb.append( "}" ); + return sb.toString(); + } + + + protected String asBytes( String s ) { + StringBuffer sb = new StringBuffer(); + char[] chars = s.toCharArray(); + for (int i = 0; i < chars.length; i++) { + sb.append( Integer.toHexString( chars[i] ) ).append( " " ); + } return sb.toString(); } |
From: Russell G. <rus...@us...> - 2002-10-22 15:12:57
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv28743/src/com/meterware/httpunit Modified Files: HttpWebResponse.java Removed Files: HttpServerNotFoundException.java Log Message: Use UnknownHostException instead of HttpServerNotFoundException Index: HttpWebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpWebResponse.java,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- HttpWebResponse.java 5 Sep 2002 19:29:55 -0000 1.26 +++ HttpWebResponse.java 22 Oct 2002 15:12:54 -0000 1.27 @@ -19,7 +19,6 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ - import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; @@ -27,6 +26,7 @@ import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; +import java.net.UnknownHostException; import java.util.Enumeration; import java.util.Hashtable; @@ -37,7 +37,7 @@ /** * A response from a web server to an Http request. * - * @author <a href="mailto:rus...@ac...">Russell Gold</a> + * @author <a href="mailto:rus...@ht...">Russell Gold</a> **/ class HttpWebResponse extends WebResponse { @@ -122,7 +122,6 @@ //------------------------------------- private members ------------------------------------- - private final static String END_OF_LINE = System.getProperty( "line.separator" ); private final static String FILE_ENCODING = System.getProperty( "file.encoding" ); @@ -132,21 +131,32 @@ private Hashtable _headers = new Hashtable(); - private void readResponseHeader( URLConnection connection ) { - if (connection.getHeaderField(0) == null) throw new HttpServerNotFoundException( connection.getURL() ); - StringTokenizer st = new StringTokenizer( connection.getHeaderField(0) ); - st.nextToken(); - if (!st.hasMoreTokens()) { - _responseCode = HttpURLConnection.HTTP_OK; - _responseMessage = "OK"; - } else try { - _responseCode = Integer.parseInt( st.nextToken() ); - _responseMessage = getRemainingTokens( st ); - } catch (NumberFormatException e) { - _responseCode = HttpURLConnection.HTTP_INTERNAL_ERROR; - _responseMessage = "Cannot parse response header"; - } + private void readResponseHeader( HttpURLConnection connection ) throws IOException { + if (needStatusWorkaround()) { + _responseCode = connection.getResponseCode(); + _responseMessage = connection.getResponseMessage(); + } else { + if (connection.getHeaderField(0) == null) throw new UnknownHostException( connection.getURL().toExternalForm() ); + + StringTokenizer st = new StringTokenizer( connection.getHeaderField(0) ); + st.nextToken(); + if (!st.hasMoreTokens()) { + _responseCode = HttpURLConnection.HTTP_OK; + _responseMessage = "OK"; + } else try { + _responseCode = Integer.parseInt( st.nextToken() ); + _responseMessage = getRemainingTokens( st ); + } catch (NumberFormatException e) { + _responseCode = HttpURLConnection.HTTP_INTERNAL_ERROR; + _responseMessage = "Cannot parse response header"; + } + } + } + + private boolean needStatusWorkaround() { + final String jdkVersion = System.getProperty( "java.version" ); + return jdkVersion.startsWith( "1.2" ) || jdkVersion.startsWith( "1.3" ); } @@ -159,10 +169,10 @@ } - private void readHeaders( URLConnection connection ) { + private void readHeaders( URLConnection connection ) throws IOException { loadHeaders( connection ); if (connection instanceof HttpURLConnection) { - readResponseHeader( connection ); + readResponseHeader( (HttpURLConnection) connection ); } else { _responseCode = HttpURLConnection.HTTP_OK; _responseMessage = "OK"; |
From: Russell G. <rus...@us...> - 2002-10-22 15:12:57
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/pseudoserver In directory usw-pr-cvs1:/tmp/cvs-serv28743/test/com/meterware/pseudoserver Modified Files: PseudoServerTest.java Log Message: Use UnknownHostException instead of HttpServerNotFoundException Index: PseudoServerTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/pseudoserver/PseudoServerTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- PseudoServerTest.java 5 Sep 2002 19:29:55 -0000 1.5 +++ PseudoServerTest.java 22 Oct 2002 15:12:54 -0000 1.6 @@ -21,10 +21,10 @@ *******************************************************************************************************************/ import com.meterware.httpunit.*; -import junit.framework.TestCase; import junit.framework.TestSuite; import java.net.HttpURLConnection; +import java.net.UnknownHostException; public class PseudoServerTest extends HttpUserAgentTest { @@ -48,9 +48,9 @@ WebConversation wc = new WebConversation(); try { - WebResponse response = wc.getResponse( "http://no.such.host" ); + wc.getResponse( "http://no.such.host" ); fail( "Should have rejected the request" ); - } catch (HttpServerNotFoundException e) { + } catch (UnknownHostException e) { } } @@ -59,7 +59,7 @@ WebConversation wc = new WebConversation(); WebRequest request = new GetMethodWebRequest( getHostPath() + "/nothing.htm" ); try { - WebResponse response = wc.getResponse( request ); + wc.getResponse( request ); fail( "Should have rejected the request" ); } catch (HttpNotFoundException e) { assertEquals( "Response code", HttpURLConnection.HTTP_NOT_FOUND, e.getResponseCode() ); @@ -86,7 +86,7 @@ WebConversation wc = new WebConversation(); WebRequest request = new GetMethodWebRequest( getHostPath() + "/error.htm" ); try { - WebResponse response = wc.getResponse( request ); + wc.getResponse( request ); fail( "Should have rejected the request" ); } catch (HttpException e) { assertEquals( "Response code", 501, e.getResponseCode() ); @@ -131,16 +131,6 @@ WebResponse response = wc.getResponse( request ); assertEquals( "requested resource", resourceValue, response.getText().trim() ); assertEquals( "content type", "text/html", response.getContentType() ); - } - - - private String asBytes( String s ) { - StringBuffer sb = new StringBuffer(); - char[] chars = s.toCharArray(); - for (int i = 0; i < chars.length; i++) { - sb.append( Integer.toHexString( chars[i] ) ).append( " " ); - } - return sb.toString(); } |
From: Russell G. <rus...@us...> - 2002-10-21 18:04:02
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv2040/doc Modified Files: release_notes.txt Log Message: Use EN_us locale for servlet unit date headers Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.196 retrieving revision 1.197 diff -u -r1.196 -r1.197 --- release_notes.txt 21 Oct 2002 13:34:18 -0000 1.196 +++ release_notes.txt 21 Oct 2002 18:03:58 -0000 1.197 @@ -14,6 +14,7 @@ Problems fixed: 1. The cookie fixes of 17-Oct had caused ServletUnit to see multiple servlets in an application with varying paths as being in separate sessions. + 2. ServletUnit now explicitly specifies its locale for generating dates as Locale.US to comply with RFC-1123 17-Oct-2002 Additions: |
From: Russell G. <rus...@us...> - 2002-10-21 18:04:02
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv2040/src/com/meterware/servletunit Modified Files: ServletUnitHttpResponse.java Log Message: Use EN_us locale for servlet unit date headers Index: ServletUnitHttpResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpResponse.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- ServletUnitHttpResponse.java 21 Oct 2002 13:34:19 -0000 1.13 +++ ServletUnitHttpResponse.java 21 Oct 2002 18:03:59 -0000 1.14 @@ -227,7 +227,7 @@ private String asDateHeaderValue( long date ) { Date value = new Date( date ); - SimpleDateFormat formatter = new SimpleDateFormat( RFC1123_DATE_SPEC ); + SimpleDateFormat formatter = new SimpleDateFormat( RFC1123_DATE_SPEC, Locale.US ); formatter.setTimeZone( TimeZone.getTimeZone( "Greenwich Mean Time" ) ); return formatter.format( value ); } |
From: Russell G. <rus...@us...> - 2002-10-21 13:34:23
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv5578/test/com/meterware/servletunit Modified Files: StatefulTest.java Log Message: Use application context as session cookie path Index: StatefulTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/StatefulTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- StatefulTest.java 22 Aug 2002 15:48:41 -0000 1.3 +++ StatefulTest.java 21 Oct 2002 13:34:19 -0000 1.4 @@ -82,20 +82,22 @@ public void testStatePreservation() throws Exception { - final String resourceName = "something/interesting"; + final String resourceName1 = "something/interesting/start"; + final String resourceName2 = "something/continue"; ServletRunner sr = new ServletRunner(); - sr.registerServlet( resourceName, StatefulServlet.class.getName() ); + sr.registerServlet( resourceName1, StatefulServlet.class.getName() ); + sr.registerServlet( resourceName2, StatefulServlet.class.getName() ); WebClient wc = sr.newClient(); - WebRequest request = new PostMethodWebRequest( "http://localhost/" + resourceName ); + WebRequest request = new PostMethodWebRequest( "http://localhost/" + resourceName1 ); request.setParameter( "color", "red" ); WebResponse response = wc.getResponse( request ); assertNotNull( "No response received", response ); assertEquals( "content type", "text/plain", response.getContentType() ); assertEquals( "requested resource", "You selected red", response.getText() ); - request = new GetMethodWebRequest( "http://localhost/" + resourceName ); + request = new GetMethodWebRequest( "http://localhost/" + resourceName2 ); response = wc.getResponse( request ); assertNotNull( "No response received", response ); assertEquals( "content type", "text/plain", response.getContentType() ); |
From: Russell G. <rus...@us...> - 2002-10-21 13:34:23
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv5578/src/com/meterware/servletunit Modified Files: InvocationContextImpl.java ServletUnitHttpResponse.java WebApplication.java Log Message: Use application context as session cookie path Index: InvocationContextImpl.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/InvocationContextImpl.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- InvocationContextImpl.java 17 Oct 2002 23:50:49 -0000 1.8 +++ InvocationContextImpl.java 21 Oct 2002 13:34:19 -0000 1.9 @@ -91,7 +91,9 @@ if (_webResponse == null) { HttpSession session = _request.getSession( /* create */ false ); if (session != null && session.isNew()) { - _response.addCookie( new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, session.getId() ) ); + Cookie cookie = new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, session.getId() ); + cookie.setPath( _application.getContextPath() ); + _response.addCookie( cookie ); } _webResponse = new ServletUnitWebResponse( _client, _target, _requestURL, _response ); } Index: ServletUnitHttpResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpResponse.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- ServletUnitHttpResponse.java 2 Oct 2002 14:50:39 -0000 1.12 +++ ServletUnitHttpResponse.java 21 Oct 2002 13:34:19 -0000 1.13 @@ -570,7 +570,7 @@ StringBuffer sb = new StringBuffer(); for (Enumeration e = _cookies.elements(); e.hasMoreElements();) { Cookie cookie = (Cookie) e.nextElement(); - sb.append( cookie.getName() ).append( '=' ).append( cookie.getValue() ); + sb.append( cookie.getName() ).append( '=' ).append( cookie.getValue() ).append( ";path=" ).append( cookie.getPath() ); if (e.hasMoreElements()) sb.append( ',' ); } setHeader( "Set-Cookie", sb.toString() ); Index: WebApplication.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/WebApplication.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- WebApplication.java 9 Oct 2002 19:15:29 -0000 1.14 +++ WebApplication.java 21 Oct 2002 13:34:19 -0000 1.15 @@ -101,6 +101,11 @@ } + String getContextPath() { + return _contextPath; + } + + /** * Registers a servlet class to be run. **/ |