【问题标题】:Tracing input & output of message channels of Spring Integration跟踪 Spring Integration 的消息通道的输入和输出
【发布时间】:2019-05-19 01:06:02
【问题描述】:

我已经使用 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 spring-mvc junit spring-integration


    【解决方案1】:

    首先你可以看看 Spring 集成测试框架:https://docs.spring.io/spring-integration/reference/html/testing.html#test-context

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

    如果这对您来说仍然很困难,您始终可以将这些通道注入您的测试类,并在其中添加 ChannelInterceptor 并在其 preSend() 实现中验证消息。

    【讨论】:

    • 我期待着你比兰的回复。几天前,我看到了您的 Gut 存储库代码,您在其中为 Spring Integration 进行了单元测试。我也是测试频道的东西。这就是我必须继续的方式吗?。
    • 好。它有帮助吗?你已经可以接受答案了吗?还是您还有其他疑问?
    • 我会写一些测试用例并在这里发布
    • 是的,这些很有帮助。我正在关注那些。让我们看看我是否可以毫无问题地做到这一点。
    • 我在关注这个链接。 github.com/spring-projects/spring-integration-samples/tree/… 我们是否必须创建 xml 来测试每个通道?我必须在更新部分为流程编写测试用例。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-06
    • 2022-01-17
    • 2011-04-19
    • 2019-06-29
    • 1970-01-01
    • 2023-04-02
    • 2015-02-15
    相关资源
    最近更新 更多