2017-02-09 40 views
1

我正在嘗試爲流配置實施一些測試。我將JMS入站通道適配器作爲流和出站文件通道適配器(附帶ExpressionEvaluatingRequestHandlerAdvice)的入口點作爲最後一個端點。流量集成測試(Java DSL配置)

這裏是一個示例代碼:

@Bean 
public IntegrationFlow fileProcessingFlow() { 
    DefaultMessageListenerContainer dmlc = new DefaultMessageListenerContainer(); 
    dmlc.setConnectionFactory(connectionFactory); 
    dmlc.setDestination(jmsQueue); 

    return IntegrationFlows.from(Jms.messageDrivenChannelAdapter(dmlc)) 
     .<String, File>transform(p -> new File(p)) 
     .handle(headerEnricherService) 
     .<Boolean>route("T(SomeEnum).INVALID.equals(headers['headerName'])", mapping -> mapping 
      .subFlowMapping(Boolean.TRUE, sf -> sf.handle(serviceRef, "handleInvalidFile")) 
      .subFlowMapping(Boolean.FALSE, sf -> sf 
       .handle(serviceRef, "handleValidFile") 
       .handle(anotherServiceRef))) 
     .filter(additionalFilterRef) 
     .handle(Files.outboundAdapter("'output/dir/path'") 
        .autoCreateDirectory(true) 
        .deleteSourceFiles(true), 
       c -> c.advice(fileCopyAdvice())) 
     .get(); 
} 

我用這篇文章來實現上面的代碼 - https://spring.io/blog/2014/11/25/spring-integration-java-dsl-line-by-line-tutorial。但是,我無法找到有關測試代碼的信息。

我有關於上面的代碼中幾個問題:

  1. 我在哪裏可以找到一個類似定義流程的測試實例(S)?或者至少,有關該主題的一些教程或文章?
  2. 什麼是模擬JMS連接的最佳方式?
  3. 如何在流配置中未明確定義通道時引用通道?優選地,我想在我的測試配置中自動裝入通道,然後向其發送示例消息。類似於jmsInputChannel.send(testMessage);
  4. 有什麼方法可以在測試中使用MessageHistory?

謝謝。

回答

2

好,亞歷克斯,

既然你找不到任何樣品,也不物品或其他任何東西,這意味着就是沒有這樣的。

僅僅因爲Spring Integration沒有自以爲是的測試工具。

我們仍然試圖想出一些東西,並鼓勵社區分享他們對此事的看法:https://github.com/spring-projects/spring-integration-java-dsl/issues/23

正如你所看到的沒有那麼多的進步。

現在讓我試着回答你的其他問題。

我們使用真正的嵌入式ActiveMQ進行測試。它只是通過ConnectionFactory自動啓動代理並正確填充所有目的地。雖然你可以找到在spring-integration-jms測試一些Stub*類:https://github.com/spring-projects/spring-integration/tree/master/spring-integration-jms/src/test/java/org/springframework/integration/jms

你可以得到那些隱性渠道的引用,以及:https://github.com/spring-projects/spring-integration-java-dsl/wiki/Spring-Integration-Java-DSL-Reference#message-channels

默認情況下端點通過DirectChannel其中bean名稱是基於有線模式:[IntegrationFlow.beanName].channel#[channelNameIndex]

所以,在你的情況下,通道Jms.messageDrivenChannelAdapter()transform()之前有一個bean的名稱,比如fileProcessingFlow.channel#0。不知道MessageHistory。您可以簡單地將一個@Configuration類添加到您的測試工具,您可以聲明@EnableMessageHistory

+0

嗨Artem。非常感謝您的詳細回覆。 – Alex