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.GrantedAuthority;
21 import org.acegisecurity.GrantedAuthorityImpl;
22
23
24 /***
25 * Tests {@link TestingAuthenticationToken}.
26 *
27 * @author Ben Alex
28 * @version $Id: TestingAuthenticationTokenTests.java,v 1.2 2005/11/17 00:55:48 benalex Exp $
29 */
30 public class TestingAuthenticationTokenTests extends TestCase {
31
32
33 public TestingAuthenticationTokenTests() {
34 super();
35 }
36
37 public TestingAuthenticationTokenTests(String arg0) {
38 super(arg0);
39 }
40
41
42
43 public final void setUp() throws Exception {
44 super.setUp();
45 }
46
47 public static void main(String[] args) {
48 junit.textui.TestRunner.run(TestingAuthenticationTokenTests.class);
49 }
50
51 public void testAuthenticated() {
52 TestingAuthenticationToken token = new TestingAuthenticationToken("Test",
53 "Password", null);
54 assertTrue(!token.isAuthenticated());
55 token.setAuthenticated(true);
56 assertTrue(token.isAuthenticated());
57 }
58
59 public void testGetters() {
60 TestingAuthenticationToken token = new TestingAuthenticationToken("Test",
61 "Password",
62 new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_ONE"), new GrantedAuthorityImpl(
63 "ROLE_TWO")});
64 assertEquals("Test", token.getPrincipal());
65 assertEquals("Password", token.getCredentials());
66 assertEquals("ROLE_ONE", token.getAuthorities()[0].getAuthority());
67 assertEquals("ROLE_TWO", token.getAuthorities()[1].getAuthority());
68 }
69
70 public void testNoArgConstructor() {
71 try {
72 new TestingAuthenticationToken();
73 fail("Should have thrown IllegalArgumentException");
74 } catch (IllegalArgumentException expected) {
75 assertTrue(true);
76 }
77 }
78 }