1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.providers.rcp;
17
18 import junit.framework.TestCase;
19
20 import org.acegisecurity.GrantedAuthority;
21 import org.acegisecurity.MockAuthenticationManager;
22
23
24 /***
25 * Tests {@link RemoteAuthenticationManagerImpl}.
26 *
27 * @author Ben Alex
28 * @version $Id: RemoteAuthenticationManagerImplTests.java,v 1.2 2005/11/17 00:56:09 benalex Exp $
29 */
30 public class RemoteAuthenticationManagerImplTests extends TestCase {
31
32
33 public final void setUp() throws Exception {
34 super.setUp();
35 }
36
37 public static void main(String[] args) {
38 junit.textui.TestRunner.run(RemoteAuthenticationManagerImplTests.class);
39 }
40
41 public void testFailedAuthenticationReturnsRemoteAuthenticationException() {
42 RemoteAuthenticationManagerImpl manager = new RemoteAuthenticationManagerImpl();
43 manager.setAuthenticationManager(new MockAuthenticationManager(false));
44
45 try {
46 manager.attemptAuthentication("marissa", "password");
47 fail("Should have thrown RemoteAuthenticationException");
48 } catch (RemoteAuthenticationException expected) {
49 assertTrue(true);
50 }
51 }
52
53 public void testGettersSetters() {
54 RemoteAuthenticationManagerImpl manager = new RemoteAuthenticationManagerImpl();
55 manager.setAuthenticationManager(new MockAuthenticationManager(true));
56 assertNotNull(manager.getAuthenticationManager());
57 }
58
59 public void testStartupChecksAuthenticationManagerSet()
60 throws Exception {
61 RemoteAuthenticationManagerImpl manager = new RemoteAuthenticationManagerImpl();
62
63 try {
64 manager.afterPropertiesSet();
65 fail("Should have thrown IllegalArgumentException");
66 } catch (IllegalArgumentException expected) {
67 assertTrue(true);
68 }
69
70 manager.setAuthenticationManager(new MockAuthenticationManager(true));
71 manager.afterPropertiesSet();
72 assertTrue(true);
73 }
74
75 public void testSuccessfulAuthentication() {
76 RemoteAuthenticationManagerImpl manager = new RemoteAuthenticationManagerImpl();
77 manager.setAuthenticationManager(new MockAuthenticationManager(true));
78
79 GrantedAuthority[] result = manager.attemptAuthentication("marissa",
80 "password");
81 assertTrue(true);
82 }
83 }