Solved
Forum Discussion
nmrao
6 years agoChampion Level 2
richie,
Not sure what you are expecting here.
The script is sorting to ascending (irrespective of the order in the response).
Any ways, please do below changes:
def response = context.expand( '${REST Request#Response#$[\'data\']}' )
to
def response = context.expand( '${REST Request#Response}' )
Another change is
def getPropertyValues = { prop ->
json.results."$prop"
}
To
def getPropertyValues = { prop ->
json.data."$prop"
}
Not sure what you are expecting here.
The script is sorting to ascending (irrespective of the order in the response).
Any ways, please do below changes:
def response = context.expand( '${REST Request#Response#$[\'data\']}' )
to
def response = context.expand( '${REST Request#Response}' )
Another change is
def getPropertyValues = { prop ->
json.results."$prop"
}
To
def getPropertyValues = { prop ->
json.data."$prop"
}
richie
6 years agoCommunity Hero
OH!
Sorry fella - I thought the script asserted that the response was returned in a certain order - as you can see - there's plenty of the script I can't actually read - I didnt realise the script was actually doing the sorting!
Apologies - that's not what I'm after.
I have a requirement where I'm requesting the data back in either ascending or descending order relative to the queryparm I'm specifying (e.g. /api/1/{namespace}/{table}?_sort=tableAttribute desc)
I thought your script actually ASSERTED the response was in ascending order as this is what I need to verify,
my bad!
richie
- nmrao6 years agoChampion Level 2More over, it was not even reading your data at all, forget about sort order. Because that was tailored for original question.
- richie6 years agoCommunity HeroHahaha!
What a dunce.....what can i say? I'm definitely making progress with my groovy, but it's very slow going!
But actually it's a lot more elegant than using the otb functionality....totally changed my opinion....im trying to do everything with groovy now! ;)
Nice one!
richie- nmrao6 years agoChampion Level 2
richie ,
Does the below helps?
//Define the ordered list which is in the same order of the values as expected def expectedList = [] def response = context.expand( '${REST Request#Response}' ) def json = new groovy.json.JsonSlurper().parseText(response) assert expectedList == json.data.Name
Related Content
- 5 years ago
Recent Discussions
- 15 hours ago
- 4 days ago
- 15 days ago