Reputation: 14550
I want to test if my controller returns correct redirect (relative / context relative / absolute). How can I test it using spring's mockMVC? can I avoid integration tests with starting server 2 times with different contexts?
Upvotes: 1
Views: 1198
Reputation: 41133
If your handler methods always returns String, the redirection is always relative to current servlet context, or absolute. As specified on Chapter 17.5.3 of Spring Reference:
A logical view name such as redirect:/myapp/some/resource will redirect relative to the current Servlet context, while a name such as redirect:http://myhost.com/some/arbitrary/path will redirect to an absolute URL.
Hence in my opinion it is sufficient to test the returned String has "redirect:" prefix, and check for the "http://" or "https://" prefix.
Upvotes: 1