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