INT-1389 removed all dependencies on StringMessage from unit tests in spring-integration-jms
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -28,9 +28,9 @@ import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.core.GenericMessage;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
import org.springframework.integration.core.StringMessage;
|
||||
import org.springframework.jms.support.converter.MessageConversionException;
|
||||
import org.springframework.jms.support.converter.MessageConverter;
|
||||
import org.springframework.jms.support.converter.SimpleMessageConverter;
|
||||
@@ -82,7 +82,7 @@ public class ChannelPublishingJmsMessageListenerTests {
|
||||
new SimpleAsyncTaskExecutor().execute(new Runnable() {
|
||||
public void run() {
|
||||
Message<?> request = channel.receive(5000);
|
||||
Message<?> reply = new StringMessage(((String) request.getPayload()).toUpperCase());
|
||||
Message<?> reply = new GenericMessage<String>(((String) request.getPayload()).toUpperCase());
|
||||
((MessageChannel) request.getHeaders().getReplyChannel()).send(reply, 5000);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -16,25 +16,31 @@
|
||||
|
||||
package org.springframework.integration.jms;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
import org.apache.activemq.command.ActiveMQTopic;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
import org.springframework.integration.core.StringMessage;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import javax.jms.Destination;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import javax.jms.Destination;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
import org.apache.activemq.command.ActiveMQTopic;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.core.GenericMessage;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -82,8 +88,8 @@ public class JmsDestinationBackedMessageChannelTests {
|
||||
channel.start();
|
||||
channel.subscribe(handler1);
|
||||
channel.subscribe(handler2);
|
||||
channel.send(new StringMessage("foo"));
|
||||
channel.send(new StringMessage("bar"));
|
||||
channel.send(new GenericMessage<String>("foo"));
|
||||
channel.send(new GenericMessage<String>("bar"));
|
||||
latch.await(TIMEOUT, TimeUnit.MILLISECONDS);
|
||||
assertEquals(1, receivedList1.size());
|
||||
assertNotNull(receivedList1.get(0));
|
||||
@@ -120,8 +126,8 @@ public class JmsDestinationBackedMessageChannelTests {
|
||||
if (!channel.waitRegisteredWithDestination(10000)) {
|
||||
fail("Listener failed to subscribe to topic");
|
||||
}
|
||||
channel.send(new StringMessage("foo"));
|
||||
channel.send(new StringMessage("bar"));
|
||||
channel.send(new GenericMessage<String>("foo"));
|
||||
channel.send(new GenericMessage<String>("bar"));
|
||||
latch.await(TIMEOUT, TimeUnit.MILLISECONDS);
|
||||
assertEquals(2, receivedList1.size());
|
||||
assertEquals("foo", receivedList1.get(0).getPayload());
|
||||
@@ -155,8 +161,8 @@ public class JmsDestinationBackedMessageChannelTests {
|
||||
channel.start();
|
||||
channel.subscribe(handler1);
|
||||
channel.subscribe(handler2);
|
||||
channel.send(new StringMessage("foo"));
|
||||
channel.send(new StringMessage("bar"));
|
||||
channel.send(new GenericMessage<String>("foo"));
|
||||
channel.send(new GenericMessage<String>("bar"));
|
||||
latch.await(TIMEOUT, TimeUnit.MILLISECONDS);
|
||||
assertEquals(1, receivedList1.size());
|
||||
assertNotNull(receivedList1.get(0));
|
||||
@@ -193,8 +199,8 @@ public class JmsDestinationBackedMessageChannelTests {
|
||||
}
|
||||
channel.subscribe(handler1);
|
||||
channel.subscribe(handler2);
|
||||
channel.send(new StringMessage("foo"));
|
||||
channel.send(new StringMessage("bar"));
|
||||
channel.send(new GenericMessage<String>("foo"));
|
||||
channel.send(new GenericMessage<String>("bar"));
|
||||
latch.await(TIMEOUT, TimeUnit.MILLISECONDS);
|
||||
assertEquals(2, receivedList1.size());
|
||||
assertEquals("foo", receivedList1.get(0).getPayload());
|
||||
|
||||
@@ -13,10 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.jms.config;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
|
||||
/**
|
||||
@@ -25,17 +29,17 @@ import org.junit.Before;
|
||||
*/
|
||||
public class ActiveMqTestUtils {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(ActiveMqTestUtils.class);
|
||||
|
||||
|
||||
@Before
|
||||
public static void prepare() {
|
||||
System.out.println("####### Refreshing ActiveMq ########");
|
||||
logger.info("####### Refreshing ActiveMq ########");
|
||||
File activeMqTempDir = new File("activemq-data");
|
||||
deleteDir(activeMqTempDir);
|
||||
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
private static void deleteDir(File directory){
|
||||
|
||||
private static void deleteDir(File directory) {
|
||||
if (directory.exists()){
|
||||
String[] children = directory.list();
|
||||
if (children != null){
|
||||
@@ -46,4 +50,5 @@ public class ActiveMqTestUtils {
|
||||
}
|
||||
directory.delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,11 +22,12 @@ import javax.jms.Destination;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.core.GenericMessage;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
import org.springframework.integration.core.StringMessage;
|
||||
import org.springframework.integration.jms.DefaultJmsHeaderMapper;
|
||||
import org.springframework.integration.jms.JmsHeaders;
|
||||
import org.springframework.integration.jms.StubTextMessage;
|
||||
@@ -55,7 +56,7 @@ public class JmsHeaderEnricherTests {
|
||||
|
||||
@Test // INT-804
|
||||
public void verifyReplyToValue() throws Exception {
|
||||
valueTestInput.send(new StringMessage("test"));
|
||||
valueTestInput.send(new GenericMessage<String>("test"));
|
||||
Message<?> result = output.receive(0);
|
||||
assertEquals(testDestination, result.getHeaders().get(JmsHeaders.REPLY_TO));
|
||||
StubTextMessage jmsMessage = new StubTextMessage();
|
||||
@@ -66,7 +67,7 @@ public class JmsHeaderEnricherTests {
|
||||
|
||||
@Test
|
||||
public void verifyCorrelationIdValue() throws Exception {
|
||||
valueTestInput.send(new StringMessage("test"));
|
||||
valueTestInput.send(new GenericMessage<String>("test"));
|
||||
Message<?> result = output.receive(0);
|
||||
assertEquals("ABC", result.getHeaders().get(JmsHeaders.CORRELATION_ID));
|
||||
StubTextMessage jmsMessage = new StubTextMessage();
|
||||
@@ -77,7 +78,7 @@ public class JmsHeaderEnricherTests {
|
||||
|
||||
@Test // see INT-1122 and INT-1123
|
||||
public void verifyCorrelationIdExpression() throws Exception {
|
||||
expressionTestInput.send(new StringMessage("test"));
|
||||
expressionTestInput.send(new GenericMessage<String>("test"));
|
||||
Message<?> result = output.receive(0);
|
||||
assertEquals(123, result.getHeaders().get(JmsHeaders.CORRELATION_ID));
|
||||
StubTextMessage jmsMessage = new StubTextMessage();
|
||||
|
||||
@@ -36,10 +36,10 @@ import org.springframework.integration.MessageHeaders;
|
||||
import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.context.NamedComponent;
|
||||
import org.springframework.integration.core.GenericMessage;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
import org.springframework.integration.core.StringMessage;
|
||||
import org.springframework.integration.core.SubscribableChannel;
|
||||
import org.springframework.integration.history.MessageHistory;
|
||||
import org.springframework.integration.jms.DefaultJmsHeaderMapper;
|
||||
@@ -74,7 +74,7 @@ public class JmsMessageHistoryTests {
|
||||
ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("MessageHistoryTests-withHeaderMapper.xml", JmsMessageHistoryTests.class);
|
||||
DirectChannel input = applicationContext.getBean("outbound-channel", DirectChannel.class);
|
||||
PollableChannel jmsInputChannel = applicationContext.getBean("jmsInputChannel", PollableChannel.class);
|
||||
input.send(new StringMessage("hello"));
|
||||
input.send(new GenericMessage<String>("hello"));
|
||||
Message<?> message = jmsInputChannel.receive(50000);
|
||||
Iterator<Properties> historyIterator = message.getHeaders().get(MessageHistory.HEADER_NAME, MessageHistory.class).iterator();
|
||||
Properties event = historyIterator.next();
|
||||
@@ -117,7 +117,7 @@ public class JmsMessageHistoryTests {
|
||||
assertEquals("inbound-jms-channel", event.getProperty(MessageHistory.NAME_PROPERTY));
|
||||
|
||||
MessageChannel channel = (MessageChannel) message.getHeaders().getReplyChannel();
|
||||
channel.send(new StringMessage("OK"));
|
||||
channel.send(new GenericMessage<String>("OK"));
|
||||
}
|
||||
};
|
||||
handler = Mockito.spy(handler);
|
||||
@@ -125,18 +125,26 @@ public class JmsMessageHistoryTests {
|
||||
gateway.echo("hello");
|
||||
Mockito.verify(handler, Mockito.times(1)).handleMessage(Mockito.any(Message.class));
|
||||
}
|
||||
|
||||
public static interface SampleGateway{
|
||||
|
||||
|
||||
public static interface SampleGateway {
|
||||
|
||||
public void send(String value);
|
||||
|
||||
public Message<?> echo(String value);
|
||||
|
||||
}
|
||||
|
||||
public static class SampleService{
|
||||
public Message<?> echoMessage(String value){
|
||||
return new StringMessage(value);
|
||||
|
||||
|
||||
public static class SampleService {
|
||||
|
||||
public Message<?> echoMessage(String value) {
|
||||
return new GenericMessage<String>(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static class SampleHeaderMapper extends DefaultJmsHeaderMapper {
|
||||
|
||||
public void fromHeaders(MessageHeaders headers, javax.jms.Message jmsMessage) {
|
||||
@@ -171,19 +179,26 @@ public class JmsMessageHistoryTests {
|
||||
return headers;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static class SampleComponent implements NamedComponent{
|
||||
|
||||
private String name;
|
||||
|
||||
private String type;
|
||||
|
||||
public SampleComponent(String name, String type){
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getComponentName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getComponentType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,8 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.jms.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
@@ -24,69 +27,75 @@ import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.core.GenericMessage;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
import org.springframework.integration.core.StringMessage;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
import org.springframework.oxm.XmlMappingException;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
public class JmsWithMarshallingMessageConverterTests {
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void demoWithMarshallingConverter(){
|
||||
@SuppressWarnings("unchecked")
|
||||
public void demoWithMarshallingConverter() {
|
||||
ActiveMqTestUtils.prepare();
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("JmsWithMarshallingMessageConverterTests-context.xml", JmsWithMarshallingMessageConverterTests.class);
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext(
|
||||
"JmsWithMarshallingMessageConverterTests-context.xml", JmsWithMarshallingMessageConverterTests.class);
|
||||
MessageChannel input = ac.getBean("outbound-gateway-channel", MessageChannel.class);
|
||||
PollableChannel output = ac.getBean("output", PollableChannel.class);
|
||||
|
||||
input.send(new StringMessage("hello"));
|
||||
input.send(new GenericMessage<String>("hello"));
|
||||
Message<String> replyMessage = (Message<String>) output.receive();
|
||||
System.out.println("Message: " + replyMessage);
|
||||
assertEquals("HELLO", replyMessage.getPayload());
|
||||
}
|
||||
|
||||
public static class SampleService{
|
||||
public String echo(String value){
|
||||
|
||||
|
||||
public static class SampleService {
|
||||
|
||||
public String echo(String value) {
|
||||
return value.toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
public static class SampleMarshaller implements Marshaller{
|
||||
public void marshal(Object graph, Result result) throws IOException,
|
||||
XmlMappingException {
|
||||
|
||||
|
||||
public static class SampleMarshaller implements Marshaller {
|
||||
|
||||
public void marshal(Object graph, Result result) throws IOException, XmlMappingException {
|
||||
String payload = null;
|
||||
if (graph instanceof Message<?>){
|
||||
if (graph instanceof Message<?>) {
|
||||
payload = (String) ((Message<?>)graph).getPayload();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
payload = (String) graph;
|
||||
}
|
||||
((StreamResult)result).getOutputStream().write(payload.getBytes());
|
||||
|
||||
}
|
||||
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SampleUnmarshaller implements Unmarshaller{
|
||||
|
||||
|
||||
public static class SampleUnmarshaller implements Unmarshaller {
|
||||
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return true;
|
||||
}
|
||||
public Object unmarshal(Source source) throws IOException,
|
||||
XmlMappingException {
|
||||
|
||||
|
||||
public Object unmarshal(Source source) throws IOException, XmlMappingException {
|
||||
InputStream io = ((StreamSource)source).getInputStream();
|
||||
byte[] bytes = new byte[io.available()];
|
||||
io.read(bytes);
|
||||
return new StringMessage(new String(bytes));
|
||||
return new GenericMessage<String>(new String(bytes));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user