Forum Discussion
try this sample code (valuesin UpperCases change):
//Validate request nodes REST
// the library import
import groovy.json.JsonSlurper
//Validate response nodes REST
//def requestMessage = message.Exchange.request.requestContent
def responseMessage = messageExchange.response.responseContent
def json = new JsonSlurper().parseText(responseMessage)
//assert node values
// syntax: assert json.JSONPATH.ELEMENT.toString() COMPARE SYMBOLS LIKE IN IF (>,<,>=,<=,==,!=,you may use as comparing value "null")
def headers = messageExchange.getResponseHeaders()
assert ['HTTP/1.1 200 OK'] == headers["#status#"] : "Test Case HTTP Erorr: " + headers["#status#"]
log.info "Header status" + headers["#status#"]
assert ["YOURSERVER"] == headers["Server"] : "Test Case Server Erorr: " + headers["Server"]
log.info "Server: " + headers["Server"]
assert json.response.responseHeader.toString() != null : "responseHeader is empty: " + json.response.responseHeader //validation on responseHeader is not empty
log.info "responseHeader is: " + json.response.responseHeader
assert json.response.responseHeader.ELEMENT.toString() != null : "ELEMENT is empty: " + json.response.responseHeader.ELEMENT //validation on ELEMENT is not empty
log.info "providerId is: " + json.response.responseHeader.providerId
assert json.response.responseBody.returnCode.toString() == "0" : "returnCode is not 0: " + json.response.responseBody.returnCode
log.info "returnCode is: " + json.response.responseBody.returnCode
//check for attachments
assert messageExchange.responseAttachments.length == 0 : "Response Attachments is not NULL"
log.info "Number of atachments " + (messageExchange.responseAttachments.length)
// some other thing
/*
testStepName = messageExchange.modelItem.testStep.name //to get the Test Step Name
log.info testStepName
xmlHold = messageExchange.responseContentAsXml.toString() //to store the response as Xml
*/
Related Content
- 10 years ago
- 4 years ago
- 12 years ago
Recent Discussions
- 4 days ago