【问题标题】:add custom string helpers in wiremock在wiremock中添加自定义字符串助手
【发布时间】:2017-11-07 19:11:11
【问题描述】:

我需要在wiremock 中添加自定义帮助函数,它会根据查询字符串中的输入值生成一个字符串。 需要添加多个功能。 正在寻找这方面的工作样本。

【问题讨论】:

    标签: function helper wiremock


    【解决方案1】:
    //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")));
    

    【讨论】:

      猜你喜欢
      • 2017-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-04
      • 2019-12-21
      • 2015-05-29
      • 2017-11-09
      • 1970-01-01
      相关资源
      最近更新 更多