/*
* Test method for
* 'org.apache.lucene.gdata.storage.db4o.DB4oStorage.updateAccount(GDataAccount)'
*/
public void testUpdateAccount() throws StorageException {
GDataAccount account = new GDataAccount();
account.setName("simon");
account.setPassword("somepass");
Storage storage = this.controller.getStorage();
try {
storage.updateAccount(account);
fail("Account does not exist");
} catch (Exception e) {
//
}
try {
storage.updateAccount(null);
fail("Account is null");
} catch (Exception e) {
//
}
storage.storeAccount(account);
ObjectContainer container = getContainer();
Query q = container.query();
q.constrain(GDataAccount.class);
q.descend("name").constrain(account.getName());
ObjectSet set = q.execute();
assertEquals(1, set.size());
assertEquals(account.getPassword(), ((GDataAccount) set.next())
.getPassword());
account = new GDataAccount();
account.setName("simon");
account.setPassword("newPass");
storage.updateAccount(account);
container.close();
container = getContainer();
q = container.query();
q.constrain(GDataAccount.class);
q.descend("name").constrain(account.getName());
set = q.execute();
assertEquals(1, set.size());
assertEquals(account.getPassword(), ((GDataAccount) set.next())
.getPassword());
container.close();
}