httpunit-commit Mailing List for httpunit (Page 59)
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-02 16:26:19
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript
In directory usw-pr-cvs1:/tmp/cvs-serv27406/test/com/meterware/httpunit/javascript
Modified Files:
ScriptingTest.java
Log Message:
add document.links and link.onMouseOver support
Index: ScriptingTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/ScriptingTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ScriptingTest.java 1 Aug 2002 20:23:16 -0000 1.2
+++ ScriptingTest.java 2 Aug 2002 16:26:15 -0000 1.3
@@ -23,6 +23,7 @@
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebResponse;
import com.meterware.httpunit.WebForm;
+import com.meterware.httpunit.WebLink;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
@@ -108,6 +109,31 @@
}
+ public void testDocumentFindLinks() throws Exception {
+ defineResource( "OnCommand.html", "<html><head><script language='JavaScript'>" +
+ "function getFound( object ) {" +
+ " return (object == null) ? \"did not find \" : \"found \";" +
+ " }" +
+ "function viewLinks() { " +
+ " alert( \"found \" + document.links.length + \" link(s)\" );" +
+ " alert( getFound( document.reallink ) + \"link 'reallink'\" );" +
+ " alert( getFound( document.nolink ) + \"link 'nolink'\" );" +
+ "}" +
+ "</script></head>" +
+ "<body onLoad='viewLinks()'>" +
+ "<a href='something' name='reallink'>first</a>" +
+ "<a href='else'>second</a>" +
+ "</body></html>" );
+ WebConversation wc = new WebConversation();
+ WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" );
+ JavaScript.run( response );
+ 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() );
+ }
+
+
public void testSetFormFieldValue() throws Exception {
defineResource( "OnCommand.html", "<html><head></head>" +
"<body onLoad=\"document.realform.color.value='green'\">" +
@@ -118,6 +144,23 @@
JavaScript.run( response );
WebForm form = response.getFormWithName( "realform" );
assertEquals( "color parameter value", "green", form.getParameterValue( "color" ) );
+ }
+
+
+ public void testLinkMouseOverEvent() throws Exception {
+ defineResource( "OnCommand.html", "<html><head></head>" +
+ "<body>" +
+ "<form name='realform'><input name='color' value='blue'></form>" +
+ "<a href='#' onMouseOver=\"document.realform.color.value='green'\">green</a>" +
+ "</body></html>" );
+ WebConversation wc = new WebConversation();
+ WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" );
+ JavaScript.run( response );
+ WebForm form = response.getFormWithName( "realform" );
+ WebLink link = response.getLinks()[0];
+ assertEquals( "initial parameter value", "blue", form.getParameterValue( "color" ) );
+ link.mouseOver();
+ assertEquals( "changed parameter value", "green", form.getParameterValue( "color" ) );
}
|
|
From: Russell G. <rus...@us...> - 2002-08-02 16:26:19
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript
In directory usw-pr-cvs1:/tmp/cvs-serv27406/src/com/meterware/httpunit/javascript
Modified Files:
JavaScript.java
Log Message:
add document.links and link.onMouseOver support
Index: JavaScript.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JavaScript.java 1 Aug 2002 20:23:16 -0000 1.2
+++ JavaScript.java 2 Aug 2002 16:26:15 -0000 1.3
@@ -23,8 +23,10 @@
import com.meterware.httpunit.ScriptEngine;
import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.WebResponse;
+import com.meterware.httpunit.WebLink;
import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
import org.mozilla.javascript.ClassDefinitionException;
import org.mozilla.javascript.Context;
@@ -51,11 +53,13 @@
Scriptable scope = context.initStandardObjects( null );
ScriptableObject.defineClass( scope, Window.class );
ScriptableObject.defineClass( scope, Document.class );
+ ScriptableObject.defineClass( scope, Link.class );
ScriptableObject.defineClass( scope, Form.class );
ScriptableObject.defineClass( scope, Control.class );
+ ScriptableObject.defineClass( scope, Link.class );
Window w = (Window) context.newObject( scope, "Window" );
- w.initialize( response.getScriptableObject() );
+ w.initialize( null, response.getScriptableObject() );
}
@@ -73,7 +77,7 @@
}
- void initialize( com.meterware.httpunit.ScriptableObject scriptable )
+ void initialize( JavaScriptEngine parent, com.meterware.httpunit.ScriptableObject scriptable )
throws JavaScriptException, NotAFunctionException, PropertyException, SAXException {
_scriptable = scriptable;
_scriptable.setScriptEngine( this );
@@ -120,9 +124,12 @@
/**
* Converts a scriptable delegate obtained from a subobject into the appropriate Rhino-compatible Scriptable.
+ * This default implementation throws an exception.
**/
- abstract Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate )
- throws PropertyException, NotAFunctionException, JavaScriptException, SAXException;
+ Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate )
+ throws PropertyException, NotAFunctionException, JavaScriptException, SAXException {
+ throw new UnsupportedOperationException();
+ }
}
@@ -152,11 +159,11 @@
}
- void initialize( com.meterware.httpunit.ScriptableObject scriptable )
+ void initialize( JavaScriptEngine parent, com.meterware.httpunit.ScriptableObject scriptable )
throws JavaScriptException, NotAFunctionException, PropertyException, SAXException {
- super.initialize( scriptable );
+ super.initialize( this, scriptable );
_document = (Document) Context.getCurrentContext().newObject( this, "Document" );
- _document.initialize( getDelegate().getDocument() );
+ _document.initialize( this, getDelegate().getDocument() );
getDelegate().load();
}
@@ -181,6 +188,7 @@
static public class Document extends JavaScriptEngine {
private Scriptable _forms;
+ private Scriptable _links;
public String getClassName() {
@@ -188,9 +196,10 @@
}
- void initialize( com.meterware.httpunit.ScriptableObject scriptable )
+ void initialize( JavaScriptEngine parent, com.meterware.httpunit.ScriptableObject scriptable )
throws JavaScriptException, NotAFunctionException, PropertyException, SAXException {
- super.initialize( scriptable );
+ super.initialize( this, scriptable );
+ initializeLinks();
initializeForms();
}
@@ -200,11 +209,26 @@
}
+ public Scriptable jsGet_links() {
+ return _links;
+ }
+
+
public Scriptable jsGet_forms() {
return _forms;
}
+ private void initializeLinks() throws PropertyException, NotAFunctionException, JavaScriptException, SAXException {
+ WebLink.Scriptable scriptables[] = getDelegate().getLinks();
+ Link[] links = new Link[ scriptables.length ];
+ for (int i = 0; i < links.length; i++) {
+ links[ i ] = (Link) toScriptable( scriptables[ i ] );
+ }
+ _links = Context.getCurrentContext().newArray( this, links );
+ }
+
+
private void initializeForms() throws PropertyException, NotAFunctionException, JavaScriptException, SAXException {
WebForm.Scriptable scriptables[] = getDelegate().getForms();
Form[] forms = new Form[ scriptables.length ];
@@ -217,9 +241,20 @@
Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate )
throws PropertyException, JavaScriptException, NotAFunctionException, SAXException {
- final Form form = (Form) Context.getCurrentContext().newObject( this, "Form" );
- form.initialize( delegate );
- return form;
+ JavaScriptEngine element = (JavaScriptEngine) Context.getCurrentContext().newObject( this, getScriptableClassName( delegate ) );
+ element.initialize( this, delegate );
+ return element;
+ }
+
+
+ private String getScriptableClassName( com.meterware.httpunit.ScriptableObject delegate ) {
+ if (delegate instanceof WebForm.Scriptable) {
+ return "Form";
+ } else if (delegate instanceof WebLink.Scriptable) {
+ return "Link";
+ } else {
+ throw new IllegalArgumentException( "Unknown ScriptableObject class: " + delegate.getClass() );
+ }
}
@@ -230,7 +265,39 @@
}
- static public class Form extends JavaScriptEngine {
+ abstract static public class HTMLElement extends JavaScriptEngine {
+
+ private Document _document;
+
+
+ public Document jsGet_document() {
+ return _document;
+ }
+
+
+ void initialize( JavaScriptEngine parent, com.meterware.httpunit.ScriptableObject scriptable )
+ throws JavaScriptException, NotAFunctionException, PropertyException, SAXException {
+ super.initialize( parent, scriptable );
+ _document = (Document) parent;
+ }
+
+ }
+
+
+ static public class Link extends HTMLElement {
+
+ public Document jsGet_document() {
+ return super.jsGet_document();
+ }
+
+
+ public String getClassName() {
+ return "Link";
+ }
+ }
+
+
+ static public class Form extends HTMLElement {
public String getClassName() {
return "Form";
@@ -240,7 +307,7 @@
Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate )
throws PropertyException, NotAFunctionException, JavaScriptException, SAXException {
final Control control = (Control) Context.getCurrentContext().newObject( this, "Control" );
- control.initialize( delegate );
+ control.initialize( this, delegate );
return control;
}
@@ -251,11 +318,6 @@
public String getClassName() {
return "Control";
- }
-
-
- Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate ) {
- return null;
}
}
|
|
From: Russell G. <rus...@us...> - 2002-08-02 16:26:18
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv27406/src/com/meterware/httpunit
Modified Files:
HTMLPage.java WebLink.java
Log Message:
add document.links and link.onMouseOver support
Index: HTMLPage.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HTMLPage.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HTMLPage.java 1 Aug 2002 14:58:59 -0000 1.2
+++ HTMLPage.java 2 Aug 2002 16:26:15 -0000 1.3
@@ -132,13 +132,27 @@
public Object get( String propertyName ) {
WebForm wf = getFormWithName( propertyName );
- if (wf == null) return super.get( propertyName );
- return wf.getScriptableObject();
+ if (wf != null) return wf.getScriptableObject();
+
+ WebLink wl = getLinkWithName( propertyName );
+ if (wl != null) return wl.getScriptableObject();
+
+ return super.get( propertyName );
}
public String getTitle() throws SAXException {
return HTMLPage.this.getTitle();
+ }
+
+
+ public WebLink.Scriptable[] getLinks() {
+ WebLink[] links = HTMLPage.this.getLinks();
+ WebLink.Scriptable[] result = new WebLink.Scriptable[ links.length ];
+ for (int i = 0; i < links.length; i++) {
+ result[i] = links[i].getScriptableObject();
+ }
+ return result;
}
Index: WebLink.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- WebLink.java 1 Aug 2002 14:58:59 -0000 1.20
+++ WebLink.java 2 Aug 2002 16:26:15 -0000 1.21
@@ -43,6 +43,9 @@
**/
public class WebLink extends WebRequestSource {
+ private Scriptable _scriptable;
+
+
/**
* Returns the URL referenced by this link. This may be a relative URL.
**/
@@ -72,13 +75,31 @@
/**
- * Submits a request as though the user had clicked on this link.
+ * Submits a request as though the user had clicked on this link. Will also fire the 'onClick' event if defined.
**/
public void click() throws IOException, SAXException {
submitRequest();
}
+ /**
+ * Simulates moving the mouse over the link. Will fire the 'onMouseOver' event if defined.
+ **/
+ public void mouseOver() {
+ String event = NodeUtils.getNodeAttribute( getNode(), "onmouseover" );
+ if (event.length() > 0) getScriptableObject().doEvent( event );
+ }
+
+
+ /**
+ * Returns an object which provides scripting access to this link.
+ **/
+ public Scriptable getScriptableObject() {
+ if (_scriptable == null) _scriptable = new Scriptable();
+ return _scriptable;
+ }
+
+
//----------------------------------------- WebRequestSource methods ---------------------------------------------------
@@ -206,7 +227,11 @@
}
- //--------------------------------------------------- package members --------------------------------------------------
+ public class Scriptable extends ScriptableObject {
+ }
+
+
+//--------------------------------------------------- package members --------------------------------------------------
/**
|
|
From: Russell G. <rus...@us...> - 2002-08-02 16:26:18
|
Update of /cvsroot/httpunit/httpunit/doc
In directory usw-pr-cvs1:/tmp/cvs-serv27406/doc
Modified Files:
release_notes.txt
Log Message:
add document.links and link.onMouseOver support
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.124
retrieving revision 1.125
diff -u -r1.124 -r1.125
--- release_notes.txt 1 Aug 2002 20:23:15 -0000 1.124
+++ release_notes.txt 2 Aug 2002 16:26:15 -0000 1.125
@@ -7,11 +7,16 @@
3. The regression test "pseudo-server" does not appear to run properly under JDK 1.4
Limitations:
- 1. HttpUnit does not support JavaScript
+ 1. JavaScript support is minimal
2. JDK 1.2 or higher is required
Revision History:
+ 2-Aug-2002
+Additions:
+ 1. Added JavaScript support for document.links and document.<link name> and the link 'onMouseOver' event.
+ 2. You may now call link.mouseOver() to trigger the 'onMouseOver' event.
+
1-Aug-2002
Additions:
1. You may now follow a link by calling link.click() rather than client.getResponse( link.getRequest() ).
|
|
From: Russell G. <rus...@us...> - 2002-08-01 20:23:21
|
Update of /cvsroot/httpunit/httpunit/doc
In directory usw-pr-cvs1:/tmp/cvs-serv4813/doc
Modified Files:
release_notes.txt
Log Message:
Added JavaScript support for text field values
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.123
retrieving revision 1.124
diff -u -r1.123 -r1.124
--- release_notes.txt 1 Aug 2002 14:58:59 -0000 1.123
+++ release_notes.txt 1 Aug 2002 20:23:15 -0000 1.124
@@ -19,6 +19,7 @@
case you must set any parameters directly into the form.
3. You may now obtain the current page from a web client by calling client.getCurrentPage() rather than
client.getFrameContents( "_top" );
+ 4. Added JavaScript support for form.<text field>.value
29-Jul-2002
Acknowledgements:
|
|
From: Russell G. <rus...@us...> - 2002-08-01 20:23:20
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript
In directory usw-pr-cvs1:/tmp/cvs-serv4813/src/com/meterware/httpunit/javascript
Modified Files:
JavaScript.java
Log Message:
Added JavaScript support for text field values
Index: JavaScript.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JavaScript.java 24 Jul 2002 20:54:31 -0000 1.1
+++ JavaScript.java 1 Aug 2002 20:23:16 -0000 1.2
@@ -19,21 +19,19 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
-import com.meterware.httpunit.WebResponse;
import com.meterware.httpunit.HTMLPage;
-import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.ScriptEngine;
+import com.meterware.httpunit.WebForm;
+import com.meterware.httpunit.WebResponse;
-import java.util.Arrays;
-import java.util.HashMap;
import java.lang.reflect.InvocationTargetException;
+import org.mozilla.javascript.ClassDefinitionException;
import org.mozilla.javascript.Context;
-import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.JavaScriptException;
-import org.mozilla.javascript.ClassDefinitionException;
-import org.mozilla.javascript.PropertyException;
import org.mozilla.javascript.NotAFunctionException;
+import org.mozilla.javascript.PropertyException;
+import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import org.xml.sax.SAXException;
@@ -54,6 +52,7 @@
ScriptableObject.defineClass( scope, Window.class );
ScriptableObject.defineClass( scope, Document.class );
ScriptableObject.defineClass( scope, Form.class );
+ ScriptableObject.defineClass( scope, Control.class );
Window w = (Window) context.newObject( scope, "Window" );
w.initialize( response.getScriptableObject() );
@@ -62,6 +61,9 @@
abstract static class JavaScriptEngine extends ScriptableObject implements ScriptEngine {
+ protected com.meterware.httpunit.ScriptableObject _scriptable;
+
+
public void executeScript( String script ) {
try {
Context.getCurrentContext().evaluateString( this, script, "httpunit", 0, null );
@@ -69,12 +71,64 @@
throw new RuntimeException( "Script '" + script + "' failed: " + e );
}
}
+
+
+ void initialize( com.meterware.httpunit.ScriptableObject scriptable )
+ throws JavaScriptException, NotAFunctionException, PropertyException, SAXException {
+ _scriptable = scriptable;
+ _scriptable.setScriptEngine( this );
+ }
+
+
+ public boolean has( String propertyName, Scriptable scriptable ) {
+ return super.has( propertyName, scriptable ) ||
+ (_scriptable != null && _scriptable.get( propertyName ) != null);
+ }
+
+
+ public Object get( String propertyName, Scriptable scriptable ) {
+ Object result = super.get( propertyName, scriptable );
+ if (result != NOT_FOUND) return result;
+ if (_scriptable == null) return NOT_FOUND;
+
+ final Object property = _scriptable.get( propertyName );
+ if (property == null) return NOT_FOUND;
+ if (!(property instanceof com.meterware.httpunit.ScriptableObject)) return property;
+
+ try {
+ return toScriptable( (com.meterware.httpunit.ScriptableObject) property );
+ } catch (PropertyException e) {
+ throw new RuntimeException( e.toString() );
+ } catch (NotAFunctionException e) {
+ throw new RuntimeException( e.toString() );
+ } catch (JavaScriptException e) {
+ throw new RuntimeException( e.toString() );
+ } catch (SAXException e) {
+ throw new RuntimeException( e.toString() );
+ }
+ }
+
+
+ public void put( String propertyName, Scriptable scriptable, Object value ) {
+ if (_scriptable == null || _scriptable.get( propertyName ) == null) {
+ super.put( propertyName, scriptable, value );
+ } else {
+ _scriptable.set( propertyName, value );
+ }
+ }
+
+
+ /**
+ * Converts a scriptable delegate obtained from a subobject into the appropriate Rhino-compatible Scriptable.
+ **/
+ abstract Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate )
+ throws PropertyException, NotAFunctionException, JavaScriptException, SAXException;
+
}
static public class Window extends JavaScriptEngine {
- private WebResponse.Scriptable _scriptable;
private Document _document;
@@ -98,69 +152,51 @@
}
- void initialize( WebResponse.Scriptable scriptable )
- throws JavaScriptException, NotAFunctionException, PropertyException, SAXException {
- _scriptable = scriptable;
- _scriptable.setScriptEngine( this );
+ void initialize( com.meterware.httpunit.ScriptableObject scriptable )
+ throws JavaScriptException, NotAFunctionException, PropertyException, SAXException {
+ super.initialize( scriptable );
_document = (Document) Context.getCurrentContext().newObject( this, "Document" );
- _document.initialize( _scriptable.getDocument() );
+ _document.initialize( getDelegate().getDocument() );
- _scriptable.load();
+ getDelegate().load();
}
public void jsFunction_alert( String message ) {
- _scriptable.alert( message );
+ getDelegate().alert( message );
}
- }
-
-
- static public class Document extends JavaScriptEngine {
-
- private HTMLPage.Scriptable _scriptable;
- private Scriptable _forms;
- public String getClassName() {
- return "Document";
+ Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate ) {
+ return null;
}
- public boolean has( String propertyName, Scriptable scriptable ) {
- return super.has( propertyName, scriptable ) || _scriptable.get( propertyName ) != null;
+ private WebResponse.Scriptable getDelegate() {
+ return (WebResponse.Scriptable) _scriptable;
}
+ }
- public Object get( String propertyName, Scriptable scriptable ) {
- Object result = super.get( propertyName, scriptable );
- if (result != NOT_FOUND) return result;
- if (_scriptable == null) return NOT_FOUND;
+ static public class Document extends JavaScriptEngine {
- final Object delegate = _scriptable.get( propertyName );
- if (delegate == null) return NOT_FOUND;
+ private Scriptable _forms;
- try {
- return toScriptable( (WebForm.Scriptable) delegate );
- } catch (PropertyException e) {
- throw new RuntimeException( e.toString() );
- } catch (NotAFunctionException e) {
- throw new RuntimeException( e.toString() );
- } catch (JavaScriptException e) {
- throw new RuntimeException( e.toString() );
- }
+
+ public String getClassName() {
+ return "Document";
}
- void initialize( HTMLPage.Scriptable scriptable )
- throws JavaScriptException, NotAFunctionException, PropertyException {
- _scriptable = scriptable;
- _scriptable.setScriptEngine( this );
+ void initialize( com.meterware.httpunit.ScriptableObject scriptable )
+ throws JavaScriptException, NotAFunctionException, PropertyException, SAXException {
+ super.initialize( scriptable );
initializeForms();
}
public String jsGet_title() throws SAXException {
- return _scriptable.getTitle();
+ return getDelegate().getTitle();
}
@@ -169,40 +205,58 @@
}
- private void initializeForms() throws PropertyException, NotAFunctionException, JavaScriptException {
- WebForm.Scriptable scriptables[] = _scriptable.getForms();
+ private void initializeForms() throws PropertyException, NotAFunctionException, JavaScriptException, SAXException {
+ WebForm.Scriptable scriptables[] = getDelegate().getForms();
Form[] forms = new Form[ scriptables.length ];
for (int i = 0; i < forms.length; i++) {
- forms[i] = toScriptable( scriptables[i] );
+ forms[ i ] = (Form) toScriptable( scriptables[ i ] );
}
_forms = Context.getCurrentContext().newArray( this, forms );
}
- private Form toScriptable( final WebForm.Scriptable scriptable )
- throws PropertyException, NotAFunctionException, JavaScriptException {
+ Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate )
+ throws PropertyException, JavaScriptException, NotAFunctionException, SAXException {
final Form form = (Form) Context.getCurrentContext().newObject( this, "Form" );
- form.initialize( scriptable );
+ form.initialize( delegate );
return form;
}
- }
- static public class Form extends JavaScriptEngine {
+ private HTMLPage.Scriptable getDelegate() {
+ return (HTMLPage.Scriptable) _scriptable;
+ }
- private WebForm.Scriptable _scriptable;
+ }
+ static public class Form extends JavaScriptEngine {
+
public String getClassName() {
return "Form";
}
- void initialize( WebForm.Scriptable scriptable ) {
- _scriptable = scriptable;
- scriptable.setScriptEngine( this );
+ Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate )
+ throws PropertyException, NotAFunctionException, JavaScriptException, SAXException {
+ final Control control = (Control) Context.getCurrentContext().newObject( this, "Control" );
+ control.initialize( delegate );
+ return control;
}
+
}
+
+ static public class Control extends JavaScriptEngine {
+
+ public String getClassName() {
+ return "Control";
+ }
+
+
+ Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate ) {
+ return null;
+ }
+ }
}
|
|
From: Russell G. <rus...@us...> - 2002-08-01 20:23:20
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv4813/test/com/meterware/httpunit
Modified Files:
HttpUnitSuite.java
Log Message:
Added JavaScript support for text field values
Index: HttpUnitSuite.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitSuite.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- HttpUnitSuite.java 24 Jul 2002 17:32:08 -0000 1.19
+++ HttpUnitSuite.java 1 Aug 2002 20:23:16 -0000 1.20
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2001, Russell Gold
+* Copyright (c) 2000-2002, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -19,11 +19,15 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
-
import com.meterware.pseudoserver.PseudoServerTest;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.InvocationTargetException;
+
import junit.framework.Test;
import junit.framework.TestSuite;
+import junit.framework.TestCase;
/**
@@ -31,6 +35,9 @@
**/
public class HttpUnitSuite {
+ private static Class[] NO_PARAMETERS = new Class[ 0 ];
+
+
public static void main( String[] args ) {
junit.textui.TestRunner.run( suite() );
}
@@ -54,15 +61,27 @@
result.addTest( JTidyPrintWriterTest.suite() );
addOptionalTestCase( result, "com.meterware.httpunit.XMLPageTest" );
addOptionalTestCase( result, "com.meterware.httpunit.FileUploadTest" );
+ addOptionalTestCase( result, "com.meterware.httpunit.javascript.ScriptingTest" );
+ addOptionalTestCase( result, "com.meterware.servletunit.ServletUnitSuite" );
return result;
}
private static void addOptionalTestCase( TestSuite testSuite, String testCaseName ) {
try {
- testSuite.addTest( new TestSuite( Class.forName( testCaseName ) ) );
+ final Class testClass = Class.forName( testCaseName );
+ Method suiteMethod = testClass.getMethod( "suite", NO_PARAMETERS );
+ if (suiteMethod != null && Modifier.isStatic( suiteMethod.getModifiers() )) {
+ testSuite.addTest( (Test) suiteMethod.invoke( null, NO_PARAMETERS ) );
+ } else if (TestCase.class.isAssignableFrom( testClass )) {
+ testSuite.addTest( new TestSuite( testClass ) );
+ } else {
+ System.out.println( "Note: test suite " + testCaseName + " not a TestClass and has no suite() method" );
+ }
} catch (ClassNotFoundException e) {
System.out.println( "Note: test suite " + testCaseName + " not found; skipping." );
+ } catch (Exception e) {
+ System.out.println( "Note: unable to add " + testCaseName + ": " + e );
}
}
|
|
From: Russell G. <rus...@us...> - 2002-08-01 20:23:20
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript
In directory usw-pr-cvs1:/tmp/cvs-serv4813/test/com/meterware/httpunit/javascript
Modified Files:
ScriptingTest.java
Log Message:
Added JavaScript support for text field values
Index: ScriptingTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/javascript/ScriptingTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ScriptingTest.java 24 Jul 2002 20:54:31 -0000 1.1
+++ ScriptingTest.java 1 Aug 2002 20:23:16 -0000 1.2
@@ -22,6 +22,7 @@
import com.meterware.httpunit.HttpUnitTest;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebResponse;
+import com.meterware.httpunit.WebForm;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
@@ -104,6 +105,19 @@
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() );
+ }
+
+
+ public void testSetFormFieldValue() throws Exception {
+ defineResource( "OnCommand.html", "<html><head></head>" +
+ "<body onLoad=\"document.realform.color.value='green'\">" +
+ "<form name='realform'><input name='color' value='blue'></form>" +
+ "</body></html>" );
+ WebConversation wc = new WebConversation();
+ WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" );
+ JavaScript.run( response );
+ WebForm form = response.getFormWithName( "realform" );
+ assertEquals( "color parameter value", "green", form.getParameterValue( "color" ) );
}
|
|
From: Russell G. <rus...@us...> - 2002-08-01 20:23:19
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv4813/src/com/meterware/httpunit
Modified Files:
FormControl.java WebForm.java
Log Message:
Added JavaScript support for text field values
Index: FormControl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- FormControl.java 24 Jul 2002 20:54:31 -0000 1.12
+++ FormControl.java 1 Aug 2002 20:23:15 -0000 1.13
@@ -544,6 +544,15 @@
class Scriptable extends FormControl.Scriptable {
+ public Object get( String propertyName ) {
+ if (propertyName.equalsIgnoreCase( "value" )) {
+ return getValues()[0];
+ } else {
+ return super.get( propertyName );
+ }
+ }
+
+
public void set( String propertyName, Object value ) {
if (propertyName.equalsIgnoreCase( "value" )) {
_value[0] =_defaultValue[0] = value.toString();
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- WebForm.java 1 Aug 2002 14:58:59 -0000 1.51
+++ WebForm.java 1 Aug 2002 20:23:16 -0000 1.52
@@ -413,6 +413,13 @@
public String getAction() { return WebForm.this.getAction(); }
public void setAction( String newAction ) { _action = newAction; }
+
+ public Object get( String propertyName ) {
+ final FormParameter parameter = getParameter( propertyName );
+ return parameter == UNKNOWN_PARAMETER ? null : parameter.getScriptableObject();
+ }
+
+
public void setParameterValue( String name, String value ) {
getParameter( name ).getScriptableObject().set( "value", value );
}
|
|
From: Russell G. <rus...@us...> - 2002-08-01 14:59:04
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit
In directory usw-pr-cvs1:/tmp/cvs-serv9683/test/com/meterware/servletunit
Modified Files:
HttpServletResponseTest.java JUnitServletTest.java
Log Message:
Support link.click and form.submit
Index: HttpServletResponseTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/HttpServletResponseTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HttpServletResponseTest.java 6 Jul 2001 17:11:04 -0000 1.2
+++ HttpServletResponseTest.java 1 Aug 2002 14:58:59 -0000 1.3
@@ -55,7 +55,7 @@
public void testDefaultResponse() throws Exception {
ServletUnitHttpResponse servletResponse = new ServletUnitHttpResponse();
- WebResponse response = new ServletUnitWebResponse( "_self", null, servletResponse );
+ WebResponse response = new ServletUnitWebResponse( null, "_self", null, servletResponse );
assertEquals( "Content type", "text/plain", response.getContentType() );
assertEquals( "Contents", "", response.getText() );
}
@@ -67,7 +67,7 @@
PrintWriter pw = servletResponse.getWriter();
pw.println( "<html><head><title>Sample Page</title></head><body></body></html>" );
- WebResponse response = new ServletUnitWebResponse( "_self", null, servletResponse );
+ WebResponse response = new ServletUnitWebResponse( null, "_self", null, servletResponse );
assertEquals( "Status code", HttpServletResponse.SC_OK, response.getResponseCode() );
assertEquals( "Content type", "text/html", response.getContentType() );
assertEquals( "Title", "Sample Page", response.getTitle() );
@@ -85,7 +85,7 @@
pw.print( page );
pw.close();
- WebResponse response = new ServletUnitWebResponse( "_self", null, servletResponse );
+ WebResponse response = new ServletUnitWebResponse( null, "_self", null, servletResponse );
assertEquals( "Character set", "iso-8859-8", response.getCharacterSet() );
assertEquals( "Title", hebrewTitle, response.getTitle() );
}
@@ -97,7 +97,7 @@
ServletOutputStream sos = servletResponse.getOutputStream();
sos.println( "<html><head><title>Sample Page</title></head><body></body></html>" );
- WebResponse response = new ServletUnitWebResponse( "_self", null, servletResponse );
+ WebResponse response = new ServletUnitWebResponse( null, "_self", null, servletResponse );
assertEquals( "Status code", HttpServletResponse.SC_OK, response.getResponseCode() );
assertEquals( "Content type", "text/html", response.getContentType() );
assertEquals( "Title", "Sample Page", response.getTitle() );
Index: JUnitServletTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/JUnitServletTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JUnitServletTest.java 4 Feb 2002 22:33:55 -0000 1.2
+++ JUnitServletTest.java 1 Aug 2002 14:58:59 -0000 1.3
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
- * Copyright (c) 2001, Russell Gold
+ * Copyright (c) 2001-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
@@ -180,8 +180,8 @@
static class MyFactory implements InvocationContextFactory {
private static ServletRunner _runner;
- public InvocationContext newInvocation( WebRequest request, Cookie[] clientCookies, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException {
- return new InvocationContextImpl( _runner, request, clientCookies, clientHeaders, messageBody );
+ public InvocationContext newInvocation( ServletUnitClient client, WebRequest request, Cookie[] clientCookies, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException {
+ return new InvocationContextImpl( client, _runner, request, clientCookies, clientHeaders, messageBody );
}
}
}
|
|
From: Russell G. <rus...@us...> - 2002-08-01 14:59:04
|
Update of /cvsroot/httpunit/httpunit/doc
In directory usw-pr-cvs1:/tmp/cvs-serv9683/doc
Modified Files:
release_notes.txt
Log Message:
Support link.click and form.submit
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.122
retrieving revision 1.123
diff -u -r1.122 -r1.123
--- release_notes.txt 30 Jul 2002 13:16:52 -0000 1.122
+++ release_notes.txt 1 Aug 2002 14:58:59 -0000 1.123
@@ -12,6 +12,14 @@
Revision History:
+ 1-Aug-2002
+Additions:
+ 1. You may now follow a link by calling link.click() rather than client.getResponse( link.getRequest() ).
+ 2. You may now submit a form by calling form.submit() rather than client.getResponse( form.getRequest() ). In this
+ case you must set any parameters directly into the form.
+ 3. You may now obtain the current page from a web client by calling client.getCurrentPage() rather than
+ client.getFrameContents( "_top" );
+
29-Jul-2002
Acknowledgements:
Thanks to Sebastien Rosset for pointing out the case sensitivity problem with WebResponse.isHTML
|
|
From: Russell G. <rus...@us...> - 2002-08-01 14:59:03
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv9683/src/com/meterware/httpunit
Modified Files:
FrameHolder.java HTMLPage.java HttpWebResponse.java
ParsedHTML.java TableCell.java WebClient.java
WebConversation.java WebForm.java WebFrame.java WebLink.java
WebRequestSource.java WebResponse.java WebTable.java
Log Message:
Support link.click and form.submit
Index: FrameHolder.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FrameHolder.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FrameHolder.java 14 Feb 2002 14:33:49 -0000 1.1
+++ FrameHolder.java 1 Aug 2002 14:58:59 -0000 1.2
@@ -19,18 +19,80 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Vector;
+import java.util.List;
+import java.util.ArrayList;
+
+import org.xml.sax.SAXException;
/**
- * An interface for a class which can act as a map of frame names to web responses.
*
* @author <a href="mailto:rus...@ac...">Russell Gold</a>
**/
-interface FrameHolder {
+class FrameHolder {
+
+ private WebClient _client;
+ private Hashtable _contents = new Hashtable();
+ private Hashtable _subFrames = new Hashtable();
+ private String _frameName;
+ private WebResponse _response = WebResponse.BLANK_RESPONSE;
+
+
+ FrameHolder( WebClient client, String name ) {
+ _client = client;
+ _frameName = name;
+ }
+
+
+ public WebResponse get( String frameName ) {
+ return (WebResponse) _contents.get( frameName );
+ }
+
+
+ List getActiveFrameNames() {
+ List result = new ArrayList();
+ for (Enumeration e = _contents.keys(); e.hasMoreElements();) {
+ result.add( e.nextElement() );
+ }
+
+ return result;
+ }
+
+
+ void updateFrames( WebResponse response ) throws MalformedURLException, IOException, SAXException {
+ removeSubFrames( response.getTarget() );
+ _contents.put( response.getTarget(), response );
+
+ if (response.isHTML()) {
+ createSubFrames( response.getTarget(), response.getFrameNames() );
+ WebRequest[] requests = response.getFrameRequests();
+ for (int i = 0; i < requests.length; i++) _client.getResponse( requests[ i ] );
+ }
+ }
+
+
+ private void removeSubFrames( String targetName ) {
+ String[] names = (String[]) _subFrames.get( targetName );
+ if (names == null) return;
+ for (int i = 0; i < names.length; i++) {
+ removeSubFrames( names[ i ] );
+ _contents.remove( names[ i ] );
+ _subFrames.remove( names[ i ] );
+ }
+ }
+
+
+ private void createSubFrames( String targetName, String[] frameNames ) {
+ _subFrames.put( targetName, frameNames );
+ for (int i = 0; i < frameNames.length; i++) {
+ _contents.put( frameNames[ i ], WebResponse.BLANK_RESPONSE );
+ }
+ }
- /**
- * Returns the response associated with the specified frame name.
- * Throws a runtime exception if no matching frame is defined.
- **/
- WebResponse getFrameContents( String frameName );
}
+
Index: HTMLPage.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HTMLPage.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HTMLPage.java 24 Jul 2002 20:54:31 -0000 1.1
+++ HTMLPage.java 1 Aug 2002 14:58:59 -0000 1.2
@@ -43,8 +43,8 @@
public class HTMLPage extends ParsedHTML {
- public HTMLPage( URL url, String parentTarget, String pageText, String characterSet ) throws SAXException {
- super( url, parentTarget, getDOM( url, pageText ), characterSet );
+ public HTMLPage( WebResponse response, URL url, String parentTarget, String pageText, String characterSet ) throws SAXException {
+ super( response, url, parentTarget, getDOM( url, pageText ), characterSet );
setBaseAttributes();
}
Index: HttpWebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpWebResponse.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- HttpWebResponse.java 18 Jun 2002 16:37:03 -0000 1.23
+++ HttpWebResponse.java 1 Aug 2002 14:58:59 -0000 1.24
@@ -48,8 +48,8 @@
* @param url the url from which the response was received
* @param connection the URL connection from which the response can be read
**/
- HttpWebResponse( String target, URL url, URLConnection connection, boolean throwExceptionOnError ) throws IOException {
- super( target, url );
+ HttpWebResponse( WebConversation client, String target, URL url, URLConnection connection, boolean throwExceptionOnError ) throws IOException {
+ super( client, target, url );
readHeaders( connection );
/** make sure that any IO exception for HTML received page happens here, not later. **/
Index: ParsedHTML.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- ParsedHTML.java 15 Jul 2002 14:30:32 -0000 1.21
+++ ParsedHTML.java 1 Aug 2002 14:58:59 -0000 1.22
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2001, Russell Gold
+* Copyright (c) 2000-2002, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -31,11 +31,13 @@
**/
class ParsedHTML {
- private WebForm[] _forms;
- private WebImage[] _images;
+ private WebForm[] _forms;
+ private WebImage[] _images;
+ private WebResponse _response;
- ParsedHTML( URL baseURL, String baseTarget, Node rootNode, String characterSet ) {
+ ParsedHTML( WebResponse response, URL baseURL, String baseTarget, Node rootNode, String characterSet ) {
+ _response = response;
_baseURL = baseURL;
_baseTarget = baseTarget;
_rootNode = rootNode;
@@ -52,7 +54,7 @@
_forms = new WebForm[ forms.getLength() ];
for (int i = 0; i < _forms.length; i++) {
- _forms[i] = new WebForm( _baseURL, _baseTarget, forms.item( i ), _characterSet );
+ _forms[i] = new WebForm( _response, _baseURL, _baseTarget, forms.item( i ), _characterSet );
}
}
return _forms;
@@ -107,7 +109,7 @@
for (int i = 0; i < nl.getLength(); i++) {
Node child = nl.item(i);
if (isLinkAnchor( child )) {
- list.addElement( new WebLink( _baseURL, _baseTarget, child ) );
+ list.addElement( new WebLink( _response, _baseURL, _baseTarget, child ) );
}
}
}
@@ -208,7 +210,7 @@
* they appear.
**/
public WebTable[] getTables() {
- return WebTable.getTables( getOriginalDOM(), _baseURL, _baseTarget, _characterSet );
+ return WebTable.getTables( _response, getOriginalDOM(), _baseURL, _baseTarget, _characterSet );
}
Index: TableCell.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/TableCell.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TableCell.java 9 Nov 2001 18:35:14 -0000 1.7
+++ TableCell.java 1 Aug 2002 14:58:59 -0000 1.8
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2001, Russell Gold
+* Copyright (c) 2000-2002, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -66,8 +66,8 @@
//---------------------------------------- package methods -----------------------------------------
- TableCell( Element cellNode, URL url, String parentTarget, String characterSet ) {
- super( url, parentTarget, cellNode, characterSet );
+ TableCell( WebResponse response, Element cellNode, URL url, String parentTarget, String characterSet ) {
+ super( response, url, parentTarget, cellNode, characterSet );
_element = cellNode;
_colSpan = getAttributeValue( cellNode, "colspan", 1 );
_rowSpan = getAttributeValue( cellNode, "rowspan", 1 );
Index: WebClient.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- WebClient.java 30 Jul 2002 14:11:15 -0000 1.25
+++ WebClient.java 1 Aug 2002 14:58:59 -0000 1.26
@@ -47,7 +47,7 @@
* @author Oliver Imbusch
**/
abstract
-public class WebClient implements FrameHolder {
+public class WebClient {
/**
* Submits a GET method request and returns a response.
@@ -67,6 +67,14 @@
/**
+ * Returns the response representing the current main page.
+ */
+ public WebResponse getCurrentPage() {
+ return getFrameContents( WebRequest.TOP_FRAME );
+ }
+
+
+ /**
* Submits a web request and returns a response, using all state developed so far as stored in
* cookies as requested by the server.
* @exception SAXException thrown if there is an error parsing the retrieved page
@@ -113,7 +121,7 @@
* any listeners or preferences which may have been set.
**/
public void clearContents() {
- _frameContents = new FrameHolderImpl();
+ _frameContents = new FrameHolder( this, WebRequest.TOP_FRAME );
_cookies = new Hashtable();
_headers = new HeaderDictionary();
}
@@ -123,7 +131,8 @@
* Returns the name of the currently active frames.
**/
public String[] getFrameNames() {
- return _frameContents.getFrameNames();
+ final List names = _frameContents.getActiveFrameNames();
+ return (String[]) names.toArray( new String[ names.size() ] );
}
@@ -311,7 +320,7 @@
delay( HttpUnitOptions.getRedirectDelay() );
getResponse( new RedirectWebRequest( response ) );
} else {
- updateFrames( response );
+ _frameContents.updateFrames( response );
}
}
@@ -332,11 +341,7 @@
/** A map of frame names to current contents. **/
- private FrameHolderImpl _frameContents = new FrameHolderImpl();
-
-
- /** A map of frame names to frames nested within them. **/
- private Hashtable _subFrames = new Hashtable();
+ private FrameHolder _frameContents = new FrameHolder( this, WebRequest.TOP_FRAME );
/** A map of header names to values. **/
@@ -390,36 +395,6 @@
}
}
- private void updateFrames( WebResponse response ) throws MalformedURLException, IOException, SAXException {
- removeSubFrames( response.getTarget() );
- response.setFrameHolder( this );
- _frameContents.put( response.getTarget(), response );
-
- if (response.isHTML()) {
- createSubFrames( response.getTarget(), response.getFrameNames() );
- WebRequest[] requests = response.getFrameRequests();
- for (int i = 0; i < requests.length; i++) getResponse( requests[i] );
- }
- }
-
-
- private void createSubFrames( String targetName, String[] frameNames ) {
- _subFrames.put( targetName, frameNames );
- for (int i = 0; i < frameNames.length; i++) {
- _frameContents.put( frameNames[i], WebResponse.BLANK_RESPONSE );
- }
- }
-
-
- private void removeSubFrames( String targetName ) {
- String[] names = (String[]) _subFrames.get( targetName );
- if (names == null) return;
- for (int i = 0; i < names.length; i++) {
- removeSubFrames( names[i] );
- _frameContents.remove( names[i] );
- _subFrames.remove( names[i] );
- }
- }
//==================================================================================================
@@ -489,34 +464,5 @@
-class FrameHolderImpl {
- private Hashtable _contents = new Hashtable();
-
- void put( String targetName, WebResponse contents ) {
- _contents.put( targetName, contents );
- }
-
-
- WebResponse get( String targetName ) {
- return (WebResponse) _contents.get( targetName );
- }
-
- void remove( String targetName ) {
- _contents.remove( targetName );
- }
-
-
- public String[] getFrameNames() {
- Vector names = new Vector();
- for (Enumeration e = _contents.keys(); e.hasMoreElements();) {
- names.addElement( e.nextElement() );
- }
-
- String[] result = new String[ names.size() ];
- names.copyInto( result );
- return result;
- }
-
-}
Index: WebConversation.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- WebConversation.java 11 Feb 2002 14:33:53 -0000 1.24
+++ WebConversation.java 1 Aug 2002 14:58:59 -0000 1.25
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2001, Russell Gold
+* Copyright (c) 2000-2002, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -63,7 +63,7 @@
}
}
request.completeRequest( connection );
- return new HttpWebResponse( request.getTarget(), request.getURL(), connection, getExceptionsThrownOnErrorStatus() );
+ return new HttpWebResponse( this, request.getTarget(), request.getURL(), connection, getExceptionsThrownOnErrorStatus() );
}
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- WebForm.java 24 Jul 2002 20:54:31 -0000 1.50
+++ WebForm.java 1 Aug 2002 14:58:59 -0000 1.51
@@ -31,6 +31,7 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
/**
@@ -43,6 +44,14 @@
/**
+ * Submits this form using the web client from which it was originally obtained.
+ **/
+ public void submit() throws IOException, SAXException {
+ submitRequest();
+ }
+
+
+ /**
* Returns the method defined for this form.
**/
public String getMethod() {
@@ -416,8 +425,8 @@
* Contructs a web form given the URL of its source page and the DOM extracted
* from that page.
**/
- WebForm( URL baseURL, String frameName, Node node, String characterSet ) {
- super( node, baseURL, NodeUtils.getNodeAttribute( node, "action" ), frameName );
+ WebForm( WebResponse response, URL baseURL, String frameName, Node node, String characterSet ) {
+ super( response, node, baseURL, NodeUtils.getNodeAttribute( node, "action" ), frameName );
_characterSet = characterSet;
}
Index: WebFrame.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebFrame.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- WebFrame.java 30 Jul 2002 14:11:15 -0000 1.8
+++ WebFrame.java 1 Aug 2002 14:58:59 -0000 1.9
@@ -2,14 +2,14 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2001, Russell Gold
+* Copyright (c) 2000-2002, Russell Gold
*
-* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
-* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+* 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
@@ -28,7 +28,7 @@
**/
class WebFrame {
-
+
//---------------------------------------- package methods -----------------------------------------
@@ -78,7 +78,7 @@
WebRequest getInitialRequest() {
- return new GetMethodWebRequest( _baseURL,
+ return new GetMethodWebRequest( _baseURL,
NodeUtils.getNodeAttribute( _element, "src" ),
getName() );
}
Index: WebLink.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- WebLink.java 19 Jun 2002 13:46:51 -0000 1.19
+++ WebLink.java 1 Aug 2002 14:58:59 -0000 1.20
@@ -31,6 +31,7 @@
import java.io.IOException;
import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
/**
* This class represents a link in an HTML page. Users of this class may examine the
@@ -70,6 +71,14 @@
}
+ /**
+ * Submits a request as though the user had clicked on this link.
+ **/
+ public void click() throws IOException, SAXException {
+ submitRequest();
+ }
+
+
//----------------------------------------- WebRequestSource methods ---------------------------------------------------
@@ -204,8 +213,8 @@
* Contructs a web link given the URL of its source page and the DOM extracted
* from that page.
**/
- WebLink( URL baseURL, String parentTarget, Node node ) {
- super( node, baseURL, NodeUtils.getNodeAttribute( node, "href" ), parentTarget );
+ WebLink( WebResponse response, URL baseURL, String parentTarget, Node node ) {
+ super( response, node, baseURL, NodeUtils.getNodeAttribute( node, "href" ), parentTarget );
}
Index: WebRequestSource.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequestSource.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- WebRequestSource.java 14 Feb 2002 14:33:49 -0000 1.8
+++ WebRequestSource.java 1 Aug 2002 14:58:59 -0000 1.9
@@ -21,9 +21,11 @@
package com.meterware.httpunit;
import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
import java.net.URL;
import java.util.StringTokenizer;
+import java.io.IOException;
abstract
@@ -49,9 +51,7 @@
* Returns the target for this request source.
**/
public String getTarget() {
- if (getSpecifiedTarget().length() == 0) {
- return _pageFrame;
- } else if (getSpecifiedTarget().equalsIgnoreCase( "_self" )) {
+ if (getSpecifiedTarget().length() == 0 || getSpecifiedTarget().equalsIgnoreCase( "_self" )) {
return _pageFrame;
} else if (getSpecifiedTarget().equalsIgnoreCase( "_top" )) {
return "_top";
@@ -125,8 +125,9 @@
* Contructs a web form given the URL of its source page and the DOM extracted
* from that page.
**/
- WebRequestSource( Node node, URL baseURL, String destination, String pageFrame ) {
+ WebRequestSource( WebResponse response, Node node, URL baseURL, String destination, String pageFrame ) {
if (node == null) throw new IllegalArgumentException( "node must not be null" );
+ _baseResponse = response;
_node = node;
_baseURL = baseURL;
_destination = destination;
@@ -164,6 +165,15 @@
/**
+ * Submits a request to the web client from which this request source was originally obtained.
+ **/
+ final
+ protected void submitRequest() throws IOException, SAXException {
+ _baseResponse.getClient().sendRequest( getRequest() );
+ }
+
+
+ /**
* Records a parameter defined by including it in the destination URL.
* The value can be null, if the parameter name was not specified with an equals sign.
**/
@@ -175,6 +185,9 @@
private static final String PARAM_DELIM = "&";
+
+ /** The web response containing this request source. **/
+ private WebResponse _baseResponse;
/** The name of the frame in which the response containing this request source is rendered. **/
private String _pageFrame;
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -r1.69 -r1.70
--- WebResponse.java 30 Jul 2002 13:16:52 -0000 1.69
+++ WebResponse.java 1 Aug 2002 14:58:59 -0000 1.70
@@ -58,7 +58,7 @@
* access to WebResponse parsing without using a WebClient.
**/
public static WebResponse newResponse( URLConnection connection ) throws IOException {
- return new HttpWebResponse( "_top", connection.getURL(), connection, HttpUnitOptions.getExceptionsThrownOnErrorStatus() );
+ return new HttpWebResponse( null, "_top", connection.getURL(), connection, HttpUnitOptions.getExceptionsThrownOnErrorStatus() );
}
@@ -281,8 +281,8 @@
* @param subFrameName the name of the desired frame as defined in the frameset.
**/
public WebResponse getSubframeContents( String subFrameName ) {
- if (_frameHolder == null) throw new NoSuchFrameException( subFrameName );
- return _frameHolder.getFrameContents( WebFrame.getNestedFrameName( _frameName, subFrameName ) );
+ if (_client == null) throw new NoSuchFrameException( subFrameName );
+ return _client.getFrameContents( WebFrame.getNestedFrameName( _frameName, subFrameName ) );
}
@@ -512,7 +512,8 @@
* @param frameName the name of the frame to hold the response
* @param url the url from which the response was received
**/
- protected WebResponse( String frameName, URL url ) {
+ protected WebResponse( WebClient client, String frameName, URL url ) {
+ _client = client;
_url = url;
_frameName = frameName;
}
@@ -594,11 +595,8 @@
}
- /**
- * Provides a FrameHolder to help with computation of subframes.
- **/
- void setFrameHolder( FrameHolder holder ) {
- _frameHolder = holder;
+ WebClient getClient() {
+ return _client;
}
@@ -645,8 +643,6 @@
private WebRequest _refreshRequest;
- private FrameHolder _frameHolder;
-
private int _refreshDelay;
private String _responseText;
@@ -661,6 +657,8 @@
private String _frameName;
+ private WebClient _client;
+
protected void loadResponseText() throws IOException {
if (_responseText != null) throw new IllegalStateException( "May only invoke loadResponseText once" );
@@ -912,7 +910,7 @@
if (_page == null) {
try {
if (!isHTML()) throw new NotHTMLException( getContentType() );
- _page = new HTMLPage( _url, _frameName, getText(), getCharacterSet() );
+ _page = new HTMLPage( this, _url, _frameName, getText(), getCharacterSet() );
} catch (IOException e) {
throw new SAXException( e );
}
@@ -930,7 +928,7 @@
for (int i = 0; i < DEFAULT_ENCODING_CANDIDATES.length; i++) {
try {
_defaultEncoding = DEFAULT_ENCODING_CANDIDATES[i];
- "abcd".getBytes( _defaultEncoding );
+ "abcd".getBytes( _defaultEncoding ); // throws an exception if the encoding is not supported
return _defaultEncoding;
} catch (UnsupportedEncodingException e) {
}
@@ -1050,7 +1048,7 @@
DefaultWebResponse( String text ) {
- super( "", null );
+ super( null, "", null );
_responseText = text;
}
Index: WebTable.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebTable.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- WebTable.java 19 Jun 2002 13:46:52 -0000 1.16
+++ WebTable.java 1 Aug 2002 14:58:59 -0000 1.17
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2001, Russell Gold
+* Copyright (c) 2000-2002, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -232,13 +232,13 @@
/**
* Returns the top-level tables found in the specified DOM.
**/
- static WebTable[] getTables( Node domRoot, URL baseURL, String parentTarget, String characterSet ) {
+ static WebTable[] getTables( WebResponse response, Node domRoot, URL baseURL, String parentTarget, String characterSet ) {
NodeList nl = NodeUtils.getElementsByTagName( domRoot, "table" );
Vector topLevelTables = new Vector();
for (int i = 0; i < nl.getLength(); i++) {
if (isTopLevelTable( nl.item(i), domRoot )) {
- topLevelTables.addElement( new WebTable( nl.item(i), baseURL, parentTarget, characterSet ) );
+ topLevelTables.addElement( new WebTable( response, nl.item(i), baseURL, parentTarget, characterSet ) );
}
}
@@ -251,16 +251,18 @@
//----------------------------------- private members -----------------------------------
- private Element _dom;
- private URL _url;
- private String _parentTarget;
- private String _characterSet;
+ private Element _dom;
+ private URL _url;
+ private String _parentTarget;
+ private String _characterSet;
+ private WebResponse _response;
private TableCell[][] _cells;
- private WebTable( Node domTreeRoot, URL sourceURL, String parentTarget, String characterSet ) {
+ private WebTable( WebResponse response, Node domTreeRoot, URL sourceURL, String parentTarget, String characterSet ) {
+ _response = response;
_dom = (Element) domTreeRoot;
_url = sourceURL;
_parentTarget = parentTarget;
@@ -372,7 +374,7 @@
private void collectChildren( String childTag, final Vector children ) {
processChildren( _element, childTag, "table", new ElementHandler() {
public void handleElement( Element element ) {
- children.addElement( new TableCell( element, _url, _parentTarget, _characterSet ) );
+ children.addElement( new TableCell( _response, element, _url, _parentTarget, _characterSet ) );
}
} );
}
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit
In directory usw-pr-cvs1:/tmp/cvs-serv9683/src/com/meterware/servletunit
Modified Files:
InvocationContextFactory.java InvocationContextImpl.java
ServletRunner.java ServletUnitClient.java
ServletUnitWebResponse.java
Log Message:
Support link.click and form.submit
Index: InvocationContextFactory.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/InvocationContextFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- InvocationContextFactory.java 4 Feb 2002 22:33:55 -0000 1.2
+++ InvocationContextFactory.java 1 Aug 2002 14:58:59 -0000 1.3
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
- * Copyright (c) 2001, Russell Gold
+ * Copyright (c) 2001-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
@@ -38,6 +38,6 @@
/**
* Creates and returns a new invocation context to test calling of servlet methods.
**/
- public InvocationContext newInvocation( WebRequest request, Cookie[] clientCookies, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException;
+ public InvocationContext newInvocation( ServletUnitClient client, WebRequest request, Cookie[] clientCookies, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException;
}
Index: InvocationContextImpl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/InvocationContextImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- InvocationContextImpl.java 23 Jun 2002 23:52:39 -0000 1.6
+++ InvocationContextImpl.java 1 Aug 2002 14:58:59 -0000 1.7
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2001, Russell Gold
+* Copyright (c) 2001-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
@@ -93,7 +93,7 @@
if (session != null && session.isNew()) {
_response.addCookie( new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, session.getId() ) );
}
- _webResponse = new ServletUnitWebResponse( _target, _requestURL, _response );
+ _webResponse = new ServletUnitWebResponse( _client, _target, _requestURL, _response );
}
return _webResponse;
}
@@ -130,10 +130,11 @@
* Constructs a servlet invocation context for a specified servlet container,
* request, and cookie headers.
**/
- InvocationContextImpl( ServletRunner runner, WebRequest request, Cookie[] cookies, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException {
- _application = runner.getApplication();
- _requestURL = request.getURL();
- _target = request.getTarget();
+ InvocationContextImpl( ServletUnitClient client, ServletRunner runner, WebRequest request, Cookie[] cookies, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException {
+ _client = client;
+ _application = runner.getApplication();
+ _requestURL = request.getURL();
+ _target = request.getTarget();
_request = new ServletUnitHttpRequest( _application.getServletRequest( _requestURL ), request, runner.getContext(),
clientHeaders, messageBody );
@@ -149,6 +150,8 @@
//------------------------------ private members ---------------------------------------
+
+ private ServletUnitClient _client;
private WebApplication _application;
private ServletUnitHttpRequest _request;
Index: ServletRunner.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletRunner.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- ServletRunner.java 23 Jun 2002 23:52:39 -0000 1.17
+++ ServletRunner.java 1 Aug 2002 14:58:59 -0000 1.18
@@ -185,8 +185,8 @@
private ServletUnitContext _context;
private InvocationContextFactory _factory = new InvocationContextFactory() {
- public InvocationContext newInvocation( WebRequest request, Cookie[] clientCookies, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException {
- return new InvocationContextImpl( ServletRunner.this, request, clientCookies, clientHeaders, messageBody );
+ public InvocationContext newInvocation( ServletUnitClient client, WebRequest request, Cookie[] clientCookies, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException {
+ return new InvocationContextImpl( client, ServletRunner.this, request, clientCookies, clientHeaders, messageBody );
}
};
Index: ServletUnitClient.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitClient.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ServletUnitClient.java 23 Jun 2002 23:52:39 -0000 1.6
+++ ServletUnitClient.java 1 Aug 2002 14:58:59 -0000 1.7
@@ -72,7 +72,7 @@
public InvocationContext newInvocation( WebRequest request ) throws IOException, MalformedURLException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
writeMessageBody( request, baos );
- return _invocationContextFactory.newInvocation( request, getCookies(), this.getHeaderFields(), baos.toByteArray() );
+ return _invocationContextFactory.newInvocation( this, request, getCookies(), this.getHeaderFields(), baos.toByteArray() );
}
Index: ServletUnitWebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitWebResponse.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ServletUnitWebResponse.java 6 Mar 2002 04:59:52 -0000 1.9
+++ ServletUnitWebResponse.java 1 Aug 2002 14:58:59 -0000 1.10
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2001, Russell Gold
+* Copyright (c) 2000-2002, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -52,8 +52,8 @@
* @param url the url from which the response was received
* @param response the response populated by the servlet
**/
- ServletUnitWebResponse( String target, URL url, HttpServletResponse response ) throws IOException {
- super( target, url );
+ ServletUnitWebResponse( ServletUnitClient client, String target, URL url, HttpServletResponse response ) throws IOException {
+ super( client, target, url );
_response = (ServletUnitHttpResponse) response;
defineRawInputStream( new ByteArrayInputStream( _response.getContents() ) );
}
|
|
From: Russell G. <rus...@us...> - 2002-08-01 14:59:03
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv9683/test/com/meterware/httpunit
Modified Files:
WebFormTest.java WebLinkTest.java
Log Message:
Support link.click and form.submit
Index: WebFormTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFormTest.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- WebFormTest.java 24 Jul 2002 17:32:08 -0000 1.22
+++ WebFormTest.java 1 Aug 2002 14:58:59 -0000 1.23
@@ -65,6 +65,20 @@
}
+ public void testSubmitFromForm() throws Exception {
+ defineWebPage( "Form", "<form method=GET id=main action = 'tryMe'>" +
+ "<Input type=text Name=name>" +
+ "<input type=\"checkbox\" name=second checked>Enabled" +
+ "</form>" );
+ defineResource( "/tryMe?name=master&second=on", "You made it!" );
+ WebResponse wr = _wc.getResponse( getHostPath() + "/Form.html" );
+ WebForm form = wr.getFormWithID( "main" );
+ form.setParameter( "name", "master" );
+ form.submit();
+ assertEquals( "Expected response", "You made it!", _wc.getCurrentPage().getText() );
+ }
+
+
public void testFindNoForm() throws Exception {
defineWebPage( "NoForms", "This has no forms but it does" +
"have <a href=\"/other.html\">an active link</A>" +
Index: WebLinkTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebLinkTest.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- WebLinkTest.java 30 Jul 2002 13:17:49 -0000 1.21
+++ WebLinkTest.java 1 Aug 2002 14:58:59 -0000 1.22
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2001, Russell Gold
+* Copyright (c) 2000-2002, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -166,7 +166,7 @@
assertEquals( "Num links in next page", 1, nextPage.getLinks().length );
link = nextPage.getLinks()[0];
- wc.sendRequest( link.getRequest() );
+ link.click();
assertEquals( "Title of next page", "Initial", wc.getFrameContents( link.getTarget() ).getTitle() );
}
|
|
From: Russell G. <rus...@us...> - 2002-07-30 14:11:17
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv29389/src/com/meterware/httpunit
Modified Files:
WebClient.java WebFrame.java
Log Message:
Started refactoring towards link.click
Index: WebClient.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- WebClient.java 26 Jun 2002 15:48:56 -0000 1.24
+++ WebClient.java 30 Jul 2002 14:11:15 -0000 1.25
@@ -113,7 +113,7 @@
* any listeners or preferences which may have been set.
**/
public void clearContents() {
- _frameContents = new Hashtable();
+ _frameContents = new FrameHolderImpl();
_cookies = new Hashtable();
_headers = new HeaderDictionary();
}
@@ -123,14 +123,7 @@
* Returns the name of the currently active frames.
**/
public String[] getFrameNames() {
- Vector names = new Vector();
- for (Enumeration e = _frameContents.keys(); e.hasMoreElements();) {
- names.addElement( e.nextElement() );
- }
-
- String[] result = new String[ names.size() ];
- names.copyInto( result );
- return result;
+ return _frameContents.getFrameNames();
}
@@ -339,7 +332,7 @@
/** A map of frame names to current contents. **/
- private Hashtable _frameContents = new Hashtable();
+ private FrameHolderImpl _frameContents = new FrameHolderImpl();
/** A map of frame names to frames nested within them. **/
@@ -492,6 +485,38 @@
public String getMethod() {
return "GET";
}
+}
+
+
+
+class FrameHolderImpl {
+ private Hashtable _contents = new Hashtable();
+
+ void put( String targetName, WebResponse contents ) {
+ _contents.put( targetName, contents );
+ }
+
+
+ WebResponse get( String targetName ) {
+ return (WebResponse) _contents.get( targetName );
+ }
+
+ void remove( String targetName ) {
+ _contents.remove( targetName );
+ }
+
+
+ public String[] getFrameNames() {
+ Vector names = new Vector();
+ for (Enumeration e = _contents.keys(); e.hasMoreElements();) {
+ names.addElement( e.nextElement() );
+ }
+
+ String[] result = new String[ names.size() ];
+ names.copyInto( result );
+ return result;
+ }
+
}
Index: WebFrame.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebFrame.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- WebFrame.java 15 Jul 2002 16:42:44 -0000 1.7
+++ WebFrame.java 30 Jul 2002 14:11:15 -0000 1.8
@@ -51,12 +51,19 @@
}
+ /**
+ * Given the qualified name of a frame and the name of a nested frame, returns the qualified name of the nested frame.
+ */
static String getNestedFrameName( String parentFrameName, final String relativeName ) {
if (parentFrameName.equalsIgnoreCase( WebRequest.TOP_FRAME )) return relativeName;
return parentFrameName + ':' + relativeName;
}
+ /**
+ * Returns the qualified name of a target frame.
+ *
+ */
static String getTargetFrameName( String sourceFrameName, final String relativeName ) {
if (relativeName.equalsIgnoreCase( "_parent" )) return getParentFrameName( sourceFrameName );
if (sourceFrameName.indexOf( ':' ) < 0) return relativeName;
|
|
From: Russell G. <rus...@us...> - 2002-07-30 14:11:17
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv29389/doc Modified Files: faq.html Log Message: Started refactoring towards link.click Index: faq.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/faq.html,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- faq.html 25 Jul 2002 11:19:18 -0000 1.13 +++ faq.html 30 Jul 2002 14:11:14 -0000 1.14 @@ -91,7 +91,7 @@ <li>If you call <code>HttpUnitOptions.setParameterValuesValidated( false )</code> before calling getRequest on your form, the request will be created with validation disabled and you will be able to set any values you like. Note that in such a case the order of parameters in the request is not guaranteed, in case your server cares about such things (servlets do not). -<li>You can call <code><form>.getScriptableObject().setParameterValue( <name>, <valuem> );</code> to change +<li>You can call <code><form>.getScriptableObject().setParameterValue( <name>, <value> );</code> to change the underlying value in the form. This will behave the way JavaScript does - resetting the form will now restore this value, rather than the original one. </ul> |
|
From: Russell G. <rus...@us...> - 2002-07-30 13:17:52
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv6811/test/com/meterware/httpunit
Modified Files:
WebLinkTest.java
Log Message:
Use sendRequest to test link following
Index: WebLinkTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebLinkTest.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- WebLinkTest.java 25 Jul 2002 11:19:18 -0000 1.20
+++ WebLinkTest.java 30 Jul 2002 13:17:49 -0000 1.21
@@ -166,8 +166,8 @@
assertEquals( "Num links in next page", 1, nextPage.getLinks().length );
link = nextPage.getLinks()[0];
- WebResponse thirdPage = wc.getResponse( link.getRequest() );
- assertEquals( "Title of next page", "Initial", thirdPage.getTitle() );
+ wc.sendRequest( link.getRequest() );
+ assertEquals( "Title of next page", "Initial", wc.getFrameContents( link.getTarget() ).getTitle() );
}
|
|
From: Russell G. <rus...@us...> - 2002-07-30 13:16:55
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv6148/src/com/meterware/httpunit
Modified Files:
WebResponse.java
Log Message:
Test for content type case-insensitive
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -r1.68 -r1.69
--- WebResponse.java 24 Jul 2002 20:54:31 -0000 1.68
+++ WebResponse.java 30 Jul 2002 13:16:52 -0000 1.69
@@ -66,7 +66,7 @@
* Returns true if the response is HTML.
**/
public boolean isHTML() {
- return getContentType().equals( HTML_CONTENT );
+ return getContentType().equalsIgnoreCase( HTML_CONTENT );
}
|
|
From: Russell G. <rus...@us...> - 2002-07-30 13:16:55
|
Update of /cvsroot/httpunit/httpunit/doc
In directory usw-pr-cvs1:/tmp/cvs-serv6148/doc
Modified Files:
release_notes.txt
Log Message:
Test for content type case-insensitive
Index: release_notes.txt
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v
retrieving revision 1.121
retrieving revision 1.122
diff -u -r1.121 -r1.122
--- release_notes.txt 25 Jul 2002 11:19:18 -0000 1.121
+++ release_notes.txt 30 Jul 2002 13:16:52 -0000 1.122
@@ -12,6 +12,13 @@
Revision History:
+29-Jul-2002
+Acknowledgements:
+ Thanks to Sebastien Rosset for pointing out the case sensitivity problem with WebResponse.isHTML
+
+Problems fixed:
+ 1. WebResponses are now recognized as HTML even if the content type is not lower case.
+
Acknowledgements:
Thanks to Rajan Narasimhan for fixing the relative URL computation problem.
|
|
From: Russell G. <rus...@us...> - 2002-07-25 11:19:21
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv28540/doc Modified Files: faq.html release_notes.txt Log Message: Rajan Narasimhan: fixed problem with base URLs containing slash in a query string Index: faq.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/faq.html,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- faq.html 20 Jun 2002 15:39:29 -0000 1.12 +++ faq.html 25 Jul 2002 11:19:18 -0000 1.13 @@ -7,15 +7,14 @@ <OL> <LI><A HREF="#Cannot unzip">Why can't I unzip the download library?</A></LI> <LI><A HREF="#org.xml.sax">What is the org.xml.sax package?</A></LI> -<LI><A HREF="#meterware.com">Where is meterware.com?</A></LI> <LI><A HREF="#javascript">How do I use HttpUnit to test my pages that use JavaScript?</A></LI> <LI><A HREF="sslfaq.html">Does HttpUnit support https?</A></LI> <LI><A HREF="#proxy">Can I use HttpUnit through a proxy server?</A></LI> <LI><A HREF="#charset">Why isn't HttpUnit handling my non-English pages?</A></LI> -<LI><A HREF="#utf8">HttpUnit fails with an IllegalArgumentException: sun.io.CharToByteUTF-8, what do I do?</A></LI> <LI><A HREF="#buttons">HttpUnit is not finding the buttons and parameters in my forms. What is wrong?</A></LI> <LI><A HREF="#reload">Why do I get java.lang.IllegalAccessError when calling getResponse()?</A></LI> <LI><A HREF="#badPost">Why doesn't my servlet see parameters on a POST request?</A></LI> +<LI><A HREF="#hidden">Why can't I change hidden parameters?</A></LI> </OL> @@ -30,15 +29,9 @@ <A HREF="http://sourceforge.net/project/showfiles.php?group_id=13153">its SourceForge download page</A> and install Tidy.jar in your classpath. -<A NAME="meterware.com"><H2>Where is meterware.com?</H2></A> -When I started HttpUnit, I had a web site with the meterware.com domain, and relied on it to host some of the example code. -Since then, my ISP has dropped the hosting package I was using and I have not yet signed up with another host, mostly due to -lack of funds. I hope to correct this in the near future. - <A NAME="javascript"><H2>How do I use HttpUnit to test my pages that use JavaScript?</H2></A> -Unfortunately, you can't. HttpUnit does not support any dialect of JavaScript. I have been shown a JavaScript library and it is possible -that I will one day add JavaScript support, but since I use it very little in my own development, and since it looks like a lot of work, -it is not a major priority for me. If you feel ambitious enough to add JavaScript support yourself, I would be happy to accept submissions. +Unfortunately, you can't - yet. I have started to add JavaScript support, but it is very basic as yet. +If you would like to help out, please examine the code in cvs. <A NAME="proxy"><H2>Can I use HttpUnit through a proxy server?</H2></A> Yes. HttpUnit uses java.net.HttpURLConnection, so the @@ -65,14 +58,6 @@ </code></blockquote> where the proper encoding should be substituted for "EUC_JP". The <code>getBytes</code> call is needed to extract the raw bytes from the parameter string. -<A NAME="utf8"><H2>HttpUnit fails with an IllegalArgumentException: -sun.io.CharToByteUTF-8, what do I do?</H2></A> -JTidy requires bytes, not characters, and HttpUnit 1.2.1 sends it bytes in UTF-8 -encoding, which it obtains from the input page -using <code>getBytes( "UTF-8" )</code>. Unfortunately, Sun used the wrong -encoding name in its JDK 1.1.x implementations, so this code -fails under JDK 1.1. This has been corrected in HttpUnit 1.2.2. - <A NAME="buttons"><H2>HttpUnit is not finding the buttons and parameters in my forms. What is wrong?</H2></A> This often happens when your HTML is not valid. Most browsers are extremely forgiving of bad HTML; however, JTidy (the HTML parser used by HttpUnit) is not. It expects tags to be nested according to the HTML specification and @@ -94,10 +79,23 @@ tests to reload safely.</ul></p> <p>This problem appears to be resolved in JTidy r7, which is included with HttpUnit 1.4.1 or later. -<A HREF="#badPost"><H2>Why doesn't my servlet see parameters on a POST request?</H2></A> +<A NAME="#badPost"><H2>Why doesn't my servlet see parameters on a POST request?</H2></A> Some older servlet engines, such as Tomcat 3.1, get confused when they see a charset attribute on the Content-Type header. HttpUnit 1.2.6 sends this attribute; As of HttpUnit 1.2.7 it will only send it if you call <code>HttpUnitOptions.setPostIncludesCharset(true)</code> before your request. + +<A name="#hidden"><h2>Why can't I change hidden parameter values?</h2></A> +By default, HttpUnit verifies any parameter value changes against the form containing them. Since a user cannot directly +change hidden parameters, HttpUnit stops you from doing it in your code. If you have to change these values, you have a couple +of choices:<ul> +<li>If you call <code>HttpUnitOptions.setParameterValuesValidated( false )</code> before calling getRequest on your form, +the request will be created with validation disabled and you will be able to set any values you like. Note that in such a case +the order of parameters in the request is not guaranteed, in case your server cares about such things (servlets do not). +<li>You can call <code><form>.getScriptableObject().setParameterValue( <name>, <valuem> );</code> to change +the underlying value in the form. This will behave the way JavaScript does - resetting the form will now restore this value, +rather than the original one. +</ul> + </BODY></HTML> Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.120 retrieving revision 1.121 diff -u -r1.120 -r1.121 --- release_notes.txt 24 Jul 2002 20:54:31 -0000 1.120 +++ release_notes.txt 25 Jul 2002 11:19:18 -0000 1.121 @@ -12,6 +12,13 @@ Revision History: +Acknowledgements: + Thanks to Rajan Narasimhan for fixing the relative URL computation problem. + +25-Jul-2002 +Problems fixed: + 1. Relative URLs were not being computed properly when the base URL had a query string containing a slash. + 24-Jul-2002 Additions: 1. PseudoServer and associated classes are now publically available and in their own package, pseudoserver. |
|
From: Russell G. <rus...@us...> - 2002-07-25 11:19:21
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv28540/src/com/meterware/httpunit
Modified Files:
WebRequest.java
Log Message:
Rajan Narasimhan: fixed problem with base URLs containing slash in a query string
Index: WebRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- WebRequest.java 20 May 2002 16:00:43 -0000 1.41
+++ WebRequest.java 25 Jul 2002 11:19:18 -0000 1.42
@@ -69,7 +69,13 @@
**/
public URL getURL() throws MalformedURLException {
if (getURLBase() == null || getURLString().indexOf( ':' ) > 0) validateProtocol( getURLString() );
- return new URL( getURLBase(), getURLString() );
+ if (getURLBase() == null || getURLBase().toString().indexOf( "?" ) < 0) {
+ return new URL( getURLBase(), getURLString() );
+ } else {
+ final String urlBaseString = getURLBase().toString();
+ URL newurlbase = new URL( urlBaseString.substring( 0, urlBaseString.indexOf( "?" ) ) );
+ return new URL( newurlbase, getURLString() );
+ }
}
|
|
From: Russell G. <rus...@us...> - 2002-07-25 11:19:21
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv28540/test/com/meterware/httpunit
Modified Files:
WebLinkTest.java
Log Message:
Rajan Narasimhan: fixed problem with base URLs containing slash in a query string
Index: WebLinkTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebLinkTest.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- WebLinkTest.java 23 Jan 2002 18:35:56 -0000 1.19
+++ WebLinkTest.java 25 Jul 2002 11:19:18 -0000 1.20
@@ -192,6 +192,23 @@
}
+ public void testLinksWithSlashesInQuery() throws Exception {
+ WebConversation wc = new WebConversation();
+ defineResource( "sample/Initial.html?age=3/5", "<html><head><title>Initial</title></head><body>" +
+ "Go to <a href=\"Next.html\">the next page.</a>" +
+ "</body></html>" );
+ defineWebPage( "sample/Next", "And go back to <a href=\"Initial.html?age=3/5\">the first page.</a>" );
+
+ WebResponse initialPage = wc.getResponse( getHostPath() + "/sample/Initial.html?age=3/5" );
+ assertEquals( "Num links in initial page", 1, initialPage.getLinks().length );
+ WebLink link = initialPage.getLinks()[0];
+
+ WebResponse nextPage = wc.getResponse( link.getRequest() );
+ assertEquals( "Title of next page", "sample/Next", nextPage.getTitle() );
+ assertEquals( "Num links in next page", 1, nextPage.getLinks().length );
+ }
+
+
public void testDocumentBase() throws Exception {
WebConversation wc = new WebConversation();
defineWebPage( "alternate/Target", "Found me!" );
|
|
From: Russell G. <rus...@us...> - 2002-07-24 21:05:53
|
Update of /cvsroot/httpunit/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv14374
Modified Files:
build.xml
Log Message:
Ensure that build does not fail w/o Rhino
Index: build.xml
===================================================================
RCS file: /cvsroot/httpunit/httpunit/build.xml,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- build.xml 20 Jun 2002 15:35:17 -0000 1.43
+++ build.xml 24 Jul 2002 21:05:51 -0000 1.44
@@ -51,6 +51,8 @@
classpathref="base.classpath" />
<available property="xerces.present" classname="org.apache.xerces.parsers.DOMParser"
classpathref="base.classpath" />
+ <available property="rhino.present" classname="org.mozilla.javascript.Context"
+ classpathref="base.classpath" />
</target>
@@ -72,6 +74,7 @@
debug="${debug}" deprecation="${deprecation}" optimize="${optimize}">
<classpath refid="base.classpath" />
<exclude name="**/servletunit/*" unless="jsdk.present" />
+ <exclude name="**/javascript/*" unless="rhino.present" />
</javac>
</target>
@@ -90,6 +93,7 @@
<exclude name="**/servletunit/*" unless="jsdk.present" />
<exclude name="**/FileUploadTest.java" unless="javamail.present" />
<exclude name="**/XMLPageTest.java" unless="xerces.present" />
+ <exclude name="**/javascript/*" unless="rhino.present" />
</javac>
</target>
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv10054/src/com/meterware/httpunit
Modified Files:
FormControl.java ScriptableObject.java WebForm.java
WebResponse.java
Added Files:
HTMLPage.java ScriptEngine.java
Removed Files:
ReceivedPage.java
Log Message:
Initialize JavaScript implementation
***** Error reading new file[Errno 2] No such file or directory: 'HTMLPage.java'
***** Error reading new file[Errno 2] No such file or directory: 'ScriptEngine.java'
Index: FormControl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- FormControl.java 14 May 2002 18:38:54 -0000 1.11
+++ FormControl.java 24 Jul 2002 20:54:31 -0000 1.12
@@ -240,16 +240,7 @@
}
- class Scriptable implements ScriptableObject {
-
- public Object get( String propertyName ) {
- throw new RuntimeException( "Unknown property: " + propertyName );
- }
-
-
- public void set( String propertyName, Object value ) {
- throw new RuntimeException( "Unknown property: " + propertyName );
- }
+ class Scriptable extends ScriptableObject {
}
}
Index: ScriptableObject.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ScriptableObject.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ScriptableObject.java 8 Apr 2002 18:40:23 -0000 1.1
+++ ScriptableObject.java 24 Jul 2002 20:54:31 -0000 1.2
@@ -25,17 +25,42 @@
*
* @author <a href="mailto:rus...@ac...">Russell Gold</a>
**/
-public interface ScriptableObject {
+abstract public class ScriptableObject {
+
+ private ScriptEngine _scriptEngine;
+
+
+ /**
+ * Executes the specified scripted event.
+ **/
+ public void doEvent( String eventScript ) {
+ if (_scriptEngine == null) throw new IllegalStateException( "Script engine must be defined before running an event" );
+ _scriptEngine.executeScript( eventScript );
+ }
+
/**
- * Returns the value of the named property. Will throw a runtime exception if the property does not exist.
+ * Returns the value of the named property. Will return null if the property does not exist.
**/
- public Object get( String propertyName );
+ public Object get( String propertyName ) {
+ return null;
+ }
/**
* Sets the value of the named property. Will throw a runtime exception if the property does not exist or
* cannot accept the specified value.
**/
- public void set( String propertyName, Object value );
+ public void set( String propertyName, Object value ) {
+ throw new RuntimeException( "No such property: " + propertyName );
+ }
+
+
+ /**
+ * Specifies the scripting engine to be used.
+ */
+ public void setScriptEngine( ScriptEngine scriptEngine ) {
+ _scriptEngine = scriptEngine;
+ }
+
}
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- WebForm.java 8 Apr 2002 18:40:23 -0000 1.49
+++ WebForm.java 24 Jul 2002 20:54:31 -0000 1.50
@@ -400,17 +400,13 @@
}
- public class Scriptable implements ScriptableObject {
+ public class Scriptable extends ScriptableObject {
public String getAction() { return WebForm.this.getAction(); }
public void setAction( String newAction ) { _action = newAction; }
public void setParameterValue( String name, String value ) {
getParameter( name ).getScriptableObject().set( "value", value );
}
-
-
- public void set( String propertyName, Object value ) {}
- public Object get( String propertyName ) { return null; }
}
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -r1.67 -r1.68
--- WebResponse.java 15 Jul 2002 14:30:32 -0000 1.67
+++ WebResponse.java 24 Jul 2002 20:54:31 -0000 1.68
@@ -33,6 +33,7 @@
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
+import java.util.LinkedList;
import java.util.zip.GZIPInputStream;
import org.w3c.dom.Document;
@@ -453,6 +454,50 @@
}
+//---------------------------------------- JavaScript methods ----------------------------------------
+
+ private LinkedList _alerts = new LinkedList();
+
+ /**
+ * Returns the next javascript alert without removing it from the queue.
+ */
+ public String getNextAlert() {
+ return _alerts.isEmpty() ? null : (String) _alerts.getFirst();
+ }
+
+
+ /**
+ * Returns the next javascript alert and removes it from the queue.
+ */
+ public String popNextAlert() {
+ return (String) _alerts.removeFirst();
+ }
+
+
+ public Scriptable getScriptableObject() {
+ return new Scriptable();
+ }
+
+
+ public class Scriptable extends ScriptableObject {
+
+ public void alert( String message ) {
+ _alerts.addLast( message );
+ }
+
+
+ public HTMLPage.Scriptable getDocument() throws SAXException {
+ return getReceivedPage().getScriptableObject();
+ }
+
+
+ public void load() throws SAXException {
+ doEvent( getReceivedPage().getScripts() );
+ doEvent( getReceivedPage().getOnLoadEvent() );
+ }
+ }
+
+
//---------------------------------------- Object methods --------------------------------------------
abstract
@@ -586,7 +631,7 @@
private WebFrame[] _frames;
- private ReceivedPage _page;
+ private HTMLPage _page;
private String _contentHeader;
@@ -863,11 +908,11 @@
}
- private ReceivedPage getReceivedPage() throws SAXException {
+ private HTMLPage getReceivedPage() throws SAXException {
if (_page == null) {
try {
if (!isHTML()) throw new NotHTMLException( getContentType() );
- _page = new ReceivedPage( _url, _frameName, getText(), getCharacterSet() );
+ _page = new HTMLPage( _url, _frameName, getText(), getCharacterSet() );
} catch (IOException e) {
throw new SAXException( e );
}
|
|
From: Russell G. <rus...@us...> - 2002-07-24 20:54:34
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv10054/src/com/meterware/httpunit/javascript Added Files: JavaScript.java Log Message: Initialize JavaScript implementation ***** Error reading new file[Errno 2] No such file or directory: 'JavaScript.java' |