diff options
Diffstat (limited to 'spring-jms/src/test/java/org/springframework/jms/config/MethodJmsListenerEndpointTests.java')
-rw-r--r-- | spring-jms/src/test/java/org/springframework/jms/config/MethodJmsListenerEndpointTests.java | 44 |
1 files changed, 31 insertions, 13 deletions
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); |