Wiremock setup
Our current wiremock setup supports:
- Data loading when server is deployed from JSON data files with different endpoints.
- GUI to make temporary endpoints and edit existing endpoints.
Setup
1. Clone the repo from
- Clone the repository from https://git.sharedservices.cmgroep.local/connect/common/mock into your local computer.
2. Let’s understand the repo format.
- Mapping folders: There are two mapping folders for different mock servers in the root of the repo with the name “mappings-{mock name}“
- Dockerfiles: Each mocking server has their different docker file for copying the mapping data to respective server and deploy the modified image. Docker file name format is “{mock name}.Dockerfile“
Understanding wiremock:
Wiremock has the simplest way format to create mock endpoint and to see the documentation, follow this link https://wiremock.org/docs/
Here is the example of a basic endpoint
{
"request": {
"url": "/crm/salesforce/v1/orders",
"method": "GET"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"jsonBody": {
"orders": [
{
"order_number": "CMO1234",
"list_view": {
"order_number": "CMO1234",
"date": "29-01-2021 12:34",
"status": "In progress"
}
}
]
}
}
}
Here there are two parts where we define the configuration of the request and response of that. Follow this link to dive deep in formating the endpoints https://wiremock.org/docs/stubbing/
- Request: In this part we define what should be the configuration to hit this specific endpoint
- Url: It defines which url to map. Suppose, here the URL is
/crm/salesforce/v1/ordersand our server is running onhttps://localhost:8080then the complete request URL to hit this specific endpoint will behttps://localhost:8080/crm/salesforce/v1/orders - Method: We define the type of method here, it’s GET in this case but it can be GET, POST, PUT, PATCH, DELETE etc
- Url: It defines which url to map. Suppose, here the URL is
- Response: In this part we define what to return when the request comes with matching request parameters to this endpoint
- Status: It’s HTTP status codes of response, whether we want to make it success(200), not found(404), Bad request(400) etc.
- Header: header is a object where we define key value pair of response headers. In this case, as we wanted to send JSON response, we defined { “Content-Type“: “application/json“ }
- jsonBody: This is also a object where our response body is stored.
Of Course it supports URL mapping to, although it has limited capabilities.
- URL mapping in wiremock is done by some parameter change from URL to urlPattern/urlPath/urlPathPattern.
- More details you can find from this page https://wiremock.org/docs/request-matching/