跟踪Spring Integration消息通道的输入和输出



我已经使用Spring Integration构建了一个小型应用程序。我还为更多的服务和其他类编写了一些jUnit。我已经将XML配置用于通道和连接点配置,我想知道是否可以测试特定通道的输入和输出。有没有一种方法可以测试通道的输入和输出?。。

更新

我正试着往下流。我该怎么办?

<int:channel id="getPresciption" />
<int:channel id="respPrescription" />
<int:channel id="storePrcedureChannell" />
<int-http:inbound-gateway
request-channel="getPresciption" reply-channel="respPrescription"
supported-methods="GET" path="/getAllPresciption">
<int-http:request-mapping
consumes="application/json" produces="application/json" />
</int-http:inbound-gateway>
<int:service-activator
ref="prescriptionServiceActivator" method="buildPrescription"
input-channel="getPresciption" output-channel="storePrcedureChannell" />
<int:service-activator
ref="prescriptionServiceActivator" method="storePrescription"
input-channel="storePrcedureChannell"></int:service-activator>

那么我该如何编写测试上下文呢?

下面是通道流调用的方法。

public Message<List<Prescription>> buildPrescription() {
//Do some processing
}
public Message<List<Prescription>> storePrescription(Message<List<Prescription>> msg) {
//Do something and return the List.
}

首先,您可以了解一下Spring集成测试框架:https://docs.spring.io/spring-integration/reference/html/testing.html#test-上下文

然后使用MockIntegration.mockMessageHandler()MockIntegrationContext.substituteMessageHandlerFor()来替换端点中的实际处理程序,并验证来自通道的传入数据。

如果这对您来说仍然很困难,那么您总是可以将这些通道注入到测试类中,并向它们添加ChannelInterceptor,并在其preSend()实现中验证消息。

最新更新