001: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
002: *
003: * Licensed under the Apache License, Version 2.0 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at
006: *
007: * http://www.apache.org/licenses/LICENSE-2.0
008: *
009: * Unless required by applicable law or agreed to in writing, software
010: * distributed under the License is distributed on an "AS IS" BASIS,
011: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: * See the License for the specific language governing permissions and
013: * limitations under the License.
014: */
015:
016: package org.acegisecurity.util;
017:
018: import junit.framework.TestCase;
019:
020: import java.util.HashMap;
021: import java.util.Map;
022:
023: /**
024: * Tests {@link PortMapperImpl}.
025: *
026: * @author Ben Alex
027: * @version $Id: PortMapperImplTests.java 1496 2006-05-23 13:38:33Z benalex $
028: */
029: public class PortMapperImplTests extends TestCase {
030: //~ Constructors ===================================================================================================
031:
032: public PortMapperImplTests() {
033: super ();
034: }
035:
036: public PortMapperImplTests(String arg0) {
037: super (arg0);
038: }
039:
040: //~ Methods ========================================================================================================
041:
042: public static void main(String[] args) {
043: junit.textui.TestRunner.run(PortMapperImplTests.class);
044: }
045:
046: public final void setUp() throws Exception {
047: super .setUp();
048: }
049:
050: public void testDefaultMappingsAreKnown() throws Exception {
051: PortMapperImpl portMapper = new PortMapperImpl();
052: assertEquals(new Integer(80), portMapper
053: .lookupHttpPort(new Integer(443)));
054: assertEquals(new Integer(8080), portMapper
055: .lookupHttpPort(new Integer(8443)));
056: assertEquals(new Integer(443), portMapper
057: .lookupHttpsPort(new Integer(80)));
058: assertEquals(new Integer(8443), portMapper
059: .lookupHttpsPort(new Integer(8080)));
060: }
061:
062: public void testDetectsEmptyMap() throws Exception {
063: PortMapperImpl portMapper = new PortMapperImpl();
064:
065: try {
066: portMapper.setPortMappings(new HashMap());
067: fail("Should have thrown IllegalArgumentException");
068: } catch (IllegalArgumentException expected) {
069: assertTrue(true);
070: }
071: }
072:
073: public void testDetectsNullMap() throws Exception {
074: PortMapperImpl portMapper = new PortMapperImpl();
075:
076: try {
077: portMapper.setPortMappings(null);
078: fail("Should have thrown IllegalArgumentException");
079: } catch (IllegalArgumentException expected) {
080: assertTrue(true);
081: }
082: }
083:
084: public void testGetTranslatedPortMappings() {
085: PortMapperImpl portMapper = new PortMapperImpl();
086: assertEquals(2, portMapper.getTranslatedPortMappings().size());
087: }
088:
089: public void testRejectsOutOfRangeMappings() {
090: PortMapperImpl portMapper = new PortMapperImpl();
091: Map map = new HashMap();
092: map.put("79", "80559");
093:
094: try {
095: portMapper.setPortMappings(map);
096: fail("Should have thrown IllegalArgumentException");
097: } catch (IllegalArgumentException expected) {
098: assertTrue(true);
099: }
100: }
101:
102: public void testReturnsNullIfHttpPortCannotBeFound() {
103: PortMapperImpl portMapper = new PortMapperImpl();
104: assertTrue(portMapper.lookupHttpPort(new Integer("34343")) == null);
105: }
106:
107: public void testSupportsCustomMappings() {
108: PortMapperImpl portMapper = new PortMapperImpl();
109: Map map = new HashMap();
110: map.put("79", "442");
111:
112: portMapper.setPortMappings(map);
113:
114: assertEquals(new Integer(79), portMapper
115: .lookupHttpPort(new Integer(442)));
116: assertEquals(new Integer(442), portMapper
117: .lookupHttpsPort(new Integer(79)));
118: }
119: }
|