1 15 package org.apache.tapestry.request; 16 17 import java.io.IOException ; 18 19 import javax.servlet.ServletException ; 20 import javax.servlet.http.HttpServletRequest ; 21 import javax.servlet.http.HttpServletResponse ; 22 23 import org.apache.hivemind.test.HiveMindTestCase; 24 import org.apache.tapestry.Tapestry; 25 import org.apache.tapestry.services.ServletRequestServicer; 26 import org.apache.tapestry.spec.ILibrarySpecification; 27 import org.easymock.MockControl; 28 29 35 public class TestDecodedRequestInjector extends HiveMindTestCase 36 { 37 private static class ServicerFixture implements ServletRequestServicer 38 { 39 HttpServletRequest _request; 40 41 public void service(HttpServletRequest request, HttpServletResponse response) 42 throws IOException , ServletException 43 { 44 _request = request; 45 } 46 } 47 48 private HttpServletRequest newRequest() 49 { 50 return (HttpServletRequest ) newMock(HttpServletRequest .class); 51 } 52 53 private HttpServletResponse newResponse() 54 { 55 return (HttpServletResponse ) newMock(HttpServletResponse .class); 56 } 57 58 private ILibrarySpecification newSpec(boolean exists, IRequestDecoder decoder) 59 { 60 MockControl control = newControl(ILibrarySpecification.class); 61 ILibrarySpecification spec = (ILibrarySpecification) control.getMock(); 62 63 spec.checkExtension(Tapestry.REQUEST_DECODER_EXTENSION_NAME); 64 control.setReturnValue(exists); 65 66 if (exists) 67 { 68 spec.getExtension(Tapestry.REQUEST_DECODER_EXTENSION_NAME, IRequestDecoder.class); 69 control.setReturnValue(decoder); 70 } 71 72 return spec; 73 } 74 75 public void testNoExtension() throws Exception 76 { 77 HttpServletRequest request = newRequest(); 78 HttpServletResponse response = newResponse(); 79 ILibrarySpecification spec = newSpec(false, null); 80 81 ServletRequestServicer servicer = (ServletRequestServicer) newMock(ServletRequestServicer.class); 82 83 servicer.service(request, response); 84 85 replayControls(); 86 87 DecodedRequestInjector dri = new DecodedRequestInjector(); 88 89 dri.setApplicationSpecification(spec); 90 dri.initializeService(); 91 92 dri.service(request, response, servicer); 93 94 verifyControls(); 95 } 96 97 public void testWithExtension() throws Exception 98 { 99 HttpServletRequest request = newRequest(); 100 HttpServletResponse response = newResponse(); 101 102 MockControl decoderc = newControl(IRequestDecoder.class); 103 IRequestDecoder decoder = (IRequestDecoder) decoderc.getMock(); 104 ILibrarySpecification spec = newSpec(true, decoder); 105 106 ServicerFixture servicer = new ServicerFixture(); 107 108 DecodedRequest decoded = new DecodedRequest(); 109 decoded.setRequestURI("/foo/bar/baz"); 110 111 decoder.decodeRequest(request); 112 decoderc.setReturnValue(decoded); 113 114 replayControls(); 115 116 DecodedRequestInjector dri = new DecodedRequestInjector(); 117 118 dri.setApplicationSpecification(spec); 119 dri.initializeService(); 120 121 dri.service(request, response, servicer); 122 123 125 assertEquals("/foo/bar/baz", servicer._request.getRequestURI()); 126 127 verifyControls(); 128 } 129 } | Popular Tags |