문제

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