1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.ui.basicauth;
17
18 import junit.framework.TestCase;
19
20 import org.acegisecurity.DisabledException;
21
22
23
24 import org.springframework.mock.web.MockHttpServletRequest;
25 import org.springframework.mock.web.MockHttpServletResponse;
26
27
28 /***
29 * Tests {@link BasicProcessingFilterEntryPoint}.
30 *
31 * @author Ben Alex
32 * @version $Id: BasicProcessingFilterEntryPointTests.java,v 1.4 2005/11/17 00:56:30 benalex Exp $
33 */
34 public class BasicProcessingFilterEntryPointTests extends TestCase {
35
36
37 public BasicProcessingFilterEntryPointTests() {
38 super();
39 }
40
41 public BasicProcessingFilterEntryPointTests(String arg0) {
42 super(arg0);
43 }
44
45
46
47 public final void setUp() throws Exception {
48 super.setUp();
49 }
50
51 public static void main(String[] args) {
52 junit.textui.TestRunner.run(BasicProcessingFilterEntryPointTests.class);
53 }
54
55 public void testDetectsMissingRealmName() throws Exception {
56 BasicProcessingFilterEntryPoint ep = new BasicProcessingFilterEntryPoint();
57
58 try {
59 ep.afterPropertiesSet();
60 fail("Should have thrown IllegalArgumentException");
61 } catch (IllegalArgumentException expected) {
62 assertEquals("realmName must be specified", expected.getMessage());
63 }
64 }
65
66 public void testGettersSetters() {
67 BasicProcessingFilterEntryPoint ep = new BasicProcessingFilterEntryPoint();
68 ep.setRealmName("realm");
69 assertEquals("realm", ep.getRealmName());
70 }
71
72 public void testNormalOperation() throws Exception {
73 BasicProcessingFilterEntryPoint ep = new BasicProcessingFilterEntryPoint();
74 ep.setRealmName("hello");
75
76 MockHttpServletRequest request = new MockHttpServletRequest();
77 request.setRequestURI("/some_path");
78 MockHttpServletResponse response = new MockHttpServletResponse();
79
80 ep.afterPropertiesSet();
81
82 String msg = "These are the jokes kid";
83 ep.commence(request, response, new DisabledException(msg));
84
85 assertEquals(401, response.getStatus());
86 assertEquals(msg, response.getErrorMessage());
87
88 assertEquals("Basic realm=\"hello\"",
89 response.getHeader("WWW-Authenticate"));
90 }
91 }