Karate: Running karate with patch method fails

Created on 29 Dec 2017  路  2Comments  路  Source: intuit/karate

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.

  1. feature - https://github.com/vidhya03/http-patch-jax-rs/blob/master/src/test/java/com/labkit/test/personapi/PersonApi.feature

  2. Project link -
    https://github.com/vidhya03/http-patch-jax-rs

  3. IDE error log -
    surefire-reports.zip

Please let me know if you need to reproduce this issue

question

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-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

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

76creates picture 76creates  路  3Comments

ianrenauld picture ianrenauld  路  4Comments

hascode picture hascode  路  3Comments

mhavilah picture mhavilah  路  4Comments

ptrthomas picture ptrthomas  路  5Comments