01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * 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.util;
17:
18: import junit.framework.TestCase;
19:
20: import org.springframework.mock.web.MockHttpServletRequest;
21:
22: /**
23: * Tests {@link PortResolverImpl}.
24: *
25: * @author Ben Alex
26: * @version $Id: PortResolverImplTests.java 1496 2006-05-23 13:38:33Z benalex $
27: */
28: public class PortResolverImplTests extends TestCase {
29: //~ Constructors ===================================================================================================
30:
31: public PortResolverImplTests() {
32: super ();
33: }
34:
35: public PortResolverImplTests(String arg0) {
36: super (arg0);
37: }
38:
39: //~ Methods ========================================================================================================
40:
41: public static void main(String[] args) {
42: junit.textui.TestRunner.run(PortResolverImplTests.class);
43: }
44:
45: public final void setUp() throws Exception {
46: super .setUp();
47: }
48:
49: public void testDetectsBuggyIeHttpRequest() throws Exception {
50: PortResolverImpl pr = new PortResolverImpl();
51: pr.afterPropertiesSet();
52:
53: MockHttpServletRequest request = new MockHttpServletRequest();
54: request.setServerPort(8443);
55: request.setScheme("HTtP"); // proves case insensitive handling
56: assertEquals(8080, pr.getServerPort(request));
57: }
58:
59: public void testDetectsBuggyIeHttpsRequest() throws Exception {
60: PortResolverImpl pr = new PortResolverImpl();
61: pr.afterPropertiesSet();
62:
63: MockHttpServletRequest request = new MockHttpServletRequest();
64: request.setServerPort(8080);
65: request.setScheme("HTtPs"); // proves case insensitive handling
66: assertEquals(8443, pr.getServerPort(request));
67: }
68:
69: public void testDetectsEmptyPortMapper() throws Exception {
70: PortResolverImpl pr = new PortResolverImpl();
71: pr.setPortMapper(null);
72:
73: try {
74: pr.afterPropertiesSet();
75: fail("Should have thrown IllegalArgumentException");
76: } catch (IllegalArgumentException expected) {
77: assertTrue(true);
78: }
79: }
80:
81: public void testGettersSetters() throws Exception {
82: PortResolverImpl pr = new PortResolverImpl();
83: assertTrue(pr.getPortMapper() != null);
84: pr.setPortMapper(new PortMapperImpl());
85: assertTrue(pr.getPortMapper() != null);
86: }
87:
88: public void testNormalOperation() throws Exception {
89: PortResolverImpl pr = new PortResolverImpl();
90: pr.afterPropertiesSet();
91:
92: MockHttpServletRequest request = new MockHttpServletRequest();
93: request.setScheme("http");
94: request.setServerPort(1021);
95: assertEquals(1021, pr.getServerPort(request));
96: }
97: }
|