You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2010/05/01 18:34:16 UTC
svn commit: r940075 - in /click/trunk/click/framework/test/org/apache/click:
PageTest.java control/AbstractContainerTest.java control/FieldSetTest.java
control/FormTest.java control/PanelTest.java
Author: sabob
Date: Sat May 1 16:34:15 2010
New Revision: 940075
URL: http://svn.apache.org/viewvc?rev=940075&view=rev
Log:
updated tests. CLK-666
Modified:
click/trunk/click/framework/test/org/apache/click/PageTest.java
click/trunk/click/framework/test/org/apache/click/control/AbstractContainerTest.java
click/trunk/click/framework/test/org/apache/click/control/FieldSetTest.java
click/trunk/click/framework/test/org/apache/click/control/FormTest.java
click/trunk/click/framework/test/org/apache/click/control/PanelTest.java
Modified: click/trunk/click/framework/test/org/apache/click/PageTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/PageTest.java?rev=940075&r1=940074&r2=940075&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/PageTest.java (original)
+++ click/trunk/click/framework/test/org/apache/click/PageTest.java Sat May 1 16:34:15 2010
@@ -19,6 +19,7 @@
package org.apache.click;
import junit.framework.TestCase;
+import org.apache.click.control.Form;
import org.apache.click.pages.JspRedirectPage;
import org.apache.click.pages.RedirectToHtm;
import org.apache.click.pages.RedirectToJsp;
@@ -166,4 +167,36 @@ public class PageTest extends TestCase {
version = page.getMessage("version", args);
assertEquals(expected, version);
}
+
+ /**
+ * Check that adding controls replace existing controls with the same name.
+ *
+ * CLK-666
+ */
+ public void testReplace() {
+ MockContext.initContext();
+
+ Page page = new Page();
+
+ // Add two controls named child1 and child2
+ Form child1 = new Form("child1");
+ Form child2 = new Form("child2");
+ page.addControl(child1);
+ page.addControl(child2);
+ assertEquals(2, page.getModel().size());
+ assertEquals(2, page.getControls().size());
+ assertSame(child1, page.getControls().get(0));
+ assertSame(child2, page.getControls().get(1));
+
+ // Add another two controls named child1 and child2 and test that these
+ // controls replaces the previous controls
+ child1 = new Form("child1");
+ child2 = new Form("child2");
+ page.addControl(child1);
+ page.addControl(child2);
+ assertEquals(2, page.getModel().size());
+ assertEquals(2, page.getControls().size());
+ assertSame(child1, page.getControls().get(0));
+ assertSame(child2, page.getControls().get(1));
+ }
}
Modified: click/trunk/click/framework/test/org/apache/click/control/AbstractContainerTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/control/AbstractContainerTest.java?rev=940075&r1=940074&r2=940075&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/control/AbstractContainerTest.java (original)
+++ click/trunk/click/framework/test/org/apache/click/control/AbstractContainerTest.java Sat May 1 16:34:15 2010
@@ -74,7 +74,8 @@ public class AbstractContainerTest exten
fail("Field has name defined and is valid");
}
- // Check that adding TextField without name fails
+ // Check that adding TextField without name fails because Field#setParent
+ // ensures that Field name is set
try {
container.add(new TextField());
fail("Field must define a name");
Modified: click/trunk/click/framework/test/org/apache/click/control/FieldSetTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/control/FieldSetTest.java?rev=940075&r1=940074&r2=940075&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/control/FieldSetTest.java (original)
+++ click/trunk/click/framework/test/org/apache/click/control/FieldSetTest.java Sat May 1 16:34:15 2010
@@ -28,30 +28,31 @@ import org.apache.click.MockContext;
public class FieldSetTest extends TestCase {
/** FieldSet which index position to test. */
- private FieldSet fieldSet;
+ private FieldSet testFieldSet;
/** TextField which position is tracked in the FieldSet. */
private TextField trackField;
/**
- * Setup the fieldSet and trackField instances for testing the Control index
+ * Setup the testFieldSet and trackField instances for testing the Control index
* positions after being added or inserted.
*/
+ @Override
public void setUp() {
- // Create form and fieldSet.
+ // Create form and testFieldSet.
Form form = new Form("form");
- fieldSet = new FieldSet("fieldSet");
- form.add(fieldSet);
+ testFieldSet = new FieldSet("fieldSet");
+ form.add(testFieldSet);
- // Create the trackField at index 0 and check the fieldSet index
+ // Create the trackField at index 0 and check the testFieldSet index
// position for the lists FieldSet#controls and FieldSet#fieldList
trackField = new TextField("track");
- fieldSet.add(trackField);
+ testFieldSet.add(trackField);
// trackField index: #controls=0
- assertTrue(fieldSet.getControls().indexOf(trackField) == 0);
+ assertTrue(testFieldSet.getControls().indexOf(trackField) == 0);
// trackField index: #fieldList=0
- assertTrue(fieldSet.getFieldList().indexOf(trackField) == 0);
+ assertTrue(testFieldSet.getFieldList().indexOf(trackField) == 0);
}
/**
@@ -62,17 +63,17 @@ public class FieldSetTest extends TestCa
*/
public void testInsertOrderAfterAddingField() {
TextField nameField = new TextField("score");
- fieldSet.add(nameField);
+ testFieldSet.add(nameField);
// nameField index: #controls=1
- assertTrue(fieldSet.getControls().indexOf(nameField) == 1);
+ assertTrue(testFieldSet.getControls().indexOf(nameField) == 1);
// nameField index: #fieldList=1
- assertTrue(fieldSet.getFieldList().indexOf(nameField) == 1);
+ assertTrue(testFieldSet.getFieldList().indexOf(nameField) == 1);
// trackField index: #controls=0
- assertTrue(fieldSet.getControls().indexOf(trackField) == 0);
+ assertTrue(testFieldSet.getControls().indexOf(trackField) == 0);
// trackField index: #fieldList=0
- assertTrue(fieldSet.getFieldList().indexOf(trackField) == 0);
+ assertTrue(testFieldSet.getFieldList().indexOf(trackField) == 0);
}
/**
@@ -83,17 +84,17 @@ public class FieldSetTest extends TestCa
*/
public void testInsertOrderAfterInsertingField() {
TextField nameField = new TextField("name");
- fieldSet.insert(nameField, 0);
+ testFieldSet.insert(nameField, 0);
// nameindex: #controls=0
- assertTrue(fieldSet.getControls().indexOf(nameField) == 0);
+ assertTrue(testFieldSet.getControls().indexOf(nameField) == 0);
// nameindex: #fieldList=1
- assertTrue(fieldSet.getFieldList().indexOf(nameField) == 1);
+ assertTrue(testFieldSet.getFieldList().indexOf(nameField) == 1);
// trackField index: #controls=1
- assertTrue(fieldSet.getControls().indexOf(trackField) == 1);
+ assertTrue(testFieldSet.getControls().indexOf(trackField) == 1);
// trackField index: #fieldList=0
- assertTrue(fieldSet.getFieldList().indexOf(trackField) == 0);
+ assertTrue(testFieldSet.getFieldList().indexOf(trackField) == 0);
}
/**
@@ -106,17 +107,17 @@ public class FieldSetTest extends TestCa
Table table = new Table("table");
// Insert table at index 0
- fieldSet.insert(table, 0);
+ testFieldSet.insert(table, 0);
// table: #controls=0
- assertTrue(fieldSet.getControls().indexOf(table) == 0);
+ assertTrue(testFieldSet.getControls().indexOf(table) == 0);
// table: #fieldList=-1
- assertTrue(fieldSet.getFieldList().indexOf(table) == -1);
+ assertTrue(testFieldSet.getFieldList().indexOf(table) == -1);
// trackField index: #controls=1
- assertTrue(fieldSet.getControls().indexOf(trackField) == 1);
+ assertTrue(testFieldSet.getControls().indexOf(trackField) == 1);
// trackField index: #fieldList=0
- assertTrue(fieldSet.getFieldList().indexOf(trackField) == 0);
+ assertTrue(testFieldSet.getFieldList().indexOf(trackField) == 0);
}
/**
@@ -127,15 +128,15 @@ public class FieldSetTest extends TestCa
*/
public void testInsertOrderAfterInsertingButton() {
// Check that the fieldList contains only one item -> trackField
- assertTrue(fieldSet.getFieldList().size() == 1);
+ assertTrue(testFieldSet.getFieldList().size() == 1);
Button button = new Button("button1");
- fieldSet.insert(button, 0);
+ testFieldSet.insert(button, 0);
// button: #controls=0
- assertTrue(fieldSet.getControls().indexOf(button) == 0);
+ assertTrue(testFieldSet.getControls().indexOf(button) == 0);
// Check that fieldList still only contains one item
- assertTrue(fieldSet.getFieldList().size() == 1);
+ assertTrue(testFieldSet.getFieldList().size() == 1);
}
/**
@@ -149,17 +150,17 @@ public class FieldSetTest extends TestCa
HiddenField hidden = new HiddenField("hidden", Boolean.class);
// Insert hidden at index 0
- fieldSet.insert(hidden, 0);
+ testFieldSet.insert(hidden, 0);
// button: #controls=0
- assertTrue(fieldSet.getControls().indexOf(hidden) == 0);
+ assertTrue(testFieldSet.getControls().indexOf(hidden) == 0);
// hidden index: #fieldList=1
- assertTrue(fieldSet.getFieldList().indexOf(hidden) == 1);
+ assertTrue(testFieldSet.getFieldList().indexOf(hidden) == 1);
// trackField index: #controls=1
- assertTrue(fieldSet.getControls().indexOf(trackField) == 1);
+ assertTrue(testFieldSet.getControls().indexOf(trackField) == 1);
// trackField index: #fieldList=0
- assertTrue(fieldSet.getFieldList().indexOf(trackField) == 0);
+ assertTrue(testFieldSet.getFieldList().indexOf(trackField) == 0);
}
/**
@@ -168,35 +169,35 @@ public class FieldSetTest extends TestCa
public void testRemove() {
TextField field = new TextField("field");
- fieldSet.insert(field, 0);
+ testFieldSet.insert(field, 0);
// field index: #controls=0
- assertTrue(fieldSet.getControls().indexOf(field) == 0);
+ assertTrue(testFieldSet.getControls().indexOf(field) == 0);
// field index: #fieldList=1
- assertTrue(fieldSet.getFieldList().indexOf(field) == 1);
+ assertTrue(testFieldSet.getFieldList().indexOf(field) == 1);
// trackField index: #controls=1
- assertTrue(fieldSet.getControls().indexOf(trackField) == 1);
+ assertTrue(testFieldSet.getControls().indexOf(trackField) == 1);
// trackField index: #fieldList=0
- assertTrue(fieldSet.getFieldList().indexOf(trackField) == 0);
+ assertTrue(testFieldSet.getFieldList().indexOf(trackField) == 0);
int expectedSize = 2;
// Check the list sizes to be 2
- assertTrue(fieldSet.getControls().size() == expectedSize);
- assertTrue(fieldSet.getFieldList().size() == expectedSize);
+ assertTrue(testFieldSet.getControls().size() == expectedSize);
+ assertTrue(testFieldSet.getFieldList().size() == expectedSize);
// Removing field should shift up trackField index
- fieldSet.remove(field);
+ testFieldSet.remove(field);
expectedSize = 1;
// Check the list sizes to be 1
- assertTrue(fieldSet.getControls().size() == expectedSize);
- assertTrue(fieldSet.getFieldList().size() == expectedSize);
+ assertTrue(testFieldSet.getControls().size() == expectedSize);
+ assertTrue(testFieldSet.getFieldList().size() == expectedSize);
// trackField index: #controls=0
- assertTrue(fieldSet.getControls().indexOf(trackField) == 0);
+ assertTrue(testFieldSet.getControls().indexOf(trackField) == 0);
// trackField index: #fieldList=0
- assertTrue(fieldSet.getFieldList().indexOf(trackField) == 0);
+ assertTrue(testFieldSet.getFieldList().indexOf(trackField) == 0);
}
/**
@@ -207,21 +208,21 @@ public class FieldSetTest extends TestCa
TextField field = new TextField("field");
// Check that fieldWidth is empty
- assertTrue(fieldSet.getFieldWidths().isEmpty());
+ assertTrue(testFieldSet.getFieldWidths().isEmpty());
int colspan = 4;
- fieldSet.add(field, colspan);
+ testFieldSet.add(field, colspan);
// Check that fieldWidth has entry for field
- assertTrue(fieldSet.getFieldWidths().size() == 1);
+ assertTrue(testFieldSet.getFieldWidths().size() == 1);
- Integer width = (Integer) fieldSet.getFieldWidths().get(field.getName());
+ Integer width = (Integer) testFieldSet.getFieldWidths().get(field.getName());
assertEquals(4, width.intValue());
- fieldSet.remove(field);
+ testFieldSet.remove(field);
// Check that fieldWidth is empty
- assertTrue(fieldSet.getFieldWidths().isEmpty());
+ assertTrue(testFieldSet.getFieldWidths().isEmpty());
}
/**
@@ -232,21 +233,21 @@ public class FieldSetTest extends TestCa
Table table = new Table("table");
// Check that fieldWidth is empty
- assertTrue(fieldSet.getFieldWidths().isEmpty());
+ assertTrue(testFieldSet.getFieldWidths().isEmpty());
int colspan = 4;
- fieldSet.add(table, colspan);
+ testFieldSet.add(table, colspan);
// Check that fieldWidth has entry for table
- assertTrue(fieldSet.getFieldWidths().size() == 1);
+ assertTrue(testFieldSet.getFieldWidths().size() == 1);
- Integer width = (Integer) fieldSet.getFieldWidths().get(table.getName());
+ Integer width = (Integer) testFieldSet.getFieldWidths().get(table.getName());
assertEquals(4, width.intValue());
- fieldSet.remove(table);
+ testFieldSet.remove(table);
// Check that fieldWidth is empty
- assertTrue(fieldSet.getFieldWidths().isEmpty());
+ assertTrue(testFieldSet.getFieldWidths().isEmpty());
}
/**
@@ -310,10 +311,10 @@ public class FieldSetTest extends TestCa
assertFalse(fieldSet.getFieldList().contains(button));
// Check that list contains other FieldSet
- //assertTrue(fieldSet.getFieldList().contains(anotherFieldSet));
+ //assertTrue(testFieldSet.getFieldList().contains(anotherFieldSet));
// Check that list does *not* contains the other FieldSet's Field
- //assertFalse(fieldSet.getFieldList().contains(anotherFieldSetField));
+ //assertFalse(testFieldSet.getFieldList().contains(anotherFieldSetField));
// Check that field list is cached
assertSame(fieldSet.getFieldList(), fieldSet.getFieldList());
@@ -326,9 +327,9 @@ public class FieldSetTest extends TestCa
* The main use case for FieldSet.getFields() is that it enables one to use
* Velocity to render Controls and Fields e.g.:
*
- * $form.fieldSet.fields.name <- name this is a TextField
- * $form.fieldSet.fields.div <- div is a AbstractContainer
- * $form.fieldSet.fields.button <- button is a Submit
+ * $form.testFieldSet.fields.name <- name this is a TextField
+ * $form.testFieldSet.fields.div <- div is a AbstractContainer
+ * $form.testFieldSet.fields.button <- button is a Submit
*
* Also check that FieldSet.getFields() returns a cached Map so that access to
* FieldSet.getFields() is fast.
@@ -384,21 +385,21 @@ public class FieldSetTest extends TestCa
* CLK-497
*/
public void testFieldParent() {
- // Initially fieldSet contains 1 hidden field
- assertTrue(fieldSet.getControls().size() == 1);
+ // Initially testFieldSet contains 1 hidden field
+ assertTrue(testFieldSet.getControls().size() == 1);
TextField nameField = new TextField("score");
- fieldSet.add(nameField);
+ testFieldSet.add(nameField);
- assertTrue(fieldSet.getControls().size() == 2);
+ assertTrue(testFieldSet.getControls().size() == 2);
// Test that Field parent is a FieldSet
assertEquals(FieldSet.class, nameField.getParent().getClass());
- assertTrue(fieldSet.remove((Control) nameField));
+ assertTrue(testFieldSet.remove((Control) nameField));
assertTrue(nameField.getParent() == null);
- assertTrue(fieldSet.getControls().size() == 1);
+ assertTrue(testFieldSet.getControls().size() == 1);
}
/**
@@ -407,13 +408,13 @@ public class FieldSetTest extends TestCa
*/
public void testIsDisabled() {
// Fieldset is not disabled.
- assertFalse(this.fieldSet.isDisabled());
+ assertFalse(this.testFieldSet.isDisabled());
// Textfield inside is not disabled.
assertFalse(this.trackField.isDisabled());
// Change fieldset state.
- this.fieldSet.setDisabled(true);
+ this.testFieldSet.setDisabled(true);
// Textfield is now disabled too.
assertTrue(this.trackField.isDisabled());
@@ -425,19 +426,55 @@ public class FieldSetTest extends TestCa
*/
public void testIsReadonly() {
// Fieldset is not disabled.
- assertFalse(this.fieldSet.isReadonly());
+ assertFalse(this.testFieldSet.isReadonly());
// Textfield inside is not disabled.
assertFalse(this.trackField.isReadonly());
// Change fieldset state.
- this.fieldSet.setReadonly(true);
+ this.testFieldSet.setReadonly(true);
// Textfield is now disabled too.
assertTrue(this.trackField.isReadonly());
}
/**
+ * Check that adding controls replace existing controls with the same name.
+ *
+ * CLK-666
+ */
+ public void testReplace() {
+ FieldSet fieldset = new FieldSet("fieldset");
+
+ // Add two fields named child1 and child2
+ Field child1 = new TextField("child1");
+ Field child2 = new TextField("child2");
+ fieldset.add(child1);
+ fieldset.add(child2);
+ assertEquals(2, fieldset.getControlMap().size());
+ assertEquals(2, fieldset.getControls().size());
+ assertEquals(2, fieldset.getFields().size());
+ assertSame(child1, fieldset.getControls().get(0));
+ assertSame(child2, fieldset.getControls().get(1));
+ assertSame(child1, fieldset.getFieldList().get(0));
+ assertSame(child2, fieldset.getFieldList().get(1));
+
+ // Add another two fields named child1 and child2 and test that these
+ // panels replaces the previous fields
+ child1 = new TextField("child1");
+ child2 = new TextField("child2");
+ fieldset.add(child1);
+ fieldset.add(child2);
+ assertEquals(2, fieldset.getControlMap().size());
+ assertEquals(2, fieldset.getControls().size());
+ assertEquals(2, fieldset.getFields().size());
+ assertSame(child1, fieldset.getControls().get(0));
+ assertSame(child2, fieldset.getControls().get(1));
+ assertSame(child1, fieldset.getFieldList().get(0));
+ assertSame(child2, fieldset.getFieldList().get(1));
+ }
+
+ /**
* A custom Div container.
*/
static class Div extends AbstractContainer {
@@ -456,6 +493,7 @@ public class FieldSetTest extends TestCa
*
* @return the div tag
*/
+ @Override
public String getTag() {
return "div";
}
Modified: click/trunk/click/framework/test/org/apache/click/control/FormTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/control/FormTest.java?rev=940075&r1=940074&r2=940075&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/control/FormTest.java (original)
+++ click/trunk/click/framework/test/org/apache/click/control/FormTest.java Sat May 1 16:34:15 2010
@@ -162,7 +162,7 @@ public class FormTest extends TestCase {
}
/** Form which index position to test. */
- private Form form;
+ private Form testForm;
/** Field which position is tracked in the Form. */
private HiddenField trackField;
@@ -171,9 +171,10 @@ public class FormTest extends TestCase {
* Setup the form and trackField instances for testing the Control index
* positions after being added or inserted.
*/
+ @Override
public void setUp() {
// Create form.
- form = new Form("form");
+ testForm = new Form("form");
// Form automatically creates and adds two HiddenFields. One for storing
// the form anem between requests and one for tracking if form validation
@@ -181,12 +182,12 @@ public class FormTest extends TestCase {
// of each test.
// The tests below checks the trackField index position in the Form
// for the lists Form#controls, Form#fieldList and Form#buttonList
- trackField = (HiddenField) form.getField(Form.FORM_NAME);
+ trackField = (HiddenField) testForm.getField(Form.FORM_NAME);
// trackField index: #controls=0
- assertTrue(form.getControls().indexOf(trackField) == 0);
+ assertTrue(testForm.getControls().indexOf(trackField) == 0);
// trackField index: #fieldList=0
- assertTrue(form.getFieldList().indexOf(trackField) == 0);
+ assertTrue(testForm.getFieldList().indexOf(trackField) == 0);
}
/**
@@ -199,17 +200,17 @@ public class FormTest extends TestCase {
TextField nameField = new TextField("name");
// Add new field
- form.add(nameField);
+ testForm.add(nameField);
// nameField index: #controls=0
- assertTrue(form.getControls().indexOf(nameField) == 0);
+ assertTrue(testForm.getControls().indexOf(nameField) == 0);
// nameField index: #fieldList=0
- assertTrue(form.getFieldList().indexOf(nameField) == 0);
+ assertTrue(testForm.getFieldList().indexOf(nameField) == 0);
// trackField index: #controls=1
- assertTrue(form.getControls().indexOf(trackField) == 1);
+ assertTrue(testForm.getControls().indexOf(trackField) == 1);
// trackField index: #fieldList=1
- assertTrue(form.getFieldList().indexOf(trackField) == 1);
+ assertTrue(testForm.getFieldList().indexOf(trackField) == 1);
}
/**
@@ -222,17 +223,17 @@ public class FormTest extends TestCase {
TextField nameField = new TextField("name");
// Insert field at index 0
- form.insert(nameField, 0);
+ testForm.insert(nameField, 0);
// nameField index: #controls=0
- assertTrue(form.getControls().indexOf(nameField) == 0);
+ assertTrue(testForm.getControls().indexOf(nameField) == 0);
// nameField index: #fieldList=0
- assertTrue(form.getFieldList().indexOf(nameField) == 0);
+ assertTrue(testForm.getFieldList().indexOf(nameField) == 0);
// trackField index: #controls=1
- assertTrue(form.getControls().indexOf(trackField) == 1);
+ assertTrue(testForm.getControls().indexOf(trackField) == 1);
// trackField index: #fieldList=1
- assertTrue(form.getFieldList().indexOf(trackField) == 1);
+ assertTrue(testForm.getFieldList().indexOf(trackField) == 1);
}
/**
@@ -245,17 +246,17 @@ public class FormTest extends TestCase {
Table table = new Table("table");
// Insert table at index 0
- form.insert(table, 0);
+ testForm.insert(table, 0);
// table index: #controls=0
- assertTrue(form.getControls().indexOf(table) == 0);
+ assertTrue(testForm.getControls().indexOf(table) == 0);
// table index: #fieldList=-1
- assertTrue(form.getFieldList().indexOf(table) == -1);
+ assertTrue(testForm.getFieldList().indexOf(table) == -1);
// trackField index: #controls=1
- assertTrue(form.getControls().indexOf(trackField) == 1);
+ assertTrue(testForm.getControls().indexOf(trackField) == 1);
// trackField index: #fieldList=0
- assertTrue(form.getFieldList().indexOf(trackField) == 0);
+ assertTrue(testForm.getFieldList().indexOf(trackField) == 0);
}
/**
@@ -267,18 +268,18 @@ public class FormTest extends TestCase {
public void testInsertOrderAfterInsertingButton() {
// Check that the fieldList includes only two hidden fields (FORM_NAME
// and BYPASS_VALIDATION) thus size is 2
- assertTrue(form.getFieldList().size() == 2);
+ assertTrue(testForm.getFieldList().size() == 2);
Button button = new Button("button1");
- form.insert(button, 0);
+ testForm.insert(button, 0);
// button index: #controls=0
- assertTrue(form.getControls().indexOf(button) == 0);
+ assertTrue(testForm.getControls().indexOf(button) == 0);
// button index: #buttonList=0
- assertTrue(form.getButtonList().indexOf(button) == 0);
+ assertTrue(testForm.getButtonList().indexOf(button) == 0);
// Check that button was not added to fieldList accidentally
- assertTrue(form.getFieldList().size() == 2);
+ assertTrue(testForm.getFieldList().size() == 2);
}
/**
@@ -291,17 +292,17 @@ public class FormTest extends TestCase {
HiddenField hidden = new HiddenField("hidden", Boolean.class);
// Insert hidden at index 0
- form.insert(hidden, 0);
+ testForm.insert(hidden, 0);
// hidden index: #controls=0
- assertTrue(form.getControls().indexOf(hidden) == 0);
+ assertTrue(testForm.getControls().indexOf(hidden) == 0);
// hidden index: #fieldList=0
- assertTrue(form.getFieldList().indexOf(hidden) == 0);
+ assertTrue(testForm.getFieldList().indexOf(hidden) == 0);
// trackField index: #controls=1
- assertTrue(form.getControls().indexOf(trackField) == 1);
+ assertTrue(testForm.getControls().indexOf(trackField) == 1);
// trackField index: #fieldList=1
- assertTrue(form.getFieldList().indexOf(trackField) == 1);
+ assertTrue(testForm.getFieldList().indexOf(trackField) == 1);
}
/**
@@ -310,35 +311,35 @@ public class FormTest extends TestCase {
public void testRemove() {
TextField field = new TextField("field");
- form.insert(field, 0);
+ testForm.insert(field, 0);
// field index: #controls=0
- assertTrue(form.getControls().indexOf(field) == 0);
+ assertTrue(testForm.getControls().indexOf(field) == 0);
// field index: #fieldList=0
- assertTrue(form.getFieldList().indexOf(field) == 0);
+ assertTrue(testForm.getFieldList().indexOf(field) == 0);
// trackField index: #controls=1
- assertTrue(form.getControls().indexOf(trackField) == 1);
+ assertTrue(testForm.getControls().indexOf(trackField) == 1);
// trackField index: #fieldList=1
- assertTrue(form.getFieldList().indexOf(trackField) == 1);
+ assertTrue(testForm.getFieldList().indexOf(trackField) == 1);
int expectedSize = 3;
// Check the list sizes to be 3
- assertTrue(form.getControls().size() == expectedSize);
- assertTrue(form.getFieldList().size() == expectedSize);
+ assertTrue(testForm.getControls().size() == expectedSize);
+ assertTrue(testForm.getFieldList().size() == expectedSize);
// Removing field should shift up trackField index
- form.remove(field);
+ testForm.remove(field);
expectedSize = 2;
// Check the list sizes to be 2
- assertTrue(form.getControls().size() == expectedSize);
- assertTrue(form.getFieldList().size() == expectedSize);
+ assertTrue(testForm.getControls().size() == expectedSize);
+ assertTrue(testForm.getFieldList().size() == expectedSize);
// trackField index: #controls=0
- assertTrue(form.getControls().indexOf(trackField) == 0);
+ assertTrue(testForm.getControls().indexOf(trackField) == 0);
// trackField index: #fieldList=0
- assertTrue(form.getFieldList().indexOf(trackField) == 0);
+ assertTrue(testForm.getFieldList().indexOf(trackField) == 0);
}
/**
@@ -349,21 +350,21 @@ public class FormTest extends TestCase {
TextField field = new TextField("field");
// Check that fieldWidth is empty
- assertTrue(form.getFieldWidths().isEmpty());
+ assertTrue(testForm.getFieldWidths().isEmpty());
int colspan = 4;
- form.add(field, colspan);
+ testForm.add(field, colspan);
// Check that fieldWidth has entry for field
- assertTrue(form.getFieldWidths().size() == 1);
+ assertTrue(testForm.getFieldWidths().size() == 1);
- Integer width = (Integer) form.getFieldWidths().get(field.getName());
+ Integer width = (Integer) testForm.getFieldWidths().get(field.getName());
assertEquals(4, width.intValue());
- form.remove(field);
+ testForm.remove(field);
// Check that fieldWidth is empty
- assertTrue(form.getFieldWidths().isEmpty());
+ assertTrue(testForm.getFieldWidths().isEmpty());
}
/**
@@ -374,21 +375,21 @@ public class FormTest extends TestCase {
Table table = new Table("table");
// Check that fieldWidth is empty
- assertTrue(form.getFieldWidths().isEmpty());
+ assertTrue(testForm.getFieldWidths().isEmpty());
int colspan = 4;
- form.add(table, colspan);
+ testForm.add(table, colspan);
// Check that fieldWidth has entry for table
- assertTrue(form.getFieldWidths().size() == 1);
+ assertTrue(testForm.getFieldWidths().size() == 1);
- Integer width = (Integer) form.getFieldWidths().get(table.getName());
+ Integer width = (Integer) testForm.getFieldWidths().get(table.getName());
assertEquals(4, width.intValue());
- form.remove(table);
+ testForm.remove(table);
// Check that fieldWidth is empty
- assertTrue(form.getFieldWidths().isEmpty());
+ assertTrue(testForm.getFieldWidths().isEmpty());
}
/**
@@ -715,13 +716,13 @@ public class FormTest extends TestCase {
*/
public void testIsDisabled() {
// Form is not disabled.
- assertFalse(this.form.isDisabled());
+ assertFalse(this.testForm.isDisabled());
// Hiddenfield inside is not disabled.
assertFalse(this.trackField.isDisabled());
// Change form state.
- this.form.setDisabled(true);
+ this.testForm.setDisabled(true);
// Hiddenfield is now disabled too.
assertTrue(this.trackField.isDisabled());
@@ -733,19 +734,91 @@ public class FormTest extends TestCase {
*/
public void testIsReadonly() {
// Form is not disabled.
- assertFalse(this.form.isReadonly());
+ assertFalse(this.testForm.isReadonly());
// Hiddenfield inside is not disabled.
assertFalse(this.trackField.isReadonly());
// Change form state.
- this.form.setReadonly(true);
+ this.testForm.setReadonly(true);
// Hiddenfield is now disabled too.
assertTrue(this.trackField.isReadonly());
}
/**
+ * Check that adding fields replace existing fields with the same name.
+ *
+ * CLK-666
+ */
+ public void testReplaceFields() {
+ Form form = new Form("form");
+
+ // Add two fields named child1 and child2
+ Field child1 = new TextField("child1");
+ Field child2 = new TextField("child2");
+ form.add(child1);
+ form.add(child2);
+ assertEquals(4, form.getControlMap().size());
+ assertEquals(4, form.getControls().size());
+ assertEquals(4, form.getFields().size());
+ assertSame(child1, form.getControls().get(0));
+ assertSame(child2, form.getControls().get(1));
+ assertSame(child1, form.getFieldList().get(0));
+ assertSame(child2, form.getFieldList().get(1));
+
+ // Add another two fields named child1 and child2 and test that these
+ // panels replaces the previous fields
+ child1 = new TextField("child1");
+ child2 = new TextField("child2");
+ form.add(child1);
+ form.add(child2);
+ assertEquals(4, form.getControlMap().size());
+ assertEquals(4, form.getControls().size());
+ assertEquals(4, form.getFields().size());
+ assertSame(child1, form.getControls().get(0));
+ assertSame(child2, form.getControls().get(1));
+ assertSame(child1, form.getFieldList().get(0));
+ assertSame(child2, form.getFieldList().get(1));
+ }
+
+ /**
+ * Check that adding buttons replace existing buttons with the same name.
+ *
+ * CLK-666
+ */
+ public void testReplaceButtons() {
+ Form form = new Form("form");
+
+ // Add two fields named child1 and child2
+ Button child1 = new Button("child1");
+ Button child2 = new Button("child2");
+ form.add(child1);
+ form.add(child2);
+ assertEquals(4, form.getControlMap().size());
+ assertEquals(4, form.getControls().size());
+ assertEquals(4, form.getFields().size());
+ assertSame(child1, form.getControls().get(0));
+ assertSame(child2, form.getControls().get(1));
+ assertSame(child1, form.getButtonList().get(0));
+ assertSame(child2, form.getButtonList().get(1));
+
+ // Add another two fields named child1 and child2 and test that these
+ // panels replaces the previous fields
+ child1 = new Button("child1");
+ child2 = new Button("child2");
+ form.add(child1);
+ form.add(child2);
+ assertEquals(4, form.getControlMap().size());
+ assertEquals(4, form.getControls().size());
+ assertEquals(4, form.getFields().size());
+ assertSame(child1, form.getControls().get(0));
+ assertSame(child2, form.getControls().get(1));
+ assertSame(child1, form.getButtonList().get(0));
+ assertSame(child2, form.getButtonList().get(1));
+ }
+
+ /**
* Populate the given Form with hidden fields.
*
* @param count the number of hidden fields to add
@@ -778,6 +851,7 @@ public class FormTest extends TestCase {
/**
* @return div tag
*/
+ @Override
public String getTag() {
return "div";
}
Modified: click/trunk/click/framework/test/org/apache/click/control/PanelTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/control/PanelTest.java?rev=940075&r1=940074&r2=940075&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/control/PanelTest.java (original)
+++ click/trunk/click/framework/test/org/apache/click/control/PanelTest.java Sat May 1 16:34:15 2010
@@ -40,4 +40,38 @@ public class PanelTest extends TestCase
panel = new Panel(name);
assertEquals(name, panel.getId());
}
+
+ /**
+ * Check that adding controls replace existing controls with the same name.
+ *
+ * CLK-666
+ */
+ public void testReplace() {
+ Panel panel = new Panel("panel");
+
+ // Add two panels named child1 and child2
+ Panel child1 = new Panel("child1");
+ Panel child2 = new Panel("child2");
+ panel.add(child1);
+ panel.add(child2);
+ assertEquals(2, panel.getControlMap().size());
+ assertEquals(2, panel.getControls().size());
+ assertSame(child1, panel.getControls().get(0));
+ assertSame(child2, panel.getControls().get(1));
+ assertSame(child1, panel.getPanels().get(0));
+ assertSame(child2, panel.getPanels().get(1));
+
+ // Add another two panels named child1 and child2 and test that these
+ // panels replaces the previous panels
+ child1 = new Panel("child1");
+ child2 = new Panel("child2");
+ panel.add(child1);
+ panel.add(child2);
+ assertEquals(2, panel.getControlMap().size());
+ assertEquals(2, panel.getControls().size());
+ assertSame(child1, panel.getControls().get(0));
+ assertSame(child2, panel.getControls().get(1));
+ assertSame(child1, panel.getPanels().get(0));
+ assertSame(child2, panel.getPanels().get(1));
+ }
}