springboot无参数的WireMock mock。

问题描述 投票:3回答:1

我有这个模拟,工作正常

stubFor(WireMock.get("/varela/offerszones?channel=123").willReturn(aResponse()
                .withStatus(200)
                .withHeader("content-type", "application/json")
                .withBodyFile("zones_config.json")));

但我想知道是否有可能在没有参数的情况下模拟它,因为我已经尝试过了,但它是不工作的。

stubFor(WireMock.get("/varela/offerszones").willReturn(aResponse()
                .withStatus(200)
                .withHeader("content-type", "application/json")
                .withBodyFile("zones_config.json")));
spring spring-boot spring-mvc junit wiremock
1个回答
0
投票

在WireMock中,URL匹配可能很难记住。查看 申请匹配文件 以获取更多信息。

您应该能够 平等 只匹配URL路径,使用 urlPathEqualTo 在Java中("urlPath" JSON中的)。)

stubFor(WireMock.get(urlPathEqualTo("/varela/offerszones"))
    .willReturn(aResponse()
    .withStatus(200)
    .withHeader("content-type", "application/json")
    .withBodyFile("zones_config.json")));

其他选项有 (以Java JSON形式列出)

  • urlEqualTo "url"在路径和查询上进行平等匹配
  • urlMatching "urlPattern":路径和查询的regex匹配
  • urlPathMatching "urlPathPattern":只对路径进行regex匹配
© www.soinside.com 2019 - 2024. All rights reserved.