Closed jesimone57 closed 5 years ago
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: `Results :
Tests in error: nourl.feature:11 - path: $['content-type'][0], actual: null, expected: 'application/json', reason: actual value is not a string
Tests run: 72, Failures: 0, Errors: 1, Skipped: 1`
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 (28 of them) except for 1.
What failed is a test that checks for a NoHandlerFoundException when an invalid URL is given. The expected response is
{ method: "GET", status_code: 404, uri_path: "/hello", error_message: "The URL you have reached is not in service at this time", errors: [ ] }
This test, of necessity, would depend on the following 2 application properties being set in the test environment (application.properties file)
# exception handling (see GlobalExceptionHandler handleNoHandlerFoundException method) spring.mvc.throw-exception-if-no-handler-found=true spring.resources.add-mappings=false
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
`Feature: No URLfound proper error response
Background:
configure lowerCaseResponseHeaders = true
Scenario: Invalid URL response Given path '/hello' When method get Then status 404 And match header content-type contains 'application/json' And match header content-type contains 'charset=utf-8' And match response.status_code == 404 And match response.method == 'GET' And match response.error_message == 'The URL you have reached is not in service at this time' And match response.errors == '#[]'`
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
@Configuration @EnableAutoConfiguration @PropertySource("classpath:application.properties")
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.
@ptrthomas please accept my apology for taking so long to write this up.
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: `Results :
Tests in error: nourl.feature:11 - path: $['content-type'][0], actual: null, expected: 'application/json', reason: actual value is not a string
Tests run: 72, Failures: 0, Errors: 1, Skipped: 1`
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 (28 of them) except for 1.
What failed is a test that checks for a NoHandlerFoundException when an invalid URL is given. The expected response is
{ method: "GET", status_code: 404, uri_path: "/hello", error_message: "The URL you have reached is not in service at this time", errors: [ ] }
This test, of necessity, would depend on the following 2 application properties being set in the test environment (application.properties file)
# exception handling (see GlobalExceptionHandler handleNoHandlerFoundException method) spring.mvc.throw-exception-if-no-handler-found=true spring.resources.add-mappings=false
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
`Feature: No URLfound proper error response
Background:
configure lowerCaseResponseHeaders = true
Scenario: Invalid URL response Given path '/hello' When method get Then status 404 And match header content-type contains 'application/json' And match header content-type contains 'charset=utf-8' And match response.status_code == 404 And match response.method == 'GET' And match response.error_message == 'The URL you have reached is not in service at this time' And match response.errors == '#[]'`
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
@Configuration @EnableAutoConfiguration @PropertySource("classpath:application.properties")
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.