简体   繁体   English

接受来自 SpringBootTest 上下文的外部 REST 调用并验证调用

[英]Accept external REST calls from SpringBootTest context and verify the call

I am writing Spring Boot Integration test.我正在编写 Spring 引导集成测试。 For this, we boot up the empty application (context) and call multiple services as part of test.为此,我们启动空应用程序(上下文)并调用多个服务作为测试的一部分。

One of the requirements is to call the external REST endpoint with payload that contains an URL to notify (call back) and that service, after some business logic, calls the URL received in the payload.要求之一是调用外部 REST 端点,其有效负载包含 URL 以通知(回调),并且该服务在一些业务逻辑之后调用在有效负载中接收到的 ZE6B391A8D2C4D45902A23A8B6587。

From the test, I can call the REST endpoint, which is external service.通过测试,我可以调用 REST 端点,也就是外部服务。 But I want to be able to test the call back from that service for the given URL.但我希望能够针对给定的 URL 测试该服务的回调。 URL can be random. URL 可以是随机的。

Can I do with MockClientServer ?我可以使用MockClientServer吗? OR MockRestServiceServer Or some other day to test this?MockRestServiceServer或其他一天来测试这个?

Essentially, I want the test to be able to get an external call and verify it.本质上,我希望测试能够获得外部调用并对其进行验证。

After trying out a couple things, WireMock actually does what I wanted.在尝试了几件事之后, WireMock确实做到了我想要的。 It takes the rest call from outside application(s).它接受来自外部应用程序的 rest 调用。 Very useful for testing.对测试非常有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM