I have a REST API that retrieves a list of values. I am performing a SQL Query that retrieves the values from the Oracle DB. I am trying to find a way to compare/assert that the retrieved values from the API are the same ones with the ones stored in DB. My code is:
import groovy.json.JsonSlurper
import groovy.sql.GroovyRowResult
context.setProperty("crudManager", new CrudManager())
CrudManager.log = log
// CrudManager
public class CrudManager {
// Check Retrieved Games
public void checkRetrievedGames(testRunner, testCase){
// Get Test Step's Response.
def slurper = new JsonSlurper()
def response = testRunner.testCase.getTestStepByName("Get Games").getPropertyValue("response")
def responseJson = slurper.parseText(response)
//Get the Games stored in DB
def gameCode = "GM_CD"
def query = "SELECT $gameCode FROM SCHEMA.PGM"
def array = new OracleConnector().select(query)
System.out.println(array);
def gameCodesList = Arrays.asList(array)
// Assertions - Compare response with DB.
assert responseJson == gameCodesList
}
}
When calling checkRetrievedGames function I get error Message: {Assertion failed: assert responseJson == gameCodesList | | | | | [[[GM_CD:15000], [GM_CD:15100], [GM_CD:15200], [GM_CD:15300], [GM_CD:15550], [GM_CD:15600], [GM_CD:15900], [GM_CD:16000]]] | false [15000, 15100, 15200, 15300, 15900, 16000] error at line: 5}
The retrieved json file is: [ 15000, 15100, 15200, 15300, 15900, 16000 ]
And the sql query response is: GM_CD 15000 15100 15200 15300 15550 15600 15900 16000
From what I understand I have to somehow remove the "GM_CODE:" from the retrieved list of the sql query. Thank you for your time