Added test for annotation-driven endpoint with Message-typed parameter for handler method.

This commit is contained in:
Mark Fisher
2008-01-09 16:11:44 +00:00
parent 7986d8a6c7
commit fada237b51
3 changed files with 69 additions and 2 deletions

View File

@@ -24,7 +24,7 @@ import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.message.StringMessage;
/**
* @author Mark Fisher
@@ -37,7 +37,19 @@ public class MessageEndpointAnnotationPostProcessorTests {
context.start();
MessageChannel inputChannel = (MessageChannel) context.getBean("inputChannel");
MessageChannel outputChannel = (MessageChannel) context.getBean("outputChannel");
inputChannel.send(new GenericMessage<String>(1, "world"));
inputChannel.send(new StringMessage("world"));
Message<String> message = outputChannel.receive(1000);
assertEquals("hello world", message.getPayload());
context.stop();
}
@Test
public void testMessageParameterHandler() throws InterruptedException {
AbstractApplicationContext context = new ClassPathXmlApplicationContext("messageParameterAnnotatedEndpointTests.xml", this.getClass());
context.start();
MessageChannel inputChannel = (MessageChannel) context.getBean("inputChannel");
MessageChannel outputChannel = (MessageChannel) context.getBean("outputChannel");
inputChannel.send(new StringMessage("world"));
Message<String> message = outputChannel.receive(1000);
assertEquals("hello world", message.getPayload());
context.stop();

View File

@@ -0,0 +1,35 @@
/*
* Copyright 2002-2007 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.endpoint.annotation;
import org.springframework.integration.annotation.Handler;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.StringMessage;
/**
* @author Mark Fisher
*/
@MessageEndpoint(input="inputChannel", defaultOutput="outputChannel", pollPeriod=10)
public class MessageParameterAnnotatedEndpoint {
@Handler
public StringMessage sayHello(Message<?> message) {
return new StringMessage("hello " + message.getPayload());
}
}

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:integration="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
<integration:message-bus/>
<integration:annotation-driven/>
<integration:channel id="inputChannel"/>
<integration:channel id="outputChannel"/>
<bean id="endpoint" class="org.springframework.integration.endpoint.annotation.MessageParameterAnnotatedEndpoint"/>
</beans>