I'm using Wiremock with a client calling the OSISoft PI Web API and I'm having issues matching against the POST body to the request defined here as with Wiremock the POST body will have a URL containing the randomly generated port. e.g.
{
"1": {
"Method": "POST",
"Resource": "http://localhost:24353/piwebapi/assetdatabases/D0NxzXSxtlKkGzAaZhKOB-KABJ2buwfWrkye3YhdL2FOUAUEhMQUZTMDRcQgYUUEVSRk9STUFOQ0UgVEVTVElORw/elements",
"Content": "{\"Name\":\"New Element\"}"
}
}
How can I match against the URL in the Resource element where the port number will change between test runs? Obviously I cannot use templating for requests like I would with responses.
From reviewing the docs on request matching I see that using equalToJson
with placeholders or matchesJsonPath
with a regex expression may be an option but I'm not clear on the exact syntax. Or is there a simpler option that I'm missing?
From wiremock-user Google Group
If you don't need to match anything in particular for that element you could use a JSON placeholder e.g.
"Resource": "${json-unit.any-string}".
If you do need to match the part after the port number then you can use the regex form e.g.:
"Resource": "${json-unit.regex}.*/piwebapi/assetdatabases/D0NxzXSxtlKkGzAaZhKOB-KABJ2buwfWrkye3YhdL2FOUAUEhMQUZTMDRcQgYUUEVSRk9STUFOQ0UgVEVTVElORw/elements"}"