*/
public void testCopyObjectToForm() {
// 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);
HiddenField hidden = new HiddenField("hidden", String.class);
form.add(hidden);
// Populate object
SampleObject sampleObject = new SampleObject();
sampleObject.setId(ID);
sampleObject.setName(NAME);
sampleObject.setDateOfBirth(DATE_OF_BIRTH);
sampleObject.setInt(INT);
sampleObject.setDouble(DOUBLE);
sampleObject.setBoolean(BOOLEAN);
// copy object to form
ClickUtils.copyObjectToForm(sampleObject, form, true);
// has the form been configured correctly?
assertEquals(sampleObject.getId(), new Integer(idField.getValue()));
assertEquals(sampleObject.getName(), nameField.getValue());
assertEquals(sampleObject.getDateOfBirth().toString(), dateField.getValue());
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());
user.getAddress().getState().setCode("NSW");
form = new Form();
TextField codeField = new TextField("address.state.code");
form.add(codeField);
form.copyFrom(user, true);
assertEquals("NSW", codeField.getValueObject());
Map map = new HashMap();
map.put("name", "malcolm");
form = new Form();
TextField nameField2 = new TextField("name");
form.add(nameField2);
form.copyFrom(map, true);
assertEquals("malcolm", nameField2.getValue());
}