    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;
    17
    18  import junit.framework.TestCase;
    19
    20  import org.acegisecurity.providers.TestingAuthenticationToken;
    21  import org.acegisecurity.providers.anonymous.AnonymousAuthenticationToken;
    22  import org.acegisecurity.providers.rememberme.RememberMeAuthenticationToken;
    23
    24
    25  /***
    26   * Tests {@link org.acegisecurity.AuthenticationTrustResolverImpl}.
    27   *
    28   * @author Ben Alex
    29   * @version $Id: AuthenticationTrustResolverImplTests.java,v 1.3 2005/11/17 00:55:47 benalex Exp $
    30   */
    31  public class AuthenticationTrustResolverImplTests extends TestCase {
    32      //~ Constructors ===========================================================
    33
    34      public AuthenticationTrustResolverImplTests() {
    35          super();
    36      }
    37
    38      public AuthenticationTrustResolverImplTests(String arg0) {
    39          super(arg0);
    40      }
    41
    42      //~ Methods ================================================================
    43
    44      public static void main(String[] args) {
    45          junit.textui.TestRunner.run(AuthenticationTrustResolverImplTests.class);
    46      }
    47
    48      public void testCorrectOperationIsAnonymous() {
    49          AuthenticationTrustResolverImpl trustResolver = new AuthenticationTrustResolverImpl();
    50          assertTrue(trustResolver.isAnonymous(
    51                  new AnonymousAuthenticationToken("ignored", "ignored",
    52                      new GrantedAuthority[] {new GrantedAuthorityImpl("ignored")})));
    53          assertFalse(trustResolver.isAnonymous(
    54                  new TestingAuthenticationToken("ignored", "ignored",
    55                      new GrantedAuthority[] {new GrantedAuthorityImpl("ignored")})));
    56      }
    57
    58      public void testCorrectOperationIsRememberMe() {
    59          AuthenticationTrustResolverImpl trustResolver = new AuthenticationTrustResolverImpl();
    60          assertTrue(trustResolver.isRememberMe(
    61                  new RememberMeAuthenticationToken("ignored", "ignored",
    62                      new GrantedAuthority[] {new GrantedAuthorityImpl("ignored")})));
    63          assertFalse(trustResolver.isAnonymous(
    64                  new TestingAuthenticationToken("ignored", "ignored",
    65                      new GrantedAuthority[] {new GrantedAuthorityImpl("ignored")})));
    66      }
    67
    68      public void testGettersSetters() {
    69          AuthenticationTrustResolverImpl trustResolver = new AuthenticationTrustResolverImpl();
    70
    71          assertEquals(AnonymousAuthenticationToken.class,
    72              trustResolver.getAnonymousClass());
    73          trustResolver.setAnonymousClass(String.class);
    74          assertEquals(String.class, trustResolver.getAnonymousClass());
    75
    76          assertEquals(RememberMeAuthenticationToken.class,
    77              trustResolver.getRememberMeClass());
    78          trustResolver.setRememberMeClass(String.class);
    79          assertEquals(String.class, trustResolver.getRememberMeClass());
    80      }
    81  }