我有一个REST API,可以检索值列表。我正在执行一个SQL查询,它从Oracle DB中检索值。我试图找到一种方法来比较/断言API中检索到的值与存储在DB中的值相同。我的代码是:
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
}
}
调用checkRetrievedGames函数时出现错误消息: {断言失败:断言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]错误在线:5}
检索到的json文件是: [ 15000, 15100, 15200, 15300, 15900, 16000 ]
sql查询响应是: GM_CD 15000 15100 15200 15300 15550 15600 15900 16000
根据我的理解,我必须以某种方式删除" GM_CODE:"从检索到的sql查询列表中。 谢谢你的时间