Search in sources :

Example 1 with MessagingMessageListenerAdapter

use of org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter in project spring-framework by spring-projects.

the class MethodJmsListenerEndpointTests method setExtraCollaborators.

@Test
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);
    assertThat(accessor.getPropertyValue("messageConverter")).isSameAs(messageConverter);
    assertThat(accessor.getPropertyValue("destinationResolver")).isSameAs(destinationResolver);
}
Also used : DestinationResolver(org.springframework.jms.support.destination.DestinationResolver) MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) MessageConverter(org.springframework.jms.support.converter.MessageConverter) Test(org.junit.jupiter.api.Test)

Example 2 with MessagingMessageListenerAdapter

use of org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter in project spring-framework by spring-projects.

the class MethodJmsListenerEndpointTests method resolveMessageAndSession.

@Test
void resolveMessageAndSession() throws JMSException {
    MessagingMessageListenerAdapter listener = createDefaultInstance(jakarta.jms.Message.class, Session.class);
    Session session = mock(Session.class);
    listener.onMessage(createSimpleJmsTextMessage("test"), session);
    assertDefaultListenerMethodInvocation();
}
Also used : MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 3 with MessagingMessageListenerAdapter

use of org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter in project spring-framework by spring-projects.

the class MethodJmsListenerEndpointTests method invalidMessagePayloadType.

@Test
void invalidMessagePayloadType() throws JMSException {
    MessagingMessageListenerAdapter listener = createDefaultInstance(Message.class);
    Session session = mock(Session.class);
    // Message<String> as Message<Integer>
    assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() -> listener.onMessage(createSimpleJmsTextMessage("test"), session)).withCauseInstanceOf(MessageConversionException.class);
}
Also used : MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 4 with MessagingMessageListenerAdapter

use of org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter in project spring-framework by spring-projects.

the class MethodJmsListenerEndpointTests method processFromTopicAndReplyWithSendToQueue.

@Test
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);
}
Also used : MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) SimpleMessageListenerContainer(org.springframework.jms.listener.SimpleMessageListenerContainer) Test(org.junit.jupiter.api.Test)

Example 5 with MessagingMessageListenerAdapter

use of org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter in project spring-framework by spring-projects.

the class MethodJmsListenerEndpointTests method processFromQueueAndReplyWithSendToTopic.

@Test
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);
}
Also used : MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) SimpleMessageListenerContainer(org.springframework.jms.listener.SimpleMessageListenerContainer) Test(org.junit.jupiter.api.Test)

Aggregations

MessagingMessageListenerAdapter (org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter)26 Test (org.junit.jupiter.api.Test)24 Session (jakarta.jms.Session)17 StubTextMessage (org.springframework.jms.StubTextMessage)9 SimpleMessageListenerContainer (org.springframework.jms.listener.SimpleMessageListenerContainer)7 Method (java.lang.reflect.Method)3 TextMessage (jakarta.jms.TextMessage)2 ListenerExecutionFailedException (org.springframework.jms.listener.adapter.ListenerExecutionFailedException)2 QosSettings (org.springframework.jms.support.QosSettings)2 MessageConverter (org.springframework.jms.support.converter.MessageConverter)2 DestinationResolver (org.springframework.jms.support.destination.DestinationResolver)2 DefaultMessageHandlerMethodFactory (org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory)2 Destination (jakarta.jms.Destination)1 ObjectMessage (jakarta.jms.ObjectMessage)1 QueueSender (jakarta.jms.QueueSender)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 JmsListenerContainerTestFactory (org.springframework.jms.config.JmsListenerContainerTestFactory)1 MethodJmsListenerEndpoint (org.springframework.jms.config.MethodJmsListenerEndpoint)1 MessageConversionException (org.springframework.messaging.converter.MessageConversionException)1 InvocableHandlerMethod (org.springframework.messaging.handler.invocation.InvocableHandlerMethod)1