httpunit-commit Mailing List for httpunit (Page 55)
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-08-23 19:33:16
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv15716/src/com/meterware/httpunit/javascript Modified Files: JavaScript.java Log Message: Added support for javascript: URLs Index: JavaScript.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- JavaScript.java 21 Aug 2002 19:06:27 -0000 1.15 +++ JavaScript.java 23 Aug 2002 19:33:13 -0000 1.16 @@ -104,6 +104,19 @@ } } + /** + * Evaluates the specified string as JavaScript. Will return null if the script has no return value. + */ + public String getURLContents( String urlString ) { + try { + Object result = Context.getCurrentContext().evaluateString( this, urlString, "httpunit", 0, null ); + return (result == null || result instanceof Undefined) ? null : result.toString(); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException( "Script '" + urlString + "' failed: " + e ); + } + } + void initialize( JavaScriptEngine parent, ScriptableDelegate scriptable ) throws JavaScriptException, NotAFunctionException, PropertyException, SAXException { |
From: Russell G. <rus...@us...> - 2002-08-23 19:33:16
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv15716/test/com/meterware/httpunit/javascript Modified Files: FormScriptingTest.java ScriptingTest.java Log Message: Added support for javascript: URLs Index: FormScriptingTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- FormScriptingTest.java 21 Aug 2002 03:45:01 -0000 1.5 +++ FormScriptingTest.java 23 Aug 2002 19:33:13 -0000 1.6 @@ -24,6 +24,7 @@ import com.meterware.httpunit.WebForm; import com.meterware.httpunit.HttpUnitTest; import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebClient; import org.xml.sax.SAXException; @@ -79,9 +80,9 @@ assertEquals( "Initial state", null, form.getParameterValue( "ready" ) ); response.getLinks()[ 0 ].click(); - assertEquals( "Message 1", "form has 3 elements", response.popNextAlert() ); - assertEquals( "Message 2", "value is Initial Text", response.popNextAlert() ); - assertEquals( "Message 3", "index is 1", response.popNextAlert() ); + assertEquals( "Message 1", "form has 3 elements", wc.popNextAlert() ); + assertEquals( "Message 2", "value is Initial Text", wc.popNextAlert() ); + assertEquals( "Message 3", "index is 1", wc.popNextAlert() ); assertEquals( "Changed state", "on", form.getParameterValue( "ready" ) ); } @@ -166,14 +167,14 @@ WebForm form = response.getFormWithName( "the_form" ); assertEquals( "Initial state", "blue", form.getParameterValue( "color" ) ); - assertEquals( "Alert message before change", null, response.getNextAlert() ); + assertEquals( "Alert message before change", null, wc.getNextAlert() ); form.setParameter( "color", "red" ); - assertEquals( "Alert after change", "color is now red", response.popNextAlert() ); + assertEquals( "Alert after change", "color is now red", wc.popNextAlert() ); assertEquals( "Changed state", "red", form.getParameterValue( "color" ) ); response.getLinks()[ 0 ].click(); assertEquals( "Final state", "green", form.getParameterValue( "color" ) ); - assertEquals( "Alert message after JavaScript change", null, response.getNextAlert() ); + assertEquals( "Alert message after JavaScript change", null, wc.getNextAlert() ); } @@ -196,7 +197,7 @@ WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); WebForm form = response.getFormWithName( "realform" ); response.getLinkWithName( "report" ).mouseOver(); - verifyCheckbox( response, /* default */ false, /* checked */ false, /* value */ "good" ); + verifyCheckbox( /* default */ wc, false, /* checked */ false, /* value */ "good" ); assertEquals( "initial parameter value", null, form.getParameterValue( "ready" ) ); response.getLinkWithName( "set" ).mouseOver(); @@ -206,7 +207,7 @@ response.getLinkWithName( "change" ).mouseOver(); assertEquals( "final parameter value", null, form.getParameterValue( "ready" ) ); response.getLinkWithName( "report" ).mouseOver(); - verifyCheckbox( response, /* default */ false, /* checked */ false, /* value */ "waiting" ); + verifyCheckbox( /* default */ wc, false, /* checked */ false, /* value */ "waiting" ); form.setParameter( "ready", "waiting" ); } @@ -228,15 +229,15 @@ WebConversation wc = new WebConversation(); WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); WebForm form = response.getFormWithName( "realform" ); - verifyCheckbox( response, /* default */ true, /* checked */ true, /* value */ "good" ); - verifyCheckbox( response, /* default */ false, /* checked */ false, /* value */ "bad" ); + verifyCheckbox( /* default */ wc, true, /* checked */ true, /* value */ "good" ); + verifyCheckbox( /* default */ wc, false, /* checked */ false, /* value */ "bad" ); } - private void verifyCheckbox( WebResponse response, boolean defaultChecked, boolean checked, String value ) throws SAXException { - assertEquals( "Message " + 1 + "-1", "checkbox ready default = " + defaultChecked, response.popNextAlert() ); - assertEquals( "Message " + 1 + "-2", "checkbox ready checked = " + checked, response.popNextAlert() ); - assertEquals( "Message " + 1 + "-3", "checkbox ready value = " + value, response.popNextAlert() ); + private void verifyCheckbox( WebClient wc, boolean defaultChecked, boolean checked, String value ) throws SAXException { + assertEquals( "Message " + 1 + "-1", "checkbox ready default = " + defaultChecked, wc.popNextAlert() ); + assertEquals( "Message " + 1 + "-2", "checkbox ready checked = " + checked, wc.popNextAlert() ); + assertEquals( "Message " + 1 + "-3", "checkbox ready value = " + value, wc.popNextAlert() ); } @@ -254,18 +255,18 @@ WebForm form = response.getFormWithName( "the_form" ); assertEquals( "Initial state", null, form.getParameterValue( "color" ) ); - assertEquals( "Alert message before change", null, response.getNextAlert() ); + assertEquals( "Alert message before change", null, wc.getNextAlert() ); form.removeParameter( "color" ); - assertEquals( "Alert message w/o change", null, response.getNextAlert() ); + assertEquals( "Alert message w/o change", null, wc.getNextAlert() ); form.setParameter( "color", "blue" ); - assertEquals( "Alert after change", "color-blue is now true", response.popNextAlert() ); + assertEquals( "Alert after change", "color-blue is now true", wc.popNextAlert() ); form.removeParameter( "color" ); - assertEquals( "Alert after change", "color-blue is now false", response.popNextAlert() ); + assertEquals( "Alert after change", "color-blue is now false", wc.popNextAlert() ); assertEquals( "Changed state", null, form.getParameterValue( "color" ) ); response.getLinks()[ 0 ].click(); assertEquals( "Final state", "blue", form.getParameterValue( "color" ) ); - assertEquals( "Alert message after JavaScript change", null, response.getNextAlert() ); + assertEquals( "Alert message after JavaScript change", null, wc.getNextAlert() ); } @@ -286,15 +287,15 @@ WebConversation wc = new WebConversation(); WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); WebForm form = response.getFormWithName( "realform" ); - verifyRadio( response, /* default */ true, /* checked */ true, /* value */ "good" ); - verifyRadio( response, /* default */ false, /* checked */ false, /* value */ "bad" ); + verifyRadio( /* default */ wc, true, /* checked */ true, /* value */ "good" ); + verifyRadio( /* default */ wc, false, /* checked */ false, /* value */ "bad" ); } - private void verifyRadio( WebResponse response, boolean defaultChecked, boolean checked, String value ) throws SAXException { - assertEquals( "Message " + 1 + "-1", "radio ready default = " + defaultChecked, response.popNextAlert() ); - assertEquals( "Message " + 1 + "-2", "radio ready checked = " + checked, response.popNextAlert() ); - assertEquals( "Message " + 1 + "-3", "radio ready value = " + value, response.popNextAlert() ); + private void verifyRadio( WebClient wc, boolean defaultChecked, boolean checked, String value ) throws SAXException { + assertEquals( "Message " + 1 + "-1", "radio ready default = " + defaultChecked, wc.popNextAlert() ); + assertEquals( "Message " + 1 + "-2", "radio ready checked = " + checked, wc.popNextAlert() ); + assertEquals( "Message " + 1 + "-3", "radio ready value = " + value, wc.popNextAlert() ); } @@ -314,18 +315,18 @@ WebForm form = response.getFormWithName( "the_form" ); assertEquals( "Initial state", "red", form.getParameterValue( "color" ) ); - assertEquals( "Alert message before change", null, response.getNextAlert() ); + assertEquals( "Alert message before change", null, wc.getNextAlert() ); form.setParameter( "color", "red" ); - assertEquals( "Alert message w/o change", null, response.getNextAlert() ); + assertEquals( "Alert message w/o change", null, wc.getNextAlert() ); form.setParameter( "color", "blue" ); - assertEquals( "Alert after change", "color is now blue", response.popNextAlert() ); + assertEquals( "Alert after change", "color is now blue", wc.popNextAlert() ); form.setParameter( "color", "red" ); - assertEquals( "Alert after change", "color is now red", response.popNextAlert() ); + assertEquals( "Alert after change", "color is now red", wc.popNextAlert() ); assertEquals( "Changed state", "red", form.getParameterValue( "color" ) ); response.getLinks()[ 0 ].click(); assertEquals( "Final state", "blue", form.getParameterValue( "color" ) ); - assertEquals( "Alert message after JavaScript change", null, response.getNextAlert() ); + assertEquals( "Alert message after JavaScript change", null, wc.getNextAlert() ); } @@ -339,7 +340,7 @@ "<a href='#' name='doShow' onClick='alert( document.the_form.action );'>show</a>" ); WebResponse page = wc.getResponse( getHostPath() + "/Default.html" ); page.getLinkWithName( "doShow" ).click(); - assertEquals( "Current action", "ask", page.popNextAlert() ); + assertEquals( "Current action", "ask", wc.popNextAlert() ); page.getLinkWithName( "doTell" ).click(); WebRequest request = page.getForms()[0].getRequest(); @@ -369,7 +370,7 @@ WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); WebForm form = response.getFormWithName( "realform" ); form.submit(); - assertEquals( "Alert message", "wrong color", response.popNextAlert() ); + assertEquals( "Alert message", "wrong color", wc.popNextAlert() ); assertSame( "Current response", response, wc.getCurrentPage() ); form.setParameter( "color", "pink" ); WebResponse newResponse = form.submit(); @@ -399,17 +400,17 @@ "</body></html>" ); WebConversation wc = new WebConversation(); WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); - assertEquals( "1st message", "select has 2 options", response.popNextAlert() ); - assertEquals( "2nd message", "select still has 2 options", response.popNextAlert() ); - assertEquals( "3rd message", "select option 0 is red", response.popNextAlert() ); - assertEquals( "4th message", "select 2nd option value is 3", response.popNextAlert() ); - assertEquals( "5th message", "blue selected", response.popNextAlert() ); + assertEquals( "1st message", "select has 2 options", wc.popNextAlert() ); + assertEquals( "2nd message", "select still has 2 options", wc.popNextAlert() ); + assertEquals( "3rd message", "select option 0 is red", wc.popNextAlert() ); + assertEquals( "4th message", "select 2nd option value is 3", wc.popNextAlert() ); + assertEquals( "5th message", "blue selected", wc.popNextAlert() ); response.getLinks()[0].mouseOver(); - assertEquals( "before change message", "selected #1", response.popNextAlert() ); + assertEquals( "before change message", "selected #1", wc.popNextAlert() ); response.getFormWithName( "the_form" ).setParameter( "choices", "1" ); response.getLinks()[0].mouseOver(); - assertEquals( "after change message", "selected #0", response.popNextAlert() ); + assertEquals( "after change message", "selected #0", wc.popNextAlert() ); } @@ -435,16 +436,16 @@ final WebForm form = response.getFormWithName( "the_form" ); assertEquals( "Initial state", "blue", form.getParameterValue( "choices" ) ); - assertEquals( "Alert message before change", null, response.getNextAlert() ); + assertEquals( "Alert message before change", null, wc.getNextAlert() ); form.setParameter( "choices", "red" ); - assertEquals( "Alert after change", "Selected index is 0", response.popNextAlert() ); + assertEquals( "Alert after change", "Selected index is 0", wc.popNextAlert() ); form.setParameter( "choices", "blue" ); - assertEquals( "Alert after change", "Selected index is 1", response.popNextAlert() ); + assertEquals( "Alert after change", "Selected index is 1", wc.popNextAlert() ); assertEquals( "Initial state", "blue", form.getParameterValue( "choices" ) ); response.getLinks()[ 0 ].click(); assertEquals( "Final state", "red", form.getParameterValue( "choices" ) ); - assertEquals( "Alert message after JavaScript change", null, response.getNextAlert() ); + assertEquals( "Alert message after JavaScript change", null, wc.getNextAlert() ); } Index: ScriptingTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/ScriptingTest.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- ScriptingTest.java 21 Aug 2002 19:06:27 -0000 1.16 +++ ScriptingTest.java 23 Aug 2002 19:33:13 -0000 1.17 @@ -46,14 +46,61 @@ } + public void testJavaScriptURLWithValue() throws Exception { + defineResource( "OnCommand.html", "<html><head></head>" + + "<body>" + + "<a href='javascript:\"You made it!\"'>go</a>" + + "</body></html>" ); + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + response.getLinks()[0].click(); + assertEquals( "New page", "You made it!", wc.getCurrentPage().getText() ); + assertEquals( "New URL", "javascript:\"You made it!\"", wc.getCurrentPage().getURL().toExternalForm() ); + } + + + public void testJavaScriptURLWithNoValue() throws Exception { + defineResource( "OnCommand.html", "<html><head></head>" + + "<body>" + + "<a href='javascript:alert( \"Hi there!\" )'>go</a>" + + "</body></html>" ); + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + response.getLinks()[0].click(); + assertEquals( "Alert message", "Hi there!", wc.popNextAlert() ); + assertEquals( "Current page URL", getHostPath() + "/OnCommand.html", wc.getCurrentPage().getURL().toExternalForm() ); + } + + + public void testInitialJavaScriptURL() throws Exception { + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( "javascript:alert( 'Hi there!' )" ); + assertEquals( "Alert message", "Hi there!", wc.popNextAlert() ); + } + + + public void testJavaScriptURLWithParameters() throws Exception { + defineResource( "OnCommand.html", "<html><head></head>" + + "<body>" + + "<a href='javascript:\"Our winner is... \" + document.the_form.winner.value'>go</a>" + + "<form name='the_form'>" + + " <input name=winner type=text value='George of the Jungle'>" + + "</form></body></html>" ); + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + response.getLinks()[0].click(); + assertEquals( "New page", "Our winner is... George of the Jungle", wc.getCurrentPage().getText() ); + } + + public void testSingleCommandOnLoad() throws Exception { defineResource( "OnCommand.html", "<html><head></head>" + "<body onLoad='alert(\"Ouch!\")'></body>" ); WebConversation wc = new WebConversation(); WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); - assertNotNull( "No alert detected", response.getNextAlert() ); - assertEquals( "Alert message", "Ouch!", response.popNextAlert() ); - assertNull( "Alert should have been removed", response.getNextAlert() ); + assertNotNull( "No alert detected", wc.getNextAlert() ); + assertEquals( "Alert message", "Ouch!", wc.popNextAlert() ); + assertNull( "Alert should have been removed", wc.getNextAlert() ); } @@ -107,7 +154,7 @@ "<body onLoad='sayCheese()'></body>" ); WebConversation wc = new WebConversation(); WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); - assertEquals( "Alert message", "Cheese!", response.popNextAlert() ); + assertEquals( "Alert message", "Cheese!", wc.popNextAlert() ); } @@ -116,7 +163,7 @@ "<body onLoad='alert(\"Window title is \" + document.title)'></body>" ); WebConversation wc = new WebConversation(); WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); - assertEquals( "Alert message", "Window title is Amazing!", response.popNextAlert() ); + assertEquals( "Alert message", "Window title is Amazing!", wc.popNextAlert() ); } @@ -135,10 +182,10 @@ "</body></html>" ); WebConversation wc = new WebConversation(); WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); - assertEquals( "Alert message", "found 1 form(s)", response.popNextAlert() ); - assertEquals( "Alert message", "found form 'realform'", response.popNextAlert() ); - assertEquals( "Alert message", "did not find form 'noform'", response.popNextAlert() ); - assertNull( "Alert should have been removed", response.getNextAlert() ); + assertEquals( "Alert message", "found 1 form(s)", wc.popNextAlert() ); + assertEquals( "Alert message", "found form 'realform'", wc.popNextAlert() ); + assertEquals( "Alert message", "did not find form 'noform'", wc.popNextAlert() ); + assertNull( "Alert should have been removed", wc.getNextAlert() ); } @@ -159,10 +206,10 @@ "</body></html>" ); WebConversation wc = new WebConversation(); WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); - assertEquals( "Alert message", "found 2 link(s)", response.popNextAlert() ); - assertEquals( "Alert message", "found link 'reallink'", response.popNextAlert() ); - assertEquals( "Alert message", "did not find link 'nolink'", response.popNextAlert() ); - assertNull( "Alert should have been removed", response.getNextAlert() ); + assertEquals( "Alert message", "found 2 link(s)", wc.popNextAlert() ); + assertEquals( "Alert message", "found link 'reallink'", wc.popNextAlert() ); + assertEquals( "Alert message", "did not find link 'nolink'", wc.popNextAlert() ); + assertNull( "Alert should have been removed", wc.getNextAlert() ); } @@ -186,7 +233,7 @@ defineResource( "OnCommand.html", "<html><head></head>" + "<body>" + "<form name='realform'><input name='color' value='blue'></form>" + - "<a href='nothing.html' onClick=\"document.realform.color.value='green';return false;\">green</a>" + + "<a href='nothing.html' onClick=\"JavaScript:document.realform.color.value='green';return false;\">green</a>" + "</body></html>" ); WebConversation wc = new WebConversation(); WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); @@ -251,11 +298,11 @@ "</body></html>" ); WebConversation wc = new WebConversation(); WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); - assertEquals( "Alert message", getHostPath() + "/demo.html", response.popNextAlert() ); - assertEquals( "Alert message", getHostPath() + "/guide.html", response.popNextAlert() ); - assertEquals( "Alert message", getHostPath() + "/search.html", response.popNextAlert() ); - assertEquals( "Alert message", getHostPath() + "/sample.html", response.popNextAlert() ); - assertNull( "Alert should have been removed", response.getNextAlert() ); + assertEquals( "Alert message", getHostPath() + "/demo.html", wc.popNextAlert() ); + assertEquals( "Alert message", getHostPath() + "/guide.html", wc.popNextAlert() ); + assertEquals( "Alert message", getHostPath() + "/search.html", wc.popNextAlert() ); + assertEquals( "Alert message", getHostPath() + "/sample.html", wc.popNextAlert() ); + assertNull( "Alert should have been removed", wc.getNextAlert() ); } @@ -276,11 +323,11 @@ "</body></html>" ); WebConversation wc = new WebConversation(); WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); - assertEquals( "Alert message", "found 2 images(s)", response.popNextAlert() ); - assertEquals( "Alert message", "found image 'realimage'", response.popNextAlert() ); - assertEquals( "Alert message", "did not find image 'noimage'", response.popNextAlert() ); - assertEquals( "Alert message", "2nd image is pict2.gif", response.popNextAlert() ); - assertNull( "Alert should have been removed", response.getNextAlert() ); + assertEquals( "Alert message", "found 2 images(s)", wc.popNextAlert() ); + assertEquals( "Alert message", "found image 'realimage'", wc.popNextAlert() ); + assertEquals( "Alert message", "did not find image 'noimage'", wc.popNextAlert() ); + assertEquals( "Alert message", "2nd image is pict2.gif", wc.popNextAlert() ); + assertNull( "Alert should have been removed", wc.getNextAlert() ); } |
From: Russell G. <rus...@us...> - 2002-08-23 19:33:16
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/scripting In directory usw-pr-cvs1:/tmp/cvs-serv15716/src/com/meterware/httpunit/scripting Modified Files: ScriptableDelegate.java ScriptingEngine.java Log Message: Added support for javascript: URLs Index: ScriptableDelegate.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/scripting/ScriptableDelegate.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ScriptableDelegate.java 16 Aug 2002 17:24:00 -0000 1.2 +++ ScriptableDelegate.java 23 Aug 2002 19:33:13 -0000 1.3 @@ -31,11 +31,9 @@ private ScriptingEngine _scriptEngine; private static final ScriptingEngine NULL_SCRIPT_ENGINE = new ScriptingEngine() { - public void executeScript( String script ) { - } - public boolean performEvent( String eventScript ) { - return true; - } + public void executeScript( String script ) {} + public boolean performEvent( String eventScript ) { return true; } + public String getURLContents( String urlString ) { return null; } }; @@ -53,6 +51,15 @@ **/ public void runScript( String script ) { if (script.length() != 0) getScriptEngine().executeScript( script ); + } + + + /** + * Evaluates the specified javascript URL. + **/ + public String evaluateURL( String urlString ) { + if (urlString.length() == 0) return null; + return getScriptEngine().getURLContents( urlString ); } Index: ScriptingEngine.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/scripting/ScriptingEngine.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ScriptingEngine.java 8 Aug 2002 20:47:22 -0000 1.1 +++ ScriptingEngine.java 23 Aug 2002 19:33:13 -0000 1.2 @@ -19,7 +19,6 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ -import java.util.*; /** @@ -29,9 +28,21 @@ public interface ScriptingEngine { + /** + * Interprets the specified script, which may include global function definitions. + */ public void executeScript( String script ); + /** + * Interprets the specified script and returns a boolean result. + */ public boolean performEvent( String eventScript ); + + + /** + * Evaluates the specified string as JavaScript. Will return null if the script has no return value. + */ + public String getURLContents( String urlString ); } |
From: Russell G. <rus...@us...> - 2002-08-23 19:33:15
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv15716/doc Modified Files: release_notes.txt Log Message: Added support for javascript: URLs Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.146 retrieving revision 1.147 diff -u -r1.146 -r1.147 --- release_notes.txt 22 Aug 2002 20:18:27 -0000 1.146 +++ release_notes.txt 23 Aug 2002 19:33:12 -0000 1.147 @@ -11,6 +11,10 @@ Revision History: +23-Aug-2002 +Additions: + 1. javascript URLs are now supported. + 22-Aug-2002 Acknowledgements: |
From: Russell G. <rus...@us...> - 2002-08-22 20:18:34
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv2867/test/com/meterware/servletunit Modified Files: StatelessTest.java Log Message: from Geert Bevin: fixed ServletUnit dropping of POST parameters Index: StatelessTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/StatelessTest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- StatelessTest.java 22 Aug 2002 15:48:41 -0000 1.8 +++ StatelessTest.java 22 Aug 2002 20:18:32 -0000 1.9 @@ -24,6 +24,7 @@ import com.meterware.httpunit.PostMethodWebRequest; import com.meterware.httpunit.WebRequest; import com.meterware.httpunit.WebResponse; +import com.meterware.httpunit.WebForm; import java.io.IOException; import java.io.InputStream; @@ -157,6 +158,20 @@ } + public void testParameterHandling() throws Exception { + ServletRunner sr = new ServletRunner(); + sr.registerServlet( "/testForm", FormSubmissionServlet.class.getName() ); + + ServletUnitClient client = sr.newClient(); + WebResponse wr = client.getResponse( "http://localhost/testForm" ); + WebForm form = wr.getForms()[0]; + form.setParameter( "login", "me" ); + form.setParameter( "password", "haha" ); + form.submit(); + assertEquals( "Resultant response", "You posted me,haha", client.getCurrentPage().getText() ); + } + + public void testSimplePost() throws Exception { final String resourceName = "something/interesting"; @@ -234,6 +249,32 @@ resp.setContentType( "text/plain" ); PrintWriter pw = resp.getWriter(); pw.print( "You posted " + req.getParameter( "color" ) ); + pw.close(); + } + + } + + + static class FormSubmissionServlet extends HttpServlet { + + protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException { + resp.setContentType( "text/html" ); + + PrintWriter pw = resp.getWriter(); + pw.println( "<html><head></head><body>" ); + pw.println( "<FORM ACTION='/testForm?submission=act' METHOD='POST'>" ); + pw.println( "<INPUT NAME='login' TYPE='TEXT'>" ); + pw.println( "<INPUT NAME='password' TYPE='PASSWORD'>" ); + pw.println( "<INPUT TYPE='SUBMIT'>" ); + pw.println( "</FORM></body></html>" ); + pw.close(); + } + + + protected void doPost( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException { + resp.setContentType( "text/plain" ); + PrintWriter pw = resp.getWriter(); + pw.print( "You posted " + req.getParameter( "login" ) + "," + req.getParameter( "password" ) ); pw.close(); } |
From: Russell G. <rus...@us...> - 2002-08-22 20:18:34
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv2867/src/com/meterware/servletunit Modified Files: ServletUnitHttpRequest.java Log Message: from Geert Bevin: fixed ServletUnit dropping of POST parameters Index: ServletUnitHttpRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpRequest.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- ServletUnitHttpRequest.java 19 Jun 2002 13:47:19 -0000 1.13 +++ ServletUnitHttpRequest.java 22 Aug 2002 20:18:31 -0000 1.14 @@ -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 @@ -69,19 +69,16 @@ 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 { - if (_contentType == null || _contentType.indexOf( "x-www-form-urlencoded" ) >= 0 ) { - loadParameters( request.getQueryString() ); - loadParameters( new String( _messageBody ) ); - } + if (file.indexOf( '?' ) >= 0) loadParameters( file.substring( file.indexOf( '?' )+1 ) ); + if (_messageBody == null) return; + if (_contentType == null || _contentType.indexOf( "x-www-form-urlencoded" ) >= 0 ) { + loadParameters( new String( _messageBody ) ); } } //----------------------------------------- HttpServletRequest methods -------------------------- - + /** * Returns the name of the authentication scheme used to protect the servlet, for example, "BASIC" or "SSL," @@ -101,7 +98,7 @@ /** - * Returns an array containing all of the Cookie objects the client sent with this request. + * Returns an array containing all of the Cookie objects the client sent with this request. * This method returns null if no cookies were sent. **/ public Cookie[] getCookies() { @@ -116,9 +113,9 @@ /** - * Returns the value of the specified request header as an int. If the request does not have a header - * of the specified name, this method returns -1. If the header cannot be converted to an integer, - * this method throws a NumberFormatException. + * Returns the value of the specified request header as an int. If the request does not have a header + * of the specified name, this method returns -1. If the header cannot be converted to an integer, + * this method throws a NumberFormatException. **/ public int getIntHeader( String name ) { return -1; @@ -126,12 +123,12 @@ /** - * Returns the value of the specified request header as a long value that represents a Date object. - * Use this method with headers that contain dates, such as If-Modified-Since. + * Returns the value of the specified request header as a long value that represents a Date object. + * Use this method with headers that contain dates, such as If-Modified-Since. * <br> - * The date is returned as the number of milliseconds since January 1, 1970 GMT. The header name is case insensitive. + * The date is returned as the number of milliseconds since January 1, 1970 GMT. The header name is case insensitive. * - * If the request did not have a header of the specified name, this method returns -1. + * If the request did not have a header of the specified name, this method returns -1. * If the header can't be converted to a date, the method throws an IllegalArgumentException. **/ public long getDateHeader( String name ) { @@ -140,8 +137,8 @@ /** - * Returns the value of the specified request header as a String. If the request did not include - * a header of the specified name, this method returns null. The header name is case insensitive. + * Returns the value of the specified request header as a String. If the request did not include + * a header of the specified name, this method returns null. The header name is case insensitive. * You can use this method with any request header. **/ public String getHeader( String name ) { @@ -150,10 +147,10 @@ /** - * Returns an enumeration of all the header names this request contains. If the request has no headers, - * this method returns an empty enumeration. + * Returns an enumeration of all the header names this request contains. If the request has no headers, + * this method returns an empty enumeration. * - * Some servlet containers do not allow do not allow servlets to access headers using this method, + * Some servlet containers do not allow do not allow servlets to access headers using this method, * in which case this method returns null. **/ public Enumeration getHeaderNames() { @@ -162,8 +159,8 @@ /** - * Returns the part of this request's URL that calls the servlet. This includes either the servlet name - * or a path to the servlet, but does not include any extra path information or a query string. + * Returns the part of this request's URL that calls the servlet. This includes either the servlet name + * or a path to the servlet, but does not include any extra path information or a query string. **/ public String getServletPath() { return _servletRequest.getServletPath(); @@ -179,17 +176,17 @@ /** - * Returns any extra path information associated with the URL the client sent when it made this request. - * The extra path information follows the servlet path but precedes the query string. + * Returns any extra path information associated with the URL the client sent when it made this request. + * The extra path information follows the servlet path but precedes the query string. * This method returns null if there was no extra path information. - **/ + **/ public String getPathInfo() { return _servletRequest.getPathInfo(); } /** - * Returns any extra path information after the servlet name but before the query string, + * Returns any extra path information after the servlet name but before the query string, * and translates it to a real path. If the URL does not have any extra path information, this method returns null. **/ public String getPathTranslated() { @@ -206,18 +203,18 @@ /** - * Returns the login of the user making this request, if the user has been authenticated, + * Returns the login of the user making this request, if the user has been authenticated, * or null if the user has not been authenticated. * Whether the user name is sent with each subsequent request depends on the browser and type of authentication. - **/ + **/ public String getRemoteUser() { return _userName; } /** - * Returns the session ID specified by the client. This may not be the same as the ID of the actual session in use. - * For example, if the request specified an old (expired) session ID and the server has started a new session, + * Returns the session ID specified by the client. This may not be the same as the ID of the actual session in use. + * For example, if the request specified an old (expired) session ID and the server has started a new session, * this method gets a new session with a new ID. If the request did not specify a session ID, this method returns null. **/ public String getRequestedSessionId() { @@ -237,11 +234,11 @@ } /** - * Returns the current HttpSession associated with this request or, if there is no current session - * and create is true, returns a new session. + * Returns the current HttpSession associated with this request or, if there is no current session + * and create is true, returns a new session. * <br> * If create is false and the request has no valid HttpSession, this method returns null. - **/ + **/ public HttpSession getSession( boolean create ) { if (_session == null && getRequestedSessionId() != null) { _session = _context.getSession( getRequestedSessionId() ); @@ -506,17 +503,17 @@ /** - * Returns the preferred Locale that the client will accept content in, based on the Accept-Language header. + * Returns the preferred Locale that the client will accept content in, based on the Accept-Language header. * If the client request doesn't provide an Accept-Language header, this method returns the default locale for the server. **/ public java.util.Locale getLocale() { throw new RuntimeException( "getLocale not implemented" ); } - + /** - * Returns an Enumeration of Locale objects indicating, in decreasing order starting with the preferred locale, - * the locales that are acceptable to the client based on the Accept-Language header. + * Returns an Enumeration of Locale objects indicating, in decreasing order starting with the preferred locale, + * the locales that are acceptable to the client based on the Accept-Language header. * If the client request doesn't provide an Accept-Language header, this * method returns an Enumeration containing one Locale, the default locale for the server. **/ @@ -524,49 +521,49 @@ throw new RuntimeException( "getLocales not implemented" ); } - + /** - * Removes an attribute from this request. This method is not generally needed + * Removes an attribute from this request. This method is not generally needed * as attributes only persist as long as the request is being handled. - **/ + **/ public void removeAttribute( String name ) { _attributes.remove( name ); } /** - * Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. - * A RequestDispatcher object can be used to forward a request to the resource or to include the - * resource in a response. The resource can be dynamic or static. - * - * The pathname specified may be relative, although it cannot extend outside the current servlet - * context. If the path begins with a "/" it is interpreted as relative to the current context root. - * This method returns null if the servlet container cannot return a RequestDispatcher. + * Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. + * A RequestDispatcher object can be used to forward a request to the resource or to include the + * resource in a response. The resource can be dynamic or static. + * + * The pathname specified may be relative, although it cannot extend outside the current servlet + * context. If the path begins with a "/" it is interpreted as relative to the current context root. + * This method returns null if the servlet container cannot return a RequestDispatcher. * - * The difference between this method and ServletContext.getRequestDispatcher(java.lang.String) + * The difference between this method and ServletContext.getRequestDispatcher(java.lang.String) * is that this method can take a relative path. - **/ + **/ public RequestDispatcher getRequestDispatcher( String path ) { throw new RuntimeException( "getRequestDispatcher not implemented" ); } - + //--------------------------------- methods added to HttpServletRequest in JSDK 2.2 ------------------------------------------------ /** - * Returns a java.security.Principal object containing the name of the current authenticated user. + * Returns a java.security.Principal object containing the name of the current authenticated user. * If the user has not been authenticated, the method returns null. **/ public java.security.Principal getUserPrincipal() { return null; } - + /** - * Returns a boolean indicating whether the authenticated user is included in the specified - * logical "role". Roles and role membership can be defined using deployment descriptors. + * Returns a boolean indicating whether the authenticated user is included in the specified + * logical "role". Roles and role membership can be defined using deployment descriptors. * If the user has not been authenticated, the method returns false. **/ public boolean isUserInRole( String role ) { @@ -577,7 +574,7 @@ return false; } - + /** * Returns all the values of the specified request header as an Enumeration of String objects. **/ @@ -585,11 +582,11 @@ throw new RuntimeException( "getHeaders not implemented" ); } - + /** - * Returns the portion of the request URI that indicates the context of the request. - * The context path always comes first in a request URI. The path starts with a "/" character - * but does not end with a "/" character. For servlets in the default (root) context, + * Returns the portion of the request URI that indicates the context of the request. + * The context path always comes first in a request URI. The path starts with a "/" character + * but does not end with a "/" character. For servlets in the default (root) context, * this method returns "". **/ public java.lang.String getContextPath() { |
From: Russell G. <rus...@us...> - 2002-08-22 20:18:34
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv2867/doc Modified Files: release_notes.txt Log Message: from Geert Bevin: fixed ServletUnit dropping of POST parameters Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.145 retrieving revision 1.146 diff -u -r1.145 -r1.146 --- release_notes.txt 22 Aug 2002 16:19:53 -0000 1.145 +++ release_notes.txt 22 Aug 2002 20:18:27 -0000 1.146 @@ -15,6 +15,7 @@ Acknowledgements: Thanks to Michael Reardon for implementing the ServletUnit header method handling code and session.getAttributeNames + Thanks to Geert Bevin for finding and fixing the ServletUnit POST parameters bug. Additions: 1. ServletUnit now supports HttpServletResponse header methods: setHeader, addHeader, setIntHeader, addIntHeader, @@ -22,6 +23,9 @@ 2. ServletUnit now supports HttpSession.getAttributeNames. 3. WebImage now supports a read-only 'altText' property. 4. WebResponse and TableCell now support getImageWithAltText to find an image with a specified value in its 'alt' attribute. + +Problems fixed: + 1. ServletUnit was not recognizing form parameters on a POST request which contained a query string in the URL. 21-Aug-2002 |
From: Russell G. <rus...@us...> - 2002-08-22 16:19:57
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv21232/test/com/meterware/httpunit Modified Files: WebImageTest.java Log Message: Added WebImage.getAltText, WebResponse.getImageWithAltText Index: WebImageTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebImageTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- WebImageTest.java 15 Jul 2002 14:30:32 -0000 1.1 +++ WebImageTest.java 22 Aug 2002 16:19:54 -0000 1.2 @@ -52,13 +52,17 @@ "<html><head><title>A Sample Page</title></head>\n" + "<body><img src='sample.jpg'>\n" + "<IMG SRC='another.png'>" + - " and <img src='onemore.gif'>\n" + + " and <img src='onemore.gif' alt='one'>\n" + "</body></html>\n" ); WebConversation wc = new WebConversation(); WebRequest request = new GetMethodWebRequest( getHostPath() + "/SimplePage.html" ); WebResponse simplePage = wc.getResponse( request ); assertEquals( "Number of images", 3, simplePage.getImages().length ); assertEquals( "First image source", "sample.jpg", simplePage.getImages()[0].getSource() ); + + WebImage image = simplePage.getImageWithAltText( "one" ); + assertNotNull( "No image found", image ); + assertEquals( "Selected image source", "onemore.gif", image.getSource() ); } |
From: Russell G. <rus...@us...> - 2002-08-22 16:19:56
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv21232/src/com/meterware/httpunit Modified Files: HTMLSegment.java ParsedHTML.java WebImage.java WebResponse.java Log Message: Added WebImage.getAltText, WebResponse.getImageWithAltText Index: HTMLSegment.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HTMLSegment.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- HTMLSegment.java 9 Nov 2001 18:35:14 -0000 1.3 +++ HTMLSegment.java 22 Aug 2002 16:19:54 -0000 1.4 @@ -71,6 +71,34 @@ /** + * Returns the images found in the page in the order in which they appear. + * @exception SAXException thrown if there is an error parsing the segment. + **/ + public WebImage[] getImages() throws SAXException; + + + /** + * Returns the image found in the page with the specified name. + * @exception SAXException thrown if there is an error parsing the segment. + **/ + public WebImage getImageWithName( String name ) throws SAXException; + + + /** + * Returns the first image found in the page with the specified src attribute. + * @exception SAXException thrown if there is an error parsing the segment. + **/ + public WebImage getImageWithSource( String source ) throws SAXException; + + + /** + * Returns the first image found in the page with the specified alt attribute. + * @exception SAXException thrown if there is an error parsing the segment. + **/ + public WebImage getImageWithAltText( String source ) throws SAXException; + + + /** * Returns the top-level tables found in this HTML segment in the order in which * they appear. * @exception SAXException thrown if there is an error parsing the segment. Index: ParsedHTML.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- ParsedHTML.java 5 Aug 2002 17:34:25 -0000 1.24 +++ ParsedHTML.java 22 Aug 2002 16:19:54 -0000 1.25 @@ -135,20 +135,8 @@ * Returns the first link which contains an image with the specified text as its 'alt' attribute. **/ public WebLink getLinkWithImageText( String text ) { - WebLink[] links = getLinks(); - for (int i = 0; i < links.length; i++) { - NodeList nl = ((Element) links[i].getDOMSubtree()).getElementsByTagName( "img" ); - for (int j = 0; j < nl.getLength(); j++) { - NamedNodeMap nnm = nl.item(j).getAttributes(); - if (text.equals( getValue( nnm.getNamedItem( "alt" ) ) )) { - return links[i]; - } else if (HttpUnitOptions.getMatchesIgnoreCase() && - text.equalsIgnoreCase( getValue( nnm.getNamedItem( "alt" ) ) )) { - return links[i]; - } - } - } - return null; + WebImage image = getImageWithAltText( text ); + return image == null ? null : image.getLink(); } @@ -210,13 +198,26 @@ /** - * Returns the image found in the page with the specified src attribute. + * Returns the first image found in the page with the specified src attribute. **/ public WebImage getImageWithSource( String source ) { WebImage[] images = getImages(); for (int i = 0; i < images.length; i++) { if (images[i].getSource().equals( source )) return images[i]; else if (HttpUnitOptions.getMatchesIgnoreCase() && images[i].getSource().equalsIgnoreCase( source )) return images[i]; + } + return null; + } + + + /** + * Returns the first image found in the page with the specified alt attribute. + **/ + public WebImage getImageWithAltText( String altText ) { + WebImage[] images = getImages(); + for (int i = 0; i < images.length; i++) { + if (images[i].getSource().equals( altText )) return images[i]; + else if (HttpUnitOptions.getMatchesIgnoreCase() && images[i].getAltText().equalsIgnoreCase( altText )) return images[i]; } return null; } Index: WebImage.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebImage.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- WebImage.java 8 Aug 2002 20:47:21 -0000 1.3 +++ WebImage.java 22 Aug 2002 16:19:54 -0000 1.4 @@ -36,7 +36,8 @@ private Node _node; private ParsedHTML _parsedHTML; private Scriptable _scriptable; - private String _src; + private String _src; + private String _alt; WebImage( ParsedHTML parsedHTML, URL baseURL, Node node ) { @@ -44,6 +45,7 @@ _node = node; _parsedHTML = parsedHTML; _src = NodeUtils.getNodeAttribute( _node, "src" ); + _alt = NodeUtils.getNodeAttribute( _node, "alt" ); } @@ -54,6 +56,11 @@ public String getSource() { return _src; + } + + + public String getAltText() { + return _alt; } Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.75 retrieving revision 1.76 diff -u -r1.75 -r1.76 --- WebResponse.java 21 Aug 2002 19:06:27 -0000 1.75 +++ WebResponse.java 22 Aug 2002 16:19:54 -0000 1.76 @@ -381,11 +381,19 @@ /** - * Returns the image found in the page with the specified src attribute. + * Returns the first image found in the page with the specified src attribute. * @exception SAXException thrown if there is an error parsing the response. **/ public WebImage getImageWithSource( String source ) throws SAXException { return getReceivedPage().getImageWithSource( source ); + } + + + /** + * Returns the first image found in the page with the specified alt attribute. + **/ + public WebImage getImageWithAltText( String altText ) throws SAXException { + return getReceivedPage().getImageWithAltText( altText ); } |
From: Russell G. <rus...@us...> - 2002-08-22 16:19:56
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv21232/doc Modified Files: release_notes.txt Log Message: Added WebImage.getAltText, WebResponse.getImageWithAltText Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.144 retrieving revision 1.145 diff -u -r1.144 -r1.145 --- release_notes.txt 22 Aug 2002 15:48:41 -0000 1.144 +++ release_notes.txt 22 Aug 2002 16:19:53 -0000 1.145 @@ -19,7 +19,9 @@ Additions: 1. ServletUnit now supports HttpServletResponse header methods: setHeader, addHeader, setIntHeader, addIntHeader, setDateHeader, and addDateHeader. - 2. ServletUnit now supports HttpSession.getAttributeNames + 2. ServletUnit now supports HttpSession.getAttributeNames. + 3. WebImage now supports a read-only 'altText' property. + 4. WebResponse and TableCell now support getImageWithAltText to find an image with a specified value in its 'alt' attribute. 21-Aug-2002 |
From: Russell G. <rus...@us...> - 2002-08-22 15:48:50
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv7190/test/com/meterware/servletunit Modified Files: HttpServletResponseTest.java StatefulTest.java StatelessTest.java Log Message: from Michael Reardon: Added support for ServletUnit headers and attribute names Index: HttpServletResponseTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/HttpServletResponseTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- HttpServletResponseTest.java 1 Aug 2002 14:58:59 -0000 1.3 +++ HttpServletResponseTest.java 22 Aug 2002 15:48:41 -0000 1.4 @@ -23,6 +23,8 @@ import java.util.Enumeration; import java.util.Vector; +import java.util.Date; +import java.text.SimpleDateFormat; import javax.servlet.*; import javax.servlet.http.*; @@ -126,6 +128,53 @@ } } + + public void testSingleHeaders() throws Exception { + ServletUnitHttpResponse servletResponse = new ServletUnitHttpResponse(); + servletResponse.setContentType( "text/html" ); + + servletResponse.setHeader( "foo", "bar" ); + String headerValue = servletResponse.getHeaderField( "foo" ); + assertEquals( "header is wrong", "bar", headerValue ); + + servletResponse.setHeader( "foo", "baz" ); + headerValue = servletResponse.getHeaderField( "foo" ); + assertEquals( "header is wrong", "baz", headerValue ); + + servletResponse.setIntHeader( "three", 3 ); + headerValue = servletResponse.getHeaderField( "three" ); + assertEquals( "int header is wrong", "3", headerValue ); + + SimpleDateFormat df = new SimpleDateFormat( "MM/dd/yyyy z" ); + Date d = df.parse( "12/9/1969 GMT" ); + servletResponse.setDateHeader( "date", d.getTime() ); + headerValue = servletResponse.getHeaderField( "date" ); + assertEquals( "date header is wrong", "Tue, 09 Dec 1969 12:00:00 GMT", headerValue ); + } + + + public void testMultipleHeaders() throws Exception { + ServletUnitHttpResponse servletResponse = new ServletUnitHttpResponse(); + servletResponse.setContentType( "text/html" ); + + SimpleDateFormat df = new SimpleDateFormat( "MM/dd/yyyy z" ); + Date date = df.parse( "12/9/1969 GMT" ); + + servletResponse.addHeader( "list", "over-rideme" ); + servletResponse.setHeader( "list", "foo" ); + servletResponse.addIntHeader( "list", 3 ); + servletResponse.addDateHeader( "list", date.getTime() ); + String[] headerList = servletResponse.getHeaderFields( "list" ); + assertEquals( "header is wrong", "foo", headerList[ 0 ] ); + assertEquals( "header is wrong", "3", headerList[ 1 ] ); + assertEquals( "header is wrong", "Tue, 09 Dec 1969 12:00:00 GMT", headerList[ 2 ] ); + + servletResponse.setHeader( "list", "monkeyboy" ); + headerList = servletResponse.getHeaderFields( "list" ); + assertEquals( "setHeader did not replace the list header", headerList.length, 1 ); + assertEquals( "header is wrong", "monkeyboy", headerList[ 0 ] ); + + } } Index: StatefulTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/StatefulTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- StatefulTest.java 18 Jun 2001 20:21:30 -0000 1.2 +++ StatefulTest.java 22 Aug 2002 15:48:41 -0000 1.3 @@ -21,6 +21,8 @@ *******************************************************************************************************************/ import java.io.*; import java.net.HttpURLConnection; +import java.util.Enumeration; + import javax.servlet.ServletException; import javax.servlet.http.*; @@ -118,6 +120,12 @@ ss.setColor( ic.getRequest(), "blue" ); assertEquals( "Color in session", "blue", ss.getColor( ic.getRequest() ) ); + + Enumeration e = ic.getRequest().getSession().getAttributeNames(); + assertNotNull( "No attribute list returned", e ); + assertTrue( "No attribute names in list", e.hasMoreElements() ); + assertEquals( "First attribute name", "color", e.nextElement() ); + assertTrue( "List did not end after one name", !e.hasMoreElements() ); } @@ -199,6 +207,7 @@ protected String getColor( HttpServletRequest req ) throws ServletException { HttpSession session = req.getSession( /* create */ false ); if (session == null) return null; + return (String) session.getAttribute( "color" ); } Index: StatelessTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/StatelessTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- StatelessTest.java 21 May 2002 20:43:31 -0000 1.7 +++ StatelessTest.java 22 Aug 2002 15:48:41 -0000 1.8 @@ -1,46 +1,55 @@ package com.meterware.servletunit; /******************************************************************************************************************** -* $Id$ -* -* Copyright (c) 2000-2001, Russell Gold -* -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -* documentation files (the "Software"), to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and -* to permit persons to whom the Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or substantial portions -* of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO -* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF -* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -* DEALINGS IN THE SOFTWARE. -* -*******************************************************************************************************************/ -import java.io.*; + * $Id$ + * + * 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 + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *******************************************************************************************************************/ +import com.meterware.httpunit.GetMethodWebRequest; +import com.meterware.httpunit.HttpNotFoundException; +import com.meterware.httpunit.PostMethodWebRequest; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; + +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; import java.net.HttpURLConnection; + import javax.servlet.ServletException; -import javax.servlet.http.*; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; -import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; -import com.meterware.httpunit.*; /** * Tests support for stateless HttpServlets. **/ public class StatelessTest extends TestCase { - public static void main(String args[]) { + public static void main( String args[] ) { junit.textui.TestRunner.run( suite() ); } - public static Test suite() { + public static TestSuite suite() { return new TestSuite( StatelessTest.class ); } @@ -53,7 +62,7 @@ public void testNotFound() throws Exception { ServletRunner sr = new ServletRunner(); - WebRequest request = new GetMethodWebRequest( "http://localhost/nothing" ); + WebRequest request = new GetMethodWebRequest( "http://localhost/nothing" ); try { sr.getResponse( request ); fail( "Should have rejected the request" ); @@ -69,7 +78,7 @@ ServletRunner sr = new ServletRunner(); sr.registerServlet( resourceName, AccessCountServlet.class.getName() ); - WebRequest request = new GetMethodWebRequest( "http://localhost/" + resourceName ); + WebRequest request = new GetMethodWebRequest( "http://localhost/" + resourceName ); assertEquals( "First reply", "1", sr.getResponse( request ).getText().trim() ); assertEquals( "Second reply", "2", sr.getResponse( request ).getText().trim() ); } @@ -78,7 +87,7 @@ public void testServletAccessByClassName() throws Exception { ServletRunner sr = new ServletRunner(); - WebRequest request = new GetMethodWebRequest( "http://localhost/servlet/" + SimpleGetServlet.class.getName() ); + WebRequest request = new GetMethodWebRequest( "http://localhost/servlet/" + SimpleGetServlet.class.getName() ); WebResponse response = sr.getResponse( request ); assertNotNull( "No response received", response ); assertEquals( "content type", "text/html", response.getContentType() ); @@ -92,7 +101,7 @@ ServletRunner sr = new ServletRunner(); sr.registerServlet( resourceName, SimpleGetServlet.class.getName() ); - WebRequest request = new GetMethodWebRequest( "http://localhost/" + resourceName ); + WebRequest request = new GetMethodWebRequest( "http://localhost/" + resourceName ); WebResponse response = sr.getResponse( request ); assertNotNull( "No response received", response ); assertEquals( "content type", "text/html", response.getContentType() ); @@ -106,12 +115,16 @@ ServletRunner sr = new ServletRunner(); sr.registerServlet( resourceName, ParameterServlet.class.getName() ); - WebRequest request = new GetMethodWebRequest( "http://localhost/" + resourceName ); + WebRequest request = new GetMethodWebRequest( "http://localhost/" + resourceName ); request.setParameter( "color", "red" ); WebResponse response = sr.getResponse( request ); assertNotNull( "No response received", response ); assertEquals( "content type", "text/plain", response.getContentType() ); assertEquals( "requested resource", "You selected red", response.getText() ); + String[] headers = response.getHeaderFields( "MyHeader" ); + assertEquals( "Number of MyHeaders returned", 2, headers.length ); + assertEquals( "MyHeader #1", "value1", headers[ 0 ] ); + assertEquals( "MyHeader #2", "value2", headers[ 1 ] ); } @@ -121,13 +134,14 @@ ServletRunner sr = new ServletRunner(); sr.registerServlet( resourceName, ParameterServlet.class.getName() ); - WebRequest request = new GetMethodWebRequest( "http://localhost/" + resourceName + "?color=dark+red" ); + WebRequest request = new GetMethodWebRequest( "http://localhost/" + resourceName + "?color=dark+red" ); WebResponse response = sr.getResponse( request ); assertNotNull( "No response received", response ); assertEquals( "content type", "text/plain", response.getContentType() ); assertEquals( "requested resource", "You selected dark red", response.getText() ); } + public void testHeaderRetrieval() throws Exception { ServletRunner sr = new ServletRunner(); sr.registerServlet( "/Parameters", ParameterServlet.class.getName() ); @@ -135,12 +149,12 @@ ServletUnitClient client = sr.newClient(); client.setHeaderField( "Sample", "Value" ); client.setHeaderField( "Request", "Client" ); - WebRequest request = new GetMethodWebRequest( "http://localhost/Parameters?color=dark+red" ); + WebRequest request = new GetMethodWebRequest( "http://localhost/Parameters?color=dark+red" ); request.setHeaderField( "request", "Caller" ); InvocationContext ic = client.newInvocation( request ); assertEquals( "Sample header", "Value", ic.getRequest().getHeader( "sample" ) ); assertEquals( "Request header", "Caller", ic.getRequest().getHeader( "Request" ) ); - } + } public void testSimplePost() throws Exception { @@ -149,7 +163,7 @@ ServletRunner sr = new ServletRunner(); sr.registerServlet( resourceName, ParameterServlet.class.getName() ); - WebRequest request = new PostMethodWebRequest( "http://localhost/" + resourceName ); + WebRequest request = new PostMethodWebRequest( "http://localhost/" + resourceName ); request.setParameter( "color", "red" ); WebResponse response = sr.getResponse( request ); assertNotNull( "No response received", response ); @@ -172,11 +186,12 @@ } - static class SimpleGetServlet extends HttpServlet { + static String RESPONSE_TEXT = "the desired content\r\n"; - protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException,IOException { + + protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException { resp.setContentType( "text/html" ); PrintWriter pw = resp.getWriter(); pw.print( RESPONSE_TEXT ); @@ -186,9 +201,11 @@ static class AccessCountServlet extends HttpServlet { + private int _numAccesses; - protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException,IOException { + + protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException { resp.setContentType( "text/plain" ); PrintWriter pw = resp.getWriter(); pw.print( String.valueOf( ++_numAccesses ) ); @@ -198,16 +215,22 @@ static class ParameterServlet extends HttpServlet { + static String RESPONSE_TEXT = "the desired content\r\n"; - protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException,IOException { + + protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException { resp.setContentType( "text/plain" ); + resp.addHeader( "MyHeader", "value1" ); + resp.addHeader( "MyHeader", "value2" ); + PrintWriter pw = resp.getWriter(); pw.print( "You selected " + req.getParameter( "color" ) ); pw.close(); } - protected void doPost( HttpServletRequest req, HttpServletResponse resp ) throws ServletException,IOException { + + protected void doPost( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException { resp.setContentType( "text/plain" ); PrintWriter pw = resp.getWriter(); pw.print( "You posted " + req.getParameter( "color" ) ); |
From: Russell G. <rus...@us...> - 2002-08-22 15:48:47
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv7190/src/com/meterware/servletunit Modified Files: ServletUnitHttpResponse.java ServletUnitHttpSession.java ServletUnitWebResponse.java Log Message: from Michael Reardon: Added support for ServletUnit headers and attribute names Index: ServletUnitHttpResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpResponse.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- ServletUnitHttpResponse.java 30 Jan 2002 21:21:11 -0000 1.10 +++ ServletUnitHttpResponse.java 22 Aug 2002 15:48:41 -0000 1.11 @@ -32,6 +32,10 @@ import java.util.Hashtable; import java.util.Locale; import java.util.Vector; +import java.util.ArrayList; +import java.util.TimeZone; +import java.util.Date; +import java.text.SimpleDateFormat; import javax.servlet.ServletOutputStream; import javax.servlet.http.Cookie; @@ -40,6 +44,9 @@ class ServletUnitHttpResponse implements HttpServletResponse { + // rfc1123-date is "Sun, 06 Nov 1994 08:49:37 GMT" + private static final String RFC1123_DATE_SPEC = "EEE, dd MMM yyyy hh:mm:ss z"; + /** * @deprecated Use encodeURL(String url) @@ -180,7 +187,11 @@ * value. **/ public void setHeader( String name, String value ) { - _headers.put( name.toUpperCase(), value ); + ArrayList values = new ArrayList(); + values.add( value ); + synchronized (_headers) { + _headers.put( name.toUpperCase(), values ); + } } @@ -192,12 +203,16 @@ * setting its value. **/ public void setIntHeader( String name, int value ) { - throw new RuntimeException( "setIntHeader not implemented" ); + setHeader( name, asHeaderValue( value ) ); + } + + + private String asHeaderValue( int value ) { + return Integer.toString( value ); } /** - * * Adds a field to the response header with the given name and * date-valued field. The date is specified in terms of * milliseconds since the epoch. If the date field had already @@ -206,7 +221,15 @@ * presence of a header before setting its value. **/ public void setDateHeader( String name, long date ) { - throw new RuntimeException( "setDateHeader not implemented" ); + setHeader( name, asDateHeaderValue( date ) ); + } + + + private String asDateHeaderValue( long date ) { + Date value = new Date( date ); + SimpleDateFormat formatter = new SimpleDateFormat( RFC1123_DATE_SPEC ); + formatter.setTimeZone( TimeZone.getTimeZone( "Greenwich Mean Time" ) ); + return formatter.format( value ); } @@ -307,7 +330,15 @@ * Adds a response header with the given name and value. This method allows response headers to have multiple values. **/ public void addHeader( String name, String value ) { - throw new RuntimeException( "addHeader not implemented" ); + synchronized (_headers) { + String key = name.toUpperCase(); + ArrayList values = (ArrayList) _headers.get( key ); + if (values == null) { + values = new ArrayList(); + _headers.put( key, values ); + } + values.add( value ); + } } @@ -315,7 +346,7 @@ * Adds a response header with the given name and value. This method allows response headers to have multiple values. **/ public void addIntHeader( String name, int value ) { - throw new RuntimeException( "addIntHeader not implemented" ); + addHeader( name, asHeaderValue( value ) ); } @@ -323,7 +354,7 @@ * Adds a response header with the given name and value. This method allows response headers to have multiple values. **/ public void addDateHeader( String name, long value ) { - throw new RuntimeException( "addDateHeader not implemented" ); + addHeader( name, asDateHeaderValue( value ) ); } @@ -472,9 +503,35 @@ **/ String getHeaderField( String name ) { if (!_headersComplete) completeHeaders(); - return (String) _headers.get( name.toUpperCase() ); - } + ArrayList values = null; + synchronized (_headers) { + values = (ArrayList) _headers.get( name.toUpperCase() ); + } + + return values == null ? null : (String) values.get( 0 ); + } + + + /** + * Return an array of all the header values associated with the + * specified header name, or an zero-length array if there are no such + * header values. + * + * @param name Header name to look up + */ + public String[] getHeaderFields(String name) { + if (!_headersComplete) completeHeaders(); + ArrayList values = null; + synchronized (_headers) { + values = (ArrayList) _headers.get(name.toUpperCase()); + } + if (values == null) + return (new String[0]); + String results[] = new String[values.size()]; + return ((String[]) values.toArray(results)); + + } //------------------------------------------- private members ------------------------------------ Index: ServletUnitHttpSession.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpSession.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ServletUnitHttpSession.java 26 Nov 2001 14:20:12 -0000 1.5 +++ ServletUnitHttpSession.java 22 Aug 2002 15:48:41 -0000 1.6 @@ -185,7 +185,7 @@ **/ public Enumeration getAttributeNames() { if (_isInvalid) throw new IllegalStateException(); - throw new RuntimeException( "getValueNames not implemented" ); + return _values.keys(); } Index: ServletUnitWebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitWebResponse.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- ServletUnitWebResponse.java 1 Aug 2002 14:58:59 -0000 1.10 +++ ServletUnitWebResponse.java 22 Aug 2002 15:48:41 -0000 1.11 @@ -1,51 +1,38 @@ package com.meterware.servletunit; /******************************************************************************************************************** -* $Id$ -* -* 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 -* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and -* to permit persons to whom the Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or substantial portions -* of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO -* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF -* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -* DEALINGS IN THE SOFTWARE. -* -*******************************************************************************************************************/ + * $Id$ + * + * Copyright (c) 2000-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 + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *******************************************************************************************************************/ +import com.meterware.httpunit.WebResponse; import java.io.ByteArrayInputStream; -import java.io.BufferedReader; -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.io.IOException; - -import java.net.HttpURLConnection; import java.net.URL; -import java.net.URLConnection; - -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.StringTokenizer; import javax.servlet.http.HttpServletResponse; -import com.meterware.httpunit.*; - /** * A response from to a request from the simulated servlet environment. **/ class ServletUnitWebResponse extends WebResponse { - /** * Constructs a response object from a servlet response. * @param target the target frame on which the response will be displayed @@ -89,8 +76,7 @@ public String[] getHeaderFields( String fieldName ) { - String field = getHeaderField( fieldName ); - return field == null ? NO_HEADERS : new String[] { _response.getHeaderField( fieldName ) }; + return _response.getHeaderFields( fieldName ); } @@ -103,8 +89,6 @@ private ServletUnitHttpResponse _response; - - private static final String[] NO_HEADERS = new String[0]; } |
From: Russell G. <rus...@us...> - 2002-08-22 15:48:47
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv7190/doc Modified Files: release_notes.txt Log Message: from Michael Reardon: Added support for ServletUnit headers and attribute names Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.143 retrieving revision 1.144 diff -u -r1.143 -r1.144 --- release_notes.txt 21 Aug 2002 19:06:27 -0000 1.143 +++ release_notes.txt 22 Aug 2002 15:48:41 -0000 1.144 @@ -11,6 +11,16 @@ Revision History: +22-Aug-2002 + +Acknowledgements: + Thanks to Michael Reardon for implementing the ServletUnit header method handling code and session.getAttributeNames + +Additions: + 1. ServletUnit now supports HttpServletResponse header methods: setHeader, addHeader, setIntHeader, addIntHeader, + setDateHeader, and addDateHeader. + 2. ServletUnit now supports HttpSession.getAttributeNames + 21-Aug-2002 Additions: |
From: Russell G. <rus...@us...> - 2002-08-21 20:49:42
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv13178/doc Modified Files: todo.txt Log Message: record next JavaScript steps Index: todo.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/todo.txt,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- todo.txt 20 Jun 2002 15:33:18 -0000 1.27 +++ todo.txt 21 Aug 2002 20:49:39 -0000 1.28 @@ -8,9 +8,14 @@ o Support _new frame tag o Documentation, Documentation +JavaScript priorities: +o Document.write +o JavaScript URLs +o Form.onreset and Form.reset + Possibles: o replace JTidy with a simpler custom parser -o support JavaScript + Low priority: o history on web conversation |
From: Russell G. <rus...@us...> - 2002-08-21 19:06:30
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv25069/test/com/meterware/httpunit/javascript Modified Files: ScriptingTest.java Log Message: Added support for prompt() and confirm() Index: ScriptingTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/ScriptingTest.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- ScriptingTest.java 20 Aug 2002 15:09:28 -0000 1.15 +++ ScriptingTest.java 21 Aug 2002 19:06:27 -0000 1.16 @@ -57,6 +57,47 @@ } + public void testConfirmationDialog() throws Exception { + defineWebPage( "OnCommand", "<a href='NextPage' id='go' onClick='return confirm( \"go on?\" );'>" ); + defineResource( "NextPage", "Got the next page!" ); + + WebConversation wc = new WebConversation(); + WebResponse wr = wc.getResponse( getHostPath() + "/OnCommand.html" ); + wc.setDialogResponder( new DialogAdapter() { + public boolean getConfirmation( String confirmationPrompt ) { + assertEquals( "Confirmation prompt", "go on?", confirmationPrompt ); + return false; + } + } ); + wr.getLinkWithID( "go" ).click(); + assertEquals( "Current page", wr, wc.getCurrentPage() ); + wc.setDialogResponder( new DialogAdapter() ); + wr.getLinkWithID( "go" ).click(); + assertEquals( "Page after confirmation", "Got the next page!", wc.getCurrentPage().getText() ); + } + + + public void testPromptDialog() throws Exception { + defineWebPage( "OnCommand", "<a href='NextPage' id='go' onClick='return \"yes\" == prompt( \"go on?\", \"no\" );'>" ); + defineResource( "NextPage", "Got the next page!" ); + + WebConversation wc = new WebConversation(); + WebResponse wr = wc.getResponse( getHostPath() + "/OnCommand.html" ); + wr.getLinkWithID( "go" ).click(); + assertEquals( "Current page", wr, wc.getCurrentPage() ); + + wc.setDialogResponder( new DialogAdapter() { + public String getUserResponse( String prompt, String defaultResponse ) { + assertEquals( "Confirmation prompt", "go on?", prompt ); + assertEquals( "Default response", "no", defaultResponse ); + return "yes"; + } + } ); + wr.getLinkWithID( "go" ).click(); + assertEquals( "Page after confirmation", "Got the next page!", wc.getCurrentPage().getText() ); + } + + public void testFunctionCallOnLoad() throws Exception { defineResource( "OnCommand.html", "<html><head><script language='JavaScript'>" + "<!-- " + |
From: Russell G. <rus...@us...> - 2002-08-21 19:06:30
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv25069/src/com/meterware/httpunit/javascript Modified Files: JavaScript.java Log Message: Added support for prompt() and confirm() Index: JavaScript.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- JavaScript.java 21 Aug 2002 03:45:01 -0000 1.14 +++ JavaScript.java 21 Aug 2002 19:06:27 -0000 1.15 @@ -228,6 +228,16 @@ } + public boolean jsFunction_confirm( String message ) { + return getDelegate().getConfirmationResponse( message ); + } + + + public String jsFunction_prompt( String message, String defaultResponse ) { + return getDelegate().getUserResponse( message, defaultResponse ); + } + + Scriptable toScriptable( ScriptableDelegate delegate ) { return null; } |
From: Russell G. <rus...@us...> - 2002-08-21 19:06:30
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv25069/src/com/meterware/httpunit Modified Files: WebClient.java WebResponse.java Added Files: DialogAdapter.java DialogResponder.java Log Message: Added support for prompt() and confirm() ***** Error reading new file[Errno 2] No such file or directory: 'DialogAdapter.java' ***** Error reading new file[Errno 2] No such file or directory: 'DialogResponder.java' Index: WebClient.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- WebClient.java 1 Aug 2002 14:58:59 -0000 1.26 +++ WebClient.java 21 Aug 2002 19:06:27 -0000 1.27 @@ -254,6 +254,14 @@ } + /** + * Specifies the object which will respond to all dialogs. + **/ + public void setDialogResponder( DialogResponder responder ) { + _dialogResponder = responder; + } + + //------------------------------------------ protected members ----------------------------------- @@ -333,6 +341,19 @@ } +//------------------------------------------ package members ------------------------------------ + + + boolean getConfirmationResponse( String message ) { + return _dialogResponder.getConfirmation( message ); + } + + + String getUserResponse( String message, String defaultResponse ) { + return _dialogResponder.getUserResponse( message, defaultResponse ); + } + + //------------------------------------------ private members ------------------------------------- @@ -350,6 +371,8 @@ private boolean _exceptionsThrownOnErrorStatus = HttpUnitOptions.getExceptionsThrownOnErrorStatus(); private List _clientListeners = new ArrayList(); + + private DialogResponder _dialogResponder = new DialogAdapter(); /** Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.74 retrieving revision 1.75 diff -u -r1.74 -r1.75 --- WebResponse.java 20 Aug 2002 15:09:28 -0000 1.74 +++ WebResponse.java 21 Aug 2002 19:06:27 -0000 1.75 @@ -507,6 +507,16 @@ } + public boolean getConfirmationResponse( String message ) { + return _client.getConfirmationResponse( message ); + } + + + public String getUserResponse( String prompt, String defaultResponse ) { + return _client.getUserResponse( prompt, defaultResponse ); + } + + public HTMLPage.Scriptable getDocument() throws SAXException { return getReceivedPage().getScriptableObject(); } |
From: Russell G. <rus...@us...> - 2002-08-21 19:06:30
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv25069/doc Modified Files: Javascript-support.html release_notes.txt Log Message: Added support for prompt() and confirm() Index: Javascript-support.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/Javascript-support.html,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- Javascript-support.html 21 Aug 2002 03:45:01 -0000 1.11 +++ Javascript-support.html 21 Aug 2002 19:06:27 -0000 1.12 @@ -20,7 +20,9 @@ </ul> <h4>methods</h4> <ul> -<li>alert() - queues up an alert message, accessible via WebResponse.getNextAlert() or popNextAlert()</li> +<li>alert() - queues up an alert message, accessible via WebResponse.getNextAlert() or popNextAlert()</li> +<li>confirm() - invokes a callback supplied via WebClient.setDialogResponder to return the user's response</li> +<li>prompt() - invokes a callback supplied via WebClient.setDialogResponder to return the user's response</li> </ul> <h3>Document</h3> Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.142 retrieving revision 1.143 diff -u -r1.142 -r1.143 --- release_notes.txt 21 Aug 2002 03:45:01 -0000 1.142 +++ release_notes.txt 21 Aug 2002 19:06:27 -0000 1.143 @@ -11,6 +11,14 @@ Revision History: +21-Aug-2002 + +Additions: + 1. JavaScript - Window.confirm is now supported. By default, it always returns true. Users may change this by supplying an + implementation of DialogResponder to the WebClient. + 2. JavScript - Window.prompt is now supported. By default, it always returns the default value. Users may change this by supplying an + implementation of DialogResponder to the WebClient. + 20-Aug-2002 Problems fixed: |
From: Russell G. <rus...@us...> - 2002-08-21 03:45:04
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv2259/doc Modified Files: Javascript-support.html release_notes.txt Log Message: Added JavaScript support for Radio buttons Index: Javascript-support.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/Javascript-support.html,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- Javascript-support.html 20 Aug 2002 19:39:20 -0000 1.10 +++ Javascript-support.html 21 Aug 2002 03:45:01 -0000 1.11 @@ -129,6 +129,18 @@ </ul> <h4>events</h4> <ul> +<li>onClick - invoked when the state of the control is changed via form.setParameter or form.removeParameter</li> +</ul> + +<h3>Radio</h3> +<h4>properties</h4> +<ul> +<li>checked - read/write - the state of the radio button</li> +<li>defaultChecked - read-only - the default state of the radio button</li> +<li>value - read/write - the value transmitted if the control is checked</li> +</ul> +<h4>events</h4> +<ul> <li>onClick - invoked when the state of the control is changed via form.setParameter</li> </ul> Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.141 retrieving revision 1.142 diff -u -r1.141 -r1.142 --- release_notes.txt 20 Aug 2002 19:39:20 -0000 1.141 +++ release_notes.txt 21 Aug 2002 03:45:01 -0000 1.142 @@ -4,10 +4,10 @@ 1. The "_new" and "_empty" frame targets are not handled correctly 2. The "accept-charset" attribute for forms is ignored; the page content character set is used to encode any response. This behavior matches that currently used by IE and Navigator. - 3. The regression test "pseudo-server" does not appear to run properly under Unix. Limitations: 1. JDK 1.2 or higher is required + 2. JavaScript support does not include document.write and some DOM properties Revision History: @@ -16,9 +16,12 @@ Problems fixed: 1. JavaScript - HTML comments prevented JavaScript from working 2. JavaScript - Errors were reported if Rhino was not present in the classpath + 3. Fixed handling of error statuses when information is still sent on input stream Additions: 1. JavaScript - Added Checkbox.value property, along with Checkbox.defaultChecked and Input.name + 2. JavaScript - Added Radio.value, Radio.checked, and Radio.defaultChecked properties + 3. JavaScript - Added Radio.onClick event support 19-Aug-2002 |
From: Russell G. <rus...@us...> - 2002-08-21 03:45:04
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv2259/src/com/meterware/httpunit/javascript Modified Files: JavaScript.java Log Message: Added JavaScript support for Radio buttons Index: JavaScript.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- JavaScript.java 20 Aug 2002 15:09:28 -0000 1.13 +++ JavaScript.java 21 Aug 2002 03:45:01 -0000 1.14 @@ -140,9 +140,10 @@ private Object convertIfNeeded( final Object property ) { if (property == null) return NOT_FOUND; - if (!(property instanceof ScriptableDelegate)) return property; try { + if (property instanceof ScriptableDelegate[]) return toScriptable( (ScriptableDelegate[]) property ); + if (!(property instanceof ScriptableDelegate)) return property; return toScriptable( (ScriptableDelegate) property ); } catch (PropertyException e) { throw new RuntimeException( e.toString() ); @@ -156,6 +157,16 @@ } + private Object toScriptable( ScriptableDelegate[] list ) + throws PropertyException, NotAFunctionException, JavaScriptException, SAXException { + Object[] delegates = new Object[ list.length ]; + for (int i = 0; i < delegates.length; i++) { + delegates[i] = toScriptable( list[i] ); + } + return Context.getCurrentContext().newArray( this, delegates ); + } + + public void put( String propertyName, Scriptable scriptable, Object value ) { if (_scriptable == null || _scriptable.get( propertyName ) == null) { super.put( propertyName, scriptable, value ); @@ -412,7 +423,7 @@ private void initializeControls() throws PropertyException, NotAFunctionException, JavaScriptException, SAXException { - ScriptableDelegate scriptables[] = getDelegate().getControls(); + ScriptableDelegate scriptables[] = getDelegate().getElementDelegates(); Control[] controls = new Control[ scriptables.length ]; for (int i = 0; i < controls.length; i++) { controls[ i ] = (Control) toScriptable( scriptables[ i ] ); |
From: Russell G. <rus...@us...> - 2002-08-21 03:45:04
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv2259/test/com/meterware/httpunit/javascript Modified Files: FormScriptingTest.java Log Message: Added JavaScript support for Radio buttons Index: FormScriptingTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/FormScriptingTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- FormScriptingTest.java 20 Aug 2002 19:39:20 -0000 1.4 +++ FormScriptingTest.java 21 Aug 2002 03:45:01 -0000 1.5 @@ -195,6 +195,7 @@ WebConversation wc = new WebConversation(); WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); WebForm form = response.getFormWithName( "realform" ); + response.getLinkWithName( "report" ).mouseOver(); verifyCheckbox( response, /* default */ false, /* checked */ false, /* value */ "good" ); assertEquals( "initial parameter value", null, form.getParameterValue( "ready" ) ); @@ -204,13 +205,35 @@ assertEquals( "final parameter value", null, form.getParameterValue( "ready" ) ); response.getLinkWithName( "change" ).mouseOver(); assertEquals( "final parameter value", null, form.getParameterValue( "ready" ) ); + response.getLinkWithName( "report" ).mouseOver(); verifyCheckbox( response, /* default */ false, /* checked */ false, /* value */ "waiting" ); form.setParameter( "ready", "waiting" ); } + public void testIndexedCheckboxProperties() throws Exception { + defineResource( "OnCommand.html", "<html><head><script language='JavaScript'>" + + "function viewCheckbox( checkbox ) { \n" + + " alert( 'checkbox ' + checkbox.name + ' default = ' + checkbox.defaultChecked )\n;" + + " alert( 'checkbox ' + checkbox.name + ' checked = ' + checkbox.checked )\n;" + + " alert( 'checkbox ' + checkbox.name + ' value = ' + checkbox.value )\n;" + + "}\n" + + "</script></head>" + + "<body onload='viewCheckbox( document.realform.ready[0] ); viewCheckbox( document.realform.ready[1] );'>" + + "<form name='realform'>" + + "<input type='checkbox' name='ready' value='good' checked>" + + "<input type='checkbox' name='ready' value='bad'>" + + "</form>" + + "</body></html>" ); + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + WebForm form = response.getFormWithName( "realform" ); + verifyCheckbox( response, /* default */ true, /* checked */ true, /* value */ "good" ); + verifyCheckbox( response, /* default */ false, /* checked */ false, /* value */ "bad" ); + } + + private void verifyCheckbox( WebResponse response, boolean defaultChecked, boolean checked, String value ) throws SAXException { - response.getLinkWithName( "report" ).mouseOver(); assertEquals( "Message " + 1 + "-1", "checkbox ready default = " + defaultChecked, response.popNextAlert() ); assertEquals( "Message " + 1 + "-2", "checkbox ready checked = " + checked, response.popNextAlert() ); assertEquals( "Message " + 1 + "-3", "checkbox ready value = " + value, response.popNextAlert() ); @@ -240,6 +263,66 @@ assertEquals( "Alert after change", "color-blue is now false", response.popNextAlert() ); assertEquals( "Changed state", null, form.getParameterValue( "color" ) ); + response.getLinks()[ 0 ].click(); + assertEquals( "Final state", "blue", form.getParameterValue( "color" ) ); + assertEquals( "Alert message after JavaScript change", null, response.getNextAlert() ); + } + + + public void testIndexedRadioProperties() throws Exception { + defineResource( "OnCommand.html", "<html><head><script language='JavaScript'>" + + "function viewRadio( radio ) { \n" + + " alert( 'radio ' + radio.name + ' default = ' + radio.defaultChecked )\n;" + + " alert( 'radio ' + radio.name + ' checked = ' + radio.checked )\n;" + + " alert( 'radio ' + radio.name + ' value = ' + radio.value )\n;" + + "}\n" + + "</script></head>" + + "<body onload='viewRadio( document.realform.ready[0] ); viewRadio( document.realform.ready[1] );'>" + + "<form name='realform'>" + + "<input type='radio' name='ready' value='good' checked>" + + "<input type='radio' name='ready' value='bad'>" + + "</form>" + + "</body></html>" ); + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + WebForm form = response.getFormWithName( "realform" ); + verifyRadio( response, /* default */ true, /* checked */ true, /* value */ "good" ); + verifyRadio( response, /* default */ false, /* checked */ false, /* value */ "bad" ); + } + + + private void verifyRadio( WebResponse response, boolean defaultChecked, boolean checked, String value ) throws SAXException { + assertEquals( "Message " + 1 + "-1", "radio ready default = " + defaultChecked, response.popNextAlert() ); + assertEquals( "Message " + 1 + "-2", "radio ready checked = " + checked, response.popNextAlert() ); + assertEquals( "Message " + 1 + "-3", "radio ready value = " + value, response.popNextAlert() ); + } + + + public void testRadioOnClickEvent() throws Exception { + defineResource( "OnCommand.html", "<html><head></head>" + + "<body>" + + "<form name='the_form'>" + + " <input type='radio' name='color' value='blue' " + + " onClick='alert( \"color is now blue\" );'>" + + " <input type='radio' name='color' value='red' checked" + + " onClick='alert( \"color is now red\" );'>" + + "</form>" + + "<a href='#' onClick='document.the_form.color[1].checked=false; document.the_form.color[0].checked=true;'>blue</a>" + + "</body></html>" ); + WebConversation wc = new WebConversation(); + WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + WebForm form = response.getFormWithName( "the_form" ); + assertEquals( "Initial state", "red", form.getParameterValue( "color" ) ); + + assertEquals( "Alert message before change", null, response.getNextAlert() ); + form.setParameter( "color", "red" ); + assertEquals( "Alert message w/o change", null, response.getNextAlert() ); + form.setParameter( "color", "blue" ); + assertEquals( "Alert after change", "color is now blue", response.popNextAlert() ); + form.setParameter( "color", "red" ); + assertEquals( "Alert after change", "color is now red", response.popNextAlert() ); + + assertEquals( "Changed state", "red", form.getParameterValue( "color" ) ); response.getLinks()[ 0 ].click(); assertEquals( "Final state", "blue", form.getParameterValue( "color" ) ); assertEquals( "Alert message after JavaScript change", null, response.getNextAlert() ); |
From: Russell G. <rus...@us...> - 2002-08-21 03:45:04
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv2259/src/com/meterware/httpunit Modified Files: FormControl.java WebForm.java Log Message: Added JavaScript support for Radio buttons Index: FormControl.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- FormControl.java 20 Aug 2002 19:39:20 -0000 1.19 +++ FormControl.java 21 Aug 2002 03:45:01 -0000 1.20 @@ -100,6 +100,11 @@ abstract String[] getValues(); + Object getDelegate() { + return getScriptableObject(); + } + + /** * Returns a scriptable object which can act as a proxy for this control. */ @@ -325,10 +330,17 @@ private final boolean _isCheckedDefault; + protected FormControl.Scriptable newScriptable() { + return new Scriptable(); + } + + class Scriptable extends FormControl.Scriptable { public Object get( String propertyName ) { - if (propertyName.equalsIgnoreCase( "checked" )) { + if (propertyName.equalsIgnoreCase( "value" )) { + return getQueryValue(); + } else if (propertyName.equalsIgnoreCase( "checked" )) { return isChecked() ? Boolean.TRUE : Boolean.FALSE; } else if (propertyName.equalsIgnoreCase( "defaultchecked" )) { return _isCheckedDefault ? Boolean.TRUE : Boolean.FALSE; @@ -445,6 +457,7 @@ public RadioGroupFormControl() { } + void addRadioButton( RadioButtonFormControl control ) { _buttonList.add( control ); _buttons = null; @@ -473,6 +486,15 @@ } + Object getDelegate() { + ScriptableDelegate[] delegates = new ScriptableDelegate[ getButtons().length ]; + for (int i = 0; i < delegates.length; i++) { + delegates[i] = getButtons()[i].getScriptableObject(); + } + return delegates; + } + + void addValues( ParameterProcessor processor, String characterSet ) throws IOException { for (int i = 0; i < getButtons().length; i++) getButtons()[i].addValues( processor, characterSet ); } @@ -495,10 +517,12 @@ } if (matchingButtonIndex <0) throw new IllegalParameterValueException( getButtons()[0].getName(), (String) values.get(0), getAllowedValues() ); + boolean wasChecked = getButtons()[ matchingButtonIndex ].isChecked(); for (int i = 0; i < getButtons().length; i++) { if (!getButtons()[i].isReadOnly()) getButtons()[i].setChecked( i == matchingButtonIndex ); } values.remove( getButtons()[ matchingButtonIndex ].getQueryValue() ); + if (!wasChecked) getButtons()[ matchingButtonIndex ].sendOnClickEvent(); } @@ -539,32 +563,6 @@ setChecked( values.contains( getQueryValue() ) ); if (isChecked()) values.remove( getQueryValue() ); if (isChecked() != wasChecked) sendOnClickEvent(); - } - - - protected FormControl.Scriptable newScriptable() { - return new Scriptable(); - } - - - class Scriptable extends BooleanFormControl.Scriptable { - - public Object get( String propertyName ) { - if (propertyName.equalsIgnoreCase( "value" )) { - return getQueryValue(); - } else { - return super.get( propertyName ); - } - } - - - public void set( String propertyName, Object value ) { - if (propertyName.equalsIgnoreCase( "checked" )) { - setChecked( value instanceof Boolean && ((Boolean) value).booleanValue() ); - } else { - super.set( propertyName, value ); - } - } } Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.58 retrieving revision 1.59 diff -u -r1.58 -r1.59 --- WebForm.java 19 Aug 2002 18:52:26 -0000 1.58 +++ WebForm.java 21 Aug 2002 03:45:01 -0000 1.59 @@ -319,7 +319,7 @@ * Resets all parameters to their initial values. */ public void reset() { - FormControl controls[] = getFormControls(); + FormControl[] controls = getFormControls(); for (int i = 0; i < controls.length; i++) { controls[i].reset(); } @@ -471,11 +471,16 @@ public void setParameterValue( String name, String value ) { - getParameter( name ).getScriptableObject().set( "value", value ); + final Object scriptableObject = getParameter( name ).getScriptableObject(); + if (scriptableObject instanceof ScriptableDelegate) { + ((ScriptableDelegate) scriptableObject).set( "value", value ); + } else if (scriptableObject instanceof ScriptableDelegate[]) { + ((ScriptableDelegate[]) scriptableObject)[0].set( "value", value ); + } } - public ScriptableDelegate[] getControls() { + public ScriptableDelegate[] getElementDelegates() { FormControl[] controls = getFormControls(); ScriptableDelegate[] result = new ScriptableDelegate[ controls.length ]; for (int i = 0; i < result.length; i++) { @@ -649,8 +654,19 @@ } - ScriptableDelegate getScriptableObject() { - return getControls()[0].getScriptableObject(); + Object getScriptableObject() { + if (getControls().length == 1) { + return getControls()[0].getDelegate(); + } else { + ArrayList list = new ArrayList(); + for (int i = 0; i < _controls.length; i++) { + FormControl control = _controls[i]; + if (control instanceof CheckboxFormControl) { + list.add( control.getScriptableObject() ); + } + } + return list.toArray( new ScriptableDelegate[ list.size() ] ); + } } |
From: Russell G. <rus...@us...> - 2002-08-21 03:44:29
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv2192/src/com/meterware/httpunit Modified Files: HttpWebResponse.java Log Message: handle error status return across platforms Index: HttpWebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpWebResponse.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- HttpWebResponse.java 1 Aug 2002 14:58:59 -0000 1.24 +++ HttpWebResponse.java 21 Aug 2002 03:44:26 -0000 1.25 @@ -54,11 +54,21 @@ /** make sure that any IO exception for HTML received page happens here, not later. **/ if (_responseCode < HttpURLConnection.HTTP_BAD_REQUEST || !throwExceptionOnError) { - InputStream stream = (_responseCode < HttpURLConnection.HTTP_BAD_REQUEST) ? connection.getInputStream() - : ((HttpURLConnection) connection).getErrorStream(); - defineRawInputStream( new BufferedInputStream( stream ) ); + defineRawInputStream( new BufferedInputStream( getInputStream( connection ) ) ); if (getContentType().startsWith( "text" )) loadResponseText(); } + } + + + private InputStream getInputStream( URLConnection connection ) throws IOException { + return isResponseOnErrorStream( connection ) + ? ((HttpURLConnection) connection).getErrorStream() + : connection.getInputStream(); + } + + + private boolean isResponseOnErrorStream( URLConnection connection ) { + return _responseCode >= HttpURLConnection.HTTP_BAD_REQUEST && ((HttpURLConnection) connection).getErrorStream() != null; } |
From: Russell G. <rus...@us...> - 2002-08-20 19:39:23
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv26478/doc Modified Files: Javascript-support.html release_notes.txt Log Message: Added properties for Checkbox Index: Javascript-support.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/Javascript-support.html,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- Javascript-support.html 20 Aug 2002 15:09:27 -0000 1.9 +++ Javascript-support.html 20 Aug 2002 19:39:20 -0000 1.10 @@ -71,6 +71,7 @@ <h4>properties</h4> <ul> <li>form - read-only - the form containing the input</li> +<li>name - read-only - the name of the control</li> </ul> <h4>methods</h4> <ul> @@ -122,7 +123,13 @@ <h3>Checkbox</h3> <h4>properties</h4> <ul> -<li>checked - read/write - the state of the checkbox</li> +<li>checked - read/write - the state of the checkbox</li> +<li>defaultChecked - read-only - the default state of the checkbox</li> +<li>value - read/write - the value transmitted if the control is checked</li> +</ul> +<h4>events</h4> +<ul> +<li>onClick - invoked when the state of the control is changed via form.setParameter</li> </ul> <h3>Select</h3> Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.140 retrieving revision 1.141 diff -u -r1.140 -r1.141 --- release_notes.txt 20 Aug 2002 15:09:27 -0000 1.140 +++ release_notes.txt 20 Aug 2002 19:39:20 -0000 1.141 @@ -14,8 +14,11 @@ 20-Aug-2002 Problems fixed: - 1. JavaScript - HTML comments were not supported + 1. JavaScript - HTML comments prevented JavaScript from working 2. JavaScript - Errors were reported if Rhino was not present in the classpath + +Additions: + 1. JavaScript - Added Checkbox.value property, along with Checkbox.defaultChecked and Input.name 19-Aug-2002 |
From: Russell G. <rus...@us...> - 2002-08-20 19:39:23
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv26478/src/com/meterware/httpunit Modified Files: FormControl.java Log Message: Added properties for Checkbox Index: FormControl.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- FormControl.java 19 Aug 2002 18:52:25 -0000 1.18 +++ FormControl.java 20 Aug 2002 19:39:20 -0000 1.19 @@ -45,10 +45,13 @@ private String _name; private final String _id; - private final String _valueAttribute; + private String _valueAttribute; private final boolean _readOnly; private final boolean _disabled; - private Scriptable _scriptable; + private final String _onChangeEvent; + private final String _onClickEvent; + + private Scriptable _scriptable; FormControl() { @@ -57,6 +60,8 @@ _valueAttribute = ""; _readOnly = false; _disabled = false; + _onChangeEvent = ""; + _onClickEvent = ""; } @@ -66,6 +71,8 @@ _valueAttribute = NodeUtils.getNodeAttribute( node, "value" ); _readOnly = NodeUtils.isNodeAttributePresent( node, "readonly" ); _disabled = NodeUtils.isNodeAttributePresent( node, "disabled" ); + _onChangeEvent = NodeUtils.getNodeAttribute( node, "onchange" ); + _onClickEvent = NodeUtils.getNodeAttribute( node, "onclick" ); } @@ -96,7 +103,7 @@ /** * Returns a scriptable object which can act as a proxy for this control. */ - public ScriptableDelegate getScriptableObject() { + ScriptableDelegate getScriptableObject() { if (_scriptable == null) _scriptable = newScriptable(); return _scriptable; } @@ -113,7 +120,7 @@ /** * Returns the list of values displayed by this control, if any. **/ - public String[] getDisplayedOptions() { + String[] getDisplayedOptions() { return NO_VALUE; } @@ -121,7 +128,7 @@ /** * Returns true if this control is read-only. **/ - public boolean isReadOnly() { + boolean isReadOnly() { return _readOnly; } @@ -129,7 +136,7 @@ /** * Returns true if this control is disabled, meaning that it will not send a value to the server as part of a request. **/ - public boolean isDisabled() { + boolean isDisabled() { return _disabled; } @@ -137,15 +144,15 @@ /** * Returns true if this control accepts free-form text. **/ - public boolean isTextControl() { + boolean isTextControl() { return false; } /** - * Returns true if only one control of this kind can have a value. This is true for radio buttons. + * Returns true if only one control of this kind with this name can have a value. This is true for radio buttons. **/ - public boolean isExclusive() { + boolean isExclusive() { return false; } @@ -153,7 +160,7 @@ /** * Returns true if a single control can have multiple values. **/ - public boolean isMultiValued() { + boolean isMultiValued() { return false; } @@ -161,7 +168,7 @@ /** * Returns true if this control accepts a file for upload. **/ - public boolean isFileParameter() { + boolean isFileParameter() { return false; } @@ -205,6 +212,22 @@ /** + * Performs the 'onChange' event defined for this control. + */ + protected void sendOnChangeEvent() { + if (_onChangeEvent.length() > 0) getScriptableObject().doEvent( _onChangeEvent ); + } + + + /** + * Performs the 'onClick' event defined for this control. + */ + protected void sendOnClickEvent() { + if (_onClickEvent.length() > 0) getScriptableObject().doEvent( _onClickEvent ); + } + + + /** * Creates and returns a scriptable object for this control. Subclasses should override this if they use a different * implementation of Scriptable. */ @@ -272,6 +295,23 @@ class Scriptable extends ScriptableDelegate { + + public Object get( String propertyName ) { + if (propertyName.equalsIgnoreCase( "name" )) { + return getName(); + } else { + return super.get( propertyName ); + } + } + + + public void set( String propertyName, Object value ) { + if (propertyName.equalsIgnoreCase( "value" )) { + _valueAttribute = value.toString(); + } else { + super.set( propertyName, value ); + } + } } } @@ -285,7 +325,27 @@ private final boolean _isCheckedDefault; + class Scriptable extends FormControl.Scriptable { + public Object get( String propertyName ) { + if (propertyName.equalsIgnoreCase( "checked" )) { + return isChecked() ? Boolean.TRUE : Boolean.FALSE; + } else if (propertyName.equalsIgnoreCase( "defaultchecked" )) { + return _isCheckedDefault ? Boolean.TRUE : Boolean.FALSE; + } else { + return super.get( propertyName ); + } + } + + + public void set( String propertyName, Object value ) { + if (propertyName.equalsIgnoreCase( "checked" )) { + setChecked( value instanceof Boolean && ((Boolean) value).booleanValue() ); + } else { + super.set( propertyName, value ); + } + } + } public BooleanFormControl( Node node ) { super( node ); @@ -474,9 +534,11 @@ void claimUniqueValue( List values ) { + boolean wasChecked = isChecked(); if (isValueRequired()) return; setChecked( values.contains( getQueryValue() ) ); if (isChecked()) values.remove( getQueryValue() ); + if (isChecked() != wasChecked) sendOnClickEvent(); } @@ -485,11 +547,11 @@ } - class Scriptable extends FormControl.Scriptable { + class Scriptable extends BooleanFormControl.Scriptable { public Object get( String propertyName ) { - if (propertyName.equalsIgnoreCase( "checked" )) { - return isChecked() ? Boolean.TRUE : Boolean.FALSE; + if (propertyName.equalsIgnoreCase( "value" )) { + return getQueryValue(); } else { return super.get( propertyName ); } @@ -535,29 +597,10 @@ } -abstract class ScalarFormControl extends FormControl { - - private final String _onChangeEvent; - - - public ScalarFormControl( Node node ) { - super( node ); - _onChangeEvent = NodeUtils.getNodeAttribute( node, "onchange" ); - } - - - protected void sendOnChangeEvent() { - if (_onChangeEvent.length() > 0) getScriptableObject().doEvent( _onChangeEvent ); - } - -} - - -class TextFormControl extends ScalarFormControl { +class TextFormControl extends FormControl { private String[] _value = new String[1]; private String[] _defaultValue; - private Scriptable _scriptable; public TextFormControl( Node node, String defaultValue ) { @@ -583,9 +626,8 @@ } - public ScriptableDelegate getScriptableObject() { - if (_scriptable == null) _scriptable = new Scriptable(); - return _scriptable; + protected FormControl.Scriptable newScriptable() { + return new Scriptable(); } @@ -687,7 +729,7 @@ } -class FileSubmitFormControl extends ScalarFormControl { +class FileSubmitFormControl extends FormControl { private UploadFileSpec _fileToUpload; @@ -734,13 +776,12 @@ } -class SelectionFormControl extends ScalarFormControl { +class SelectionFormControl extends FormControl { private final boolean _multiSelect; private final boolean _listBox; private Options _selectionOptions; - private Scriptable _scriptable; SelectionFormControl( Node node ) { @@ -801,9 +842,8 @@ } - public ScriptableDelegate getScriptableObject() { - if (_scriptable == null) _scriptable = new Scriptable(); - return _scriptable; + protected FormControl.Scriptable newScriptable() { + return new Scriptable(); } |