org.springframework.integration.test.matcher
Class HeaderMatcher

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

public class HeaderMatcher
extends org.hamcrest.BaseMatcher<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));
 


Method Summary
 void describeTo(org.hamcrest.Description description)
          
static org.hamcrest.Matcher<Message<?>> hasAllHeaders(java.util.Map<java.lang.String,?> entries)
           
static
<T> org.hamcrest.Matcher<Message<?>>
hasCorrelationId(T value)
           
static org.hamcrest.Matcher<Message<?>> hasExpirationDate(java.util.Date value)
           
static org.hamcrest.Matcher<Message<?>> hasExpirationDate(org.hamcrest.Matcher<java.lang.Long> matcher)
           
static
<T> org.hamcrest.Matcher<Message<?>>
hasHeader(java.lang.String key, org.hamcrest.Matcher<?> valueMatcher)
           
static
<T> org.hamcrest.Matcher<Message<?>>
hasHeader(java.lang.String key, T value)
           
static
<T> org.hamcrest.Matcher<Message<?>>
hasHeaderKey(java.lang.String key)
           
static
<T> org.hamcrest.Matcher<Message<?>>
hasMessageId(T value)
           
static org.hamcrest.Matcher<Message<?>> hasSequenceNumber(java.lang.Integer value)
           
static org.hamcrest.Matcher<Message<?>> hasSequenceNumber(org.hamcrest.Matcher<java.lang.Integer> matcher)
           
static org.hamcrest.Matcher<Message<?>> hasSequenceSize(java.lang.Integer value)
           
static org.hamcrest.Matcher<Message<?>> hasSequenceSize(org.hamcrest.Matcher<java.lang.Integer> value)
           
static org.hamcrest.Matcher<Message<?>> hasTimestamp(java.util.Date value)
           
static org.hamcrest.Matcher<Message<?>> hasTimestamp(org.hamcrest.Matcher<java.lang.Long> matcher)
           
 boolean matches(java.lang.Object item)
          Method made final to prevent accidental override.
 boolean matchesSafely(Message<?> item)
          Subclasses should implement this.
 
Methods inherited from class org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

matchesSafely

public boolean matchesSafely(Message<?> item)
Subclasses should implement this. The item will already have been checked for the specific type and will never be null.


describeTo

public void describeTo(org.hamcrest.Description description)


hasHeader

public static <T> org.hamcrest.Matcher<Message<?>> hasHeader(java.lang.String key,
                                                             T value)

hasHeader

public static <T> org.hamcrest.Matcher<Message<?>> hasHeader(java.lang.String key,
                                                             org.hamcrest.Matcher<?> valueMatcher)

hasHeaderKey

public static <T> org.hamcrest.Matcher<Message<?>> hasHeaderKey(java.lang.String key)

hasAllHeaders

public static org.hamcrest.Matcher<Message<?>> hasAllHeaders(java.util.Map<java.lang.String,?> entries)

hasMessageId

public static <T> org.hamcrest.Matcher<Message<?>> hasMessageId(T value)

hasCorrelationId

public static <T> org.hamcrest.Matcher<Message<?>> hasCorrelationId(T value)

hasSequenceNumber

public static org.hamcrest.Matcher<Message<?>> hasSequenceNumber(java.lang.Integer value)

hasSequenceNumber

public static org.hamcrest.Matcher<Message<?>> hasSequenceNumber(org.hamcrest.Matcher<java.lang.Integer> matcher)

hasSequenceSize

public static org.hamcrest.Matcher<Message<?>> hasSequenceSize(java.lang.Integer value)

hasSequenceSize

public static org.hamcrest.Matcher<Message<?>> hasSequenceSize(org.hamcrest.Matcher<java.lang.Integer> value)

hasExpirationDate

public static org.hamcrest.Matcher<Message<?>> hasExpirationDate(java.util.Date value)

hasExpirationDate

public static org.hamcrest.Matcher<Message<?>> hasExpirationDate(org.hamcrest.Matcher<java.lang.Long> matcher)

hasTimestamp

public static org.hamcrest.Matcher<Message<?>> hasTimestamp(java.util.Date value)

hasTimestamp

public static org.hamcrest.Matcher<Message<?>> hasTimestamp(org.hamcrest.Matcher<java.lang.Long> matcher)

matches

public final boolean matches(java.lang.Object item)
Method made final to prevent accidental override. If you need to override this, there's no point on extending TypeSafeMatcher. Instead, extend the BaseMatcher.