@Test
public void testUpdateSimple() throws Exception
{
PersistenceManager persist = new PersistenceManager(driver, database, login, password);
// create a simple object
SimpleObject object = new SimpleObject();
object.setAge(500L);
// save it
persist.saveObject(object);
// make sure only one object exists
List<SimpleObject> allObjects = persist.getObjectsMatching(new SimpleObject());
assertEquals(1, allObjects.size());
// change the object
object.setAge(1000L);
// save the object again
persist.saveObject(object);
// make sure there's still only one object
allObjects = persist.getObjectsMatching(new SimpleObject());
assertEquals(1, allObjects.size());
// re-open the database connection
persist.close();
persist = new PersistenceManager(driver, database, login, password);
// make sure the object has been changed
allObjects = persist.getObjectsMatching(new SimpleObject());
assertEquals(1, allObjects.size());
SimpleObject first = allObjects.get(0);
assertTrue(first.getAge().equals(1000L));
// add another object
SimpleObject nuObject = new SimpleObject();
nuObject.setAge(1L);
persist.saveObject(nuObject);
// update the new object
nuObject.setAge(2L);
// make sure only one object has been modified
allObjects = persist.getObjectsMatching(new SimpleObject());
assertEquals(2, allObjects.size());
first = allObjects.get(0);
SimpleObject second = allObjects.get(1);
assertTrue((first.getAge() == 2L && second.getAge() == 1000L)
|| (first.getAge() == 1000L && second.getAge() == 2L));
persist.close();
}