This commit is contained in:
David Turanski
2011-04-29 11:51:02 -04:00
parent 6c4af186dc
commit 714b952b58
3 changed files with 140 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
package org.springframework.integration.config.xml;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;
/**
* parser for the top level 'wire-tap' element
* @author David Turanski
* @since 2.1
*
*/
public class GlobalWireTapParser extends GlobalChannelInterceptorParser {
@Override
protected Object getBeanDefinitionBuilderConstructorValue(Element element, ParserContext parserContext){
String wireTapBeanName = new WireTapParser().parse(element, parserContext);
return new RuntimeBeanReference(wireTapBeanName);
}
}

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<message-history/>
<channel id="channel"/>
<channel id="wiretap-single">
<queue/>
</channel>
<channel id="wiretap-all">
<queue/>
</channel>
<channel id="output">
<queue/>
</channel>
<channel id="random-channel"/>
<bridge input-channel="channel" output-channel="output"/>
<bridge input-channel="random-channel" output-channel="output"/>
<!-- This wiretap targets a single channel -->
<wire-tap id="wiretap-single-channel" channel="wiretap-single" pattern="channel"/>
<!-- This wiretap targets all channels -->
<wire-tap id="wiretap-all-channels" channel="wiretap-all"/>
</beans:beans>

View File

@@ -0,0 +1,87 @@
package org.springframework.integration.channel.interceptor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.core.PollableChannel;
import org.springframework.integration.message.GenericMessage;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
*
* @author David Turanski
*
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class GlobalWireTapTests {
@Autowired
@Qualifier("channel")
MessageChannel channel;
@Autowired
@Qualifier("random-channel")
MessageChannel anotherChannel;
@Autowired
@Qualifier("wiretap-single")
PollableChannel wiretapSingle;
@Autowired
@Qualifier("wiretap-all")
PollableChannel wiretapAll;
@Test
public void testWireTapsOnTargetedChannel(){
Message<?> message = new GenericMessage<String>("hello");
channel.send(message);
Message <?> wireTapMessage = wiretapSingle.receive(100);
assertNotNull(wireTapMessage);
//There shoud be two messages on this channel. One for 'channel' and one for 'output'
wireTapMessage = wiretapAll.receive(100);
int msgCount=0;
while (wireTapMessage != null){
msgCount++;
assertEquals(wireTapMessage.getPayload(),message.getPayload());
wireTapMessage = wiretapAll.receive(100);
}
assertEquals(2,msgCount);
}
@Test
public void testWireTapsOnRandomChannel(){
Message<?> message = new GenericMessage<String>("hello");
anotherChannel.send(message);
//This time no message on wiretapSingle
Message <?> wireTapMessage = wiretapSingle.receive(100);
assertNull(wireTapMessage);
//There shoud be two messages on this channel. One for 'channel' and one for 'output'
wireTapMessage = wiretapAll.receive(100);
int msgCount=0;
while (wireTapMessage != null){
msgCount++;
assertEquals(wireTapMessage.getPayload(),message.getPayload());
wireTapMessage = wiretapAll.receive(100);
}
assertEquals(2,msgCount);
}
}