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
24 import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
25
26
27
28
29
30
31
32
33 public class AuthenticationEventTests extends TestCase {
34
35
36 private Authentication getAuthentication() {
37 UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken("Principal",
38 "Credentials");
39 authentication.setDetails("127.0.0.1");
40
41 return authentication;
42 }
43
44 public static void main(String[] args) {
45 junit.textui.TestRunner.run(AuthenticationEventTests.class);
46 }
47
48 public final void setUp() throws Exception {
49 super.setUp();
50 }
51
52 public void testAbstractAuthenticationEvent() {
53 Authentication auth = getAuthentication();
54 AbstractAuthenticationEvent event = new AuthenticationSuccessEvent(auth);
55 assertEquals(auth, event.getAuthentication());
56 }
57
58 public void testAbstractAuthenticationFailureEvent() {
59 Authentication auth = getAuthentication();
60 AuthenticationException exception = new DisabledException("TEST");
61 AbstractAuthenticationFailureEvent event = new AuthenticationFailureDisabledEvent(auth, exception);
62 assertEquals(auth, event.getAuthentication());
63 assertEquals(exception, event.getException());
64 }
65
66 public void testRejectsNullAuthentication() {
67 AuthenticationException exception = new DisabledException("TEST");
68
69 try {
70 AuthenticationFailureDisabledEvent event = new AuthenticationFailureDisabledEvent(null, exception);
71 fail("Should have thrown IllegalArgumentException");
72 } catch (IllegalArgumentException expected) {
73 assertTrue(true);
74 }
75 }
76
77 public void testRejectsNullAuthenticationException() {
78 try {
79 new AuthenticationFailureDisabledEvent(getAuthentication(), null);
80 fail("Should have thrown IllegalArgumentException");
81 } catch (IllegalArgumentException expected) {
82 assertTrue(true);
83 }
84 }
85 }