本文整理了Java中org.springframework.test.web.servlet.MockMvc.getDispatcherServlet()
方法的一些代码示例,展示了MockMvc.getDispatcherServlet()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MockMvc.getDispatcherServlet()
方法的具体详情如下:
包路径:org.springframework.test.web.servlet.MockMvc
类名称:MockMvc
方法名:getDispatcherServlet
[英]Return the underlying DispatcherServlet instance that this MockMvc was initialized with.
This is intended for use in custom request processing scenario where a request handling component happens to delegate to the DispatcherServletat runtime and therefore needs to be injected with it.
For most processing scenarios, simply use MockMvc#perform, or if you need to configure the DispatcherServlet, provide a DispatcherServletCustomizer to the MockMvcBuilder.
[中]返回初始化此MockMvc的基础DispatcherServlet实例。
这是为了在自定义请求处理场景中使用,在该场景中,请求处理组件恰好在运行时委托给DispatcherServlet,因此需要注入它。
对于大多数处理场景,只需使用MockMvc#perform,或者如果需要配置DispatcherServlet,请为MockMvcBuilder提供DispatcherServletCustomizer。
代码示例来源:origin: spring-projects/spring-security
@Test
public void requestWhenCreateSessionIsSetToIfRequiredThenCreatesSessionOnLoginChallenge()
throws Exception {
this.spring.configLocations(this.xml("CreateSessionIfRequired")).autowire();
ServletContext servletContext = this.mvc.getDispatcherServlet().getServletContext();
MockHttpServletRequest request = get("/auth").buildRequest(servletContext);
MockHttpServletResponse response = request(request, this.spring.getContext());
assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_MOVED_TEMPORARILY);
assertThat(request.getSession(false)).isNotNull();
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void requestWhenCreateSessionIsSetToIfRequiredThenDoesNotCreateSessionOnPublicInvocation()
throws Exception {
this.spring.configLocations(this.xml("CreateSessionIfRequired")).autowire();
ServletContext servletContext = this.mvc.getDispatcherServlet().getServletContext();
MockHttpServletRequest request = get("/").buildRequest(servletContext);
MockHttpServletResponse response = request(request, this.spring.getContext());
assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
assertThat(request.getSession(false)).isNull();
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void requestWhenCreateSessionIsSetToIfRequiredThenCreatesSessionOnLogin()
throws Exception {
this.spring.configLocations(this.xml("CreateSessionIfRequired")).autowire();
ServletContext servletContext = this.mvc.getDispatcherServlet().getServletContext();
MockHttpServletRequest request = post("/login")
.param("username", "user")
.param("password", "password")
.buildRequest(servletContext);
request = csrf().postProcessRequest(request);
MockHttpServletResponse response = request(request, this.spring.getContext());
assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_MOVED_TEMPORARILY);
assertThat(request.getSession(false)).isNotNull();
}
代码示例来源:origin: org.springframework.boot/spring-boot-test-autoconfigure
@Bean
@ConditionalOnMissingBean
public DispatcherServlet dispatcherServlet(MockMvc mockMvc) {
return mockMvc.getDispatcherServlet();
}
内容来源于网络,如有侵权,请联系作者删除!