fork(1) download
  1. //commented below as we are testing with fixed data
  2. //def jsonText = context.response
  3.  
  4. def jsonText = '''{
  5. "cars": [
  6. {
  7. "name" : "Jetta",
  8. "brand" : "Volkswagen"
  9. },
  10. {
  11. "name" : "Polo GT",
  12. "brand" : "Volkswagen"
  13. },
  14. {
  15. "name" : "i30",
  16. "brand" : "Hyundai"
  17. }
  18. ]
  19. }'''
  20.  
  21.  
  22. def brandToCheck = 'Volkswagen'
  23. def expectedCars = ['Jetta', 'Polo GT']
  24.  
  25.  
  26.  
  27. def cars = new groovy.json.JsonSlurper().parseText(jsonText).cars
  28.  
  29. assert expectedCars == cars.findAll { it.brand == brandToCheck }.name, 'Not matching the expected cars'
  30.  
  31.  
  32. //User want to validate brand of i30
  33.  
  34. assert 'Hyundai' == cars.find { it.name == 'i30'}.brand, 'Not matching the brand for i30 car'
Success #stdin #stdout 1.83s 134544KB
stdin
Standard input is empty
stdout
Standard output is empty