How To Create Mock Web Service In Soapui
SoapUI- Mocking REST APIs Part 1
If you are working on an integration project which deals with different teams, departments or third party systems, you may often come across the situation to use the REST APIs developed and exposed by the other internal teams/department or third party systems.
These APIs either would have been already developed or the y are being developed while your development work starts in parallel. In both cases , APIs will have success responses as well as error responses. Therefore when writing code or configuring any integration tools to consume APIs, we need to handle all the possible responses from the API which is getting integrated.
In order to understand the request and responses of an API, always recommended to get the APIs behavior documented by the internal development team/department or third party. OpenAPI specification(Swagger) is a well adopted and widely used documentation method to describe REST APIs.
Once we received finalized version of OpenAPI specification, we can start integrating the API with our system. In this point we need to test all the possible request and response scenarios for the API. But it is not always possible to simulate the each responses with real API endpoint. For example if we want to handle the Internal Server Error (HTTP 500) scenario of an real API, we need to ask the API provider to produce this error for us, which is not practical. Also if the APIs being developed by other team based on the OpenAPI definition, we cant hold on our development till they finish, due to tight time lines.
Creating the Mock REST APIs with given OpenAPI specification would help us to test all positive and negative flows of the APIs as well as it will help start integration in parallel to API development by other team. Nowadays creating mock services or APIs is very easy with using mock servers and tools.
In this post we are going to see, how to create REST API mock services using SoapUI tool.
- Create a project and import Open API specification. Using PetStore OpenAPI specification as sample.
- Right click the on imported API project and select Generate Rest Mock Service, which will prompt a window to enter mock service name as below.
Enter the name and save which will generate the mock service for all the resources in the imported API project.
3. Created Mock service is running on default port 8090. We can change the port as we need by clicking the wheel button in the mock service window and change the value.
- Stop the running service
- Open the setting by clicking the wheel icon, which will pop up the setting options. Change the port as you want here. You can even add base context path to mock API here if needed.
- Save the changes and run the API. Now mock API will run on provided port
Now we have created Mock API with few simple clicks and configuration. Next we need to mock the responses of every API resources according to the OpenAPI specification given. Next post SoapUI- Mocking REST APIs Part 2 will cover the detail on creating mock responses.
How To Create Mock Web Service In Soapui
Source: https://medium.com/@Jenananthan/soapui-mocking-rest-apis-part-1-1e69eaf67beb
Posted by: hendricksonfalmyst64.blogspot.com
0 Response to "How To Create Mock Web Service In Soapui"
Post a Comment