httpunit-commit Mailing List for httpunit (Page 65)
Brought to you by:
russgold
You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(5) |
Sep
(31) |
Oct
(39) |
Nov
(18) |
Dec
(6) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(8) |
Feb
(5) |
Mar
(8) |
Apr
(25) |
May
(20) |
Jun
(23) |
Jul
(28) |
Aug
(10) |
Sep
(3) |
Oct
(32) |
Nov
(61) |
Dec
(24) |
2002 |
Jan
(50) |
Feb
(34) |
Mar
(35) |
Apr
(3) |
May
(25) |
Jun
(25) |
Jul
(30) |
Aug
(146) |
Sep
(49) |
Oct
(156) |
Nov
(121) |
Dec
(54) |
2003 |
Jan
(12) |
Feb
(79) |
Mar
(88) |
Apr
(26) |
May
(67) |
Jun
(29) |
Jul
(8) |
Aug
(16) |
Sep
(20) |
Oct
(17) |
Nov
|
Dec
(5) |
2004 |
Jan
|
Feb
(40) |
Mar
(30) |
Apr
(5) |
May
|
Jun
(83) |
Jul
(34) |
Aug
(20) |
Sep
(44) |
Oct
(46) |
Nov
|
Dec
(14) |
2005 |
Jan
(4) |
Feb
|
Mar
(5) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(4) |
Oct
|
Nov
|
Dec
(1) |
2006 |
Jan
|
Feb
|
Mar
(26) |
Apr
(8) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(5) |
Nov
|
Dec
|
2008 |
Jan
|
Feb
|
Mar
|
Apr
(36) |
May
(38) |
Jun
(1) |
Jul
(1) |
Aug
|
Sep
(4) |
Oct
|
Nov
(18) |
Dec
(4) |
2009 |
Jan
|
Feb
(2) |
Mar
(3) |
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
(35) |
Sep
(1) |
Oct
|
Nov
|
Dec
(1) |
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
(9) |
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(21) |
Oct
(18) |
Nov
(1) |
Dec
|
From: Russell G. <rus...@us...> - 2002-02-08 13:32:09
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv4914/doc Modified Files: servletunit-intro.html Log Message: Note explicit requirements before calling InvocationContext.getServletResponse Index: servletunit-intro.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/servletunit-intro.html,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- servletunit-intro.html 28 Nov 2001 18:25:33 -0000 1.2 +++ servletunit-intro.html 8 Feb 2002 13:32:05 -0000 1.3 @@ -91,15 +91,18 @@ You can test the response from the servlet as well, if you invoke the code which creates it: <PRE><CODE> StatefulServlet ss = (StatefulServlet) ic.getServlet(); + ic.getResponse().setContentType( "text/plain" ); ss.writeSelectMessage( "blue", ic.getResponse().getWriter() ); WebResponse response = ic.getServletResponse(); assertEquals( "requested resource", "You selected blue", response.getText() ); assertEquals( "Returned cookie count", 1, response.getNewCookieNames().length ); </CODE></PRE> -Note that the response returned from <CODE>getServletResponse</CODE> is the actual one returned by the -servlet, without any processing by the client. For example, if the request contains a bad status or -a forward request, the client might do some additional processing, which is not done at this time. +Note first that you must do all of the processing that the <code>service</code> method would have done if you take this +approach. You may either call the <code>service</code> method itself, or a combination of other calls that will prepare +the response in the fashion you wish to test. Not also that the response returned from <CODE>getServletResponse</CODE> +is the actual one returned by the servlet, without any processing by the client. For example, if the request contains a +bad status or a forward request, the client might do some additional processing, which is not done at this time. Of course, since the response extends <CODE>WebResponse</CODE>, all of the normal HTML parsing methods are available to examine it. |
From: Russell G. <rus...@us...> - 2002-02-06 18:38:16
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv27789/test/com/meterware/httpunit Modified Files: WebFormTest.java Log Message: Support reset for forms Index: WebFormTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFormTest.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- WebFormTest.java 2002/02/04 22:33:55 1.19 +++ WebFormTest.java 2002/02/06 18:38:13 1.20 @@ -36,8 +36,8 @@ public static void main(String args[]) { junit.textui.TestRunner.run( suite() ); } - - + + public static Test suite() { return new TestSuite( WebFormTest.class ); } @@ -60,8 +60,8 @@ "<br><Input type=submit value = \"Log in\">" + "</form>" ); } - - + + public void testFindNoForm() throws Exception { defineWebPage( "NoForms", "This has no forms but it does" + "have <a href=\"/other.html\">an active link</A>" + @@ -87,7 +87,7 @@ "<B>Enter the name 'master': <Input type=TEXT Name=name></B>" + "<br><Input type=submit value = \"Log in\">" + "</form>" ); - + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); assertNull( "Found nonexistent form", page.getFormWithName( "nobody" ) ); assertNotNull( "Did not find named form", page.getFormWithName( "oneform" ) ); @@ -132,6 +132,9 @@ assertEquals( "Original text area value", "Something", form.getParameterValue( "name" ) ); form.setParameter( "name", "Something Else" ); assertEquals( "Changed text area value", "Something Else", form.getParameterValue( "name" ) ); + + form.reset(); + assertEquals( "Reset text area value", "Something", form.getParameterValue( "name" ) ); } @@ -151,7 +154,7 @@ "<B>Enter the name 'master': <Input type=TEXT Name=name></B>" + "<br><Input type=submit value = \"Log in\">" + "</form>" ); - + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); WebForm form = page.getForms()[0]; assertEquals( 3, form.getParameterNames().length ); @@ -180,7 +183,7 @@ "<B>Enter the name 'master': <Input type=TEXT Name=name></B>" + "<br><Input type=submit value = \"Log in\">" + "</form>" ); - + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); WebForm form = page.getForms()[0]; assertEquals( 3, form.getParameterNames().length ); @@ -220,6 +223,9 @@ } catch (IllegalRequestParameterException e) { } assertEquals( "Preserved value for sex", "neuter", form.getParameterValue( "sex" ) ); + + form.reset(); + assertEquals( "Reverted value", "female", form.getParameterValue( "sex" ) ); } @@ -245,10 +251,15 @@ assertEquals( "New select value", "green", form.getParameterValue( "color" ) ); try { - form.setParameter( "color", new String[] { "red", "green" } ); + form.setParameter( "color", new String[] { "green", "red" } ); fail( "Should have rejected set with multiple values" ); } catch (IllegalRequestParameterException e) { } + + form.setParameter( "color", "green" ); + assertEquals( "Pre-reset color", "green", form.getParameterValue( "color" ) ); + form.reset(); + assertEquals( "Reverted color", "red", form.getParameterValue( "color" ) ); } @@ -283,9 +294,12 @@ fail( "Should have rejected set with bad values" ); } catch (IllegalRequestParameterException e) { } + + form.reset(); + assertMatchingSet( "Reverted colors", new String[] { "red", "pink" }, form.getParameterValues( "colors" ) ); } + - public void testUnspecifiedDefaults() throws Exception { defineWebPage( "Default", "<form method=GET action = \"/ask\">" + "<Select name=colors><Option>blue<Option>red</Select>" + @@ -326,13 +340,15 @@ assertMatchingSet( "default colors", new String[] { "red", "blue" }, form.getParameterValues( "color" ) ); form.setParameter( "color", "red" ); - assertMatchingSet( "default colors", new String[] { "red" }, form.getParameterValues( "color" ) ); + assertMatchingSet( "modified colors", new String[] { "red" }, form.getParameterValues( "color" ) ); try { form.setParameter( "color", new String[] { "red", "purple" } ); fail( "Should have rejected set with bad values" ); } catch (IllegalRequestParameterException e) { } + form.reset(); + assertMatchingSet( "reverted colors", new String[] { "red", "blue" }, form.getParameterValues( "color" ) ); } |
From: Russell G. <rus...@us...> - 2002-02-06 18:38:16
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv27789/src/com/meterware/servletunit Modified Files: ServletUnitHttpRequest.java Log Message: Support reset for forms Index: ServletUnitHttpRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpRequest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- ServletUnitHttpRequest.java 2002/02/04 22:33:55 1.8 +++ ServletUnitHttpRequest.java 2002/02/06 18:38:13 1.9 @@ -2,7 +2,7 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000-2001, Russell Gold +* Copyright (c) 2000-2002, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
From: Russell G. <rus...@us...> - 2002-02-06 18:38:16
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv27789/src/com/meterware/httpunit Modified Files: FormControl.java WebForm.java Log Message: Support reset for forms Index: FormControl.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- FormControl.java 2002/01/17 19:38:09 1.7 +++ FormControl.java 2002/02/06 18:38:13 1.8 @@ -172,6 +172,13 @@ /** + * Resets this control to its initial value. + **/ + void reset() { + } + + + /** * Returns the default value of this control in the form. If no value is specified, defaults to the empty string. **/ protected String getValueAttribute() { @@ -253,6 +260,11 @@ } + void reset() { + _isChecked = _isCheckedDefault; + } + + /** * Returns the current value(s) associated with this control. These values will be transmitted to the server * if the control is 'successful'. @@ -387,6 +399,11 @@ } + void reset() { + for (int i = 0; i < getButtons().length; i++) getButtons()[i].reset(); + } + + private String[] getAllowedValues() { if (_allowedValues == null) { _allowedValues = new String[ getButtons().length ]; @@ -494,6 +511,11 @@ } + void reset() { + _value[0] = null; + } + + void claimRequiredValues( List values ) { if (isReadOnly()) claimValueIsRequired( values ); } @@ -597,7 +619,9 @@ private final String[] _optionValues; private final String[] _displayedOptions; - private String[] _values; + private String[] _values; + private boolean[] _selectionIndexes; + private boolean[] _initialIndexes; SelectionFormControl( Node node ) { @@ -607,7 +631,10 @@ _multiSelect = NodeUtils.isNodeAttributePresent( node, "multiple" ); _optionValues = getInitialOptionValues( node ); _displayedOptions = getInitialDisplayedOptions( node ); - _values = getInitialValues( node, _optionValues ); + + _initialIndexes = getInitialSelectionIndexes( node ); + _selectionIndexes = (boolean[]) _initialIndexes.clone(); + _values = getSelectedValues( _selectionIndexes, _optionValues ); } @@ -659,34 +686,49 @@ if (!_multiSelect) { if (numMatches == 0) throw new IllegalParameterValueException( getName(), (String) values.get(0), getOptionValues() ); - } - ArrayList newValues = new ArrayList( matches.length ); for (int i = 0; i < matches.length; i++) { - if (matches[i]) { - values.remove( _optionValues[i] ); - newValues.add( _optionValues[i] ); + if (matches[i]) values.remove( _optionValues[i] ); + } + + _selectionIndexes = matches; + _values = getSelectedValues( matches, _optionValues ); + } + + + void reset() { + _selectionIndexes = (boolean[]) _initialIndexes.clone(); + _values = getSelectedValues( _selectionIndexes, _optionValues ); + } + + + private String[] getSelectedValues( boolean[] selected, String[] optionValues ) { + ArrayList values = new ArrayList(); + for (int i = 0; i < selected.length; i++) { + if (selected[i]) { + values.add( optionValues[i] ); } } - _values = (String[]) newValues.toArray( new String[ values.size() ] ); + return (String[]) values.toArray( new String[ values.size() ] ); } - private String[] getInitialValues( Node selectionNode, String[] optionValues ) { - ArrayList selected = new ArrayList(); + private boolean[] getInitialSelectionIndexes( Node selectionNode ) { + boolean noneSelected = true; NodeList nl = ((Element) selectionNode).getElementsByTagName( "option" ); + boolean isSelected[] = new boolean[ nl.getLength() ]; for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i).getAttributes().getNamedItem( "selected" ) != null) { - selected.add( optionValues[i] ); + isSelected[i] = true; + noneSelected = false; } } - if (!isMultiValued() && selected.size() == 0 && nl.getLength() > 0) { - selected.add( optionValues[0] ); + if (!isMultiValued() && noneSelected && isSelected.length > 0) { + isSelected[0] = true; } - - return (String[]) selected.toArray( new String[ selected.size() ] ); + return isSelected; } Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.44 retrieving revision 1.45 diff -u -r1.44 -r1.45 --- WebForm.java 2002/02/04 22:33:55 1.44 +++ WebForm.java 2002/02/06 18:38:13 1.45 @@ -257,6 +257,17 @@ return "multipart/form-data".equalsIgnoreCase( NodeUtils.getNodeAttribute( getNode(), "enctype" ) ); } + + /** + * Resets all parameters to their initial values. + */ + public void reset() { + FormControl controls[] = getFormControls(); + for (int i = 0; i < controls.length; i++) { + controls[i].reset(); + } + } + //---------------------------------- WebRequestSource methods -------------------------------- /** |
From: Russell G. <rus...@us...> - 2002-02-06 18:38:16
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv27789/doc Modified Files: release_notes.txt Log Message: Support reset for forms Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.86 retrieving revision 1.87 diff -u -r1.86 -r1.87 --- release_notes.txt 2002/02/04 22:33:54 1.86 +++ release_notes.txt 2002/02/06 18:38:13 1.87 @@ -11,6 +11,10 @@ Revision History: + 5-Feb-2002 +Additions: + 1. Form parameters can be reset to their initial values using WebForm.reset(). + 4-Feb-2002 Problems corrected: 1. Forms with query strings included in the action attribute now are submitted with that string intact. |
From: Russell G. <rus...@us...> - 2002-02-04 22:33:58
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv7183/test/com/meterware/servletunit Modified Files: HttpServletRequestTest.java JUnitServletTest.java Log Message: Handle query strings on form actions Index: HttpServletRequestTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/HttpServletRequestTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- HttpServletRequestTest.java 2001/11/26 14:20:13 1.3 +++ HttpServletRequestTest.java 2002/02/04 22:33:55 1.4 @@ -54,7 +54,7 @@ public void testGetDefaultProperties() throws Exception { WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" ); - HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable() ); + HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY ); assertNull( "Authorization incorrectly specified", request.getAuthType() ); assertNull( "Character encoding incorrectly specified", request.getCharacterEncoding() ); assertEquals( "Parameters unexpectedly specified", "", request.getQueryString() ); @@ -65,7 +65,7 @@ WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" ); wr.setParameter( "age", "12" ); wr.setParameter( "color", new String[] { "red", "blue" } ); - HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable() ); + HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY ); assertEquals( "age parameter", "12", request.getParameter( "age" ) ); assertNull( "unset parameter should be null", request.getParameter( "unset" ) ); @@ -76,7 +76,7 @@ WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" ); wr.setParameter( "age", "12" ); wr.setParameter( "color", new String[] { "red", "blue" } ); - HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable() ); + HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY ); assertMatchingSet( "age parameter", new String[] { "12" }, request.getParameterValues( "age" ) ); assertMatchingSet( "color parameter", new String[] { "red", "blue" }, request.getParameterValues( "color" ) ); @@ -88,7 +88,7 @@ WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" ); wr.setParameter( "age", "12" ); wr.setParameter( "color", new String[] { "red", "blue" } ); - HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable() ); + HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY ); assertEquals( "query string", "color=red&color=blue&age=12", request.getQueryString() ); } @@ -96,7 +96,7 @@ public void testInlineSingleValuedParameter() throws Exception { WebRequest wr = new GetMethodWebRequest( "http://localhost/simple?color=red&color=blue&age=12" ); - HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable() ); + HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY ); assertEquals( "age parameter", "12", request.getParameter( "age" ) ); assertNull( "unset parameter should be null", request.getParameter( "unset" ) ); @@ -105,7 +105,7 @@ public void testInlineMultiValuedParameter() throws Exception { WebRequest wr = new GetMethodWebRequest( "http://localhost/simple?color=red&color=blue&age=12" ); - HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable() ); + HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY ); assertMatchingSet( "age parameter", new String[] { "12" }, request.getParameterValues( "age" ) ); assertMatchingSet( "color parameter", new String[] { "red", "blue" }, request.getParameterValues( "color" ) ); @@ -115,7 +115,7 @@ public void notestInlineQueryString() throws Exception { WebRequest wr = new GetMethodWebRequest( "http://localhost/simple?color=red&color=blue&age=12" ); - HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable() ); + HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY ); assertEquals( "query string", "color=red&color=blue&age=12", request.getQueryString() ); } @@ -123,7 +123,7 @@ public void testDefaultAttributes() throws Exception { WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" ); - HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable() ); + HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY ); assertNull( "attribute should not be defined yet", request.getAttribute( "unset" ) ); assertTrue( "attribute enumeration should be empty", !request.getAttributeNames().hasMoreElements() ); @@ -132,7 +132,7 @@ public void testNonDefaultAttributes() throws Exception { WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" ); - HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable() ); + HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY ); Object value = new Integer(1); request.setAttribute( "one", value ); @@ -148,7 +148,7 @@ public void testDuplicateAttributes() throws Exception { WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" ); - HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable() ); + HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY ); Object value = new Integer(1); request.setAttribute( "one", value ); @@ -163,7 +163,7 @@ public void testSessionCreation() throws Exception { WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" ); - HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable() ); + HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY ); HttpSession session = request.getSession( /* create */ false ); assertNull( "Unexpected session found", session ); @@ -176,7 +176,7 @@ public void testDefaultCookies() throws Exception { WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" ); - HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable() ); + HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY ); Cookie[] cookies = request.getCookies(); assertNull( "Unexpected cookies found", cookies ); } @@ -184,7 +184,7 @@ public void testSetCookies() throws Exception { WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" ); - ServletUnitHttpRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable() ); + ServletUnitHttpRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY ); request.addCookie( new Cookie( "flavor", "vanilla" ) ); Cookie[] cookies = request.getCookies(); @@ -199,14 +199,14 @@ WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" ); ServletUnitContext context = new ServletUnitContext(); - ServletUnitHttpRequest request = new ServletUnitHttpRequest( wr, context, new Hashtable() ); + ServletUnitHttpRequest request = new ServletUnitHttpRequest( wr, context, new Hashtable(), NO_MESSAGE_BODY ); request.addCookie( new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, context.newSession().getId() ) ); HttpSession session = request.getSession( /* create */ false ); assertNotNull( "No session created", session ); } - + private final static byte[] NO_MESSAGE_BODY = new byte[0]; } Index: JUnitServletTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/JUnitServletTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- JUnitServletTest.java 2001/12/03 19:14:59 1.1 +++ JUnitServletTest.java 2002/02/04 22:33:55 1.2 @@ -180,8 +180,8 @@ static class MyFactory implements InvocationContextFactory { private static ServletRunner _runner; - public InvocationContext newInvocation( WebRequest request, Cookie[] clientCookies, Dictionary clientHeaders ) throws IOException, MalformedURLException { - return new InvocationContextImpl( _runner, request, clientCookies, clientHeaders ); + public InvocationContext newInvocation( WebRequest request, Cookie[] clientCookies, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException { + return new InvocationContextImpl( _runner, request, clientCookies, clientHeaders, messageBody ); } } } |
From: Russell G. <rus...@us...> - 2002-02-04 22:33:58
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv7183/src/com/meterware/httpunit Modified Files: GetMethodWebRequest.java ParameterHolder.java PostMethodWebRequest.java UncheckedParameterHolder.java WebForm.java WebLink.java WebRequest.java WebRequestSource.java Log Message: Handle query strings on form actions Index: GetMethodWebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/GetMethodWebRequest.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- GetMethodWebRequest.java 2002/01/17 19:38:09 1.13 +++ GetMethodWebRequest.java 2002/02/04 22:33:55 1.14 @@ -20,6 +20,7 @@ * *******************************************************************************************************************/ import java.net.URL; +import java.io.IOException; /** * An HTTP request using the GET method. @@ -59,6 +60,21 @@ } + /** + * Returns the query string defined for this request. + **/ + public String getQueryString() { + try { + URLEncodedString encoder = new URLEncodedString(); + getParameterHolder().recordPredefinedParameters( encoder ); + getParameterHolder().recordParameters( encoder ); + return encoder.getString(); + } catch (IOException e) { + throw new RuntimeException( "Programming error: " + e ); // should never happen + } + } + + //--------------------------------------- package members --------------------------------------------- @@ -75,19 +91,6 @@ **/ GetMethodWebRequest( WebLink sourceLink ) { super( sourceLink ); - } - - -//------------------------------------- protected members --------------------------------------------- - - - protected String getURLString() { - final String parameterString = getParameterString(); - if (parameterString.length() == 0) { - return super.getURLString(); - } else { - return super.getURLString() + "?" + parameterString; - } } Index: ParameterHolder.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParameterHolder.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ParameterHolder.java 2002/01/17 19:38:09 1.4 +++ ParameterHolder.java 2002/02/04 22:33:55 1.5 @@ -40,6 +40,14 @@ /** + * Iterates through the fixed, predefined parameters in this holder, recording them in the supplied parameter processor.\ + * These parameters always go on the URL, no matter what encoding method is used. + **/ + abstract + void recordPredefinedParameters( ParameterProcessor processor ) throws IOException; + + + /** * Iterates through the parameters in this holder, recording them in the supplied parameter processor. **/ abstract Index: PostMethodWebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/PostMethodWebRequest.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- PostMethodWebRequest.java 2002/01/17 19:38:09 1.22 +++ PostMethodWebRequest.java 2002/02/04 22:33:55 1.23 @@ -84,6 +84,20 @@ /** + * Returns the query string defined for this request. + **/ + public String getQueryString() { + try { + URLEncodedString encoder = new URLEncodedString(); + getParameterHolder().recordPredefinedParameters( encoder ); + return encoder.getString(); + } catch (IOException e) { + throw new RuntimeException( "Programming error: " + e ); // should never happen + } + } + + + /** * Returns true if selectFile may be called with this parameter. */ protected boolean maySelectFile( String parameterName ) @@ -155,7 +169,18 @@ * Transmits the body of this request as a sequence of bytes. **/ void writeTo( OutputStream outputStream ) throws IOException { - outputStream.write( getRequest().getParameterString().getBytes() ); + outputStream.write( getParameterString().getBytes() ); + } + + + private String getParameterString() { + try { + URLEncodedString encoder = new URLEncodedString(); + getRequest().getParameterHolder().recordParameters( encoder ); + return encoder.getString(); + } catch (IOException e) { + throw new RuntimeException( "Programming error: " + e ); // should never happen + } } } Index: UncheckedParameterHolder.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/UncheckedParameterHolder.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- UncheckedParameterHolder.java 2002/01/17 19:38:09 1.4 +++ UncheckedParameterHolder.java 2002/02/04 22:33:55 1.5 @@ -68,6 +68,13 @@ /** + * Does nothing, since unchecked requests treat all parameters the same. + **/ + void recordPredefinedParameters( ParameterProcessor processor ) throws IOException { + } + + + /** * Iterates through the parameters in this holder, recording them in the supplied parameter processor. **/ void recordParameters( ParameterProcessor processor ) throws IOException { Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.43 retrieving revision 1.44 diff -u -r1.43 -r1.44 --- WebForm.java 2002/01/17 19:38:09 1.43 +++ WebForm.java 2002/02/04 22:33:55 1.44 @@ -21,13 +21,7 @@ *******************************************************************************************************************/ import java.net.URL; -import java.util.Hashtable; -import java.util.Vector; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Arrays; -import java.util.Map; -import java.util.Iterator; +import java.util.*; import java.io.IOException; import org.w3c.dom.Element; @@ -307,6 +301,14 @@ } + /** + * Records a parameter defined by including it in the destination URL. + **/ + protected void addPresetParameter( String name, String value ) { + _presets.add( new PresetFormParameter( name, value ) ); + } + + //---------------------------------- ParameterHolder methods -------------------------------- @@ -319,6 +321,19 @@ /** + * Iterates through the fixed, predefined parameters in this holder, recording them in the supplied parameter processor.\ + * These parameters always go on the URL, no matter what encoding method is used. + **/ + + void recordPredefinedParameters( ParameterProcessor processor ) throws IOException { + FormControl[] controls = getPresetParameters(); + for (int i = 0; i < controls.length; i++) { + controls[i].addValues( processor, getCharacterSet() ); + } + } + + + /** * Iterates through the parameters in this holder, recording them in the supplied parameter processor. **/ public void recordParameters( ParameterProcessor processor ) throws IOException { @@ -392,6 +407,10 @@ private Vector _buttonVector; + private FormControl[] _presetParameters; + private ArrayList _presets; + + private SubmitButton getDefaultButton() { if (getSubmitButtons().length == 1) { return getSubmitButtons()[0]; @@ -418,6 +437,16 @@ } + private FormControl[] getPresetParameters() { + if (_presetParameters == null) { + _presets = new ArrayList(); + loadDestinationParameters(); + _presetParameters = (FormControl[]) _presets.toArray( new FormControl[ _presets.size() ] ); + } + return _presetParameters; + } + + /** * Returns an array of form parameter attributes for this form. **/ @@ -446,21 +475,26 @@ private Map getFormParameters() { if (_formParameters == null) { _formParameters = new HashMap(); - FormControl[] controls = getFormControls(); - for (int i = 0; i < controls.length; i++) { - if (controls[i].getName().length() == 0) continue; - FormParameter parameter = (FormParameter) _formParameters.get( controls[i].getName() ); - if (parameter == null) { - parameter = new FormParameter(); - _formParameters.put( controls[i].getName(), parameter ); - } - parameter.addControl( controls[i] ); - } + loadFormParameters( getPresetParameters() ); + loadFormParameters( getFormControls() ); } return _formParameters; } + private void loadFormParameters( FormControl[] controls ) { + for (int i = 0; i < controls.length; i++) { + if (controls[i].getName().length() == 0) continue; + FormParameter parameter = (FormParameter) _formParameters.get( controls[i].getName() ); + if (parameter == null) { + parameter = new FormParameter(); + _formParameters.put( controls[i].getName(), parameter ); + } + parameter.addControl( controls[i] ); + } + } + + private void addFormParametersToList( NodeList children, Vector list ) { for (int i = 0; i < children.getLength(); i++) { addFormParametersToList( children.item(i), list ); @@ -599,8 +633,72 @@ } } + +//========================================== class PresetFormParameter ================================================= + + + class PresetFormParameter extends FormControl { + + PresetFormParameter( String name, String value ) { + _name = name; + _value = value; + } + + + /** + * Returns the name of this control.. + **/ + public String getName() { + return _name; + } + + + /** + * Returns true if this control is read-only. + **/ + public boolean isReadOnly() { + return true; + } + + + /** + * Returns true if this control accepts free-form text. + **/ + public boolean isTextControl() { + return true; + } + + + /** + * Remove any required values for this control from the list, throwing an exception if they are missing. + **/ + void claimRequiredValues( List values ) { + if (_value != null) claimValueIsRequired( values, _value ); + } + + + /** + * Returns the current value(s) associated with this control. These values will be transmitted to the server + * if the control is 'successful'. + **/ + public String[] getValues() { + if (_values == null) _values = new String[] { _value }; + return _values; + } + + + void addValues( ParameterProcessor processor, String characterSet ) throws IOException { + processor.addParameter( _name, _value, characterSet ); + } + + + private String _name; + private String _value; + private String[] _values; + } + -//================================ exception class NoSuchParameterException ========================================= +//===========================---===== exception class NoSuchParameterException ========================================= /** Index: WebLink.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- WebLink.java 2002/01/23 18:35:56 1.16 +++ WebLink.java 2002/02/04 22:33:55 1.17 @@ -111,6 +111,15 @@ /** + * Iterates through the fixed, predefined parameters in this holder, recording them in the supplied parameter processor.\ + * These parameters always go on the URL, no matter what encoding method is used. + **/ + + void recordPredefinedParameters( ParameterProcessor processor ) throws IOException { + } + + + /** * Iterates through the parameters in this holder, recording them in the supplied parameter processor. **/ void recordParameters( ParameterProcessor processor ) throws IOException { @@ -204,25 +213,11 @@ private static final String[] NO_VALUES = new String[0]; - private static final String PARAM_DELIM = "&"; private Map _presetParameterMap; private ArrayList _presetParameterList; - /** - * Gets all parameters from a URL - **/ - private String getParametersString() { - final String url = getURLString(); - final int questionMarkIndex = url.indexOf("?"); - if (questionMarkIndex >= 1 && questionMarkIndex < url.length() - 1) { - return url.substring(questionMarkIndex + 1); - } - return ""; - } - - private Map getPresetParameterMap() { if (_presetParameterMap == null) loadPresetParameters(); return _presetParameterMap; @@ -238,23 +233,13 @@ private void loadPresetParameters() { _presetParameterMap = new HashMap(); _presetParameterList = new ArrayList(); - StringTokenizer st = new StringTokenizer( getParametersString(), PARAM_DELIM ); - while (st.hasMoreTokens()) stripOneParameter( _presetParameterList, _presetParameterMap, st.nextToken() ); + loadDestinationParameters(); } - /** - * add a pair key-value to the hashtable, creates an array of values if param already exists. - **/ - private void stripOneParameter( ArrayList list, Map map, String param ) { - final int index = param.indexOf( "=" ); - String value = ((index < 0) ? null - : ((index == param.length() - 1) - ? "" - : HttpUnitUtils.decode( param.substring( index + 1 ) ).trim() )); - String name = (index < 0) ? param.trim() : HttpUnitUtils.decode( param.substring( 0, index ) ).trim(); - map.put( name, withNewValue( (String[]) map.get( name ), value ) ); - list.add( new LinkParameter( name, value ) ); + protected void addPresetParameter( String name, String value ) { + _presetParameterMap.put( name, withNewValue( (String[]) _presetParameterMap.get( name ), value ) ); + _presetParameterList.add( new LinkParameter( name, value ) ); } Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- WebRequest.java 2002/01/25 19:09:08 1.38 +++ WebRequest.java 2002/02/04 22:33:55 1.39 @@ -82,18 +82,19 @@ /** - * Returns the query string defined for this request. + * Returns the HTTP method defined for this request. **/ - public String getQueryString() { - return getParameterString(); - } + abstract + public String getMethod(); /** - * Returns the HTTP method defined for this request. + * Returns the query string defined for this request. The query string is sent to the HTTP server as part of + * the request header. This default implementation returns an empty string. **/ - abstract - public String getMethod(); + public String getQueryString() { + return ""; + } //------------------------------------- ParameterCollection methods ------------------------------------ @@ -348,19 +349,15 @@ } - protected String getURLString() { - return _urlString; - } +//------------------------------------- protected members --------------------------------------------- - final - protected String getParameterString() { - try { - URLEncodedString encoder = new URLEncodedString(); - _parameterHolder.recordParameters( encoder ); - return encoder.getString(); - } catch (IOException e) { - throw new RuntimeException( "Programming error: " + e ); // should never happen + protected String getURLString() { + final String queryString = getQueryString(); + if (queryString.length() == 0) { + return _urlString; + } else { + return _urlString + "?" + queryString; } } Index: WebRequestSource.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequestSource.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- WebRequestSource.java 2002/01/17 19:38:09 1.5 +++ WebRequestSource.java 2002/02/04 22:33:55 1.6 @@ -23,6 +23,7 @@ import org.w3c.dom.Node; import java.net.URL; +import java.util.StringTokenizer; abstract @@ -126,7 +127,7 @@ if (node == null) throw new IllegalArgumentException( "node must not be null" ); _node = node; _baseURL = baseURL; - _destination = destination; + _destination = destination; _parentTarget = parentTarget; } @@ -148,9 +149,31 @@ return _node; } - //----------------------------- private members ----------------------------------------------- + /** + * Extracts any parameters specified as part of the destination URL, calling addPresetParameter for each one + * in the order in which they are found. + */ + final + protected void loadDestinationParameters() { + StringTokenizer st = new StringTokenizer( getParametersString(), PARAM_DELIM ); + while (st.hasMoreTokens()) stripOneParameter( st.nextToken() ); + } + + /** + * Records a parameter defined by including it in the destination URL. + * The value can be null, if the parameter name was not specified with an equals sign. + **/ + abstract + protected void addPresetParameter( String name, String value ); + + +//----------------------------- private members ----------------------------------------------- + + + private static final String PARAM_DELIM = "&"; + /** The target in which the parent response is to be rendered. **/ private String _parentTarget; @@ -166,6 +189,35 @@ private String getSpecifiedTarget() { return NodeUtils.getNodeAttribute( _node, "target" ); } + + + /** + * Gets all parameters from a URL + **/ + private String getParametersString() { + final String url = trimFragment( getDestination() ); + final int questionMarkIndex = url.indexOf("?"); + if (questionMarkIndex >= 1 && questionMarkIndex < url.length() - 1) { + return url.substring( questionMarkIndex + 1 ); + } + return ""; + } + + + /** + * Extracts a parameter of the form <name>[=[<value>]]. + **/ + private void stripOneParameter( String param ) { + final int index = param.indexOf( "=" ); + String value = ((index < 0) + ? null + : ((index == param.length() - 1) + ? "" + : HttpUnitUtils.decode( param.substring( index + 1 ) ).trim() )); + String name = (index < 0) ? param.trim() : HttpUnitUtils.decode( param.substring( 0, index ) ).trim(); + addPresetParameter( name, value ); + } + } |
From: Russell G. <rus...@us...> - 2002-02-04 22:33:58
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv7183/test/com/meterware/httpunit Modified Files: WebFormTest.java Log Message: Handle query strings on form actions Index: WebFormTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFormTest.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- WebFormTest.java 2002/01/14 18:13:45 1.18 +++ WebFormTest.java 2002/02/04 22:33:55 1.19 @@ -336,5 +336,60 @@ } + public void testGetWithQueryString() throws Exception { + defineResource( "QueryForm.html", + "<html><head></head>" + + "<form method=GET action=\"SayHello?speed=fast\">" + + "<input type=text name=name><input type=submit></form></body></html>" ); + defineResource( "SayHello?speed=fast&name=me", new PseudoServlet() { + public WebResource getGetResponse() { + WebResource result = new WebResource( "<html><body><table><tr><td>Hello, there" + + "</td></tr></table></body></html>" ); + return result; + } + } ); + + WebConversation wc = new WebConversation(); + WebResponse formPage = wc.getResponse( getHostPath() + "/QueryForm.html" ); + WebForm form = formPage.getForms()[0]; + form.setParameter( "name", "me" ); + WebRequest request = form.getRequest(); + assertEquals( "Request URL", getHostPath() + "/SayHello?speed=fast&name=me", request.getURL().toExternalForm() ); + + WebResponse answer = wc.getResponse( request ); + String[][] cells = answer.getTables()[0].asText(); + + assertEquals( "Message", "Hello, there", cells[0][0] ); + } + + + public void testPostWithQueryString() throws Exception { + defineResource( "QueryForm.html", + "<html><head></head>" + + "<form method=POST action=\"SayHello?speed=fast\">" + + "<input type=text name=name><input type=submit></form></body></html>" ); + defineResource( "SayHello?speed=fast", new PseudoServlet() { + public WebResource getPostResponse() { + String name = getParameter( "name" )[0]; + WebResource result = new WebResource( "<html><body><table><tr><td>Hello, there" + + "</td></tr></table></body></html>" ); + return result; + } + } ); + + WebConversation wc = new WebConversation(); + WebResponse formPage = wc.getResponse( getHostPath() + "/QueryForm.html" ); + WebForm form = formPage.getForms()[0]; + WebRequest request = form.getRequest(); + request.setParameter( "name", "Charlie" ); + assertEquals( "Request URL", getHostPath() + "/SayHello?speed=fast", request.getURL().toExternalForm() ); + + WebResponse answer = wc.getResponse( request ); + String[][] cells = answer.getTables()[0].asText(); + + assertEquals( "Message", "Hello, there", cells[0][0] ); + } + + private WebConversation _wc; } |
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv7183/src/com/meterware/servletunit Modified Files: InvocationContextFactory.java InvocationContextImpl.java ServletRunner.java ServletUnitClient.java ServletUnitHttpRequest.java Log Message: Handle query strings on form actions Index: InvocationContextFactory.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/InvocationContextFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- InvocationContextFactory.java 2001/11/30 15:27:36 1.1 +++ InvocationContextFactory.java 2002/02/04 22:33:55 1.2 @@ -38,6 +38,6 @@ /** * Creates and returns a new invocation context to test calling of servlet methods. **/ - public InvocationContext newInvocation( WebRequest request, Cookie[] clientCookies, Dictionary clientHeaders ) throws IOException, MalformedURLException; + public InvocationContext newInvocation( WebRequest request, Cookie[] clientCookies, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException; } Index: InvocationContextImpl.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/InvocationContextImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- InvocationContextImpl.java 2001/12/03 15:40:33 1.2 +++ InvocationContextImpl.java 2002/02/04 22:33:55 1.3 @@ -130,12 +130,12 @@ * Constructs a servlet invocation context for a specified servlet container, * request, and cookie headers. **/ - InvocationContextImpl( ServletRunner runner, WebRequest request, Cookie[] cookies, Dictionary clientHeaders ) throws IOException, MalformedURLException { + InvocationContextImpl( ServletRunner runner, WebRequest request, Cookie[] cookies, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException { _application = runner._application; _requestURL = request.getURL(); _target = request.getTarget(); - _request = new ServletUnitHttpRequest( request, runner.getContext(), clientHeaders ); + _request = new ServletUnitHttpRequest( request, runner.getContext(), clientHeaders, messageBody ); for (int i = 0; i < cookies.length; i++) _request.addCookie( cookies[i] ); if (_application.usesBasicAuthentication()) _request.readBasicAuthentication(); Index: ServletRunner.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletRunner.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- ServletRunner.java 2002/02/01 14:31:43 1.11 +++ ServletRunner.java 2002/02/04 22:33:55 1.12 @@ -125,8 +125,8 @@ private ServletUnitContext _context = new ServletUnitContext(); private InvocationContextFactory _factory = new InvocationContextFactory() { - public InvocationContext newInvocation( WebRequest request, Cookie[] clientCookies, Dictionary clientHeaders ) throws IOException, MalformedURLException { - return new InvocationContextImpl( ServletRunner.this, request, clientCookies, clientHeaders ); + public InvocationContext newInvocation( WebRequest request, Cookie[] clientCookies, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException { + return new InvocationContextImpl( ServletRunner.this, request, clientCookies, clientHeaders, messageBody ); } }; Index: ServletUnitClient.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitClient.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ServletUnitClient.java 2001/11/30 15:27:36 1.4 +++ ServletUnitClient.java 2002/02/04 22:33:55 1.5 @@ -22,6 +22,7 @@ import com.meterware.httpunit.*; import java.io.IOException; +import java.io.ByteArrayOutputStream; import java.net.MalformedURLException; import java.net.URL; @@ -69,7 +70,9 @@ * Creates and returns a new invocation context to test calling of servlet methods. **/ public InvocationContext newInvocation( WebRequest request ) throws IOException, MalformedURLException { - return _invocationContextFactory.newInvocation( request, getCookies(), this.getHeaderFields() ); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + writeMessageBody( request, baos ); + return _invocationContextFactory.newInvocation( request, getCookies(), this.getHeaderFields(), baos.toByteArray() ); } Index: ServletUnitHttpRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpRequest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- ServletUnitHttpRequest.java 2001/11/26 14:20:12 1.7 +++ ServletUnitHttpRequest.java 2002/02/04 22:33:55 1.8 @@ -27,6 +27,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.io.ByteArrayOutputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; @@ -49,22 +50,28 @@ **/ class ServletUnitHttpRequest implements HttpServletRequest { + /** * Constructs a ServletUnitHttpRequest from a WebRequest object. **/ - ServletUnitHttpRequest( WebRequest request, ServletUnitContext context, Dictionary clientHeaders ) throws MalformedURLException { + ServletUnitHttpRequest( WebRequest request, ServletUnitContext context, Dictionary clientHeaders, byte[] messageBody ) throws MalformedURLException { _request = request; _context = context; _headers = new WebClient.HeaderDictionary(); _headers.addEntries( clientHeaders ); _headers.addEntries( request.getHeaders() ); + _messageBody = messageBody; if (context == null) throw new IllegalArgumentException( "Context must not be null" ); String file = request.getURL().getFile(); if (file.indexOf( '?' ) >= 0) { loadParameters( file.substring( file.indexOf( '?' )+1 ) ); } else { - loadParameters( request.getQueryString() ); + final Object contentType = _headers.get( "Content-Type" ); + if (contentType == null || contentType.toString().indexOf( "x-www-form-urlencoded" ) >= 0 ) { + loadParameters( request.getQueryString() ); + loadParameters( new String( _messageBody ) ); + } } } @@ -713,6 +720,7 @@ private Hashtable _parameters = new Hashtable(); private Vector _cookies = new Vector(); private String _sessionID; + private byte[] _messageBody; private String _userName; private String[] _roles; |
From: Russell G. <rus...@us...> - 2002-02-04 22:33:57
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv7183/doc Modified Files: release_notes.txt Log Message: Handle query strings on form actions Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.85 retrieving revision 1.86 diff -u -r1.85 -r1.86 --- release_notes.txt 2002/02/01 14:31:42 1.85 +++ release_notes.txt 2002/02/04 22:33:54 1.86 @@ -11,6 +11,13 @@ Revision History: + 4-Feb-2002 +Problems corrected: + 1. Forms with query strings included in the action attribute now are submitted with that string intact. +Additions: + 1. Parameters defined in form query strings are now included in the known parameters of a form and requests + built from it. + 1-Feb-2002 Acknowledgements: Thanks to Jochen Hiller for supplying code to use jaxp to select a parser rather than being hardcoded to xerces |
From: Russell G. <rus...@us...> - 2002-02-01 14:31:48
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv8509/src/com/meterware/servletunit Modified Files: ServletRunner.java Log Message: From Jochen Hiller: use JAXP-compliant parser Index: ServletRunner.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletRunner.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- ServletRunner.java 2002/02/01 14:21:35 1.10 +++ ServletRunner.java 2002/02/01 14:31:43 1.11 @@ -35,10 +35,6 @@ import javax.servlet.ServletException; import javax.servlet.http.Cookie; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - import org.xml.sax.SAXException; import org.xml.sax.InputSource; import org.w3c.dom.Document; @@ -61,8 +57,7 @@ * Constructor which expects the full path to the web.xml for the application. **/ public ServletRunner( String webXMLFileSpec ) throws IOException, SAXException { - DocumentBuilder parser = HttpUnitUtils.newParser(); - _application = new WebApplication( parser.parse( webXMLFileSpec ) ); + _application = new WebApplication( HttpUnitUtils.newParser().parse( webXMLFileSpec ) ); } @@ -70,8 +65,7 @@ * Constructor which expects an input stream containing the web.xml for the application. **/ public ServletRunner( InputStream webXML ) throws IOException, SAXException { - DocumentBuilder parser = HttpUnitUtils.newParser(); - _application = new WebApplication( parser.parse( new InputSource( webXML ) ) ); + _application = new WebApplication( HttpUnitUtils.newParser().parse( new InputSource( webXML ) ) ); } |
From: Russell G. <rus...@us...> - 2002-02-01 14:31:47
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv8509/doc Modified Files: release_notes.txt Log Message: From Jochen Hiller: use JAXP-compliant parser Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.84 retrieving revision 1.85 diff -u -r1.84 -r1.85 --- release_notes.txt 2002/02/01 14:21:35 1.84 +++ release_notes.txt 2002/02/01 14:31:42 1.85 @@ -16,7 +16,7 @@ Thanks to Jochen Hiller for supplying code to use jaxp to select a parser rather than being hardcoded to xerces Additions: - 1. ServletUnit can now use any jaxp-compliant parser + 1. HttpUnit can now use any jaxp-compliant parser, rather than just xerces. 30-Jan-2002 Acknkowledgements: |
From: Russell G. <rus...@us...> - 2002-02-01 14:31:47
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv8509/src/com/meterware/httpunit Modified Files: WebResponse.java Log Message: From Jochen Hiller: use JAXP-compliant parser Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.58 retrieving revision 1.59 diff -u -r1.58 -r1.59 --- WebResponse.java 2002/01/10 22:18:13 1.58 +++ WebResponse.java 2002/02/01 14:31:43 1.59 @@ -355,7 +355,11 @@ if (isHTML()) { return (Document) getReceivedPage().getDOM(); } else { - return getXMLDOM(); + try { + return HttpUnitUtils.newParser().parse( new InputSource( new StringReader( getText() ) ) ); + } catch (IOException e) { + throw new SAXException( e ); + } } } @@ -797,45 +801,6 @@ return _page; } - - private Document getXMLDOM() throws SAXException { - Document doc = null; - - try { - Class parserClass = Class.forName("org.apache.xerces.parsers.DOMParser"); - Constructor constructor = parserClass.getConstructor( null ); - Object parser = constructor.newInstance( null ); - - Class[] parseMethodArgTypes = { InputSource.class }; - Object[] parseMethodArgs = { new InputSource( new StringReader( getText() ) ) }; - Method parseMethod = parserClass.getMethod( "parse", parseMethodArgTypes ); - parseMethod.invoke( parser, parseMethodArgs ); - - Method getDocumentMethod = parserClass.getMethod( "getDocument", null ); - doc = (Document)getDocumentMethod.invoke( parser, null ); - } catch (IOException e) { - throw new SAXException( e ); - } catch (InvocationTargetException ex) { - Throwable tex = ex.getTargetException(); - if (tex instanceof SAXException) { - throw (SAXException)tex; - } else if (tex instanceof IOException) { - throw new RuntimeException( tex.toString() ); - } else { - throw new IllegalStateException( "unexpected exception" ); - } - } catch (NoSuchMethodException ex) { - throw new IllegalStateException( "parse method not found" ); - } catch (IllegalAccessException ex) { - throw new IllegalStateException( "parse method not public" ); - } catch (InstantiationException ex) { - throw new IllegalStateException( "error instantiating parser" ); - } catch (ClassNotFoundException ex) { - throw new IllegalStateException( "parser class not found" ); - } - - return doc; - } private static String _defaultEncoding; |
From: Russell G. <rus...@us...> - 2002-02-01 14:21:40
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv5756/src/com/meterware/servletunit Modified Files: ServletRunner.java Log Message: From Jochen Hiller: use JAXP-compliant parser for ServletUnit Index: ServletRunner.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletRunner.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- ServletRunner.java 2001/11/30 15:27:36 1.9 +++ ServletRunner.java 2002/02/01 14:21:35 1.10 @@ -2,7 +2,7 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000-2001, Russell Gold +* Copyright (c) 2000-2002, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation @@ -23,6 +23,7 @@ import com.meterware.httpunit.WebRequest; import com.meterware.httpunit.HttpNotFoundException; import com.meterware.httpunit.HttpInternalErrorException; +import com.meterware.httpunit.HttpUnitUtils; import java.io.InputStream; import java.io.IOException; @@ -34,10 +35,13 @@ import javax.servlet.ServletException; import javax.servlet.http.Cookie; -import org.apache.xerces.parsers.DOMParser; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; import org.xml.sax.SAXException; import org.xml.sax.InputSource; +import org.w3c.dom.Document; /** @@ -57,9 +61,8 @@ * Constructor which expects the full path to the web.xml for the application. **/ public ServletRunner( String webXMLFileSpec ) throws IOException, SAXException { - DOMParser parser = new DOMParser(); - parser.parse( webXMLFileSpec ); - _application = new WebApplication( parser.getDocument() ); + DocumentBuilder parser = HttpUnitUtils.newParser(); + _application = new WebApplication( parser.parse( webXMLFileSpec ) ); } @@ -67,9 +70,8 @@ * Constructor which expects an input stream containing the web.xml for the application. **/ public ServletRunner( InputStream webXML ) throws IOException, SAXException { - DOMParser parser = new DOMParser(); - parser.parse( new InputSource( webXML ) ); - _application = new WebApplication( parser.getDocument() ); + DocumentBuilder parser = HttpUnitUtils.newParser(); + _application = new WebApplication( parser.parse( new InputSource( webXML ) ) ); } |
From: Russell G. <rus...@us...> - 2002-02-01 14:21:39
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv5756/src/com/meterware/httpunit Modified Files: HttpUnitUtils.java Log Message: From Jochen Hiller: use JAXP-compliant parser for ServletUnit Index: HttpUnitUtils.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitUtils.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- HttpUnitUtils.java 2002/01/10 15:42:00 1.6 +++ HttpUnitUtils.java 2002/02/01 14:21:35 1.7 @@ -2,7 +2,7 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000-2001, Russell Gold +* Copyright (c) 2000-2002, Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation @@ -21,6 +21,12 @@ *******************************************************************************************************************/ import java.util.StringTokenizer; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.xml.sax.SAXException; + /** * Utility code shared by httpunit and servletunit. **/ @@ -79,5 +85,19 @@ } } return sb.toString(); + } + + + /** + * creates a parser using JAXP API. + */ + public static DocumentBuilder newParser() throws SAXException { + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + return factory.newDocumentBuilder(); + } catch (ParserConfigurationException ex) { + // redirect the new exception for code compatibility + throw new SAXException( ex ); + } } } |
From: Russell G. <rus...@us...> - 2002-02-01 14:21:39
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv5756/doc Modified Files: release_notes.txt Log Message: From Jochen Hiller: use JAXP-compliant parser for ServletUnit Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.83 retrieving revision 1.84 diff -u -r1.83 -r1.84 --- release_notes.txt 2002/01/30 21:21:10 1.83 +++ release_notes.txt 2002/02/01 14:21:35 1.84 @@ -7,10 +7,17 @@ Limitations: 1. HttpUnit does not support JavaScript - 2. JDK 1.2 or higher is now required + 2. JDK 1.2 or higher is required Revision History: + 1-Feb-2002 +Acknowledgements: + Thanks to Jochen Hiller for supplying code to use jaxp to select a parser rather than being hardcoded to xerces + +Additions: + 1. ServletUnit can now use any jaxp-compliant parser + 30-Jan-2002 Acknkowledgements: Thanks to Alex Chaffee for implementing context parameters for web.xml in ServletUnit |
From: Russell G. <rus...@us...> - 2002-01-30 21:29:54
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv15077/src/com/meterware/servletunit Modified Files: ServletUnitHttpResponse.java ServletUnitServletConfig.java ServletUnitServletContext.java WebApplication.java Log Message: from Alex Chaffee: implemented context parameters in ServletUnit Index: ServletUnitHttpResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpResponse.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- ServletUnitHttpResponse.java 2002/01/22 15:25:16 1.9 +++ ServletUnitHttpResponse.java 2002/01/30 21:21:11 1.10 @@ -5,12 +5,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 @@ -110,6 +110,7 @@ * Relative URLs are not permitted here. */ public void sendRedirect( String location ) throws IOException { + setStatus( HttpServletResponse.SC_MOVED_PERMANENTLY ); setHeader( "Location", location ); } @@ -162,8 +163,8 @@ /** - * @deprecated As of version 2.1, due to ambiguous meaning of the message parameter. - * To set a status code use setStatus(int), to send an error with a description + * @deprecated As of version 2.1, due to ambiguous meaning of the message parameter. + * To set a status code use setStatus(int), to send an error with a description * use sendError(int, String). Sets the status code and message for this response. **/ public void setStatus( int sc, String msg ) { @@ -325,10 +326,10 @@ throw new RuntimeException( "addDateHeader not implemented" ); } - + /** - * Sets the preferred buffer size for the body of the response. The servlet container - * will use a buffer at least as large as the size requested. The actual buffer size + * Sets the preferred buffer size for the body of the response. The servlet container + * will use a buffer at least as large as the size requested. The actual buffer size * used can be found using getBufferSize. **/ public void setBufferSize( int size ) { // XXX throw IllegalStateException if anything has been written @@ -338,32 +339,32 @@ /** * Returns the actual buffer size used for the response. If no buffering is used, this method returns 0. - **/ + **/ public int getBufferSize() { return 0; } /** - * Returns a boolean indicating if the response has been committed. A commited response has + * Returns a boolean indicating if the response has been committed. A commited response has * already had its status code and headers written. **/ public boolean isCommitted() { return false; // XXX set true if flushBuffer has been called } - - + + /** - * Forces any content in the buffer to be written to the client. A call to this method automatically + * Forces any content in the buffer to be written to the client. A call to this method automatically * commits the response, meaning the status code and headers will be written. **/ public void flushBuffer() throws IOException { throw new RuntimeException( "flushBuffer not implemented" ); } - + /** - * Clears any data that exists in the buffer as well as the status code and headers. + * Clears any data that exists in the buffer as well as the status code and headers. * If the response has been committed, this method throws an IllegalStateException. **/ public void reset() { @@ -372,23 +373,23 @@ /** - * Sets the locale of the response, setting the headers (including the Content-Type's charset) - * as appropriate. This method should be called before a call to getWriter(). + * Sets the locale of the response, setting the headers (including the Content-Type's charset) + * as appropriate. This method should be called before a call to getWriter(). * By default, the response locale is the default locale for the server. **/ public void setLocale( Locale locale ) { throw new RuntimeException( "setLocale not implemented" ); } + - /** * Returns the locale assigned to the response. **/ public Locale getLocale() { throw new RuntimeException( "getLocale not implemented" ); } + - //----------------------------- methods added to ServletResponse in JSDK 2.3 -------------------------------------- Index: ServletUnitServletConfig.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitServletConfig.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ServletUnitServletConfig.java 2002/01/22 15:25:16 1.3 +++ ServletUnitServletConfig.java 2002/01/30 21:21:11 1.4 @@ -4,12 +4,12 @@ * * Copyright (c) 2000-2002, Russell Gold * -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -* documentation files (the "Software"), to deal in the Software without restriction, including without limitation +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +* documentation files (the "Software"), to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * -* The above copyright notice and this permission notice shall be included in all copies or substantial portions +* The above copyright notice and this permission notice shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO @@ -33,10 +33,10 @@ class ServletUnitServletConfig implements ServletConfig { - ServletUnitServletConfig( Servlet servlet, WebApplication application, Hashtable initParams ) { + ServletUnitServletConfig( Servlet servlet, WebApplication application, Hashtable initParams, Hashtable contextParams ) { _name = servlet.getClass().getName(); _initParameters = initParams; - _context = new ServletUnitServletContext( application ); + _context = new ServletUnitServletContext( application, contextParams ); } Index: ServletUnitServletContext.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitServletContext.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ServletUnitServletContext.java 2002/01/22 15:25:16 1.6 +++ ServletUnitServletContext.java 2002/01/30 21:21:11 1.7 @@ -4,12 +4,12 @@ * * Copyright (c) 2000-2002, Russell Gold * -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -* documentation files (the "Software"), to deal in the Software without restriction, including without limitation +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +* documentation files (the "Software"), to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * -* The above copyright notice and this permission notice shall be included in all copies or substantial portions +* The above copyright notice and this permission notice shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO @@ -39,13 +39,14 @@ **/ class ServletUnitServletContext implements ServletContext { - public ServletUnitServletContext( WebApplication application ) { + ServletUnitServletContext( WebApplication application, Hashtable contextParams ) { _application = application; + _contextParams = contextParams; } /** - * Returns a ServletContext object that corresponds to a specified URL on the server. + * Returns a ServletContext object that corresponds to a specified URL on the server. * <p> * This method allows servlets to gain access to the context for various parts of the server, * and as needed obtain RequestDispatcher objects from the context. The given path must be @@ -59,7 +60,7 @@ /** - * Returns the major version of the Java Servlet API that this servlet container supports. + * Returns the major version of the Java Servlet API that this servlet container supports. * All implementations that comply with Version 2.3 must have this method return the integer 2. **/ public int getMajorVersion() { @@ -68,7 +69,7 @@ /** - * Returns the minor version of the Servlet API that this servlet container supports. + * Returns the minor version of the Servlet API that this servlet container supports. * All implementations that comply with Version 2.3 must have this method return the integer 3. **/ public int getMinorVersion() { @@ -77,8 +78,8 @@ /** - * Returns the MIME type of the specified file, or null if the MIME type is not known. - * The MIME type is determined by the configuration of the servlet container, and + * Returns the MIME type of the specified file, or null if the MIME type is not known. + * The MIME type is determined by the configuration of the servlet container, and * may be specified in a web application deployment descriptor. Common MIME types are * "text/html" and "image/gif". **/ @@ -88,20 +89,20 @@ /** - * Returns a URL to the resource that is mapped to a specified path. The path must begin - * with a "/" and is interpreted as relative to the current context root. + * Returns a URL to the resource that is mapped to a specified path. The path must begin + * with a "/" and is interpreted as relative to the current context root. * <p> - * This method allows the servlet container to make a resource available to servlets from any source. - * Resources can be located on a local or remote file system, in a database, or in a .war file. + * This method allows the servlet container to make a resource available to servlets from any source. + * Resources can be located on a local or remote file system, in a database, or in a .war file. * <p> - * The servlet container must implement the URL handlers and URLConnection objects that are necessary to access the resource. + * The servlet container must implement the URL handlers and URLConnection objects that are necessary to access the resource. * <p> - * This method returns null if no resource is mapped to the pathname. + * This method returns null if no resource is mapped to the pathname. * - * Some containers may allow writing to the URL returned by this method using the methods of the URL class. + * Some containers may allow writing to the URL returned by this method using the methods of the URL class. * * The resource content is returned directly, so be aware that requesting a .jsp page returns the JSP source code. Use a - * RequestDispatcher instead to include results of an execution. + * RequestDispatcher instead to include results of an execution. * * This method has a different purpose than java.lang.Class.getResource, which looks up resources based on a class loader. This * method does not use class loaders. @@ -112,14 +113,14 @@ /** - * Returns the resource located at the named path as an InputStream object. + * Returns the resource located at the named path as an InputStream object. * * The data in the InputStream can be of any type or length. The path must be specified according to the rules given in getResource. - * This method returns null if no resource exists at the specified path. + * This method returns null if no resource exists at the specified path. - * Meta-information such as content length and content type that is available via getResource method is lost when using this method. + * Meta-information such as content length and content type that is available via getResource method is lost when using this method. - * The servlet container must implement the URL handlers and URLConnection objects necessary to access the resource. + * The servlet container must implement the URL handlers and URLConnection objects necessary to access the resource. * This method is different from java.lang.Class.getResourceAsStream, which uses a class loader. This method allows servlet * containers to make a resource available to a servlet from any location, without using a class loader. @@ -149,10 +150,10 @@ /** - * Returns a RequestDispatcher object that acts as a wrapper for the named servlet. - * + * Returns a RequestDispatcher object that acts as a wrapper for the named servlet. + * * Servlets (and JSP pages also) may be given names via server administration or via a web application deployment descriptor. A servlet - * instance can determine its name using ServletConfig.getServletName(). + * instance can determine its name using ServletConfig.getServletName(). * * This method returns null if the ServletContext cannot return a RequestDispatcher for any reason. **/ @@ -186,7 +187,7 @@ /** - * Writes the specified message to a servlet log file, usually an event log. + * Writes the specified message to a servlet log file, usually an event log. * The name and type of the servlet log file is specific to the servlet container. **/ public void log( String message ) { // XXX change this to use something testable @@ -202,7 +203,7 @@ /** - * Writes an explanatory message and a stack trace for a given Throwable exception to the servlet log file. + * Writes an explanatory message and a stack trace for a given Throwable exception to the servlet log file. * The name and type of the servlet log file is specific to the servlet container, usually an event log. **/ public void log( String message, Throwable t ) { @@ -213,7 +214,7 @@ /** * Returns a String containing the real path for a given virtual path. For example, the virtual path "/index.html" has a real path of - * whatever file on the server's filesystem would be served by a request for "/index.html". + * whatever file on the server's filesystem would be served by a request for "/index.html". * * The real path returned will be in a form appropriate to the computer and operating system on which the servlet container is running, * including the proper path separators. This method returns null if the servlet container cannot translate the virtual path to a real path for @@ -225,10 +226,10 @@ /** - * Returns the name and version of the servlet container on which the servlet is running. + * Returns the name and version of the servlet container on which the servlet is running. * The form of the returned string is servername/versionnumber. For example, the JavaServer Web Development Kit may return the - * string JavaServer Web Dev Kit/1.0. + * string JavaServer Web Dev Kit/1.0. * The servlet container may return other optional information after the primary string in parentheses, for example, JavaServer Web * Dev Kit/1.0 (JDK 1.1.6; Windows NT 4.0 x86). @@ -239,31 +240,31 @@ /** - * Returns a String containing the value of the named context-wide initialization parameter, or null if the parameter does not exist. + * Returns a String containing the value of the named context-wide initialization parameter, or null if the parameter does not exist. * * This method can make available configuration information useful to an entire "web application". For example, it can provide a * webmaster's email address or the name of a system that holds critical data. **/ public java.lang.String getInitParameter( String name ) { - return null; // XXX not implemented - } + return (String) _contextParams.get( name ); + } /** - * Returns the names of the context's initialization parameters as an Enumeration of String objects, + * Returns the names of the context's initialization parameters as an Enumeration of String objects, * or an empty Enumeration if the context has no initialization parameters. **/ public java.util.Enumeration getInitParameterNames() { - return EMPTY_VECTOR.elements(); // XXX not implemented - } + return _contextParams.keys(); + } /** - * Returns the servlet container attribute with the given name, or null if there is no attribute by that name. - * An attribute allows a servlet container to give the servlet additional information not already + * Returns the servlet container attribute with the given name, or null if there is no attribute by that name. + * An attribute allows a servlet container to give the servlet additional information not already * provided by this interface. See your server documentation for information * about its attributes. A list of supported attributes can be retrieved using getAttributeNames. - **/ + **/ public Object getAttribute( String name ) { return _attributes.get( name ); } @@ -325,6 +326,18 @@ return null; } +//------------------------------------------- package members ---------------------------------------------------- + + + void setInitParameter( String name, Object initParameter ) { + _contextParams.put( name, initParameter ); + } + + + void removeInitParameter( String name ) { + _contextParams.remove( name ); + } + //------------------------------------------- private members ---------------------------------------------------- @@ -332,4 +345,5 @@ private Hashtable _attributes = new Hashtable(); private WebApplication _application; + private Hashtable _contextParams = new Hashtable(); } Index: WebApplication.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/WebApplication.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- WebApplication.java 2002/01/22 15:25:16 1.3 +++ WebApplication.java 2002/01/30 21:21:11 1.4 @@ -70,6 +70,7 @@ _securityConstraints.add( new SecurityConstraintImpl( (Element) nl.item(i) ) ); } + extractContextParameters( document ); extractLoginConfiguration( document ); } @@ -98,7 +99,7 @@ if (!Servlet.class.isAssignableFrom( servletClass )) throw new HttpInternalErrorException( url ); Servlet servlet = (Servlet) servletClass.newInstance(); // XXX cache instances - by class? - servlet.init( new ServletUnitServletConfig( servlet, this, configuration.getInitParams() ) ); + servlet.init( new ServletUnitServletConfig( servlet, this, configuration.getInitParams(), _contextParameters ) ); return servlet; } catch (ClassNotFoundException e) { throw new HttpNotFoundException( url, e ); @@ -201,6 +202,7 @@ private URL _errorURL; + private Hashtable _contextParameters = new Hashtable(); final static private SecurityConstraint NULL_SECURITY_CONSTRAINT = new NullSecurityConstraint(); @@ -243,6 +245,17 @@ private void registerServlet( Dictionary mapping, Element servletElement ) throws SAXException { registerServlet( getChildNodeValue( servletElement, "url-pattern" ), (ServletConfiguration) mapping.get( getChildNodeValue( servletElement, "servlet-name" ) ) ); + } + + + private void extractContextParameters( Document document ) throws SAXException { + NodeList nl = document.getElementsByTagName( "context-param" ); + for (int i = 0; i < nl.getLength(); i++) { + Element param = (Element)nl.item(i); + String name = getChildNodeValue(param, "param-name"); + String value = getChildNodeValue(param, "param-value"); + _contextParameters.put(name, value); + } } |
From: Russell G. <rus...@us...> - 2002-01-30 21:29:54
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv15077/test/com/meterware/servletunit Modified Files: WebXMLString.java WebXMLTest.java Log Message: from Alex Chaffee: implemented context parameters in ServletUnit Index: WebXMLString.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/WebXMLString.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- WebXMLString.java 2001/12/03 15:42:39 1.1 +++ WebXMLString.java 2002/01/30 21:21:11 1.2 @@ -42,6 +42,12 @@ String asText() { StringBuffer result = new StringBuffer( "<?xml version='1.0' encoding='UTF-8'?>\n<web-app>\n" ); + + for (Iterator i = _contextParams.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Map.Entry) i.next(); + result.append( " <context-param>\n <param-name>" ).append( entry.getKey() ); + result.append( "</param-name>\n <param-value>" ).append( entry.getValue() ).append( "</param-value>\n </context-param>\n" ); + } for (int i = _servlets.size() - 1; i >= 0; i--) { result.append( " <servlet>\n <servlet-name>servlet_" ).append( i ).append( "</servlet-name>\n" ); result.append( " <servlet-class>" ).append( ((Class) _servlets.get( i )).getName() ).append( "</servlet-class>\n" ); @@ -72,6 +78,11 @@ } + void addContextParam( String name, String value ) { + _contextParams.put( name, value ); + } + + void addServlet( String urlPattern, Class servletClass ) { _servlets.add( servletClass ); _mappings.add( urlPattern ); @@ -127,6 +138,7 @@ private String _loginConfig = ""; private Hashtable _resources = new Hashtable(); private Hashtable _initParams = new Hashtable(); + private Hashtable _contextParams = new Hashtable(); private WebResourceSpec getWebResource( String resourceName ) { Index: WebXMLTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/WebXMLTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- WebXMLTest.java 2002/01/08 23:21:54 1.5 +++ WebXMLTest.java 2002/01/30 21:21:11 1.6 @@ -124,6 +124,25 @@ } + public void testContextParameters() throws Exception { + WebXMLString wxs = new WebXMLString(); + wxs.addServlet( "/SimpleServlet", SimpleGetServlet.class ); + wxs.addContextParam( "icecream", "vanilla" ); + wxs.addContextParam( "cone", "waffle" ); + + ServletRunner sr = new ServletRunner( toInputStream( wxs.asText() ) ); + ServletUnitClient client = sr.newClient(); + InvocationContext ic = client.newInvocation( "http://localhost/SimpleServlet" ); + + javax.servlet.ServletContext sc = ((HttpServlet) ic.getServlet()).getServletContext(); + assertNotNull( "ServletContext should not be null", sc ); + assertEquals( "ServletContext.getInitParameter()", "vanilla", sc.getInitParameter( "icecream" ) ); + assertEquals( "init parameter: cone", "waffle", sc.getInitParameter( "cone" ) ); + assertNull( "ServletContext.getInitParameter() should be null", sc.getInitParameter( "shoesize" ) ); + + } + + private Document newDocument( String contents ) throws UnsupportedEncodingException, SAXException, IOException { DOMParser parser = new DOMParser(); parser.parse( new InputSource( toInputStream( contents ) ) ); |
From: Russell G. <rus...@us...> - 2002-01-30 21:29:54
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv15077/doc Modified Files: release_notes.txt Log Message: from Alex Chaffee: implemented context parameters in ServletUnit Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.82 retrieving revision 1.83 diff -u -r1.82 -r1.83 --- release_notes.txt 2002/01/25 19:09:08 1.82 +++ release_notes.txt 2002/01/30 21:21:10 1.83 @@ -11,6 +11,13 @@ Revision History: +30-Jan-2002 +Acknkowledgements: + Thanks to Alex Chaffee for implementing context parameters for web.xml in ServletUnit + +Additions: + 1. ServletUnit now supports the <context-param> tag. + 24-Jan-2002 Additions: 1. You can now call HttpUnitOptions.setAutoRedirect( false ) to enable explicit testing of redirect requests. |
From: Russell G. <rus...@us...> - 2002-01-28 21:37:08
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv28193/src/com/meterware/httpunit Modified Files: HttpUnitOptions.java Log Message: Make sure to initialize new static property to default value! Index: HttpUnitOptions.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- HttpUnitOptions.java 2002/01/24 17:59:45 1.16 +++ HttpUnitOptions.java 2002/01/28 21:37:05 1.17 @@ -318,7 +318,7 @@ private static boolean _autoRefresh; - private static boolean _autoRedirect; + private static boolean _autoRedirect = true; private static boolean _postIncludesCharset = false; |
From: Russell G. <rus...@us...> - 2002-01-28 21:11:00
|
Update of /cvsroot/httpunit/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv20271 Modified Files: build.xml Log Message: Added manifest to jar Index: build.xml =================================================================== RCS file: /cvsroot/httpunit/httpunit/build.xml,v retrieving revision 1.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- build.xml 2002/01/14 18:13:45 1.38 +++ build.xml 2002/01/28 21:10:57 1.39 @@ -58,6 +58,7 @@ <!-- Prepares the build directory --> <!-- =================================================================== --> <target name="prepare"> + <tstamp /> <mkdir dir="${build.dir}" /> </target> @@ -126,7 +127,12 @@ <!-- =================================================================== --> <target name="jar" depends="compile"> <mkdir dir="${lib.dir}" /> - <jar jarfile="${lib.dir}/${name}.jar" basedir="${build.classes}" includes="com/**" /> + <echo file="${build.dir}/info.txt" message="Manifest-Version: 1.0" /> + <echo file="${build.dir}/info.txt" message="Sealed: false" append="yes" /> + <echo file="${build.dir}/info.txt" message="HttpUnit-Version: ${version}" append="yes" /> + <echo file="${build.dir}/info.txt" message="Build-Date: ${TODAY}" append="yes" /> + <echo file="${build.dir}/info.txt" message="Build-Time: ${TSTAMP}" append="yes" /> + <jar jarfile="${lib.dir}/${name}.jar" basedir="${build.classes}" includes="com/**" manifest="${build.dir}/info.txt" /> </target> |
From: Russell G. <rus...@us...> - 2002-01-28 18:43:28
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv28744/test/com/meterware/httpunit Modified Files: HttpUnitTest.java PseudoServerTest.java WebFrameTest.java Log Message: Clean up handling of disabled auto-redirect Index: HttpUnitTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitTest.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- HttpUnitTest.java 2002/01/14 18:13:45 1.18 +++ HttpUnitTest.java 2002/01/28 18:43:25 1.19 @@ -68,6 +68,11 @@ } + protected void defineResource( String resourceName, String value, int statusCode ) { + _server.setErrorResource( resourceName, statusCode, value ); + } + + protected void defineResource( String resourceName, String value, String contentType ) { _server.setResource( resourceName, value, contentType ); } Index: PseudoServerTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServerTest.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- PseudoServerTest.java 2002/01/10 22:18:14 1.19 +++ PseudoServerTest.java 2002/01/28 18:43:25 1.20 @@ -172,7 +172,7 @@ PseudoServer ps = new PseudoServer(); int port = ps.getConnectedPort(); ps.setResource( resourceName, resourceValue ); - ps.setResource( redirectName, "" ); + ps.setErrorResource( redirectName, HttpURLConnection.HTTP_MOVED_PERM, "" ); ps.addResourceHeader( redirectName, "Location: http://localhost:" + port + '/' + resourceName ); try { @@ -186,6 +186,32 @@ } } + + public void testDisabledRedirect() throws Exception { + String resourceName = "something/redirected"; + String resourceValue = "the desired content"; + + String redirectName = "anOldOne"; + String redirectValue = "old content"; + + PseudoServer ps = new PseudoServer(); + int port = ps.getConnectedPort(); + ps.setResource( resourceName, resourceValue ); + ps.setErrorResource( redirectName, HttpURLConnection.HTTP_MOVED_PERM, redirectValue ); + ps.addResourceHeader( redirectName, "Location: http://localhost:" + port + '/' + resourceName ); + + try { + HttpUnitOptions.setAutoRedirect( false ); + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + '/' + redirectName ); + WebResponse response = wc.getResponse( request ); + assertEquals( "requested resource", redirectValue, response.getText().trim() ); + assertEquals( "content type", "text/html", response.getContentType() ); + } finally { + HttpUnitOptions.setAutoRedirect( true ); + ps.shutDown(); + } + } public void testCookies() throws Exception { Index: WebFrameTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFrameTest.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- WebFrameTest.java 2002/01/17 19:38:09 1.9 +++ WebFrameTest.java 2002/01/28 18:43:25 1.10 @@ -20,6 +20,7 @@ * *******************************************************************************************************************/ import java.net.URL; +import java.net.HttpURLConnection; import junit.framework.Test; import junit.framework.TestCase; @@ -262,7 +263,7 @@ public void testSelfTargetForm() throws Exception { defineWebPage( "Linker", "<form action=redirect.html target=_self><input type=text name=sample value=z></form>" ); - defineResource( "redirect.html?sample=z", "" ); + defineResource( "redirect.html?sample=z", "", HttpURLConnection.HTTP_MOVED_PERM ); addResourceHeader( "redirect.html?sample=z", "Location: " + getHostPath() + "/Target.html" ); _wc.getResponse( getHostPath() + "/Frames.html" ); @@ -274,7 +275,7 @@ public void testSubFrameRedirect() throws Exception { - defineResource( "Linker.html", "" ); + defineResource( "Linker.html", "", HttpURLConnection.HTTP_MOVED_PERM ); addResourceHeader( "Linker.html", "Location: " + getHostPath() + "/Target.html" ); _wc.getResponse( getHostPath() + "/Frames.html" ); |
From: Russell G. <rus...@us...> - 2002-01-28 18:43:28
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv28744/src/com/meterware/httpunit Modified Files: HttpWebResponse.java WebClient.java Log Message: Clean up handling of disabled auto-redirect Index: HttpWebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpWebResponse.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- HttpWebResponse.java 2001/11/09 18:35:14 1.16 +++ HttpWebResponse.java 2002/01/28 18:43:25 1.17 @@ -52,7 +52,7 @@ readHeaders( connection ); /** make sure that any IO exception for HTML received page happens here, not later. **/ - if (_responseCode == HttpURLConnection.HTTP_OK || !HttpUnitOptions.getExceptionsThrownOnErrorStatus()) { + if (_responseCode < HttpURLConnection.HTTP_BAD_REQUEST || !HttpUnitOptions.getExceptionsThrownOnErrorStatus()) { defineRawInputStream( new BufferedInputStream( connection.getInputStream() ) ); if (getContentType().startsWith( "text" )) loadResponseText(); } Index: WebClient.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- WebClient.java 2002/01/25 19:09:08 1.16 +++ WebClient.java 2002/01/28 18:43:25 1.17 @@ -219,12 +219,20 @@ validateHeaders( response ); if (HttpUnitOptions.getAutoRefresh() && response.getRefreshRequest() != null) { getResponse( response.getRefreshRequest() ); - } else if (!HttpUnitOptions.getAutoRedirect() || response.getHeaderField( "Location" ) == null) { - updateFrames( response ); - } else { + } else if (shouldFollowRedirect( response )) { delay( HttpUnitOptions.getRedirectDelay() ); getResponse( new RedirectWebRequest( response ) ); + } else { + updateFrames( response ); } + } + + + private boolean shouldFollowRedirect( WebResponse response ) { + return HttpUnitOptions.getAutoRedirect() + && response.getResponseCode() >= HttpURLConnection.HTTP_MOVED_PERM + && response.getResponseCode() <= HttpURLConnection.HTTP_MOVED_TEMP + && response.getHeaderField( "Location" ) != null; } |
From: Russell G. <rus...@us...> - 2002-01-28 05:06:41
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv15875/test/com/meterware/httpunit Modified Files: PseudoServer.java Log Message: Made constructor public Index: PseudoServer.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServer.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- PseudoServer.java 2001/11/09 18:35:14 1.16 +++ PseudoServer.java 2002/01/28 05:06:37 1.17 @@ -40,7 +40,7 @@ public class PseudoServer { - PseudoServer() { + public PseudoServer() { Thread t = new Thread() { public void run() { while (_active) { |
From: Russell G. <rus...@us...> - 2002-01-28 05:05:34
|
Update of /cvsroot/httpunit/httpunit/examples In directory usw-pr-cvs1:/tmp/cvs-serv15671 Modified Files: Example.java ExampleTest.java Log Message: Cleanup - use getText and getTitle methods Index: Example.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/examples/Example.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- Example.java 2000/06/12 13:09:26 1.1.1.1 +++ Example.java 2002/01/28 05:05:30 1.2 @@ -1 +1 @@ -import com.meterware.httpunit.*; import java.io.IOException; import java.net.MalformedURLException; import org.xml.sax.*; public class Example { public static void main( String[] params ) { try { WebRequest request; WebResponse response; WebConversation conversation = new WebConversation(); request = new GetMethodWebRequest( "http://www.meterware.com/servlet/TopSecret" ); response = conversation.getResponse( request ); System.out.println( response ); WebForm loginForm = response.getForms()[0]; request = loginForm.getRequest(); request.setParameter( "name", "master" ); response = conversation.getResponse( request ); System.out.println( response ); } catch (Exception e) { System.err.println( "Exception: " + e ); } } } \ No newline at end of file +import com.meterware.httpunit.*; import java.io.IOException; import java.net.MalformedURLException; import org.xml.sax.*; public class Example { public static void main( String[] params ) { try { WebRequest request; WebResponse response; WebConversation conversation = new WebConversation(); request = new GetMethodWebRequest( "http://www.meterware.com/servlet/TopSecret" ); response = conversation.getResponse( request ); System.out.println( response ); WebForm loginForm = response.getForms()[0]; request = loginForm.getRequest(); request.setParameter( "name", "master" ); response = conversation.getResponse( request ); System.out.println( response.getText() ); } catch (Exception e) { System.err.println( "Exception: " + e ); } } } \ No newline at end of file Index: ExampleTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/examples/ExampleTest.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- ExampleTest.java 2000/06/12 13:09:26 1.1.1.1 +++ ExampleTest.java 2002/01/28 05:05:30 1.2 @@ -57,7 +57,7 @@ WebForm loginForm = response.getForms()[0]; request = loginForm.getRequest(); response = conversation.getResponse( request ); - assert( "Login not rejected", response.toString().indexOf( "Login failed" ) != -1 ); + assertTrue( "Login not rejected", response.getText().indexOf( "Login failed" ) != -1 ); } @@ -74,12 +74,9 @@ request = loginForm.getRequest(); request.setParameter( "name", "master" ); response = conversation.getResponse( request ); - assert( "Login not accepted", response.toString().indexOf( "You made it!" ) != -1 ); + assertTrue( "Login not accepted", response.getText().indexOf( "You made it!" ) != -1 ); - Document document = response.getDOM(); - NodeList nl = document.getElementsByTagName( "title" ); - assert( "No unique title found", nl.getLength() == 1 ); - assertEquals( "Top Secret", nl.item(0).getFirstChild().getNodeValue() ); + assertEquals( "Page title", "Top Secret", response.getTitle() ); } } |