1   /* Copyright 2004, 2005 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.adapters;
17  
18  import junit.framework.TestCase;
19  
20  import org.acegisecurity.GrantedAuthority;
21  import org.acegisecurity.GrantedAuthorityImpl;
22  
23  
24  /***
25   * Tests {@link PrincipalAcegiUserToken}.
26   *
27   * @author Ben Alex
28   * @version $Id: PrincipalAcegiUserTokenTests.java,v 1.7 2005/11/25 00:26:29 benalex Exp $
29   */
30  public class PrincipalAcegiUserTokenTests extends TestCase {
31      //~ Constructors ===========================================================
32  
33      public PrincipalAcegiUserTokenTests() {
34          super();
35      }
36  
37      public PrincipalAcegiUserTokenTests(String arg0) {
38          super(arg0);
39      }
40  
41      //~ Methods ================================================================
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(PrincipalAcegiUserTokenTests.class);
49      }
50  
51      public void testGetters() throws Exception {
52          PrincipalAcegiUserToken token = new PrincipalAcegiUserToken("my_password",
53                  "Test", "Password",
54                  new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_ONE"), new GrantedAuthorityImpl(
55                          "ROLE_TWO")}, null);
56          assertEquals("Test", token.getPrincipal());
57          assertEquals("Password", token.getCredentials());
58          assertEquals("my_password".hashCode(), token.getKeyHash());
59          assertEquals("Test", token.getName());
60      }
61  
62      public void testNoArgsConstructor() {
63          try {
64              new PrincipalAcegiUserToken();
65              fail("Should have thrown IllegalArgumentException");
66          } catch (IllegalArgumentException expected) {
67              assertTrue(true);
68          }
69      }
70  }