Groovy in SOAP UI


Published on

Tutorials to write Restful service integration test using Groovy in SOAP UI

Published in: Technology, Business
1 Comment
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Groovy in SOAP UI

  1. 1. Groovy Tutorials With SOAP UI 1(C ) All copy rights to Ravi Reddy, Dilip & Abdur (
  2. 2. Presentation to illustrate to write web service integration test usinggroovy in soap UI. I’m unable to find a valuable solutions in online forums to write a simple integration tests for web services. Here I want demonstrate how to write services integration test for restful end points using groovy in SOAP UI for simple CRUD operations.Tools 2 Use C:Program Files (x86)SmartBearsoapUI-4.0.1 • SOAP-UI • Jersey (JAX-RS) API’s • jersey-client-1.8 • jersey-core-1.8 • jersey-server-1.8 • jersey-test-framework- • SOAPRestClient (Custom jar file)Download and copy above jars (libraries) to lib of Soap UIinstallation folder show in the image.** Note : Ping me @: SOAPRestClient is custom jar file which consists of wrapper class to consume REST end points for POST/PUT/DELETE/GET operations.(C ) All copy rights to Ravi Reddy, Dilip ( 2
  3. 3. » Create a REST end point project in SOAP UI tool which is shown in below image  Create a Test Suite called “ServiceIntegration-TestSuite”.  Create a test case (Example: CustomerService-IntegrationTest show in image)  Create a new Groovy script as a test case. In above example I’m showing a example for CRUD (Create, Read, Update, Delete) operations for a customer service.(C ) All copy rights to Ravi Reddy, Dilip ( 3
  4. 4. Below examples presenting CRUD operations for customer service integration test using groovy script in SOAP UI ** Note : use your REST end point with appropriate input either JSON/XML format.  Create Customer def CREATE_CUSTOMER_ENDPOINT = " POC/services/customerService/addCustomer"; def createCustomerLogRef = "Create Customer Information::"; def customerJsonInput = buildJsonInput(); ClientResponse createCustomerResponse = serviceResoruces.postResponse(CREATE_CUSTOMER_ENDPOINT,customerJsonInput);"Response Status = "+createCustomerResponse.getStatus()); assert createCustomerResponse.getStatus() == 204"----------------------------------------------------------------------------------------------");  Update Customer def UPDATE_CUSTOMER_ENDPOINT = " POC/services/customerService/updateCustomer"; def updateStepLogRef = "Update Customer Step::"; ClientResponse searchCustomerForUpdate = getCustomerSearchResponse(); /* Validate for whether customer information found or not for the given the ID to update.*/ if(searchCustomerForUpdate.getStatus() == 204){"No Customer found for the given id to update."); }else {"~~~~!!!! Customer Information is Updated !!!!~~~~"); /* Format the json structure for update operation.*/ String searchByIdForUpdate = searchCustomerForUpdate.getEntity(String.class); def jsonForUpdate = formatJsonStructure(searchByIdForUpdate); ClientResponse updateCustomerResponse = serviceResoruces.putResponse(UPDATE_CUSTOMER_ENDPOINT,jsonForUpdate);"Response Status = "+updateCustomerResponse.getStatus()); assert updateCustomerResponse.getStatus() == 204 } 4(C ) All copy rights to Ravi Reddy, Dilip (
  5. 5.  Delete Customerdef deleteCustomerLogRef = "Delete Customer::";def DELETE_CUSTOMER_ENDPOINT = " POC/services/customerService/deleteCustomer?customerId"+ IntegrationTestUtils.generateRangeRandomNumber(103,400);ClientResponse deleteCustomerResponse = serviceResoruces.deleteResponse(DELETE_CUSTOMER_ENDPOINT);"Response Status = "+deleteCustomerResponse.getStatus());if(deleteCustomerResponse.getStatus() == 204){"Customer Found To Delete."); assert deleteCustomerResponse.getStatus() == 204}else{"Customer Not Found To Delete."); assert deleteCustomerResponse.getStatus() == 500} Find Customerdef searchByIdLogRef = "Search Customer By Id::";ClientResponse customerSearchResponse = getCustomerSearchResponse();/* Validate for whether customer information found or not for the given the ID.*/if(customerSearchResponse.getStatus() == 204){"No Customer found for the given id.");}else { String searchByIdResponseXml = customerSearchResponse.getEntity(String.class);; assert customerSearchResponse.getStatus() == 200} 5(C ) All copy rights to Ravi Reddy, Dilip (
  6. 6.  Find All Customer def SEARCH_ALL_CUSTOMERS_ENDPOINT = " POC/services/customerService/getAllCustomers"; def searchAllLogRef = "Search All Customers::"; ClientResponse searchAllResponse = serviceResoruces.getResponse(SEARCH_ALL_CUSTOMERS_ENDPOINT);"Response Status = "+searchAllResponse.getStatus()); assert searchAllResponse.getStatus() == 200 String searchResponseXml = searchAllResponse.getEntity(String.class);"~~!!!! RESPONSE XML For All Customers !!!!~~~~");; ** If you want full groovy script and SOAPRestClient jar please send me e-mail to Also mean time I will try to upload the required libraries (jar) and code in GitHub. Authors Ravi Reddy Dilip Ladhani 6(C ) All copy rights to Ravi Reddy, Dilip (