Question

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.

No correct solution

OTHER TIPS

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top