summaryrefslogtreecommitdiff
path: root/spring-jms/src/test/java/org/springframework/jms/config
diff options
context:
space:
mode:
Diffstat (limited to 'spring-jms/src/test/java/org/springframework/jms/config')
-rw-r--r--spring-jms/src/test/java/org/springframework/jms/config/JmsListenerContainerFactoryIntegrationTests.java19
-rw-r--r--spring-jms/src/test/java/org/springframework/jms/config/MethodJmsListenerEndpointTests.java44
2 files changed, 46 insertions, 17 deletions
diff --git a/spring-jms/src/test/java/org/springframework/jms/config/JmsListenerContainerFactoryIntegrationTests.java b/spring-jms/src/test/java/org/springframework/jms/config/JmsListenerContainerFactoryIntegrationTests.java
index da2a90c1..dcfceb82 100644
--- a/spring-jms/src/test/java/org/springframework/jms/config/JmsListenerContainerFactoryIntegrationTests.java
+++ b/spring-jms/src/test/java/org/springframework/jms/config/JmsListenerContainerFactoryIntegrationTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2016 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.
@@ -17,7 +17,6 @@
package org.springframework.jms.config;
import java.lang.reflect.Method;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import javax.jms.JMSException;
@@ -36,6 +35,7 @@ import org.springframework.jms.listener.DefaultMessageListenerContainer;
import org.springframework.jms.listener.SessionAwareMessageListener;
import org.springframework.jms.support.converter.MessageConversionException;
import org.springframework.jms.support.converter.MessageConverter;
+import org.springframework.jms.support.converter.MessagingMessageConverter;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory;
@@ -66,10 +66,21 @@ public class JmsListenerContainerFactoryIntegrationTests {
@Test
public void messageConverterUsedIfSet() throws JMSException {
- containerFactory.setMessageConverter(new UpperCaseMessageConverter());
+ this.containerFactory.setMessageConverter(new UpperCaseMessageConverter());
+ testMessageConverterIsUsed();
+ }
+
+ @Test
+ public void messagingMessageConverterCanBeUsed() throws JMSException {
+ MessagingMessageConverter converter = new MessagingMessageConverter();
+ converter.setPayloadConverter(new UpperCaseMessageConverter());
+ this.containerFactory.setMessageConverter(converter);
+ testMessageConverterIsUsed();
+ }
+ private void testMessageConverterIsUsed() throws JMSException {
MethodJmsListenerEndpoint endpoint = createDefaultMethodJmsEndpoint(
- listener.getClass(), "handleIt", String.class, String.class);
+ this.listener.getClass(), "handleIt", String.class, String.class);
Message message = new StubTextMessage("foo-bar");
message.setStringProperty("my-header", "my-value");
diff --git a/spring-jms/src/test/java/org/springframework/jms/config/MethodJmsListenerEndpointTests.java b/spring-jms/src/test/java/org/springframework/jms/config/MethodJmsListenerEndpointTests.java
index c8771107..fb16b199 100644
--- a/spring-jms/src/test/java/org/springframework/jms/config/MethodJmsListenerEndpointTests.java
+++ b/spring-jms/src/test/java/org/springframework/jms/config/MethodJmsListenerEndpointTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2016 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.
@@ -57,14 +57,18 @@ import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory;
-import org.springframework.messaging.handler.annotation.support.MethodArgumentTypeMismatchException;
import org.springframework.util.ReflectionUtils;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
import org.springframework.validation.annotation.Validated;
-import static org.junit.Assert.*;
-import static org.mockito.BDDMockito.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.BDDMockito.mock;
+import static org.mockito.BDDMockito.verify;
/**
* @author Stephane Nicoll
@@ -266,7 +270,7 @@ public class MethodJmsListenerEndpointTests {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
MessagingMessageListenerAdapter listener = createInstance(this.factory,
getListenerMethod(methodName, String.class), container);
- processAndReplyWithSendTo(listener, false);
+ processAndReplyWithSendTo(listener, "replyDestination", false);
assertListenerMethodInvocation(sample, methodName);
}
@@ -278,7 +282,7 @@ public class MethodJmsListenerEndpointTests {
container.setReplyPubSubDomain(false);
MessagingMessageListenerAdapter listener = createInstance(this.factory,
getListenerMethod(methodName, String.class), container);
- processAndReplyWithSendTo(listener, false);
+ processAndReplyWithSendTo(listener, "replyDestination", false);
assertListenerMethodInvocation(sample, methodName);
}
@@ -289,7 +293,7 @@ public class MethodJmsListenerEndpointTests {
container.setPubSubDomain(true);
MessagingMessageListenerAdapter listener = createInstance(this.factory,
getListenerMethod(methodName, String.class), container);
- processAndReplyWithSendTo(listener, true);
+ processAndReplyWithSendTo(listener, "replyDestination", true);
assertListenerMethodInvocation(sample, methodName);
}
@@ -300,11 +304,19 @@ public class MethodJmsListenerEndpointTests {
container.setReplyPubSubDomain(true);
MessagingMessageListenerAdapter listener = createInstance(this.factory,
getListenerMethod(methodName, String.class), container);
- processAndReplyWithSendTo(listener, true);
+ processAndReplyWithSendTo(listener, "replyDestination", true);
assertListenerMethodInvocation(sample, methodName);
}
- private void processAndReplyWithSendTo(MessagingMessageListenerAdapter listener, boolean pubSubDomain) throws JMSException {
+ @Test
+ public void processAndReplyWithDefaultSendTo() throws JMSException {
+ MessagingMessageListenerAdapter listener = createDefaultInstance(String.class);
+ processAndReplyWithSendTo(listener, "defaultReply", false);
+ assertDefaultListenerMethodInvocation();
+ }
+
+ private void processAndReplyWithSendTo(MessagingMessageListenerAdapter listener,
+ String replyDestinationName, boolean pubSubDomain) throws JMSException {
String body = "echo text";
String correlationId = "link-1234";
Destination replyDestination = new Destination() {};
@@ -314,7 +326,7 @@ public class MethodJmsListenerEndpointTests {
QueueSender queueSender = mock(QueueSender.class);
Session session = mock(Session.class);
- given(destinationResolver.resolveDestinationName(session, "replyDestination", pubSubDomain))
+ given(destinationResolver.resolveDestinationName(session, replyDestinationName, pubSubDomain))
.willReturn(replyDestination);
given(session.createTextMessage(body)).willReturn(reply);
given(session.createProducer(replyDestination)).willReturn(queueSender);
@@ -324,7 +336,7 @@ public class MethodJmsListenerEndpointTests {
inputMessage.setJMSCorrelationID(correlationId);
listener.onMessage(inputMessage, session);
- verify(destinationResolver).resolveDestinationName(session, "replyDestination", pubSubDomain);
+ verify(destinationResolver).resolveDestinationName(session, replyDestinationName, pubSubDomain);
verify(reply).setJMSCorrelationID(correlationId);
verify(queueSender).send(reply);
verify(queueSender).close();
@@ -399,7 +411,7 @@ public class MethodJmsListenerEndpointTests {
Session session = mock(Session.class);
thrown.expect(ListenerExecutionFailedException.class);
- thrown.expectCause(Matchers.isA(MethodArgumentTypeMismatchException.class));
+ thrown.expectCause(Matchers.isA(MessageConversionException.class));
listener.onMessage(createSimpleJmsTextMessage("test"), session); // Message<String> as Message<Integer>
}
@@ -470,9 +482,10 @@ public class MethodJmsListenerEndpointTests {
}
+ @SendTo("defaultReply") @SuppressWarnings("unused")
static class JmsEndpointSampleBean {
- private final Map<String, Boolean> invocations = new HashMap<String, Boolean>();
+ private final Map<String, Boolean> invocations = new HashMap<>();
public void resolveMessageAndSession(javax.jms.Message message, Session session) {
invocations.put("resolveMessageAndSession", true);
@@ -549,6 +562,11 @@ public class MethodJmsListenerEndpointTests {
return content;
}
+ public String processAndReplyWithDefaultSendTo(String content) {
+ invocations.put("processAndReplyWithDefaultSendTo", true);
+ return content;
+ }
+
@SendTo("")
public String emptySendTo(String content) {
invocations.put("emptySendTo", true);