-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
MockSpringMvcServlet not respecting @ControllerAdvice NoHandlerFoundException #710
Comments
yes. it may be unrealistic to expect the fake dispatcher servlet to mimic all the edge cases of spring boot. we will take a look at this - but you may be better off ignoring this test in "mock servlet" mode using a tag. marking this ticket as "help wanted" |
moving to project roadmap board: https://github.com/intuit/karate/projects/3#card-22529274 |
@ptrthomas this is also an open issue i guess? shall i pick this up? |
@Nishant-sehgal yes, please go ahead |
released 0.9.5 |
verified fix is good in 0.9.5 after changing the MockSpringMvcServlet file to reflect the changes in the Spring MVC Dispatcher Servlet example link in the MockServlet documentation to this: https://intuit.github.io/karate/karate-mock-servlet/src/test/java/demo/MockSpringMvcServlet.java |
The code to demonstrate this issue is available as a github project here:
https://github.com/jesimone57/spring_boot_rest_examples
Set up
mvn clean compile test
All test pass except for one karate test which tests an endpoint which does not exist for a proper error response. The failing test is ...
Description:
I just added the Karate mock servlet dependency to my project and followed the instructions for making use of it to test all the karate features without the need to run a spring-boot server. All the feature tests passed successfully (49 karate test pass) except for 1.
What failed is a test that checks for a NoHandlerFoundException when an invalid URL is given. The expected response is
This test, of necessity, would depend on the following 2 application properties being set in the test environment (application.properties file)
This is according to the Spring documentation for handling NoHandlerFoundException.
The junit 4 version of this @SpringBootTest passes successfully and may be found in HelloWorldControllerExceptionTest. We get the expected response as given above.
However, the nourl.feature file given as
fails because no NoHandlerFoundException is ever thrown by the mock servlet container upon a request for a non-existent URL. The code for this handler is found in @ControllerAdvice annotated class GlobalExceptionHandler.
I added the following
as specified in the MockConfig from the karate mock servlet demo, but still fails.
What am I missing to make this work. Is this a karate bug or limitation.
Thanks.
The text was updated successfully, but these errors were encountered: