extends FlintstoneTestAbstract {
public void testCreateModelFromProxies() {
Person person = new Person();
Address address;
BeanProxy personProxy = (BeanProxy) createProxy(person);
OpaqueProxy firstNameProxy = (OpaqueProxy) personProxy.getPropertyProxy(
Person.FIRST_NAME);
firstNameProxy.setModelObject("Fred");
assertEquals("First name", "Fred", person.getFirstName());
OpaqueProxy ageProxy = (OpaqueProxy) personProxy.getPropertyProxy(
Person.AGE);
ageProxy.setModelObject(new Integer(10030));
assertEquals("Age", 10030, person.getAge());
// Address should be null before it is modified.
address = person.getAddress();
assertNull("Address not null", address);
BeanProxy addressProxy = (BeanProxy) personProxy.getPropertyProxy(
Person.ADDRESS);
ListProxy linesProxy = (ListProxy) addressProxy.getPropertyProxy(
Address.LINES);
// Address should still be null after its proxy and a nested proxy have
// been added.
address = person.getAddress();
assertNull("Address not null", address);
OpaqueProxy lineProxy;
lineProxy = (OpaqueProxy) linesProxy.addItemProxy();
lineProxy.setModelObject("301 Cobblestone Way");
// Address should not be null now.
address = person.getAddress();
assertNotNull("Address null", address);
lineProxy = (OpaqueProxy) linesProxy.addItemProxy();
lineProxy.setModelObject("Bedrock");
lineProxy = (OpaqueProxy) linesProxy.addItemProxy();
lineProxy.setModelObject("70777");
List expectedAddressLines = new ArrayList();
expectedAddressLines.add("301 Cobblestone Way");
expectedAddressLines.add("Bedrock");
expectedAddressLines.add("70777");
// Lines should not be null and should match expected.
List actualAddressLines = address.getLines();
assertNotNull("Address lines null", actualAddressLines);
assertEquals(
"Address lines mismatch", expectedAddressLines,
actualAddressLines);
}