INT-809 Added namespace support for MessagePublishigInterceptor

This commit is contained in:
Oleg Zhurakousky
2009-10-28 20:46:54 +00:00
parent 6c4d28fbd2
commit 8d49507cb0
5 changed files with 299 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd"
xmlns:beans="http://www.springframework.org/schema/beans">
<beans:bean id="testBean"
class="org.springframework.integration.config.xml.MessagePublishingInterceptorParserTests$TestBean" />
<beans:bean id="defaultTestBean"
class="org.springframework.integration.config.xml.MessagePublishingInterceptorParserTests$DefaultTestBean" />
<publish-subscribe-channel id="defaultChannel"/>
<publish-subscribe-channel id="echoChannel"/>
<publish-subscribe-channel id="echoUpperCaseChannel"/>
<aop:config>
<aop:advisor advice-ref="interceptor" pointcut="bean(testBean)" />
</aop:config>
<publisher id="interceptor" default-channel="defaultChannel">
<method pattern="echo" payload="'Echoing: ' + #return" headers="foo='bar'" channel="echoChannel"/>
<method pattern="echoDef*" payload="#return"/>
</publisher>
<aop:config>
<aop:advisor advice-ref="anotherInterceptor" pointcut="bean(defaultTestBean)" />
</aop:config>
<publisher id="anotherInterceptor"/>
</beans:beans>

View File

@@ -0,0 +1,113 @@
/*
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.config.xml;
import static junit.framework.Assert.assertEquals;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.channel.SubscribableChannel;
import org.springframework.integration.core.Message;
import org.springframework.integration.message.MessageHandler;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Oleg Zhurakousky
* @since 2.0
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class MessagePublishingInterceptorParserTests {
@Autowired
private TestBean testBean;
@Autowired
private DefaultTestBean defaultTestBean;
@Autowired
@Qualifier("defaultChannel")
private SubscribableChannel defaultChannel;
@Autowired
@Qualifier("echoChannel")
private SubscribableChannel echoChannel;
@SuppressWarnings("unchecked")
@Test
public void validateDefaultChannelPublishing(){
MessageHandler handler = Mockito.mock(MessageHandler.class);
defaultChannel.subscribe(handler);
doAnswer(new Answer() {
public Object answer(InvocationOnMock invocation) {
Message<?> message = (Message<?>) invocation.getArguments()[0];
assertEquals("hello",message.getPayload());
return null;
}})
.when(handler).handleMessage((Message<?>) anyObject());
testBean.echoDefaultChannel("hello");
verify(handler, times(1)).handleMessage((Message<?>) anyObject());
}
@SuppressWarnings("unchecked")
@Test
public void validateEchoChannelPublishing(){
MessageHandler handler = Mockito.mock(MessageHandler.class);
echoChannel.subscribe(handler);
doAnswer(new Answer() {
public Object answer(InvocationOnMock invocation) {
Message<?> message = (Message<?>) invocation.getArguments()[0];
assertEquals("bar", message.getHeaders().get("foo"));
assertEquals("Echoing: hello", message.getPayload());
return null;
}})
.when(handler).handleMessage((Message<?>) anyObject());
testBean.echo("hello");
verify(handler, times(1)).handleMessage((Message<?>) anyObject());
}
/**
* Need to set 'debug' level
*/
@Test
public void validateNullChannelPublishing(){
defaultTestBean.echo("hello");
}
public static class TestBean{
public String echo(String str){
return str;
}
public String echoUpperCase(String str){
return str.toUpperCase();
}
public String echoDefaultChannel(String str){
return str;
}
}
public static class DefaultTestBean{
public String echo(String str){
return str;
}
}
}