Spring end to end test including filters and controller method using MockHttpServletRequest

StackOverflow https://stackoverflow.com/questions/22152530

Вопрос

I'm trying to write more of an end to end Spring test that will test my filters and the controller method associated to the given request. I tried RequestMappingHandlerAdapter.handle() but this doesn't call the filters. What classes do I need to use if I have a MockHttpServletRequest with a given path? I don't want to call doFilter followed by handle. Instead, I'm looking to call the code that ultimately calls both of these methods.

EDIT: needs to work in Spring 3.1.

Нет правильного решения

Другие советы

You can register filters when you are setting up your MockMvc using MockMvcBuilders.

MockMvc mockMvc = MockMvcBuilders
          .webAppContextSetup(webApplicationContext)
          .addFilter(filter, urlPatterns);

The javadoc has more details. This method of registering filters is (mock-)equivalent to the web.xml configuration. For example

<filter-mapping>
    <filter-name>filter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top