A Coder's Blog
SoapUI provides a feature to create mock services. Suppose you have to integrate your application with a third party service based on a WSDL. Maybe, for some reasons, you don’t want to call the real service, or the real service is still under development.
SoapUI, with the mock service feature, allows you to create a fake service that simulates the real one.
Let’s suppose we have to call a web service dedicated to retrieve stock item information such as the availability of a product in the storehouse and, unfortunately, the service is still under development.
So we retrieve or we get provided with the WSDL. In SoapUI we create a new SoapUI project importing the WSDL.
Then SoapUI will create automatically the interfaces for the real service.
Now, in order to create a mock service,right click on the interface and click on “generate mock service”
Now, we can create the responses for the specific service methods:
The last thing we need to do is to dinamically rout the request to the desired response.
We can select a response based on the request content. In order to achieve this we could create a simple script.
Double click on the service method, as a dispatch method we select “script”. With an XPath query we retrieve the itemCode and based on that value we return the desired response.
To run the script click on green arrow
Start the mock service: double click on the service and click on the start arrow
Submit a request: right click on the service method, click “open request”, modify your imput parameters and click on the submit arrow.