header
header
Main Menu
Home
Eviware Store
Downloads
Products
News
Forum
Eviware Blog
Search
FAQs
Customer Area
Support
Documentation
Tutorials
CookBook
Downloads
Forum
Login Form
Welcome, Guest. Please login or register.
January 08, 2009, 10:21:20 pm
Username: Password:
Login with username, password and session length

Forgot your password?
 
Replace "?" with default value in MockResponse using Groovy Script
Welcome, Guest. Please login or register.
January 08, 2009, 10:21:20 pm
Home Help Search Login Register
News: The Forums are up! Welcome to eviware.

+  Eviware Forum
|-+  soapUI
| |-+  soapUI
| | |-+  Replace "?" with default value in MockResponse using Groovy Script
« previous next »
Pages: [1] Print
Author Topic: Replace "?" with default value in MockResponse using Groovy Script  (Read 664 times)
apoorva
Newbie
*
Posts: 16


« on: July 03, 2008, 10:28:21 pm »

Hi All,

I created MockResponse for one of the operation in MockService.

By default, Default value for all elements in MockResponse is "?".
Now I want to insert some value instead of "?" in MockResponse using groovy script...

My MockResponse is looks like below

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <ns:getSidInformationResponse xmlns:ns="http://sidmgmt.com">
         <ns:return type="com.SidInfoResp"    xmlns:ax28="http://dto.group.com/xsd" xmlns:ax22="http://service.bds.com/xsd" xmlns:ax24="http://dto.sidmgmt.com/xsd" xmlns:ax26="http://dto.action.com/xsd" xmlns:ax21="http://sidmgmt.com/xsd">
            <ax21:devices type="com.sidmgmt.dto.Device">
               <ax24:api>?</ax24:api>               
               <ax24:language>?</ax24:language>
               <ax24:lastUsed>?</ax24:lastUsed>
   
               <!-- 1 or more occurence of licenses element -->
               <ax24:licenses type="com.sidmgmt.dto.License">                 
                    <ax24:itemName>?</ax24:itemName>
                    <ax24:itemVersion>?</ax24:itemVersion>
                    <ax24:lastEvent type="com.sidmgmt.dto.Event">                     
                             <ax24:customerId>?</ax24:customerId>
                             <ax24:custType>?</ax24:custType>                     
                             <ax24:eventSource xsi:nil=?  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>                     
                    </ax24:lastEvent>
                    <ax24:price>?</ax24:price>                                   
                    <ax24:priceMethod>?</ax24:priceMethod>
                    <ax24:type xsi:nil=? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
              </ax24:licenses>
          
            </ax21:devices>
            <ax21:results type="com.Result">
               <ax22:code>?</ax22:code>
               <ax22:message>?</ax22:message>
            </ax21:results>
            <ax21:sid>?</ax21:sid>
         </ns:return>
      </ns:getSidInformationResponse>
   </soapenv:Body>
</soapenv:Envelope>


I will appreciate if any input will be available.

Regards,
Jim
Logged
omatzura
Administrator
Hero Member
*****
Posts: 1,666


« Reply #1 on: July 04, 2008, 08:26:52 am »

Hi Jim,

you can use the Response Script (at the bottom of the MockResponse editor) to dynamically insert values into a response, just set the desired values in the context and then expand them in your response.. for example this script

context.randomNum = Math.random()

and this expansion in your mockresponse xml

<someElement>${randomNum}</someElement>

will return a mock response with a random number in the someElement..

Hope this helps!

regards,

/Ole
eviware.com
Logged
apoorva
Newbie
*
Posts: 16


« Reply #2 on: July 07, 2008, 09:50:45 pm »

Hi Ole,

Thanks for your reply... But I want to replace with specific value, not random one and  I write following script to do this

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( "Request 1#Response" )

holder.namespaces["ns"] = "http://sidmgmt.com/xsd"
def res = holder.getNodeValue( "//ns:results" )

def ret = groovyUtils.getXmlHolder(res)
ret.namespaces["ns1"] = "http://service.bds.com/xsd"
def codevalue = ret.getNodeValue( "//ns1:code" )
ret.setNodeValue("//ns1:code", "400") //not sure

I got following error
 com.eviware.soapui.impl.wsdl.mock.DispatchException: Failed to dispatch using script; java.lang.NullPointerException

Can you please suggest whats the suggested argument value in getXmlHolder to get access to mockResponse..


Thanks,
Jim
Logged
omatzura
Administrator
Hero Member
*****
Posts: 1,666


« Reply #3 on: July 08, 2008, 09:04:40 am »

Hi Jim

maybe you could just put


 <ax22:code>${code}</ax22:code>

into your response and then set

context.code = "400"

in the response script?

regards,

/Ole
eviware.com
Logged
Pages: [1] Print 
« previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
header header
header
header