Is there any way of testing the functionality of a forward:/
view being returned from a Spring MVC controller in a JUnit test?
I'm using the MockMvc
functionality from Spring 3.2 and my controller under certain circumstances forwards to another (by means of returning a view name of forward:/pathHandledByController
).
It'd be great to be able to assert that when this forwarding has taken place, all the @ModelAttribute
s from the second controller are applied and everything processes properly. Unfortunately MockMvc
only lets me assert that the view name returned started with forward:/
.
Is there any way I can test this without spinning up the whole web-app in something like Jetty? I've got lots of services plumbed into the MVC application, how would I create a web-app that uses separate Spring config (from src/test/resources
) with mocks of these services?
You can use forwardedUrl
matcher:
mockMvc.perform(get("/controller/path"))
.andExpect(forwardedUrl("/forwarded/url"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With