001 // Copyright 2005 The Apache Software Foundation 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 package org.apache.tapestry.request; 016 017 import static org.easymock.EasyMock.expect; 018 019 import org.apache.tapestry.BaseComponentTestCase; 020 import org.testng.annotations.Test; 021 022 import javax.servlet.http.HttpServletRequest; 023 024 /** 025 * Tests for {@link org.apache.tapestry.request.DecodedRequestWrapper}and 026 * {@link org.apache.tapestry.request.DecodedRequest}. 027 * 028 * @author Howard M. Lewis Ship 029 * @since 4.0 030 */ 031 @Test 032 public class TestDecodedRequestWrapper extends BaseComponentTestCase 033 { 034 private HttpServletRequest newHttpRequest() 035 { 036 return newMock(HttpServletRequest.class); 037 } 038 039 public void testInterceptedMethods() 040 { 041 DecodedRequest dr = new DecodedRequest(); 042 043 dr.setRequestURI("/foo/bar/baz"); 044 dr.setScheme("https"); 045 dr.setServerPort(2170); 046 dr.setServerName("www.flintstone.com"); 047 048 HttpServletRequest request = newHttpRequest(); 049 050 replay(); 051 052 DecodedRequestWrapper w = new DecodedRequestWrapper(request, dr); 053 054 assertEquals("/foo/bar/baz", w.getRequestURI()); 055 assertEquals("https", w.getScheme()); 056 assertEquals(2170, w.getServerPort()); 057 assertEquals("www.flintstone.com", w.getServerName()); 058 059 verify(); 060 } 061 062 public void testRequestConstructor() 063 { 064 HttpServletRequest request = newHttpRequest(); 065 066 expect(request.getScheme()).andReturn("https"); 067 068 expect(request.getServerName()).andReturn("www.flintstone.com"); 069 070 expect(request.getRequestURI()).andReturn("/foo/bar/baz"); 071 072 expect(request.getServerPort()).andReturn(2170); 073 074 replay(); 075 076 DecodedRequest dr = new DecodedRequest(request); 077 078 assertEquals("/foo/bar/baz", dr.getRequestURI()); 079 assertEquals("https", dr.getScheme()); 080 assertEquals(2170, dr.getServerPort()); 081 assertEquals("www.flintstone.com", dr.getServerName()); 082 083 verify(); 084 } 085 }