soapuiassertionsjsonpath

SoapUI JSONPath assertion based on count of returned items


In the response to my request I get a JSON list of items

{
"Id": 111,
"Name": "aaa"
},
{
"Id": 222,
"Name": "bbb"
}

I need to assert that in my response there are at least 5 items. When using JSONPath Count I can only check for the exact value using $..*. Unfortunately I don't know the exact number of items returned and as long as more than 5 are in the response everything is ok. Can I do that using any of the JSONPath assertions?


Solution

  • It seems I have to use Script Assertion for that:

    import groovy.json.JsonSlurper
    def ResponseMessage = messageExchange.response.responseContent
    def ParsedMessage = new JsonSlurper().parseText(ResponseMessage)
    assert !(ParsedMessage.isEmpty())
    assert ParsedMessage.Id != null
    assert ParsedMessage.Name != null
    assert ParsedMessage.size() > 30