Groovy web console

subscribe to the feed Subscribe
to this
jdbc assertion (via #groovywebconsole)
tweet this snippet Tweet

jdbc assertion

Published 2 weeks ago by nmrao with tags jdbc
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
//define your expected data as map
def expectedData = ['TASK1':'Value1', 'TASK2':'Value1']

def jdbcResponse = """<Results>
    <ResultSet fetchSize="10">
     <Row rowNumber="1">
       <Row rowNumber="2">

//Parse and get rows
def rows = new XmlSlurper().parseText(jdbcResponse).ResultSet.Row

def getRowData = { data, elementName, elementValue ->
	data.'**'.findAll { == elementName && it == elementValue }*.parent()

def assertionErrors = new StringBuffer()

//Loop thur expectedData and capture the errors
expectedData.each { key, value->
	def matchingRow = getRowData(rows, 'T2', key)[0]
	value == matchingRow.T3.text() ?: assertionErrors.append("Assertion failed for rowNumber ${matchingRow.@rowNumber}\n")

//Check and show the result
if (assertionErrors) {
	throw new Error(assertionErrors.toString())
} else {
	println 'Assertions passed'