Hi I am trying to run the below feature fails. I suspect Patch method (content-type 'application/json-patch+json') might be the root cause for the issue.
Project link -
https://github.com/vidhya03/http-patch-jax-rs
IDE error log -
surefire-reports.zip
Please let me know if you need to reproduce this issue
First - thanks for being one of the very few who actually provides proper information to replicate an error. I wish more of the world was like you !
Now, you are doing a couple of things wrong. You need to set headers BEFORE you fire the method, this is clearly mentioned in the documentation.
By the way, there is no need to set Content-Type 90% of the time as Karate will auto-detect and send it automatically.
So here is your final working test. The last step needs the Accept header to be set, else the server gets confused with the PATCH strange Content-Type. Karate is working perfectly.
Background:
* url 'http://http-patch-vidhya.1d35.starter-us-east-1.openshiftapps.com/v1'
Scenario: Test for PUT person
Given path 'person'
And request {"name":"Vidhya","age":29,"locale":"en","twitter":"VidhyaJava","email":"[email protected]"}
When method put
Then status 204
Scenario: Navigate to Get person
Given path 'person'
When method get
Then status 200
And match response == {"name":"Vidhya","age":29,"locale":"en","twitter":"VidhyaJava","email":"[email protected]"}
Scenario: Test for POST person
Given path 'person'
And request {"name":"Vidhya","age":29,"locale":"en","twitter":"VidhyaJava","email":"[email protected]"}
When method post
Then status 204
Scenario: Test for PATCH METHOD
Given path 'person'
And request [{ "op": "remove", "path": "/email" }, {"op":"replace", "path": "/name", "value": "Vidhyadharan Deivamani" }]
And header Content-Type = 'application/json-patch+json'
And header Accept = 'application/json'
When method patch
Then status 200
Thanks a lot Peeter Thoma @ptrthomas . You're really a community guy!. Cheers.
Most helpful comment
First - thanks for being one of the very few who actually provides proper information to replicate an error. I wish more of the world was like you !
Now, you are doing a couple of things wrong. You need to set headers BEFORE you fire the
method, this is clearly mentioned in the documentation.By the way, there is no need to set
Content-Type90% of the time as Karate will auto-detect and send it automatically.So here is your final working test. The last step needs the
Acceptheader to be set, else the server gets confused with thePATCHstrangeContent-Type. Karate is working perfectly.