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; ...

Get Spring Integration Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.