我有这个模拟,工作正常
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")));
在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匹配