1

I need to execute POST request with the following preconditions: json has 2 parent concepts with the same concept name, but different properties, like

{
"dictionary": {
 "concept": {
   "c1": {
    "logicalName": "c1",
    "isNull": true
   },
   "c1": {
    "logicalName": "c1",
    "isNull": false
   }
 }
}}

but after post request i observed that 1st concept with json property "isNull": true was removed. But i'm expecting that in this case system will fail with proper error code and shown proper validation message.

i double checked with the regular cURL and the same input json from file - everything looks fine.

Why karate removes 1 block from json input? Could you please advice?

Thank you

1 Answers1

2

This is invalid JSON. If you want Karate to not parse the JSON I guess for a "negative test", please use text.

* url 'https://httpbin.org/anything'
* text body =
"""
{
   "dictionary":{
      "concept":{
         "c1":{
            "logicalName":"c1",
            "isNull":true
         },
         "c1":{
            "logicalName":"c1",
            "isNull":false
         }
      }
   }
}
"""
* header Content-Type = 'application/json'
* request body
* method post

Even though the request log may show "valid" JSON, you can run the above request and see the response "echo" the actual request - which will be what you want.

14:47:03.100 [main] DEBUG com.intuit.karate - response time in milliseconds: 1219
1 < 200
1 < Date: Mon, 12 Jul 2021 09:17:03 GMT
1 < Content-Type: application/json
1 < Content-Length: 871
1 < Connection: keep-alive
1 < Server: gunicorn/19.9.0
1 < Access-Control-Allow-Origin: *
1 < Access-Control-Allow-Credentials: true
{"args":{},"data":"{\n   \"dictionary\":{\n      \"concept\":{\n         \"c1\":{\n            \"logicalName\":\"c1\",\n            \"isNull\":true\n         },\n         \"c1\":{\n            \"logicalName\":\"c1\",\n            \"isNull\":false\n         }\n      }\n   }\n}", "more": "..."}
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    yep! Working as expected in this case.. and also verified that input get trimmed in case when set karate.configure('logPrettyRequest', true); in karate-config.js file Thank you, sir! – Igor Petrenko Jul 12 '21 at 10:08