1   /* Copyright 2004 Acegi Technology Pty Limited
2    *
3    * Licensed under the Apache License, Version 2.0 (the "License");
4    * you may not use this file except in compliance with the License.
5    * You may obtain a copy of the License at
6    *
7    *     http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * 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  /***
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      //~ Methods ================================================================
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  }