Search in sources :

Example 71 with TextMessage

use of javax.jms.TextMessage in project spring-framework by spring-projects.

the class JmsMessagingTemplateTests method convertAndSendPayloadName.

@Test
public void convertAndSendPayloadName() throws JMSException {
    messagingTemplate.convertAndSend("myQueue", "my Payload");
    verify(jmsTemplate).send(eq("myQueue"), messageCreator.capture());
    TextMessage textMessage = createTextMessage(messageCreator.getValue());
    assertEquals("my Payload", textMessage.getText());
}
Also used : StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 72 with TextMessage

use of javax.jms.TextMessage in project spring-framework by spring-projects.

the class JmsMessagingTemplateTests method convertAndSendDefaultDestinationName.

@Test
public void convertAndSendDefaultDestinationName() throws JMSException {
    messagingTemplate.setDefaultDestinationName("myQueue");
    messagingTemplate.convertAndSend("my Payload");
    verify(jmsTemplate).send(eq("myQueue"), messageCreator.capture());
    TextMessage textMessage = createTextMessage(messageCreator.getValue());
    assertEquals("my Payload", textMessage.getText());
}
Also used : StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 73 with TextMessage

use of javax.jms.TextMessage in project spring-framework by spring-projects.

the class JmsMessagingTemplateTests method createTextMessage.

protected TextMessage createTextMessage(MessageCreator creator) throws JMSException {
    Session mock = mock(Session.class);
    given(mock.createTextMessage(BDDMockito.<String>any())).willAnswer(new Answer<TextMessage>() {

        @Override
        public TextMessage answer(InvocationOnMock invocation) throws Throwable {
            return new StubTextMessage((String) invocation.getArguments()[0]);
        }
    });
    javax.jms.Message message = creator.createMessage(mock);
    verify(mock).createTextMessage(BDDMockito.<String>any());
    return TextMessage.class.cast(message);
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) StubTextMessage(org.springframework.jms.StubTextMessage) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 74 with TextMessage

use of javax.jms.TextMessage in project spring-framework by spring-projects.

the class MessagingMessageListenerAdapterTests method replyPayloadNoDestination.

@Test
public void replyPayloadNoDestination() throws JMSException {
    Queue replyDestination = mock(Queue.class);
    Session session = mock(Session.class);
    MessageProducer messageProducer = mock(MessageProducer.class);
    TextMessage responseMessage = mock(TextMessage.class);
    given(session.createTextMessage("Response")).willReturn(responseMessage);
    given(session.createProducer(replyDestination)).willReturn(messageProducer);
    MessagingMessageListenerAdapter listener = getPayloadInstance("Response", "replyPayloadNoDestination", Message.class);
    listener.setDefaultResponseDestination(replyDestination);
    listener.onMessage(mock(javax.jms.Message.class), session);
    verify(session, times(0)).createQueue(anyString());
    verify(session).createTextMessage("Response");
    verify(messageProducer).send(responseMessage);
    verify(messageProducer).close();
}
Also used : StubTextMessage(org.springframework.jms.StubTextMessage) Message(org.springframework.messaging.Message) TextMessage(javax.jms.TextMessage) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 75 with TextMessage

use of javax.jms.TextMessage in project spring-framework by spring-projects.

the class MessagingMessageListenerAdapterTests method testReplyWithJackson.

public TextMessage testReplyWithJackson(String methodName, String replyContent) throws JMSException {
    Queue replyDestination = mock(Queue.class);
    Session session = mock(Session.class);
    MessageProducer messageProducer = mock(MessageProducer.class);
    TextMessage responseMessage = mock(TextMessage.class);
    given(session.createTextMessage(replyContent)).willReturn(responseMessage);
    given(session.createProducer(replyDestination)).willReturn(messageProducer);
    MessagingMessageListenerAdapter listener = getPayloadInstance("Response", methodName, Message.class);
    MappingJackson2MessageConverter messageConverter = new MappingJackson2MessageConverter();
    messageConverter.setTargetType(MessageType.TEXT);
    listener.setMessageConverter(messageConverter);
    listener.setDefaultResponseDestination(replyDestination);
    listener.onMessage(mock(javax.jms.Message.class), session);
    verify(session, times(0)).createQueue(anyString());
    verify(session).createTextMessage(replyContent);
    verify(messageProducer).send(responseMessage);
    verify(messageProducer).close();
    return responseMessage;
}
Also used : MappingJackson2MessageConverter(org.springframework.jms.support.converter.MappingJackson2MessageConverter) StubTextMessage(org.springframework.jms.StubTextMessage) Message(org.springframework.messaging.Message) TextMessage(javax.jms.TextMessage) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Aggregations

TextMessage (javax.jms.TextMessage)231 Test (org.junit.Test)92 Session (javax.jms.Session)75 MessageProducer (javax.jms.MessageProducer)71 Message (javax.jms.Message)70 JMSException (javax.jms.JMSException)64 Connection (javax.jms.Connection)44 Destination (javax.jms.Destination)44 MessageConsumer (javax.jms.MessageConsumer)44 ObjectMessage (javax.jms.ObjectMessage)25 BytesMessage (javax.jms.BytesMessage)22 Queue (javax.jms.Queue)21 QueueSession (javax.jms.QueueSession)20 StubTextMessage (org.springframework.jms.StubTextMessage)18 ConnectionFactory (javax.jms.ConnectionFactory)13 QueueConnection (javax.jms.QueueConnection)13 CountDownLatch (java.util.concurrent.CountDownLatch)12 MapMessage (javax.jms.MapMessage)11 Topic (javax.jms.Topic)11 JMSContext (javax.jms.JMSContext)9