Mock Web Service With soapUI

Mock Web Service With soapUI explains about how to create mock service using soapUI
Mock service is a dummy or approximate implementation of actual webservice, it helps you to simulate the service before actual webservice is developed
When & Why Mock Web Service Required?
If your webservice (WSDL) is done by some third parties and, you only got WSDL with some sample request/response. In this situation you can use mock service with soapUI, because our aim is to start the development without waiting for the other team to complete the service.
In this Mock web service with soapUI example we are using Groovy script for testing complex test cases
Required Libraries
You need to download
Select File->New soapUI Project, just provide a name and browse WSDL from file system
Generate MockService as per below screenshot
You can change the port and name binding here
You can modify the MockService name
Create New MockResponse, Here I am creating 3 dummy responses as Sony,Rockey,Rose
You can modify the MockResponse on this window
Here I am creating 3 dummy responses as Sony,Rockey and Rose
Here I have edited the name as Sony (You need to repeat this step for all 3 responses like Sony,Rockey and Rose)
Starting the MockService with soapUI
Just browse http://localhost:8080, you can view the running service
Paste the below code in Groovy inside MockOperation Editor
def xmlHolder = new com.eviware.soapui.support.XmlHolder( mockRequest.requestContent ) def namePrefix = xmlHolder["//*[local-name()='name']"] log.info("Search request with name prefix:" + namePrefix) if (namePrefix == 'Rockey') { return 'Rockey' } else if (namePrefix == 'Rose') { return 'Rose' } else { return 'Sony' }
You need to modify the endpoint (See the screenshot)
Run service as Rockey, you can see the output, also try with request as Sony and Rose too,,