}
@Test
public void testAddUser() {
BaseUser user = new BaseUser();
user.addGroup(group1);
user.setFirstName("John");
user.setLastName("Doe");
user.setEmailAddress("johndoe@unittest.com");
UserCredential userAccount = new UserCredential();
userAccount.setPassword("unittest");
userAccount.setUsername("jdoe");
userAccount.setUser(user);
user.setCredential(userAccount);
coreUserDAO.saveEntityModel(user);
// ensure user is saved and has id
assertNotNull(user.getId());
assertEquals( 1, jdbcTemplate.queryForInt("select count(*) from USER_PROFILE where EMAIL='johndoe@unittest.com'"));
long userId = user.getId();
Map result = jdbcTemplate.queryForMap("select * from USER_PROFILE where ID=?", new Object[]{userId});
assertEquals("John",result.get("FIRSTNAME"));
assertEquals("Doe",result.get("LASTNAME"));
assertEquals("johndoe@unittest.com",result.get("EMAIL"));
Map cred = jdbcTemplate.queryForMap("select * from USERS where USERID=?", new Object[]{userId});
assertEquals("jdoe",cred.get("USERNAME"));
assertEquals("unittest",cred.get("PASSWORD"));
// add user group
BaseUser testUser = coreUserDAO.loadEntityModel(user.getId());
Set<UserGroup> groups = testUser.getGroups();
assertNotNull(groups);
assertTrue(groups.size() == 1);
assertTrue(groups.iterator().next().getId().equals(group1.getId()));
// remove user group
testUser.removeGroup(group1);
coreUserDAO.saveEntityModel(testUser);
BaseUser testUser2 = coreUserDAO.loadEntityModel(testUser.getId());
assertTrue(testUser2.getGroups().size() == 0);
// remove user
int id = jdbcTemplate.queryForInt("select id from USER_PROFILE where EMAIL='johndoe@unittest.com'");
coreUserDAO.deleteEntityModel(user.getId());
assertEquals(0, jdbcTemplate.queryForInt("select count(*) from USER_PROFILE where ID="+user.getId()));