private MessagingMessageListenerAdapter createInstance(DefaultMessageHandlerMethodFactory factory, Method method) { return createInstance(factory, method, new SimpleMessageListenerContainer()); }
private MessagingMessageListenerAdapter createDefaultInstance(Class<?>... parameterTypes) { return createInstance(this.factory, getDefaultListenerMethod(parameterTypes)); }
@Test public void processAndReplyWithSendToQueue() throws JMSException { String methodName = "processAndReplyWithSendTo"; SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); MessagingMessageListenerAdapter listener = createInstance(this.factory, getListenerMethod(methodName, String.class), container); processAndReplyWithSendTo(listener, "replyDestination", false); assertListenerMethodInvocation(this.sample, methodName); }
@Test public void processFromQueueAndReplyWithSendToTopic() throws JMSException { String methodName = "processAndReplyWithSendTo"; SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setReplyPubSubDomain(true); MessagingMessageListenerAdapter listener = createInstance(this.factory, getListenerMethod(methodName, String.class), container); processAndReplyWithSendTo(listener, "replyDestination", true); assertListenerMethodInvocation(this.sample, methodName); }
@Test public void processAndReplyWithSendToTopic() throws JMSException { String methodName = "processAndReplyWithSendTo"; SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setPubSubDomain(true); MessagingMessageListenerAdapter listener = createInstance(this.factory, getListenerMethod(methodName, String.class), container); processAndReplyWithSendTo(listener, "replyDestination", true); assertListenerMethodInvocation(this.sample, methodName); }
@Test public void processAndReplyWithNullReplyQosSettings() throws JMSException { String methodName = "processAndReplyWithSendTo"; SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setReplyQosSettings(null); MessagingMessageListenerAdapter listener = createInstance(this.factory, getListenerMethod(methodName, String.class), container); processAndReplyWithSendTo(listener, "replyDestination", false); assertListenerMethodInvocation(this.sample, methodName); }
@Test public void processAndReplyWithCustomReplyQosSettings() throws JMSException { String methodName = "processAndReplyWithSendTo"; SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); QosSettings replyQosSettings = new QosSettings(1, 6, 6000); container.setReplyQosSettings(replyQosSettings); MessagingMessageListenerAdapter listener = createInstance(this.factory, getListenerMethod(methodName, String.class), container); processAndReplyWithSendTo(listener, "replyDestination", false, replyQosSettings); assertListenerMethodInvocation(this.sample, methodName); }
@Test public void processFromTopicAndReplyWithSendToQueue() throws JMSException { String methodName = "processAndReplyWithSendTo"; SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setPubSubDomain(true); container.setReplyPubSubDomain(false); MessagingMessageListenerAdapter listener = createInstance(this.factory, getListenerMethod(methodName, String.class), container); processAndReplyWithSendTo(listener, "replyDestination", false); assertListenerMethodInvocation(this.sample, methodName); }
@Test public void validatePayloadInvalid() throws JMSException { DefaultMessageHandlerMethodFactory customFactory = new DefaultMessageHandlerMethodFactory(); customFactory.setValidator(testValidator("invalid value")); Method method = getListenerMethod("validatePayload", String.class); MessagingMessageListenerAdapter listener = createInstance(customFactory, method); Session session = mock(Session.class); this.thrown.expect(ListenerExecutionFailedException.class); listener.onMessage(createSimpleJmsTextMessage("invalid value"), session); // test is an invalid value }
@Test public void validatePayloadValid() throws JMSException { String methodName = "validatePayload"; DefaultMessageHandlerMethodFactory customFactory = new DefaultMessageHandlerMethodFactory(); customFactory.setValidator(testValidator("invalid value")); initializeFactory(customFactory); Method method = getListenerMethod(methodName, String.class); MessagingMessageListenerAdapter listener = createInstance(customFactory, method); Session session = mock(Session.class); listener.onMessage(createSimpleJmsTextMessage("test"), session); // test is a valid value assertListenerMethodInvocation(this.sample, methodName); }
@Test public void setExtraCollaborators() { MessageConverter messageConverter = mock(MessageConverter.class); DestinationResolver destinationResolver = mock(DestinationResolver.class); this.container.setMessageConverter(messageConverter); this.container.setDestinationResolver(destinationResolver); MessagingMessageListenerAdapter listener = createInstance(this.factory, getListenerMethod("resolveObjectPayload", MyBean.class), this.container); DirectFieldAccessor accessor = new DirectFieldAccessor(listener); assertSame(messageConverter, accessor.getPropertyValue("messageConverter")); assertSame(destinationResolver, accessor.getPropertyValue("destinationResolver")); }