{"id":455,"date":"2009-10-19T12:25:55","date_gmt":"2009-10-19T16:25:55","guid":{"rendered":"http:\/\/www.pressleypress.com\/blog\/?p=455"},"modified":"2013-01-07T14:32:55","modified_gmt":"2013-01-07T18:32:55","slug":"getting-soapui-to-pass-back-a-value-from-a-request-using-a-mock-service","status":"publish","type":"post","link":"https:\/\/www.pressleypress.com\/blog\/?p=455","title":{"rendered":"Getting SOAPUI to Pass Back a Value froma Request Using a Mock Service"},"content":{"rendered":"<p>If need a Mock Service to reply to a SOAP request with a value from that request, here&#8217;s the Groovy script to do it. (<a href=\"http:\/\/groovy.codehaus.org\/\">Groovy<\/a> is a scripting language that can be run in the Java JVM. SOAPUI has it built in.) <\/p>\n<p>1) Select your Mock Service in SOAPUI<br \/>\n2) Select the Mock Service operation<br \/>\n3) Select the appropriate Mock Service response<br \/>\n4) Click the &#8220;Script&#8221; tab at the bottom of the response editor window<br \/>\n5) Paste the following code into the script editing pane, substituting your values<br \/>\n<code><br \/>\ndef groovyUtils = new com.eviware.soapui.support.GroovyUtils( context)<br \/>\ndef holder = groovyUtils.getXmlHolder(mockRequest.requestContent)<br \/>\ndef id = String.valueOf(holder.getNodeValue(\"<strong>THE NODE CONTAINING THE VALUE YOU WANT TO REPLY WITH HERE<\/strong>\")<br \/>\nContext.setProperty(\"<strong>PARAMETER NAME HERE<\/strong>\", id)<br \/>\n<\/code><\/p>\n<p>So basically you&#8217;re pulling the value from the node you define in line 3, into the variable called &#8220;id&#8221;. You&#8217;re then assigning the value of &#8220;id&#8221; to the parameter you define in line 4. You then insert the parameter into your response message and viola! <\/p>\n<p>For example if the node you wanted to pull the value from was a node called &#8220;Name&#8221;, and the parameter you wanted to use was &#8220;nameid&#8221; then your code would look like this :<\/p>\n<p>def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context)<br \/>\ndef holder = groovyUtils.getXmlHolder(mockRequest.requestContent)<br \/>\ndef id = String.valueOf(holder.getNodeValue(&#8220;Name&#8221;))<br \/>\ncontext.setProperty(&#8220;nameid&#8221;, id)<\/p>\n<p>You&#8217;d then put ${nameid} into your MockService response.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If need a Mock Service to reply to a SOAP request with a value from that request, here&#8217;s the Groovy script to do it. (Groovy is a scripting language that can be run in the &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_seo_schema_type":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[3],"tags":[16],"class_list":["post-455","post","type-post","status-publish","format-standard","hentry","category-computers","tag-soapui"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p32FB4-7l","jetpack-related-posts":[{"id":781,"url":"https:\/\/www.pressleypress.com\/blog\/?p=781","url_meta":{"origin":455,"position":0},"title":"Need a UUID for use in SOAPUI?","author":"Matt","date":"May 11, 2012","format":false,"excerpt":"Create a property using a Groovy Script test step with the following line : def property = java.util.UUID.randomUUID() or let SOAPUI parse it in-line : ${=java.util.UUID.randomUUID()}","rel":"","context":"In &quot;Computers&quot;","block_context":{"text":"Computers","link":"https:\/\/www.pressleypress.com\/blog\/?cat=3"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":587,"url":"https:\/\/www.pressleypress.com\/blog\/?p=587","url_meta":{"origin":455,"position":1},"title":"Use Epoch Time in SOAPUI as a unique value","author":"Matt","date":"May 13, 2010","format":false,"excerpt":"Want SOAPUI to insert epoch time into your request to be used as a unique value when the request is submitted? Use the following string in your SOAP request and epoch time will be inserted in its place! ${= System.currentTimeMillis() }","rel":"","context":"In &quot;Computers&quot;","block_context":{"text":"Computers","link":"https:\/\/www.pressleypress.com\/blog\/?cat=3"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":609,"url":"https:\/\/www.pressleypress.com\/blog\/?p=609","url_meta":{"origin":455,"position":2},"title":"SOAPUI &#8211; Generating a Random Value","author":"Matt","date":"August 31, 2010","format":false,"excerpt":"By placing the following property expansion in your SOAP request in SOAPUI, a random number between 0 and 50,000 will be inserted in it's place. ${=(int)(Math.random()*50000)}","rel":"","context":"In &quot;Computers&quot;","block_context":{"text":"Computers","link":"https:\/\/www.pressleypress.com\/blog\/?cat=3"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":708,"url":"https:\/\/www.pressleypress.com\/blog\/?p=708","url_meta":{"origin":455,"position":3},"title":"Property Expansion in SOAPUI","author":"Matt","date":"October 19, 2011","format":false,"excerpt":"From groovyinsoapui.wordpress.com : Accessing variable values on the go while sending SOAP request to some service, might solve many problems at times. In SOAP UI, there are two ways to accomplish this i) Using \u2018Property Transfer\u2019 step ii) Using \u2018Property Expansion\u2019 accordingly wherever required. Here I am explaining this procedure\u2026","rel":"","context":"In &quot;Computers&quot;","block_context":{"text":"Computers","link":"https:\/\/www.pressleypress.com\/blog\/?cat=3"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":793,"url":"https:\/\/www.pressleypress.com\/blog\/?p=793","url_meta":{"origin":455,"position":4},"title":"SOAPUI Oracle Thin Client Format","author":"Matt","date":"October 3, 2012","format":false,"excerpt":"jdbc:oracle:thin:{schema name}\/{password}@{hostname}:1521:{instance name}","rel":"","context":"In &quot;Computers&quot;","block_context":{"text":"Computers","link":"https:\/\/www.pressleypress.com\/blog\/?cat=3"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":649,"url":"https:\/\/www.pressleypress.com\/blog\/?p=649","url_meta":{"origin":455,"position":5},"title":"SOAPUI &#8211; Catching Test Case Completion Time","author":"Matt","date":"January 10, 2011","format":false,"excerpt":"To capture how long it took a particular test case to complete, use the following property expansion in your DataSink. ${=testRunner.TimeTaken} The result is in milliseconds. It is the sum of the time taken by all test steps during the execution of your test case.","rel":"","context":"In &quot;Computers&quot;","block_context":{"text":"Computers","link":"https:\/\/www.pressleypress.com\/blog\/?cat=3"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.pressleypress.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/455","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pressleypress.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pressleypress.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pressleypress.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pressleypress.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=455"}],"version-history":[{"count":10,"href":"https:\/\/www.pressleypress.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/455\/revisions"}],"predecessor-version":[{"id":959,"href":"https:\/\/www.pressleypress.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/455\/revisions\/959"}],"wp:attachment":[{"href":"https:\/\/www.pressleypress.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pressleypress.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pressleypress.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}