1
votes

i was unable to find an simple example to unit test the spring integration dsl, which involves picking up a message from queue and making a rest call.

I looked at the examples https://github.com/spring-projects/spring-integration-java-dsl but was not clear on qualifiers etc for the below code for which i want to write unit test on.

    IntegrationFlows.from(Jms.inboundGateway(connectionFactory)
            .id("inputChannel")
            .destination(sourceQueue)
            .jmsMessageConverter(new MarshallingMessageConverter(jaxbMarshaller())))
            .something to validate and route
            .handle(Http.outboundGateway("http://localhost:9999/create)
                            .httpMethod(HttpMethod.POST)
                            .expectedResponseType(String.class))
            .get();
1

1 Answers

1
votes

Something else is needed in your question to explain more the requirements.

Anyway I'll try to answer in my best feeling on the matter.

Spring Integration Java DSL is nothing more then codding tool to wire beans and build integration components into flows. In the end, at runtime, we just have a set of beans with which we can interact as with any other beans in the application context.

So, if the story is about consuming some destination from JMS and verify what we get from there, there is just enough to run ActiveMQ in the embedded mode - it is as simple as bean for:

new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false")

Then you use JmsTemplate to send some test data to the desired destination (will be created on demand) and consume an Integration message from the channel defined in the mentioned in your question IntegrationFlow.

Typically for consuming test data we use a QueueChannel and its receive(long timeout). This way we block a unit test until data arrives or timeout is elapsed.

Another way to verify a flow work is with the Spring Integration Testing Framework. From there you can use a MockIntegration to replace the real MessageHandler in the application context and verify an interaction with the mock afterward.

Hope that helps a bit.