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