Search in sources :

Example 11 with User

use of org.nextprot.api.user.domain.User in project nextprot-api by calipho-sib.

the class UserDaoTest method testReadUserWithRoles.

@Test
public void testReadUserWithRoles() {
    User user = userDao.getUserByUsername("spongebob");
    Assert.assertEquals(23, user.getId());
    Assert.assertEquals("spongebob", user.getUsername());
    Assert.assertNull(user.getFirstName());
    Assert.assertNull(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")));
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) User(org.nextprot.api.user.domain.User) UserResourceBaseTest(org.nextprot.api.user.dao.test.base.UserResourceBaseTest) Test(org.junit.Test)

Example 12 with User

use of org.nextprot.api.user.domain.User in project nextprot-api by calipho-sib.

the class UserDaoTest method testUpdateUserWithRoles.

@Test
public void testUpdateUserWithRoles() {
    User updated = new User();
    updated.setId(23);
    updated.setUsername("spongebob");
    updated.setFirstName("sponge");
    updated.setLastName("bob");
    Set<GrantedAuthority> hs = new HashSet<GrantedAuthority>();
    hs.add(new SimpleGrantedAuthority("ROLE_USER"));
    updated.setAuthorities(hs);
    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(1, user.getAuthorities().size());
    Assert.assertTrue(user.getAuthorities().contains(new SimpleGrantedAuthority("ROLE_USER")));
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) User(org.nextprot.api.user.domain.User) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) HashSet(java.util.HashSet) UserResourceBaseTest(org.nextprot.api.user.dao.test.base.UserResourceBaseTest) Test(org.junit.Test)

Aggregations

User (org.nextprot.api.user.domain.User)12 Test (org.junit.Test)9 UserResourceBaseTest (org.nextprot.api.user.dao.test.base.UserResourceBaseTest)7 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)7 GrantedAuthority (org.springframework.security.core.GrantedAuthority)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 HashSet (java.util.HashSet)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)1 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)1