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