在Spring REST Docs测试中模拟@MessagingGateway

问题描述 投票:1回答:1

我有一个使用@RestController@MessagingGateway,我想知道Spring REST Docs是否有内置的模拟Spring Integration组件的支持。利用Spring REST Docs为此场景生成文档的最佳方法是什么(即,模拟@MessagingGateway的最佳支持方式是什么)?

spring-integration spring-restdocs
1个回答
1
投票

如果你的意思是你想对一个注入了模拟接口的控制器运行REST Docs,那么像这样的东西应该有效......

@Autowired
private MyController controller;

@Test
public void restDocsWithMockGateway() {
    MyGateway gate = mock(MyGateway.class);
    willReturn(new Bar("xxx")).given(gate).foo(any(Foo.class));
    this.controller.setMyGateway(gate); // replace the SI implementation with the mock

    // now do mockmvc stuff with REST Docs

}

假设

@MessagingGateway
public interface MyGateway {

    Bar foo(Foo foo);

}

但是,模拟网关实际上与REST Docs无关。

如果那不是您的意思,请扩展您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.