Spring Cloud Contract for Webflux Reactive APIs

假如想象 提交于 2021-02-07 14:28:30

问题


I'm trying to apply Spring Cloud Contract to a Reactive API built with Spring Webflux. Basically be able to send a Flux and receive a response Flux from an API in the style of:

@RequestMapping("/endlessecho")
public Flux<String> endlessEcho(Flux<String> input) {
    return input;
}

I can however find no information online or in the documentation on whether I can do this with Spring Cloud Contract.

Is it even possible to write a Contract for this? Will it be able to feed wiremock and generate the appropriate JUnit tests?


回答1:


With this commit (https://github.com/spring-cloud-samples/spring-cloud-contract-samples/commit/f7030148a9337d4c7184f7c8e27c271d9b89681b) I've added a WebFlux example to the Spring Cloud COntract Samples.

It's enough to define the contract as usual, pass the EXPLICIT mode for testMode parameter in the plugin setup. Instead of RestASsuredMockMvc you have to use the standard RestAssured static URI field to set up the URI of the app that is using WebFlux. You need to setup the whole Spring Context and bind to a port and that's pretty much it.

In the project called consumer there's a test that uses the stubs from the producer-webflux project. From the Stub Runner's perspective, there's no change in how the stubs are started.



来源:https://stackoverflow.com/questions/49885765/spring-cloud-contract-for-webflux-reactive-apis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!