在Spring REST Docs测试中模拟@MessagingGateway

时间:2017-12-29 17:23:17

标签: spring-integration spring-restdocs

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

1 个答案:

答案 0 :(得分: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无关。

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

相关问题