I'm currently writing some tests in ReadyAPI to test a new API that we are building. The API will return JSON in the following format:
{
"testJSON" : [
{
"test1" : "111",
"test2" : "ABC"
},
{
"test1" : "222",
"test2" : "DEF"
}
]
}
I have added the following Groovy code that breaks down the JSON and lists each value:
import groovy.json.JsonSlurper
def jsonResp = context.expand( '${GetTest#Response}' )
def jsonElements = new JsonSlurper().parseText(jsonResp)
for ( value in jsonElements.testInput ) {
value.each{
log.info "${it.key}:${it.value}"
}
}
What I am trying to do is to take this JSON response and compare it to a pre-defined list of data (using a Data Source within ReadyAPI). This data source will contain a column titled 'test1' and a column titled 'test2' -these will contain all the values expected for each object. So we would need to ensure that each test1 value from the datasource is displayed in the response JSON. And we'd also like to confirm that for each 'test1' we get the correct corresponding 'test2'.
So in example above, we'd want to prove that the response contained 'test1' values of 111 and 222, and that for 111 we got a 'test2' value of ABC etc.
The example above is a simplistic view of our new API and in reality it will contain a much larger number of fields and a lot more responses. So ideally, I don't want to have to hard code specific values within the Groovy script - which is why I'm trying to use a data sheet.
Has anyone had any experience of this sort of thing and can make any suggestions?
Thanks in advance for your help, please let me know if you need any more information.
Cheers, Matt