Testing headers
As we tested the payload, it's fairly easy to test headers. Let's write a header enricher and then a test case to validate it:
<int:header-enricher input-channel="filteredFeedChannel" output-channel="transformedChannel"> <int:header name="testHeaderKey1" value="testHeaderValue1"/> <int:header name="testHeaderKey2" value="testHeaderValue2"/> </int:header-enricher>
Headers will be added to any message that is put on filteredFeedChannel
. The following code snippet is the test to verify whether these headers are added or not:
import static org.junit.Assert.assertThat; import static org.springframework.integration.test.matcher.HeaderMatcher.hasHeader; import static org.springframework.integration.test.matcher.HeaderMatcher.hasHeaderKey; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.integration.channel.QueueChannel; import org.springframework...