How to Mock SOAP Web Service Using SoapUI?
SoapUI is an open-source testing tool used to test both REST(Representational State Transfer) and SOAP(Simple Object Access Protocol) web services. SoapUI provides the soap service mocking feature which allows to simulate a SOAP-based web service. This helps enterprise-level applications create web service prototypes to test various scenarios without creating the actual service. This feature can be leveraged to set up multiple responses for a mock service with custom HTTP Headers, attachments, and other data to test different incoming requests. This article demonstrates a step-by-step guideline to mock a soap web service:
Stepwise Implementation
Step 1: Create a new SOAP project by clicking on the SOAP icon present in the toolbar as shown below.
Step 2: Specify the project name and the required WSDL Web URL in the appeared dialog box and then click on OK.
In this example, we are going to name our soap project as TemperatureConversion and make use of below mentioned WSDL Web URL.
Step 3: Expand the SOAP project created and right-click on any soap interface. Click on Generate SOAP MockService to create the mock service.
Generate MockService dialog appears which contains operations, path, and port pre-configured for the mock service. Click on Ok to proceed.
Specify the name of the MockService to be created and click OK. In this example, we are naming the mock service as TempConvertSoap-MockService
Within the soap project, a soap mock service is created along with a list of operations.
Step 4: Double-click on the mock service to open the mock service editor as below. It displays the list of operations included in the mock service.
Double-click on any operation to get a list of responses associated with that operation. In this example, we are using the CelciusToFahrenheit SOAP interface.
Step 5: Double-click on the response to open the Response Editor containing the XML-based response of the web service as shown below.
The left side section displays the last incoming request this service has received along with the header and attachment details. On the right side section, the response of the web service is displayed which can be edited. The question mark in the response can be replaced with the value needed to be returned in the response. In this example, we are setting the value to 98.6.
Step 6: To start the web service, click on the green play button to start the mock service.
Once the green play button is clicked, the SOAP MockService starts running as shown below.
It specifies the port it is running. The red square button can be used to stop the mock service.
Steps To Test The MockService
In order to check whether the soap service is working properly please follow below steps:
Step 1: Create a new soap request by clicking on the button as shown below.
Step 2: A pop-up dialog appears which allows you to either select an existing request from the dropdown or create a new request. Select the request for the operation to open or create and then click on Ok to proceed.
A Request Editor is opened which can be used to edit the XML-based request of the mock service.
Step 3: Click on the green play button to send the request to the mock service.
Once the green play button is clicked, a request is sent to the MockService created and we get a response as shown below.