org.springframework.test.web.servlet.MockMvc.setDefaultRequest()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(3.6k)|赞(0)|评价(0)|浏览(88)

本文整理了Java中org.springframework.test.web.servlet.MockMvc.setDefaultRequest()方法的一些代码示例,展示了MockMvc.setDefaultRequest()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MockMvc.setDefaultRequest()方法的具体详情如下:
包路径:org.springframework.test.web.servlet.MockMvc
类名称:MockMvc
方法名:setDefaultRequest

MockMvc.setDefaultRequest介绍

[英]A default request builder merged into every performed request.
[中]默认请求生成器合并到每个执行的请求中。

代码示例

代码示例来源:origin: spring-projects/spring-framework

protected final MockMvc createMockMvc(Filter[] filters, MockServletConfig servletConfig,
    WebApplicationContext webAppContext, @Nullable RequestBuilder defaultRequestBuilder,
    List<ResultMatcher> globalResultMatchers, List<ResultHandler> globalResultHandlers,
    @Nullable List<DispatcherServletCustomizer> dispatcherServletCustomizers) {
  TestDispatcherServlet dispatcherServlet = new TestDispatcherServlet(webAppContext);
  if (dispatcherServletCustomizers != null) {
    for (DispatcherServletCustomizer customizers : dispatcherServletCustomizers) {
      customizers.customize(dispatcherServlet);
    }
  }
  try {
    dispatcherServlet.init(servletConfig);
  }
  catch (ServletException ex) {
    // should never happen..
    throw new MockMvcBuildException("Failed to initialize TestDispatcherServlet", ex);
  }
  MockMvc mockMvc = new MockMvc(dispatcherServlet, filters);
  mockMvc.setDefaultRequest(defaultRequestBuilder);
  mockMvc.setGlobalResultMatchers(globalResultMatchers);
  mockMvc.setGlobalResultHandlers(globalResultHandlers);
  return mockMvc;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-test

protected final MockMvc createMockMvc(Filter[] filters, MockServletConfig servletConfig,
    WebApplicationContext webAppContext, @Nullable RequestBuilder defaultRequestBuilder,
    List<ResultMatcher> globalResultMatchers, List<ResultHandler> globalResultHandlers,
    @Nullable List<DispatcherServletCustomizer> dispatcherServletCustomizers) {
  TestDispatcherServlet dispatcherServlet = new TestDispatcherServlet(webAppContext);
  if (dispatcherServletCustomizers != null) {
    for (DispatcherServletCustomizer customizers : dispatcherServletCustomizers) {
      customizers.customize(dispatcherServlet);
    }
  }
  try {
    dispatcherServlet.init(servletConfig);
  }
  catch (ServletException ex) {
    // should never happen..
    throw new MockMvcBuildException("Failed to initialize TestDispatcherServlet", ex);
  }
  MockMvc mockMvc = new MockMvc(dispatcherServlet, filters);
  mockMvc.setDefaultRequest(defaultRequestBuilder);
  mockMvc.setGlobalResultMatchers(globalResultMatchers);
  mockMvc.setGlobalResultHandlers(globalResultHandlers);
  return mockMvc;
}

代码示例来源:origin: apache/servicemix-bundles

protected final MockMvc createMockMvc(Filter[] filters, MockServletConfig servletConfig,
    WebApplicationContext webAppContext, RequestBuilder defaultRequestBuilder,
    List<ResultMatcher> globalResultMatchers, List<ResultHandler> globalResultHandlers,
    List<DispatcherServletCustomizer> dispatcherServletCustomizers) {
  ServletContext servletContext = webAppContext.getServletContext();
  TestDispatcherServlet dispatcherServlet = new TestDispatcherServlet(webAppContext);
  if (dispatcherServletCustomizers != null) {
    for (DispatcherServletCustomizer customizers : dispatcherServletCustomizers) {
      customizers.customize(dispatcherServlet);
    }
  }
  try {
    dispatcherServlet.init(servletConfig);
  }
  catch (ServletException ex) {
    // should never happen..
    throw new MockMvcBuildException("Failed to initialize TestDispatcherServlet", ex);
  }
  MockMvc mockMvc = new MockMvc(dispatcherServlet, filters, servletContext);
  mockMvc.setDefaultRequest(defaultRequestBuilder);
  mockMvc.setGlobalResultMatchers(globalResultMatchers);
  mockMvc.setGlobalResultHandlers(globalResultHandlers);
  return mockMvc;
}

相关文章