    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.intercept;
    17
    18  import junit.framework.TestCase;
    19
    20  import org.acegisecurity.ConfigAttributeDefinition;
    21  import org.acegisecurity.SecurityConfig;
    22  import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
    23  import org.acegisecurity.util.SimpleMethodInvocation;
    24
    25  import org.aopalliance.intercept.MethodInvocation;
    26
    27
    28  /***
    29   * Tests {@link InterceptorStatusToken}.
    30   *
    31   * @author Ben Alex
    32   * @version $Id: InterceptorStatusTokenTests.java,v 1.3 2005/11/25 04:17:24 benalex Exp $
    33   */
    34  public class InterceptorStatusTokenTests extends TestCase {
    35      //~ Constructors ===========================================================
    36
    37      public InterceptorStatusTokenTests() {
    38          super();
    39      }
    40
    41      public InterceptorStatusTokenTests(String arg0) {
    42          super(arg0);
    43      }
    44
    45      //~ Methods ================================================================
    46
    47      public static void main(String[] args) {
    48          junit.textui.TestRunner.run(InterceptorStatusTokenTests.class);
    49      }
    50
    51      public void testDefaultConstructor() {
    52          try {
    53              new InterceptorStatusToken();
    54              fail("Should have thrown IllegalArgumentException");
    55          } catch (IllegalArgumentException expected) {
    56              assertTrue(true);
    57          }
    58      }
    59
    60      public void testOperation() {
    61          ConfigAttributeDefinition attr = new ConfigAttributeDefinition();
    62          attr.addConfigAttribute(new SecurityConfig("FOO"));
    63
    64          MethodInvocation mi = new SimpleMethodInvocation();
    65
    66          InterceptorStatusToken token = new InterceptorStatusToken(new UsernamePasswordAuthenticationToken(
    67                      "marissa", "koala"), true, attr, mi);
    68
    69          assertTrue(token.isContextHolderRefreshRequired());
    70          assertEquals(attr, token.getAttr());
    71          assertEquals(mi, token.getSecureObject());
    72          assertEquals("marissa", token.getAuthentication().getPrincipal());
    73      }
    74  }