BeHappy BeHappy - 5 months ago 91
JSON Question

How to verify JSON output with RestFixture using googleapis

See below my code, it is not executing. What am I missing here?

start slim
!path C:\Fitnesse\RestFixture\lib\*.jar
!path C:\Fitnesse\RestFixture\lib\smartrics-RestFixture-3.0.jar
!define expectedReturnHeaders {Content-Length : [\d]+
Content-Type : application/json }
|!-Table:smartrics.rest.fitnesse.fixture.RestFixture-! | https://www.googleapis.com/books/v1/volumes?q=isbn:0735619670|
|GET| Content-Type : application/json |jsonbody.items[0].id=="QnghAQAAIAAJ"


I am getting error as

jsonbody.items.id=="QnghAQAAIAAJ"

java.lang.IllegalArgumentException: Cannot evaluate 'jsonbody.items.id=="QnghAQAAIAAJ"' in {
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Required parameter: q",
"locationType": "parameter",
"location": "q"
}
],
"code": 400,
"message": "Required parameter: q"
}
}

Answer

sample code

|!-    Table:smartrics.rest.fitnesse.fixture.RestFixture-!|http://maps.googleapis.com/maps/api/geocode/json|
|setHeader              |!-Accept: application/json-!                    |
|GET                    |?address=1600+Amphitheatre+Parkway   |200   |      |!-/* javascript */
result = false;
var addr = jsonbody.results[0].address_components;
for (i in addr) {
   if (addr[i].types[0]==='route') {
     if (addr[i].long_name==='Amphitheatre Parkway') {
        result = true;
    }
 }
}
result;
 -!|
Comments