I have a scenario where I'm retrieving rows of data from a Postgres DB table and matching the corresponding column output against a separate .json file. The db.readRow() Java Util method returns a Map<String, Object>. The column in question that's causing a data type mismatch is defined as 'json' datatype in Postgres DB. This problem is similar to a recent post that my colleague submitted, and I looked at the information Peter T. provided (thanks Peter!).
Below is the feature file code and supporting file and attached is the corresponding Karate report showing the match error on line 15. Line 16 is a workaround I/we found where we have a helper function that converts the results of that column to a JSON object. We then are able to match the data correctly against the specific column on line 18. The ideal would be having line 15 work as normally there will be other column data in the embeddedJsonDb.json included in the same table. For the other non-json columns, #regex, #notnull, or other matching types are working as expected.
Thanks in advance for any help or tips.
embeddedJson.feature:
Feature: Karate Embedded Json Example
Background:
* def dbExpectedResults = read('embeddedJsonDb.json')
* def DBUtils = Java.type('utils.DBUtils')
* def db = new DBUtils()
* def helpers = call karate.read('classpath:helpers2.feature')
@embeddedJson
Scenario Outline: Karate Embedded Json Example
* def dbResult = db.readRow("select * from embedded_json_table")
* json embedded_json_msg = embeddedJsonMsg
* print "dbResult: ", dbResult
* print "dbResult.embedded_json_message: ", dbResult.embedded_json_message
* match dbResult == dbExpectedResults.karateJsonIssue.embedded_json_table
* def embeddedJsonObject = helpers.jsonStringToJsonObject(dbResult.embedded_json_message.toString())
* print "embeddedJsonObject", embeddedJsonObject
* match embeddedJsonObject == embedded_json_msg
Examples:
| testDescription | embeddedJsonMsg |
| embedded json | {"name":"Luke Skywalker","info":"{\"occupation\":{\"jobTitle\":\"Jedi\"}"} |
embeddedJsonDb.json:
{
"karateJsonIssue": {
"embedded_json_table": {
"embedded_json_message": "#(embedded_json_msg)"
}
}
}