Quantcast
Channel: New board topics in SmartBear Community
Viewing all articles
Browse latest Browse all 21061

Using Groovy to return a MockResponse based on validation of the request

$
0
0

Dears,

 

I want to fill MockResponse value based on input Mockrequest values. Therefor I read the xml and test it.

If certain conditions are met, I'll fill the value one by one on the response. The input and outpout structure are the same.

 

Hereunder the MockRequest structure.

 

I write the following groovy script in the MochtResponse tab-script but it says to me "No values were rertuned"

 

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( mockRequest.requestContent )
holder.namespaces["ns"] = "http://demo.cgisap.com"
def Var_age =  holder.getNodeValue("//age")
requestContext.age = Var_age

 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:demo="http://demo.cgisap.com">
   <soapenv:Header/>
   <soapenv:Body>
      <demo:MT_FirstName>
         <!--Optional:-->
         <ConnId>gero et</ConnId>
         <!--Optional:-->
         <firstname>sonoras imperio</firstname>
         <!--Optional:-->
         <lastName>quae divum incedo</lastName>
         <!--Optional:-->
         <age>100</age>
         <!--Optional:-->
         <adress1>verrantque per auras</adress1>
         <!--Optional:-->
         <adress2>per auras</adress2>
         <!--Optional:-->
         <city>circum claustra</city>
         <!--Optional:-->
         <country>nimborum in</country>
      </demo:MT_FirstName>
   </soapenv:Body>
</soapenv:Envelope>

 

In the MockResponse structure, I'll use for example ${age}

 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:demo="http://demo.cgisap.com">
   <soapenv:Header/>
   <soapenv:Body>
      <demo:MT_FirstName>
         <!--Optional:-->
         <ConnId>gero et</ConnId>
         <!--Optional:-->
         <firstname>sonoras imperio</firstname>
         <!--Optional:-->
         <lastName>quae divum incedo</lastName>
         <!--Optional:-->
         <age>${age}</age>
         <!--Optional:-->
         <adress1>verrantque per auras</adress1>
         <!--Optional:-->
         <adress2>per auras</adress2>
         <!--Optional:-->
         <city>circum claustra</city>
         <!--Optional:-->
         <country>nimborum in</country>
      </demo:MT_FirstName>
   </soapenv:Body>
</soapenv:Envelope>

 

Has anybody an idea what's wrong with the script, as I get no syntax errors however the value of the "age" node is not read ?

 

Much appreciated for your help,

Bas


Viewing all articles
Browse latest Browse all 21061

Trending Articles