I have seen something unusual with my SOAP UI script. I just want to perform an assertion that the data with is correct so I have written this code beLow:
import com.eviware.soapui.support.GroovyUtils
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
def response = messageExchange.response.responseContent
def json = new JsonSlurper().parseText(response)
def jsonFormat = (response).toString()
def policies = [
[x: 28, xxx: 41, xxxxx: 1, name: 'Individual 18-50', aaa: true],
[x: 31, xxx: 41, xxxxx: 1, name: 'Individual 51-60', aaa: true],
[x: 34, xxx: 41, xxxxx: 1, name: 'Individual 61-75', aaa: true],
[x: 37, xxx: 41, xxxxx: 1, name: 'Individual 76-85', aaa: false]
]
log.warn json.policies
log.error policies
assert json.policies == policies
When I look at the log.warn and log.error info, it displays the json response in the incorrect order as it display 'isActive' field first.
log.warn json.policies displays this:
[{aaa=true, xx=28, xxxxx=1, name=Individual 18-50, xxxx=41}, {aaa=true, x=31, xxxxx=1, name=Individual 51-60, xxx=41}, {aaa=true, x=34, xxxxx=1, name=Individual 61-75, xxx=41}, {aaa=true, x=37, xxxxx=1, name=Individual 76-85, xxx=41}]
log.error policies displays this:
[{x=28, xxx=41, xxxxx=1, name=Individual 18-50, aaa=true}, {x=31, xxx=41, xxxxx=1, name=Individual 51-60, aaa=true}, {x=34, xxxx=41, xxxxxx=1, name=Individual 61-75, aaa=true}, {x=37, xxx=41, xxxxx=1, name=Individual 76-85, aaa=false}]
How can I have the DTOs to be displayed within the correct order with json.policies so that it is displayed in the correct order as policies?
One more unusual thing, I ran the test case 10 times and the test step which this assertion checks has passed 3 out of 10 times. It should never have passed as if you compare the last DTO as the end for policies, it displays isActive as false which the last isActive in json.policies is true.
log.warn json.policies*.getClass()andlog.warn policies*.getClass()show you they are? My guess is the json one is a LazyMap, and this is why they are not the same... They are different classes (containing the same data)