public class TestDirtyProperties extends BaseTestCase {
@Test
public void testEmbeddedUpdateEmbeddedProperty() {
EMain emain = new EMain();
EntityBean eb = (EntityBean)emain;
EntityBeanIntercept ebi = eb._ebean_getIntercept();
emain.setId(1);
emain.setName("foo");
Eembeddable embeddable = setEmbeddedBean(emain, "bar");
setEmbeddedLoaded(embeddable);
// sets loaded state so follow setters are deemed as changes to the bean
ebi.setLoaded();
emain.setName("changedFoo");
DefaultBeanState beanState = new DefaultBeanState(eb);
Set<String> changedProps = beanState.getChangedProps();
Assert.assertEquals(1, changedProps.size());
Assert.assertTrue(changedProps.contains("name"));
Map<String, ValuePair> dirtyValues = beanState.getDirtyValues();
Assert.assertEquals(1, dirtyValues.size());
Assert.assertTrue(dirtyValues.keySet().contains("name"));
ValuePair valuePair = dirtyValues.get("name");
Assert.assertNotNull(valuePair);
Assert.assertEquals("changedFoo",valuePair.getNewValue());
Assert.assertEquals("foo",valuePair.getOldValue());
Eembeddable embeddableRead = emain.getEmbeddable();
embeddableRead.setDescription("embChanged");
Set<String> changedProps2 = beanState.getChangedProps();
Assert.assertEquals(2, changedProps2.size());
Assert.assertTrue(changedProps2.contains("name"));