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.event.authorization;
17:
18: import junit.framework.TestCase;
19:
20: import org.acegisecurity.AccessDeniedException;
21: import org.acegisecurity.ConfigAttributeDefinition;
22:
23: import org.acegisecurity.event.authorization.AuthorizationFailureEvent;
24:
25: import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
26:
27: import org.acegisecurity.util.SimpleMethodInvocation;
28:
29: /**
30: * Tests {@link AuthorizationFailureEvent}.
31: *
32: * @author Ben Alex
33: * @version $Id: AuthorizationFailureEventTests.java 1496 2006-05-23 13:38:33Z benalex $
34: */
35: public class AuthorizationFailureEventTests extends TestCase {
36: //~ Constructors ===================================================================================================
37:
38: public AuthorizationFailureEventTests() {
39: super ();
40: }
41:
42: public AuthorizationFailureEventTests(String arg0) {
43: super (arg0);
44: }
45:
46: //~ Methods ========================================================================================================
47:
48: public static void main(String[] args) {
49: junit.textui.TestRunner
50: .run(AuthorizationFailureEventTests.class);
51: }
52:
53: public void testRejectsNulls() {
54: try {
55: new AuthorizationFailureEvent(null,
56: new ConfigAttributeDefinition(),
57: new UsernamePasswordAuthenticationToken("foo",
58: "bar"), new AccessDeniedException("error"));
59: fail("Should have thrown IllegalArgumentException");
60: } catch (IllegalArgumentException expected) {
61: assertTrue(true);
62: }
63:
64: try {
65: new AuthorizationFailureEvent(new SimpleMethodInvocation(),
66: null, new UsernamePasswordAuthenticationToken(
67: "foo", "bar"), new AccessDeniedException(
68: "error"));
69: fail("Should have thrown IllegalArgumentException");
70: } catch (IllegalArgumentException expected) {
71: assertTrue(true);
72: }
73:
74: try {
75: new AuthorizationFailureEvent(new SimpleMethodInvocation(),
76: new ConfigAttributeDefinition(), null,
77: new AccessDeniedException("error"));
78: fail("Should have thrown IllegalArgumentException");
79: } catch (IllegalArgumentException expected) {
80: assertTrue(true);
81: }
82:
83: try {
84: new AuthorizationFailureEvent(new SimpleMethodInvocation(),
85: new ConfigAttributeDefinition(),
86: new UsernamePasswordAuthenticationToken("foo",
87: "bar"), null);
88: fail("Should have thrown IllegalArgumentException");
89: } catch (IllegalArgumentException expected) {
90: assertTrue(true);
91: }
92: }
93: }
|