Script Assertion each statement
I'm trying to assert 0 position in file with my expected results. Within the log expected[0] appears to = filtered[0] which is the filtered parsed json file. When I do an assert within each statement it appears instead of comparing expected[0] = filtered[0] it's actually trying to compare all the results returned within filtered[0] (filtered json file)??? Please help....
//////Script
def responseMsg = messageExchange.response.responseContent
def parsedJson = new groovy.json.JsonSlurper().parseText(context.response)
//new variable to reduce the response list specific to levelOfCareName == 'Hospital_Level_of_Care'
def parsedJsonFiltered = parsedJson.criteria_LIST.findAll{it.levelOfCareName == 'Hospital_Level_of_Care'}
//def expectedResults Array
def expectedResults = [
[criteriaName: "Impact_On_Functioning", levelOfCareName: "Hospital_Level_of_Care", outcome: "Met", parentCriteria: "null", parentCriteriaName: "null", programName: "Hospital_Level_of_Care"]
//will be adding more to array after I get first assert to pass
]
log.info "ParsedJson Filtered: ${parsedJsonFiltered}}"
//go through each and assert
expectedResults.each
assert parsedJsonFiltered[0] == expectedResults[0]
//show filtered json in log
log.info "parsedJsonFiltered[0]: ${parsedJsonFiltered[0]}}"
log.info "expectedResults[0]: ${expectedResults[0]}}"
//////////////////////////////////////////////////////////////
//log output
Tue Sep 25 09:03:59 CDT 2018:INFO:ParsedJson Filtered: [[criteriaName:Impact_On_Functioning, levelOfCareName:Hospital_Level_of_Care, outcome:Met, parentCriteria:null, parentCriteriaName:null, programName:Hospital_Level_of_Care], [criteriaName:Physician_Determined, levelOfCareName:Hospital_Level_of_Care, outcome:Met, parentCriteria:null, parentCriteriaName:null, programName:Hospital_Level_of_Care], [criteriaName:Vulnerability_Requiring_24_Hour_Plan_Of_Care, levelOfCareName:Hospital_Level_of_Care, outcome:Met, parentCriteria:null, parentCriteriaName:null, programName:Hospital_Level_of_Care], [criteriaName:Specialized_Support_Need, levelOfCareName:Hospital_Level_of_Care, outcome:Met, parentCriteria:null, parentCriteriaName:null, programName:Hospital_Level_of_Care]]}
Tue Sep 25 09:03:59 CDT 2018:INFO:parsedJsonFiltered[0]: [criteriaName:Impact_On_Functioning, levelOfCareName:Hospital_Level_of_Care, outcome:Met, parentCriteria:null, parentCriteriaName:null, programName:Hospital_Level_of_Care]}
Tue Sep 25 09:03:59 CDT 2018:INFO:expectedResults[0]: [criteriaName:Impact_On_Functioning, levelOfCareName:Hospital_Level_of_Care, outcome:Met, parentCriteria:null, parentCriteriaName:null, programName:Hospital_Level_of_Care]}
//////////////////////////////////////////////////////////////
Assert Error:
assert parsedJsonFiltered[0] == expectedResults[0] | | | | | | | | | [criteriaName:Impact_On_Functioning, levelOfCareName:Hospital_Level_of_Care, outcome:Met, parentCriteria:null, parentCriteriaName:null, programName:Hospital_Level_of_Care] | | | [[criteriaName:Impact_On_Functioning, levelOfCareName:Hospital_Level_of_Care, outcome:Met, parentCriteria:null, parentCriteriaName:null, programName:Hospital_Level_of_Care]] | | false | [criteriaName:Impact_On_Functioning, levelOfCareName:Hospital_Level_of_Care, outcome:Met, parentCriteria:null, parentCriteriaName:null, programName:Hospital_Level_of_Care] [[criteriaName:Impact_On_Functioning, levelOfCareName:Hospital_Level_of_Care, outcome:Met, parentCriteria:null, parentCriteriaName:null, programName:Hospital_Level_of_Care], [criteriaName:Physician_Determined, levelOfCareName:Hospital_Level_of_Care, outcome:Met, parentCriteria:null, parentCriteriaName:null, programName:Hospital_Level_of_Care], [criteriaName:Vulnerability_Requiring_24_Hour_Plan_Of_Care, levelOfCareName:Hospital_Level_of_Care, outcome:Met, parentCriteria:null, parentCriteriaName:null, programName:Hospital_Level_of_Care], [criteriaName:Specialized_Support_Need, levelOfCareName:Hospital_Level_of_Care, outcome:Met, parentCriteria:null, parentCriteriaName:null, programName:Hospital_Level_of_Care]]
This is just a guess from looking at you post above, where you define your expected results (I've reformatted for clarity):
def expectedResults = [ [ criteriaName: "Impact_On_Functioning", levelOfCareName: "Hospital_Level_of_Care", outcome: "Met", parentCriteria: "null", parentCriteriaName: "null", programName: "Hospital_Level_of_Care" ] ]
I see that you are representing your null values as the string "null" which is different to a true null value. But when logged out would look the same. Try changing your expected reply to:
def expectedResults = [ [ criteriaName: "Impact_On_Functioning", levelOfCareName: "Hospital_Level_of_Care", outcome: "Met", parentCriteria: null, parentCriteriaName: null, programName: "Hospital_Level_of_Care" ] ]
Note: How I've dropped the quotes around the two null values.
As I mentioned this is just a guess but could be worth a try.