1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.providers;
17
18 import junit.framework.TestCase;
19
20 import org.acegisecurity.Authentication;
21 import org.acegisecurity.GrantedAuthority;
22 import org.acegisecurity.GrantedAuthorityImpl;
23
24
25 /***
26 * Tests {@link TestingAuthenticationProvider}.
27 *
28 * @author Ben Alex
29 * @version $Id: TestingAuthenticationProviderTests.java,v 1.2 2005/11/17 00:55:48 benalex Exp $
30 */
31 public class TestingAuthenticationProviderTests extends TestCase {
32
33
34 public TestingAuthenticationProviderTests() {
35 super();
36 }
37
38 public TestingAuthenticationProviderTests(String arg0) {
39 super(arg0);
40 }
41
42
43
44 public final void setUp() throws Exception {
45 super.setUp();
46 }
47
48 public static void main(String[] args) {
49 junit.textui.TestRunner.run(TestingAuthenticationProviderTests.class);
50 }
51
52 public void testAuthenticates() {
53 TestingAuthenticationProvider provider = new TestingAuthenticationProvider();
54 TestingAuthenticationToken token = new TestingAuthenticationToken("Test",
55 "Password",
56 new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_ONE"), new GrantedAuthorityImpl(
57 "ROLE_TWO")});
58 Authentication result = provider.authenticate(token);
59
60 if (!(result instanceof TestingAuthenticationToken)) {
61 fail("Should have returned instance of TestingAuthenticationToken");
62 }
63
64 TestingAuthenticationToken castResult = (TestingAuthenticationToken) result;
65 assertEquals("Test", castResult.getPrincipal());
66 assertEquals("Password", castResult.getCredentials());
67 assertEquals("ROLE_ONE", castResult.getAuthorities()[0].getAuthority());
68 assertEquals("ROLE_TWO", castResult.getAuthorities()[1].getAuthority());
69 }
70
71 public void testSupports() {
72 TestingAuthenticationProvider provider = new TestingAuthenticationProvider();
73 assertTrue(provider.supports(TestingAuthenticationToken.class));
74 assertTrue(!provider.supports(String.class));
75 }
76 }