Closed wilkinsona closed 8 years ago
I don't really know at this point if it will work out this way but it's a starting point at least for discussing ways to provide a better experience when using Spring MVC Test with Spring Boot applications.
I suppose the MockMvcBuilders#webAppContext setup (backed by DefaultMockMvcBuilder) should bring in much of the auto configuration but things like filters for example aren't picked up. Another route might be to explore whether we can use the MockServletContext to access the Filter registrations made by Boot. The best place to start would be to create a sample and identify a list of things along the lines of what the user did in https://github.com/spring-projects/spring-restdocs/issues/41 but more formally.
Tentatively targeting to 1.3
It might be cool if a MockMvc
instance for the Spring Boot application could also be easily injected similar to @MockBean
.
@rwinch +1. I thought the same thing when I saw what Phil had done with @MockBean
.
+1 - I have an app that could use that feature.
Fixed in bbc91cc03f5df31c1985811d07abe4f9a906355e
Hi Phil,
it is possible to apply springSecurity to the mockMvc anymore?
My custom code before Spring Boot 1.4 was:
MockMvc restMvc = MockMvcBuilders.webAppContextSetup(context)
.apply(springSecurity()).build();
Now MockMvc is autowired and I cannot add this? Or maybe I have overseen anything?
Thanks, Jens
@jgoldhammer You can use a MockMvcBuilderCustomizer
bean
@wilkinsona Thanks for the response. I haven't played with the feature yet, but do we think that Spring Boot could automatically apply(springSecurity())
(if it does not already) if there is a springSecurityFilterChain bean?
As things stand, any Filter
beans in the context will be added to the auto-configured MockMvc
instance. What does springSecurity()
do beyond that?
@wilkinsona Thanks for the response. It also registers testSecurityContext() to ensure that users can leverage features like @WithMockUser
.
@rwinch Thanks. I've opened #5702.
@wilkinsona Thanks!
PS: I'd consider using apply(springSecurity())
as this should cover future use cases (i.e. if we later add other post processors that are necessary).
The idea came from @rstoyanchev while discussing a Spring REST docs issue