public void insert_update() {
// init user ids
assertUserIdList(userDao.getUserIdList(), "admin", "j2ee");
// insert new user
User user = userDao.getUserById("j2ee");
user.setUserId("myuser");
user.setPassword("mypass");
user.setRole("r1, r2");
userDao.insertUser(user);
// check user ids again
assertUserIdList(userDao.getUserIdList(), "admin", "j2ee", "myuser");
// check new user
user = userDao.getAuthenticatedUser("myuser", "mypass");
assertEquals("myuser", user.getUserId());
assertUser(user, false, "r1", "r2");
// change password
user.setPassword("newpass");
userDao.updateUser(user);
assertNull(userDao.getAuthenticatedUser("myuser", "mypass"));
user = userDao.getAuthenticatedUser("myuser", "newpass");
assertEquals("myuser", user.getUserId());
assertUser(user, false, "r1", "r2");
// update other data
user.getAccount().setCity("newcity");
user.getAccount().setCreditCardExpiryMonth(1);
user.getAccount().setCreditCardExpiryYear(2011);
user.getProfile().setLanguagePreference("chinese");
userDao.updateUser(user);
user = userDao.getAuthenticatedUser("myuser", "newpass");
assertEquals("myuser", user.getUserId());
assertEquals("newcity", user.getAccount().getCity());
assertEquals("2011-01-15", new SimpleDateFormat("yyyy-MM-dd").format(user.getAccount().getCreditCardExpiry()));
assertEquals(1, user.getAccount().getCreditCardExpiryMonth());
assertEquals(2011, user.getAccount().getCreditCardExpiryYear());
assertEquals("chinese", user.getProfile().getLanguagePreference());
}