Forum Discussion
max1965
13 years agoContributor
I write the following groovy script:
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.GET
import static groovyx.net.http.ContentType.TEXT
def Indirizzo_F5_FE = context.expand( '${#Global#Indirizzo_F5_FE}' )
def Porta_F5_FE = context.expand( '${#Global#Porta_F5_FE}' )
def props = testRunner.testCase.getTestStepByName( "Properties" )
def cli = props.getPropertyValue("cli");
def ippresenza = props.getPropertyValue("ippresenza");
// log.info ("$Indirizzo_F5_FE, $Porta_F5_FE, $cli, $ippresenza")
def http = new HTTPBuilder( "http://${Indirizzo_F5_FE}:${Porta_F5_FE}/AuthInterface/acctRequest?cli=${cli}&ip=${ippresenza}&sessionType=APT&msgType=START" )
http.request(GET,TEXT) { req ->
headers.'Connection' = 'Keep-Alive'
headers.'User-Agent' = 'SoapUI 4.5.1'
response.success = { resp, reader ->
assert resp.status == 200
System.out << reader
}
}
The request is correctly sent, and in the soapui http.log is trace the request/answer:
Thu Feb 28 15:45:15 CET 2013:DEBUG:>> "GET /AuthInterface/acctRequest?cli=0804000000&ip=206.100.0.110&sessionType=APT&msgType=START HTTP/1.1[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:>> "Accept: text/plain[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:>> "User-Agent: SoapUI 4.5.1[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:>> "Connection: Keep-Alive[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:>> "Host: 138.132.115.21:80[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:>> "Accept-Encoding: gzip,deflate[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:>> "[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:<< "HTTP/1.1 200 OK[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:<< "Date: Thu, 28 Feb 2013 14:45:15 GMT[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:<< "Server: WebLogic Server 8.1 SP2 Fri Dec 5 15:01:51 PST 2003 316284 [\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:<< "Content-Length: 84[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:<< "Content-Type: text/html[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:<< "[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:<< "<?xml version="1.0" ?>[\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:<< "<ACA errorCode="5000">[\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:<< "<errorMessage></errorMessage>[\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:<< "</ACA>[\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:<< "[\n]"
When I used the HTTP Test Request to send the get request, I have the following groovy script to analyze the response:
import com.eviware.soapui.support.xml.XmlUtils
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
xmlResponseHolder = groovyUtils.getXmlHolder("ACCT START UMA#ResponseAsXML") //ACCT START UMA is the test step name
xmlBody = new XmlSlurper().parseText(xmlResponseHolder.getXml())
errorCode = xmlBody.@errorCode
def props = testRunner.testCase.getTestStepByName( "Properties" )
def cli = props.getPropertyValue("cli");
if ( errorCode != "5000" )
{
log.info("ACCT START UMA $cli - wrong errorCode: $errorCode")
testRunner.fail( "errorCode" )
}
How can now analyze the answer if i use the groovy script ?
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.GET
import static groovyx.net.http.ContentType.TEXT
def Indirizzo_F5_FE = context.expand( '${#Global#Indirizzo_F5_FE}' )
def Porta_F5_FE = context.expand( '${#Global#Porta_F5_FE}' )
def props = testRunner.testCase.getTestStepByName( "Properties" )
def cli = props.getPropertyValue("cli");
def ippresenza = props.getPropertyValue("ippresenza");
// log.info ("$Indirizzo_F5_FE, $Porta_F5_FE, $cli, $ippresenza")
def http = new HTTPBuilder( "http://${Indirizzo_F5_FE}:${Porta_F5_FE}/AuthInterface/acctRequest?cli=${cli}&ip=${ippresenza}&sessionType=APT&msgType=START" )
http.request(GET,TEXT) { req ->
headers.'Connection' = 'Keep-Alive'
headers.'User-Agent' = 'SoapUI 4.5.1'
response.success = { resp, reader ->
assert resp.status == 200
System.out << reader
}
}
The request is correctly sent, and in the soapui http.log is trace the request/answer:
Thu Feb 28 15:45:15 CET 2013:DEBUG:>> "GET /AuthInterface/acctRequest?cli=0804000000&ip=206.100.0.110&sessionType=APT&msgType=START HTTP/1.1[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:>> "Accept: text/plain[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:>> "User-Agent: SoapUI 4.5.1[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:>> "Connection: Keep-Alive[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:>> "Host: 138.132.115.21:80[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:>> "Accept-Encoding: gzip,deflate[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:>> "[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:<< "HTTP/1.1 200 OK[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:<< "Date: Thu, 28 Feb 2013 14:45:15 GMT[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:<< "Server: WebLogic Server 8.1 SP2 Fri Dec 5 15:01:51 PST 2003 316284 [\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:<< "Content-Length: 84[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:<< "Content-Type: text/html[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:<< "[\r][\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:<< "<?xml version="1.0" ?>[\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:<< "<ACA errorCode="5000">[\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:<< "<errorMessage></errorMessage>[\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:<< "</ACA>[\n]"
Thu Feb 28 15:45:15 CET 2013:DEBUG:<< "[\n]"
When I used the HTTP Test Request to send the get request, I have the following groovy script to analyze the response:
import com.eviware.soapui.support.xml.XmlUtils
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
xmlResponseHolder = groovyUtils.getXmlHolder("ACCT START UMA#ResponseAsXML") //ACCT START UMA is the test step name
xmlBody = new XmlSlurper().parseText(xmlResponseHolder.getXml())
errorCode = xmlBody.@errorCode
def props = testRunner.testCase.getTestStepByName( "Properties" )
def cli = props.getPropertyValue("cli");
if ( errorCode != "5000" )
{
log.info("ACCT START UMA $cli - wrong errorCode: $errorCode")
testRunner.fail( "errorCode" )
}
How can now analyze the answer if i use the groovy script ?