Reputation: 3190
I am trying to implement some tests for the flow configuration. I have JMS inbound channel adapter as an entry point of the flow and outbound file channel adapter(with attached ExpressionEvaluatingRequestHandlerAdvice) as a last endpoint.
Here is a sample code:
@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();
}
I was using this article to implement code above - https://spring.io/blog/2014/11/25/spring-integration-java-dsl-line-by-line-tutorial . However, I was not able to find information about testing of that code.
I've got several questions regarding code above:
jmsInputChannel.send(testMessage);
Thank you.
Upvotes: 1
Views: 843
Reputation: 121177
Well, Alex,
Since you can't find any samples, nor articles or anything else, that means that there is just no like that.
Just because Spring Integration doesn't have an opinionated testing tool.
We still try to come up with something and encourage community to share their thoughts on the matter: https://github.com/spring-projects/spring-integration-java-dsl/issues/23.
As you see not so much progress.
Now let me try to answer to your other questions.
We uses real embedded ActiveMQ for testing. It just starts broker automatically via ConnectionFactory
and properly populate all the destinations. Although you can find some Stub*
classes in the spring-integration-jms
tests: https://github.com/spring-projects/spring-integration/tree/master/spring-integration-jms/src/test/java/org/springframework/integration/jms
You can get references to those implicit channels as well: https://github.com/spring-projects/spring-integration-java-dsl/wiki/Spring-Integration-Java-DSL-Reference#message-channels :
By default endpoints are wired via
DirectChannel
where the bean name is based on the pattern:[IntegrationFlow.beanName].channel#[channelNameIndex]
.
So, in your case the channel after Jms.messageDrivenChannelAdapter()
and before transform()
has a bean name like fileProcessingFlow.channel#0
.
Not sure in your concern about MessageHistory
. You can simply add one more @Configuration
class to your test harness where you can declare @EnableMessageHistory
.
Upvotes: 2