Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
19   58   5   4,75
0   42   0,26   4
4     1,25  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  DefaultUserDetailsServiceTest       Line # 18 19 0% 5 1 95,7% 0.95652175
 
  (6)
 
1    package net.sourceforge.pebble.security;
2   
3    import junit.framework.TestCase;
4    import net.sourceforge.pebble.Constants;
5    import org.acegisecurity.userdetails.UserDetails;
6    import org.acegisecurity.userdetails.UsernameNotFoundException;
7    import org.acegisecurity.GrantedAuthorityImpl;
8   
9    import java.util.Arrays;
10    import java.util.List;
11    import java.util.HashMap;
12   
13    /**
14    * Tests for the DefaultUserDetails class.
15    *
16    * @author Simon Brown
17    */
 
18    public class DefaultUserDetailsServiceTest extends TestCase {
19   
20    private DefaultUserDetailsService service;
21    private SecurityRealm securityRealm;
22   
 
23  6 toggle protected void setUp() {
24  6 service = new DefaultUserDetailsService();
25  6 securityRealm = new MockSecurityRealm();
26  6 service.setSecurityRealm(securityRealm);
27    }
28   
 
29  2 toggle public void testSecurityRealm() {
30  2 assertSame(securityRealm, service.getSecurityRealm());
31    }
32   
 
33  2 toggle public void testLoadByUsername() throws Exception {
34  2 PebbleUserDetails pud = new PebbleUserDetails("username", "password", "name", "emailAddress", "website", "profile", new String[]{Constants.BLOG_OWNER_ROLE}, new HashMap<String,String>(), true);
35  2 securityRealm.createUser(pud);
36  2 UserDetails user = service.loadUserByUsername("username");
37   
38  2 assertNotNull(user);
39  2 assertEquals("username", user.getUsername());
40  2 assertEquals("password", user.getPassword());
41   
42  2 List authorities = Arrays.asList(user.getAuthorities());
43  2 assertEquals(2, authorities.size());
44  2 assertTrue(authorities.contains(new GrantedAuthorityImpl(Constants.BLOG_OWNER_ROLE)));
45  2 assertTrue(authorities.contains(new GrantedAuthorityImpl(Constants.BLOG_READER_ROLE)));
46    }
47   
 
48  2 toggle public void testLoadByUsernameThrowsExceptionWhenUserDoesntExist() throws Exception {
49  2 try {
50  2 PebbleUserDetails pud = new PebbleUserDetails("username", "password", "name", "emailAddress", "website", "profile", new String[]{Constants.BLOG_OWNER_ROLE}, new HashMap<String,String>(), true);
51  2 securityRealm.createUser(pud);
52  2 UserDetails user = service.loadUserByUsername("someotherusername");
53  0 fail();
54    } catch (UsernameNotFoundException e) {
55    }
56    }
57   
58    }