* Sanity checks for ClickUtils.copyFormToObject.
*/
public void testCopyFormToObject() {
// set up the form
Form form = new Form("sample");
TextField idField = new TextField("id");
form.add(idField);
FieldSet fieldset = new FieldSet("fieldset");
form.add(fieldset);
TextField nameField = new TextField("name");
fieldset.add(nameField);
TextField dateField = new TextField("dateOfBirth");
fieldset.add(dateField);
TextField intField = new TextField("int");
form.add(intField);
TextField doubleField = new TextField("double");
form.add(doubleField);
Checkbox checkBox = new Checkbox("boolean");
form.add(checkBox);
TextField telephoneField = new TextField("telephone");
form.add(telephoneField);
HiddenField hidden = new HiddenField("hidden", String.class);
form.add(hidden);
// Populate fields
idField.setValueObject(ID);
nameField.setValue(NAME);
dateField.setValueObject(DATE_OF_BIRTH);
intField.setValue(String.valueOf(INT));
doubleField.setValue(String.valueOf(DOUBLE));
checkBox.setChecked(BOOLEAN);
telephoneField.setValue(TELEPHONE);
// copy form to object
SampleObject sampleObject = new SampleObject();
ClickUtils.copyFormToObject(form, sampleObject, true);
// has the object been configured correctly?
assertEquals(new Integer(idField.getValue()), sampleObject.getId());
assertEquals(nameField.getValue(), sampleObject.getName());
//NOTE the dateField was NOT copied to the sampleObject's Date property.
//Use org.apache.click.extras.control.DateField in the extras project, to
//copy a Date property.
assertEquals(null, sampleObject.getDateOfBirth());
assertEquals(telephoneField.getValueObject().toString(), sampleObject.getTelephone());
assertTrue(sampleObject.getInt() == new Integer(intField.getValue()).intValue());
assertTrue(sampleObject.getDouble() == new Double(doubleField.getValue()).doubleValue());
assertTrue(sampleObject.isBoolean() == checkBox.isChecked());
// Test object path copying
User user = new User();
user.setAddress(new Address());
user.getAddress().setState(new State());
form = new Form();
TextField codeField = new TextField("address.state.code");
codeField.setValue("NSW");
form.add(codeField);
form.copyTo(user, true);
assertEquals("NSW", user.getAddress().getState().getCode());
}