Search in sources :

Example 21 with StubTextMessage

use of org.springframework.jms.StubTextMessage in project spring-framework by spring-projects.

the class AbstractJmsAnnotationDrivenTests method testJmsHandlerMethodFactoryConfiguration.

/**
 * Test for {@link ValidationBean} with a validator ({@link TestValidator}) specified
 * in a custom {@link org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory}.
 *
 * The test should throw a {@link org.springframework.jms.listener.adapter.ListenerExecutionFailedException}
 */
protected void testJmsHandlerMethodFactoryConfiguration(ApplicationContext context) throws JMSException {
    JmsListenerContainerTestFactory simpleFactory = context.getBean("defaultFactory", JmsListenerContainerTestFactory.class);
    assertThat(simpleFactory.getListenerContainers().size()).isEqualTo(1);
    MethodJmsListenerEndpoint endpoint = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainers().get(0).getEndpoint();
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    endpoint.setupListenerContainer(container);
    MessagingMessageListenerAdapter listener = (MessagingMessageListenerAdapter) container.getMessageListener();
    listener.onMessage(new StubTextMessage("failValidation"), mock(Session.class));
}
Also used : MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) StubTextMessage(org.springframework.jms.StubTextMessage) SimpleMessageListenerContainer(org.springframework.jms.listener.SimpleMessageListenerContainer) JmsListenerContainerTestFactory(org.springframework.jms.config.JmsListenerContainerTestFactory) MethodJmsListenerEndpoint(org.springframework.jms.config.MethodJmsListenerEndpoint) Session(jakarta.jms.Session)

Example 22 with StubTextMessage

use of org.springframework.jms.StubTextMessage in project spring-framework by spring-projects.

the class JmsListenerContainerFactoryIntegrationTests method testMessageConverterIsUsed.

private void testMessageConverterIsUsed() throws JMSException {
    MethodJmsListenerEndpoint endpoint = createDefaultMethodJmsEndpoint(this.listener.getClass(), "handleIt", String.class, String.class);
    Message message = new StubTextMessage("foo-bar");
    message.setStringProperty("my-header", "my-value");
    invokeListener(endpoint, message);
    assertListenerMethodInvocation("handleIt");
}
Also used : Message(jakarta.jms.Message) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) StubTextMessage(org.springframework.jms.StubTextMessage)

Example 23 with StubTextMessage

use of org.springframework.jms.StubTextMessage in project spring-framework by spring-projects.

the class MessagingMessageListenerAdapterTests method buildMessageWithStandardMessage.

@Test
public void buildMessageWithStandardMessage() throws JMSException {
    Destination replyTo = new Destination() {
    };
    Message<String> result = MessageBuilder.withPayload("Response").setHeader("foo", "bar").setHeader(JmsHeaders.TYPE, "msg_type").setHeader(JmsHeaders.REPLY_TO, replyTo).build();
    Session session = mock(Session.class);
    given(session.createTextMessage("Response")).willReturn(new StubTextMessage("Response"));
    MessagingMessageListenerAdapter listener = getSimpleInstance("echo", Message.class);
    jakarta.jms.Message replyMessage = listener.buildMessage(session, result);
    verify(session).createTextMessage("Response");
    assertThat(replyMessage).as("reply should never be null").isNotNull();
    assertThat(((TextMessage) replyMessage).getText()).isEqualTo("Response");
    assertThat(replyMessage.getStringProperty("foo")).as("custom header not copied").isEqualTo("bar");
    assertThat(replyMessage.getJMSType()).as("type header not copied").isEqualTo("msg_type");
    assertThat(replyMessage.getJMSReplyTo()).as("replyTo header not copied").isEqualTo(replyTo);
}
Also used : Destination(jakarta.jms.Destination) StubTextMessage(org.springframework.jms.StubTextMessage) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 24 with StubTextMessage

use of org.springframework.jms.StubTextMessage in project spring-framework by spring-projects.

the class SimpleJmsHeaderMapperTests method jmsReplyToMappedToHeader.

@Test
public void jmsReplyToMappedToHeader() throws JMSException {
    Destination replyTo = new Destination() {
    };
    jakarta.jms.Message jmsMessage = new StubTextMessage();
    jmsMessage.setJMSReplyTo(replyTo);
    assertInboundHeader(jmsMessage, JmsHeaders.REPLY_TO, replyTo);
}
Also used : Destination(jakarta.jms.Destination) StubTextMessage(org.springframework.jms.StubTextMessage) Test(org.junit.jupiter.api.Test)

Example 25 with StubTextMessage

use of org.springframework.jms.StubTextMessage in project spring-framework by spring-projects.

the class SimpleJmsHeaderMapperTests method destinationMappedToHeader.

@Test
public void destinationMappedToHeader() throws JMSException {
    Destination destination = new Destination() {
    };
    jakarta.jms.Message jmsMessage = new StubTextMessage();
    jmsMessage.setJMSDestination(destination);
    assertInboundHeader(jmsMessage, JmsHeaders.DESTINATION, destination);
}
Also used : Destination(jakarta.jms.Destination) StubTextMessage(org.springframework.jms.StubTextMessage) Test(org.junit.jupiter.api.Test)

Aggregations

StubTextMessage (org.springframework.jms.StubTextMessage)26 Test (org.junit.jupiter.api.Test)21 Session (jakarta.jms.Session)14 Destination (jakarta.jms.Destination)10 TextMessage (jakarta.jms.TextMessage)9 MessagingMessageListenerAdapter (org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter)8 JMSException (jakarta.jms.JMSException)3 Message (jakarta.jms.Message)3 QueueSender (jakarta.jms.QueueSender)2 Assertions.assertThatIllegalStateException (org.assertj.core.api.Assertions.assertThatIllegalStateException)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ProxyFactory (org.springframework.aop.framework.ProxyFactory)2 MessageConverter (org.springframework.jms.support.converter.MessageConverter)2 Message (org.springframework.messaging.Message)2 MessageFormatException (jakarta.jms.MessageFormatException)1 MessageNotWriteableException (jakarta.jms.MessageNotWriteableException)1 ObjectMessage (jakarta.jms.ObjectMessage)1 Writer (java.io.Writer)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1