Reputation: 4324
I want to check if every instance of occupanysequenceorder
matches the request inputted for this field. When I do a log.error
it outputs this:
ERROR:[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
ERROR:1
So as the request inputted 1, it means in the list all instances needs to equal 1, which it does above. However when I perform an assert:
assert roominfo.occupancySequenceOrder.flatten() == occupancysequenceorder_request
It throws a false assertion and I am not sure why? How can I get the script assertion to pass with it performing the relevant check. I change assert to
assert roominfo.occupancySequenceOrder.flatten().contains(occupancysequenceorder_request)
and it passes but I am not sure if that is actually does the correct check to ensure every instance of occupanysequenceorder
is matching the request inputted.
Below is the code:
json.testregions.each { roominfo ->
log.error roominfo.occupancySequenceOrder.flatten()
log.error occupancysequenceorder_request
assert roominfo.occupancySequenceOrder.flatten() == occupancysequenceorder_request
}
Upvotes: 0
Views: 133
Reputation: 21349
Looking at OP's other question and its data from here
You can try below Script Assertion
:
//Check if the response is not empty
assert context.response, "Response is empty or null"
//Modify the value of the quest or read it thru properties if you want
def requestValue = 1
def json = new groovy.json.JsonSlurper().parseText(context.response)
json.regions.each { region ->
region.hotels.each { hotel ->
hotel.roomInformation. each { room ->
assert room.occupancySequenceOrder == requestValue, "Value did not match for room ${room.hotelRoomId}"
}
}
}
Upvotes: 1
Reputation: 84756
Rather try:
roominfo.occupancySequenceOrder.every { it == 1 }
flatten()
will have no effect on flat List
.
You may also try:
roominfo.occupancySequenceOrder.unique() == [1]
if you'd like to compare lists.
Upvotes: 0