Wiremock response of a certain regex

327 Views Asked by At

I have to send a random value back from wiremocked response. I have seen examples using {{randomValue type='ALPHANUMERIC'}}

However I could not find anything where I can give randomvalue of a particular regex - say alphanumeric value which starts with ABC and 9 random digits.

I did try -

{{randomValue regex='ABC[0-9]{9}'}}

But this is not working. I am not sure if there is any other way to do this.Please guide me to any appropriate resource if available.

1

There are 1 best solutions below

0
On

The only way to do this currently is via a custom Handlebars helper.

You can provide custom helpers when creating the templating transformer during startup e.g.

WireMockServer wm = new WireMockServer(wireMockConfig()
  .dynamicPort()
  .extensions(new ResponseTemplateTransformer(
    false,
    Collections.singletonMap("myHelper", new MyHelper()))
  )
);

Where MyHelper should extend the HandlebarsHelper abstract class.