Contributions
comparing json response with jdbc response
I am trying to compare json response to jdbc response. The script seems to be comparing only the last object. How do I get it to compare all the objects. Please see my code below import groovy.json.* import groovy.xml.* import net.sf.json.JSON import net.sf.json.JSONSerializer import net.sf.json.xml.XMLSerializer @groovy.transform.Canonical class Model { def name def id def buildJdbcData(row) { row.with { name = it."PLACES_MASTER.NAME" id = it."PLACES_MASTER.PLACE_ID" } } def buildJsonData(place){ name = place.name id = place.id } } def jdbcResponse = testRunner.testCase.testSteps["JDBC Request"].testRequest.response.contentAsString def jsonResponse = testRunner.testCase.testSteps["JSON_Request"].testRequest.response.contentAsString JSON json = JSONSerializer.toJSON( jsonResponse ) XMLSerializer xmlSerializer = new XMLSerializer() xmlSerializer.setTypeHintsCompatibility( true ) String xml = xmlSerializer.write( json ) //log.info(xml) //Parsing the jdbc and build the jdbc model object list def results = new XmlSlurper().parseText(jdbcResponse) def jdbcDataObjects = [] results.ResultSet.Row.each { row -> jdbcDataObjects.add(new Model().buildJdbcData(row))} log.info(jdbcDataObjects) //Parsing the json and build the json model object list def arrayOfTagInfo = new XmlSlurper().parseText(xml) def jsonDataObjects = [] arrayOfTagInfo.place.each { tagInfo -> jsonDataObjects.add(new Model().buildJsonData(tagInfo)) } log.info(jsonDataObjects) //sorting the Data before checking for equality jdbcDataObjects.sort() jsonDataObjects.sort() if (jdbcDataObjects.size() != jsonDataObjects.size()) { System.err.println("Jdbc resultset size is : ${jdbcDataObjects.size()} and Json result size is : ${jsonDataObjects.size()}") } assert jdbcDataObjects == jsonDataObjects, "Comparison of Jdbc and Json data is failed" Here is my json response {"place": { "elevation": 0, "id": "TAS_RS098", "coordinate": { "longitude": 147.0036, "latitude": -42.3811 }, "gridcells": {"forecast": { "x": 587, "y": 52 }}, "name": "River Clyde at Bothwell", "postcode": { "name": "7030", "description": "APSLEY" }, "timezone": "Australia/Hobart", "type": "river_site", "location_hierarchy": { "region": [ { "aac": "AUS_FA001", "description": "Australia" }, { "aac": "TAS_FA001", "description": "Tasmania" } ], "public_district": { "aac": "TAS_PW008", "description": "Central Plateau" }, "coast": { "aac": null, "description": null }, "fire_district": { "aac": "TAS_FW008", "description": "Central Plateau" }, "flood_watch_area": [ { "aac": "TAS_FL022", "description": "Derwent River" }], "metropolitan": [ { "aac": "", "description": "" }], "coast_warn": [ { "aac": "", "description": "", "startPoint": null, "endPoint": null }], "tidal_location": { "aac": null, "description": null }, "nearest": { "elevation": 350, "id": "TAS_RO0029", "coordinate": { "longitude": 147.0036, "latitude": -42.3811 }, "gridcells": {"forecast": { "x": 587, "y": 52 }}, "name": "River Clyde at Bothwell", "state": "TAS", "timezone": "Australia/Hobart", "postcode": { "name": "7030", "description": "APSLEY" }, "type": "river_obs_point", "distance": 0, "feature_code": "river_obs_point" }, "nearby": [ { "elevation": 337, "id": "TAS_PT124", "coordinate": { "longitude": 147.000005, "latitude": -42.380001 }, "gridcells": {"forecast": { "x": 587, "y": 52 }}, "name": "Bothwell", "state": "TAS", "timezone": "Australia/Hobart", "postcode": { "name": "7030", "description": "APSLEY" }, "type": "bom_poi", "distance": 319.57495, "feature_code": "bom_poi" }, { "elevation": 0, "id": "232818", "coordinate": { "longitude": 147, "latitude": -42.380001 }, "gridcells": {"forecast": { "x": 587, "y": 52 }}, "name": "Bothwell", "state": "TAS", "timezone": "Australia/Hobart", "postcode": { "name": "7030", "description": "APSLEY" }, "type": "place", "distance": 319.9567, "feature_code": "SUB" }, { "elevation": 0, "id": "242455", "coordinate": { "longitude": 147, "latitude": -42.380001 }, "gridcells": {"forecast": { "x": 587, "y": 52 }}, "name": "Queens Park", "state": "TAS", "timezone": "Australia/Hobart", "postcode": { "name": "7030", "description": "APSLEY" }, "type": "place", "distance": 319.9567, "feature_code": "RESV" }, { "elevation": 0, "id": "35009", "coordinate": { "longitude": 147.008316, "latitude": -42.384769 }, "gridcells": {"forecast": { "x": 587, "y": 52 }}, "name": "Bothwell", "state": "TAS", "timezone": "Australia/Hobart", "postcode": { "name": "7030", "description": "APSLEY" }, "type": "place", "distance": 562.5672, "feature_code": "POPL" }, { "elevation": 0, "id": "248514", "coordinate": { "longitude": 147.039993, "latitude": -42.380001 }, "gridcells": {"forecast": { "x": 588, "y": 52 }}, "name": "Pub Corner", "state": "TAS", "timezone": "Australia/Hobart", "postcode": { "name": "7030", "description": "APSLEY" }, "type": "place", "distance": 2991.7427, "feature_code": "LOCU" } ], "national_landscape": null, "capital_area": { "name": "6RTAS", "description": "Rest of Tas." }, "post_code": { "name": "7030", "description": "APSLEY" }, "suburb": { "name": "60063", "description": "Bothwell" }, "lga": { "name": "61010", "description": "Central Highlands (M) (Tas.)" }, "state": { "abbrev": "TAS", "name": "TASMANIA", "aac": "TAS_ST001" }, "country": { "aac": "AUS_CO001", "name": "Australia" } }, "feature_code": "river_site" }} Here is my jdbc response <Results> <ResultSet fetchSize="0"> <Row rowNumber="1"> <PLACES_MASTER.DMP_ID>2259</PLACES_MASTER.DMP_ID> <PLACES_MASTER.PLACE_ID>TAS_RS098</PLACES_MASTER.PLACE_ID> <PLACES_MASTER.STATE_ABBREV>TAS</PLACES_MASTER.STATE_ABBREV> <PLACES_MASTER.NAME>River Clyde at Bothwell</PLACES_MASTER.NAME> <PLACES_MASTER.FEATURE_CO>river_site</PLACES_MASTER.FEATURE_CO> <PLACES_MASTER.RECORD_ID>N/A</PLACES_MASTER.RECORD_ID> <PLACES_MASTER.ELEVATION>0.0</PLACES_MASTER.ELEVATION> <PLACES_MASTER.FORECAST_POINT>TAS_RS098</PLACES_MASTER.FORECAST_POINT> <PLACES_MASTER.REGION>AUS_FA001|TAS_FA001</PLACES_MASTER.REGION> <PLACES_MASTER.REGION_NAME>Australia|Tasmania</PLACES_MASTER.REGION_NAME> <PLACES_MASTER.SUB_REGION/> <PLACES_MASTER.SUB_REGION_NAME/> <PLACES_MASTER.PUBLIC_DISTRICT>TAS_PW008</PLACES_MASTER.PUBLIC_DISTRICT> <PLACES_MASTER.PUBLIC_DISTRICT_NAME>Central Plateau</PLACES_MASTER.PUBLIC_DISTRICT_NAME> <PLACES_MASTER.FIRE_AREA>TAS_FW008</PLACES_MASTER.FIRE_AREA> <PLACES_MASTER.FIRE_AREA_NAME>Central Plateau</PLACES_MASTER.FIRE_AREA_NAME> <PLACES_MASTER.MARINE_WARNING_AREA/> <PLACES_MASTER.MARINE_WARNING_AREA_NAME/> <PLACES_MASTER.MARINE_COAST/> <PLACES_MASTER.MARINE_COAST_NAME/> <PLACES_MASTER.METROPOLITAN_AREA/> <PLACES_MASTER.METROPOLITAN_AREA_NAME/> <PLACES_MASTER.COASTAL_AREA/> <PLACES_MASTER.COASTAL_AREA_NAME/> <PLACES_MASTER.CATCHMENT>TAS_RC006|TAS_RC042</PLACES_MASTER.CATCHMENT> <PLACES_MASTER.CATCHMENT_NAME>River Derwent|River Clyde</PLACES_MASTER.CATCHMENT_NAME> <PLACES_MASTER.FLOOD_WATCH_AREA>TAS_FL022</PLACES_MASTER.FLOOD_WATCH_AREA> <PLACES_MASTER.FLOOD_WATCH_AREA_NAME>Derwent River</PLACES_MASTER.FLOOD_WATCH_AREA_NAME> <PLACES_MASTER.NATIONAL_LANDSCAPE/> <PLACES_MASTER.FLAG_MAR>f</PLACES_MASTER.FLAG_MAR> <PLACES_MASTER.FLAG_TERR>t</PLACES_MASTER.FLAG_TERR> <PLACES_MASTER.SSC_CODE>60063</PLACES_MASTER.SSC_CODE> <PLACES_MASTER.SSC_CODE_NAME>Bothwell</PLACES_MASTER.SSC_CODE_NAME> <PLACES_MASTER.LGA_CODE>61010</PLACES_MASTER.LGA_CODE> <PLACES_MASTER.LGA_CODE_NAME>Central Highlands (M) (Tas.)</PLACES_MASTER.LGA_CODE_NAME> <PLACES_MASTER.GCC_CODE>6RTAS</PLACES_MASTER.GCC_CODE> <PLACES_MASTER.GCC_CODE_NAME>Rest of Tas.</PLACES_MASTER.GCC_CODE_NAME> <PLACES_MASTER.POST_CODE>7030</PLACES_MASTER.POST_CODE> <PLACES_MASTER.POST_CODE_NAME>APSLEY</PLACES_MASTER.POST_CODE_NAME> <PLACES_MASTER.TIDAL_LOCATION/> <PLACES_MASTER.TIDAL_LOCATION_NAME/> <PLACES_MASTER.SOURCE_TYPE>river_site</PLACES_MASTER.SOURCE_TYPE> <PLACES_MASTER.TZ_CODE>Australia/Hobart</PLACES_MASTER.TZ_CODE> <PLACES_MASTER.GEOM>0101000020E61000008048BF7D1D606240B84082E2C73045C0</PLACES_MASTER.GEOM> <PLACES_MASTER.LONGITUDE>147.003600000000006</PLACES_MASTER.LONGITUDE> <PLACES_MASTER.LATITUDE>-42.3811000000000035</PLACES_MASTER.LATITUDE> <PLACES_MASTER.GRIDCELL_LONG_INDEX>587</PLACES_MASTER.GRIDCELL_LONG_INDEX> <PLACES_MASTER.GRIDCELL_LAT_INDEX>52</PLACES_MASTER.GRIDCELL_LAT_INDEX> <PLACES_MASTER.CAPABILITY>N/A</PLACES_MASTER.CAPABILITY> <PLACES_MASTER.STATION_COMMON_NAME/> <PLACES_MASTER.TIDAL_LOCATION_AREA/> <PLACES_MASTER.TIDAL_LOCATION_AREA_NAME/> <PLACES_MASTER.PRIMARY_SORT>101</PLACES_MASTER.PRIMARY_SORT> <PLACES_MASTER.TERTIARY_SORT>6</PLACES_MASTER.TERTIARY_SORT> <PLACES_MASTER.STATE_AREA>TAS_ST001</PLACES_MASTER.STATE_AREA> <PLACES_MASTER.STATE_AREA_NAME>TASMANIA</PLACES_MASTER.STATE_AREA_NAME> <PLACES_MASTER.COUNTRY_AREA>AUS_CO001</PLACES_MASTER.COUNTRY_AREA> <PLACES_MASTER.COUNTRY_AREA_NAME>Australia</PLACES_MASTER.COUNTRY_AREA_NAME> <PLACES_MASTER.LOCALITY_FCST/> <PLACES_MASTER.LOCALITY_FCST_NAME/> <PLACES_MASTER.PRECIS_FCST>TAS_PT124</PLACES_MASTER.PRECIS_FCST> <PLACES_MASTER.PRECIS_FCST_NAME>Bothwell</PLACES_MASTER.PRECIS_FCST_NAME> </Row> </ResultSet> </Results>345Views0likes0CommentsHow to compare json response with jdbc response using groovy
I know this question has been asked earlier. The previous response was comparison of two xml responses. Here I need to compare json response which with jdbc's xml response. I have made necessary changes as per my json response and jdbc response. I am still getting error that the assertion has failed. I have been struggling with this for couple of weeks. Please advise. here is my json response "meta": {"api_response_datetime_utc": "2022-09-19T04:11:42.013964Z"}, "warnings": [ { "id": "ABC23879", "issue_datetime_utc": "2022-03-07T19:21:31Z", "expires_datetime_utc": "2025-03-14T19:21:24Z", "title": "", "sub_title": "", "area_summary": [ "North Central", "North East", "Central", "West and South Gippsland and East Gippsland forecast districts" ], "phenomena_summary": null, "severity_code": ["STD"], "issue_type": "Update", "type": "WFR", "area_state_code": "VIC", "link_details": null }, { "id": "BAC22000", "issue_datetime_utc": "2022-03-07T19:21:29Z", "expires_datetime_utc": "2025-03-14T19:21:24Z", "title": "Fire Weather", "sub_title": "Mallee, Northern Country, North Central and North East forecast districts", "area_summary": [ "Mallee", "Northern Country", "North Central and North East" ], "phenomena_summary": null, "severity_code": ["SEV"], "issue_type": "Alert", "type": "WFW", "area_state_code": "VIC", "link_details": null } ] } Here is my jdbc response <Results> <ResultSet fetchSize="0"> <Row rowNumber="1"> <WARNINGS_VW.PRODUCT_IDENT_NUMBER>ABC23879</WARNINGS_VW.PRODUCT_IDENT_NUMBER> <WARNINGS_VW.DMP_ID>34434</WARNINGS_VW.DMP_ID> <WARNINGS_VW.WARNING_TYPE>WFW</WARNINGS_VW.WARNING_TYPE> <WARNINGS_VW.GEOCODE_TYPE>aac:fire_district</WARNINGS_VW.GEOCODE_TYPE> <WARNINGS_VW.GEOCODE_CODE>VIC_FW008</WARNINGS_VW.GEOCODE_CODE> <WARNINGS_VW.AREA_SUMMARY>Mallee, Northern Country, North Central and North East</WARNINGS_VW.AREA_SUMMARY> <WARNINGS_VW.WARNING_AREA_TYPE>geocode</WARNINGS_VW.WARNING_AREA_TYPE> <WARNINGS_VW.SEARCH_POLYGON/> </Row> <Row rowNumber="2"> <WARNINGS_VW.PRODUCT_IDENT_NUMBER>BAC23000</WARNINGS_VW.PRODUCT_IDENT_NUMBER> <WARNINGS_VW.DMP_ID>34439</WARNINGS_VW.DMP_ID> <WARNINGS_VW.WARNING_TYPE>WFR</WARNINGS_VW.WARNING_TYPE> <WARNINGS_VW.GEOCODE_TYPE>aac:public_district</WARNINGS_VW.GEOCODE_TYPE> <WARNINGS_VW.GEOCODE_CODE>VIC_PW008</WARNINGS_VW.GEOCODE_CODE> <WARNINGS_VW.AREA_SUMMARY>North Central, North East, Central, West and South Gippsland and East Gippsland forecast districts</WARNINGS_VW.AREA_SUMMARY> <WARNINGS_VW.WARNING_AREA_TYPE>geocode</WARNINGS_VW.WARNING_AREA_TYPE> <WARNINGS_VW.SEARCH_POLYGON/> </Row> </ResultSet> </Results> My groovy script import groovy.json.* import groovy.xml.* @groovy.transform.Canonical class Model { def id def warningType def geocodeType def geocodeCode def areaSummary def warningAreaType def searchPolygon def buildJdbcData(row) { row.with { id = WARNINGS_VW.PRODUCT_IDENT_NUMBER warningType= WARNINGS_VW.WARNING_TYPE } } def buildJsonData(warnings){ id = warnings.id warningType = warnings.type } } def jdbcResponse = testRunner.testCase.testSteps["JDBC Request"].testRequest.response.contentAsString def jsonResponse = testRunner.testCase.testSteps["List1-Request1"].testRequest.response.contentAsString //Parsing the jdbc and build the jdbc model object list def results = new XmlSlurper().parseText(jdbcResponse) def jdbcDataObjects = [] results.ResultSet.Row.each { row -> jdbcDataObjects.add(new Model().buildJdbcData(row))} //Parsing the json and build the json model object list def arrayOfTagInfo = new JsonSlurper().parseText(jsonResponse) def jsonDataObjects = [] arrayOfTagInfo.TagInfo.each { tagInfo -> jsonDataObjects.add(new Model().buildJsonData(tagInfo)) } //sorting the Data before checking for equality jdbcDataObjects.sort() jsonDataObjects.sort() assert jdbcDataObjects == jsonDataObjects, "Comparison of Jdbc XML data and Json data has failed"475Views0likes1CommentSoapui Maven with Gitlab - The gitlab job succeeds despite the failure of tests
Gitlab does not fail the job despite the tests fail. I have been working on this error forever. I couldn't find a solution. Please find the screen shot below Please advise. This is urgent. ThanksSolved607Views0likes1CommentNo Suitable driver exception when I try to connect to postgres using the jdbc step in SoapUI (free v
downloaded the postgres jdbc driver from the following linkhttps://jdbc.postgresql.org/download.htmldownloaded the latest version Pasted the jar file in the soapui_home/bin/ext folder Restarted SoapUI still getting the same error I have added a jdbc step in SoapUI Here is the driver, I have used PostgreSQL/org.postgresql.Driver The string is dbc:postgresql://localhost:5432/databaseName?user=username&password=password This is super urgent. Please advise. Thanks Environment Redhat Linux jdk version is 11 SoapUI version 5.7.0935Views0likes3Comments