use of org.nextprot.api.user.domain.User in project nextprot-api by calipho-sib.
the class UserDaoImpl method getUserByUsername.
@Override
public User getUserByUsername(String username) throws DataAccessException {
Map<String, String> namedParams = new HashMap<String, String>();
namedParams.put("user_name", username);
String sql = sqlDictionary.getSQLQuery("read-user-by-name");
NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(dsLocator.getUserDataSource());
List<User> users = template.query(sql, namedParams, new UsersExtractor());
if (users.isEmpty())
throw new EmptyResultDataAccessException(1);
return users.get(0);
}
use of org.nextprot.api.user.domain.User in project nextprot-api by calipho-sib.
the class UsersExtractorTest method testExtractDataSortedByUsername.
@Test
public void testExtractDataSortedByUsername() throws Exception {
UsersExtractor extractor = new UsersExtractor(true);
List<Map<String, ?>> records = new ArrayList<Map<String, ?>>();
records.add(ImmutableMap.of("user_id", 24L, "user_name", "tahitibob", "first_name", "tahiti", "last_name", "bob", "role_name", ""));
records.add(ImmutableMap.of("user_id", 23L, "user_name", "spongebob", "first_name", "", "last_name", "", "role_name", "ROLE_USER"));
records.add(ImmutableMap.of("user_id", 23L, "user_name", "spongebob", "first_name", "", "last_name", "", "role_name", "ROLE_ADMIN"));
List<User> users = extractor.extractData(mockResultSet(records));
Assert.assertEquals(2, users.size());
User user = users.get(1);
Assert.assertEquals(24, user.getId());
Assert.assertEquals("tahitibob", user.getUsername());
Assert.assertEquals("tahiti", user.getFirstName());
Assert.assertEquals("bob", user.getLastName());
Assert.assertTrue(user.getAuthorities().isEmpty());
user = users.get(0);
Assert.assertEquals(23, user.getId());
Assert.assertEquals("spongebob", user.getUsername());
Assert.assertNull(user.getFirstName());
Assert.assertNull(user.getLastName());
Assert.assertTrue(!user.getAuthorities().isEmpty());
Assert.assertTrue(user.getAuthorities().contains(new SimpleGrantedAuthority("ROLE_USER")));
Assert.assertTrue(user.getAuthorities().contains(new SimpleGrantedAuthority("ROLE_USER")));
}
use of org.nextprot.api.user.domain.User in project nextprot-api by calipho-sib.
the class UserDaoTest method testUpdateUser.
@Test
public void testUpdateUser() {
User updated = new User();
updated.setId(23L);
updated.setUsername("spongebob");
updated.setFirstName("sponge");
updated.setLastName("bob");
userDao.updateUser(updated);
User user = userDao.getUserByUsername("spongebob");
Assert.assertEquals(23, user.getId());
Assert.assertEquals("spongebob", user.getUsername());
Assert.assertEquals("sponge", user.getFirstName());
Assert.assertEquals("bob", user.getLastName());
Assert.assertTrue(!user.getAuthorities().isEmpty());
Assert.assertEquals(2, user.getAuthorities().size());
Assert.assertTrue(user.getAuthorities().contains(new SimpleGrantedAuthority("ROLE_USER")));
Assert.assertTrue(user.getAuthorities().contains(new SimpleGrantedAuthority("ROLE_ADMIN")));
}
use of org.nextprot.api.user.domain.User in project nextprot-api by calipho-sib.
the class UserDaoTest method testDeleteUser.
@Test
public void testDeleteUser() {
User toDelete = new User();
toDelete.setId(23);
Assert.assertEquals(2, userDao.getUserList().size());
userDao.deleteUser(toDelete);
Assert.assertEquals(1, userDao.getUserList().size());
}
use of org.nextprot.api.user.domain.User in project nextprot-api by calipho-sib.
the class UserDaoTest method testCreateAndGetUserWithRole.
@Test
public void testCreateAndGetUserWithRole() {
User user = new User();
user.setUsername("freud");
user.setFirstName("huber");
user.setLastName("freud");
Set<GrantedAuthority> hs = new HashSet<GrantedAuthority>();
hs.add(new SimpleGrantedAuthority("ROLE_USER"));
user.setAuthorities(hs);
long id = userDao.createUser(user);
Assert.assertTrue(id > 0);
user = userDao.getUserByUsername(user.getUsername());
Assert.assertEquals("huber", user.getFirstName());
Assert.assertEquals("freud", user.getLastName());
Assert.assertTrue(!user.getAuthorities().isEmpty());
Assert.assertEquals(1, user.getAuthorities().size());
Assert.assertTrue(user.getAuthorities().contains(new SimpleGrantedAuthority("ROLE_USER")));
}
Aggregations