@Before public void setUp() { List<User> testUsers = new ArrayList<User>(); for (int i = 0; i < 10; i++) { User user = new User(); user.setEmail("alex_clavijo" + i + "@gmail.com"); user.setUsername("alex" + i); user.setPassword(EncryptorManager.encryptPassword("acp")); user.setName("Alejandro" + i); user.setLastName("Clavijo" + i); user.setCreated(DateTime.now()); Set<UserRole> roles = new HashSet<UserRole>(); roles.add(UserRole.USER); user.setRoles(roles); testUsers.add(user); } userRepository.saveAll(testUsers); }
@Test @Transactional public void saveUser() { User user = new User(); user.setEmail("*****@*****.**"); user.setUsername("alber"); user.setPassword(EncryptorManager.encryptPassword("acc")); user.setName("Alberto"); user.setLastName("Clavijo"); Set<UserRole> roles = new HashSet<UserRole>(); roles.add(UserRole.ADMIN); user.setRoles(roles); // userRepository.save(user); sessionFactory.getCurrentSession().save(user); sessionFactory.getCurrentSession().flush(); assertNotNull(user.getUserId()); }