-
Notifications
You must be signed in to change notification settings - Fork 737
Provide easy way to add context path to sample curl request #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is already possible. As described in the documentation, you should use |
Don't you get a java.lang.IllegalArgumentException: requestURI [/some/resource] does not start with contextPath [/context] Not sure how this should work in practice. |
Did you look at the test that I added? You need to provide a request URI that begins with the context path. Mock MVC is then smart enough to strip off the context path before it figures out which request mapping will handle the request, just as would happen in a real servlet container. In your case, you should set the context path to mockMvc.perform(get("/myapp/some/resource/").contextPath("/myapp"))
.andExpect(status().isOk()).andDo(document("custom-context-path")); You might also like to read the relevant section of the Spring MVC Test documentation. |
Thanks. I did look at the tests you added. What I was missing was adding the context path to the url as well as via contextPath(). Thanks again. |
I have a project named 'myapp'. When I deploy to a web server, the context path is '/myapp'.
Requests to a Controller with a RequestMapping(value="/some/resource") will be accessed with:
The generated snippet will create:
which is only useful for apps deployed to the root context. I don't see an easy way to change this via config. (setting the contextPath on the MockMvc.perform() won't work, because the RequestMapping doesn't include the contextPath).
The text was updated successfully, but these errors were encountered: