Browse Source

Getter for DispatcherSerlvet in MockMvc

Issue: SPR-16924
pull/1856/head
Rossen Stoyanchev 7 years ago
parent
commit
a31204938a
  1. 21
      spring-test/src/main/java/org/springframework/test/web/servlet/MockMvc.java

21
spring-test/src/main/java/org/springframework/test/web/servlet/MockMvc.java

@ -26,6 +26,8 @@ import javax.servlet.ServletResponse; @@ -26,6 +26,8 @@ import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import org.apache.tools.ant.dispatch.Dispatchable;
import org.springframework.beans.Mergeable;
import org.springframework.lang.Nullable;
import org.springframework.mock.web.MockFilterChain;
@ -35,6 +37,7 @@ import org.springframework.util.Assert; @@ -35,6 +37,7 @@ import org.springframework.util.Assert;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.DispatcherServlet;
/**
* <strong>Main entry point for server-side Spring MVC test support.</strong>
@ -122,6 +125,24 @@ public final class MockMvc { @@ -122,6 +125,24 @@ public final class MockMvc {
this.defaultResultHandlers = resultHandlers;
}
/**
* Return the underlying {@link DispatcherServlet} instance that this
* {@code MockMvc} was initialized with.
* <p>This is intended for use in custom request processing scenario where
* a request handling component happens to delegate to the
* {@code DispatcherServlet} at runtime and therefore needs to be injected
* with it.
* <p>For most processing scenarios, simply use {@link MockMvc#perform}, or
* if you need to configure the {@code DispatcherServlet}, provide a
* {@link DispatcherServletCustomizer} to the {@code MockMvcBuilder}.
* @since 5.1
*/
public DispatcherServlet getDispatcherServlet() {
return this.servlet;
}
/**
* Perform a request and return a type that allows chaining further
* actions, such as asserting expectations, on the result.

Loading…
Cancel
Save