Refactor AbstractHeaderMapper
This commit updates AbstractHeaderMapper in a number of ways: * The 'userDefinedHeaderPrefix' property has been removed as some advanced tests revealed that the feature is actually broken right now and there is no easy way to fix it. A new richer hook point that indicates if the property comes from the target object or the standard MessageHeaders has been added. * A HeaderMatcher interface has been introduced to replace the lengthy checks in shouldMapHeader. Several implementations of that interface are provided * An additional pattern has been added that maps any header that is *not* a standard header. It uses the standardHeaderPrefix property for that purpose * A number of protected method that were only used to create the instance have been removed in favour of a non default constructor. Subclasses should provide those *static* values in their own default constructor. * The list of transient headers can now be customized. Transient headers are headers that should never be mapped. The standard ErrorChannel and ReplyChannel headers have also been removed from the default transient headers list as they no longer need to be transient header-mapper: Polishing
This commit is contained in:
committed by
Artem Bilan
parent
84421fd91c
commit
463c185b38
@@ -18,11 +18,10 @@ package org.springframework.integration.xmpp.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smackx.jiveproperties.JivePropertiesManager;
|
||||
import org.junit.Test;
|
||||
@@ -32,6 +31,7 @@ import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.integration.mapping.AbstractHeaderMapper;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
@@ -96,10 +96,15 @@ public class ChatMessageOutboundChannelAdapterParserTests {
|
||||
Object eventConsumer = context.getBean("outboundEventAdapter");
|
||||
DefaultXmppHeaderMapper headerMapper =
|
||||
TestUtils.getPropertyValue(eventConsumer, "handler.headerMapper", DefaultXmppHeaderMapper.class);
|
||||
List<String> requestHeaderNames = TestUtils.getPropertyValue(headerMapper, "requestHeaderNames", List.class);
|
||||
assertEquals(2, requestHeaderNames.size());
|
||||
assertEquals("foo*", requestHeaderNames.get(0));
|
||||
assertEquals("bar*", requestHeaderNames.get(1));
|
||||
|
||||
AbstractHeaderMapper.HeaderMatcher requestHeaderMatcher = TestUtils.getPropertyValue(headerMapper,
|
||||
"requestHeaderMatcher", AbstractHeaderMapper.HeaderMatcher.class);
|
||||
assertTrue(requestHeaderMatcher.matchHeader("foo"));
|
||||
assertTrue(requestHeaderMatcher.matchHeader("foo123"));
|
||||
assertTrue(requestHeaderMatcher.matchHeader("bar"));
|
||||
assertTrue(requestHeaderMatcher.matchHeader("bar123"));
|
||||
assertFalse(requestHeaderMatcher.matchHeader("biz"));
|
||||
assertFalse(requestHeaderMatcher.matchHeader("else"));
|
||||
assertTrue(eventConsumer instanceof EventDrivenConsumer);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user