1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.util;
17
18 import junit.framework.TestCase;
19 import org.springframework.mock.web.MockHttpServletRequest;
20
21
22
23 /***
24 * Tests {@link PortResolverImpl}.
25 *
26 * @author Ben Alex
27 * @version $Id: PortResolverImplTests.java,v 1.5 2005/11/17 00:56:08 benalex Exp $
28 */
29 public class PortResolverImplTests extends TestCase {
30
31
32 public PortResolverImplTests() {
33 super();
34 }
35
36 public PortResolverImplTests(String arg0) {
37 super(arg0);
38 }
39
40
41
42 public final void setUp() throws Exception {
43 super.setUp();
44 }
45
46 public static void main(String[] args) {
47 junit.textui.TestRunner.run(PortResolverImplTests.class);
48 }
49
50 public void testDetectsBuggyIeHttpRequest() throws Exception {
51 PortResolverImpl pr = new PortResolverImpl();
52 pr.afterPropertiesSet();
53
54 MockHttpServletRequest request = new MockHttpServletRequest();
55 request.setServerPort(8443);
56 request.setScheme("HTtP");
57 assertEquals(8080, pr.getServerPort(request));
58 }
59
60 public void testDetectsBuggyIeHttpsRequest() throws Exception {
61 PortResolverImpl pr = new PortResolverImpl();
62 pr.afterPropertiesSet();
63
64 MockHttpServletRequest request = new MockHttpServletRequest();
65 request.setServerPort(8080);
66 request.setScheme("HTtPs");
67 assertEquals(8443, pr.getServerPort(request));
68 }
69
70 public void testDetectsEmptyPortMapper() throws Exception {
71 PortResolverImpl pr = new PortResolverImpl();
72 pr.setPortMapper(null);
73
74 try {
75 pr.afterPropertiesSet();
76 fail("Should have thrown IllegalArgumentException");
77 } catch (IllegalArgumentException expected) {
78 assertTrue(true);
79 }
80 }
81
82 public void testGettersSetters() throws Exception {
83 PortResolverImpl pr = new PortResolverImpl();
84 assertTrue(pr.getPortMapper() != null);
85 pr.setPortMapper(new PortMapperImpl());
86 assertTrue(pr.getPortMapper() != null);
87 }
88
89 public void testNormalOperation() throws Exception {
90 PortResolverImpl pr = new PortResolverImpl();
91 pr.afterPropertiesSet();
92
93 MockHttpServletRequest request = new MockHttpServletRequest();
94 request.setScheme("http");
95 request.setServerPort(1021);
96 assertEquals(1021, pr.getServerPort(request));
97 }
98 }