Reputation: 5867
I am new to spring integration. I need to write unit test for the integeration graph. This graph starts with gateway->splitter->enricher->aggregator->Transformer. So if i want to write a unit test for enricher alone, how do i need to do it.?
I referred this article, but all of them has only one component. But how to do it in this case as above.?
Upvotes: 2
Views: 1888
Reputation: 174484
It's not clear why the testing samples referenced by your cited answer don't help you. It doesn't matter what's in the flow; the basic idea is to send a message into the start of the flow and examine the result from the end of the flow, perhaps by replacing the final channel with a queue channel, which you can poll from your test case.
You can stop()
the ultimate consumer so he doesn't grab the result.
EDIT: (in response to comments below).
You can preempt the component's output channel...
...
<int:channel id="toHE"/>
<int:header-enricher id="he" input-channel="toHE" output-channel="fromHE">
<int:header name="foo" value="bar"/>
</int:header-enricher>
<int:channel id="fromHE"/>
...
And then...
@Autowired
private MessageChannel toHE;
@Autowired
@Qualifier("he.handler")
private MessageTransformingHandler headerEnricher;
@Test
@DirtiesContext
public void testEnricher() {
PollableChannel outputChannel = new QueueChannel();
headerEnricher.setOutputChannel(outputChannel);
toHE.send(MessageBuilder.withPayload("baz").build());
Message<?> out = outputChannel.receive(10000);
assertNotNull(out);
assertEquals("bar", out.getHeaders().get("foo"));
}
Upvotes: 3