httpunit-commit Mailing List for httpunit (Page 67)
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-01-09 23:22:13
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv30652/src/com/meterware/httpunit
Modified Files:
GetMethodWebRequest.java MessageBodyWebRequest.java
PostMethodWebRequest.java UncheckedParameterCollection.java
WebForm.java WebLink.java WebRequest.java
WebRequestSource.java
Log Message:
Move more common behavior to WebRequestSource
Index: GetMethodWebRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/GetMethodWebRequest.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- GetMethodWebRequest.java 2001/11/09 18:35:14 1.9
+++ GetMethodWebRequest.java 2002/01/09 23:22:10 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
@@ -65,8 +65,8 @@
/**
* Constructs a web request for a form.
**/
- GetMethodWebRequest( URL urlBase, String urlString, String target, WebForm sourceForm, SubmitButton button ) {
- super( urlBase, urlString, target, sourceForm, button );
+ GetMethodWebRequest( WebForm sourceForm, SubmitButton button ) {
+ super( sourceForm, button );
}
Index: MessageBodyWebRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/MessageBodyWebRequest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MessageBodyWebRequest.java 2001/11/26 14:20:12 1.3
+++ MessageBodyWebRequest.java 2002/01/09 23:22:10 1.4
@@ -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
@@ -90,8 +90,8 @@
/**
* Constructs a web request for a form.
**/
- MessageBodyWebRequest( URL urlBase, String urlString, String target, WebForm sourceForm, SubmitButton button ) {
- super( urlBase, urlString, target, sourceForm, button );
+ MessageBodyWebRequest( WebForm sourceForm, SubmitButton button ) {
+ super( sourceForm, button );
}
Index: PostMethodWebRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/PostMethodWebRequest.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- PostMethodWebRequest.java 2001/11/26 14:20:12 1.19
+++ PostMethodWebRequest.java 2002/01/09 23:22:10 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
@@ -149,8 +149,8 @@
/**
* Constructs a web request for a form.
**/
- PostMethodWebRequest( URL urlBase, String urlString, String target, WebForm sourceForm, SubmitButton button ) {
- super( urlBase, urlString, target, sourceForm, button );
+ PostMethodWebRequest( WebForm sourceForm, SubmitButton button ) {
+ super( sourceForm, button );
}
Index: UncheckedParameterCollection.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/UncheckedParameterCollection.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UncheckedParameterCollection.java 2002/01/08 23:21:53 1.1
+++ UncheckedParameterCollection.java 2002/01/09 23:22:10 1.2
@@ -24,6 +24,7 @@
import java.util.Hashtable;
import java.util.Enumeration;
+import java.net.URLEncoder;
/**
@@ -34,6 +35,87 @@
Hashtable _parameters = new Hashtable();
private static final String[] NO_VALUES = new String[ 0 ];
+ private final String _characterSet;
+
+
+ UncheckedParameterCollection() {
+ _characterSet = "iso-8859-1";
+ }
+
+
+ UncheckedParameterCollection( WebRequestSource source ) {
+ _characterSet = source.getCharacterSet();
+ String[] names = source.getParameterNames();
+ for (int i = 0; i < names.length; i++) {
+ if (names[i].length() > 0 && !source.isFileParameter( names[i] )) {
+ _parameters.put( names[i], source.getParameterValues( names[i] ) );
+ }
+ }
+ }
+
+
+ String getParameterString() {
+ StringBuffer sb = new StringBuffer(HttpUnitUtils.DEFAULT_BUFFER_SIZE);
+ Enumeration e = _parameters.keys();
+
+ while (e.hasMoreElements()) {
+ String name = (String) e.nextElement();
+ Object value = _parameters.get( name );
+ if (value instanceof String) {
+ appendParameter( sb, name, (String) value, e.hasMoreElements() );
+ } else {
+ appendParameters( sb, name, (String[]) value, e.hasMoreElements() );
+ }
+ }
+ return sb.toString();
+ }
+
+
+ private void appendParameters( StringBuffer sb, String name, String[] values, boolean moreToCome ) {
+ for (int i = 0; i < values.length; i++) {
+ appendParameter( sb, name, values[i], (i < values.length-1 || moreToCome ) );
+ }
+ }
+
+
+ private void appendParameter( StringBuffer sb, String name, String value, boolean moreToCome ) {
+ sb.append( encode( name ) );
+ if (value != null) sb.append( '=' ).append( encode( value ) );
+ if (moreToCome) sb.append( '&' );
+ }
+
+
+ /**
+ * Returns a URL-encoded version of the string, including all eight bits, unlike URLEncoder, which strips the high bit.
+ **/
+ private String encode( String source ) {
+ if (_characterSet.equalsIgnoreCase( "iso-8859-1" )) {
+ return URLEncoder.encode( source );
+ } else {
+ try {
+ byte[] rawBytes = source.getBytes( _characterSet );
+ StringBuffer result = new StringBuffer(HttpUnitUtils.DEFAULT_BUFFER_SIZE);
+ for (int i = 0; i < rawBytes.length; i++) {
+ int candidate = rawBytes[i] & 0xff;
+ if (candidate == ' ') {
+ result.append( '+' );
+ } else if ((candidate >= 'A' && candidate <= 'Z') ||
+ (candidate >= 'a' && candidate <= 'z') ||
+ (candidate == '.') ||
+ (candidate >= '0' && candidate <= '9')) {
+ result.append( (char) rawBytes[i] );
+ } else if (candidate < 16) {
+ result.append( "%0" ).append( Integer.toHexString( candidate ).toUpperCase() );
+ } else {
+ result.append( '%' ).append( Integer.toHexString( candidate ).toUpperCase() );
+ }
+ }
+ return result.toString();
+ } catch (java.io.UnsupportedEncodingException e) {
+ return "????"; // XXX should pass the exception through as IOException ultimately
+ }
+ }
+ }
public Enumeration getParameterNames() {
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- WebForm.java 2002/01/09 12:57:48 1.39
+++ WebForm.java 2002/01/09 23:22:10 1.40
@@ -95,8 +95,7 @@
/**
- * Returns an array containing the names of the parameters defined for this form,
- * in the order in which they appear.
+ * Returns an array containing the names of the parameters defined for this form.
**/
public String[] getParameterNames() {
ArrayList parameterNames = new ArrayList( getFormParameters().keySet() );
@@ -283,24 +282,18 @@
}
}
- String action = getAction();
- if (action.trim().length() == 0) action = getBaseURL().getFile();
-
- WebRequest request;
if (getMethod().equalsIgnoreCase( "post" )) {
- request = new PostMethodWebRequest( getBaseURL(), action, getTarget(), this, button );
+ return new PostMethodWebRequest( this, button );
} else {
- request = new GetMethodWebRequest( getBaseURL(), action, getTarget(), this, button );
+ return new GetMethodWebRequest( this, button );
}
+ }
- String[] parameterNames = getParameterNames();
- for (int i = 0; i < parameterNames.length; i++) {
- if (parameterNames[i].length() > 0 && !isFileParameter( parameterNames[i] )) {
- request.setParameter( parameterNames[i], getParameterValues( parameterNames[i] ) );
- }
- }
- request.setHeaderField( "Referer", getBaseURL().toExternalForm() );
- return request;
+
+ String getRelativeURL() {
+ String action = getAction();
+ if (action.trim().length() == 0) action = getBaseURL().getFile();
+ return action;
}
Index: WebLink.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- WebLink.java 2001/11/27 16:40:47 1.13
+++ WebLink.java 2002/01/09 23:22:10 1.14
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2001, Russell Gold
+* Copyright (c) 2000-2002, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -21,8 +21,10 @@
*******************************************************************************************************************/
import java.net.URL;
-import java.util.Enumeration;
-import java.util.Hashtable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
import java.util.StringTokenizer;
import org.w3c.dom.Node;
@@ -38,10 +40,41 @@
public class WebLink extends WebRequestSource {
/**
+ * Returns the URL referenced by this link. This may be a relative URL.
+ **/
+ public String getURLString() {
+ String href = NodeUtils.getNodeAttribute( getNode(), "href" );
+ final int hashIndex = href.indexOf( '#' );
+ if (hashIndex < 0) {
+ return href;
+ } else {
+ return href.substring( 0, hashIndex );
+ }
+ }
+
+
+ /**
+ * Returns the text value of this link.
+ **/
+ public String asText() {
+ if (getNode().getNodeName().equals( "area" )) {
+ return NodeUtils.getNodeAttribute( getNode(), "alt" );
+ } else if (!getNode().hasChildNodes()) {
+ return "";
+ } else {
+ return NodeUtils.asText( getNode().getChildNodes() );
+ }
+ }
+
+
+//----------------------------------------- WebRequestSource methods ---------------------------------------------------
+
+
+ /**
* Creates and returns a web request which will simulate clicking on this link.
**/
public WebRequest getRequest() {
- WebRequest request = new GetMethodWebRequest( getBaseURL(), getBareURL(), getTarget() );
+ WebRequest request = new GetMethodWebRequest( getBaseURL(), getRelativeURL(), getTarget() );
addPresetParameters( request );
request.setHeaderField( "Referer", getBaseURL().toExternalForm() );
return request;
@@ -49,9 +82,27 @@
/**
- * Strips a URL from its parameters
+ * Returns an array containing the names of any parameters defined as part of this link's URL.
**/
- private String getBareURL() {
+ public String[] getParameterNames() {
+ ArrayList parameterNames = new ArrayList( getPresetParameters().keySet() );
+ return (String[]) parameterNames.toArray( new String[ parameterNames.size() ] );
+ }
+
+
+ /**
+ * Returns the multiple default values of the named parameter.
+ **/
+ public String[] getParameterValues( String name ) {
+ final String[] values = (String[]) getPresetParameters().get( name );
+ return values == null ? NO_VALUES : values;
+ }
+
+
+ /**
+ * Returns the HREF URL w/o its parameters.
+ **/
+ String getRelativeURL() {
final String url = getURLString();
final int questionMarkIndex = url.indexOf("?");
if (questionMarkIndex >= 1 && questionMarkIndex < url.length() - 1) {
@@ -61,11 +112,32 @@
}
+//--------------------------------------------------- package members --------------------------------------------------
+
+
+ /**
+ * 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, parentTarget );
+ }
+
+
+//--------------------------------------------------- private members --------------------------------------------------
+
+
+ private static final String[] NO_VALUES = new String[0];
+ private static final String PARAM_DELIM = "&";
+
+ private Map _presetParameters;
+
+
private void addPresetParameters(WebRequest request) {
- Hashtable params = getPresetParameters();
- Enumeration e = params.keys();
- while (e.hasMoreElements()) {
- String key = (String) e.nextElement();
+ Map params = getPresetParameters();
+ Iterator i = params.keySet().iterator();
+ while (i.hasNext()) {
+ String key = (String) i.next();
request.setParameter( key, (String[]) params.get( key ) );
}
}
@@ -87,18 +159,20 @@
/**
* Builds list of parameters
**/
- private Hashtable getPresetParameters() {
- Hashtable params = new Hashtable();
- StringTokenizer st = new StringTokenizer( getParametersString(), PARAM_DELIM );
- while (st.hasMoreTokens()) stripOneParameter( params, st.nextToken() );
- return params;
+ private Map getPresetParameters() {
+ if (_presetParameters == null) {
+ _presetParameters = new HashMap();
+ StringTokenizer st = new StringTokenizer( getParametersString(), PARAM_DELIM );
+ while (st.hasMoreTokens()) stripOneParameter( _presetParameters, st.nextToken() );
+ }
+ return _presetParameters;
}
/**
* add a pair key-value to the hashtable, creates an array of values if param already exists.
**/
- private void stripOneParameter( Hashtable params, String param ) {
+ private void stripOneParameter( Map params, String param ) {
final int index = param.indexOf( "=" );
String value = ((index < 0) ? null
: ((index == param.length() - 1)
@@ -124,49 +198,5 @@
return result;
}
-
- /**
- * Returns the URL referenced by this link. This may be a relative URL.
- **/
- public String getURLString() {
- String href = NodeUtils.getNodeAttribute( getNode(), "href" );
- final int hashIndex = href.indexOf( '#' );
- if (hashIndex < 0) {
- return href;
- } else {
- return href.substring( 0, hashIndex );
- }
- }
-
-
- /**
- * Returns the text value of this link.
- **/
- public String asText() {
- if (getNode().getNodeName().equals( "area" )) {
- return NodeUtils.getNodeAttribute( getNode(), "alt" );
- } else if (!getNode().hasChildNodes()) {
- return "";
- } else {
- return NodeUtils.asText( getNode().getChildNodes() );
- }
- }
-
-
-//---------------------------------- package members --------------------------------
-
-
- /**
- * 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, parentTarget );
- }
-
-//---------------------------------- private members --------------------------------
-
- private static final Hashtable NO_PARAMS = new Hashtable();
- private static final String PARAM_DELIM = "&";
}
Index: WebRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- WebRequest.java 2002/01/08 23:21:53 1.32
+++ WebRequest.java 2002/01/09 23:22:10 1.33
@@ -235,10 +235,13 @@
/**
* Constructs a web request from a form.
**/
- protected WebRequest( URL urlBase, String urlString, String target, WebForm sourceForm, SubmitButton button ) {
- this( urlBase, urlString, target );
+ protected WebRequest( WebForm sourceForm, SubmitButton button ) {
+ this( sourceForm.getBaseURL(), sourceForm.getRelativeURL(), sourceForm.getTarget() );
_sourceForm = sourceForm;
+ _parameterCollection = new UncheckedParameterCollection( sourceForm );
+ setHeaderField( "Referer", sourceForm.getBaseURL().toExternalForm() );
+
if (button != null && button.getName().length() > 0) {
_parameterCollection._parameters.put( button.getName(), button.getValue() );
if (button.isImageButton()) {
@@ -328,24 +331,14 @@
return _parameterCollection._parameters.size() == 0;
}
+
final
protected String getParameterString() {
- StringBuffer sb = new StringBuffer(HttpUnitUtils.DEFAULT_BUFFER_SIZE);
- Enumeration e = _parameterCollection._parameters.keys();
-
- while (e.hasMoreElements()) {
- String name = (String) e.nextElement();
- Object value = _parameterCollection._parameters.get( name );
- if (value instanceof String) {
- appendParameter( sb, name, (String) value, e.hasMoreElements() );
- } else {
- appendParameters( sb, name, (String[]) value, e.hasMoreElements() );
- }
- }
- return sb.toString();
+ return _parameterCollection.getParameterString();
}
+
//---------------------------------- package members --------------------------------
/** The name of the topmost frame. **/
@@ -465,53 +458,6 @@
private Hashtable _headers;
private boolean _httpsProtocolSupportEnabled;
-
-
- private void appendParameters( StringBuffer sb, String name, String[] values, boolean moreToCome ) {
- for (int i = 0; i < values.length; i++) {
- appendParameter( sb, name, values[i], (i < values.length-1 || moreToCome ) );
- }
- }
-
-
- private void appendParameter( StringBuffer sb, String name, String value, boolean moreToCome ) {
- sb.append( encode( name ) );
- if (value != null) sb.append( '=' ).append( encode( value ) );
- if (moreToCome) sb.append( '&' );
- }
-
-
- /**
- * Returns a URL-encoded version of the string, including all eight bits, unlike URLEncoder, which strips the high bit.
- **/
- private String encode( String source ) {
- if (_sourceForm == null || _sourceForm.getCharacterSet().equalsIgnoreCase( "iso-8859-1" )) {
- return URLEncoder.encode( source );
- } else {
- try {
- byte[] rawBytes = source.getBytes( _sourceForm.getCharacterSet() );
- StringBuffer result = new StringBuffer(HttpUnitUtils.DEFAULT_BUFFER_SIZE);
- for (int i = 0; i < rawBytes.length; i++) {
- int candidate = rawBytes[i] & 0xff;
- if (candidate == ' ') {
- result.append( '+' );
- } else if ((candidate >= 'A' && candidate <= 'Z') ||
- (candidate >= 'a' && candidate <= 'z') ||
- (candidate == '.') ||
- (candidate >= '0' && candidate <= '9')) {
- result.append( (char) rawBytes[i] );
- } else if (candidate < 16) {
- result.append( "%0" ).append( Integer.toHexString( candidate ).toUpperCase() );
- } else {
- result.append( '%' ).append( Integer.toHexString( candidate ).toUpperCase() );
- }
- }
- return result.toString();
- } catch (java.io.UnsupportedEncodingException e) {
- return "????"; // XXX should pass the exception through as IOException ultimately
- }
- }
- }
private void validateParameterValue( String name, String value ) {
Index: WebRequestSource.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequestSource.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WebRequestSource.java 2001/10/25 14:51:05 1.2
+++ WebRequestSource.java 2002/01/09 23:22:10 1.3
@@ -1,7 +1,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
@@ -72,7 +72,44 @@
public WebRequest getRequest();
- //----------------------------- protected members ---------------------------------------------
+ /**
+ * Returns an array containing the names of any parameters to be sent on a request based on this request source.
+ **/
+ abstract
+ public String[] getParameterNames();
+
+
+ /**
+ * Returns the values of the named parameter.
+ **/
+ abstract
+ public String[] getParameterValues( String name );
+
+
+ /**
+ * Returns the character set encoding for the request.
+ **/
+ String getCharacterSet() {
+ return "iso-8859-1";
+ }
+
+
+ /**
+ * Returns the URL relative to the current page which will handle the request.
+ */
+ abstract
+ String getRelativeURL();
+
+
+ /**
+ * Returns true if the specified name is that of a file parameter. The default implementation returns false.
+ */
+ boolean isFileParameter( String name ) {
+ return false;
+ }
+
+
+//----------------------------- protected members ---------------------------------------------
/**
* Contructs a web form given the URL of its source page and the DOM extracted
|
|
From: Russell G. <rus...@us...> - 2002-01-09 12:57:51
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv22896/test/com/meterware/httpunit
Modified Files:
FormSubmitTest.java
Log Message:
Made SubmitButton subclass of FormControl
Index: FormSubmitTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FormSubmitTest.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- FormSubmitTest.java 2001/12/03 15:39:31 1.11
+++ FormSubmitTest.java 2002/01/09 12:57:48 1.12
@@ -142,7 +142,7 @@
SubmitButton[] buttons = form.getSubmitButtons();
assertEquals( "num detected submit buttons", 2, buttons.length );
SubmitButton sb = form.getSubmitButton( "recalculate" );
- assertNotNull( "Failed to find disabled button" );
+ assertNotNull( "Failed to find disabled button", sb );
assertTrue( "Disabled button not marked as disabled", sb.isDisabled() );
try {
form.getRequest( sb );
|
|
From: Russell G. <rus...@us...> - 2002-01-09 12:57:51
|
Update of /cvsroot/httpunit/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv22896
Modified Files:
build.xml
Log Message:
Made SubmitButton subclass of FormControl
Index: build.xml
===================================================================
RCS file: /cvsroot/httpunit/httpunit/build.xml,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- build.xml 2001/11/28 18:34:26 1.36
+++ build.xml 2002/01/09 12:57:47 1.37
@@ -77,7 +77,7 @@
<target name="testcompile" depends="compile,check_for_optional_packages">
<mkdir dir="${test.classes}" />
<javac srcdir="${tstsrc.dir}" destdir="${test.classes}"
- debug="off" deprecation="on" optimize="off">
+ debug="on" deprecation="on" optimize="off">
<classpath>
<path refid="base.classpath" />
<pathelement location="${build.classes}" />
|
|
From: Russell G. <rus...@us...> - 2002-01-09 12:57:51
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv22896/src/com/meterware/httpunit
Modified Files:
FormControl.java SubmitButton.java WebForm.java
Log Message:
Made SubmitButton subclass of FormControl
Index: FormControl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FormControl.java 2002/01/08 23:21:53 1.3
+++ FormControl.java 2002/01/09 12:57:48 1.4
@@ -36,15 +36,25 @@
final static String[] NO_VALUE = new String[0];
- private String _name;
- private boolean _readOnly;
- private boolean _disabled;
+ private final String _name;
+ private final String _valueAttribute;
+ private final boolean _readOnly;
+ private final boolean _disabled;
+
+
+ FormControl() {
+ _name = "";
+ _valueAttribute = "";
+ _readOnly = false;
+ _disabled = false;
+ }
FormControl( Node node ) {
- _name = NodeUtils.getNodeAttribute( node, "name" );
- _readOnly = NodeUtils.isNodeAttributePresent( node, "readonly" );
- _disabled = NodeUtils.isNodeAttributePresent( node, "disabled" );
+ _name = NodeUtils.getNodeAttribute( node, "name" );
+ _valueAttribute = NodeUtils.getNodeAttribute( node, "value" );
+ _readOnly = NodeUtils.isNodeAttributePresent( node, "readonly" );
+ _disabled = NodeUtils.isNodeAttributePresent( node, "disabled" );
}
@@ -131,24 +141,11 @@
}
- protected void addValue( Hashtable valueMap, String name, String value ) {
- String[] currentValues = (String[]) valueMap.get( name );
- if (currentValues == null) {
- valueMap.put( name, new String[] { value } );
- } else {
- valueMap.put( name, withNewValue( currentValues, value ) );
- }
- }
-
-
/**
- * Adds a string to an array of strings and returns the result.
+ * Returns the default value of this control in the form. If no value is specified, defaults to the empty string.
**/
- private String[] withNewValue( String[] group, String value ) {
- String[] result = new String[ group.length+1 ];
- System.arraycopy( group, 0, result, 0, group.length );
- result[ group.length ] = value;
- return result;
+ protected String getValueAttribute() {
+ return _valueAttribute;
}
@@ -169,6 +166,8 @@
return new RadioButtonFormControl( node );
} else if (type.equalsIgnoreCase( "checkbox" )) {
return new CheckboxFormControl( node );
+// } else if (type.equalsIgnoreCase( "submit" ) || type.equalsIgnoreCase( "image" )) {
+// return new SubmitButton( node );
} else if (type.equalsIgnoreCase( "file" )) {
return new FileSubmitFormControl( node );
} else {
@@ -187,14 +186,12 @@
private String[] _value = new String[1];
private final boolean _isCheckedDefault;
- private final String _valueAttribute;
public BooleanFormControl( Node node ) {
super( node );
_isChecked = _isCheckedDefault = NodeUtils.isNodeAttributePresent( node, "checked" );
- _valueAttribute = NodeUtils.getNodeAttribute( node, "value" );
}
@@ -220,14 +217,6 @@
}
- /**
- * Returns the default value of this control in the form. If no value is specified, defaults to the empty string.
- **/
- String getValueAttribute() {
- return _valueAttribute;
- }
-
-
abstract String getQueryValue();
@@ -284,6 +273,28 @@
final String value = getValueAttribute();
return value.length() == 0 ? "on" : value;
}
+
+
+ private void addValue( Hashtable valueMap, String name, String value ) {
+ String[] currentValues = (String[]) valueMap.get( name );
+ if (currentValues == null) {
+ valueMap.put( name, new String[] { value } );
+ } else {
+ valueMap.put( name, withNewValue( currentValues, value ) );
+ }
+ }
+
+
+ /**
+ * Adds a string to an array of strings and returns the result.
+ **/
+ private String[] withNewValue( String[] group, String value ) {
+ String[] result = new String[ group.length+1 ];
+ System.arraycopy( group, 0, result, 0, group.length );
+ result[ group.length ] = value;
+ return result;
+ }
+
}
Index: SubmitButton.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/SubmitButton.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SubmitButton.java 2001/12/03 15:39:31 1.5
+++ SubmitButton.java 2002/01/09 12:57:48 1.6
@@ -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
@@ -22,26 +22,19 @@
import org.w3c.dom.Node;
/**
- * This class represents a suubmit button in an HTML form.
+ * This class represents a submit button in an HTML form.
**/
-public class SubmitButton {
+public class SubmitButton extends FormControl {
- public static SubmitButton UNNAMED_BUTTON = new SubmitButton();
-
- /**
- * Returns the name of this submit button.
- **/
- public String getName() {
- return _name;
- }
+ public static SubmitButton UNNAMED_BUTTON = new SubmitButton();
/**
* Returns the value associated with this submit button.
**/
public String getValue() {
- return _value;
+ return getValueAttribute();
}
@@ -50,7 +43,7 @@
* @return the button ID, or an empty string if no ID is defined.
**/
public String getID() {
- return NodeUtils.getNodeAttribute( _node, "id" );
+ return _id;
}
@@ -63,10 +56,11 @@
/**
- * Returns true if this submit button is disabled. Requests cannot be made for disabled buttons.
+ * Returns the current value(s) associated with this control. These values will be transmitted to the server
+ * if the control is 'successful'.
**/
- public boolean isDisabled() {
- return _isDisabled;
+ public String[] getValues() {
+ return isDisabled() ? NO_VALUE : toArray( getValueAttribute() );
}
@@ -92,26 +86,29 @@
SubmitButton( Node node ) {
- _node = node;
- _name = NodeUtils.getNodeAttribute( node, "name" );
- _value = NodeUtils.getNodeAttribute( _node, "value" );
- _isImageButton = NodeUtils.getNodeAttribute( _node, "type" ).equalsIgnoreCase( "image" );
- _isDisabled = _node.getAttributes().getNamedItem( "disabled" ) != null;
+ super( node );
+ _isImageButton = NodeUtils.getNodeAttribute( node, "type" ).equalsIgnoreCase( "image" );
+ _id = NodeUtils.getNodeAttribute( node, "id" );
}
//------------------------------------------ private members ----------------------------------
+
- private Node _node;
- private String _name;
- private String _value;
- private boolean _isImageButton;
- private boolean _isDisabled;
+ private final String _id;
+ private final boolean _isImageButton;
+ private String[] _value = new String[1];
private SubmitButton() {
- _name = "";
- _value = "";
+ _id = "";
+ _isImageButton = false;
+ }
+
+
+ private String[] toArray( String value ) {
+ _value[0] = value;
+ return _value;
}
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- WebForm.java 2002/01/08 23:21:53 1.38
+++ WebForm.java 2002/01/09 12:57:48 1.39
@@ -153,8 +153,7 @@
nl = ((Element) getNode()).getElementsByTagName( "button" );
for (int i = 0; i < nl.getLength(); i++) {
- if ((hasMatchingAttribute( nl.item(i), "type", "submit" ) || hasMatchingAttribute( nl.item(i), "type", "" ))
- && nl.item(i).getAttributes().getNamedItem( "disabled" ) == null) {
+ if (hasMatchingAttribute( nl.item(i), "type", "submit" ) || hasMatchingAttribute( nl.item(i), "type", "" )) {
_buttonVector.addElement( new SubmitButton( nl.item(i) ) );
}
}
|
|
From: Russell G. <rus...@us...> - 2002-01-09 03:13:15
|
Update of /cvsroot/httpunit/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv26321 Modified Files: index.html Log Message: Added reference to Mastering Open Source Tools Index: index.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/index.html,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- index.html 2001/11/28 18:29:55 1.18 +++ index.html 2002/01/09 03:13:13 1.19 @@ -1,4 +1,4 @@ -<HTML> +<HTML> <HEAD> <TITLE>HttpUnit</TITLE> </HEAD> @@ -12,7 +12,7 @@ HttpUnit makes this easy. Written in Java, HttpUnit emulates the relevant portions of browser behavior, including -form submission, basic <A HREF="ftp://ftp.isi.edu/in-notes/rfc2617.txt">http authentication</A>, +form submission, basic <A HREF="ftp://ftp.isi.edu/in-notes/rfc2617.txt">http authentication</A>, cookies and automatic page redirection, and allows Java test code to examine returned pages as text, an XML DOM, or containers of forms, tables, and links.</P> <P> @@ -23,30 +23,34 @@ <h2>What is it?</h2> <blockquote> -<strong>HttpUnit</strong> is a free, <A HREF="doc/license.html">open source</A> Java API for accessing web sites without a browser, -and is ideally suited for automated unit testing of web sites when combined with a -Java unit test framework such as <A HREF="http://www.junit.org">JUnit</a>. +<strong>HttpUnit</strong> is a free, <A HREF="doc/license.html">open source</A> Java API for accessing web sites without a browser, +and is ideally suited for automated unit testing of web sites when combined with a +Java unit test framework such as <A HREF="http://www.junit.org">JUnit</a>. It was designed and implemented by <a href="mailto:rus...@us...">Russell Gold.</a></blockquote> <h2>Documentation</h2> <blockquote>A rudimentary <A HREF="doc/Cookbook.html">User's manual</A> is available, as are a <a href="doc/tutorial/index.html">tutorial</a>, a <A HREF="doc/faq.html">FAQ</A> and the <A HREF="doc/api/index.html">javadoc</A>. -Several working example files come with the distribution download.</blockquote> +Several working example files come with the distribution download.<br /> +In addition, Wiley press has published +<a href="http://www.wiley.com/Corporate/Website/Objects/Products/0,9049,1847817,00.html"> +<i>Java Tools for Extreme Programming: Mastering Open Source Tools, including Ant, JUnit, and Cactus</i></a> +which contains two chapters dealing with HttpUnit.</blockquote> <h2>Where do I get releases?</h2> -<blockquote>Releases of HttpUnit are available +<blockquote>Releases of HttpUnit are available from <a href="http://sourceforge.net/project/showfiles.php?group_id=6550"> the project download page.</a> <var:publish><br><var:publish>Other builds are available by <a href="ftp://httpunit.sourceforge.net/pub/httpunit"> <var:publish>anonymous ftp</a>. </blockquote> - + <h2>How do I get help, contribute, give feedback, fix bugs and so on?</h2> <ul> -<li>We have a <a href="http://lists.sourceforge.net/mailman/listinfo/httpunit-develop">mailing list</a> for discussion of +<li>We have a <a href="http://lists.sourceforge.net/mailman/listinfo/httpunit-develop">mailing list</a> for discussion of the code. -<li>Read-only access to the CVS "<b>HttpUnit</b>" repository is available both -<a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/httpunit/">online</a> as well as with +<li>Read-only access to the CVS "<b>HttpUnit</b>" repository is available both +<a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/httpunit/">online</a> as well as with a cvs client, accessing the repository at <code>:pserver:ano...@cv...:/cvsroot/httpunit</code>. </ul> |
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv13413/src/com/meterware/httpunit
Modified Files:
FormControl.java NodeUtils.java WebForm.java WebRequest.java
Added Files:
ParameterHolder.java UncheckedParameterCollection.java
Log Message:
Started moving the manipulation of parameters to a separate class to allow alternative strategies
***** Error reading new file[Errno 2] No such file or directory: 'ParameterHolder.java'
***** Error reading new file[Errno 2] No such file or directory: 'UncheckedParameterCollection.java'
Index: FormControl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FormControl.java 2002/01/08 14:29:27 1.2
+++ FormControl.java 2002/01/08 23:21:53 1.3
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-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
@@ -26,6 +26,7 @@
import java.util.Hashtable;
import java.util.Vector;
+import java.util.ArrayList;
/**
@@ -33,6 +34,8 @@
**/
abstract class FormControl {
+ final static String[] NO_VALUE = new String[0];
+
private String _name;
private boolean _readOnly;
private boolean _disabled;
@@ -48,7 +51,7 @@
/**
* Returns the name of this control. If no name is specified, defaults to the empty string.
**/
- String getName() {
+ public String getName() {
return _name;
}
@@ -56,14 +59,30 @@
/**
* Returns the current value(s) associated with this control. These values will be transmitted to the server
* if the control is 'successful'.
+ **/
+ abstract public String[] getValues();
+
+
+ /**
+ * Returns the values permitted in this control. Does not apply to text or file controls.
+ **/
+ public String[] getOptionValues() {
+ return NO_VALUE;
+ }
+
+
+ /**
+ * Returns the list of values displayed by this control, if any.
**/
- abstract String[] getValues();
+ public String[] getDisplayedOptions() {
+ return NO_VALUE;
+ }
/**
* Returns true if this control is read-only.
**/
- boolean isReadOnly() {
+ public boolean isReadOnly() {
return _readOnly;
}
@@ -71,7 +90,7 @@
/**
* Returns true if this control is disabled, meaning that it will not send a value to the server as part of a request.
**/
- boolean isDisabled() {
+ public boolean isDisabled() {
return _disabled;
}
@@ -79,7 +98,7 @@
/**
* Returns true if this control accepts free-form text.
**/
- boolean isTextControl() {
+ public boolean isTextControl() {
return false;
}
@@ -87,7 +106,7 @@
/**
* Returns true if only one control of this kind can have a value. This is true for radio buttons.
**/
- boolean isExclusive() {
+ public boolean isExclusive() {
return false;
}
@@ -95,7 +114,7 @@
/**
* Returns true if a single control can have multiple values.
**/
- boolean isMultiValued() {
+ public boolean isMultiValued() {
return false;
}
@@ -103,7 +122,7 @@
/**
* Returns true if this control accepts a file for upload.
**/
- boolean isFileParameter() {
+ public boolean isFileParameter() {
return false;
}
@@ -112,14 +131,6 @@
}
- void updateParameterOptions( Hashtable options ) {
- }
-
-
- void updateParameterOptionValues( Hashtable options ) {
- }
-
-
protected void addValue( Hashtable valueMap, String name, String value ) {
String[] currentValues = (String[]) valueMap.get( name );
if (currentValues == null) {
@@ -172,8 +183,6 @@
abstract
class BooleanFormControl extends FormControl {
- final static String[] NO_VALUE = new String[0];
-
private boolean _isChecked;
private String[] _value = new String[1];
@@ -195,31 +204,33 @@
/**
- * Returns the default value of this control in the form. If no value is specified, defaults to the empty string.
+ * Returns the current value(s) associated with this control. These values will be transmitted to the server
+ * if the control is 'successful'.
**/
- String getValueAttribute() {
- return _valueAttribute;
+ public String[] getValues() {
+ return isChecked() ? toArray( getQueryValue() ) : NO_VALUE;
}
/**
- * Returns the current value(s) associated with this control. These values will be transmitted to the server
- * if the control is 'successful'.
+ * Returns the values permitted in this control.
**/
- String[] getValues() {
- return isChecked() ? toArray( getQueryValue() ) : NO_VALUE;
+ public String[] getOptionValues() {
+ return (isReadOnly() && !isChecked()) ? NO_VALUE : toArray( getQueryValue() );
}
- abstract String getQueryValue();
+ /**
+ * Returns the default value of this control in the form. If no value is specified, defaults to the empty string.
+ **/
+ String getValueAttribute() {
+ return _valueAttribute;
+ }
- void updateParameterOptionValues( Hashtable options ) {
- if (isChecked() || !isReadOnly()) {
- addValue( options, getName(), getQueryValue() );
- }
- }
+ abstract String getQueryValue();
+
private String[] toArray( String value ) {
_value[0] = value;
return _value;
@@ -238,7 +249,7 @@
/**
* Returns true if only one control of this kind can have a value.
**/
- boolean isExclusive() {
+ public boolean isExclusive() {
return true;
}
@@ -292,7 +303,7 @@
* Returns the current value(s) associated with this control. These values will be transmitted to the server
* if the control is 'successful'.
**/
- String[] getValues() {
+ public String[] getValues() {
return (_value[0] != null) ? _value : _defaultValue;
}
@@ -300,7 +311,7 @@
/**
* Returns true to indicate that this control accepts free-form text.
**/
- boolean isTextControl() {
+ public boolean isTextControl() {
return true;
}
@@ -347,81 +358,84 @@
/**
* Returns true if this control accepts a file for upload.
**/
- boolean isFileParameter() {
+ public boolean isFileParameter() {
return true;
}
- String[] getValues() {
+ public String[] getValues() {
return null; // XXX what should this really do?
}
}
class SelectionFormControl extends FormControl {
- private boolean _multiSelect;
- private Node _node;
+ private final boolean _multiSelect;
+ private final String[] _optionValues;
+ private final String[] _displayedOptions;
+
+ private String[] _values;
SelectionFormControl( Node node ) {
super( node );
if (!node.getNodeName().equalsIgnoreCase( "select" )) throw new RuntimeException( "Not a select element" );
- _node = node;
- _multiSelect = NodeUtils.isNodeAttributePresent( node, "multiple" );
+ _multiSelect = NodeUtils.isNodeAttributePresent( node, "multiple" );
+ _optionValues = getInitialOptionValues( node );
+ _displayedOptions = getInitialDisplayedOptions( node );
+ _values = getInitialValues( node, _optionValues );
}
- String[] getValues() {
- return getSelected();
+ public String[] getValues() {
+ return _values;
}
- /**
- * Returns true if a single control can have multiple values.
- **/
- boolean isMultiValued() {
- return _multiSelect;
+ public String[] getOptionValues() {
+ return _optionValues;
}
- void updateRequiredParameters( Hashtable required ) {
- if (isReadOnly()) required.put( getName(), getSelected() );
+ public String[] getDisplayedOptions() {
+ return _displayedOptions;
}
- void updateParameterOptions( Hashtable options ) {
- options.put( getName(), getOptions() );
+ /**
+ * Returns true if a single control can have multiple values.
+ **/
+ public boolean isMultiValued() {
+ return _multiSelect;
}
- void updateParameterOptionValues( Hashtable options ) {
- options.put( getName(), getOptionValues() );
+ void updateRequiredParameters( Hashtable required ) {
+ if (isReadOnly()) required.put( getName(), getValues() );
}
- String[] getSelected() {
- Vector selected = new Vector();
- NodeList nl = ((Element) _node).getElementsByTagName( "option" );
+ private String[] getInitialValues( Node selectionNode, String[] optionValues ) {
+ ArrayList selected = new ArrayList();
+ NodeList nl = ((Element) selectionNode).getElementsByTagName( "option" );
for (int i = 0; i < nl.getLength(); i++) {
if (nl.item(i).getAttributes().getNamedItem( "selected" ) != null) {
- selected.addElement( getOptionValue( nl.item(i) ) );
+ selected.add( optionValues[i] );
}
}
if (!isMultiValued() && selected.size() == 0 && nl.getLength() > 0) {
- selected.addElement( getOptionValue( nl.item(0) ) );
+ selected.add( optionValues[0] );
}
- String[] result = new String[ selected.size() ];
- selected.copyInto( result );
- return result;
+ return (String[]) selected.toArray( new String[ selected.size() ] );
}
- String[] getOptions() {
+ private String[] getInitialDisplayedOptions( Node node ) {
Vector options = new Vector();
- NodeList nl = ((Element) _node).getElementsByTagName( "option" );
+ NodeList nl = ((Element) node).getElementsByTagName( "option" );
for (int i = 0; i < nl.getLength(); i++) {
options.addElement( getValue( nl.item(i).getFirstChild() ) );
}
@@ -431,15 +445,13 @@
}
- String[] getOptionValues() {
- Vector options = new Vector();
- NodeList nl = ((Element) _node).getElementsByTagName( "option" );
+ private String[] getInitialOptionValues( Node selectNode ) {
+ NodeList nl = ((Element) selectNode).getElementsByTagName( "option" );
+ ArrayList options = new ArrayList( nl.getLength() );
for (int i = 0; i < nl.getLength(); i++) {
- options.addElement( getOptionValue( nl.item(i) ) );
+ options.add( getOptionValue( nl.item(i) ) );
}
- String[] result = new String[ options.size() ];
- options.copyInto( result );
- return result;
+ return (String[]) options.toArray( new String[ options.size() ] );
}
Index: NodeUtils.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/NodeUtils.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- NodeUtils.java 2002/01/08 14:29:27 1.9
+++ NodeUtils.java 2002/01/08 23:21:53 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
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- WebForm.java 2002/01/08 14:29:27 1.37
+++ WebForm.java 2002/01/08 23:21:53 1.38
@@ -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
@@ -68,6 +68,13 @@
/**
+ * Sets the value of a parameter in this form.
+ **/
+ public void setParameter( String name, String value ) {
+ }
+
+
+ /**
* Returns true if a parameter with given name exists in this form.
**/
public boolean hasParameterNamed( String soughtName ) {
@@ -270,7 +277,7 @@
if (HttpUnitOptions.getParameterValuesValidated()) {
if (button == null) {
throw new IllegalUnnamedSubmitButtonException();
- } else if (!getSubmitButtonVector().contains( button )) {
+ } else if (!getSubmitButtonVector().contains( button )) {
throw new IllegalSubmitButtonException( button );
} else if (button.isDisabled()) {
throw new DisabledSubmitButtonException( button );
@@ -330,9 +337,12 @@
* Returns the displayed options defined for the specified parameter name.
**/
public String[] getOptions( String name ) {
- Object result = getParameterOptions().get( name );
- if (result instanceof String[]) return (String[]) result;
- return new String[0];
+ ArrayList optionList = new ArrayList();
+ FormControl[] controls = getParameter( name ).getControls();
+ for (int i = 0; i < controls.length; i++) {
+ optionList.addAll( Arrays.asList( controls[i].getDisplayedOptions() ) );
+ }
+ return (String[]) optionList.toArray( new String[ optionList.size() ] );
}
@@ -340,9 +350,12 @@
* Returns the option values defined for the specified parameter name.
**/
public String[] getOptionValues( String name ) {
- Object result = getParameterOptionValues().get( name );
- if (result instanceof String[]) return (String[]) result;
- return new String[0];
+ ArrayList valueList = new ArrayList();
+ FormControl[] controls = getParameter( name ).getControls();
+ for (int i = 0; i < controls.length; i++) {
+ valueList.addAll( Arrays.asList( controls[i].getOptionValues() ) );
+ }
+ return (String[]) valueList.toArray( new String[ valueList.size() ] );
}
@@ -433,12 +446,6 @@
/** The attributes of the form parameters. **/
private FormControl[] _parameters;
- /** The parameters with their displayed options. **/
- private Hashtable _options;
-
- /** The parameters with their options. **/
- private Hashtable _optionValues;
-
/** The submit buttons in this form. **/
private SubmitButton[] _submitButtons;
@@ -447,10 +454,11 @@
/** A map of parameter names to form parameter objects. **/
private Map _formParameters;
-
+ /** A map of parameter names to their required values. **/
private Hashtable _required;
+
private Hashtable getParameterRequiredValues() {
if (_required == null) {
FormControl[] parameters = getFormControls();
@@ -464,35 +472,7 @@
}
- private Hashtable getParameterOptions() {
- if (_options == null) {
- Hashtable options = new Hashtable();
- FormControl[] parameters = getFormControls();
- for (int i = 0; i < parameters.length; i++) {
- parameters[i].updateParameterOptions( options );
- }
- _options = options;
- }
- return _options;
- }
-
-
- private Hashtable getParameterOptionValues() {
- if (_optionValues == null) {
- Hashtable options = new Hashtable();
- FormControl[] parameters = getFormControls();
- for (int i = 0; i < parameters.length; i++) {
- parameters[i].updateParameterOptionValues( options );
- }
- _optionValues = options;
- }
- return _optionValues;
- }
-
- /**
- * Returns an array of select control descriptors for this form.
- **/
/**
* Returns an array of form parameter attributes for this form.
**/
Index: WebRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- WebRequest.java 2001/11/27 19:51:27 1.31
+++ WebRequest.java 2002/01/08 23:21:53 1.32
@@ -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
@@ -43,7 +43,7 @@
* A request sent to a web server.
**/
abstract
-public class WebRequest {
+public class WebRequest implements ParameterHolder {
/**
@@ -63,11 +63,46 @@
/**
+ * Returns the final URL associated with this web request.
+ **/
+ public URL getURL() throws MalformedURLException {
+ if (getURLBase() == null || getURLString().indexOf( ':' ) > 0) validateProtocol( getURLString() );
+ return new URL( getURLBase(), getURLString() );
+ }
+
+
+ /**
+ * Returns the target for this web request.
+ **/
+ public String getTarget() {
+ return _target;
+ }
+
+
+ /**
+ * Returns the query string defined for this request.
+ **/
+ public String getQueryString() {
+ return getParameterString();
+ }
+
+
+ /**
+ * Returns the HTTP method defined for this request.
+ **/
+ abstract
+ public String getMethod();
+
+
+//------------------------------------- ParameterCollection methods ------------------------------------
+
+
+ /**
* Sets the value of a parameter in a web request.
**/
public void setParameter( String name, String value ) {
if (HttpUnitOptions.getParameterValuesValidated()) validateParameterValue( name, value );
- _parameters.put( name, value );
+ _parameterCollection.setParameter( name, value );
}
@@ -76,7 +111,7 @@
**/
public void setParameter( String name, String[] values ) {
if (HttpUnitOptions.getParameterValuesValidated()) validateParameterValues( name, values );
- _parameters.put( name, values );
+ _parameterCollection.setParameter( name, values );
}
@@ -128,7 +163,7 @@
* Returns an enumeration of all parameters in this web request.
**/
public Enumeration getParameterNames() {
- return _parameters.keys();
+ return _parameterCollection.getParameterNames();
}
@@ -138,14 +173,8 @@
* if it is not set.
**/
public String getParameter( String name ) {
- Object value = _parameters.get( name );
- if (value instanceof String[]) {
- return ((String[]) value)[0];
- } else if (value == null) {
- return "";
- } else {
- return value.toString();
- }
+ String[] values = getParameterValues( name );
+ return values.length == 0 ? "" : values[0];
}
@@ -153,11 +182,7 @@
* Returns the multiple default values of the named parameter.
**/
public String[] getParameterValues( String name ) {
- Object result = _parameters.get( name );
- if (result instanceof String) return new String[] { (String) result };
- if (result instanceof String[]) return (String[]) result;
- if (result instanceof UploadFileSpec) return new String[] { result.toString() };
- return new String[0];
+ return _parameterCollection.getParameterValues( name );
}
@@ -165,41 +190,11 @@
* Removes a parameter from this web request.
**/
public void removeParameter( String name ) {
- _parameters.remove( name );
+ _parameterCollection.removeParameter( name );
}
-
- /**
- * Returns the final URL associated with this web request.
- **/
- public URL getURL() throws MalformedURLException {
- if (getURLBase() == null || getURLString().indexOf( ':' ) > 0) validateProtocol( getURLString() );
- return new URL( getURLBase(), getURLString() );
- }
-
-
- /**
- * Returns the target for this web request.
- **/
- public String getTarget() {
- return _target;
- }
-
-
- /**
- * Returns the query string defined for this request.
- **/
- public String getQueryString() {
- return getParameterString();
- }
-
-
- /**
- * Returns the HTTP method defined for this request.
- **/
- abstract
- public String getMethod();
+//------------------------------------- Object methods ------------------------------------
public String toString() {
@@ -245,7 +240,7 @@
_sourceForm = sourceForm;
if (button != null && button.getName().length() > 0) {
- _parameters.put( button.getName(), button.getValue() );
+ _parameterCollection._parameters.put( button.getName(), button.getValue() );
if (button.isImageButton()) {
_imageButtonName = button.getName();
setSubmitPosition( 0, 0 );
@@ -330,17 +325,17 @@
final
protected boolean hasNoParameters() {
- return _parameters.size() == 0;
+ return _parameterCollection._parameters.size() == 0;
}
final
protected String getParameterString() {
StringBuffer sb = new StringBuffer(HttpUnitUtils.DEFAULT_BUFFER_SIZE);
- Enumeration e = _parameters.keys();
+ Enumeration e = _parameterCollection._parameters.keys();
while (e.hasMoreElements()) {
String name = (String) e.nextElement();
- Object value = _parameters.get( name );
+ Object value = _parameterCollection._parameters.get( name );
if (value instanceof String) {
appendParameter( sb, name, (String) value, e.hasMoreElements() );
} else {
@@ -359,8 +354,8 @@
void setSubmitPosition( int x, int y ) {
if (_imageButtonName == null) return;
- _parameters.put( _imageButtonName + ".x", Integer.toString( x ) );
- _parameters.put( _imageButtonName + ".y", Integer.toString( y ) );
+ _parameterCollection._parameters.put( _imageButtonName + ".x", Integer.toString( x ) );
+ _parameterCollection._parameters.put( _imageButtonName + ".y", Integer.toString( y ) );
}
@@ -460,10 +455,10 @@
/** The name of the JSSE class which supports the https protocol. **/
private final static String SSL_PROTOCOL_HANDLER = "com.sun.net.ssl.internal.www.protocol";
+ private UncheckedParameterCollection _parameterCollection = new UncheckedParameterCollection();
private URL _urlBase;
private String _urlString;
- private Hashtable _parameters = new Hashtable();
private WebForm _sourceForm;
private String _imageButtonName;
private String _target = TOP_FRAME;
|
|
From: Russell G. <rus...@us...> - 2002-01-08 23:21:56
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv13413/test/com/meterware/httpunit
Modified Files:
FormParametersTest.java WebFormTest.java
Log Message:
Started moving the manipulation of parameters to a separate class to allow alternative strategies
Index: FormParametersTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/FormParametersTest.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- FormParametersTest.java 2001/12/03 15:39:31 1.8
+++ FormParametersTest.java 2002/01/08 23:21:53 1.9
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000, 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
Index: WebFormTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFormTest.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- WebFormTest.java 2002/01/08 14:29:27 1.16
+++ WebFormTest.java 2002/01/08 23:21:53 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
@@ -128,6 +128,10 @@
assertTrue( "Did not find parameter 'first'", form.hasParameterNamed( "first" ) );
assertTrue( "Did not find parameter with prefix 'sec'", form.hasParameterStartingWithPrefix( "sec" ) );
assertTrue( "Did not find parameter with prefix 'nam'", form.hasParameterStartingWithPrefix( "nam" ) );
+
+ assertEquals( "Original text area value", "Something", form.getParameterValue( "name" ) );
+// form.setParameter( "name", "Something Else" );
+// assertEquals( "Changed text area value", "Something Else", form.getParameterValue( "name" ) );
}
|
|
From: Russell G. <rus...@us...> - 2002-01-08 23:21:56
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv13413/test/com/meterware/servletunit Modified Files: WebXMLTest.java Log Message: Started moving the manipulation of parameters to a separate class to allow alternative strategies Index: WebXMLTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/WebXMLTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- WebXMLTest.java 2002/01/01 19:29:08 1.4 +++ WebXMLTest.java 2002/01/08 23:21:54 1.5 @@ -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 |
|
From: Russell G. <rus...@us...> - 2002-01-08 14:29:30
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv5179/test/com/meterware/httpunit
Modified Files:
WebFormTest.java
Log Message:
More refactoring
Index: WebFormTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFormTest.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- WebFormTest.java 2001/12/11 21:41:38 1.15
+++ WebFormTest.java 2002/01/08 14:29:27 1.16
@@ -122,8 +122,9 @@
assertNotNull( parameters );
assertMatchingSet( "form parameter names", new String[] { "first", "name", "second" }, parameters );
- assertEquals( "First checkbox", "", form.getParameterValue( "first" ) );
+ assertNull( "First checkbox has a non-null value", form.getParameterValue( "first" ) );
assertEquals( "Second checkbox", "on", form.getParameterValue( "second" ) );
+ assertNull( "Found extraneous value for unknown parameter 'magic'", form.getParameterValue( "magic" ) );
assertTrue( "Did not find parameter 'first'", form.hasParameterNamed( "first" ) );
assertTrue( "Did not find parameter with prefix 'sec'", form.hasParameterStartingWithPrefix( "sec" ) );
assertTrue( "Did not find parameter with prefix 'nam'", form.hasParameterStartingWithPrefix( "nam" ) );
@@ -230,6 +231,7 @@
String[] parameterNames = form.getParameterNames();
assertEquals( "num parameters", 1, parameterNames.length );
assertEquals( "parameter name", "colors", parameterNames[0] );
+ assertTrue( "Found extraneous values for unknown parameter 'magic'", form.getParameterValues( "magic" ).length == 0 );
assertMatchingSet( "Select defaults", new String[] { "red", "pink" }, form.getParameterValues( "colors" ) );
assertMatchingSet( "Select options", new String[] { "blue", "red", "green", "salmon" }, form.getOptions( "colors" ) );
assertEquals( "Select values", new String[] { "blue", "red", "green", "pink" }, form.getOptionValues( "colors" ) );
|
|
From: Russell G. <rus...@us...> - 2002-01-08 14:29:30
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv5179/src/com/meterware/httpunit
Modified Files:
FormControl.java NodeUtils.java WebForm.java
Log Message:
More refactoring
Index: FormControl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FormControl.java 2002/01/01 19:29:07 1.1
+++ FormControl.java 2002/01/08 14:29:27 1.2
@@ -33,26 +33,15 @@
**/
abstract class FormControl {
- protected Node _node;
- /** The type of a parameter which accepts files for upload. **/
- final static Integer TYPE_FILE = new Integer(4);
- /** The type of a parameter which accepts any text. **/
- final static Integer TYPE_TEXT = new Integer(1);
- /** The type of a parameter which accepts single predefined values. **/
- final static Integer TYPE_SCALAR = new Integer(2);
- /** The type of a parameter which accepts multiple predefined values. **/
- final static Integer TYPE_MULTI_VALUED = new Integer(3);
- /** A constant set to indicate one parameter. **/
- final static Integer ONE_PARAMETER = new Integer(1);
+ private String _name;
+ private boolean _readOnly;
+ private boolean _disabled;
FormControl( Node node ) {
- _node = node;
- }
-
-
- Node getNamedItem( String attributeName ) {
- return _node.getAttributes().getNamedItem( attributeName );
+ _name = NodeUtils.getNodeAttribute( node, "name" );
+ _readOnly = NodeUtils.isNodeAttributePresent( node, "readonly" );
+ _disabled = NodeUtils.isNodeAttributePresent( node, "disabled" );
}
@@ -60,47 +49,75 @@
* Returns the name of this control. If no name is specified, defaults to the empty string.
**/
String getName() {
- return NodeUtils.getNodeAttribute( _node, "name" );
+ return _name;
}
/**
- * Returns the value of this control. If no value is specified, defaults to the empty string.
+ * Returns the current value(s) associated with this control. These values will be transmitted to the server
+ * if the control is 'successful'.
**/
- String getValue() {
- return NodeUtils.getNodeAttribute( _node, "value" );
- }
+ abstract String[] getValues();
/**
* Returns true if this control is read-only.
**/
boolean isReadOnly() {
- return _node.getAttributes().getNamedItem( "readonly" ) != null;
+ return _readOnly;
}
- void updateParameterDefaults( Hashtable defaults ) {
+ /**
+ * Returns true if this control is disabled, meaning that it will not send a value to the server as part of a request.
+ **/
+ boolean isDisabled() {
+ return _disabled;
}
- void updateRequiredValues( Hashtable required ) {
+ /**
+ * Returns true if this control accepts free-form text.
+ **/
+ boolean isTextControl() {
+ return false;
}
- void updateParameterOptions( Hashtable options ) {
+ /**
+ * Returns true if only one control of this kind can have a value. This is true for radio buttons.
+ **/
+ boolean isExclusive() {
+ return false;
}
- void updateParameterOptionValues( Hashtable options ) {
+ /**
+ * Returns true if a single control can have multiple values.
+ **/
+ boolean isMultiValued() {
+ return false;
+ }
+
+
+ /**
+ * Returns true if this control accepts a file for upload.
+ **/
+ boolean isFileParameter() {
+ return false;
}
- void updateTextParameterCounts( Hashtable parameterCounts ) {
+ void updateRequiredValues( Hashtable required ) {
}
+
+ void updateParameterOptions( Hashtable options ) {
+ }
- abstract void updateParameterTypes( Hashtable types );
+
+ void updateParameterOptionValues( Hashtable options ) {
+ }
protected void addValue( Hashtable valueMap, String name, String value ) {
@@ -113,16 +130,6 @@
}
- protected static String getValue( Node node ) {
- return (node == null) ? "" : emptyIfNull( node.getNodeValue() );
- }
-
-
- private static String emptyIfNull( String value ) {
- return (value == null) ? "" : value;
- }
-
-
/**
* Adds a string to an array of strings and returns the result.
**/
@@ -164,21 +171,59 @@
abstract
class BooleanFormControl extends FormControl {
+
+ final static String[] NO_VALUE = new String[0];
+
+ private boolean _isChecked;
+ private String[] _value = new String[1];
+
+ private final boolean _isCheckedDefault;
+ private final String _valueAttribute;
+
+
+
public BooleanFormControl( Node node ) {
super( node );
+ _isChecked = _isCheckedDefault = NodeUtils.isNodeAttributePresent( node, "checked" );
+ _valueAttribute = NodeUtils.getNodeAttribute( node, "value" );
}
boolean isChecked() {
- return getNamedItem( "checked" ) != null;
+ return _isChecked;
}
+ /**
+ * Returns the default value of this control in the form. If no value is specified, defaults to the empty string.
+ **/
+ String getValueAttribute() {
+ return _valueAttribute;
+ }
+
+
+ /**
+ * Returns the current value(s) associated with this control. These values will be transmitted to the server
+ * if the control is 'successful'.
+ **/
+ String[] getValues() {
+ return isChecked() ? toArray( getQueryValue() ) : NO_VALUE;
+ }
+
+
+ abstract String getQueryValue();
+
+
void updateParameterOptionValues( Hashtable options ) {
if (isChecked() || !isReadOnly()) {
- addValue( options, getName(), getValue() );
+ addValue( options, getName(), getQueryValue() );
}
}
+
+ private String[] toArray( String value ) {
+ _value[0] = value;
+ return _value;
+ }
}
@@ -190,20 +235,23 @@
}
- void updateParameterDefaults( Hashtable defaults ) {
- if (isChecked()) defaults.put( getName(), getValue() );
+ /**
+ * Returns true if only one control of this kind can have a value.
+ **/
+ boolean isExclusive() {
+ return true;
}
- void updateRequiredValues( Hashtable required ) {
- if (isReadOnly() && isChecked()) {
- required.put( getName(), getValue() );
- }
+ String getQueryValue() {
+ return getValueAttribute();
}
- void updateParameterTypes( Hashtable types ) {
- types.put( getName(), FormControl.TYPE_SCALAR );
+ void updateRequiredValues( Hashtable required ) {
+ if (isReadOnly() && isChecked()) {
+ required.put( getName(), getQueryValue() );
+ }
}
}
@@ -214,25 +262,15 @@
}
- void updateParameterDefaults( Hashtable defaults ) {
- if (isChecked()) addValue( defaults, getName(), getValue() );
- }
-
-
void updateRequiredValues( Hashtable required ) {
if (isReadOnly() && isChecked()) {
- addValue( required, getName(), getValue() );
+ addValue( required, getName(), getQueryValue() );
}
}
- void updateParameterTypes( Hashtable types ) {
- types.put( getName(), FormControl.TYPE_MULTI_VALUED );
- }
-
-
- String getValue() {
- final String value = super.getValue();
+ String getQueryValue() {
+ final String value = getValueAttribute();
return value.length() == 0 ? "on" : value;
}
}
@@ -240,41 +278,42 @@
class TextFormControl extends FormControl {
+ private String[] _value = new String[1];
+ private String[] _defaultValue;
+
- public TextFormControl( Node node ) {
+ public TextFormControl( Node node, String defaultValue ) {
super( node );
+ _defaultValue = new String[] { defaultValue };
}
- void updateParameterDefaults( Hashtable defaults ) {
- defaults.put( getName(), getValue() );
- }
+ /**
+ * Returns the current value(s) associated with this control. These values will be transmitted to the server
+ * if the control is 'successful'.
+ **/
+ String[] getValues() {
+ return (_value[0] != null) ? _value : _defaultValue;
+ }
- void updateTextParameterCounts( Hashtable parameterCounts ) {
- Integer oldCount = (Integer) parameterCounts.get( getName() );
- if (oldCount == null) {
- parameterCounts.put( getName(), ONE_PARAMETER );
- } else {
- parameterCounts.put( getName(), new Integer( oldCount.intValue() + 1 ) );
- }
+ /**
+ * Returns true to indicate that this control accepts free-form text.
+ **/
+ boolean isTextControl() {
+ return true;
}
void updateRequiredValues( Hashtable required ) {
- if (isReadOnly()) required.put( getName(), getValue() );
+ if (isReadOnly()) required.put( getName(), _defaultValue );
}
-
-
- void updateParameterTypes( Hashtable types ) {
- types.put( getName(), FormControl.TYPE_TEXT );
- }
}
class TextFieldFormControl extends TextFormControl {
public TextFieldFormControl( Node node ) {
- super( node );
+ super( node, NodeUtils.getNodeAttribute( node, "value" ) );
}
}
@@ -283,7 +322,7 @@
class TextAreaFormControl extends TextFormControl {
public TextAreaFormControl( Node node ) {
- super( node );
+ super( node, getDefaultValue( node ) );
if (!node.getNodeName().equalsIgnoreCase( "textarea" )) {
throw new RuntimeException( "Not a textarea element" );
@@ -291,8 +330,8 @@
}
- String getValue() {
- return NodeUtils.asText( _node.getChildNodes() );
+ private static String getDefaultValue( Node node ) {
+ return NodeUtils.asText( node.getChildNodes() );
}
}
@@ -304,30 +343,50 @@
super( node );
}
+
+ /**
+ * Returns true if this control accepts a file for upload.
+ **/
+ boolean isFileParameter() {
+ return true;
+ }
+
- void updateParameterTypes( Hashtable types ) {
- types.put( getName(), FormControl.TYPE_FILE );
+ String[] getValues() {
+ return null; // XXX what should this really do?
}
}
class SelectionFormControl extends FormControl {
+ private boolean _multiSelect;
+ private Node _node;
+
SelectionFormControl( Node node ) {
super( node );
- if (!node.getNodeName().equalsIgnoreCase( "select" )) {
- throw new RuntimeException( "Not a select element" );
- }
+ if (!node.getNodeName().equalsIgnoreCase( "select" )) throw new RuntimeException( "Not a select element" );
+
+ _node = node;
+ _multiSelect = NodeUtils.isNodeAttributePresent( node, "multiple" );
}
- void updateParameterDefaults( Hashtable defaults ) {
- defaults.put( getName(), getSelected() );
+ String[] getValues() {
+ return getSelected();
}
+ /**
+ * Returns true if a single control can have multiple values.
+ **/
+ boolean isMultiValued() {
+ return _multiSelect;
+ }
+
+
void updateRequiredParameters( Hashtable required ) {
- if (isDisabled()) required.put( getName(), getSelected() );
+ if (isReadOnly()) required.put( getName(), getSelected() );
}
@@ -341,11 +400,6 @@
}
- void updateParameterTypes( Hashtable types ) {
- types.put( getName(), isMultiSelect() ? FormControl.TYPE_MULTI_VALUED : FormControl.TYPE_SCALAR );
- }
-
-
String[] getSelected() {
Vector selected = new Vector();
NodeList nl = ((Element) _node).getElementsByTagName( "option" );
@@ -355,7 +409,7 @@
}
}
- if (!isMultiSelect() && selected.size() == 0 && nl.getLength() > 0) {
+ if (!isMultiValued() && selected.size() == 0 && nl.getLength() > 0) {
selected.addElement( getOptionValue( nl.item(0) ) );
}
@@ -389,16 +443,6 @@
}
- boolean isMultiSelect() {
- return _node.getAttributes().getNamedItem( "multiple" ) != null;
- }
-
-
- boolean isDisabled() {
- return _node.getAttributes().getNamedItem( "disabled" ) != null;
- }
-
-
private String getOptionValue( Node optionNode ) {
NamedNodeMap nnm = optionNode.getAttributes();
if (nnm.getNamedItem( "value" ) != null) {
@@ -408,6 +452,14 @@
}
}
+ private static String getValue( Node node ) {
+ return (node == null) ? "" : emptyIfNull( node.getNodeValue() );
+ }
+
+
+ private static String emptyIfNull( String value ) {
+ return (value == null) ? "" : value;
+ }
}
Index: NodeUtils.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/NodeUtils.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- NodeUtils.java 2001/11/27 19:51:27 1.8
+++ NodeUtils.java 2002/01/08 14:29:27 1.9
@@ -64,12 +64,15 @@
public static String getNodeAttribute( Node node, String attributeName, String defaultValue ) {
- NamedNodeMap nnm = node.getAttributes();
- Node attribute = nnm.getNamedItem( attributeName );
+ Node attribute = node.getAttributes().getNamedItem( attributeName );
return (attribute == null) ? defaultValue : attribute.getNodeValue();
}
+ static boolean isNodeAttributePresent( Node node, final String attributeName ) {
+ return node.getAttributes().getNamedItem( attributeName ) != null;
+ }
+
/**
* Converts the DOM trees rooted at the specified nodes to text, ignoring
* any HTML tags.
@@ -125,5 +128,6 @@
}
}
}
+
}
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- WebForm.java 2002/01/02 14:13:02 1.36
+++ WebForm.java 2002/01/08 14:29:27 1.37
@@ -24,6 +24,9 @@
import java.util.Hashtable;
import java.util.Vector;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Arrays;
+import java.util.Map;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
@@ -37,6 +40,7 @@
* may also create a {@link WebRequest} to simulate the submission of the form.
**/
public class WebForm extends WebRequestSource {
+ private static final FormParameter UNKNOWN_PARAMETER = new FormParameter();
/**
@@ -67,11 +71,7 @@
* Returns true if a parameter with given name exists in this form.
**/
public boolean hasParameterNamed( String soughtName ) {
- FormControl[] parameters = getParameters();
- for (int i = 0; i < parameters.length; i++) {
- if (parameters[i].getName().equals( soughtName )) return true;
- }
- return false;
+ return getFormParameters().containsKey( soughtName );
}
@@ -79,10 +79,9 @@
* Returns true if a parameter starting with a given name exists,
**/
public boolean hasParameterStartingWithPrefix( String prefix ) {
- FormControl[] parameters = getParameters();
- for (int i = 0; i < parameters.length; i++) {
- String name = parameters[i].getName();
- if (name.startsWith( prefix )) return true;
+ String[] names = getParameterNames();
+ for (int i = 0; i < names.length; i++) {
+ if (names[i].startsWith( prefix )) return true;
}
return false;
}
@@ -93,17 +92,29 @@
* in the order in which they appear.
**/
public String[] getParameterNames() {
- Vector parameterNames = new Vector();
- FormControl[] parameters = getParameters();
+ ArrayList parameterNames = new ArrayList( getFormParameters().keySet() );
+ return (String[]) parameterNames.toArray( new String[ parameterNames.size() ] );
+ }
- for (int i = 0; i < parameters.length; i++) {
- String name = parameters[i].getName();
- if (!parameterNames.contains( name )) parameterNames.addElement( name );
- }
- String[] result = new String[ parameterNames.size() ];
- parameterNames.copyInto( result );
- return result;
+ /**
+ * Returns a map of parameter name to form parameter objects. Each form parameter object represents the set of form
+ * controls with a particular name.
+ */
+ private Map getFormParameters() {
+ if (_formParameters == null) {
+ _formParameters = new HashMap();
+ FormControl[] controls = getFormControls();
+ for (int i = 0; i < controls.length; i++) {
+ FormParameter parameter = (FormParameter) _formParameters.get( controls[i].getName() );
+ if (parameter == null) {
+ parameter = new FormParameter();
+ _formParameters.put( controls[i].getName(), parameter );
+ }
+ parameter.addControl( controls[i] );
+ }
+ }
+ return _formParameters;
}
@@ -120,7 +131,6 @@
}
-
private Vector _buttonVector;
private Vector getSubmitButtonVector() {
@@ -279,13 +289,8 @@
String[] parameterNames = getParameterNames();
for (int i = 0; i < parameterNames.length; i++) {
- if (parameterNames[i].length() > 0 && getParameterDefaults().get( parameterNames[i] ) != null) {
- Object value = getParameterDefaults().get( parameterNames[i] );
- if (value instanceof String) {
- request.setParameter( parameterNames[i], (String) value);
- } else {
- request.setParameter( parameterNames[i], (String[]) value);
- }
+ if (parameterNames[i].length() > 0 && !isFileParameter( parameterNames[i] )) {
+ request.setParameter( parameterNames[i], getParameterValues( parameterNames[i] ) );
}
}
request.setHeaderField( "Referer", getBaseURL().toExternalForm() );
@@ -294,13 +299,11 @@
/**
- * Returns the default value of the named parameter.
+ * Returns the default value of the named parameter. If the parameter does not exist returns null.
**/
public String getParameterValue( String name ) {
- Object result = getParameterDefaults().get( name );
- if (result instanceof String) return (String) result;
- if (result instanceof String[] && ((String[]) result).length > 0) return ((String[]) result)[0];
- return "";
+ String[] values = getParameterValues( name );
+ return values.length == 0 ? null : values[0];
}
@@ -308,13 +311,21 @@
* Returns the multiple default values of the named parameter.
**/
public String[] getParameterValues( String name ) {
- Object result = getParameterDefaults().get( name );
- if (result instanceof String) return new String[] { (String) result };
- if (result instanceof String[]) return (String[]) result;
- return new String[0];
+ ArrayList valueList = new ArrayList();
+ FormControl[] controls = getParameter( name ).getControls();
+ for (int i = 0; i < controls.length; i++) {
+ valueList.addAll( Arrays.asList( controls[i].getValues() ) );
+ }
+ return (String[]) valueList.toArray( new String[ valueList.size() ] );
}
+ private FormParameter getParameter( String name ) {
+ final FormParameter parameter = ((FormParameter) getFormParameters().get( name ));
+ return parameter != null ? parameter : UNKNOWN_PARAMETER;
+ }
+
+
/**
* Returns the displayed options defined for the specified parameter name.
**/
@@ -339,38 +350,38 @@
* Returns true if the named parameter accepts multiple values.
**/
public boolean isMultiValuedParameter( String name ) {
- return FormControl.TYPE_MULTI_VALUED.equals( getParameterTypes().get( name ) );
- }
-
-
- /**
- * Returns true if the named parameter accepts free-form text.
- **/
- public boolean isTextParameter( String name ) {
- return FormControl.TYPE_TEXT.equals( getParameterTypes().get( name ) );
- }
+ FormControl[] controls = getParameter( name ).getControls();
+ for (int i = 0; i < controls.length; i++) {
+ if (controls[i].isMultiValued()) return true;
+ if (!controls[i].isExclusive() && controls.length > 1) return true;
+ }
+ return false;
+ }
/**
* Returns the number of text parameters in this form with the specified name.
**/
public int getNumTextParameters( String name ) {
- Object count = getTextParameterCounts().get( name );
- if (count == null) return 0;
- return ((Number) count ).intValue();
+ int result = 0;
+ FormControl[] controls = getParameter( name ).getControls();
+ for (int i = 0; i < controls.length; i++) {
+ if (controls[i].isTextControl()) result++;
+ }
+ return result;
}
- private Hashtable getTextParameterCounts() {
- if (_textParameterCounts == null) {
- Hashtable parameterCounts = new Hashtable();
- FormControl[] parameters = getParameters();
- for (int i = 0; i < parameters.length; i++) {
- parameters[i].updateTextParameterCounts( parameterCounts );
- }
- _textParameterCounts = parameterCounts;
+
+ /**
+ * Returns true if the named parameter accepts free-form text.
+ **/
+ public boolean isTextParameter( String name ) {
+ FormControl[] controls = getParameter( name ).getControls();
+ for (int i = 0; i < controls.length; i++) {
+ if (controls[i].isTextControl()) return true;
}
- return _textParameterCounts;
+ return false;
}
@@ -378,7 +389,11 @@
* Returns true if the named parameter accepts files for upload.
**/
public boolean isFileParameter( String name ) {
- return FormControl.TYPE_FILE.equals( getParameterTypes().get( name ) );
+ FormControl[] controls = getParameter( name ).getControls();
+ for (int i = 0; i < controls.length; i++) {
+ if (controls[i].isFileParameter()) return true;
+ }
+ return false;
}
@@ -418,45 +433,27 @@
/** The attributes of the form parameters. **/
private FormControl[] _parameters;
- /** The parameters with their default values. **/
- private Hashtable _defaults;
-
/** The parameters with their displayed options. **/
private Hashtable _options;
/** The parameters with their options. **/
private Hashtable _optionValues;
- /** The parameters mapped to the type of data which they accept. **/
- private Hashtable _dataTypes;
-
- /** The parameters mapped to their number of occurrences as text parameters. **/
- private Hashtable _textParameterCounts;
-
/** The submit buttons in this form. **/
private SubmitButton[] _submitButtons;
/** The character set in which the form will be submitted. **/
private String _characterSet;
+ /** A map of parameter names to form parameter objects. **/
+ private Map _formParameters;
- private Hashtable getParameterDefaults() {
- if (_defaults == null) {
- FormControl[] parameters = getParameters();
- Hashtable defaults = new Hashtable();
- for (int i = 0; i < parameters.length; i++) {
- parameters[i].updateParameterDefaults( defaults );
- }
- _defaults = defaults;
- }
- return _defaults;
- }
private Hashtable _required;
private Hashtable getParameterRequiredValues() {
if (_required == null) {
- FormControl[] parameters = getParameters();
+ FormControl[] parameters = getFormControls();
Hashtable required = new Hashtable();
for (int i = 0; i < parameters.length; i++) {
parameters[i].updateRequiredValues( required );
@@ -470,7 +467,7 @@
private Hashtable getParameterOptions() {
if (_options == null) {
Hashtable options = new Hashtable();
- FormControl[] parameters = getParameters();
+ FormControl[] parameters = getFormControls();
for (int i = 0; i < parameters.length; i++) {
parameters[i].updateParameterOptions( options );
}
@@ -483,7 +480,7 @@
private Hashtable getParameterOptionValues() {
if (_optionValues == null) {
Hashtable options = new Hashtable();
- FormControl[] parameters = getParameters();
+ FormControl[] parameters = getFormControls();
for (int i = 0; i < parameters.length; i++) {
parameters[i].updateParameterOptionValues( options );
}
@@ -493,26 +490,13 @@
}
- private Hashtable getParameterTypes() {
- if (_dataTypes == null) {
- FormControl[] parameters = getParameters();
- Hashtable types = new Hashtable();
- for (int i = 0; i < parameters.length; i++) {
- parameters[i].updateParameterTypes( types );
- }
- _dataTypes = types;
- }
- return _dataTypes;
- }
-
-
/**
* Returns an array of select control descriptors for this form.
**/
/**
* Returns an array of form parameter attributes for this form.
**/
- private FormControl[] getParameters() {
+ private FormControl[] getFormControls() {
if (_parameters == null) {
Vector list = new Vector();
if (getNode().hasChildNodes()) addFormParametersToList( getNode().getChildNodes(), list );
@@ -546,11 +530,19 @@
class FormParameter {
void addControl( FormControl control ) {
- _controls.add( control );
+ _controlList.add( control );
+ _controls = null;
+ }
+
+
+ FormControl[] getControls() {
+ if (_controls == null) _controls = (FormControl[]) _controlList.toArray( new FormControl[ _controlList.size() ] );
+ return _controls;
}
- private ArrayList _controls = new ArrayList();
+ private FormControl[] _controls;
+ private ArrayList _controlList = new ArrayList();
}
|
|
From: Russell G. <rus...@us...> - 2002-01-02 14:21:30
|
Update of /cvsroot/httpunit/httpunit/jars In directory usw-pr-cvs1:/tmp/cvs-serv9917 Added Files: activation.jar mailapi.jar Log Message: step 1: fixing jar archive |
|
From: Russell G. <rus...@us...> - 2002-01-02 14:19:37
|
Update of /cvsroot/httpunit/httpunit/jars In directory usw-pr-cvs1:/tmp/cvs-serv9419 Removed Files: activation.jar mailapi.jar Log Message: step 1: fixing jar archive |
|
From: Russell G. <rus...@us...> - 2002-01-02 14:13:04
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv8097/src/com/meterware/httpunit
Modified Files:
WebForm.java
Log Message:
Add missing semicolon
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- WebForm.java 2002/01/01 19:29:07 1.35
+++ WebForm.java 2002/01/02 14:13:02 1.36
@@ -546,7 +546,7 @@
class FormParameter {
void addControl( FormControl control ) {
- _controls.add( control )
+ _controls.add( control );
}
|
|
From: Russell G. <rus...@us...> - 2002-01-01 19:29:11
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit
In directory usw-pr-cvs1:/tmp/cvs-serv5993/test/com/meterware/servletunit
Modified Files:
WebXMLTest.java
Log Message:
More refactoring
Index: WebXMLTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/WebXMLTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- WebXMLTest.java 2001/12/03 15:42:39 1.3
+++ WebXMLTest.java 2002/01/01 19:29:08 1.4
@@ -177,14 +177,14 @@
WebXMLString wxs = new WebXMLString();
wxs.addServlet( "/Logon", SimpleLogonServlet.class );
wxs.addServlet( "/Error", SimpleErrorServlet.class );
- wxs.addServlet( "/SimpleServlet", SimpleGetServlet.class );
+ wxs.addServlet( "/Example/SimpleServlet", SimpleGetServlet.class );
wxs.requireFormAuthentication( "Sample Realm", "/Logon", "/Error" );
- wxs.addSecureURL( "SecureArea1", "/SimpleServlet" );
+ wxs.addSecureURL( "SecureArea1", "/Example/SimpleServlet" );
wxs.addAuthorizedRole( "SecureArea1", "supervisor" );
ServletRunner sr = new ServletRunner( toInputStream( wxs.asText() ) );
ServletUnitClient wc = sr.newClient();
- WebResponse response = wc.getResponse( "http://localhost/SimpleServlet" );
+ WebResponse response = wc.getResponse( "http://localhost/Example/SimpleServlet" );
WebForm form = response.getFormWithID( "login" );
assertNotNull( "did not find login form", form );
@@ -196,7 +196,7 @@
assertEquals( "content type", "text/html", response.getContentType() );
assertEquals( "requested resource", SimpleGetServlet.RESPONSE_TEXT, response.getText() );
- InvocationContext ic = wc.newInvocation( "http://localhost/SimpleServlet" );
+ InvocationContext ic = wc.newInvocation( "http://localhost/Example/SimpleServlet" );
assertEquals( "Authenticated user", "Me", ic.getRequest().getRemoteUser() );
assertTrue( "User assigned to 'bogus' role", !ic.getRequest().isUserInRole( "bogus" ) );
assertTrue( "User not assigned to 'supervisor' role", ic.getRequest().isUserInRole( "supervisor" ) );
|
|
From: Russell G. <rus...@us...> - 2002-01-01 19:29:11
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit
In directory usw-pr-cvs1:/tmp/cvs-serv5993/src/com/meterware/servletunit
Modified Files:
WebApplication.java
Log Message:
More refactoring
Index: WebApplication.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/WebApplication.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WebApplication.java 2001/11/26 14:20:12 1.1
+++ WebApplication.java 2002/01/01 19:29:08 1.2
@@ -65,7 +65,6 @@
*/
WebApplication( Document document ) throws MalformedURLException,SAXException {
registerServlets( document );
- registerServlet( "/j_security_check", SecurityCheckServlet.class.getName() );
NodeList nl = document.getElementsByTagName( "security-constraint" );
for (int i = 0; i < nl.getLength(); i++) {
_securityConstraints.add( new SecurityConstraintImpl( (Element) nl.item(i) ) );
@@ -91,7 +90,7 @@
Servlet getServlet( URL url ) throws ServletException {
- final ServletConfiguration configuration = (ServletConfiguration) _servlets.get( getServletName( getURLPath( url ) ) );
+ final ServletConfiguration configuration = getServletConfiguration( url );
if (configuration == null) throw new HttpNotFoundException( url );
try {
@@ -111,6 +110,16 @@
}
+ private ServletConfiguration getServletConfiguration(URL url) {
+ String servletName = getServletName( getURLPath( url ) );
+ if (servletName.endsWith( "j_security_check" )) {
+ return SECURITY_CHECK_CONFIGURATION;
+ } else {
+ return (ServletConfiguration) _servlets.get( servletName );
+ }
+ }
+
+
private String getURLPath( URL url ) {
return url.getFile();
}
@@ -175,6 +184,8 @@
//------------------------------------------------ private members ---------------------------------------------
+ private final static ServletConfiguration SECURITY_CHECK_CONFIGURATION = new ServletConfiguration( SecurityCheckServlet.class.getName() );
+
/** A mapping of resource names to servlet class names. **/
private Hashtable _servlets = new Hashtable();
@@ -235,12 +246,12 @@
}
- private String getChildNodeValue( Element root, String childNodeName ) throws SAXException {
+ private static String getChildNodeValue( Element root, String childNodeName ) throws SAXException {
return getChildNodeValue( root, childNodeName, null );
}
- private String getChildNodeValue( Element root, String childNodeName, String defaultValue ) throws SAXException {
+ private static String getChildNodeValue( Element root, String childNodeName, String defaultValue ) throws SAXException {
NodeList nl = root.getElementsByTagName( childNodeName );
if (nl.getLength() == 1) {
return getTextValue( nl.item(0) );
@@ -307,7 +318,7 @@
//============================================= ServletConfiguration class =============================================
- class ServletConfiguration {
+ static class ServletConfiguration {
public ServletConfiguration( String className ) {
_className = className;
|
|
From: Russell G. <rus...@us...> - 2002-01-01 19:29:10
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv5993/src/com/meterware/httpunit
Modified Files:
WebForm.java
Added Files:
FormControl.java
Log Message:
More refactoring
***** Error reading new file[Errno 2] No such file or directory: 'FormControl.java'
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- WebForm.java 2001/12/11 21:42:34 1.34
+++ WebForm.java 2002/01/01 19:29:07 1.35
@@ -23,6 +23,7 @@
import java.util.Hashtable;
import java.util.Vector;
+import java.util.ArrayList;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
@@ -70,12 +71,6 @@
for (int i = 0; i < parameters.length; i++) {
if (parameters[i].getName().equals( soughtName )) return true;
}
-
- HTMLSelectElement[] selections = getSelections();
- for (int i = 0; i < selections.length; i++) {
- if (soughtName.equals( selections[ i ].getName() )) return true;
- }
-
return false;
}
@@ -89,12 +84,6 @@
String name = parameters[i].getName();
if (name.startsWith( prefix )) return true;
}
-
- HTMLSelectElement[] selections = getSelections();
- for (int i = 0; i < selections.length; i++) {
- if (selections[ i ].getName().startsWith( prefix )) return true;
- }
-
return false;
}
@@ -112,11 +101,6 @@
if (!parameterNames.contains( name )) parameterNames.addElement( name );
}
- HTMLSelectElement[] selections = getSelections();
- for (int i = 0; i < selections.length; i++) {
- parameterNames.addElement( selections[i].getName() );
- }
-
String[] result = new String[ parameterNames.size() ];
parameterNames.copyInto( result );
return result;
@@ -283,18 +267,14 @@
}
}
- NamedNodeMap nnm = getNode().getAttributes();
String action = getAction();
- if (action.trim().length() == 0) {
- action = getBaseURL().getFile();
- }
-
- WebRequest result;
+ if (action.trim().length() == 0) action = getBaseURL().getFile();
- if (getValue( nnm.getNamedItem( "method" ) ).equalsIgnoreCase( "post" )) {
- result = new PostMethodWebRequest( getBaseURL(), action, getTarget(), this, button );
+ WebRequest request;
+ if (getMethod().equalsIgnoreCase( "post" )) {
+ request = new PostMethodWebRequest( getBaseURL(), action, getTarget(), this, button );
} else {
- result = new GetMethodWebRequest( getBaseURL(), action, getTarget(), this, button );
+ request = new GetMethodWebRequest( getBaseURL(), action, getTarget(), this, button );
}
String[] parameterNames = getParameterNames();
@@ -302,14 +282,14 @@
if (parameterNames[i].length() > 0 && getParameterDefaults().get( parameterNames[i] ) != null) {
Object value = getParameterDefaults().get( parameterNames[i] );
if (value instanceof String) {
- result.setParameter( parameterNames[i], (String) value);
+ request.setParameter( parameterNames[i], (String) value);
} else {
- result.setParameter( parameterNames[i], (String[]) value);
+ request.setParameter( parameterNames[i], (String[]) value);
}
}
}
- result.setHeaderField( "Referer", getBaseURL().toExternalForm() );
- return result;
+ request.setHeaderField( "Referer", getBaseURL().toExternalForm() );
+ return request;
}
@@ -359,7 +339,7 @@
* Returns true if the named parameter accepts multiple values.
**/
public boolean isMultiValuedParameter( String name ) {
- return TYPE_MULTI_VALUED.equals( getParameterTypes().get( name ) );
+ return FormControl.TYPE_MULTI_VALUED.equals( getParameterTypes().get( name ) );
}
@@ -367,7 +347,7 @@
* Returns true if the named parameter accepts free-form text.
**/
public boolean isTextParameter( String name ) {
- return TYPE_TEXT.equals( getParameterTypes().get( name ) );
+ return FormControl.TYPE_TEXT.equals( getParameterTypes().get( name ) );
}
@@ -382,7 +362,14 @@
private Hashtable getTextParameterCounts() {
- getParameterTypes();
+ if (_textParameterCounts == null) {
+ Hashtable parameterCounts = new Hashtable();
+ FormControl[] parameters = getParameters();
+ for (int i = 0; i < parameters.length; i++) {
+ parameters[i].updateTextParameterCounts( parameterCounts );
+ }
+ _textParameterCounts = parameterCounts;
+ }
return _textParameterCounts;
}
@@ -391,7 +378,7 @@
* Returns true if the named parameter accepts files for upload.
**/
public boolean isFileParameter( String name ) {
- return TYPE_FILE.equals( getParameterTypes().get( name ) );
+ return FormControl.TYPE_FILE.equals( getParameterTypes().get( name ) );
}
@@ -428,22 +415,6 @@
//---------------------------------- private members --------------------------------
- /** The type of a parameter which accepts any text. **/
- private final static Integer TYPE_TEXT = new Integer(1);
-
- /** The type of a parameter which accepts single predefined values. **/
- private final static Integer TYPE_SCALAR = new Integer(2);
-
- /** The type of a parameter which accepts multiple predefined values. **/
- private final static Integer TYPE_MULTI_VALUED = new Integer(3);
-
- /** The type of a parameter which accepts files for upload. **/
- private final static Integer TYPE_FILE = new Integer(4);
-
- /** A constant set to indicate one parameter. **/
- private final static Integer ONE_PARAMETER = new Integer(1);
-
-
/** The attributes of the form parameters. **/
private FormControl[] _parameters;
@@ -465,50 +436,16 @@
/** The submit buttons in this form. **/
private SubmitButton[] _submitButtons;
- /** The selections in this form. **/
- private HTMLSelectElement[] _selections;
-
/** The character set in which the form will be submitted. **/
private String _characterSet;
- private String getValue( Node node ) {
- return (node == null) ? "" : emptyIfNull( node.getNodeValue() );
- }
-
-
- private String emptyIfNull( String value ) {
- return (value == null) ? "" : value;
- }
-
-
private Hashtable getParameterDefaults() {
if (_defaults == null) {
FormControl[] parameters = getParameters();
Hashtable defaults = new Hashtable();
for (int i = 0; i < parameters.length; i++) {
- String name = parameters[i].getName();
- String value = parameters[i].getValue();
- String type = getValue( parameters[i].getNamedItem( "type" ) ).toUpperCase();
- if (type == null || type.length() == 0) type = "TEXT";
-
- if (type.equals( "TEXT" ) || type.equals( "HIDDEN" ) || type.equals( "PASSWORD" )) {
- defaults.put( name, value );
- } else if (type.equals( "RADIO" ) && parameters[i].getNamedItem( "checked" ) != null) {
- defaults.put( name, value );
- } else if (type.equals( "CHECKBOX" ) && parameters[i].getNamedItem( "checked" ) != null) {
- if (value.length() == 0) value = "on";
- String[] currentDefaults = (String[]) defaults.get( name );
- if (currentDefaults == null) {
- defaults.put( name, new String[] { value } );
- } else {
- defaults.put( name, withNewValue( currentDefaults, value ) );
- }
- }
- }
- HTMLSelectElement[] selections = getSelections();
- for (int i = 0; i < selections.length; i++) {
- defaults.put( selections[i].getName(), selections[i].getSelected() );
+ parameters[i].updateParameterDefaults( defaults );
}
_defaults = defaults;
}
@@ -522,29 +459,7 @@
FormControl[] parameters = getParameters();
Hashtable required = new Hashtable();
for (int i = 0; i < parameters.length; i++) {
- String name = parameters[i].getName();
- String value = parameters[i].getValue();
- String type = getValue( parameters[i].getNamedItem( "type" ) ).toUpperCase();
- if (type == null || type.length() == 0) type = "TEXT";
- if (!parameters[i].isReadOnly()) continue;
-
- if (type.equals( "TEXT" ) || type.equals( "HIDDEN" ) || type.equals( "PASSWORD" )) {
- required.put( name, value );
- } else if (type.equals( "RADIO" ) && parameters[i].getNamedItem( "checked" ) != null) {
- required.put( name, value );
- } else if (type.equals( "CHECKBOX" ) && parameters[i].getNamedItem( "checked" ) != null) {
- if (value.length() == 0) value = "on";
- String[] currentDefaults = (String[]) required.get( name );
- if (currentDefaults == null) {
- required.put( name, new String[] { value } );
- } else {
- required.put( name, withNewValue( currentDefaults, value ) );
- }
- }
- }
- HTMLSelectElement[] selections = getSelections();
- for (int i = 0; i < selections.length; i++) {
- if (selections[i].isDisabled()) required.put( selections[i].getName(), selections[i].getSelected() );
+ parameters[i].updateRequiredValues( required );
}
_required = required;
}
@@ -555,9 +470,9 @@
private Hashtable getParameterOptions() {
if (_options == null) {
Hashtable options = new Hashtable();
- HTMLSelectElement[] selections = getSelections();
- for (int i = 0; i < selections.length; i++) {
- options.put( selections[i].getName(), selections[i].getOptions() );
+ FormControl[] parameters = getParameters();
+ for (int i = 0; i < parameters.length; i++) {
+ parameters[i].updateParameterOptions( options );
}
_options = options;
}
@@ -570,26 +485,7 @@
Hashtable options = new Hashtable();
FormControl[] parameters = getParameters();
for (int i = 0; i < parameters.length; i++) {
- String name = parameters[i].getName();
- String value = parameters[i].getValue();
- String type = getValue( parameters[i].getNamedItem( "type" ) ).toUpperCase();
- if (type == null || type.length() == 0) type = "TEXT";
-
- if ((type.equals( "RADIO" ) || type.equals( "CHECKBOX" ))
- && (!parameters[i].isReadOnly()
- || parameters[i].getNamedItem( "checked" ) != null)) {
- if (value.length() == 0 && type.equals( "CHECKBOX" )) value = "on";
- String[] radioOptions = (String[]) options.get( name );
- if (radioOptions == null) {
- options.put( name, new String[] { value } );
- } else {
- options.put( name, withNewValue( radioOptions, value ) );
- }
- }
- }
- HTMLSelectElement[] selections = getSelections();
- for (int i = 0; i < selections.length; i++) {
- options.put( selections[i].getName(), selections[i].getOptionValues() );
+ parameters[i].updateParameterOptionValues( options );
}
_optionValues = options;
}
@@ -597,46 +493,12 @@
}
- /**
- * Adds a string to an array of strings and returns the result.
- **/
- private String[] withNewValue( String[] group, String value ) {
- String[] result = new String[ group.length+1 ];
- System.arraycopy( group, 0, result, 0, group.length );
- result[ group.length ] = value;
- return result;
- }
-
-
private Hashtable getParameterTypes() {
if (_dataTypes == null) {
FormControl[] parameters = getParameters();
Hashtable types = new Hashtable();
- _textParameterCounts = new Hashtable();
for (int i = 0; i < parameters.length; i++) {
- String name = parameters[i].getName();
- String type = getValue( parameters[i].getNamedItem( "type" ) ).toUpperCase();
- if (type == null || type.length() == 0) type = "TEXT";
-
- if (type.equals( "RADIO" )) {
- types.put( name, TYPE_SCALAR );
- } else if (type.equals( "CHECKBOX" )) {
- types.put( name, TYPE_MULTI_VALUED );
- } else if (type.equals( "FILE" )) {
- types.put( name, TYPE_FILE );
- } else if (type.equals( "TEXT" ) || type.equals( "HIDDEN" ) || type.equals( "PASSWORD" )) {
- types.put( name, TYPE_TEXT );
- Integer oldCount = (Integer) _textParameterCounts.get( name );
- if (oldCount == null) {
- _textParameterCounts.put( name, ONE_PARAMETER );
- } else {
- _textParameterCounts.put( name, new Integer( oldCount.intValue() + 1 ) );
- }
- }
- }
- HTMLSelectElement[] selections = getSelections();
- for (int i = 0; i < selections.length; i++) {
- types.put( selections[i].getName(), selections[i].isMultiSelect() ? TYPE_MULTI_VALUED : TYPE_SCALAR );
+ parameters[i].updateParameterTypes( types );
}
_dataTypes = types;
}
@@ -647,21 +509,6 @@
/**
* Returns an array of select control descriptors for this form.
**/
- private HTMLSelectElement[] getSelections() {
- if (_selections == null) {
- NodeList nl = ((Element) getNode()).getElementsByTagName( "select" );
- HTMLSelectElement[] result = new HTMLSelectElement[ nl.getLength() ];
- for (int i = 0; i < result.length; i++) {
- result[i] = new HTMLSelectElement( nl.item(i) );
- }
- _selections = result;
- }
- return _selections;
- }
-
- /**
- * Returns an array of select control descriptors for this form.
- **/
/**
* Returns an array of form parameter attributes for this form.
**/
@@ -686,180 +533,27 @@
private void addFormParametersToList( Node child, Vector list ) {
final FormControl formParameter = FormControl.newFormParameter( child );
- if (formParameter != null) {
+ if (formParameter != null) {
list.addElement( formParameter );
} else if (child.hasChildNodes()) {
addFormParametersToList( child.getChildNodes(), list );
}
}
-
- class HTMLSelectElement {
- HTMLSelectElement( Node node ) {
- if (!node.getNodeName().equalsIgnoreCase( "select" )) {
- throw new RuntimeException( "Not a select element" );
- }
- _node = node;
- }
-
-
- private Node _node;
-
-
- String getName() {
- NamedNodeMap nnm = _node.getAttributes();
- return getValue( nnm.getNamedItem( "name" ) );
- }
-
-
- String[] getSelected() {
- Vector selected = new Vector();
- NodeList nl = ((Element) _node).getElementsByTagName( "option" );
- for (int i = 0; i < nl.getLength(); i++) {
- if (nl.item(i).getAttributes().getNamedItem( "selected" ) != null) {
- selected.addElement( getOptionValue( nl.item(i) ) );
- }
- }
-
- if (!isMultiSelect() && selected.size() == 0 && nl.getLength() > 0) {
- selected.addElement( getOptionValue( nl.item(0) ) );
- }
-
- String[] result = new String[ selected.size() ];
- selected.copyInto( result );
- return result;
- }
-
-
- String[] getOptions() {
- Vector options = new Vector();
- NodeList nl = ((Element) _node).getElementsByTagName( "option" );
- for (int i = 0; i < nl.getLength(); i++) {
- options.addElement( getValue( nl.item(i).getFirstChild() ) );
- }
- String[] result = new String[ options.size() ];
- options.copyInto( result );
- return result;
- }
-
-
- String[] getOptionValues() {
- Vector options = new Vector();
- NodeList nl = ((Element) _node).getElementsByTagName( "option" );
- for (int i = 0; i < nl.getLength(); i++) {
- options.addElement( getOptionValue( nl.item(i) ) );
- }
- String[] result = new String[ options.size() ];
- options.copyInto( result );
- return result;
- }
-
-
- boolean isMultiSelect() {
- return _node.getAttributes().getNamedItem( "multiple" ) != null;
- }
-
-
- boolean isDisabled() {
- return _node.getAttributes().getNamedItem( "disabled" ) != null;
- }
-
-
- private String getOptionValue( Node optionNode ) {
- NamedNodeMap nnm = optionNode.getAttributes();
- if (nnm.getNamedItem( "value" ) != null) {
- return getValue( nnm.getNamedItem( "value" ) );
- } else {
- return getValue( optionNode.getFirstChild() );
- }
- }
-
-
- }
-
}
-
-class FormControl {
- protected Node _node;
+class FormParameter {
-
- FormControl( Node node ) {
- _node = node;
+ void addControl( FormControl control ) {
+ _controls.add( control )
}
- Node getNamedItem( String attributeName ) {
- return _node.getAttributes().getNamedItem( attributeName );
- }
-
-
- /**
- * Returns the name of this control. If no name is specified, defaults to the empty string.
- **/
- String getName() {
- return NodeUtils.getNodeAttribute( _node, "name" );
- }
-
-
- /**
- * Returns the value of this control. If no value is specified, defaults to the empty string.
- **/
- String getValue() {
- return NodeUtils.getNodeAttribute( _node, "value" );
- }
-
-
- /**
- * Returns true if this control is read-only.
- **/
- boolean isReadOnly() {
- return _node.getAttributes().getNamedItem( "readonly" ) != null;
- }
-
-
- static FormControl newFormParameter( Node node ) {
- if (node.getNodeType() != Node.ELEMENT_NODE) {
- return null;
- } else if (node.getNodeName().equals( "textarea" )) {
- return new TextAreaFormControl( node );
- } else if (!node.getNodeName().equals( "input" )) {
- return null;
- } else {
- NamedNodeMap nnm = node.getAttributes();
- Node n = nnm.getNamedItem( "type" );
- if (n == null) {
- return new FormControl( node );
- } else if (n.getNodeValue().equalsIgnoreCase( "submit" )) {
- return null;
- } else if (n.getNodeValue().equalsIgnoreCase( "reset" )) {
- return null;
- } else {
- return new FormControl( node );
- }
- }
- }
-
+ private ArrayList _controls = new ArrayList();
}
-class TextAreaFormControl extends FormControl {
-
- public TextAreaFormControl( Node node ) {
- super( node );
-
- if (!node.getNodeName().equalsIgnoreCase( "textarea" )) {
- throw new RuntimeException( "Not a textarea element" );
- }
- }
-
-
- String getValue() {
- return NodeUtils.asText( _node.getChildNodes() );
- }
-
-}
//============================= exception class IllegalUnnamedSubmitButtonException ======================================
|
|
From: Russell G. <rus...@us...> - 2001-12-17 14:53:44
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv1822/doc Added Files: .cvsignore Log Message: Added .cvsignore to cover temporaries and IDEA project --- NEW FILE --- api |
|
From: Russell G. <rus...@us...> - 2001-12-17 14:53:44
|
Update of /cvsroot/httpunit/httpunit/jars In directory usw-pr-cvs1:/tmp/cvs-serv1822/jars Modified Files: Tidy.jar Log Message: Added .cvsignore to cover temporaries and IDEA project Index: Tidy.jar =================================================================== RCS file: /cvsroot/httpunit/httpunit/jars/Tidy.jar,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 Binary files /tmp/cvs2vkm2i and /tmp/cvsrQHxKj differ |
|
From: Russell G. <rus...@us...> - 2001-12-17 14:53:43
|
Update of /cvsroot/httpunit/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv1822 Added Files: .cvsignore Log Message: Added .cvsignore to cover temporaries and IDEA project --- NEW FILE --- build *.ipr |
|
From: Russell G. <rus...@us...> - 2001-12-12 17:27:24
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv20583/test/com/meterware/httpunit
Modified Files:
JTidyPrintWriterTest.java
Log Message:
from Benoit Xhenseval: fixed bug #492003
Index: JTidyPrintWriterTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/JTidyPrintWriterTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JTidyPrintWriterTest.java 2001/11/14 17:11:29 1.1
+++ JTidyPrintWriterTest.java 2001/12/12 17:27:22 1.2
@@ -21,6 +21,7 @@
*******************************************************************************************************************/
import java.net.URL;
+import java.io.PrintWriter;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -60,6 +61,18 @@
super.tearDown();
}
+ /**
+ * Tidy seems to be returning number in a funny format... test if it is handled ok
+ **/
+ public void testLongLine() throws Exception {
+ URL url = new URL("http://localhost/blank.html");
+ PrintWriter p = new JTidyPrintWriter(url);
+ p.print("line 1234 column 1234");
+ p.print("line 1.234 column 1.234");
+ p.print("line 1.234.567 column 1.234.567");
+ p.print("line 1.2.34 column 12.34");
+ p.print("line 123..4 column 12..34");
+ }
public void testWrongXHTMLPage() throws Exception {
defineResource( "SimplePage.html",
@@ -139,4 +152,4 @@
private boolean _foundErrors;
private URL _badURL;
-}
+}
\ No newline at end of file
|
|
From: Russell G. <rus...@us...> - 2001-12-12 17:27:24
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv20583/src/com/meterware/httpunit
Modified Files:
JTidyPrintWriter.java
Log Message:
from Benoit Xhenseval: fixed bug #492003
Index: JTidyPrintWriter.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/JTidyPrintWriter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JTidyPrintWriter.java 2001/11/14 17:11:28 1.1
+++ JTidyPrintWriter.java 2001/12/12 17:27:22 1.2
@@ -70,6 +70,21 @@
}
/**
+ * Tidy is apparently returning line number in a format x.xxx remove the dots
+ **/
+ private String removeDots(String string)
+ {
+ StringTokenizer tok = new StringTokenizer(string,".");
+ StringBuffer buf = new StringBuffer();
+ String elem;
+ while(tok.hasMoreElements()) {
+ elem = tok.nextToken();
+ buf.append(elem);
+ }
+ return buf.toString();
+ }
+
+ /**
* Detects a new log if starting with "line", a warning if message starts with "Warning"
* and an error if it starts with "Error"
**/
@@ -83,11 +98,11 @@
// skip first "line"
tok.nextToken();
// get line
- _line = Integer.parseInt(tok.nextToken());
+ _line = Integer.parseInt(removeDots(tok.nextToken()));
// skip second "column"
tok.nextToken();
// get column
- _column = Integer.parseInt(tok.nextToken());
+ _column = Integer.parseInt(removeDots(tok.nextToken()));
} else if (s.startsWith("Warning")) {
_error = false;
_msg = s;
@@ -190,4 +205,4 @@
((HtmlErrorListener) enum.nextElement()).warning( _url, msg, line, column );
}
}
-}
+}
\ No newline at end of file
|
|
From: Russell G. <rus...@us...> - 2001-12-12 17:27:24
|
Update of /cvsroot/httpunit/httpunit/doc In directory usw-pr-cvs1:/tmp/cvs-serv20583/doc Modified Files: release_notes.txt Log Message: from Benoit Xhenseval: fixed bug #492003 Index: release_notes.txt =================================================================== RCS file: /cvsroot/httpunit/httpunit/doc/release_notes.txt,v retrieving revision 1.74 retrieving revision 1.75 diff -u -r1.74 -r1.75 --- release_notes.txt 2001/12/03 15:39:31 1.74 +++ release_notes.txt 2001/12/12 17:27:21 1.75 @@ -13,6 +13,11 @@ Revision History: +12-Dec-2001 + +Problems fixed: + 1. (bug #492003) JTidyPrintWriter fails to parse columns + 3-Dec-2001 Acknowledgements: |
|
From: Russell G. <rus...@us...> - 2001-12-11 21:42:38
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv23663/src/com/meterware/httpunit
Modified Files:
WebForm.java
Log Message:
Refactoring to move to internal parameter control objects
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- WebForm.java 2001/12/03 15:39:31 1.33
+++ WebForm.java 2001/12/11 21:42:34 1.34
@@ -66,10 +66,9 @@
* Returns true if a parameter with given name exists in this form.
**/
public boolean hasParameterNamed( String soughtName ) {
- NamedNodeMap[] parameters = getParameters();
+ FormControl[] parameters = getParameters();
for (int i = 0; i < parameters.length; i++) {
- String name = getValue( parameters[ i ].getNamedItem( "name" ) );
- if (name.equals( soughtName )) return true;
+ if (parameters[i].getName().equals( soughtName )) return true;
}
HTMLSelectElement[] selections = getSelections();
@@ -77,11 +76,6 @@
if (soughtName.equals( selections[ i ].getName() )) return true;
}
- HTMLTextAreaElement[] textAreas = getTextAreas();
- for (int i = 0; i < textAreas.length; i++) {
- if (soughtName.equals( textAreas[ i ].getName() )) return true;
- }
-
return false;
}
@@ -90,9 +84,9 @@
* Returns true if a parameter starting with a given name exists,
**/
public boolean hasParameterStartingWithPrefix( String prefix ) {
- NamedNodeMap[] parameters = getParameters();
+ FormControl[] parameters = getParameters();
for (int i = 0; i < parameters.length; i++) {
- String name = getValue( parameters[ i ].getNamedItem( "name" ) );
+ String name = parameters[i].getName();
if (name.startsWith( prefix )) return true;
}
@@ -101,11 +95,6 @@
if (selections[ i ].getName().startsWith( prefix )) return true;
}
- HTMLTextAreaElement[] textAreas = getTextAreas();
- for (int i = 0; i < textAreas.length; i++) {
- if (textAreas[ i ].getName().startsWith( prefix )) return true;
- }
-
return false;
}
@@ -116,10 +105,10 @@
**/
public String[] getParameterNames() {
Vector parameterNames = new Vector();
- NamedNodeMap[] parameters = getParameters();
+ FormControl[] parameters = getParameters();
for (int i = 0; i < parameters.length; i++) {
- String name = getValue( parameters[i].getNamedItem( "name" ) );
+ String name = parameters[i].getName();
if (!parameterNames.contains( name )) parameterNames.addElement( name );
}
@@ -128,11 +117,6 @@
parameterNames.addElement( selections[i].getName() );
}
- HTMLTextAreaElement[] textAreas = getTextAreas();
- for (int i = 0; i < textAreas.length; i++) {
- parameterNames.addElement( textAreas[i].getName() );
- }
-
String[] result = new String[ parameterNames.size() ];
parameterNames.copyInto( result );
return result;
@@ -300,7 +284,7 @@
}
NamedNodeMap nnm = getNode().getAttributes();
- String action = getValue( nnm.getNamedItem( "action" ) );
+ String action = getAction();
if (action.trim().length() == 0) {
action = getBaseURL().getFile();
}
@@ -461,7 +445,7 @@
/** The attributes of the form parameters. **/
- private NamedNodeMap[] _parameters;
+ private FormControl[] _parameters;
/** The parameters with their default values. **/
private Hashtable _defaults;
@@ -484,9 +468,6 @@
/** The selections in this form. **/
private HTMLSelectElement[] _selections;
- /** The text areas in this form. **/
- private HTMLTextAreaElement[] _textAreas;
-
/** The character set in which the form will be submitted. **/
private String _characterSet;
@@ -503,11 +484,11 @@
private Hashtable getParameterDefaults() {
if (_defaults == null) {
- NamedNodeMap[] parameters = getParameters();
+ FormControl[] parameters = getParameters();
Hashtable defaults = new Hashtable();
for (int i = 0; i < parameters.length; i++) {
- String name = getValue( parameters[i].getNamedItem( "name" ) );
- String value = getValue( parameters[i].getNamedItem( "value" ) );
+ String name = parameters[i].getName();
+ String value = parameters[i].getValue();
String type = getValue( parameters[i].getNamedItem( "type" ) ).toUpperCase();
if (type == null || type.length() == 0) type = "TEXT";
@@ -529,10 +510,6 @@
for (int i = 0; i < selections.length; i++) {
defaults.put( selections[i].getName(), selections[i].getSelected() );
}
- HTMLTextAreaElement[] textAreas = getTextAreas();
- for (int i = 0; i < textAreas.length; i++) {
- defaults.put( textAreas[i].getName(), textAreas[i].getValue() );
- }
_defaults = defaults;
}
return _defaults;
@@ -542,14 +519,14 @@
private Hashtable getParameterRequiredValues() {
if (_required == null) {
- NamedNodeMap[] parameters = getParameters();
+ FormControl[] parameters = getParameters();
Hashtable required = new Hashtable();
for (int i = 0; i < parameters.length; i++) {
- String name = getValue( parameters[i].getNamedItem( "name" ) );
- String value = getValue( parameters[i].getNamedItem( "value" ) );
+ String name = parameters[i].getName();
+ String value = parameters[i].getValue();
String type = getValue( parameters[i].getNamedItem( "type" ) ).toUpperCase();
if (type == null || type.length() == 0) type = "TEXT";
- if (parameters[i].getNamedItem( "readonly" ) == null) continue;
+ if (!parameters[i].isReadOnly()) continue;
if (type.equals( "TEXT" ) || type.equals( "HIDDEN" ) || type.equals( "PASSWORD" )) {
required.put( name, value );
@@ -569,10 +546,6 @@
for (int i = 0; i < selections.length; i++) {
if (selections[i].isDisabled()) required.put( selections[i].getName(), selections[i].getSelected() );
}
- HTMLTextAreaElement[] textAreas = getTextAreas();
- for (int i = 0; i < textAreas.length; i++) {
- if (textAreas[i].isReadOnly()) required.put( textAreas[i].getName(), textAreas[i].getValue() );
- }
_required = required;
}
return _required;
@@ -595,15 +568,15 @@
private Hashtable getParameterOptionValues() {
if (_optionValues == null) {
Hashtable options = new Hashtable();
- NamedNodeMap[] parameters = getParameters();
+ FormControl[] parameters = getParameters();
for (int i = 0; i < parameters.length; i++) {
- String name = getValue( parameters[i].getNamedItem( "name" ) );
- String value = getValue( parameters[i].getNamedItem( "value" ) );
+ String name = parameters[i].getName();
+ String value = parameters[i].getValue();
String type = getValue( parameters[i].getNamedItem( "type" ) ).toUpperCase();
if (type == null || type.length() == 0) type = "TEXT";
if ((type.equals( "RADIO" ) || type.equals( "CHECKBOX" ))
- && (parameters[i].getNamedItem( "readonly" ) == null
+ && (!parameters[i].isReadOnly()
|| parameters[i].getNamedItem( "checked" ) != null)) {
if (value.length() == 0 && type.equals( "CHECKBOX" )) value = "on";
String[] radioOptions = (String[]) options.get( name );
@@ -637,11 +610,11 @@
private Hashtable getParameterTypes() {
if (_dataTypes == null) {
- NamedNodeMap[] parameters = getParameters();
+ FormControl[] parameters = getParameters();
Hashtable types = new Hashtable();
_textParameterCounts = new Hashtable();
for (int i = 0; i < parameters.length; i++) {
- String name = getValue( parameters[i].getNamedItem( "name" ) );
+ String name = parameters[i].getName();
String type = getValue( parameters[i].getNamedItem( "type" ) ).toUpperCase();
if (type == null || type.length() == 0) type = "TEXT";
@@ -665,10 +638,6 @@
for (int i = 0; i < selections.length; i++) {
types.put( selections[i].getName(), selections[i].isMultiSelect() ? TYPE_MULTI_VALUED : TYPE_SCALAR );
}
- HTMLTextAreaElement[] textAreas = getTextAreas();
- for (int i = 0; i < textAreas.length; i++) {
- types.put( textAreas[i].getName(), TYPE_TEXT );
- }
_dataTypes = types;
}
return _dataTypes;
@@ -693,26 +662,14 @@
/**
* Returns an array of select control descriptors for this form.
**/
- private HTMLTextAreaElement[] getTextAreas() {
- if (_textAreas == null) {
- NodeList nl = ((Element) getNode()).getElementsByTagName( "textarea" );
- HTMLTextAreaElement[] result = new HTMLTextAreaElement[ nl.getLength() ];
- for (int i = 0; i < result.length; i++) {
- result[i] = new HTMLTextAreaElement( nl.item(i) );
- }
- _textAreas = result;
- }
- return _textAreas;
- }
-
/**
* Returns an array of form parameter attributes for this form.
**/
- private NamedNodeMap[] getParameters() {
+ private FormControl[] getParameters() {
if (_parameters == null) {
Vector list = new Vector();
if (getNode().hasChildNodes()) addFormParametersToList( getNode().getChildNodes(), list );
- _parameters = new NamedNodeMap[ list.size() ];
+ _parameters = new FormControl[ list.size() ];
list.copyInto( _parameters );
}
@@ -728,35 +685,15 @@
private void addFormParametersToList( Node child, Vector list ) {
- if (isFormParameter( child )) {
- list.addElement( child.getAttributes() );
+ final FormControl formParameter = FormControl.newFormParameter( child );
+ if (formParameter != null) {
+ list.addElement( formParameter );
} else if (child.hasChildNodes()) {
addFormParametersToList( child.getChildNodes(), list );
}
}
- private boolean isFormParameter( Node node ) {
- if (node.getNodeType() != Node.ELEMENT_NODE) {
- return false;
- } else if (!node.getNodeName().equals( "input" )) {
- return false;
- } else {
- NamedNodeMap nnm = node.getAttributes();
- Node n = nnm.getNamedItem( "type" );
- if (n == null) {
- return true;
- } else if (n.getNodeValue().equalsIgnoreCase( "submit" )) {
- return false;
- } else if (n.getNodeValue().equalsIgnoreCase( "reset" )) {
- return false;
- } else {
- return true;
- }
- }
- }
-
-
class HTMLSelectElement {
HTMLSelectElement( Node node ) {
if (!node.getNodeName().equalsIgnoreCase( "select" )) {
@@ -838,38 +775,88 @@
}
- private String getTextValue( Node optionNode ) {
- NamedNodeMap nnm = optionNode.getAttributes();
- return getValue( optionNode.getFirstChild() );
- }
}
+}
+
- class HTMLTextAreaElement {
- HTMLTextAreaElement( Node node ) {
- if (!node.getNodeName().equalsIgnoreCase( "textarea" )) {
- throw new RuntimeException( "Not a textarea element" );
+
+class FormControl {
+ protected Node _node;
+
+
+ FormControl( Node node ) {
+ _node = node;
+ }
+
+
+ Node getNamedItem( String attributeName ) {
+ return _node.getAttributes().getNamedItem( attributeName );
+ }
+
+
+ /**
+ * Returns the name of this control. If no name is specified, defaults to the empty string.
+ **/
+ String getName() {
+ return NodeUtils.getNodeAttribute( _node, "name" );
+ }
+
+
+ /**
+ * Returns the value of this control. If no value is specified, defaults to the empty string.
+ **/
+ String getValue() {
+ return NodeUtils.getNodeAttribute( _node, "value" );
+ }
+
+
+ /**
+ * Returns true if this control is read-only.
+ **/
+ boolean isReadOnly() {
+ return _node.getAttributes().getNamedItem( "readonly" ) != null;
+ }
+
+
+ static FormControl newFormParameter( Node node ) {
+ if (node.getNodeType() != Node.ELEMENT_NODE) {
+ return null;
+ } else if (node.getNodeName().equals( "textarea" )) {
+ return new TextAreaFormControl( node );
+ } else if (!node.getNodeName().equals( "input" )) {
+ return null;
+ } else {
+ NamedNodeMap nnm = node.getAttributes();
+ Node n = nnm.getNamedItem( "type" );
+ if (n == null) {
+ return new FormControl( node );
+ } else if (n.getNodeValue().equalsIgnoreCase( "submit" )) {
+ return null;
+ } else if (n.getNodeValue().equalsIgnoreCase( "reset" )) {
+ return null;
+ } else {
+ return new FormControl( node );
}
- _node = node;
- }
-
-
- private Node _node;
-
-
- String getName() {
- NamedNodeMap nnm = _node.getAttributes();
- return WebForm.this.getValue( nnm.getNamedItem( "name" ) );
}
+ }
+}
- String getValue() {
- return NodeUtils.asText(_node.getChildNodes() );
- }
- boolean isReadOnly() {
- return _node.getAttributes().getNamedItem( "readonly" ) != null;
+class TextAreaFormControl extends FormControl {
+
+ public TextAreaFormControl( Node node ) {
+ super( node );
+
+ if (!node.getNodeName().equalsIgnoreCase( "textarea" )) {
+ throw new RuntimeException( "Not a textarea element" );
}
+ }
+
+
+ String getValue() {
+ return NodeUtils.asText( _node.getChildNodes() );
}
}
|
|
From: Russell G. <rus...@us...> - 2001-12-11 21:41:52
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv23428/test/com/meterware/httpunit
Modified Files:
WebFormTest.java
Log Message:
Added test for textarea name prefix lookup
Index: WebFormTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFormTest.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- WebFormTest.java 2001/11/05 18:54:51 1.14
+++ WebFormTest.java 2001/12/11 21:41:38 1.15
@@ -109,16 +109,24 @@
public void testFormParameters() throws Exception {
- WebForm form = _wc.getResponse( getHostPath() + "/OneForm.html" ).getForms()[0];
+ defineWebPage( "AForm", "<h2>Login required</h2>" +
+ "<form method=POST action = \"/servlet/Login\"><B>" +
+ "Enter the name 'master': <textarea Name=name>Something</textarea></B>" +
+ "<input type=\"checkbox\" name=first>Disabled" +
+ "<input type=\"checkbox\" name=second checked>Enabled" +
+ "<br><Input type=submit value = \"Log in\">" +
+ "</form>" );
+
+ WebForm form = _wc.getResponse( getHostPath() + "/AForm.html" ).getForms()[0];
String[] parameters = form.getParameterNames();
assertNotNull( parameters );
- assertEquals( 3, parameters.length );
- assertEquals( "name", parameters[0] );
+ assertMatchingSet( "form parameter names", new String[] { "first", "name", "second" }, parameters );
assertEquals( "First checkbox", "", form.getParameterValue( "first" ) );
assertEquals( "Second checkbox", "on", form.getParameterValue( "second" ) );
assertTrue( "Did not find parameter 'first'", form.hasParameterNamed( "first" ) );
assertTrue( "Did not find parameter with prefix 'sec'", form.hasParameterStartingWithPrefix( "sec" ) );
+ assertTrue( "Did not find parameter with prefix 'nam'", form.hasParameterStartingWithPrefix( "nam" ) );
}
|
|
From: Russell G. <rus...@us...> - 2001-12-11 21:39:51
|
Update of /cvsroot/httpunit/httpunit/doc/tutorial/src/tutorial
In directory usw-pr-cvs1:/tmp/cvs-serv22844/doc/tutorial/src/tutorial
Modified Files:
PoolEditorTest.java
Log Message:
Make answers match tutorial
Index: PoolEditorTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/doc/tutorial/src/tutorial/PoolEditorTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PoolEditorTest.java 2001/11/27 16:40:47 1.2
+++ PoolEditorTest.java 2001/12/11 21:39:48 1.3
@@ -48,6 +48,7 @@
ServletRunner sr = new ServletRunner( "web.xml" );
ServletUnitClient client = sr.newClient();
+ client.setAuthorization( "aUser", "pool-admin" );
WebResponse response = client.getResponse( "http://localhost/PoolEditor" );
WebForm form = response.getFormWithID( "pool" );
assertNotNull( "No form found with ID 'pool'", form );
@@ -60,6 +61,7 @@
ServletRunner sr = new ServletRunner( "web.xml" );
ServletUnitClient client = sr.newClient();
+ client.setAuthorization( "aUser", "pool-admin" );
WebResponse response = client.getResponse( "http://localhost/PoolEditor" );
WebForm form = response.getFormWithID( "pool" );
assertNotNull( "No form found with ID 'pool'", form );
@@ -77,6 +79,7 @@
public void testSubmitButtons() throws Exception {
ServletRunner sr = new ServletRunner( "web.xml" );
ServletUnitClient client = sr.newClient();
+ client.setAuthorization( "aUser", "pool-admin" );
WebResponse response = client.getResponse( "http://localhost/PoolEditor" );
WebForm form = response.getFormWithID( "pool" );
@@ -97,6 +100,7 @@
ServletRunner sr = new ServletRunner( "web.xml" );
ServletUnitClient client = sr.newClient();
+ client.setAuthorization( "aUser", "pool-admin" );
WebResponse response = client.getResponse( "http://localhost/PoolEditor" );
WebForm form = response.getFormWithID( "pool" );
@@ -116,6 +120,7 @@
public void testPoolEntry() throws Exception {
ServletRunner sr = new ServletRunner( "web.xml" );
ServletUnitClient client = sr.newClient();
+ client.setAuthorization( "aUser", "pool-admin" );
WebResponse response = client.getResponse( "http://localhost/PoolEditor" );
WebForm form = response.getFormWithID( "pool" );
@@ -140,6 +145,7 @@
public void testPoolValidation() throws Exception {
ServletRunner sr = new ServletRunner( "web.xml" );
ServletUnitClient client = sr.newClient();
+ client.setAuthorization( "aUser", "pool-admin" );
WebResponse response = client.getResponse( "http://localhost/PoolEditor" );
WebForm form = response.getFormWithID( "pool" );
WebRequest request = form.getRequest( "save", "Open Pool" );
@@ -162,6 +168,7 @@
public void testPoolOpenErrorDetection() throws Exception {
ServletRunner sr = new ServletRunner( "web.xml" );
ServletUnitClient client = sr.newClient();
+ client.setAuthorization( "aUser", "pool-admin" );
WebResponse response = client.getResponse( "http://localhost/PoolEditor" );
WebForm form = response.getFormWithID( "pool" );
WebRequest request = form.getRequest( "save", "Open Pool" );
@@ -184,6 +191,7 @@
public void testGoodPoolOpen() throws Exception {
ServletRunner sr = new ServletRunner( "web.xml" );
ServletUnitClient client = sr.newClient();
+ client.setAuthorization( "aUser", "pool-admin" );
WebResponse response = client.getResponse( "http://localhost/PoolEditor" );
WebForm form = response.getFormWithID( "pool" );
WebRequest request = form.getRequest( "save", "Open Pool" );
|