Reputation: 2195
I'm using Wiremock and during a test I want to edit a mock that was defined at startup in a JSON file inside /mappings directory (a default mock).
I know that I can define an UUID in the JSON file, but I'm looking for something that is human readable (it is probably not a good idea to mention a meaningless UUID inside a test). I saw that I can define a name, but how can I edit a mock using its name?
Thanks
Upvotes: 0
Views: 2567
Reputation: 7163
You can use a combination of metadata and WireMock's Admin API.
...
"metadata": {
"name": "My Mapping"
}
...
Then using the find stub mappings by metadata, you can retrieve an array of matched objects.
POST /__admin/mappings/find-by-metadata
{
"matchesJsonPath" : {
"expression" : "$.name",
"contains" : "My Mapping"
}
}
You can parse the response for a specific UUID, and finally update a stub mapping by UUID.
Alternatively, you could query the Admin API for all mappings and find the one that matches the one you want, but I find filtering by metadata a little easier to use.
Additionally, depending on your language of use for tests, you could make something like an enum that maps a human-readable name ("My Mapping") to a UUID, and skip the step where you have to find the stub by metadata/parse all mappings, instead just using that enum value to update the stub.
Upvotes: 1