Groovy in SOAP UI

6,127 views
5,919 views

Published on

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

Published in: Technology, Business
1 Comment
6 Likes
Statistics
Notes
No Downloads
Views
Total views
6,127
On SlideShare
0
From Embeds
0
Number of Embeds
743
Actions
Shares
0
Downloads
0
Comments
1
Likes
6
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 (ravireddy76@gmail.com)
  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-1.1.5.1 • SOAPRestClient (Custom jar file)Download and copy above jars (libraries) to lib of Soap UIinstallation folder show in the image.** Note : Ping me @: ravireddy76@gmail.com 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 (ravireddy76@gmail.com) 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 (ravireddy76@gmail.com) 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 = "http://mlaptop.ravi.net:8080/JerseyRestFul-DBCRUD- POC/services/customerService/addCustomer"; def createCustomerLogRef = "Create Customer Information::"; def customerJsonInput = buildJsonInput(); ClientResponse createCustomerResponse = serviceResoruces.postResponse(CREATE_CUSTOMER_ENDPOINT,customerJsonInput); log.info(createCustomerLogRef+"Response Status = "+createCustomerResponse.getStatus()); assert createCustomerResponse.getStatus() == 204 log.info("----------------------------------------------------------------------------------------------");  Update Customer def UPDATE_CUSTOMER_ENDPOINT = "http://mlaptop.ravi.net:8080/JerseyRestFul-DBCRUD- 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){ log.info("No Customer found for the given id to update."); }else { log.info("~~~~!!!! 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); log.info(updateStepLogRef+"Response Status = "+updateCustomerResponse.getStatus()); assert updateCustomerResponse.getStatus() == 204 } 4(C ) All copy rights to Ravi Reddy, Dilip (ravireddy76@gmail.com)
  5. 5.  Delete Customerdef deleteCustomerLogRef = "Delete Customer::";def DELETE_CUSTOMER_ENDPOINT = "http://mlaptop.ravi.net:8080/JerseyRestFul-DBCRUD- POC/services/customerService/deleteCustomer?customerId"+ IntegrationTestUtils.generateRangeRandomNumber(103,400);ClientResponse deleteCustomerResponse = serviceResoruces.deleteResponse(DELETE_CUSTOMER_ENDPOINT);log.info(deleteCustomerLogRef+"Response Status = "+deleteCustomerResponse.getStatus());if(deleteCustomerResponse.getStatus() == 204){ log.info("Customer Found To Delete."); assert deleteCustomerResponse.getStatus() == 204}else{ log.info("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){ log.info("No Customer found for the given id.");}else { String searchByIdResponseXml = customerSearchResponse.getEntity(String.class); log.info(searchByIdResponseXml); assert customerSearchResponse.getStatus() == 200} 5(C ) All copy rights to Ravi Reddy, Dilip (ravireddy76@gmail.com)
  6. 6.  Find All Customer def SEARCH_ALL_CUSTOMERS_ENDPOINT = "http://mlaptop.ravi.net:8080/JerseyRestFul-DBCRUD- POC/services/customerService/getAllCustomers"; def searchAllLogRef = "Search All Customers::"; ClientResponse searchAllResponse = serviceResoruces.getResponse(SEARCH_ALL_CUSTOMERS_ENDPOINT); log.info(searchAllLogRef+"Response Status = "+searchAllResponse.getStatus()); assert searchAllResponse.getStatus() == 200 String searchResponseXml = searchAllResponse.getEntity(String.class); log.info("~~!!!! RESPONSE XML For All Customers !!!!~~~~"); log.info(searchResponseXml); ** If you want full groovy script and SOAPRestClient jar please send me e-mail to ravireddy76@gmail.com. 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 (ravireddy76@gmail.com)

×