英文:
Wiremock problem with ignore requests except one
问题
我有一个问题,需要忽略除了一个之外的所有请求。我已经有了拦截所需请求的代码,但在那之前,我必须跳过发往服务器的所有其他请求。我该如何做到这一点?
givenThat(any(anyUrl()).withHeader("SOAPAction", equalTo(""Mystifly.OnePoint/OnePoint/AirRevalidate""))
.willReturn(aResponse().withStatus(200)
.withBody("{ "message": "Roma Barladyn - 一个伟大的同事!" }")
));
我也尝试了以下方法,但是我得到了一个空的响应体,我如何发送从服务器获取的响应体?
givenThat(any(anyUrl()).atPriority(100).willReturn(aResponse()));
英文:
I have problem with ignore all requests except one. I have the code that I need to intercept the desired request, but before that I must skip all the other requests to the server. How can i do this?
givenThat(any(anyUrl()).withHeader("SOAPAction", equalTo("\"Mystifly.OnePoint/OnePoint/AirRevalidate\""))
.willReturn(aResponse().withStatus(200)
.withBody("{ \"message\": \"Roma Barladyn - a great colleague!\" }")
));
I also tried that but I get empty body of response, how I can send body which I get from server?
givenThat(any(anyUrl()).atPriority(100).willReturn(aResponse()));
答案1
得分: 0
如果您需要确保首先检查所需的请求,您可以将其添加到最高优先级。优先级1将在优先级2之前进行检查,优先级3之前进行检查,依此类推。因此,在您的示例中,优先级100将在优先级1至99之后进行检查。
givenThat(any(anyUrl())
.atPriority(1)
.withHeader("SOAPAction", equalTo("\"Mystifly.OnePoint/OnePoint/AirRevalidate\""))
.willReturn(aResponse().withStatus(200)
.withBody("{ \"message\": \"Roma Barladyn - 一个很棒的同事!\" }")
));
英文:
If you need to make sure that you check the desired request first, you can add it at the highest priority. Priority 1 will get checked before Priority 2, get checked before Priority 3, and so on. So Priority 100 in your example will get checked after Priorities 1 through 99.
givenThat(any(anyUrl())
.atPriority(1)
.withHeader("SOAPAction", equalTo("\"Mystifly.OnePoint/OnePoint/AirRevalidate\""))
.willReturn(aResponse().withStatus(200)
.withBody("{ \"message\": \"Roma Barladyn - a great colleague!\" }")
));
专注分享java语言的经验与见解,让所有开发者获益!
评论