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());
}
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());
}
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);
}
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();
}
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;
}
Aggregations