我是 Spring 集成的新手。我需要为整数图编写单元测试。该图从网关->分离器->丰富器->聚合器->转换器开始。因此,如果我想单独为丰富器编写单元测试,我需要怎么做?
我提到了this文章,但所有这些都只有一个组成部分。但是在上面这种情况下该怎么办呢?
最佳答案
目前尚不清楚为什么您引用的答案引用的测试样本对您没有帮助。流中的内容并不重要;重要的是。基本思想是将消息发送到流程的开头,并检查流程末尾的结果,也许可以通过用队列 channel 替换最终 channel ,您可以从测试用例中轮询该 channel 。
您可以stop()
最终消费者,这样他就不会获取结果。
编辑:(回应下面的评论)。
您可以抢占组件的输出 channel ...
...
<int:channel id="toHE"/>
<int:header-enricher id="he" input-channel="toHE" output-channel="fromHE">
<int:header name="foo" value="bar"/>
</int:header-enricher>
<int:channel id="fromHE"/>
...
然后...
@Autowired
private MessageChannel toHE;
@Autowired
@Qualifier("he.handler")
private MessageTransformingHandler headerEnricher;
@Test
@DirtiesContext
public void testEnricher() {
PollableChannel outputChannel = new QueueChannel();
headerEnricher.setOutputChannel(outputChannel);
toHE.send(MessageBuilder.withPayload("baz").build());
Message<?> out = outputChannel.receive(10000);
assertNotNull(out);
assertEquals("bar", out.getHeaders().get("foo"));
}
关于unit-testing - 如何在Spring集成中进行单元测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29761341/