Class HeaderMatcher<T>

java.lang.Object
org.hamcrest.BaseMatcher<T>
org.hamcrest.TypeSafeMatcher<Message<T>>
org.springframework.integration.test.matcher.HeaderMatcher<T>
All Implemented Interfaces:
org.hamcrest.Matcher<Message<T>>, org.hamcrest.SelfDescribing

public final class HeaderMatcher<T> extends org.hamcrest.TypeSafeMatcher<Message<T>>
Are the MessageHeaders of a Message containing any entry or multiple that match?

For example using Assert.assertThat(Object, Matcher) for a single entry:

 
 ANY_HEADER_KEY = "foo";
 ANY_HEADER_VALUE = "bar";
 assertThat(message, hasEntry(ANY_HEADER_KEY, ANY_HEADER_VALUE));
 assertThat(message, hasEntry(ANY_HEADER_KEY, is(String.class)));
 assertThat(message, hasEntry(ANY_HEADER_KEY, notNullValue()));
 assertThat(message, hasEntry(ANY_HEADER_KEY, is(ANY_HEADER_VALUE)));
 
 

For multiple entries to match all:

 
 Map<String, Object> expectedInHeaderMap = new HashMap<String, Object>();
 expectedInHeaderMap.put(ANY_HEADER_KEY, ANY_HEADER_VALUE);
 expectedInHeaderMap.put(OTHER_HEADER_KEY, is(OTHER_HEADER_VALUE));
 assertThat(message, HeaderMatcher.hasAllEntries(expectedInHeaderMap));
 
 

For a single key:

 ANY_HEADER_KEY = "foo";
 assertThat(message, HeaderMatcher.hasKey(ANY_HEADER_KEY));
 
Author:
Alex Peters, Iwein Fuld, Artem Bilan, Gary Russell
  • Method Details

    • matchesSafely

      public boolean matchesSafely(Message<T> item)
      Specified by:
      matchesSafely in class org.hamcrest.TypeSafeMatcher<Message<T>>
    • describeTo

      public void describeTo(org.hamcrest.Description description)
    • hasHeader

      public static <P, V> HeaderMatcher<P> hasHeader(String key, V value)
    • hasHeader

      public static <P, V> HeaderMatcher<P> hasHeader(String key, org.hamcrest.Matcher<V> valueMatcher)
    • hasHeaderKey

      public static <P> HeaderMatcher<P> hasHeaderKey(String key)
    • hasAllHeaders

      public static <P> HeaderMatcher<P> hasAllHeaders(Map<String,?> entries)
    • hasMessageId

      public static <P, V> HeaderMatcher<P> hasMessageId(V value)
    • hasCorrelationId

      public static <P, V> HeaderMatcher<P> hasCorrelationId(V value)
    • hasSequenceNumber

      public static <P> HeaderMatcher<P> hasSequenceNumber(Integer value)
    • hasSequenceNumber

      public static <P> HeaderMatcher<P> hasSequenceNumber(org.hamcrest.Matcher<Integer> matcher)
    • hasSequenceSize

      public static <P> HeaderMatcher<P> hasSequenceSize(Integer value)
    • hasSequenceSize

      public static <P> HeaderMatcher<P> hasSequenceSize(org.hamcrest.Matcher<Integer> value)
    • hasExpirationDate

      public static <P> HeaderMatcher<P> hasExpirationDate(Date value)
    • hasExpirationDate

      public static <P> HeaderMatcher<P> hasExpirationDate(org.hamcrest.Matcher<Long> matcher)
    • hasTimestamp

      public static <P> HeaderMatcher<P> hasTimestamp(Date value)
    • hasTimestamp

      public static <P> HeaderMatcher<P> hasTimestamp(org.hamcrest.Matcher<Long> matcher)