use of org.nextprot.api.user.domain.User in project nextprot-api by calipho-sib.
the class UsersExtractorTest method testExtractData.
@Test
public void testExtractData() throws Exception {
UsersExtractor extractor = new UsersExtractor();
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(0);
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(1);
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_ADMIN")));
}
use of org.nextprot.api.user.domain.User in project nextprot-api by calipho-sib.
the class UserDaoTest method testCreateAndGetUser.
@Test
public void testCreateAndGetUser() {
User user = new User();
user.setUsername("freud");
long id = userDao.createUser(user);
Assert.assertTrue(id > 0);
user = userDao.getUserByUsername(user.getUsername());
Assert.assertNull(user.getFirstName());
Assert.assertNull(user.getLastName());
Assert.assertTrue(user.getAuthorities().isEmpty());
}
use of org.nextprot.api.user.domain.User in project nextprot-api by calipho-sib.
the class UserDaoTest method testReadUser2.
@Test
public void testReadUser2() {
User user = userDao.getUserByUsername("tahitibob");
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());
}
use of org.nextprot.api.user.domain.User in project nextprot-api by calipho-sib.
the class UserResourceAuthorizationServiceTest method mockUser.
private static User mockUser(String name) {
User user = Mockito.mock(User.class);
Mockito.when(user.getUsername()).thenReturn(name);
return user;
}
use of org.nextprot.api.user.domain.User in project nextprot-api by calipho-sib.
the class UsersExtractor method extractData.
public List<User> extractData(ResultSet resultSet) throws SQLException, DataAccessException {
LinkedHashMap<Long, User> usersById = new LinkedHashMap<Long, User>();
Set<GrantedAuthority> roles;
while (resultSet.next()) {
long id = resultSet.getLong("user_id");
String roleName = resultSet.getString("role_name");
if (!usersById.containsKey(id)) {
User user = new User();
roles = new HashSet<GrantedAuthority>();
user.setId(id);
user.setUsername(resultSet.getString("user_name"));
user.setFirstName(resultSet.getString("first_name"));
user.setLastName(resultSet.getString("last_name"));
user.setAuthorities(roles);
usersById.put(id, user);
} else {
roles = usersById.get(id).getAuthorities();
}
if (roleName != null)
roles.add(new SimpleGrantedAuthority(roleName));
}
List<User> users = new ArrayList<User>(usersById.values());
if (sort)
Collections.sort(users, userComparator);
return users;
}
Aggregations