01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * 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: * Tests {@link InterceptorStatusToken}.
31: *
32: * @author Ben Alex
33: * @version $Id: InterceptorStatusTokenTests.java 1496 2006-05-23 13:38:33Z benalex $
34: */
35: public class InterceptorStatusTokenTests extends TestCase {
36: //~ Constructors ===================================================================================================
37:
38: public InterceptorStatusTokenTests() {
39: super ();
40: }
41:
42: public InterceptorStatusTokenTests(String arg0) {
43: super (arg0);
44: }
45:
46: //~ Methods ========================================================================================================
47:
48: public static void main(String[] args) {
49: junit.textui.TestRunner.run(InterceptorStatusTokenTests.class);
50: }
51:
52: public void testNoArgConstructorDoesntExist() {
53: Class clazz = InterceptorStatusToken.class;
54:
55: try {
56: clazz.getDeclaredConstructor((Class[]) null);
57: fail("Should have thrown NoSuchMethodException");
58: } catch (NoSuchMethodException expected) {
59: assertTrue(true);
60: }
61: }
62:
63: public void testOperation() {
64: ConfigAttributeDefinition attr = new ConfigAttributeDefinition();
65: attr.addConfigAttribute(new SecurityConfig("FOO"));
66:
67: MethodInvocation mi = new SimpleMethodInvocation();
68:
69: InterceptorStatusToken token = new InterceptorStatusToken(
70: 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()
77: .getPrincipal());
78: }
79: }
|