BruceyBandit
BruceyBandit

Reputation: 4324

how to check a DTO exists in a json within SOAP UI Script Assertion?

I have a json that is displayed as below:

{
 "rating": "5"
}

I have done an assertion that the value for 'rating' is not null, but I want to add another assertion that the DTO "rating" exists. How can this be done with script assertion is SOAP UI?

import com.eviware.soapui.support.GroovyUtils
import groovy.json.JsonSlurper 
def response = messageExchange.response.responseContent
def json = new JsonSlurper().parseText(response)

def rating = json.rating
assert json.rating != null

Upvotes: 0

Views: 626

Answers (1)

daggett
daggett

Reputation: 28564

assert json.containsKey('rating')

the class of json object in groovy:

http://docs.groovy-lang.org/2.4.7/html/gapi/groovy/json/internal/LazyMap.html

Upvotes: 1

Related Questions