【发布时间】:2023-04-10 22:10:02
【问题描述】:
我目前正在尝试使用 Wiremock 模拟外部服务器。 我的一个外部服务器端点需要一个有效负载。 该端点定义如下:
def sendRequestToMockServer(payload: String) = {
for {
request_entity <- Marshal(payload).to[RequestEntity]
response <- Http().singleRequest(
HttpRequest(
method = HttpMethods.GET,
uri = "http://localhost:9090/login",
entity = request_entity
)
)
} yield {
response
}
}
为了使用 Wiremock 模拟这个端点,我编写了以下代码:
stubFor(
get(urlEqualTo("/login"))
.willReturn(
aResponse()
.withHeader("Content-Type","application/json")
.withBodyFile("wireMockResponse.json")
.withStatus(200)
)
.withRequestBody(matchingJsonPath("requestBody.json"))
)
我在 requestBody.json 文件中定义了请求正文。
但是当我运行测试时,我不断收到一个错误,指出找不到请求的 Url。
我认为错误与withRequestBody(matchingJsonPath("requestBody.json")) 这一行有关,因为当我评论它时,错误消失了。
关于如何解决这个问题的任何建议?
【问题讨论】: