-1

I need to add custom helper functions in wiremock which generates a string as per input value in query string. Need to add multiple functions. looking for working sample on this.

vijayakumar
  • 21
  • 1
  • 6

1 Answers1

2
//I am able to get the sample code working
            Helper<String> serialNumberHelper = new Helper<String>() {
                // @Override    Helper<String> stringLengthHelper = new Helper<String>() {
                    // @Override
                    public Object apply(String context, Options options)
                            throws IOException {
                        return context.length();
                    }
                };
                public Object apply(String context, Options options)
                        throws IOException {
                    return context.substring(2);
                }
            };

            Map<String, Helper> helpers = new HashMap<String, Helper>();
            helpers.put("GetLength", stringLengthHelper);
            helpers.put("GetSerialNumber", serialNumberHelper);

            wireMockServer = new WireMockServer(
                    wireMockConfig().port(8080).options().extensions(
                            new ResponseTemplateTransformer(false, helpers))); 
// and able to use the same in response.

            wireMockServer
                    .stubFor(get(urlMatching("/vis/([a-z]*)\\?unitid=([0-9]*)"))
                            .willReturn(aResponse()
                                    .withHeader("Content-Type", "text/plain")
                                    .withBody(
                                            "{{GetSerialNumber request.query.unitid.[0]}}")
                                    .withTransformers("response-template")));
vijayakumar
  • 21
  • 1
  • 6