diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/spring-integration-1.0.xsd b/org.springframework.integration/src/main/java/org/springframework/integration/config/spring-integration-1.0.xsd index 7ff34755c4..d866d1a00b 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/spring-integration-1.0.xsd +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/spring-integration-1.0.xsd @@ -159,7 +159,6 @@ - diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/message/DefaultMessageCreator.java b/org.springframework.integration/src/main/java/org/springframework/integration/gateway/DefaultMessageMapper.java similarity index 51% rename from org.springframework.integration/src/main/java/org/springframework/integration/message/DefaultMessageCreator.java rename to org.springframework.integration/src/main/java/org/springframework/integration/gateway/DefaultMessageMapper.java index 63000d84a4..a1cda503ff 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/message/DefaultMessageCreator.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/gateway/DefaultMessageMapper.java @@ -14,23 +14,35 @@ * limitations under the License. */ -package org.springframework.integration.message; +package org.springframework.integration.gateway; + +import org.springframework.integration.message.Message; +import org.springframework.integration.message.MessageBuilder; /** - * A simple implementation of {@link MessageCreator} that uses the provide value - * as the {@link Message Message's} payload. + * A default implementation of both the {@link MessageMapper} and + * {@link OutboundMessageMapper} strategy interfaces. * * @author Mark Fisher */ -public class DefaultMessageCreator implements MessageCreator { +public class DefaultMessageMapper implements MessageMapper { @SuppressWarnings("unchecked") - public Message createMessage(T object) { - //prevent nesting messages - if (object instanceof Message) { - return (Message) object; + public T fromMessage(Message message) { + if (message == null || message.getPayload() == null) { + return null; } - return (object != null) ? new GenericMessage(object) : null; + return (T) message.getPayload(); + } + + public Message toMessage(T object) { + if (object == null) { + return null; + } + if (object instanceof Message) { + return (Message) object; + } + return MessageBuilder.withPayload(object).build(); } } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/message/MessageMapper.java b/org.springframework.integration/src/main/java/org/springframework/integration/gateway/MessageMapper.java similarity index 69% rename from org.springframework.integration/src/main/java/org/springframework/integration/message/MessageMapper.java rename to org.springframework.integration/src/main/java/org/springframework/integration/gateway/MessageMapper.java index ece5f6bfbc..03f6c1969d 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/message/MessageMapper.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/gateway/MessageMapper.java @@ -14,18 +14,19 @@ * limitations under the License. */ -package org.springframework.integration.message; +package org.springframework.integration.gateway; + +import org.springframework.integration.message.Message; /** - * Strategy interface for mapping from a {@link Message} to an Object. + * Strategy interface for mapping between an Object and a {@link Message}. * * @author Mark Fisher */ -public interface MessageMapper { +public interface MessageMapper { - /** - * Map from the given {@link Message} to an Object. - */ - O mapMessage(Message

message); + Message toMessage(T object); + + T fromMessage(Message message); } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java b/org.springframework.integration/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java deleted file mode 100644 index 58882e54f4..0000000000 --- a/org.springframework.integration/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.gateway; - -import org.springframework.integration.channel.MessageChannel; -import org.springframework.integration.channel.MessageChannelTemplate; - -/** - * A convenient base class providing access to a {@link MessageChannelTemplate} and exposing setter methods for - * configuring request and reply {@link MessageChannel MessageChannels}. May be used as a base class for framework - * components so that the details of messaging are well-encapsulated and hidden from application code. For example, - * see {@link SimpleMessagingGateway}. - * - * @author Mark Fisher - */ -public abstract class MessagingGatewaySupport { - - private final MessageChannelTemplate channelTemplate = new MessageChannelTemplate(); - - - /** - * Set the timeout value for sending request messages. If not - * explicitly configured, the default is an indefinite timeout. - * - * @param requestTimeout the timeout value in milliseconds - */ - public void setRequestTimeout(long requestTimeout) { - this.channelTemplate.setSendTimeout(requestTimeout); - } - - /** - * Set the timeout value for receiving reply messages. If not - * explicitly configured, the default is an indefinite timeout. - * - * @param replyTimeout the timeout value in milliseconds - */ - public void setReplyTimeout(long replyTimeout) { - this.channelTemplate.setReceiveTimeout(replyTimeout); - } - - /** - * Retrieve the {@link MessageChannelTemplate} for performing - * send and receive operations across channels. - */ - protected final MessageChannelTemplate getChannelTemplate() { - return this.channelTemplate; - } - -} diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java b/org.springframework.integration/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java index 0029143c3c..9040e5ffc1 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java @@ -21,34 +21,37 @@ import org.springframework.integration.ConfigurationException; import org.springframework.integration.bus.MessageBus; import org.springframework.integration.bus.MessageBusAware; import org.springframework.integration.channel.MessageChannel; +import org.springframework.integration.channel.MessageChannelTemplate; import org.springframework.integration.channel.PollableChannel; import org.springframework.integration.endpoint.MessagingGateway; -import org.springframework.integration.message.DefaultMessageCreator; -import org.springframework.integration.message.DefaultMessageMapper; import org.springframework.integration.message.Message; -import org.springframework.integration.message.MessageCreator; import org.springframework.integration.message.MessageDeliveryException; -import org.springframework.integration.message.MessageMapper; import org.springframework.util.Assert; /** - * A general purpose class that supports a variety of message exchanges. Useful for connecting application code to - * {@link MessageChannel MessageChannels} for sending, receiving, or request-reply operations. The sending methods - * accept any Object as the parameter value (i.e. it is not required to be a Message). A custom {@link MessageCreator} - * may be provided for creating Messages from the Objects. Likewise return values may be any Object and a custom - * implementation of the {@link MessageMapper} strategy may be provided for mapping a reply Message to an Object. + * A convenient base class for connecting application code to + * {@link MessageChannel}s for sending, receiving, or request-reply operations. + * Exposes setters for configuring request and reply {@link MessageChannel}s as + * well as the timeout values for sending and receiving Messages. + * + *

By default, each request Message will be created with the method + * parameter as its payload, and each reply Message's payload will be the + * return value. To provide custom behavior for object-to-request and/or + * reply-to-object conversion, implement and set a 'messageMapper'. + * + * @see MessageMapper * * @author Mark Fisher */ -public class SimpleMessagingGateway extends MessagingGatewaySupport implements MessagingGateway, MessageBusAware, InitializingBean { +public class SimpleMessagingGateway implements MessagingGateway, MessageBusAware, InitializingBean { private volatile MessageChannel requestChannel; private volatile MessageChannel replyChannel; - private volatile MessageCreator messageCreator = new DefaultMessageCreator(); + private volatile MessageMapper messageMapper = new DefaultMessageMapper(); - private volatile MessageMapper messageMapper = new DefaultMessageMapper(); + private final MessageChannelTemplate channelTemplate = new MessageChannelTemplate(); private volatile ReplyMessageCorrelator replyMessageCorrelator; @@ -85,12 +88,27 @@ public class SimpleMessagingGateway extends MessagingGatewaySupport implements M this.replyChannel = replyChannel; } - public void setMessageCreator(MessageCreator messageCreator) { - Assert.notNull(messageCreator, "messageCreator must not be null"); - this.messageCreator = messageCreator; + /** + * Set the timeout value for sending request messages. If not + * explicitly configured, the default is an indefinite timeout. + * + * @param requestTimeout the timeout value in milliseconds + */ + public void setRequestTimeout(long requestTimeout) { + this.channelTemplate.setSendTimeout(requestTimeout); } - public void setMessageMapper(MessageMapper messageMapper) { + /** + * Set the timeout value for receiving reply messages. If not + * explicitly configured, the default is an indefinite timeout. + * + * @param replyTimeout the timeout value in milliseconds + */ + public void setReplyTimeout(long replyTimeout) { + this.channelTemplate.setReceiveTimeout(replyTimeout); + } + + public void setMessageMapper(MessageMapper messageMapper) { Assert.notNull(messageMapper, "messageMapper must not be null"); this.messageMapper = messageMapper; } @@ -108,12 +126,10 @@ public class SimpleMessagingGateway extends MessagingGatewaySupport implements M throw new IllegalStateException( "send is not supported, because no request channel has been configured"); } - Message message = (object instanceof Message) ? (Message) object : - this.messageCreator.createMessage(object); - if (message != null) { - if (!this.getChannelTemplate().send(message, this.requestChannel)) { - throw new MessageDeliveryException(message, "failed to send Message to channel"); - } + Message message = this.messageMapper.toMessage(object); + Assert.notNull(message, "message must not be null"); + if (!this.channelTemplate.send(message, this.requestChannel)) { + throw new MessageDeliveryException(message, "failed to send Message to channel"); } } @@ -122,8 +138,8 @@ public class SimpleMessagingGateway extends MessagingGatewaySupport implements M throw new IllegalStateException( "no-arg receive is not supported, because no pollable reply channel has been configured"); } - Message message = this.getChannelTemplate().receive((PollableChannel) this.replyChannel); - return (message != null) ? this.messageMapper.mapMessage(message) : null; + Message message = this.channelTemplate.receive((PollableChannel) this.replyChannel); + return this.messageMapper.fromMessage(message); } public Object sendAndReceive(Object object) { @@ -135,19 +151,16 @@ public class SimpleMessagingGateway extends MessagingGatewaySupport implements M } private Object sendAndReceive(Object object, boolean shouldMapMessage) { - Message request = (object instanceof Message) ? (Message) object : - this.messageCreator.createMessage(object); - if (request == null) { - return null; - } + Message request = this.messageMapper.toMessage(object); Message reply = this.sendAndReceiveMessage(request); if (!shouldMapMessage) { return reply; } - return (reply != null) ? this.messageMapper.mapMessage(reply) : null; + return this.messageMapper.fromMessage(reply); } private Message sendAndReceiveMessage(Message message) { + Assert.notNull(message, "request message must not be null"); if (this.requestChannel == null) { throw new MessageDeliveryException(message, "No request channel available. Cannot send request message."); @@ -155,7 +168,7 @@ public class SimpleMessagingGateway extends MessagingGatewaySupport implements M if (this.replyChannel != null && this.replyMessageCorrelator == null) { this.registerReplyMessageCorrelator(); } - return this.getChannelTemplate().sendAndReceive(message, this.requestChannel); + return this.channelTemplate.sendAndReceive(message, this.requestChannel); } private void registerReplyMessageCorrelator() { diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/gateway/config/GatewayParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/gateway/config/GatewayParser.java index d130d971f4..22ca562c6a 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/gateway/config/GatewayParser.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/gateway/config/GatewayParser.java @@ -20,10 +20,9 @@ import org.w3c.dom.Element; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; -import org.springframework.core.Conventions; +import org.springframework.integration.config.IntegrationNamespaceUtils; import org.springframework.integration.gateway.GatewayProxyFactoryBean; import org.springframework.util.ObjectUtils; -import org.springframework.util.StringUtils; /** * Parser for the <gateway/> element. @@ -33,7 +32,7 @@ import org.springframework.util.StringUtils; public class GatewayParser extends AbstractSimpleBeanDefinitionParser { private static String[] referenceAttributes = new String[] { - "request-channel", "reply-channel", "message-mapper", "message-creator" + "request-channel", "reply-channel", "message-mapper" }; @@ -49,13 +48,9 @@ public class GatewayParser extends AbstractSimpleBeanDefinitionParser { } @Override - protected void postProcess(BeanDefinitionBuilder beanDefinition, Element element) { + protected void postProcess(BeanDefinitionBuilder builder, Element element) { for (String attributeName : referenceAttributes) { - String beanName = element.getAttribute(attributeName); - if (StringUtils.hasText(beanName)) { - beanDefinition.addPropertyReference( - Conventions.attributeNameToPropertyName(attributeName), beanName); - } + IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, attributeName); } } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/message/DefaultMessageMapper.java b/org.springframework.integration/src/main/java/org/springframework/integration/message/DefaultMessageMapper.java deleted file mode 100644 index 7c8c96d0e1..0000000000 --- a/org.springframework.integration/src/main/java/org/springframework/integration/message/DefaultMessageMapper.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.message; - -/** - * A simple implementation of {@link MessageMapper} that returns the - * {@link Message Message's} payload. - * - * @author Mark Fisher - */ -public class DefaultMessageMapper implements MessageMapper { - - public T mapMessage(Message message) { - return (message != null) ? message.getPayload() : null; - } - -} diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/message/MessageCreator.java b/org.springframework.integration/src/main/java/org/springframework/integration/message/MessageCreator.java deleted file mode 100644 index 0b1a8fac23..0000000000 --- a/org.springframework.integration/src/main/java/org/springframework/integration/message/MessageCreator.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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.message; - -/** - * Strategy interface for creating a {@link Message} from an Object. - * - * @author Mark Fisher - */ -public interface MessageCreator { - - Message

createMessage(O object); - -} diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/message/MethodInvokingSource.java b/org.springframework.integration/src/main/java/org/springframework/integration/message/MethodInvokingSource.java index 7980de043c..84b01d1bff 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/message/MethodInvokingSource.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/message/MethodInvokingSource.java @@ -83,8 +83,12 @@ public class MethodInvokingSource implements PollableSource, Initializin if (result == null) { return null; } + if (result instanceof Message) { + return (Message) result; + } return new GenericMessage(result); - } catch (InvocationTargetException e) { + } + catch (InvocationTargetException e) { throw new MessagingException( "Source method '" + this.methodName + "' threw an Exception.", e.getTargetException()); } diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/gateway/SimpleMessagingGatewayTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/gateway/SimpleMessagingGatewayTests.java index 6f6bb16506..2531ede0f8 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/gateway/SimpleMessagingGatewayTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/gateway/SimpleMessagingGatewayTests.java @@ -24,6 +24,7 @@ import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.reset; import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import org.easymock.IAnswer; import org.junit.Before; @@ -36,7 +37,6 @@ import org.springframework.integration.channel.PollableChannel; import org.springframework.integration.message.Message; import org.springframework.integration.message.MessageDeliveryException; import org.springframework.integration.message.MessageHeaders; -import org.springframework.integration.message.MessageMapper; /** * @author Iwein Fuld @@ -52,19 +52,15 @@ public class SimpleMessagingGatewayTests { private Message messageMock = createMock(Message.class); - private MessageMapper messageMapperMock = createMock(MessageMapper.class); - private MessageBus messageBusMock = createMock(MessageBus.class); - private Object[] allmocks = new Object[] { - requestChannel, replyChannel, messageMock, messageMapperMock }; + private Object[] allmocks = new Object[] { requestChannel, replyChannel, messageMock }; @Before public void initializeSample() { this.simpleMessagingGateway = new SimpleMessagingGateway(requestChannel); this.simpleMessagingGateway.setReplyChannel(replyChannel); - this.simpleMessagingGateway.setMessageMapper(messageMapperMock); this.simpleMessagingGateway.setMessageBus(messageBusMock); reset(allmocks); } @@ -114,11 +110,15 @@ public class SimpleMessagingGatewayTests { verify(allmocks); } - @Test + @Test(expected = IllegalArgumentException.class) public void sendMessage_null() { replay(allmocks); - this.simpleMessagingGateway.send(null); - verify(allmocks); + try { + this.simpleMessagingGateway.send(null); + } + finally { + verify(allmocks); + } } /* receive tests */ @@ -126,9 +126,9 @@ public class SimpleMessagingGatewayTests { @Test public void receiveMessage() { expect(replyChannel.receive()).andReturn(messageMock); - expect(messageMapperMock.mapMessage(messageMock)).andReturn(messageMock); + expect(messageMock.getPayload()).andReturn("test").anyTimes(); replay(allmocks); - assertEquals(this.simpleMessagingGateway.receive(), messageMock); + assertEquals("test", this.simpleMessagingGateway.receive()); verify(allmocks); } @@ -136,7 +136,7 @@ public class SimpleMessagingGatewayTests { public void receiveMessage_null() { expect(replyChannel.receive()).andReturn(null); replay(allmocks); - assertEquals(this.simpleMessagingGateway.receive(), null); + assertNull(this.simpleMessagingGateway.receive()); verify(allmocks); } @@ -172,12 +172,16 @@ public class SimpleMessagingGatewayTests { verify(messageHeadersMock); } - @Test + @Test(expected = IllegalArgumentException.class) public void sendNullAndReceiveObject() { expect(replyChannel.getName()).andReturn("replyChannel").anyTimes(); replay(allmocks); - this.simpleMessagingGateway.sendAndReceive(null); - verify(allmocks); + try { + this.simpleMessagingGateway.sendAndReceive(null); + } + finally { + verify(allmocks); + } } @Test @@ -207,12 +211,16 @@ public class SimpleMessagingGatewayTests { verify(allmocks); } - @Test + @Test(expected = IllegalArgumentException.class) public void sendNullAndReceiveMessage() { expect(replyChannel.getName()).andReturn("replyChannel").anyTimes(); replay(allmocks); - this.simpleMessagingGateway.sendAndReceiveMessage(null); - verify(allmocks); + try { + this.simpleMessagingGateway.sendAndReceiveMessage(null); + } + finally { + verify(allmocks); + } } } diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/gateway/config/GatewayParserTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/gateway/config/GatewayParserTests.java index 456e1eac3e..20580e05c7 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/gateway/config/GatewayParserTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/gateway/config/GatewayParserTests.java @@ -75,18 +75,7 @@ public class GatewayParserTests { this.startResponder(requestChannel, replyChannel); TestService service = (TestService) context.getBean("requestReplyWithMessageMapper"); String result = service.requestReply("foo"); - assertEquals("foo.mapped", result); - } - - @Test - public void testRequestReplyWithMessageCreator() { - ApplicationContext context = new ClassPathXmlApplicationContext("gatewayParserTests.xml", this.getClass()); - PollableChannel requestChannel = (PollableChannel) context.getBean("requestChannel"); - MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel"); - this.startResponder(requestChannel, replyChannel); - TestService service = (TestService) context.getBean("requestReplyWithMessageCreator"); - String result = service.requestReply("foo"); - assertEquals("created.foo", result); + assertEquals("pre.foo.post", result); } diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/gateway/config/TestMessageCreator.java b/org.springframework.integration/src/test/java/org/springframework/integration/gateway/config/TestMessageCreator.java deleted file mode 100644 index c26ceaa7c5..0000000000 --- a/org.springframework.integration/src/test/java/org/springframework/integration/gateway/config/TestMessageCreator.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.gateway.config; - -import org.springframework.integration.message.Message; -import org.springframework.integration.message.MessageCreator; -import org.springframework.integration.message.StringMessage; - -/** - * @author Mark Fisher - */ -public class TestMessageCreator implements MessageCreator { - - public Message createMessage(String s) { - return new StringMessage("created." + s); - } - -} diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/gateway/config/TestMessageMapper.java b/org.springframework.integration/src/test/java/org/springframework/integration/gateway/config/TestMessageMapper.java index f0817a2809..b216bff50d 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/gateway/config/TestMessageMapper.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/gateway/config/TestMessageMapper.java @@ -16,16 +16,21 @@ package org.springframework.integration.gateway.config; +import org.springframework.integration.gateway.MessageMapper; import org.springframework.integration.message.Message; -import org.springframework.integration.message.MessageMapper; +import org.springframework.integration.message.StringMessage; /** * @author Mark Fisher */ -public class TestMessageMapper implements MessageMapper { +public class TestMessageMapper implements MessageMapper { - public String mapMessage(Message message) { - return message.getPayload() + ".mapped"; + public Message toMessage(String object) { + return new StringMessage("pre." + object); + } + + public String fromMessage(Message message) { + return message.getPayload().toString() + ".post"; } } diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/gateway/config/gatewayParserTests.xml b/org.springframework.integration/src/test/java/org/springframework/integration/gateway/config/gatewayParserTests.xml index 6c1e393c2e..8df2d68fc7 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/gateway/config/gatewayParserTests.xml +++ b/org.springframework.integration/src/test/java/org/springframework/integration/gateway/config/gatewayParserTests.xml @@ -37,14 +37,6 @@ reply-channel="replyChannel" message-mapper="mapper"/> - - - - diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/message/DefaultMessageCreatorTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/message/DefaultMessageCreatorTests.java deleted file mode 100644 index 4a260fe10b..0000000000 --- a/org.springframework.integration/src/test/java/org/springframework/integration/message/DefaultMessageCreatorTests.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.message; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import org.junit.Test; - -/** - * @author Mark Fisher - */ -public class DefaultMessageCreatorTests { - - @Test - public void testStringPayload() { - DefaultMessageCreator creator = new DefaultMessageCreator(); - Message message = creator.createMessage("testing"); - assertEquals("testing", message.getPayload()); - } - - @Test - public void testObjectPayload() { - DefaultMessageCreator creator = new DefaultMessageCreator(); - Object test = new Object(); - Message message = creator.createMessage(test); - assertEquals(test, message.getPayload()); - } - - @Test - public void testMessage() { - DefaultMessageCreator creator = new DefaultMessageCreator(); - Message inputMessage = new GenericMessage("testing"); - Message message = creator.createMessage(inputMessage); - assertEquals(inputMessage, message); - } - - @Test - public void testNull() { - DefaultMessageCreator creator = new DefaultMessageCreator(); - Message message = creator.createMessage(null); - assertNull(message); - } - -} diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/message/DefaultMessageMapperTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/message/DefaultMessageMapperTests.java deleted file mode 100644 index c7c436794a..0000000000 --- a/org.springframework.integration/src/test/java/org/springframework/integration/message/DefaultMessageMapperTests.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.message; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -/** - * @author Mark Fisher - */ -public class DefaultMessageMapperTests { - - @Test - public void testStringPayload() { - DefaultMessageMapper mapper = new DefaultMessageMapper(); - String result = (String) mapper.mapMessage(new StringMessage("testing")); - assertEquals("testing", result); - } - - @Test - public void testObjectPayload() { - DefaultMessageMapper mapper = new DefaultMessageMapper(); - Object test = new Object(); - Object result = mapper.mapMessage(new GenericMessage(test)); - assertEquals(test, result); - } - - @Test - public void testNullMessage() { - DefaultMessageMapper mapper = new DefaultMessageMapper(); - Object result = mapper.mapMessage(null); - assertEquals(null, result); - } - -}