Tuesday, December 24, 2013

How to publish Mock Service with SoapUI

Overview

SoapUI is well known tool for manipulating different tests with web services and rest services. This post will discuss about mock service and applicability of mock services in your service based projects.

What is Mock service

When you developing a project with web service or rest service you will have the WSDL for web service or WADL for rest service. But there may not be a published service with those service descriptors. So you have to write slimier service and publish it on server(localhost) and then use WADL or WSDL for calling those services. It is a time consuming and more problems will have to be faced in future( eg . if any changes to WSDL then rewrite it again) .

Concept of mock service is simple. mock service is a service generate from your service descriptor which will act as real service. It will take slimier input  and output defined messages. It will not do the operation just act as service getting input and provide some output with give message type.

How to create mock service with SoapUI.

Here I have used soapUI 3.5. First launch soapUI and You will see creating new soapui window. If not go to File>> New soapUI project.

  
Then browse path to WSDL file you need to generate mock service. Here I have used HelloWorld.wsdl in my computer which output  "Hello "  + input string. You can add any WSDL you own . After that you will see project name automatically filled with service name. You can specify own project name. After click on OK you will see project structure as below. 


So project structured as

  Project >> Interface >> Operation >> Request

Right click on interface and select generate mock service as below.
Default port is 8088 .If it is conflict you have to specify the different port. Then select operation if it is not selected. 

 You can edit mock service name.

Once mock service is created it is structured as Mock service >> Operation >> Response

Click on mock service and click  |> to start the mock service.
If there is no port conflict it will run as below.

Now you have running mock service. click on response and edit output for your own output.

Now click on soap button left side in the response window and it will ask the request to use. You can select the request.(default)


Now you will see the generated request for your mock service .Once you run the request it will output response what you specified in the earlier step.


You can get the web service address in the upper side of the window as below.
http://wso2-ThinkPad-T530:8088/mockHelloServiceSOAP

When you run the WSDL in another project you can change the address with moch service address.

<wsdl:service name="mockService">
    <wsdl:port binding="tns:mockServiceSOAP" name="mockServiceSOAP">
      <soap:address location="http://wso2-ThinkPad-T530:8090/mockmockServiceSOAP"/>
    </wsdl:port>
  </wsdl:service>


No comments :

Post a Comment