httpunit-commit Mailing List for httpunit (Page 71)
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...> - 2001-11-05 15:50:41
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv10126/src/com/meterware/httpunit Modified Files: HttpUnitUtils.java WebLink.java Log Message: Corrected errors with link parameter parsing Index: HttpUnitUtils.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitUtils.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- HttpUnitUtils.java 2001/07/06 17:11:04 1.1 +++ HttpUnitUtils.java 2001/11/05 15:50:38 1.2 @@ -44,4 +44,30 @@ return result; } + /** + * Returns an interpretation of the specified URL-encoded string. + * FIXME: currently assumes iso-8859-1 character set. + **/ + static String decode( String byteString ) { + StringBuffer sb = new StringBuffer(); + char[] chars = byteString.toCharArray(); + char[] hexNum = { '0', '0', '0' }; + + int i = 0; + while (i < chars.length) { + if (chars[i] == '+') { + i++; + sb.append( ' ' ); + } else if (chars[i] == '%') { + i++; + hexNum[1] = chars[i++]; + hexNum[2] = chars[i++]; + sb.append( (char) Integer.parseInt( new String( hexNum ), 16 ) ); + } else { + sb.append( chars[i++] ); + } + } + return sb.toString(); + } + } Index: WebLink.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- WebLink.java 2001/10/24 18:06:28 1.9 +++ WebLink.java 2001/11/05 15:50:38 1.10 @@ -100,12 +100,12 @@ /** * add a pair key-value to the hashtable, creates an array of values if param already exists. **/ - private void stripOneParameter(Hashtable params, String param) { - int index = param.indexOf("="); - if (index <= 0 || index == param.length() - 1) return; - - String value = param.substring(index + 1); - String key = param.substring(0, index); + private void stripOneParameter( Hashtable params, String param ) { + int index = param.indexOf( "=" ); + String value = (index < 0 || index == param.length() - 1) + ? "" + : HttpUnitUtils.decode( param.substring( index + 1 ) ); + String key = (index < 0) ? param : HttpUnitUtils.decode( param.substring( 0, index ) ); params.put( key, withNewValue( (String[]) params.get( key ), value ) ); } |
From: Russell G. <rus...@us...> - 2001-10-26 15:41:07
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv14392/test/com/meterware/httpunit Modified Files: WebLinkTest.java WebPageTest.java Log Message: from Benoit Xhenseval: handle cases of multiple Link elements Index: WebLinkTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebLinkTest.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- WebLinkTest.java 2001/10/26 14:00:10 1.12 +++ WebLinkTest.java 2001/10/26 15:41:04 1.13 @@ -34,7 +34,7 @@ * Tests for the WebLink class. * * @author <a href="mailto:rus...@ac...>Russell Gold</a> - * @author <a href="mailto:ben...@av...>Benoit Xhenseval</a> + * @author <a href="mailto:bx...@bi...>Benoit Xhenseval</a> **/ public class WebLinkTest extends HttpUnitTest { @@ -209,70 +209,71 @@ WebLink[] links = wc.getResponse( getHostPath() + "/ParameterLinks.html" ).getLinks(); assertNotNull( links ); assertEquals( "number of links", 5, links.length ); - WebRequest request; + WebRequest request; - // first link should not have any param - request = links[0].getRequest(); - assertNotNull( request); - Enumeration e = request.getParameterNames(); - assertNotNull( e); - assertTrue( "Should not have any params", !e.hasMoreElements() ); + // first link should not have any param + request = links[0].getRequest(); + assertNotNull( request); + Enumeration e = request.getParameterNames(); + assertNotNull( e); + assertTrue( "Should not have any params", !e.hasMoreElements() ); + assertEquals("Non Existent parameter should be empty","",request.getParameter("nonexistent")); // second link should have one parameter - request = links[1].getRequest(); - assertNotNull( request ); - e = request.getParameterNames(); - assert( e.hasMoreElements() ); - String paramName = (String)e.nextElement(); - assertNotNull(paramName); - assert(!e.hasMoreElements()); - assertEquals("param1",paramName); - assertEquals("value1",request.getParameter(paramName)); - - // third link should have 2 parameters. !! Order of parameters cannot be guaranted. - request = links[2].getRequest(); - assertNotNull( request ); - e = request.getParameterNames(); - assert( e.hasMoreElements() ); - paramName = (String)e.nextElement(); - assertNotNull(paramName); - assert(e.hasMoreElements()); - String paramName2 = (String)e.nextElement(); - assertNotNull(paramName2); - assert("different names",!paramName.equals(paramName2)); - assert("test names for param1",paramName.equals("param1") || paramName2.equals("param1")); - assert("test names for param2",paramName.equals("param2") || paramName2.equals("param2")); - assertEquals("value1",request.getParameter("param1")); - assertEquals("value2",request.getParameter("param2")); - - // fourth link should have 1 parameter with 2 values. - request = links[3].getRequest(); - assertNotNull( request ); - e = request.getParameterNames(); - assert( e.hasMoreElements() ); - paramName = (String)e.nextElement(); - assertNotNull(paramName); - String[] values = request.getParameterValues("param1"); - assertEquals("Length of ",2,values.length); - assertMatchingSet("Values",new String[] {"value1", "value3"}, values); - - // fifth link should have 2 parameters with one with 2 values. - request = links[4].getRequest(); - assertNotNull( request ); - e = request.getParameterNames(); - assert( e.hasMoreElements() ); - paramName = (String)e.nextElement(); - assertNotNull(paramName); - assert( e.hasMoreElements() ); - paramName2 = (String)e.nextElement(); - assertNotNull(paramName2); - assert("different names",!paramName.equals(paramName2)); - values = request.getParameterValues("param1"); - assertEquals("Length of ",2,values.length); - assertMatchingSet("Values for param1",new String[] {"value1", "value3"}, values); - assertMatchingSet("Values form param2",new String[] {"value2"}, request.getParameterValues("param2")); - assertEquals("value2",request.getParameter("param2")); - } + request = links[1].getRequest(); + assertNotNull( request ); + e = request.getParameterNames(); + assertTrue( e.hasMoreElements() ); + String paramName = (String)e.nextElement(); + assertNotNull(paramName); + assertTrue(!e.hasMoreElements()); + assertEquals("param1",paramName); + assertEquals("value1",request.getParameter(paramName)); + + // third link should have 2 parameters. !! Order of parameters cannot be guaranted. + request = links[2].getRequest(); + assertNotNull( request ); + e = request.getParameterNames(); + assertTrue( e.hasMoreElements() ); + paramName = (String)e.nextElement(); + assertNotNull(paramName); + assertTrue(e.hasMoreElements()); + String paramName2 = (String)e.nextElement(); + assertNotNull(paramName2); + assertTrue("different names",!paramName.equals(paramName2)); + assertTrue("test names for param1",paramName.equals("param1") || paramName2.equals("param1")); + assertTrue("test names for param2",paramName.equals("param2") || paramName2.equals("param2")); + assertEquals("value1",request.getParameter("param1")); + assertEquals("value2",request.getParameter("param2")); + + // fourth link should have 1 parameter with 2 values. + request = links[3].getRequest(); + assertNotNull( request ); + e = request.getParameterNames(); + assertTrue( e.hasMoreElements() ); + paramName = (String)e.nextElement(); + assertNotNull(paramName); + String[] values = request.getParameterValues("param1"); + assertEquals("Length of ",2,values.length); + assertMatchingSet("Values",new String[] {"value1", "value3"}, values); + + // fifth link should have 2 parameters with one with 2 values. + request = links[4].getRequest(); + assertNotNull( request ); + e = request.getParameterNames(); + assertTrue( e.hasMoreElements() ); + paramName = (String)e.nextElement(); + assertNotNull(paramName); + assertTrue( e.hasMoreElements() ); + paramName2 = (String)e.nextElement(); + assertNotNull(paramName2); + assertTrue("different names",!paramName.equals(paramName2)); + values = request.getParameterValues("param1"); + assertEquals("Length of ",2,values.length); + assertMatchingSet("Values for param1",new String[] {"value1", "value3"}, values); + assertMatchingSet("Values form param2",new String[] {"value2"}, request.getParameterValues("param2")); + assertEquals("value2",request.getParameter("param2")); + } public void testImageMapLinks() throws Exception { Index: WebPageTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebPageTest.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- WebPageTest.java 2001/10/25 14:51:05 1.17 +++ WebPageTest.java 2001/10/26 15:41:04 1.18 @@ -298,6 +298,7 @@ public void testGetExternalStylesheet() throws Exception { String refreshURL = getHostPath() + "/NextPage.html"; String page = "<html><head><title>Sample</title>" + + "<link rev=\"made\" href=\"/Me...@my...\"/>" + "<link type=\"text/css\" rel=\"stylesheet\" href=\"/style.css\"/>" + "</head>\n" + "<body>This has no data\n" + |
From: Russell G. <rus...@us...> - 2001-10-26 15:41:07
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv14392/src/com/meterware/httpunit Modified Files: ReceivedPage.java Log Message: from Benoit Xhenseval: handle cases of multiple Link elements Index: ReceivedPage.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ReceivedPage.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- ReceivedPage.java 2001/10/25 14:51:05 1.14 +++ ReceivedPage.java 2001/10/26 15:41:04 1.15 @@ -68,9 +68,13 @@ **/ public String getExternalStyleSheet() throws SAXException { NodeList nl = ((Document) getDOM()).getElementsByTagName( "link" ); - if (nl.getLength() == 0) return ""; - if ("stylesheet".equalsIgnoreCase(NodeUtils.getNodeAttribute( nl.item(0), "rel" ))) - return NodeUtils.getNodeAttribute( nl.item(0), "href" ); + int length = nl.getLength(); + if (length == 0) return ""; + + for (int i = 0; i < length; i++) { + if ("stylesheet".equalsIgnoreCase(NodeUtils.getNodeAttribute( nl.item(i), "rel" ))) + return NodeUtils.getNodeAttribute( nl.item(i), "href" ); + } return ""; } |
From: Russell G. <rus...@us...> - 2001-10-26 14:00:13
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv13428/test/com/meterware/httpunit Modified Files: HttpUnitTest.java WebFormTest.java WebFrameTest.java WebLinkTest.java Log Message: Now using assertTrue for JUnit 3.7 compatibility Index: HttpUnitTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitTest.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- HttpUnitTest.java 2001/10/25 17:30:03 1.16 +++ HttpUnitTest.java 2001/10/26 14:00:10 1.17 @@ -94,7 +94,7 @@ return _hostPath; } - public void assertTrue( String comment, boolean expression ) { + public static void assertTrue( String comment, boolean expression ) { assert( comment, expression ); } Index: WebFormTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFormTest.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- WebFormTest.java 2001/08/06 20:19:41 1.12 +++ WebFormTest.java 2001/10/26 14:00:10 1.13 @@ -124,7 +124,7 @@ WebForm form = _wc.getResponse( getHostPath() + "/OneForm.html" ).getForms()[0]; WebRequest request = form.getRequest(); request.setParameter( "name", "master" ); - assert( "Should be a post request", !(request instanceof GetMethodWebRequest) ); + assertTrue( "Should be a post request", !(request instanceof GetMethodWebRequest) ); assertEquals( getHostPath() + "/servlet/Login", request.getURL().toExternalForm() ); } Index: WebFrameTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFrameTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- WebFrameTest.java 2001/07/31 16:08:59 1.7 +++ WebFrameTest.java 2001/10/26 14:00:10 1.8 @@ -75,9 +75,9 @@ public void testDefaultFrameContents() throws Exception { WebResponse response = _wc.getResponse( getHostPath() + "/Linker.html" ); - assert( "Default response not the same as default frame contents", response == _wc.getFrameContents( "_top" ) ); + assertTrue( "Default response not the same as default frame contents", response == _wc.getFrameContents( "_top" ) ); response = _wc.getResponse( response.getLinks()[0].getRequest() ); - assert( "Second response not the same as default frame contents", response == _wc.getFrameContents( "_top" ) ); + assertTrue( "Second response not the same as default frame contents", response == _wc.getFrameContents( "_top" ) ); } @@ -111,7 +111,7 @@ WebResponse response = _wc.getResponse( getHostPath() + "/Frames.html" ); response = _wc.getResponse( _wc.getFrameContents( "red" ).getLinks()[0].getRequest() ); - assert( "Second response not the same as source frame contents", response == _wc.getFrameContents( "red" ) ); + assertTrue( "Second response not the same as source frame contents", response == _wc.getFrameContents( "red" ) ); assertMatchingSet( "Frames defined for the conversation", new String[] { "_top", "red", "blue" }, _wc.getFrameNames() ); assertEquals( "URL for second request", getHostPath() + "/Target.html", response.getURL().toExternalForm() ); } @@ -134,7 +134,7 @@ WebResponse response = _wc.getResponse( getHostPath() + "/Frames.html" ); response = _wc.getResponse( _wc.getFrameContents( "red" ).getLinks()[0].getRequest() ); - assert( "Second response not the same as source frame contents", response == _wc.getFrameContents( "red" ) ); + assertTrue( "Second response not the same as source frame contents", response == _wc.getFrameContents( "red" ) ); assertMatchingSet( "Frames defined for the conversation", new String[] { "_top", "red", "blue" }, _wc.getFrameNames() ); assertEquals( "URL for second request", getHostPath() + "/Deeper/Target.html", response.getURL().toExternalForm() ); } @@ -159,7 +159,7 @@ response = _wc.getResponse( linker.getLinks()[0].getRequest() ); WebResponse target = getFrameWithURL( _wc, "Target" ); - assert( "Second response not the same as source frame contents", response == target ); + assertTrue( "Second response not the same as source frame contents", response == target ); } @@ -187,7 +187,7 @@ _wc.getResponse( _wc.getFrameContents( "red" ).getLinks()[0].getRequest() ); response = _wc.getResponse( _wc.getFrameContents( "blue" ).getLinks()[0].getRequest() ); - assert( "Second response not the same as source frame contents", response == _wc.getFrameContents( "red" ) ); + assertTrue( "Second response not the same as source frame contents", response == _wc.getFrameContents( "red" ) ); assertMatchingSet( "Frames defined for the conversation", new String[] { "_top", "red", "blue" }, _wc.getFrameNames() ); assertEquals( "URL for second request", getHostPath() + "/Linker.html", response.getURL().toExternalForm() ); } @@ -198,7 +198,7 @@ response = _wc.getResponse( _wc.getFrameContents( "red" ).getLinks()[0].getRequest() ); response = _wc.getResponse( response.getLinks()[0].getRequest() ); - assert( "Second response not the same as source frame contents", response == _wc.getFrameContents( "_top" ) ); + assertTrue( "Second response not the same as source frame contents", response == _wc.getFrameContents( "_top" ) ); assertEquals( "URL for second request", getHostPath() + "/Form.html", response.getURL().toExternalForm() ); assertMatchingSet( "Frames defined for the conversation", new String[] { "_top" }, _wc.getFrameNames() ); } @@ -225,7 +225,7 @@ _wc.getResponse( getHostPath() + "/Frames.html" ); WebResponse response = _wc.getResponse( _wc.getFrameContents( "red" ).getLinks()[0].getRequest() ); assertMatchingSet( "Frames defined for the conversation", new String[] { "_top", "red", "blue" }, _wc.getFrameNames() ); - assert( "Second response not the same as source frame contents", response == _wc.getFrameContents( "red" ) ); + assertTrue( "Second response not the same as source frame contents", response == _wc.getFrameContents( "red" ) ); assertEquals( "URL for second request", getHostPath() + "/Target.html", response.getURL().toExternalForm() ); } @@ -238,7 +238,7 @@ _wc.getResponse( getHostPath() + "/Frames.html" ); WebResponse response = _wc.getResponse( _wc.getFrameContents( "red" ).getForms()[0].getRequest() ); assertMatchingSet( "Frames defined for the conversation", new String[] { "_top", "red", "blue" }, _wc.getFrameNames() ); - assert( "Second response not the same as source frame contents", response == _wc.getFrameContents( "red" ) ); + assertTrue( "Second response not the same as source frame contents", response == _wc.getFrameContents( "red" ) ); assertEquals( "URL for second request", getHostPath() + "/Target.html", response.getURL().toExternalForm() ); } @@ -249,7 +249,7 @@ _wc.getResponse( getHostPath() + "/Frames.html" ); assertMatchingSet( "Frames defined for the conversation", new String[] { "_top", "red", "blue" }, _wc.getFrameNames() ); - assert( "Did not redirect", _wc.getFrameContents( "red" ).getURL().toExternalForm().endsWith( "Target.html" ) ); + assertTrue( "Did not redirect", _wc.getFrameContents( "red" ).getURL().toExternalForm().endsWith( "Target.html" ) ); } @@ -260,7 +260,7 @@ _wc.getResponse( getHostPath() + "/Frames.html" ); WebResponse response = _wc.getResponse( _wc.getFrameContents( "red" ).getLinks()[0].getRequest() ); assertMatchingSet( "Frames defined for the conversation", new String[] { "_top" }, _wc.getFrameNames() ); - assert( "Second response not the same as source frame contents", response == _wc.getFrameContents( "_top" ) ); + assertTrue( "Second response not the same as source frame contents", response == _wc.getFrameContents( "_top" ) ); assertEquals( "URL for second request", getHostPath() + "/Target.html", response.getURL().toExternalForm() ); } Index: WebLinkTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebLinkTest.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- WebLinkTest.java 2001/10/25 14:51:05 1.11 +++ WebLinkTest.java 2001/10/26 14:00:10 1.12 @@ -88,7 +88,7 @@ public void testLinkRequest() throws Exception { WebLink link = _simplePage.getLinks()[0]; WebRequest request = link.getRequest(); - assert( "Should be a get request", request instanceof GetMethodWebRequest ); + assertTrue( "Should be a get request", request instanceof GetMethodWebRequest ); assertEquals( getHostPath() + "/other.html", request.getURL().toExternalForm() ); } @@ -174,7 +174,7 @@ WebRequest request = link.getRequest(); assertEquals( "Destination for link", getHostPath() + "/alternate/Target.html", request.getURL().toExternalForm() ); WebResponse nextPage = wc.getResponse( request ); - assert( "Did not find the target", nextPage.getText().indexOf( "Found" ) >= 0 ); + assertTrue( "Did not find the target", nextPage.getText().indexOf( "Found" ) >= 0 ); } @@ -216,7 +216,7 @@ assertNotNull( request); Enumeration e = request.getParameterNames(); assertNotNull( e); - assert( !e.hasMoreElements() ); + assertTrue( "Should not have any params", !e.hasMoreElements() ); // second link should have one parameter request = links[1].getRequest(); |
From: Russell G. <rus...@us...> - 2001-10-25 19:23:20
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv27083/src/com/meterware/servletunit Modified Files: ServletUnitHttpRequest.java Log Message: Fix loopback address Index: ServletUnitHttpRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpRequest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ServletUnitHttpRequest.java 2000/11/21 22:18:19 1.2 +++ ServletUnitHttpRequest.java 2001/10/25 19:23:17 1.3 @@ -581,7 +581,7 @@ //--------------------------------------------- private members ---------------------------------------------- - final static private String LOOPBACK_ADDRESS = "17.0.0.1"; + final static private String LOOPBACK_ADDRESS = "127.0.0.1"; private WebRequest _request; |
From: Russell G. <rus...@us...> - 2001-10-25 19:23:20
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv27083/doc Modified Files: release_notes.txt Log Message: Fix loopback address Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.60 retrieving revision 1.61 diff -u -r1.60 -r1.61 --- release_notes.txt 2001/10/25 17:31:41 1.60 +++ release_notes.txt 2001/10/25 19:23:17 1.61 @@ -23,6 +23,7 @@ Thanks to Richard Scothern for identiying the cause of problems with POST requests and older servlet engines. Thanks to Benoit Xhenseval for adding parameter detection in links, handling of meta and link tags, and selection of table cells by ID. + Thanks to Mike Bracewell for noticing the incorrect loopback address in ServletUnitHttpRequest Problems corrected: 1. Forms with no action now default to the originating page @@ -37,6 +38,7 @@ 9. By default, POSTs included charset attributes which messed up some servlet engines 10. WebRequest.isFileParameter is now functioning and public 11. auto-redirect now handles relative URLs + 12. ServletUnit's HttpServletRequest implementation was returning "17.0.0.1" as the host address. Additions: Content and parsing enhancements |
From: Russell G. <rus...@us...> - 2001-10-25 17:31:43
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv32116/doc Modified Files: release_notes.txt todo.txt Log Message: prepare for HttpUnit 1.2.7 release Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.59 retrieving revision 1.60 diff -u -r1.59 -r1.60 --- release_notes.txt 2001/10/25 14:51:05 1.59 +++ release_notes.txt 2001/10/25 17:31:41 1.60 @@ -11,112 +11,68 @@ Revision History: -24-Oct-2001 - Acknowledgements: - Thanks to Benoit Xhenseval for adding parameter detection in links and handling of meta and link tags. - - Additions: - 1. getParameter() and getParameterNames() now works for requests built from links with embedded parameters. - 2. WebResponse.getMetaTagContent can be used to obtain the content of a meta tag (see the Javadoc) - 3. WebResponse.getStylesheet can be used to obtain the path to the stylesheet associated with a page. - 4. Added name attribute to WebLink - 5. Added getLinkWithID and getLinkWithName to WebResponse - -19-Oct-2001 - Additions: - 1. Requests may now have as many values for a text parameter name as the number of <INPUT> tags with that name. - -18-Oct-2001 - Additions: - 1. It is now possible to upload a file via a POST request not derived from a form. To do this, call - PostMessageWebRequest.setMimeEncoded( true ) before calling selectFile. - -16-Oct-2001 - Problems corrected: - 1. WebRequest.isFileParameter is now functioning and public - 2. auto-redirect now handles relative URLs - -15-Oct-2001 - Problems corrected: - 1. The http-equiv meta tag was incorrectly matched as "http_equiv" - 2. By default, POSTs included charset attributes which messed up some servlet engines - -13-Sep-2001 - Problems corrected: - 1. The refresh handling now recognizes requests with content syntax "<seconds>;<location>" or "<seconds>; URL=<location>" +25-Oct-2001 1.2.7 -21-Aug-2001 Acknowledgements: - Thanks to Richard Scothern for identiying the cause of problems with POST requests and older servlet engines. - - Additions: - 1. HttpUnitOptions now has a postIncludesCharset which can be set to false to interoperate with older servlet - engines, such as Tomcat 3.1, which cannot handle the charset attribute - -13-Aug-2001 -Acknowledgements: - Thanks to Brett Neumeier for some Javadoc fixes and adding support for the non-standard "Charset" header - - Additions: - 1. Now recognizes a Charset header if no charset is specified in the Content-type header. - - 8-Aug-2001 -Acknowledgements: - Thanks to Dave Glowacki for the default content-type code. - - Additions: - 1. HttpUnitOptions.setDefaultContentType() lets you define a content-type to use when the web server does not - supply a Content-Type header. - - 2-Aug-2001 - Problems Corrected: - 1. Set-Cookie headers are now processed even on responses with 4xx and 5xx status - 2. WebForm.getOptionValues now returns the options in the order listed in the form for both selections and radio buttons. - -31-Jul-2001 - Additions: - 1. Added ID property to SubmitButton and WebLink - 2. Added getSubmitButtonWithID to WebForm - 3. Added getMethod and getAction to WebForm - 4. Image map <area> tags are now recognized as links, whose text is equal to their 'alt' tag. This allows - them to be retrieved using getLinkWith( altText ). - 5. Added version of WebRequest.selectFile which allows clients to specify the file to upload using an input - stream rather than an actual file. - - Problems corrected: - 1. The _self target now works for forms. - -20-Jul-2001 -Acknowledgements: + Thanks to Chris Stevenson for identifying a problem with forms lacking an action Thanks to Drew Varner for more sophisticated cookie handling, including Set-Cookie2 code Thanks to David Karr for pointing out the problem with status code 3xx responses and - suggesting a fix for it. + suggesting a fix for it. + Thanks to Dave Glowacki for the default content-type code. + Thanks to Brett Neumeier for some Javadoc fixes and adding support for the non-standard "Charset" header + Thanks to Richard Scothern for identiying the cause of problems with POST requests and older servlet engines. + Thanks to Benoit Xhenseval for adding parameter detection in links, handling of meta and link tags, + and selection of table cells by ID. Problems corrected: - 1. cookies with embedded commas and quotes are now handled - 2. Status code 3xx responses no longer result in a null pointer exception when + 1. Forms with no action now default to the originating page + 2. cookies with embedded commas and quotes are now handled + 3. Status code 3xx responses no longer result in a null pointer exception when invoking getText or reading the input stream. + 4. The _self target now works for forms. + 5. Set-Cookie headers are now processed even on responses with 4xx and 5xx status + 6. WebForm.getOptionValues now returns the options in the order listed in the form for both selections and radio buttons. + 7. The refresh handling now recognizes requests with content syntax "<seconds>;<location>" or "<seconds>; URL=<location>" + 8. The http-equiv meta tag was incorrectly matched as "http_equiv" + 9. By default, POSTs included charset attributes which messed up some servlet engines + 10. WebRequest.isFileParameter is now functioning and public + 11. auto-redirect now handles relative URLs Additions: - 1. The Set-Cookie2 header is now handled + Content and parsing enhancements + 1. Added ID property to SubmitButton + 2. Added ID and name properties to WebLink + 3. May now search web responses for links by name or ID + 4. getParameter() and getParameterNames() now works for requests built from links with embedded parameters. + 5. Image map <area> tags are now recognized as links, whose text is equal to their 'alt' tag. This allows + them to be retrieved using getLinkWith( altText ). + 6. Added getSubmitButtonWithID to WebForm + 7. Added getMethod and getAction to WebForm + 8. WebResponse.getMetaTagContent can be used to obtain the content of a meta tag (see the Javadoc) + 9. WebResponse.getStylesheet can be used to obtain the path to the stylesheet associated with a page. + 10. Added WebTable.getTableCellWithID + + Request submission enhancements: + 11. Added version of WebRequest.selectFile which allows clients to specify the file to upload using an input + stream rather than an actual file. + 12. HttpUnitOptions now has a postIncludesCharset which can be set to true when working with newer servlet + engines which can handle it (such as Tomcat 3.2 or later), and which may be important for internationalization. + 13. It is now possible to upload a file via a POST request not derived from a form. To do this, call + PostMessageWebRequest.setMimeEncoded( true ) before calling selectFile. + 14. Requests may now have as many values for a text parameter name as the number of <INPUT> tags with that name. + + Response handling enhancements: + 15. It is now possible to see the response accompanying an error status by + calling HttpUnitOptions.setExceptionsThrownOnErrorStatus( false ) before calling getResponse. This will + prevent HttpUnit from throwing an exception in such cases. You can still check the status of the response by + calling WebResponse.getStatusCode() + 16. Added getHeaderFieldNames to WebResponse + 17. The Set-Cookie2 header is now handled + 18. HttpUnitOptions.setDefaultContentType() lets you define a content-type to use when the web server does not + supply a Content-Type header. + 19. Now recognizes a Charset header if no charset is specified in the Content-type header. There are some servers + which send this non-standard header. -19-Jul-2001 -Additions: - 1. Added getHeaderFieldNames to WebResponse - -16-Jul-2001 -Acknowledgements: - Thanks to Chris Stevenson for identifying a problem with forms lacking an action - -Additions: - 1. It is now possible to see the response accompanying an error status by - calling HttpUnitOptions.setExceptionsThrownOnErrorStatus( false ) before - calling getResponse. This will prevent HttpUnit from throwing an exception - in such cases. You can still check the status of the response by calling - WebResponse.getStatusCode() - -Problems corrected: - 1. Forms with no action now default to the originating page 6-Jul-2001 1.2.6 Acknowledgements: Index: todo.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/todo.txt,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- todo.txt 2001/10/25 14:15:59 1.20 +++ todo.txt 2001/10/25 17:31:41 1.21 @@ -1,6 +1,5 @@ High Priority o Allow servlet initialization parameters in registerServlet -o Add support for getLinkWithName o Prevent setParameter calls from working on requests built from links if validation is enabled Medium priority: |
From: Russell G. <rus...@us...> - 2001-10-25 17:31:43
|
Update of /cvsroot/httpunit/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv32116 Modified Files: build.xml Log Message: prepare for HttpUnit 1.2.7 release Index: build.xml =================================================================== RCS file: /cvsroot/httpunit/httpunit/build.xml,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- build.xml 2001/07/06 17:11:03 1.30 +++ build.xml 2001/10/25 17:31:41 1.31 @@ -5,8 +5,8 @@ <project name="httpunit" default="jar" basedir="."> <property name="name" value="httpunit" /> <property name="Name" value="HttpUnit" /> - <property name="version" value="1.2.6" /> - <property name="zip_version" value="1_2_6" /> + <property name="version" value="1.2.7" /> + <property name="zip_version" value="1_2_7" /> <property name="src.dir" value="src" /> <property name="tstsrc.dir" value="test" /> |
From: Russell G. <rus...@us...> - 2001-10-25 17:30:06
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv31578/src/com/meterware/httpunit Modified Files: WebTable.java Log Message: from Benoit Xhenseval: added getTableCellWithID Index: WebTable.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebTable.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- WebTable.java 2000/12/27 20:02:17 1.13 +++ WebTable.java 2001/10/25 17:30:03 1.14 @@ -2,14 +2,14 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000, Russell Gold +* Copyright (c) 2000-2001, Russell Gold * -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -* documentation files (the "Software"), to deal in the Software without restriction, including without limitation +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +* documentation files (the "Software"), to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * -* The above copyright notice and this permission notice shall be included in all copies or substantial portions +* The above copyright notice and this permission notice shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO @@ -27,6 +27,9 @@ /** * This class represents a table in an HTML page. + * + * @author <a href="mailto:rus...@ac...">Russell Gold</a> + * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a> **/ public class WebTable { @@ -51,7 +54,7 @@ /** - * Returns the contents of the specified table cell as text. + * Returns the contents of the specified table cell as text. * The row and column numbers are zero-based. * @throws IndexOutOfBoundsException if the specified cell numbers are not valid * @deprecated use #getCellAsText @@ -62,7 +65,7 @@ /** - * Returns the contents of the specified table cell as text. + * Returns the contents of the specified table cell as text. * The row and column numbers are zero-based. * @throws IndexOutOfBoundsException if the specified cell numbers are not valid **/ @@ -73,7 +76,7 @@ /** - * Returns the contents of the specified table cell as text. + * Returns the contents of the specified table cell as text. * The row and column numbers are zero-based. * @throws IndexOutOfBoundsException if the specified cell numbers are not valid **/ @@ -84,6 +87,30 @@ /** + * Returns the contents of the specified table cell with a given ID + * @return TableCell with given ID or null if ID is not found. + * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a> + **/ + public TableCell getTableCellWithID( String id ) { + if (_cells == null) readTable(); + String idToCompare; + for (int i = 0; i < getRowCount(); i++) { + for (int j = 0; j < getColumnCount(); j++) { + if (_cells[i][j]!=null) { + idToCompare = NodeUtils.getNodeAttribute( _cells[i][j].getDOM(), "id" ); + if (HttpUnitOptions.getMatchesIgnoreCase()) + if (id.equalsIgnoreCase(idToCompare)) + return _cells[i][j]; + else if (id.equals(idToCompare)) + return _cells[i][j]; + } + } + } + return null; + } + + + /** * Removes all rows and all columns from this table which have no visible text in them. **/ public void purgeEmptyCells() { @@ -116,7 +143,7 @@ boolean neededInRow = true; boolean neededInCol = true; for (int i = coords[0]; neededInRow && (i < coords[0] + cell.getRowSpan()); i++) { - neededInRow = !rowHasText[i]; + neededInRow = !rowHasText[i]; } for (int j = coords[1]; neededInCol && (j < coords[1] + cell.getColSpan()); j++) { neededInCol = !columnHasText[j]; @@ -270,7 +297,7 @@ for (int k = 0; k < spannedRows; k++) { for (int l = 0; l < cells[j].getColSpan(); l++) { placeCell( i+k, j+l, cells[j] ); - } + } } } } @@ -295,7 +322,7 @@ /** * Returns true if the desiredParentTag is found in the tree above this node more closely nested than * the undesiredParentTag, or if the top of the tree is found before the undesired tag. - **/ + **/ private static boolean isMoreCloselyNested( Node node, Node desiredParentNode, String undesiredParentTag ) { node = node.getParentNode(); while (true) { |
From: Russell G. <rus...@us...> - 2001-10-25 17:30:06
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv31578/test/com/meterware/httpunit Modified Files: HtmlTablesTest.java HttpUnitTest.java Log Message: from Benoit Xhenseval: added getTableCellWithID Index: HtmlTablesTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HtmlTablesTest.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- HtmlTablesTest.java 2000/12/13 21:55:16 1.11 +++ HtmlTablesTest.java 2001/10/25 17:30:03 1.12 @@ -2,14 +2,14 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000, Russell Gold +* Copyright (c) 2000-2001, Russell Gold * -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -* documentation files (the "Software"), to deal in the Software without restriction, including without limitation +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +* documentation files (the "Software"), to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * -* The above copyright notice and this permission notice shall be included in all copies or substantial portions +* The above copyright notice and this permission notice shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO @@ -27,15 +27,18 @@ /** - * A unit test of the httpunit parsing classes. + * A unit test of the table handling code. + * + * @author <a href="mailto:rus...@ac...">Russell Gold</a> + * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a> **/ public class HtmlTablesTest extends HttpUnitTest { public static void main(String args[]) { junit.textui.TestRunner.run( suite() ); } - - + + public static Test suite() { return new TestSuite( HtmlTablesTest.class ); } @@ -53,9 +56,9 @@ defineWebPage( "OneTable", "<h2>Interesting data</h2>" + "<table summary=\"tough luck\">" + "<tr><td>One</td><td> </td><td>1</td></tr>" + - "<tr><td colspan=3><IMG SRC=\"/images/spacer.gif\" ALT=\"\" WIDTH=1 HEIGHT=1></td></tr>" + + "<tr><td colspan=3><IMG SRC=\"/images/spacer.gif\" ALT=\"\" WIDTH=1 HEIGHT=1></td></tr>" + "<tr><td>Two</td><td> </td><td>2</td></tr>" + - "<tr><td colspan=3><IMG SRC=\"/images/spacer.gif\" ALT=\"\" WIDTH=1 HEIGHT=1></td></tr>" + + "<tr><td colspan=3><IMG SRC=\"/images/spacer.gif\" ALT=\"\" WIDTH=1 HEIGHT=1></td></tr>" + "<tr><td>Three</td><td> </td><td>3</td></tr>" + "</table>" ); defineWebPage( "SpanTable", "<h2>Interesting data</h2>" + @@ -65,8 +68,8 @@ "<tr><td>Green</td><td><a href=\"nowhere\">vert</a></td></tr>" + "</table>" ); } - - + + public void testFindNoTables() throws Exception { defineWebPage( "Default", "This has no tables but it does" + "have <a href=\"/other.html\">an active link</A>" + @@ -143,8 +146,8 @@ assertEquals( "nested columns", 2, nested[0].getColumnCount() ); String nestedString = tables[0].getCellAsText( 0, 0 ); - assert( "Cannot find 'Red' in string", nestedString.indexOf( "Red" ) >= 0 ); - assert( "Cannot find 'Blue' in string", nestedString.indexOf( "Blue" ) >= 0 ); + assertTrue( "Cannot find 'Red' in string", nestedString.indexOf( "Red" ) >= 0 ); + assertTrue( "Cannot find 'Blue' in string", nestedString.indexOf( "Blue" ) >= 0 ); } @@ -256,6 +259,44 @@ assertEquals( "Non-blank rows", 3, cells.length ); assertEquals( "Non-blank columns", 2, cells[0].length ); assertEquals( "cell at 1,1", "Value", cells[1][1] ); + } + + /** + * Get a specific cell with a given id in a WebTable + * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a> + **/ + public void testCellsWithID() throws Exception { + defineWebPage( "Default", "<h2>Interesting data</h2>" + + "<table id=\"table\" summary=little>" + + "<tr><td>Title</td><td>Data</td></tr>" + + "<tr><td id=\"id1\">value1</td><td id=\"id2\">value2</td><td>Value</td></tr>" + + "<tr><td> </td><td> </td><td>Value</td></tr>" + + "</table>" ); + + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); + WebTable table = page.getTableWithID("table"); + assertNotNull("there is a table",table); + TableCell cell = table.getTableCellWithID("id1"); + assertNotNull("cell id1",cell); + assertEquals("Value of cell id1","value1",cell.asText()); + cell = table.getTableCellWithID("id2"); + assertNotNull("cell id2",cell); + assertEquals("Value of cell id2","value2",cell.asText()); + + // test non existent cell id + cell = table.getTableCellWithID("nonExistingID"); + assertNull("cell id2",cell); + + // check the ignore case.TRUE + HttpUnitOptions.setMatchesIgnoreCase(true); + cell = table.getTableCellWithID("iD2"); + assertNotNull("cell id2",cell); + assertEquals("Value of cell id2","value2",cell.asText()); + + // check the ignore case FALSE + HttpUnitOptions.setMatchesIgnoreCase(false); + cell = table.getTableCellWithID("iD2"); + assertNull("cell iD2",cell); } private WebConversation _wc; Index: HttpUnitTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitTest.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- HttpUnitTest.java 2001/08/06 20:19:41 1.15 +++ HttpUnitTest.java 2001/10/25 17:30:03 1.16 @@ -31,7 +31,9 @@ /** - * A unit test of the httpunit parsing classes. + * a base class for HttpUnit regression tests. + * + * @author <a href="mailto:rus...@ac...">Russell Gold</a> **/ abstract class HttpUnitTest extends TestCase { @@ -90,6 +92,10 @@ protected String getHostPath() { return _hostPath; + } + + public void assertTrue( String comment, boolean expression ) { + assert( comment, expression ); } |
From: Russell G. <rus...@us...> - 2001-10-25 14:51:09
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv19806/test/com/meterware/httpunit Modified Files: WebLinkTest.java WebPageTest.java Log Message: Added search for link by name and id Index: WebLinkTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebLinkTest.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- WebLinkTest.java 2001/10/24 18:06:28 1.10 +++ WebLinkTest.java 2001/10/25 14:51:05 1.11 @@ -58,9 +58,9 @@ defineResource( "SimplePage.html", "<html><head><title>A Sample Page</title></head>\n" + "<body>This has no forms but it does\n" + - "have <a href=\"/other.html\">an <b>active</b> link</A>\n" + + "have <a href=\"/other.html\" id=\"activeID\">an <b>active</b> link</A>\n" + " and <a name=here>an anchor</a>\n" + - "<a href=\"basic.html\"><IMG SRC=\"/images/arrow.gif\" ALT=\"Next -->\" WIDTH=1 HEIGHT=4></a>\n" + + "<a href=\"basic.html\" name=\"nextLink\"><IMG SRC=\"/images/arrow.gif\" ALT=\"Next -->\" WIDTH=1 HEIGHT=4></a>\n" + "</body></html>\n" ); WebConversation wc = new WebConversation(); @@ -118,6 +118,20 @@ HttpUnitOptions.setImagesTreatedAsAltText( false ); link = _simplePage.getLinkWith( "Next -->" ); assertNull( "the image link was found based on its hidden alt attribute", link ); + } + + + public void testGetLinkByIDAndName() throws Exception { + WebLink link = _simplePage.getLinkWithID( "noSuchID" ); + assertNull( "Non-existent link should not have been found", link ); + + link = _simplePage.getLinkWithID( "activeID" ); + assertNotNull( "an active link was not found", link ); + assertEquals( "active link URL", getHostPath() + "/other.html", link.getRequest().getURL().toExternalForm() ); + + link = _simplePage.getLinkWithName( "nextLink" ); + assertNotNull( "the image link was not found", link ); + assertEquals( "image link URL", getHostPath() + "/basic.html", link.getRequest().getURL().toExternalForm() ); } Index: WebPageTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebPageTest.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- WebPageTest.java 2001/10/25 14:15:59 1.16 +++ WebPageTest.java 2001/10/25 14:51:05 1.17 @@ -276,6 +276,7 @@ "<meta Http-equiv=\"Expires\" content=\"now\"/>\n" + "<meta name=\"robots\" content=\"index,follow\"/>" + "<meta name=\"keywords\" content=\"test\"/>" + + "<meta name=\"keywords\" content=\"demo\"/>" + "</head>\n" + "<body>This has no data\n" + "</body></html>\n"; @@ -285,9 +286,9 @@ WebRequest request = new GetMethodWebRequest( getHostPath() + "/SimplePage.html" ); WebResponse simplePage = wc.getResponse( request ); - assertEquals( "robots meta tag","index,follow",simplePage.getMetaTagContent("name","robots")); - assertEquals( "keywords meta tag","test",simplePage.getMetaTagContent("name","keywords")); - assertEquals( "Expires meta tag","now",simplePage.getMetaTagContent("http-equiv","Expires")); + assertMatchingSet( "robots meta tag", new String[] {"index,follow"}, simplePage.getMetaTagContent("name","robots")); + assertMatchingSet( "keywords meta tag",new String[] {"test","demo"},simplePage.getMetaTagContent("name","keywords")); + assertMatchingSet( "Expires meta tag",new String[] {"now"},simplePage.getMetaTagContent("http-equiv","Expires")); } /** |
From: Russell G. <rus...@us...> - 2001-10-25 14:51:09
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv19806/src/com/meterware/httpunit Modified Files: ParsedHTML.java ReceivedPage.java WebForm.java WebRequestSource.java WebResponse.java Log Message: Added search for link by name and id Index: ParsedHTML.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- ParsedHTML.java 2001/07/31 16:08:59 1.17 +++ ParsedHTML.java 2001/10/25 14:51:05 1.18 @@ -57,7 +57,8 @@ public WebForm getFormWithID( String ID ) { WebForm[] forms = getForms(); for (int i = 0; i < forms.length; i++) { - if (forms[i].getID().equalsIgnoreCase( ID )) return forms[i]; + if (forms[i].getID().equals( ID )) return forms[i]; + else if (HttpUnitOptions.getMatchesIgnoreCase() && forms[i].getID().equalsIgnoreCase( ID )) return forms[i]; } return null; } @@ -70,7 +71,8 @@ public WebForm getFormWithName( String name ) { WebForm[] forms = getForms(); for (int i = 0; i < forms.length; i++) { - if (forms[i].getName().equalsIgnoreCase( name )) return forms[i]; + if (forms[i].getName().equals( name )) return forms[i]; + else if (HttpUnitOptions.getMatchesIgnoreCase() && forms[i].getName().equalsIgnoreCase( name )) return forms[i]; } return null; } @@ -130,6 +132,34 @@ return links[i]; } } + } + return null; + } + + + /** + * Returns the link found in the page with the specified ID. + * @exception SAXException thrown if there is an error parsing the response. + **/ + public WebLink getLinkWithID( String ID ) { + WebLink[] links = getLinks(); + for (int i = 0; i < links.length; i++) { + if (links[i].getID().equals( ID )) return links[i]; + else if (HttpUnitOptions.getMatchesIgnoreCase() && links[i].getID().equalsIgnoreCase( ID )) return links[i]; + } + return null; + } + + + /** + * Returns the link found in the page with the specified name. + * @exception SAXException thrown if there is an error parsing the response. + **/ + public WebLink getLinkWithName( String name ) { + WebLink[] links = getLinks(); + for (int i = 0; i < links.length; i++) { + if (links[i].getName().equals( name )) return links[i]; + else if (HttpUnitOptions.getMatchesIgnoreCase() && links[i].getName().equalsIgnoreCase( name )) return links[i]; } return null; } Index: ReceivedPage.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ReceivedPage.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- ReceivedPage.java 2001/10/25 14:15:59 1.13 +++ ReceivedPage.java 2001/10/25 14:51:05 1.14 @@ -2,7 +2,7 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000, Russell Gold +* 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 @@ -76,30 +76,33 @@ /** - * Retrieves the "content" of the first meta tag for a key pair attribute-attributeValue. + * Retrieves the "content" of the meta tags for a key pair attribute-attributeValue. * <code> - * <meta name="robots" content="index,follow" /> - <meta http-equiv="Expires" content="now" /> + * <meta name="robots" content="index" /> + * <meta name="robots" content="follow" /> + * <meta http-equiv="Expires" content="now" /> * </code> * this can be used like this * <code> - * getMetaTagContent("name","robots") will return "index,follow" - * getMetaTagContent("http-equiv","Expires") will return "now" + * getMetaTagContent("name","robots") will return { "index","follow" } + * getMetaTagContent("http-equiv","Expires") will return { "now" } * </code> - * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a> **/ - public String getMetaTagContent(String attribute, String attributeValue) { + public String[] getMetaTagContent(String attribute, String attributeValue) { + Vector matches = new Vector(); NodeList nl = ((Document) getDOM()).getElementsByTagName("meta"); int length = nl.getLength(); - if (length == 0) return ""; for (int i = 0; i < length; i++) { if (attributeValue.equalsIgnoreCase(NodeUtils.getNodeAttribute(nl.item(i), attribute))) { - return NodeUtils.getNodeAttribute(nl.item(i), "content"); + matches.addElement( NodeUtils.getNodeAttribute( nl.item(i), "content" ) ); } } - return ""; + String result[] = new String[ matches.size() ]; + matches.copyInto( result ); + return result; } + private static Node getDOM( String pageText ) throws SAXException { try { Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- WebForm.java 2001/10/19 19:16:57 1.27 +++ WebForm.java 2001/10/25 14:51:05 1.28 @@ -57,14 +57,6 @@ } - /** - * Returns the name of the form. - **/ - public String getName() { - return NodeUtils.getNodeAttribute( getNode(), "name" ); - } - - /** * Returns an array containing the names of the parameters defined for this form, * in the order in which they appear. Index: WebRequestSource.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequestSource.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- WebRequestSource.java 2001/07/31 16:08:59 1.1 +++ WebRequestSource.java 2001/10/25 14:51:05 1.2 @@ -37,6 +37,14 @@ /** + * Returns the name associated with this request source. + **/ + public String getName() { + return NodeUtils.getNodeAttribute( _node, "name" ); + } + + + /** * Returns the target for this request source. **/ public String getTarget() { Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.49 retrieving revision 1.50 diff -u -r1.49 -r1.50 --- WebResponse.java 2001/10/25 14:15:59 1.49 +++ WebResponse.java 2001/10/25 14:51:05 1.50 @@ -108,20 +108,20 @@ } /** - * Retrieves the "content" of the first meta tag for a key pair attribute-attributeValue. + * Retrieves the "content" of the meta tags for a key pair attribute-attributeValue. * <code> - * <meta name="robots" content="index,follow" /> - * <meta http-equiv="Expires" content="now" /> + * <meta name="robots" content="index" /> + * <meta name="robots" content="follow" /> + * <meta http-equiv="Expires" content="now" /> * </code> - * can be used as follows: + * this can be used like this * <code> - * getMetaTagContent("name","robots") will return "index,follow" - * getMetaTagContent("http-equiv","Expires") will return "now" + * getMetaTagContent("name","robots") will return { "index","follow" } + * getMetaTagContent("http-equiv","Expires") will return { "now" } * </code> * @exception SAXException thrown if there is an error parsing this response - * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a> **/ - public String getMetaTagContent(String attribute, String attributeValue) throws SAXException { + public String[] getMetaTagContent(String attribute, String attributeValue) throws SAXException { return getReceivedPage().getMetaTagContent(attribute, attributeValue); } @@ -304,6 +304,24 @@ **/ public WebLink getLinkWithImageText( String text ) throws SAXException { return getReceivedPage().getLinkWithImageText( text ); + } + + + /** + * Returns the link found in the page with the specified name. + * @exception SAXException thrown if there is an error parsing the response. + **/ + public WebLink getLinkWithName( String name ) throws SAXException { + return getReceivedPage().getLinkWithName( name ); + } + + + /** + * Returns the link found in the page with the specified ID. + * @exception SAXException thrown if there is an error parsing the response. + **/ + public WebLink getLinkWithID( String ID ) throws SAXException { + return getReceivedPage().getLinkWithID( ID ); } |
From: Russell G. <rus...@us...> - 2001-10-25 14:51:08
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv19806/doc Modified Files: release_notes.txt Log Message: Added search for link by name and id Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.58 retrieving revision 1.59 diff -u -r1.58 -r1.59 --- release_notes.txt 2001/10/25 14:15:59 1.58 +++ release_notes.txt 2001/10/25 14:51:05 1.59 @@ -6,7 +6,6 @@ This behavior matches that currently used by IE and Navigator. 3. No order is guaranteed for parameters from forms, contrary to the HTML 4.01 spec 4. No parameter validation is done for requests built from links - 5. getMetaTagContent only returns the first matching meta tag. Limitations: HttpUnit does not support JavaScript @@ -14,12 +13,14 @@ 24-Oct-2001 Acknowledgements: - Thanks to Benoit Xhenseval for adding parameter detection in links, and handling of meta and link tags. + Thanks to Benoit Xhenseval for adding parameter detection in links and handling of meta and link tags. Additions: 1. getParameter() and getParameterNames() now works for requests built from links with embedded parameters. 2. WebResponse.getMetaTagContent can be used to obtain the content of a meta tag (see the Javadoc) 3. WebResponse.getStylesheet can be used to obtain the path to the stylesheet associated with a page. + 4. Added name attribute to WebLink + 5. Added getLinkWithID and getLinkWithName to WebResponse 19-Oct-2001 Additions: |
From: Russell G. <rus...@us...> - 2001-10-25 14:16:03
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv10521/src/com/meterware/httpunit Modified Files: ReceivedPage.java WebResponse.java Log Message: Benoit Xhenseval: Added getStylesheet and getMetaTagContent Index: ReceivedPage.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ReceivedPage.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- ReceivedPage.java 2001/02/02 14:34:29 1.12 +++ ReceivedPage.java 2001/10/25 14:15:59 1.13 @@ -4,12 +4,12 @@ * * Copyright (c) 2000, Russell Gold * -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -* documentation files (the "Software"), to deal in the Software without restriction, including without limitation +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +* documentation files (the "Software"), to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * -* The above copyright notice and this permission notice shall be included in all copies or substantial portions +* The above copyright notice and this permission notice shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO @@ -36,6 +36,9 @@ /** * This class represents an HTML page returned from a request. + * + * @author <a href="mailto:rus...@ac...">Russell Gold</a> + * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a> **/ class ReceivedPage extends ParsedHTML { @@ -56,6 +59,47 @@ return nl.item(0).getFirstChild().getNodeValue(); } + /** + * Returns the location of the linked stylesheet in the head + * <code> + * <link type="text/css" rel="stylesheet" href="/mystyle.css" /> + * </code> + * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a> + **/ + public String getExternalStyleSheet() throws SAXException { + NodeList nl = ((Document) getDOM()).getElementsByTagName( "link" ); + if (nl.getLength() == 0) return ""; + if ("stylesheet".equalsIgnoreCase(NodeUtils.getNodeAttribute( nl.item(0), "rel" ))) + return NodeUtils.getNodeAttribute( nl.item(0), "href" ); + return ""; + } + + + /** + * Retrieves the "content" of the first meta tag for a key pair attribute-attributeValue. + * <code> + * <meta name="robots" content="index,follow" /> + <meta http-equiv="Expires" content="now" /> + * </code> + * this can be used like this + * <code> + * getMetaTagContent("name","robots") will return "index,follow" + * getMetaTagContent("http-equiv","Expires") will return "now" + * </code> + * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a> + **/ + public String getMetaTagContent(String attribute, String attributeValue) { + NodeList nl = ((Document) getDOM()).getElementsByTagName("meta"); + int length = nl.getLength(); + if (length == 0) return ""; + + for (int i = 0; i < length; i++) { + if (attributeValue.equalsIgnoreCase(NodeUtils.getNodeAttribute(nl.item(i), attribute))) { + return NodeUtils.getNodeAttribute(nl.item(i), "content"); + } + } + return ""; + } private static Node getDOM( String pageText ) throws SAXException { try { @@ -85,7 +129,7 @@ NodeList nl = ((Document) getDOM()).getElementsByTagName( "base" ); if (nl.getLength() == 0) return; try { - applyBaseAttributes( NodeUtils.getNodeAttribute( nl.item(0), "href" ), + applyBaseAttributes( NodeUtils.getNodeAttribute( nl.item(0), "href" ), NodeUtils.getNodeAttribute( nl.item(0), "target" ) ); } catch (MalformedURLException e) { throw new RuntimeException( "Unable to set document base: " + e ); @@ -105,7 +149,7 @@ private static Tidy getParser() { Tidy tidy = new Tidy(); - tidy.setCharEncoding( org.w3c.tidy.Configuration.UTF8 ); + tidy.setCharEncoding( org.w3c.tidy.Configuration.UTF8 ); tidy.setQuiet( true ); tidy.setShowWarnings( HttpUnitOptions.getParserWarningsEnabled() ); return tidy; Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.48 retrieving revision 1.49 diff -u -r1.48 -r1.49 --- WebResponse.java 2001/10/16 16:21:25 1.48 +++ WebResponse.java 2001/10/25 14:15:59 1.49 @@ -55,6 +55,7 @@ * @author <a href="mailto:rus...@ac...">Russell Gold</a> * @author <a href="mailto:DRE...@or...">Drew Varner</a> * @author <a href="mailto:dg...@ss...">Dave Glowacki</a> + * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a> **/ abstract public class WebResponse implements HTMLSegment { @@ -92,6 +93,37 @@ return getReceivedPage().getTitle(); } + + /** + * Returns the stylesheet linked in the head of the page. + * <code> + * <link type="text/css" rel="stylesheet" href="/mystyle.css" /> + * </code> + * will return "/mystyle.css". + * @exception SAXException thrown if there is an error parsing this response + * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a> + **/ + public String getExternalStyleSheet() throws SAXException { + return getReceivedPage().getExternalStyleSheet(); + } + + /** + * Retrieves the "content" of the first meta tag for a key pair attribute-attributeValue. + * <code> + * <meta name="robots" content="index,follow" /> + * <meta http-equiv="Expires" content="now" /> + * </code> + * can be used as follows: + * <code> + * getMetaTagContent("name","robots") will return "index,follow" + * getMetaTagContent("http-equiv","Expires") will return "now" + * </code> + * @exception SAXException thrown if there is an error parsing this response + * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a> + **/ + public String getMetaTagContent(String attribute, String attributeValue) throws SAXException { + return getReceivedPage().getMetaTagContent(attribute, attributeValue); + } /** * Returns the target of the page. |
From: Russell G. <rus...@us...> - 2001-10-25 14:16:03
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv10521/test/com/meterware/httpunit Modified Files: WebPageTest.java Log Message: Benoit Xhenseval: Added getStylesheet and getMetaTagContent Index: WebPageTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebPageTest.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- WebPageTest.java 2001/10/16 16:21:25 1.15 +++ WebPageTest.java 2001/10/25 14:15:59 1.16 @@ -4,12 +4,12 @@ * * Copyright (c) 2000-2001, Russell Gold * -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -* documentation files (the "Software"), to deal in the Software without restriction, including without limitation +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +* documentation files (the "Software"), to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * -* The above copyright notice and this permission notice shall be included in all copies or substantial portions +* The above copyright notice and this permission notice shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO @@ -35,15 +35,18 @@ /** - * A unit test of the httpunit parsing classes. + * Unit tests for page structure, style, and headers. + * + * @author <a href="mailto:rus...@ac...">Russell Gold</a> + * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a> **/ public class WebPageTest extends HttpUnitTest { public static void main(String args[]) { junit.textui.TestRunner.run( suite() ); } - - + + public static Test suite() { return new TestSuite( WebPageTest.class ); } @@ -59,8 +62,8 @@ HttpUnitOptions.resetDefaultCharacterSet(); HttpUnitOptions.setAutoRefresh( false ); } - - + + public void testNoResponse() throws Exception { WebConversation wc = new WebConversation(); try { @@ -186,8 +189,8 @@ public WebResource getPostResponse() { try { String name = getParameter( "name" )[0]; - WebResource result = new WebResource( "<html><body><table><tr><td>Hello, " + - new String( name.getBytes( "iso-8859-1" ), "iso-8859-8" ) + + WebResource result = new WebResource( "<html><body><table><tr><td>Hello, " + + new String( name.getBytes( "iso-8859-1" ), "iso-8859-8" ) + "</td></tr></table></body></html>" ); result.setCharacterSet( "iso-8859-8" ); result.setSendCharacterSet( true ); @@ -263,6 +266,49 @@ assertNull( "No refresh request should have been found", simplePage.getRefreshRequest() ); } + /** + * Test the meta tag content retrieval + * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a> + **/ + public void testMetaTag() throws Exception { + String refreshURL = getHostPath() + "/NextPage.html"; + String page = "<html><head><title>Sample</title>" + + "<meta Http-equiv=\"Expires\" content=\"now\"/>\n" + + "<meta name=\"robots\" content=\"index,follow\"/>" + + "<meta name=\"keywords\" content=\"test\"/>" + + "</head>\n" + + "<body>This has no data\n" + + "</body></html>\n"; + defineResource( "SimplePage.html", page ); + + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest( getHostPath() + "/SimplePage.html" ); + WebResponse simplePage = wc.getResponse( request ); + + assertEquals( "robots meta tag","index,follow",simplePage.getMetaTagContent("name","robots")); + assertEquals( "keywords meta tag","test",simplePage.getMetaTagContent("name","keywords")); + assertEquals( "Expires meta tag","now",simplePage.getMetaTagContent("http-equiv","Expires")); + } + + /** + * test the stylesheet retrieval + * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a> + **/ + public void testGetExternalStylesheet() throws Exception { + String refreshURL = getHostPath() + "/NextPage.html"; + String page = "<html><head><title>Sample</title>" + + "<link type=\"text/css\" rel=\"stylesheet\" href=\"/style.css\"/>" + + "</head>\n" + + "<body>This has no data\n" + + "</body></html>\n"; + defineResource( "SimplePage.html", page ); + + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest( getHostPath() + "/SimplePage.html" ); + WebResponse simplePage = wc.getResponse( request ); + + assertEquals( "Stylesheet","/style.css",simplePage.getExternalStyleSheet()); + } private String toUnicode( String string ) { StringBuffer sb = new StringBuffer( ); |
From: Russell G. <rus...@us...> - 2001-10-25 14:16:02
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv10521/doc Modified Files: release_notes.txt todo.txt Log Message: Benoit Xhenseval: Added getStylesheet and getMetaTagContent Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.57 retrieving revision 1.58 diff -u -r1.57 -r1.58 --- release_notes.txt 2001/10/24 18:06:28 1.57 +++ release_notes.txt 2001/10/25 14:15:59 1.58 @@ -6,6 +6,7 @@ This behavior matches that currently used by IE and Navigator. 3. No order is guaranteed for parameters from forms, contrary to the HTML 4.01 spec 4. No parameter validation is done for requests built from links + 5. getMetaTagContent only returns the first matching meta tag. Limitations: HttpUnit does not support JavaScript @@ -13,10 +14,12 @@ 24-Oct-2001 Acknowledgements: - Thanks to Benoit Xhenseval for adding parameter detection in links. + Thanks to Benoit Xhenseval for adding parameter detection in links, and handling of meta and link tags. Additions: 1. getParameter() and getParameterNames() now works for requests built from links with embedded parameters. + 2. WebResponse.getMetaTagContent can be used to obtain the content of a meta tag (see the Javadoc) + 3. WebResponse.getStylesheet can be used to obtain the path to the stylesheet associated with a page. 19-Oct-2001 Additions: Index: todo.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/todo.txt,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- todo.txt 2001/10/24 18:06:28 1.19 +++ todo.txt 2001/10/25 14:15:59 1.20 @@ -1,7 +1,6 @@ High Priority o Allow servlet initialization parameters in registerServlet o Add support for getLinkWithName -o Add WebResponse.getMetaContent (returns array of matching content entries) o Prevent setParameter calls from working on requests built from links if validation is enabled Medium priority: |
From: Russell G. <rus...@us...> - 2001-10-24 18:06:31
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv10818/test/com/meterware/httpunit Modified Files: WebLinkTest.java Log Message: from Benoit Xhenseval: added parameter detection for link-based requests Index: WebLinkTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebLinkTest.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- WebLinkTest.java 2001/07/31 16:08:59 1.9 +++ WebLinkTest.java 2001/10/24 18:06:28 1.10 @@ -2,14 +2,14 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000, Russell Gold +* Copyright (c) 2000-2001, Russell Gold * -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -* documentation files (the "Software"), to deal in the Software without restriction, including without limitation +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +* documentation files (the "Software"), to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * -* The above copyright notice and this permission notice shall be included in all copies or substantial portions +* The above copyright notice and this permission notice shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO @@ -27,18 +27,22 @@ import junit.framework.TestSuite; import java.util.Vector; +import java.util.Enumeration; /** - * A unit test of the httpunit parsing classes. + * Tests for the WebLink class. + * + * @author <a href="mailto:rus...@ac...>Russell Gold</a> + * @author <a href="mailto:ben...@av...>Benoit Xhenseval</a> **/ public class WebLinkTest extends HttpUnitTest { public static void main(String args[]) { junit.textui.TestRunner.run( suite() ); } - - + + public static Test suite() { return new TestSuite( WebLinkTest.class ); } @@ -62,8 +66,8 @@ WebConversation wc = new WebConversation(); _simplePage = wc.getResponse( getHostPath() + "/SimplePage.html" ); } - - + + public void testFindNoLinks() throws Exception { defineResource( "NoLinks.html", "<html><head><title>NoLinks</title></head><body>No links at all</body></html>" ); WebConversation wc = new WebConversation(); @@ -79,7 +83,7 @@ assertNotNull( links ); assertEquals( 2, links.length ); } - + public void testLinkRequest() throws Exception { WebLink link = _simplePage.getLinks()[0]; @@ -127,7 +131,7 @@ WebConversation wc = new WebConversation(); defineWebPage( "Initial", "Go to <a href=\"Next.html\">the next page.</a> <a name=\"bottom\">Bottom</a>" ); defineWebPage( "Next", "And go back to <a href=\"Initial.html#Bottom\">the first page.</a>" ); - + WebResponse initialPage = wc.getResponse( getHostPath() + "/Initial.html" ); assertEquals( "Num links in initial page", 1, initialPage.getLinks().length ); WebLink link = initialPage.getLinks()[0]; @@ -158,8 +162,8 @@ WebResponse nextPage = wc.getResponse( request ); assert( "Did not find the target", nextPage.getText().indexOf( "Found" ) >= 0 ); } + - public void testTargetBase() throws Exception { WebConversation wc = new WebConversation(); defineWebPage( "alternate/Target", "Found me!" ); @@ -176,6 +180,87 @@ } + public void testParametersOnLinks() throws Exception { + defineResource( "ParameterLinks.html", + "<html><head><title>Param on Link Page</title></head>\n" + + "<body>" + + "<a href=\"/other.html\">no parameter link</A>\n" + + "<a href=\"/other.html?param1=value1\">one parameter link</A>\n" + + "<a href=\"/other.html?param1=value1¶m2=value2\">two parameters link</A>\n" + + "<a href=\"/other.html?param1=value1¶m1=value3\">two values link</A>\n" + + "<a href=\"/other.html?param1=value1¶m2=value2¶m1=value3\">two values link</A>\n" + + "</body></html>\n" ); + WebConversation wc = new WebConversation(); + + WebLink[] links = wc.getResponse( getHostPath() + "/ParameterLinks.html" ).getLinks(); + assertNotNull( links ); + assertEquals( "number of links", 5, links.length ); + WebRequest request; + + // first link should not have any param + request = links[0].getRequest(); + assertNotNull( request); + Enumeration e = request.getParameterNames(); + assertNotNull( e); + assert( !e.hasMoreElements() ); + + // second link should have one parameter + request = links[1].getRequest(); + assertNotNull( request ); + e = request.getParameterNames(); + assert( e.hasMoreElements() ); + String paramName = (String)e.nextElement(); + assertNotNull(paramName); + assert(!e.hasMoreElements()); + assertEquals("param1",paramName); + assertEquals("value1",request.getParameter(paramName)); + + // third link should have 2 parameters. !! Order of parameters cannot be guaranted. + request = links[2].getRequest(); + assertNotNull( request ); + e = request.getParameterNames(); + assert( e.hasMoreElements() ); + paramName = (String)e.nextElement(); + assertNotNull(paramName); + assert(e.hasMoreElements()); + String paramName2 = (String)e.nextElement(); + assertNotNull(paramName2); + assert("different names",!paramName.equals(paramName2)); + assert("test names for param1",paramName.equals("param1") || paramName2.equals("param1")); + assert("test names for param2",paramName.equals("param2") || paramName2.equals("param2")); + assertEquals("value1",request.getParameter("param1")); + assertEquals("value2",request.getParameter("param2")); + + // fourth link should have 1 parameter with 2 values. + request = links[3].getRequest(); + assertNotNull( request ); + e = request.getParameterNames(); + assert( e.hasMoreElements() ); + paramName = (String)e.nextElement(); + assertNotNull(paramName); + String[] values = request.getParameterValues("param1"); + assertEquals("Length of ",2,values.length); + assertMatchingSet("Values",new String[] {"value1", "value3"}, values); + + // fifth link should have 2 parameters with one with 2 values. + request = links[4].getRequest(); + assertNotNull( request ); + e = request.getParameterNames(); + assert( e.hasMoreElements() ); + paramName = (String)e.nextElement(); + assertNotNull(paramName); + assert( e.hasMoreElements() ); + paramName2 = (String)e.nextElement(); + assertNotNull(paramName2); + assert("different names",!paramName.equals(paramName2)); + values = request.getParameterValues("param1"); + assertEquals("Length of ",2,values.length); + assertMatchingSet("Values for param1",new String[] {"value1", "value3"}, values); + assertMatchingSet("Values form param2",new String[] {"value2"}, request.getParameterValues("param2")); + assertEquals("value2",request.getParameter("param2")); + } + + public void testImageMapLinks() throws Exception { WebConversation wc = new WebConversation(); defineWebPage( "pageWithMap", "Here is a page with <a href=\"somewhere\">a link</a>" + @@ -193,9 +278,5 @@ assertEquals( "Relative URL", "guide.html", guide.getURLString() ); } - - private WebResponse _simplePage; - - } |
From: Russell G. <rus...@us...> - 2001-10-24 18:06:31
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv10818/src/com/meterware/httpunit Modified Files: WebLink.java Log Message: from Benoit Xhenseval: added parameter detection for link-based requests Index: WebLink.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- WebLink.java 2001/10/24 17:57:07 1.8 +++ WebLink.java 2001/10/24 18:06:28 1.9 @@ -19,9 +19,14 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ - import java.net.URL; +import java.util.Vector; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.StringTokenizer; + +import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; /** @@ -30,21 +35,98 @@ * on the link. * * @author Russell Gold + * @author <a href="mailto:ben...@av...>Benoit Xhenseval</a> **/ public class WebLink extends WebRequestSource { - /** * Creates and returns a web request which will simulate clicking on this link. **/ public WebRequest getRequest() { - WebRequest request = new GetMethodWebRequest( getBaseURL(), getURLString(), getTarget() ); + WebRequest request = new GetMethodWebRequest( getBaseURL(), getBareURL(), getTarget() ); + addPresetParameters( request ); request.setRequestHeader( "Referer", getBaseURL().toExternalForm() ); return request; } /** + * Strips a URL from its parameters + **/ + private String getBareURL() { + String url = getURLString(); + int questionMarkIndex = url.indexOf("?"); + if (questionMarkIndex >= 1 && questionMarkIndex < url.length() - 1) { + return url.substring(0, questionMarkIndex); + } + return url; + } + + + private void addPresetParameters(WebRequest request) { + Hashtable params = getPresetParameters(); + Enumeration e = params.keys(); + while (e.hasMoreElements()) { + String key = (String) e.nextElement(); + request.setParameter( key, (String[]) params.get( key ) ); + } + } + + + /** + * Gets all parameters from a URL + **/ + private String getParametersString() { + String url = getURLString(); + int questionMarkIndex = url.indexOf("?"); + if (questionMarkIndex >= 1 && questionMarkIndex < url.length() - 1) { + return url.substring(questionMarkIndex + 1); + } + return ""; + } + + + /** + * Builds list of parameters + **/ + private Hashtable getPresetParameters() { + Hashtable params = new Hashtable(); + StringTokenizer st = new StringTokenizer( getParametersString(), PARAM_DELIM ); + while (st.hasMoreTokens()) stripOneParameter( params, st.nextToken() ); + return params; + } + + + /** + * add a pair key-value to the hashtable, creates an array of values if param already exists. + **/ + private void stripOneParameter(Hashtable params, String param) { + int index = param.indexOf("="); + if (index <= 0 || index == param.length() - 1) return; + + String value = param.substring(index + 1); + String key = param.substring(0, index); + params.put( key, withNewValue( (String[]) params.get( key ), value ) ); + } + + + /** + * Returns a string array created by appending a string to an existing array. The existing array may be null. + **/ + private String[] withNewValue( String[] oldValue, String newValue ) { + String[] result; + if (oldValue == null) { + result = new String[] { newValue }; + } else { + result = new String[ oldValue.length+1 ]; + System.arraycopy( oldValue, 0, result, 0, oldValue.length ); + result[ oldValue.length ] = newValue; + } + return result; + } + + + /** * Returns the URL referenced by this link. This may be a relative URL. **/ public String getURLString() { @@ -77,5 +159,9 @@ super( node, baseURL, parentTarget ); } -} +//---------------------------------- private members -------------------------------- + private static final Hashtable NO_PARAMS = new Hashtable(); + private static final String PARAM_DELIM = "&"; + +} |
From: Russell G. <rus...@us...> - 2001-10-24 18:06:31
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv10818/doc Modified Files: release_notes.txt todo.txt Log Message: from Benoit Xhenseval: added parameter detection for link-based requests Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.56 retrieving revision 1.57 diff -u -r1.56 -r1.57 --- release_notes.txt 2001/10/19 19:16:57 1.56 +++ release_notes.txt 2001/10/24 18:06:28 1.57 @@ -5,10 +5,18 @@ 2. The "accept-charset" attribute for forms is ignored; the page content character set is used to encode any response. This behavior matches that currently used by IE and Navigator. 3. No order is guaranteed for parameters from forms, contrary to the HTML 4.01 spec + 4. No parameter validation is done for requests built from links Limitations: HttpUnit does not support JavaScript Revision History: + +24-Oct-2001 + Acknowledgements: + Thanks to Benoit Xhenseval for adding parameter detection in links. + + Additions: + 1. getParameter() and getParameterNames() now works for requests built from links with embedded parameters. 19-Oct-2001 Additions: Index: todo.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/todo.txt,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- todo.txt 2001/10/24 16:37:42 1.18 +++ todo.txt 2001/10/24 18:06:28 1.19 @@ -2,6 +2,7 @@ o Allow servlet initialization parameters in registerServlet o Add support for getLinkWithName o Add WebResponse.getMetaContent (returns array of matching content entries) +o Prevent setParameter calls from working on requests built from links if validation is enabled Medium priority: o Support optional tags which hide their contents (as in IFRAME, OBJECT, etc.) |
From: Russell G. <rus...@us...> - 2001-10-24 17:57:10
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv8436/src/com/meterware/httpunit Modified Files: WebLink.java Log Message: Added header Index: WebLink.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- WebLink.java 2001/07/31 16:08:59 1.7 +++ WebLink.java 2001/10/24 17:57:07 1.8 @@ -1,13 +1,35 @@ 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. +* +*******************************************************************************************************************/ import java.net.URL; import org.w3c.dom.Node; /** - * This class represents a link in an HTML page. Users of this class may examine the + * This class represents a link in an HTML page. Users of this class may examine the * structure of the link (as a DOM), or create a {@tag WebRequest} to simulate clicking * on the link. + * + * @author Russell Gold **/ public class WebLink extends WebRequestSource { @@ -17,8 +39,8 @@ **/ public WebRequest getRequest() { WebRequest request = new GetMethodWebRequest( getBaseURL(), getURLString(), getTarget() ); - request.setRequestHeader( "Referer", getBaseURL().toExternalForm() ); - return request; + request.setRequestHeader( "Referer", getBaseURL().toExternalForm() ); + return request; } |
From: Russell G. <rus...@us...> - 2001-10-24 16:37:45
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv17199/doc Modified Files: faq.html todo.txt Log Message: Update docs Index: faq.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/faq.html,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- faq.html 2001/08/21 19:56:21 1.10 +++ faq.html 2001/10/24 16:37:42 1.11 @@ -95,11 +95,8 @@ <A HREF="#badPost"><H2>Why doesn't my servlet see parameters on a POST request?</H2></A> Some older servlet engines, such as Tomcat 3.1, get confused when they see a charset attribute on the Content-Type -header. HttpUnit normally sends this attribute; -however you can disable it by calling <code>HttpUnitOptions.setPostIncludesCharset(false)</code>. If you run into this -problem trying disabling the charset attribute. - - +header. HttpUnit 1.2.6 sends this attribute; As of HttpUnit 1.2.7 it will only send it if you call +<code>HttpUnitOptions.setPostIncludesCharset(true)</code> before your request. </BODY></HTML> Index: todo.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/todo.txt,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- todo.txt 2001/10/15 18:25:58 1.17 +++ todo.txt 2001/10/24 16:37:42 1.18 @@ -1,9 +1,7 @@ High Priority o Allow servlet initialization parameters in registerServlet -o Allow multiple text parameters with the same name o Add support for getLinkWithName -o Allow creation of POST method with file upload w/o form -o Other changes already submitted +o Add WebResponse.getMetaContent (returns array of matching content entries) Medium priority: o Support optional tags which hide their contents (as in IFRAME, OBJECT, etc.) |
From: Russell G. <rus...@us...> - 2001-10-19 19:17:00
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv17965/test/com/meterware/httpunit Modified Files: FormParametersTest.java Log Message: Allow multi-values text parameters Index: FormParametersTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FormParametersTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- FormParametersTest.java 2001/08/06 20:19:41 1.5 +++ FormParametersTest.java 2001/10/19 19:16:57 1.6 @@ -128,8 +128,28 @@ request.setParameter( "password", "purple" ); request.setParameter( "secret", "value" ); validateSetParameterRejected( request, "colors", new String[] { "blue", "red" }, "setting input to multiple values" ); - validateSetParameterRejected( request, "fish", new String[] { "red", "pink" }, "setting password to multiple values" ); + validateSetParameterRejected( request, "password", new String[] { "red", "pink" }, "setting password to multiple values" ); validateSetParameterRejected( request, "secret", new String[] { "red", "pink" }, "setting hidden field to multiple values" ); + } + + public void testMultipleTextParameterValidation() throws Exception { + defineWebPage( "Default", "<form method=GET action = \"/ask\">" + + "<Input type=text name=color>" + + "<Input type=password name=password>" + + "<Input type=hidden name=color>" + + "<Input type=submit></form>" ); + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); + WebForm form = page.getForms()[0]; + WebRequest request = form.getRequest(); + HttpUnitOptions.setParameterValuesValidated( true ); + + assertEquals( "Number of parameters named 'password'", 1, form.getNumTextParameters( "password" ) ); + assertEquals( "Number of parameters named 'color'", 2, form.getNumTextParameters( "color" ) ); + request.setParameter( "color", "green" ); + request.setParameter( "password", "purple" ); + request.setParameter( "color", new String[] { "red", "green" } ); + validateSetParameterRejected( request, "colors", new String[] { "blue", "red", "green" }, "setting input to multiple values" ); + validateSetParameterRejected( request, "password", new String[] { "red", "pink" }, "setting password to multiple values" ); } |
From: Russell G. <rus...@us...> - 2001-10-19 19:17:00
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv17965/src/com/meterware/httpunit Modified Files: WebForm.java WebRequest.java Log Message: Allow multi-values text parameters Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- WebForm.java 2001/08/21 19:56:22 1.26 +++ WebForm.java 2001/10/19 19:16:57 1.27 @@ -337,6 +337,22 @@ /** + * Returns the number of text parameters in this form with the specified name. + **/ + public int getNumTextParameters( String name ) { + Object count = getTextParameterCounts().get( name ); + if (count == null) return 0; + return ((Number) count ).intValue(); + } + + + private Hashtable getTextParameterCounts() { + getParameterTypes(); + return _textParameterCounts; + } + + + /** * Returns true if the named parameter accepts files for upload. **/ public boolean isFileParameter( String name ) { @@ -378,7 +394,10 @@ /** The type of a parameter which accepts files for upload. **/ private final static Integer TYPE_FILE = new Integer(4); + /** A constant set to indicate one parameter. **/ + private final static Integer ONE_PARAMETER = new Integer(1); + /** The attributes of the form parameters. **/ private NamedNodeMap[] _parameters; @@ -394,6 +413,9 @@ /** The parameters mapped to the type of data which they accept. **/ private Hashtable _dataTypes; + /** The parameters mapped to their number of occurrences as text parameters. **/ + private Hashtable _textParameterCounts; + /** The submit buttons in this form. **/ private SubmitButton[] _submitButtons; @@ -513,19 +535,26 @@ if (_dataTypes == null) { NamedNodeMap[] parameters = getParameters(); Hashtable types = new Hashtable(); + _textParameterCounts = new Hashtable(); for (int i = 0; i < parameters.length; i++) { String name = getValue( parameters[i].getNamedItem( "name" ) ); String type = getValue( parameters[i].getNamedItem( "type" ) ).toUpperCase(); if (type == null || type.length() == 0) type = "TEXT"; - if (type.equals( "TEXT" ) || type.equals( "HIDDEN" ) || type.equals( "PASSWORD" )) { - types.put( name, TYPE_TEXT ); - } else if (type.equals( "RADIO" )) { + if (type.equals( "RADIO" )) { types.put( name, TYPE_SCALAR ); } else if (type.equals( "CHECKBOX" )) { types.put( name, TYPE_MULTI_VALUED ); } else if (type.equals( "FILE" )) { types.put( name, TYPE_FILE ); + } else if (type.equals( "TEXT" ) || type.equals( "HIDDEN" ) || type.equals( "PASSWORD" )) { + types.put( name, TYPE_TEXT ); + Integer oldCount = (Integer) _textParameterCounts.get( name ); + if (oldCount == null) { + _textParameterCounts.put( name, ONE_PARAMETER ); + } else { + _textParameterCounts.put( name, new Integer( oldCount.intValue() + 1 ) ); + } } } HTMLSelectElement[] selections = getSelections(); Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- WebRequest.java 2001/10/19 18:26:29 1.25 +++ WebRequest.java 2001/10/19 19:16:57 1.26 @@ -497,7 +497,11 @@ private void validateParameterValues( String name, String[] values ) { if (_sourceForm == null) return; if (values.length > 1 && !_sourceForm.isMultiValuedParameter( name )) { - throw new SingleValuedParameterException( name ); + if (!_sourceForm.isTextParameter( name ) || _sourceForm.getNumTextParameters( name ) == 1) { + throw new SingleValuedParameterException( name ); + } else if (values.length > _sourceForm.getNumTextParameters( name )) { + throw new TextParameterCountException( name, _sourceForm.getNumTextParameters( name ) ); + } } for (int i = 0; i < values.length; i++) validateParameterValue( name, values[i] ); @@ -661,6 +665,29 @@ private String _parameterName; + +} + + +/** + * This exception is thrown on an attempt to set a text parameter to more values than are allowed. + **/ +class TextParameterCountException extends IllegalRequestParameterException { + + + TextParameterCountException( String parameterName, int numAllowed ) { + _parameterName = parameterName; + _numAllowed = numAllowed; + } + + + public String getMessage() { + return "Parameter '" + _parameterName + "' may have no more than " + _numAllowed + " values."; + } + + + private String _parameterName; + private int _numAllowed; } |
From: Russell G. <rus...@us...> - 2001-10-19 19:17:00
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv17965/doc Modified Files: release_notes.txt Log Message: Allow multi-values text parameters Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.55 retrieving revision 1.56 diff -u -r1.55 -r1.56 --- release_notes.txt 2001/10/19 18:26:29 1.55 +++ release_notes.txt 2001/10/19 19:16:57 1.56 @@ -10,6 +10,10 @@ Revision History: +19-Oct-2001 + Additions: + 1. Requests may now have as many values for a text parameter name as the number of <INPUT> tags with that name. + 18-Oct-2001 Additions: 1. It is now possible to upload a file via a POST request not derived from a form. To do this, call |
From: Russell G. <rus...@us...> - 2001-10-19 18:26:32
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv7181/test/com/meterware/httpunit Modified Files: FileUploadTest.java Log Message: Allow file uploads in POST w/o form Index: FileUploadTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FileUploadTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- FileUploadTest.java 2001/07/31 16:08:59 1.7 +++ FileUploadTest.java 2001/10/19 18:26:29 1.8 @@ -182,6 +182,19 @@ } + public void testFileUploadWithoutForm() throws Exception { + ByteArrayInputStream bais = new ByteArrayInputStream( "Not much text\nBut two lines\n".getBytes() ); + + defineResource( "ListParams", new MimeEcho() ); + WebConversation wc = new WebConversation(); + PostMethodWebRequest formSubmit = new PostMethodWebRequest( getHostPath() + "/ListParams" ); + formSubmit.setMimeEncoded( true ); + formSubmit.selectFile( "message", "temp.txt", bais, "text/plain" ); + WebResponse encoding = wc.getResponse( formSubmit ); + assertEqualQueries( "text/plain:message.name=temp.txt&message.lines=2", encoding.getText().trim() ); + } + + public void testFileContentType() throws Exception { File file = new File( "temp.gif" ); FileOutputStream fos = new FileOutputStream( file ); |