Forum Discussion
JHunt
Community Hero
I had to tidy up your JSON for it to properly be parsed by SoapUI.
{ "id": "XYZ", "errordetails": null, "statuscode": 200, "message": null, "data": [ { "key1": 1294, "key2": [ { "sub-key1": 0, "sub-key2": 2360 }, { "sub-key3": 0, "sub-key4": 2820 } ], "key3": true, "key4": "3X2" }, { "Key1": 1294, "key2": [ { "sub-key1": 0, "sub-key2": 2360 }, { "sub-key3": 0, "sub-key4": 2820 } ], "key3": true, "key4": "3X2" } ] }
Here's my solution using a script assertion. It's probably a very round-about way of doing it. But it works.
def expected = [
"key1",
"key2",
"key2/sub-key1",
"key2/sub-key2",
"key2/sub-key3",
"key2/sub-key4",
"key3",
"key4"
]
def holder = new com.eviware.soapui.support.XmlHolder(messageExchange.responseContentAsXml)
def exists = { it -> holder["count(//*:data//*:${it.replace("/", "//*:")})"].toString().toInteger() > 0 }
expected.each {key -> assert exists(key) }
nkpalli
7 years agoContributor
small clarification needed ,
Looks like syntax provided in below sample is used to XML nodes right? since the sample i send is a Json is there any corresponding code to read the Json nodes?
JHunt wrote:I had to tidy up your JSON for it to properly be parsed by SoapUI.
{ "id": "XYZ", "errordetails": null, "statuscode": 200, "message": null, "data": [ { "key1": 1294, "key2": [ { "sub-key1": 0, "sub-key2": 2360 }, { "sub-key3": 0, "sub-key4": 2820 } ], "key3": true, "key4": "3X2" }, { "Key1": 1294, "key2": [ { "sub-key1": 0, "sub-key2": 2360 }, { "sub-key3": 0, "sub-key4": 2820 } ], "key3": true, "key4": "3X2" } ] }Here's my solution using a script assertion. It's probably a very round-about way of doing it. But it works.
def expected = [
"key1",
"key2",
"key2/sub-key1",
"key2/sub-key2",
"key2/sub-key3",
"key2/sub-key4",
"key3",
"key4"
]
def holder = new com.eviware.soapui.support.XmlHolder(messageExchange.responseContentAsXml)
def exists = { it -> holder["count(//*:data//*:${it.replace("/", "//*:")})"].toString().toInteger() > 0 }
expected.each {key -> assert exists(key) }
def holder = new com.eviware.soapui.support.XmlHolder(messageExchange.responseContentAsXml)
Related Content
- 3 years ago
- 5 years ago
Recent Discussions
- 15 years ago