Revision: 1529
Author:   sberlin
Date:     Thu Mar 24 06:43:25 2011
Log: issue 418 - make sure servlet extension works with context paths. thanks to Henning for provided the patches.
http://code.google.com/p/google-guice/source/detail?r=1529

Added:
/trunk/extensions/servlet/test/com/google/inject/servlet/ContextPathTest.java
Modified:
/trunk/extensions/servlet/src/com/google/inject/servlet/FilterDefinition.java /trunk/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java /trunk/extensions/servlet/test/com/google/inject/servlet/ContinuingRequestIntegrationTest.java /trunk/extensions/servlet/test/com/google/inject/servlet/FilterDefinitionTest.java /trunk/extensions/servlet/test/com/google/inject/servlet/FilterDispatchIntegrationTest.java /trunk/extensions/servlet/test/com/google/inject/servlet/FilterPipelineTest.java /trunk/extensions/servlet/test/com/google/inject/servlet/InjectedFilterPipelineTest.java /trunk/extensions/servlet/test/com/google/inject/servlet/MultiModuleDispatchIntegrationTest.java /trunk/extensions/servlet/test/com/google/inject/servlet/ServletDispatchIntegrationTest.java /trunk/extensions/servlet/test/com/google/inject/servlet/VarargsFilterDispatchIntegrationTest.java /trunk/extensions/servlet/test/com/google/inject/servlet/VarargsServletDispatchIntegrationTest.java

=======================================
--- /dev/null
+++ /trunk/extensions/servlet/test/com/google/inject/servlet/ContextPathTest.java Thu Mar 24 06:43:25 2011
@@ -0,0 +1,293 @@
+/**
+ * Copyright (C) 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.inject.servlet;
+
+import static org.easymock.EasyMock.createControl;
+import static org.easymock.EasyMock.expect;
+
+import java.io.IOException;
+
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import junit.framework.TestCase;
+
+import org.easymock.IMocksControl;
+
+import com.google.inject.Guice;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.google.inject.Key;
+import com.google.inject.Scopes;
+import com.google.inject.name.Named;
+import com.google.inject.name.Names;
+
+/** Tests to make sure that servlets with a context path are handled right. */
+public class ContextPathTest extends TestCase {
+
+  @Inject @Named("foo")
+  private TestServlet fooServlet;
+
+  @Inject @Named("bar")
+  private TestServlet barServlet;
+
+  private IMocksControl globalControl;
+  private Injector injector;
+  private ServletContext servletContext;
+  private FilterConfig filterConfig;
+  private GuiceFilter guiceFilter;
+
+  @Override
+  public final void setUp() throws Exception {
+    injector = Guice.createInjector(new ServletModule() {
+      @Override
+      protected void configureServlets() {
+        bind(TestServlet.class).annotatedWith(Names.named("foo"))
+            .to(TestServlet.class).in(Scopes.SINGLETON);
+        bind(TestServlet.class).annotatedWith(Names.named("bar"))
+            .to(TestServlet.class).in(Scopes.SINGLETON);
+ serve("/foo/*").with(Key.get(TestServlet.class, Names.named("foo"))); + serve("/bar/*").with(Key.get(TestServlet.class, Names.named("bar")));
+        // TODO: add a filter(..) call and validate it is correct
+      }
+    });
+    injector.injectMembers(this);
+
+    assertNotNull(fooServlet);
+    assertNotNull(barServlet);
+    assertNotSame(fooServlet, barServlet);
+
+    globalControl = createControl();
+    servletContext = globalControl.createMock(ServletContext.class);
+    filterConfig = globalControl.createMock(FilterConfig.class);
+
+ expect(servletContext.getAttribute(GuiceServletContextListener.INJECTOR_NAME))
+        .andReturn(injector).anyTimes();
+ expect(filterConfig.getServletContext()).andReturn(servletContext).anyTimes();
+
+    globalControl.replay();
+
+    guiceFilter = new GuiceFilter();
+    guiceFilter.init(filterConfig);
+  }
+
+  @Override
+  public final void tearDown() {
+    assertNotNull(fooServlet);
+    assertNotNull(barServlet);
+
+    fooServlet = null;
+    barServlet = null;
+
+    guiceFilter.destroy();
+    guiceFilter = null;
+
+    injector = null;
+
+    filterConfig = null;
+    servletContext = null;
+
+    globalControl.verify();
+  }
+
+  public void testSimple() throws Exception {
+    IMocksControl testControl = createControl();
+    TestFilterChain testFilterChain = new TestFilterChain();
+ HttpServletRequest req = testControl.createMock(HttpServletRequest.class); + HttpServletResponse res = testControl.createMock(HttpServletResponse.class);
+
+    expect(req.getMethod()).andReturn("GET").anyTimes();
+    expect(req.getRequestURI()).andReturn("/bar/foo").anyTimes();
+    expect(req.getServletPath()).andReturn("/bar/foo").anyTimes();
+    expect(req.getContextPath()).andReturn("").anyTimes();
+
+    testControl.replay();
+
+    guiceFilter.doFilter(req, res, testFilterChain);
+
+    assertFalse(testFilterChain.isTriggered());
+    assertFalse(fooServlet.isTriggered());
+    assertTrue(barServlet.isTriggered());
+
+    testControl.verify();
+  }
+
+  //
+  // each of the following "runTest" calls takes three path parameters:
+  //
+  // The value of "getRequestURI()"
+  // The value of "getServletPath()"
+  // The value of "getContextPath()"
+  //
+  // these values have been captured using a filter in Apache Tomcat 6.0.32
+ // and are used for real-world values that a servlet container would send into
+  // the GuiceFilter.
+  //
+  // the remaining three booleans are:
+  //
+  // True if the request gets passed down the filter chain
+  // True if the request hits the "foo" servlet
+  // True if the request hits the "bar" sevlet
+  //
+ // After adjusting the request URI for the web app deployment location, all
+  // calls
+  // should always produce the same result.
+  //
+
+  // ROOT Web app, using Tomcat default servlet
+  public void testRootDefault() throws Exception {
+ // fetching /. Should go up the filter chain (only mappings on /foo/* and /bar/*).
+    runTest("/", "/", "", true, false, false);
+    // fetching /bar/. Should hit the bar servlet
+    runTest("/bar/", "/bar/", "", false, false, true);
+    // fetching /foo/xxx. Should hit the foo servlet
+    runTest("/foo/xxx", "/foo/xxx", "", false, true, false);
+    // fetching /xxx. Should go up the chain
+    runTest("/xxx", "/xxx", "", true, false, false);
+  }
+
+  // ROOT Web app, using explicit backing servlet mounted at /*
+  public void testRootExplicit() throws Exception {
+ // fetching /. Should go up the filter chain (only mappings on /foo/* and /bar/*).
+    runTest("/", "", "", true, false, false);
+    // fetching /bar/. Should hit the bar servlet
+    runTest("/bar/", "", "", false, false, true);
+    // fetching /foo/xxx. Should hit the foo servlet
+    runTest("/foo/xxx", "", "", false, true, false);
+    // fetching /xxx. Should go up the chain
+    runTest("/xxx", "", "", true, false, false);
+  }
+
+  // ROOT Web app, using two backing servlets, mounted at /bar/* and /foo/*
+  public void testRootSpecific() throws Exception {
+ // fetching /. Should go up the filter chain (only mappings on /foo/* and /bar/*).
+    runTest("/", "/", "", true, false, false);
+    // fetching /bar/. Should hit the bar servlet
+    runTest("/bar/", "/bar", "", false, false, true);
+    // fetching /foo/xxx. Should hit the foo servlet
+    runTest("/foo/xxx", "/foo", "", false, true, false);
+    // fetching /xxx. Should go up the chain
+    runTest("/xxx", "/xxx", "", true, false, false);
+  }
+
+  // Web app located at /webtest, using Tomcat default servlet
+  public void testWebtestDefault() throws Exception {
+ // fetching /. Should go up the filter chain (only mappings on /foo/* and /bar/*).
+    runTest("/webtest/", "/", "/webtest", true, false, false);
+    // fetching /bar/. Should hit the bar servlet
+    runTest("/webtest/bar/", "/bar/", "/webtest", false, false, true);
+    // fetching /foo/xxx. Should hit the foo servlet
+ runTest("/webtest/foo/xxx", "/foo/xxx", "/webtest", false, true, false);
+    // fetching /xxx. Should go up the chain
+    runTest("/webtest/xxx", "/xxx", "/webtest", true, false, false);
+  }
+
+ // Web app located at /webtest, using explicit backing servlet mounted at /*
+  public void testWebtestExplicit() throws Exception {
+ // fetching /. Should go up the filter chain (only mappings on /foo/* and /bar/*).
+    runTest("/webtest/", "", "/webtest", true, false, false);
+    // fetching /bar/. Should hit the bar servlet
+    runTest("/webtest/bar/", "", "/webtest", false, false, true);
+    // fetching /foo/xxx. Should hit the foo servlet
+    runTest("/webtest/foo/xxx", "", "/webtest", false, true, false);
+    // fetching /xxx. Should go up the chain
+    runTest("/webtest/xxx", "", "/webtest", true, false, false);
+  }
+
+ // Web app located at /webtest, using two backing servlets, mounted at /bar/*
+  // and /foo/*
+  public void testWebtestSpecific() throws Exception {
+ // fetching /. Should go up the filter chain (only mappings on /foo/* and
+    // /bar/*).
+    runTest("/webtest/", "/", "/webtest", true, false, false);
+    // fetching /bar/. Should hit the bar servlet
+    runTest("/webtest/bar/", "/bar", "/webtest", false, false, true);
+    // fetching /foo/xxx. Should hit the foo servlet
+    runTest("/webtest/foo/xxx", "/foo", "/webtest", false, true, false);
+    // fetching /xxx. Should go up the chain
+    runTest("/webtest/xxx", "/xxx", "/webtest", true, false, false);
+  }
+
+ private void runTest(final String requestURI, final String servletPath, final String contextPath, + final boolean filterResult, final boolean fooResult, final boolean barResult)
+      throws Exception {
+    IMocksControl testControl = createControl();
+
+    barServlet.clear();
+    fooServlet.clear();
+
+    TestFilterChain testFilterChain = new TestFilterChain();
+ HttpServletRequest req = testControl.createMock(HttpServletRequest.class); + HttpServletResponse res = testControl.createMock(HttpServletResponse.class);
+
+    expect(req.getMethod()).andReturn("GET").anyTimes();
+    expect(req.getRequestURI()).andReturn(requestURI).anyTimes();
+    expect(req.getServletPath()).andReturn(servletPath).anyTimes();
+    expect(req.getContextPath()).andReturn(contextPath).anyTimes();
+
+    testControl.replay();
+
+    guiceFilter.doFilter(req, res, testFilterChain);
+
+    assertEquals(filterResult, testFilterChain.isTriggered());
+    assertEquals(fooResult, fooServlet.isTriggered());
+    assertEquals(barResult, barServlet.isTriggered());
+
+    testControl.verify();
+  }
+
+  public static class TestServlet extends HttpServlet {
+    private boolean triggered = false;
+
+    @Override
+    public void doGet(HttpServletRequest req, HttpServletResponse resp) {
+      triggered = true;
+    }
+
+    public boolean isTriggered() {
+      return triggered;
+    }
+
+    public void clear() {
+      triggered = false;
+    }
+  }
+
+  public static class TestFilterChain implements FilterChain {
+    private boolean triggered = false;
+
+ public void doFilter(ServletRequest request, ServletResponse response) throws IOException,
+        ServletException {
+      triggered = true;
+    }
+
+    public boolean isTriggered() {
+      return triggered;
+    }
+
+    public void clear() {
+      triggered = false;
+    }
+  }
+}
=======================================
--- /trunk/extensions/servlet/src/com/google/inject/servlet/FilterDefinition.java Sat Nov 13 06:28:14 2010 +++ /trunk/extensions/servlet/src/com/google/inject/servlet/FilterDefinition.java Thu Mar 24 06:43:25 2011
@@ -156,7 +156,8 @@
ServletResponse servletResponse, FilterChainInvocation filterChainInvocation)
       throws IOException, ServletException {

- final String path = ((HttpServletRequest) servletRequest).getServletPath();
+    final HttpServletRequest request = (HttpServletRequest) servletRequest;
+ final String path = request.getRequestURI().substring(request.getContextPath().length());

     if (shouldFilter(path)) {
       filter.get()
=======================================
--- /trunk/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java Sat Nov 13 06:28:14 2010 +++ /trunk/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java Thu Mar 24 06:43:25 2011
@@ -168,7 +168,10 @@
   public boolean service(ServletRequest servletRequest,
ServletResponse servletResponse) throws IOException, ServletException {

- final boolean serve = shouldServe(((HttpServletRequest) servletRequest).getServletPath());
+    final HttpServletRequest request = (HttpServletRequest) servletRequest;
+ final String path = request.getRequestURI().substring(request.getContextPath().length());
+
+    final boolean serve = shouldServe(path);

     //invocations of the chain end at the first matched servlet
     if (serve) {
@@ -186,7 +189,6 @@
* We need to suppress deprecation coz we use HttpServletRequestWrapper, which implements
    * deprecated API for backwards compatibility.
    */
-  @SuppressWarnings({ "JavaDoc", "deprecation" })
void doService(final ServletRequest servletRequest, ServletResponse servletResponse)
       throws ServletException, IOException {

=======================================
--- /trunk/extensions/servlet/test/com/google/inject/servlet/ContinuingRequestIntegrationTest.java Mon Sep 20 11:25:29 2010 +++ /trunk/extensions/servlet/test/com/google/inject/servlet/ContinuingRequestIntegrationTest.java Thu Mar 24 06:43:25 2011
@@ -118,7 +118,10 @@

     HttpServletRequest request = createMock(HttpServletRequest.class);

-    expect(request.getServletPath()).andReturn("/");
+    expect(request.getRequestURI()).andReturn("/");
+    expect(request.getContextPath())
+        .andReturn("")
+        .anyTimes();
     expect(request.getMethod()).andReturn("GET");

     FilterChain filterChain = createMock(FilterChain.class);
@@ -157,7 +160,11 @@

     HttpServletRequest request = createMock(HttpServletRequest.class);

-    expect(request.getServletPath()).andReturn("/");
+    expect(request.getRequestURI()).andReturn("/");
+    expect(request.getContextPath())
+        .andReturn("")
+        .anyTimes();
+
     expect(request.getMethod()).andReturn("GET");
     FilterChain filterChain = createMock(FilterChain.class);

=======================================
--- /trunk/extensions/servlet/test/com/google/inject/servlet/FilterDefinitionTest.java Sun Aug 22 11:48:23 2010 +++ /trunk/extensions/servlet/test/com/google/inject/servlet/FilterDefinitionTest.java Thu Mar 24 06:43:25 2011
@@ -106,7 +106,10 @@
         .andReturn(mockFilter)
         .anyTimes();

-    expect(request.getServletPath()).andReturn("/index.html");
+    expect(request.getRequestURI()).andReturn("/index.html");
+    expect(request.getContextPath())
+        .andReturn("")
+        .anyTimes();

     replay(injector, binding, request);

@@ -163,7 +166,10 @@
         .andReturn(mockFilter)
         .anyTimes();

-    expect(request.getServletPath()).andReturn("/index.html");
+    expect(request.getRequestURI()).andReturn("/index.html");
+    expect(request.getContextPath())
+        .andReturn("")
+        .anyTimes();

     replay(injector, binding, request);

=======================================
--- /trunk/extensions/servlet/test/com/google/inject/servlet/FilterDispatchIntegrationTest.java Tue Jul 20 19:48:53 2010 +++ /trunk/extensions/servlet/test/com/google/inject/servlet/FilterDispatchIntegrationTest.java Thu Mar 24 06:43:25 2011
@@ -72,12 +72,12 @@
     // create ourselves a mock request with test URI
HttpServletRequest requestMock = control.createMock(HttpServletRequest.class);

-    expect(requestMock.getServletPath())
-            .andReturn("/index.html")
-            .anyTimes();
     expect(requestMock.getRequestURI())
             .andReturn("/index.html")
             .anyTimes();
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();

     requestMock.setAttribute(REQUEST_DISPATCHER_REQUEST, true);
     requestMock.removeAttribute(REQUEST_DISPATCHER_REQUEST);
@@ -128,9 +128,12 @@
     //create ourselves a mock request with test URI
HttpServletRequest requestMock = control.createMock(HttpServletRequest.class);

-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
             .andReturn("/index.xhtml")
             .anyTimes();
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();

     //dispatch request
     FilterChain filterChain = control.createMock(FilterChain.class);
@@ -166,9 +169,12 @@
     //create ourselves a mock request with test URI
HttpServletRequest requestMock = control.createMock(HttpServletRequest.class);

-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
             .andReturn("/index")
             .anyTimes();
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();

     // dispatch request
     FilterChain filterChain = control.createMock(FilterChain.class);
@@ -211,7 +217,7 @@
         throws ServletException, IOException {
       String requestUri = httpServletRequest.getRequestURI();
       processedUris.add(requestUri);
-
+
// If the client is requesting /index.html then we forward to /forwarded.html
       if (FORWARD_FROM.equals(requestUri)) {
         httpServletRequest.getRequestDispatcher(FORWARD_TO)
=======================================
--- /trunk/extensions/servlet/test/com/google/inject/servlet/FilterPipelineTest.java Tue Jul 20 19:48:53 2010 +++ /trunk/extensions/servlet/test/com/google/inject/servlet/FilterPipelineTest.java Thu Mar 24 06:43:25 2011
@@ -70,9 +70,12 @@
         .andReturn(servletContext)
         .once();

-    expect(request.getServletPath())
+    expect(request.getRequestURI())
         .andReturn("/public/login.jsp")
         .anyTimes();
+    expect(request.getContextPath())
+        .andReturn("")
+        .anyTimes();

     //at the end, proceed down webapp's normal filter chain
proceedingFilterChain.doFilter(isA(HttpServletRequest.class), (ServletResponse) isNull());
=======================================
--- /trunk/extensions/servlet/test/com/google/inject/servlet/InjectedFilterPipelineTest.java Sat Jul 31 15:13:21 2010 +++ /trunk/extensions/servlet/test/com/google/inject/servlet/InjectedFilterPipelineTest.java Thu Mar 24 06:43:25 2011
@@ -85,9 +85,12 @@
         .andReturn(servletContext)
         .once();

-    expect(request.getServletPath())
+    expect(request.getRequestURI())
.andReturn("/non-jsp/login.html") // use a path that will fail in injector2
         .anyTimes();
+    expect(request.getContextPath())
+        .andReturn("")
+        .anyTimes();

     //at the end, proceed down webapp's normal filter chain
proceedingFilterChain.doFilter(isA(HttpServletRequest.class), (ServletResponse) isNull());
@@ -109,7 +112,7 @@



-
+
     // reset mocks and run them against the other injector
     reset(filterConfig, servletContext, request, proceedingFilterChain);

@@ -121,14 +124,17 @@
     expect(filterConfig.getServletContext())
         .andReturn(servletContext)
         .once();
-    expect(request.getServletPath())
+    expect(request.getRequestURI())
.andReturn("/public/login/login.jsp") // use a path that will fail in injector1
             .anyTimes();
+    expect(request.getContextPath())
+        .andReturn("")
+        .anyTimes();

     //at the end, proceed down webapp's normal filter chain
proceedingFilterChain2.doFilter(isA(HttpServletRequest.class), (ServletResponse) isNull());
     expectLastCall().once();
-
+
     // Never fire on this pipeline
replay(filterConfig, servletContext, request, proceedingFilterChain2, proceedingFilterChain);

=======================================
--- /trunk/extensions/servlet/test/com/google/inject/servlet/MultiModuleDispatchIntegrationTest.java Tue Jul 20 19:48:53 2010 +++ /trunk/extensions/servlet/test/com/google/inject/servlet/MultiModuleDispatchIntegrationTest.java Thu Mar 24 06:43:25 2011
@@ -72,9 +72,12 @@
     //create ourselves a mock request with test URI
     HttpServletRequest requestMock = createMock(HttpServletRequest.class);

-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
             .andReturn("/index.html")
             .anyTimes();
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();

     //dispatch request
     replay(requestMock);
=======================================
--- /trunk/extensions/servlet/test/com/google/inject/servlet/ServletDispatchIntegrationTest.java Tue Dec 29 17:05:45 2009 +++ /trunk/extensions/servlet/test/com/google/inject/servlet/ServletDispatchIntegrationTest.java Thu Mar 24 06:43:25 2011
@@ -81,9 +81,12 @@
     //create ourselves a mock request with test URI
     HttpServletRequest requestMock = createMock(HttpServletRequest.class);

-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
         .andReturn("/index.html")
         .times(1);
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();

     //dispatch request
     replay(requestMock);
@@ -125,9 +128,12 @@
     //create ourselves a mock request with test URI
     HttpServletRequest requestMock = createMock(HttpServletRequest.class);

-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
         .andReturn("/index.html")
         .times(2);
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();

     //dispatch request
     replay(requestMock);
@@ -233,9 +239,12 @@

final HttpServletRequest requestMock = createMock(HttpServletRequest.class); HttpServletResponse responseMock = createMock(HttpServletResponse.class);
-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
         .andReturn("/")
         .anyTimes();
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();

     requestMock.setAttribute(REQUEST_DISPATCHER_REQUEST, true);
expect(requestMock.getAttribute(REQUEST_DISPATCHER_REQUEST)).andReturn(true);
=======================================
--- /trunk/extensions/servlet/test/com/google/inject/servlet/VarargsFilterDispatchIntegrationTest.java Tue Jul 20 19:48:53 2010 +++ /trunk/extensions/servlet/test/com/google/inject/servlet/VarargsFilterDispatchIntegrationTest.java Thu Mar 24 06:43:25 2011
@@ -62,9 +62,12 @@
     //create ourselves a mock request with test URI
     HttpServletRequest requestMock = createMock(HttpServletRequest.class);

-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
             .andReturn("/index.html")
             .anyTimes();
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();

     //dispatch request
     replay(requestMock);
@@ -98,9 +101,12 @@
     //create ourselves a mock request with test URI
     HttpServletRequest requestMock = createMock(HttpServletRequest.class);

-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
             .andReturn("/index.xhtml")
             .anyTimes();
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();

     //dispatch request
     replay(requestMock);
@@ -135,9 +141,12 @@
     //create ourselves a mock request with test URI
     HttpServletRequest requestMock = createMock(HttpServletRequest.class);

-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
             .andReturn("/index")
             .anyTimes();
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();

     //dispatch request
     replay(requestMock);
=======================================
--- /trunk/extensions/servlet/test/com/google/inject/servlet/VarargsServletDispatchIntegrationTest.java Sat Feb 14 02:28:08 2009 +++ /trunk/extensions/servlet/test/com/google/inject/servlet/VarargsServletDispatchIntegrationTest.java Thu Mar 24 06:43:25 2011
@@ -75,9 +75,12 @@
     //create ourselves a mock request with test URI
     HttpServletRequest requestMock = createMock(HttpServletRequest.class);

-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
         .andReturn("/index.html")
         .times(1);
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();

     //dispatch request
     replay(requestMock);
@@ -112,9 +115,12 @@
     //create ourselves a mock request with test URI
     HttpServletRequest requestMock = createMock(HttpServletRequest.class);

-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
         .andReturn("/index.html")
         .times(3);
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();

     //dispatch request
     replay(requestMock);
@@ -152,9 +158,12 @@
     //create ourselves a mock request with test URI
     HttpServletRequest requestMock = createMock(HttpServletRequest.class);

-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
         .andReturn("/index.html")
         .times(2);
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();

     //dispatch request
     replay(requestMock);

--
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice-dev?hl=en.

Reply via email to