MessageMapper now defines toMessage() and fromMessage() methods, and the MessageCreator has been removed.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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<String, String> {
|
||||
|
||||
public Message<String> createMessage(String s) {
|
||||
return new StringMessage("created." + s);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<String, String> {
|
||||
public class TestMessageMapper implements MessageMapper<String> {
|
||||
|
||||
public String mapMessage(Message<String> 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";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,14 +37,6 @@
|
||||
reply-channel="replyChannel"
|
||||
message-mapper="mapper"/>
|
||||
|
||||
<gateway id="requestReplyWithMessageCreator"
|
||||
service-interface="org.springframework.integration.gateway.TestService"
|
||||
request-channel="requestChannel"
|
||||
reply-channel="replyChannel"
|
||||
message-creator="creator"/>
|
||||
|
||||
<beans:bean id="mapper" class="org.springframework.integration.gateway.config.TestMessageMapper"/>
|
||||
|
||||
<beans:bean id="creator" class="org.springframework.integration.gateway.config.TestMessageCreator"/>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -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<String>("testing");
|
||||
Message<?> message = creator.createMessage(inputMessage);
|
||||
assertEquals(inputMessage, message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNull() {
|
||||
DefaultMessageCreator creator = new DefaultMessageCreator();
|
||||
Message<?> message = creator.createMessage(null);
|
||||
assertNull(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Object>(test));
|
||||
assertEquals(test, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullMessage() {
|
||||
DefaultMessageMapper mapper = new DefaultMessageMapper();
|
||||
Object result = mapper.mapMessage(null);
|
||||
assertEquals(null, result);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user