我想对两个Spring Boot应用程序进行集成测试,这些应用程序也使用Spring Integration流程 . 要测试我的应用,我想检查通过 myMessageChannel
路由的消息 . 它在其中一个应用程序的XML流程中定义 .
如何连接到我的直接消息通道并将消息重定向到PollableChannel,以便我可以逐个读取它们?我在网上找到的所有方法都不适合我 .
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {App1.class, App2.class}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@TestPropertySource("classpath:integration.properties")
public class MyWireTapTest {
@Autowired
MessageChannel myMessageChannel;
@Test
public void test() {
// This is basically what I want to do
// But it does not work, since it is a direct channel
myMessageChannel.recieve();
}
}
2 回答
将其自动装配为
AbstractMessageChannel
并使用myMessageChannel.addInterceptor(new WireTap(tapChannel));
我写了一个示例演示如何执行此操作(通过XML配置):
https://github.com/hakanozbay/spring-integration-testing