Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<p>This page discusses <table class="wysiwyg-macro" data-macro-name="excerpt" data-macro-parameters="atlassian-macro-output-type=INLINE" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2V4Y2VycHQ6YXRsYXNzaWFuLW1hY3JvLW91dHB1dC10eXBlPUlOTElORX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>how to test Web Services using Groovy directly and in conjunction with WebTest and SoapUI</p></td></tr></table>.</p> <p>Testing Web Services can be done in several ways. Here are three:</p> <ul> <li>act like a normal web services client and perform asserts on the returned result</li> <li>use <a href="http://webtest.canoo.com">WebTest</a> (with either the XML or Groovy syntax)</li> <li>use <a href="http://soapui.org">SoapUI</a> (for functional and load testing)</li> </ul> <p>We are going to use the Web Service example at:</p> <p> <a href="http://groovy.codehaus.org/Groovy+SOAP">http://groovy.codehaus.org/Groovy+SOAP</a></p> <h2>Being a client</h2> <p>You can be a normal client web service client and perform asserts on the returned results:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> import groovy.net.soap.SoapClient def proxy = new SoapClient("http://localhost:6980/MathServiceInterface?wsdl") def result = proxy.add(1.0, 2.0) assert (result == 3.0) result = proxy.square(3.0) assert (result == 9.0) </pre></td></tr></table> <h2>Using WebTest</h2> <p>Using the WebTest variations makes sense if you are combining your tests into an acceptance test suite.</p> <p>Here is how you would test it using traditional WebTest:</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="xml" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6eG1sfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> <steps> <invoke method="POST" contentFile="addreq.xml" soapAction="" url="http://localhost:6980/MathServiceInterface"/> <verifyXPath xpath="//addResponse/out[ text()='3.0' ]"/> <invoke method="POST" contentFile="squarereq.xml" soapAction="" url="http://localhost:6980/MathServiceInterface"/> <verifyXPath xpath="//squareResponse/out[ text()='9.0' ]"/> </steps> </pre></td></tr></table> <p>Where addreq.xml would look something like:</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="xml" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6eG1sfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> <?xml version='1.0' encoding='UTF-8'?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soap:Body> <add xmlns="http://DefaultNamespace"> <in0 xmlns="http://DefaultNamespace">1.0</in0> <in1>2.0</in1> </add> </soap:Body> </soap:Envelope> </pre></td></tr></table> <p>and squarereq.xml would look something like:</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="xml" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6eG1sfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> <?xml version='1.0' encoding='UTF-8'?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soap:Body> <square xmlns="http://DefaultNamespace"> <in0 xmlns="http://DefaultNamespace">3.0</in0> </square> </soap:Body> </soap:Envelope> </pre></td></tr></table> <p>Alternatively, testing using groovy within WebTest would look like:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> <steps> <groovy> import groovy.net.soap.SoapClient def proxy = new SoapClient("http://localhost:6980/MathServiceInterface?wsdl") def result = proxy.add(1.0, 2.0) assert (result == 3.0) result = proxy.square(3.0) assert (result == 9.0) </groovy> </steps> </pre></td></tr></table> <p>Note: you will need to place the jars mentioned on that page in your webtest lib directory (i.e. groovysoap, stax, jaf and mail jars) when using this variation.</p> <p>The first approach (traditional webtest) produces more information in the test summary reporting but requires you to do more work (i.e. keep the requests around as XML). It depends if you already have those XML files around for other purposes, e.g. manual testing.</p> <h2>Using SOAPUI</h2> <p><a href="http://soapui.org/">soapui</a> is a SOAP functional and load testing tool. It can use Groovy steps within its testcases. For further details, see the soapui documentation for the <a href="http://soapui.org/userguide/functional/groovystep.html">Groovy Step</a>. This step supports data-driven tests, allows control of test execution and allows customised reporting.</p> <p><img class="confluence-embedded-image" src="/download/attachments/231080033/screenshot_soapui.gif?version=1&modificationDate=1369248628028" data-image-src="/download/attachments/231080033/screenshot_soapui.gif?version=1&modificationDate=1369248628028" data-linked-resource-id="231375273" data-linked-resource-type="attachment" data-linked-resource-default-alias="screenshot_soapui.gif" data-base-url="http://docs.codehaus.org" data-linked-resource-container-id="231080033" title="null > screenshot_soapui.gif"></p>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced