I use Wiremock Standalone.
I have a query to retrieve product information /api/product/{id} A simplified view of the stub for this query:
{
"request": {
"urlPattern": "/api/product/([0-9]/*)",
"method": "GET"
},
"response": {
"status": 200,
"jsonBody": {
"data": {
"id": "{{request.path.[3]}}",
"name": "product name",
"warehouse_id": "{{randomInt lower=1}}",
...
}
}
}
}
I also have a query to get information about warehouses /api/warehouse/ It returns a list of all warehouses. A simplified view of the stub for this query:
{
"request": {
"urlPattern": "/api/warehouse/",
"method": "GET"
},
"response": {
"status": 200,
"jsonBody": {
"data": [
{
"id": "{{randomInt lower=1}}", // I want to return here not a
// random number, but the value of warehouse_id generated in the
// response for /api/product/{id}
"address": "John av. 12",
"capacity": 1000
},
{
"id": "{{randomInt lower=1}}",
"address": "Vernon ave 79",
"capacity": 500
},
...
]
}
}
}
Inside the logic of my program I have a need to get not only the id of the warehouse, but also the address of the warehouse.
To do this, my code makes a query to get information about the product itself, and then makes a query to get all the warehouses and takes the address of the desired warehouse by the id of the warehouse.
But such an attempt doesn't work with the current stub implementation, because random id's are always generated in the response with the list of warehouses.
For this I want the stub for /api/warehouse/ for the first element in the "data" in the id field to return not a random number, but the one that was generated in the warehouse_id field when calling /api/product/{id}.
In other words I want to store the value generated in the /api/product/{id} query in the warehouse_id field and reuse it in the /api/warehouse/ query for some warehouse in the id field
How can this be done? I tried to find information about saving values in the documentation but couldn't find it