-
Notifications
You must be signed in to change notification settings - Fork 737
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
Adding Context Path in Spring REST Docs with WebTestClient #944
Comments
I have tried setting the
|
There's no concept of a context path with WebTestClient as context path is a servlet concept. You can configure a I can't really offer any more advice than this as I don't know what you're trying to test (how it is implemented, for example), exactly how you're trying to test it, or why configuring the base path didn't meet your expectations. |
Thank you for your response! I understand that WebTestClient does not have a concept of context paths like servlets do. However, I want to ensure that when the curl requests are generated, they include the context path (e.g., /my-app). The way you've mentioned it over here, this is exactly what I want to achieve with webclient. I'm testing a api : http://localhost:4444/my-app/accounts/{accountId}/users Setup
When I run the test case with If I run the test case with It seems that adding /my-app in the base URL is causing the issue. Is there any way I can include /my-app while still ensuring that the test passes? |
You need to ensure that the path to which you're making a request is handling by one of the application's routes. For example, |
Okay, Could you please give me more details on how to implement custom |
Take a look at String rawPath = request.getUri().getRawPath();
uriBuilder.replacePath("/my-app" + ((rawPath != null) ? rawPath : "")); |
I've opened #945 to track adding some support to REST Docs for this sort of URI pre-processing. I'll close this one as I don't think there's anything more to be done here. |
Thank you ! |
I'm trying to add a context path (e.g., /my-app) to the requests generated by Spring REST Docs when using WebTestClient. Currently, the generated cURL commands do not include the context path:
$ curl 'http://localhost:4444/accounts/123/dummy' -i -X GET
I would like them to reflect the context path, like this:
$ curl 'http://localhost:4444/my-app/accounts/123/dummy' -i -X GET
How can I achieve this?
Reference
Spring REST Docs Issue #135
Thank you!
The text was updated successfully, but these errors were encountered: