ContributionsMost RecentMost LikesSolutionsRe: parameterize json rest api request Yes, that answered my question. Thanks! parameterize json rest api request Was wondering if anyone had input on best solution for parameterizing a json rest api request? Here is what I'd like to parameterize: (sample request below) MDOC_PRESENTED_QUESTION_ID QUESTION MDOC_ANSWER_ID CHOICE_ID CHOICE Now I know there are the following datasource types to paramertize these: Data Connection Data Generator Directory Excel File Grid Groovy JDBC Json EML I've tried Grid which seemed to require me to create seperate properties for each(so, questionid1, question1, answerid1, choiceid1, choice1, questionid2 etc etc etc....) and I also tried JDBC and was able to get first set of values for the first request block of question and choice ids via setting "prepared properties" for choiceid and answerid and then doing a query based on where clause = :QuestionID and :ChoiceID. This method seemed to be a challange vs grid since I need all differant values in the request for :QuestionID and :ChoiceID and my query is only bringing back resutls for values set in the "prepared properties". What would be the best route to take? Just stick with grid? Thinking of the most dynamic and least maintenance if values need to change etc.... sample Json request: { "mDOC_json_data": { "mDOC_PRESENTED_QUESTION_json_dataList": [{ "MDOC_PRESENTED_QUESTION_ID": 137, "QUESTION": "Indicate_Persons_Overall_Health_Risk_137", "ANSWER_LIST": [{ "MDOC_ANSWER_ID": 45, "MDOC_PRESENTED_QUESTION_ID": 137, "CHOICE_ID": 545, "CHOICE": "Persons_Health_Conditions_Generally_Stable_545" }] }, { "MDOC_PRESENTED_QUESTION_ID": 112, "QUESTION": "HOSPITAL_Level_Of_Care_112", "ANSWER_LIST": [{ "MDOC_ANSWER_ID": 202, "MDOC_PRESENTED_QUESTION_ID": 112, "CHOICE_ID": 75, "CHOICE": "Certified_By_Physician_To_Require_Supports_Similar_To_Hospital_75" }] }, { "MDOC_PRESENTED_QUESTION_ID": 82, "QUESTION": "Clinical_Monitoring_Established_By_Persons_Physician_82", "ANSWER_LIST": [{ "MDOC_ANSWER_ID": 100, "MDOC_PRESENTED_QUESTION_ID": 82, "CHOICE_ID": 314, "CHOICE": "Person_Under_Clinical_Monitoring_Order_314" }] }], "MDOC_ID": 12345, "PERSON_ID": 965879, "MC_REFERRAL_ID": 1322 }, "PERSON_ID": 965879, "FIRST_NAME": "JOHN", "MIDDLE_NAME": "M", "LAST_NAME": "DOE", "NAME_SUFFIX": "Sr." } SolvedRe: Script Assertion each statement Thank you so much! It now works! Good catch!!! Re: Script Assertion each statement So I tried a few differant combos that were mentioned above. Below I just commented out the each statement and just tried to compare via assert the parsedJsonFiltered (which I have limited down to just one of the criteria I need to look for, there are others but for the purpose of this debug I've just limited it to one) with the expected results. The Assert fails as if the compare between parsedJsonFiltered and expectedResults don't match but when I log the output or even look at the assert error the results do match. Can't figure out what the issue is..???? ------------------------ 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.programName == 'Hospital_Level_of_Care' && it.criteriaName == 'Impact_On_Functioning'} //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"] // [levelOfCareName: "Hospital_Level_of_Care", criteriaName: "Impact_On_Functioning", outcome: "Met"], // [levelOfCareName: "Hospital_Level_of_Care", criteriaName: "Physician_Determined", outcome: "Met"], // [levelOfCareName: "Hospital_Level_of_Care", criteriaName: "Specialized_Support_Need", outcome: "Met"], // [levelOfCareName: "Hospital_Level_of_Care", criteriaName: "Clinical_Monitoring", outcome: "Met"], // [levelOfCareName: "Hospital_Level_of_Care", criteriaName: "Vulnerability_Requiring_24_Hour_Plan_Of_Care", outcome: "Met"] ] log.info "ParsedJson Filtered: ${parsedJsonFiltered}" log.info "expectedResults: ${expectedResults}" assert parsedJsonFiltered == expectedResults //go through each and assert //expectedResults.each //assert parsedJsonFiltered[0] == expectedResults //assert parsedJsonFiltered[1] == expectedResults[0] //assert parsedJsonFiltered[2] == expectedResults[1] //assert parsedJsonFiltered[3] == expectedResults[2] //assert parsedJsonFiltered[4] == expectedResults[4] //show filtered json in log //log.info "parsedJsonFiltered[0]: ${parsedJsonFiltered[0]}" //log.info "expectedResults[0]: ${expectedResults}" //log.info "parsedJsonFiltered[1]: ${parsedJsonFiltered[1]}}" //log.info "parsedJsonFiltered[2]: ${parsedJsonFiltered[2]}}" //log.info "parsedJsonFiltered[3]: ${parsedJsonFiltered[3]}}" //log.info "parsedJsonFiltered[4]: ${parsedJsonFiltered[4]}}" ---------------------------------- log output: Thu Sep 27 07:34:00 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]] Thu Sep 27 07:34:00 CDT 2018:INFO:expectedResults: [[criteriaName:Impact_On_Functioning, levelOfCareName:Hospital_Level_of_Care, outcome:Met, parentCriteria:null, parentCriteriaName:null, programName:Hospital_Level_of_Care]] ------------------------------------- Assert Error: assert parsedJsonFiltered == expectedResults | | | | | [[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]] ------------------------------------- Re: Script Assertion each statement ok, tried that, didn't change anything..... 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]] SolvedRe: Help with groovy script Thanks so much! I was making it way too complicated! I now have this and it's working great! def responseMsg = messageExchange.response.responseContent def parsedJson = new groovy.json.JsonSlurper().parseText(context.response) def expectedResults = [ [criteriaName: "Impact_On_Functioning", outcome: "Met"], [criteriaName: "Diagnostic_Determination", outcome: "Met"], [criteriaName: "Specialized_Support_Need", outcome: "Met"] ] expectedResults.each assert parsedJson.criteriaList[0] == expectedResults[0] assert parsedJson.criteriaList[1] == expectedResults[1] assert parsedJson.criteriaList[2] == expectedResults[2] One more question, if the json response is still in dev(so changes are happening) what's the best way to parameterize assertions so you don't have to go into the assertion, and say for this example above modify the: def expectedResults = [ [criteriaName: "Impact_On_Functioning", outcome: "Met"], [criteriaName: "Diagnostic_Determination", outcome: "Met"], [criteriaName: "Specialized_Support_Need", outcome: "Met"] ] I'd like to just go into the test case or some file and update the expected results for the assertion in the test case. Help with groovy script According to the log, parsedJson.criteriaList[count] contains INFO:Combined: [criteriaName:Impact_On_Functioning, outcome:Met]} and I want to match "Impact_On_Functioning, outcome:Met" however in my case statement below "~/.*(?i)Impact_On_Functioning, outcome.*/:" I can match only up to the colon, if I include the colon it comes back not matching. I can not get the right regex to match the complete string(Impact_On_Functioning, outcome:Met). Anyone have any suggestions? groovy script assertion and log below in SoapUI (free version) --------------------------------------------------------------- //grab the response to parse out json def responseMsg = messageExchange.response.responseContent def parsedJson = new groovy.json.JsonSlurper().parseText(context.response) def int count = 0; def int success; parsedJson.criteriaList.each { log.info "Combined: ${parsedJson.criteriaList[count]}}" switch (parsedJson.criteriaList[count]) { case ~/.*(?i)Impact_On_Functioning, outcome.*/: log.info("pass") success = 1 break; default: log.info("Doesn't work!") success = 0; } log.info "Item: $count" log.info "done in each" count++; } log.info "Success: $success"; if(success == 1) { log.info "Pass123"; log.info "Pass123: $success" } else{ log.info "Fail123"; log.info "Fail123: $success" assert success == 1 : "success should be 1"; } log.info "done" ----------------------------------------------------------------- Log: Wed Aug 29 06:25:29 CDT 2018:INFO:Combined: [criteriaName:Impact_On_Functioning, outcome:Met]} Wed Aug 29 06:25:29 CDT 2018:INFO:pass Wed Aug 29 06:25:29 CDT 2018:INFO:Item: 0 Wed Aug 29 06:25:29 CDT 2018:INFO:done in each Wed Aug 29 06:25:29 CDT 2018:INFO:Combined: [criteriaName:Diagnostic_Determination, outcome:Met]} Wed Aug 29 06:25:29 CDT 2018:INFO:Doesn't work! Wed Aug 29 06:25:29 CDT 2018:INFO:Item: 1 Wed Aug 29 06:25:29 CDT 2018:INFO:done in each Wed Aug 29 06:25:29 CDT 2018:INFO:Combined: [criteriaName:Specialized_Support_Need, outcome:Met]} Wed Aug 29 06:25:29 CDT 2018:INFO:Doesn't work! Wed Aug 29 06:25:29 CDT 2018:INFO:Item: 2 Wed Aug 29 06:25:29 CDT 2018:INFO:done in each Wed Aug 29 06:25:29 CDT 2018:INFO:Combined: [criteriaName:Vulnerability_Requiring_24_Hour_Plan_Of_Care, outcome:Met]} Wed Aug 29 06:25:29 CDT 2018:INFO:Doesn't work! Wed Aug 29 06:25:29 CDT 2018:INFO:Item: 3 Wed Aug 29 06:25:29 CDT 2018:INFO:done in each Wed Aug 29 06:25:29 CDT 2018:INFO:Combined: [criteriaName:Vulnerability_Requiring_24_Hour_Plan_Of_Care, outcome:Met]} Wed Aug 29 06:25:29 CDT 2018:INFO:Doesn't work! Wed Aug 29 06:25:29 CDT 2018:INFO:Item: 4 Wed Aug 29 06:25:29 CDT 2018:INFO:done in each Wed Aug 29 06:25:29 CDT 2018:INFO:Combined: [criteriaName:Medical_Assistance, outcome:Not_Met]} Wed Aug 29 06:25:29 CDT 2018:INFO:Doesn't work! Wed Aug 29 06:25:29 CDT 2018:INFO:Item: 5 Wed Aug 29 06:25:29 CDT 2018:INFO:done in each Wed Aug 29 06:25:29 CDT 2018:INFO:Combined: [criteriaName:Residential_Habitation, outcome:Not_Met]} Wed Aug 29 06:25:29 CDT 2018:INFO:Doesn't work! Wed Aug 29 06:25:29 CDT 2018:INFO:Item: 6 Wed Aug 29 06:25:29 CDT 2018:INFO:done in each Wed Aug 29 06:25:29 CDT 2018:INFO:Combined: [criteriaName:Developmental_Disability_Or_Related_Condition, outcome:Met]} Wed Aug 29 06:25:29 CDT 2018:INFO:Doesn't work! Wed Aug 29 06:25:29 CDT 2018:INFO:Item: 7 Wed Aug 29 06:25:29 CDT 2018:INFO:done in each Wed Aug 29 06:25:29 CDT 2018:INFO:Combined: [criteriaName:Activities_Of_Daily_Living_ADLs, outcome:Not_Met]} Wed Aug 29 06:25:29 CDT 2018:INFO:Doesn't work! Wed Aug 29 06:25:29 CDT 2018:INFO:Item: 8 Wed Aug 29 06:25:29 CDT 2018:INFO:done in each Wed Aug 29 06:25:29 CDT 2018:INFO:Combined: [criteriaName:Activities_Of_Daily_Living_ADLs, outcome:Not_Met]} Wed Aug 29 06:25:29 CDT 2018:INFO:Doesn't work! Wed Aug 29 06:25:29 CDT 2018:INFO:Item: 9 Wed Aug 29 06:25:29 CDT 2018:INFO:done in each Wed Aug 29 06:25:29 CDT 2018:INFO:Combined: [criteriaName:Instrumental_Activities_Of_Daily_Living_IADLs, outcome:Does_not_meet_Criteria_of_Instrumental_Activites_Of_Daily_Living]} Wed Aug 29 06:25:29 CDT 2018:INFO:Doesn't work! Wed Aug 29 06:25:29 CDT 2018:INFO:Item: 10 Wed Aug 29 06:25:29 CDT 2018:INFO:done in each Wed Aug 29 06:25:29 CDT 2018:INFO:Combined: [criteriaName:Medical_Assistance, outcome:Not_Met]} Wed Aug 29 06:25:29 CDT 2018:INFO:Doesn't work! Wed Aug 29 06:25:29 CDT 2018:INFO:Item: 11 Wed Aug 29 06:25:29 CDT 2018:INFO:done in each Wed Aug 29 06:25:29 CDT 2018:INFO:Combined: [criteriaName:Program_Access_Criteria, outcome:Not_Met]} Wed Aug 29 06:25:29 CDT 2018:INFO:Doesn't work! Wed Aug 29 06:25:29 CDT 2018:INFO:Item: 12 Wed Aug 29 06:25:29 CDT 2018:INFO:done in each Wed Aug 29 06:25:29 CDT 2018:INFO:Combined: [criteriaName:Twenty_Four_Hour_Plan_Of_Care, outcome:Met]} Wed Aug 29 06:25:29 CDT 2018:INFO:Doesn't work! Wed Aug 29 06:25:29 CDT 2018:INFO:Item: 13 Wed Aug 29 06:25:29 CDT 2018:INFO:done in each Wed Aug 29 06:25:29 CDT 2018:INFO:Combined: [criteriaName:Impact_On_Functioning, outcome:Not_Met]} Wed Aug 29 06:25:29 CDT 2018:INFO:pass Wed Aug 29 06:25:29 CDT 2018:INFO:Item: 14 Wed Aug 29 06:25:29 CDT 2018:INFO:done in each Wed Aug 29 06:25:29 CDT 2018:INFO:Success: 1 Wed Aug 29 06:25:29 CDT 2018:INFO:Pass123 Wed Aug 29 06:25:29 CDT 2018:INFO:Pass123: 1 Wed Aug 29 06:25:29 CDT 2018:INFO:done SolvedAssert Script I need to verify via script assertion that within "SimpleList" that SimpleName1 with "outcome": "Met" SimpleName2 with "outcome": "Met . . . etc...... I'm able to output SimpleName1, SimpleName2 etc but for verification I need both SimpleName1 with the "outcome": "Met" in order for my assertion to pass. Also I'd like to be able to filter my assertion, so for example only validate within SimpleList that "SimpleName1" "outcome": "Met" and "SimpleName4" "outcome": "Met" and just ignore the rest. sample response: "SimpleList": [ { "SimpleName": "SimpleName1", "outcome": "Met" }, { "SimpleName": "SimpleName2", "outcome": "Met" }, { "SimpleName": "SimpleName3", "outcome": "Met" }, { "SimpleName": "SimpleName4", "outcome": "Met" Solved