java - Wiremock Stand alone - How to manipulate response with request data -


i trying implement mocking of post rest call using wiremock standalone server. faced challenge this, suppose post body contains "name" field , value, same value should returned in response of post call. json file looks this:

{ "priority": 1, "request": {     "method": "post",     "urlpath": "/primeslots",     "bodypatterns" : [ {         "matchesjsonpath" : "{ \"things\": [ { \"name\": \"794363\" }]   }"     } ]  },  "response": {     "status": 200,     "body": "{{$.things.name.value}}",     "transformers": ["response-template"]  } } 

so, need value , 794363,but using above approach not able in post response body.

i tried too:

{  "request": {     "method": "post",     "urlpath": "/transform",     "bodypatterns": [         {             "matchesjsonpath" : "$.things[?(@.name =~ /[0-9]+/i)]"         }     ]   },   "response": {     "status": 200,     "body": "{\"responsename\": \"    {{request.body.things.name.value}}\"}",     "headers": {         "content-type": "application/json"     },     "transformers": ["body-transformer"]   }  } 

so question is, if use regex, matches number comes in request, how give same number in response using wiremock standalone json file? thanks.

unfortunately wiremock's response templating transformer doesn't break out request body map necessary you're trying do. request body single string.

the simplest way enable write handlebars helper implements jsonpath or other mechanism querying json document, registering templating transformer when initialise wiremock.

at point i'll write handlebars helpers kind of thing xml , json, won't while.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -