1 package org.gnomekr.potron.service; 2 3 import static org.gnomekr.potron.util.PotronConstants.BEAN_ID_USER_MANAGER; 4 5 import java.util.List; 6 7 import org.gnomekr.potron.data.User; 8 9 /*** 10 * UserManagerTest.java 11 * @author Xavier Cho 12 * @version $Revision 1.1 $ $Date: 2005/06/30 15:14:34 $ 13 */ 14 public class UserManagerTest extends 15 AbstractHibernateSpringContextTests { 16 17 /*** 18 * @throws Exception 19 */ 20 public void testUserPersistence() throws Exception { 21 IUserManager manager = (IUserManager) applicationContext 22 .getBean(BEAN_ID_USER_MANAGER); 23 assertNotNull(manager); 24 25 User user = new User("__test_user__"); 26 user.setRealName("Test User"); 27 user.setEmail("email"); 28 user.setPassword("password"); 29 30 manager.createUser(user); 31 32 flushCurrentSession(); 33 34 int count = jdbcTemplate.queryForInt( 35 "select count(*) from POTRON_USER where user_name=?", 36 new String[] { 37 user.getUserName() 38 }); 39 40 assertEquals(1, count); 41 42 try { 43 manager.createUser(user); 44 flushCurrentSession(); 45 46 assertTrue("Should have thrown UserExistsException here.", false); 47 } catch (UserExistsException e) { 48 } 49 50 User user2 = manager.getUser(user.getUserName()); 51 52 assertNotNull(user2); 53 assertEquals(user2, user); 54 55 user.setEmail("email2"); 56 57 manager.updateUser(user); 58 flushCurrentSession(); 59 60 String email = (String) jdbcTemplate.queryForObject( 61 "select email from POTRON_USER where user_name=?", 62 new String[] { 63 user.getUserName() 64 }, 65 String.class); 66 67 assertEquals("email2", email); 68 69 List<User> users = manager.getUsers(); 70 assertNotNull(users); 71 assertTrue(users.contains(user)); 72 73 manager.deleteUser(user.getUserName()); 74 75 flushCurrentSession(); 76 77 count = jdbcTemplate.queryForInt( 78 "select count(*) from POTRON_USER where user_name=?", 79 new String[] { 80 user.getUserName() 81 }); 82 83 assertEquals(0, count); 84 } 85 }