1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.event.authentication;
17
18 import junit.framework.TestCase;
19
20 import org.acegisecurity.Authentication;
21 import org.acegisecurity.AuthenticationException;
22 import org.acegisecurity.DisabledException;
23 import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
24
25
26 /***
27 * Tests {@link AbstractAuthenticationEvent} and its subclasses.
28 *
29 * @author Ben Alex
30 * @version $Id: AuthenticationEventTests.java,v 1.2 2005/11/17 00:56:47 benalex Exp $
31 */
32 public class AuthenticationEventTests extends TestCase {
33
34
35 public final void setUp() throws Exception {
36 super.setUp();
37 }
38
39 public static void main(String[] args) {
40 junit.textui.TestRunner.run(AuthenticationEventTests.class);
41 }
42
43 public void testAbstractAuthenticationEvent() {
44 Authentication auth = getAuthentication();
45 AbstractAuthenticationEvent event = new AuthenticationSuccessEvent(auth);
46 assertEquals(auth, event.getAuthentication());
47 }
48
49 public void testAbstractAuthenticationFailureEvent() {
50 Authentication auth = getAuthentication();
51 AuthenticationException exception = new DisabledException("TEST");
52 AbstractAuthenticationFailureEvent event = new AuthenticationFailureDisabledEvent(auth,
53 exception);
54 assertEquals(auth, event.getAuthentication());
55 assertEquals(exception, event.getException());
56 }
57
58 public void testRejectsNullAuthentication() {
59 AuthenticationException exception = new DisabledException("TEST");
60
61 try {
62 AuthenticationFailureDisabledEvent event = new AuthenticationFailureDisabledEvent(null,
63 exception);
64 fail("Should have thrown IllegalArgumentException");
65 } catch (IllegalArgumentException expected) {
66 assertTrue(true);
67 }
68 }
69
70 public void testRejectsNullAuthenticationException() {
71 try {
72 new AuthenticationFailureDisabledEvent(getAuthentication(), null);
73 fail("Should have thrown IllegalArgumentException");
74 } catch (IllegalArgumentException expected) {
75 assertTrue(true);
76 }
77 }
78
79 private Authentication getAuthentication() {
80 UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken("Principal",
81 "Credentials");
82 authentication.setDetails("127.0.0.1");
83
84 return authentication;
85 }
86 }