[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit FormControl.java,1.41,1.42 FormParameter.
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2003-06-24 22:40:39
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv25478/src/com/meterware/httpunit
Modified Files:
FormControl.java FormParameter.java WebForm.java
Log Message:
Added support for set/toggle checkbox
Index: FormControl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- FormControl.java 23 May 2003 21:55:11 -0000 1.41
+++ FormControl.java 24 Jun 2003 22:40:36 -0000 1.42
@@ -220,6 +220,22 @@
/**
+ * Toggles the value of this control.
+ */
+ public void toggle() {
+ throw new FormParameter.IllegalCheckboxParameterException( getName(), "toggleCheckbox" );
+ }
+
+
+ /**
+ * Sets the state of this boolean control.
+ */
+ public void setState( boolean state ) {
+ throw new FormParameter.IllegalCheckboxParameterException( getName(), "setCheckbox" );
+ }
+
+
+ /**
* Performs the 'onChange' event defined for this control.
*/
protected void sendOnChangeEvent() {
@@ -631,6 +647,20 @@
}
+ /**
+ * Toggles the value of this control.
+ */
+ public void toggle() {
+ setChecked( !isChecked() );
+ }
+
+
+ /**
+ * Sets the state of this boolean control.
+ */
+ public void setState( boolean state ) {
+ setChecked( state );
+ }
}
Index: FormParameter.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormParameter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FormParameter.java 6 Feb 2003 02:55:58 -0000 1.5
+++ FormParameter.java 24 Jun 2003 22:40:36 -0000 1.6
@@ -93,6 +93,20 @@
}
+ public void toggleCheckbox() {
+ FormControl[] controls = getControls();
+ if (controls.length != 1) throw new IllegalCheckboxParameterException( _name, "toggleCheckbox" );
+ controls[0].toggle();
+ }
+
+
+ public void setValue( boolean state ) {
+ FormControl[] controls = getControls();
+ if (controls.length != 1) throw new IllegalCheckboxParameterException( _name, "toggleCheckbox" );
+ controls[0].setState( state );
+ }
+
+
void setFiles( UploadFileSpec[] fileArray ) {
ArrayList list = new ArrayList( fileArray.length );
list.addAll( Arrays.asList( fileArray ) );
@@ -254,6 +268,36 @@
private int _numExpected;
private int _numSupplied;
}
+
+
+//============================= exception class IllegalCheckboxParameterException ======================================
+
+
+ /**
+ * This exception is thrown on an attempt to set a parameter to a value not permitted to it by the form.
+ **/
+ static class IllegalCheckboxParameterException extends IllegalRequestParameterException {
+
+
+ IllegalCheckboxParameterException( String parameterName, String methodName ) {
+ _parameterName = parameterName;
+ _methodName = methodName;
+ }
+
+
+ public String getMessage() {
+ StringBuffer sb = new StringBuffer(HttpUnitUtils.DEFAULT_TEXT_BUFFER_SIZE);
+ sb.append( "Attempted to invoke method '" ).append( _methodName );
+ sb.append( "' for parameter '" ).append( _parameterName ).append( "', which is not a unique checkbox control." );
+ return sb.toString();
+ }
+
+
+ private String _parameterName;
+ private String _methodName;
+ }
+
+
}
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -r1.85 -r1.86
--- WebForm.java 23 Jun 2003 23:54:03 -0000 1.85
+++ WebForm.java 24 Jun 2003 22:40:36 -0000 1.86
@@ -534,6 +534,33 @@
}
+ /**
+ * Toggles the value of the specified checkbox parameter.
+ * @param name the name of the checkbox parameter
+ * @throws IllegalArgumentException if the specified parameter is not a checkbox or there is more than one
+ * control with that name.
+ */
+ public void toggleCheckbox( String name ) {
+ FormParameter parameter = getParameter( name );
+ if (parameter == null) throw new NoSuchParameterException( name );
+ parameter.toggleCheckbox();
+ }
+
+
+ /**
+ * Sets the value of the specified checkbox parameter.
+ * @param name the name of the checkbox parameter
+ * @param state the new state of the checkbox
+ * @throws IllegalArgumentException if the specified parameter is not a checkbox or there is more than one
+ * control with that name.
+ */
+ public void setCheckbox( String name, boolean state ) {
+ FormParameter parameter = getParameter( name );
+ if (parameter == null) throw new NoSuchParameterException( name );
+ parameter.setValue( state );
+ }
+
+
public class Scriptable extends HTMLElementScriptable implements NamedDelegate {
public String getAction() { return WebForm.this.getAction(); }
public void setAction( String newAction ) { setDestination( newAction ); _presetParameters = null; }
|