assertEquals("NSW", user.getAddress().getState().getCode());
}
public void testCopyObjectToForm() {
// set up the form
Form form = new Form("sample");
IntegerField idField = new IntegerField("id");
form.add(idField);
FieldSet fieldset = new FieldSet("fieldset");
form.add(fieldset);
TextField nameField = new TextField("name");
fieldset.add(nameField);
DateField dateField = new DateField("dateOfBirth");
fieldset.add(dateField);
IntegerField intField = new IntegerField("int");
form.add(intField);
DoubleField doubleField = new DoubleField("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(), idField.getInteger());
assertEquals(sampleObject.getName(), nameField.getValue());
assertEquals(sampleObject.getDateOfBirth(), dateField.getDate());
assertTrue(sampleObject.getInt() == intField.getInteger().intValue());
assertTrue(sampleObject.getDouble() == doubleField.getDouble().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());
}