How to Assert values sent in Request Body at Rest response?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017
08:21 AM
04-27-2017
08:21 AM
How to Assert values sent in Request Body at Rest response?
Hi I am trying to make an assertion of the request body I am sending in a PUT method on the response of a GET method in another step.
Request body sent in PUT method:
{
"storeId" : "0010",
"registerNumber" : "0012"
}
Json response in GET method:
{
"PackageId": "188800120412201723609318",
"storeId" : "0010",
"registerNumber" : "0012"
"registerNumber" : "0012"
"lineId": "01"
"createdTimestamp": "04-19-2017 3:22 PM Wed UTC"
}
How can I map each node on the JSON (storeId , registerNumber ) sent in the request body at the JSON response to the same
Thanks!
SOAPUI NG 1.9
Kind regards,
Pedro
Labels:
- Labels:
-
Assertions
1 REPLY 1
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017
11:17 AM
04-27-2017
11:17 AM
Script Assertion can be used to achieve the same and below is script:
assert context.rawRequest, 'Request is empty or null' assert context.response, 'Response is empty or null' //Closure to get the required data from json def getDataMap = { data, list -> def json = new groovy.json.JsonSlurper().parseText(data) json.inject([:]) {m, key, value -> if(key in list) m[key] = value;m } } def desiredKeys = ['storeId', 'registerNumber'] def reqestMap = getDataMap(context.rawRequest, desiredKeys) def responseMap = getDataMap(context.response, desiredKeys) println "Request data : $reqestMap" println "Response data : $responseMap" assert reqestMap == responseMap, 'Response data is not matching with request data'
The above one uses dynamic request and response.
Here is the script that you can try online quickly for your fixed data and see it working.
Regards,
Rao.
