01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
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: * Tests {@link RemoteAuthenticationManagerImpl}.
25: *
26: * @author Ben Alex
27: * @version $Id: RemoteAuthenticationManagerImplTests.java 1496 2006-05-23 13:38:33Z benalex $
28: */
29: public class RemoteAuthenticationManagerImplTests extends TestCase {
30: //~ Methods ========================================================================================================
31:
32: public static void main(String[] args) {
33: junit.textui.TestRunner
34: .run(RemoteAuthenticationManagerImplTests.class);
35: }
36:
37: public final void setUp() throws Exception {
38: super .setUp();
39: }
40:
41: public void testFailedAuthenticationReturnsRemoteAuthenticationException() {
42: RemoteAuthenticationManagerImpl manager = new RemoteAuthenticationManagerImpl();
43: manager.setAuthenticationManager(new MockAuthenticationManager(
44: false));
45:
46: try {
47: manager.attemptAuthentication("marissa", "password");
48: fail("Should have thrown RemoteAuthenticationException");
49: } catch (RemoteAuthenticationException expected) {
50: assertTrue(true);
51: }
52: }
53:
54: public void testGettersSetters() {
55: RemoteAuthenticationManagerImpl manager = new RemoteAuthenticationManagerImpl();
56: manager.setAuthenticationManager(new MockAuthenticationManager(
57: true));
58: assertNotNull(manager.getAuthenticationManager());
59: }
60:
61: public void testStartupChecksAuthenticationManagerSet()
62: throws Exception {
63: RemoteAuthenticationManagerImpl manager = new RemoteAuthenticationManagerImpl();
64:
65: try {
66: manager.afterPropertiesSet();
67: fail("Should have thrown IllegalArgumentException");
68: } catch (IllegalArgumentException expected) {
69: assertTrue(true);
70: }
71:
72: manager.setAuthenticationManager(new MockAuthenticationManager(
73: true));
74: manager.afterPropertiesSet();
75: assertTrue(true);
76: }
77:
78: public void testSuccessfulAuthentication() {
79: RemoteAuthenticationManagerImpl manager = new RemoteAuthenticationManagerImpl();
80: manager.setAuthenticationManager(new MockAuthenticationManager(
81: true));
82:
83: GrantedAuthority[] result = manager.attemptAuthentication(
84: "marissa", "password");
85: assertTrue(true);
86: }
87: }
|