use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class MappingJackson2MessageConverterTests method testToTextMessageWithReturnType.
private void testToTextMessageWithReturnType(MethodParameter returnType) throws JMSException, NoSuchMethodException {
converter.setTargetType(MessageType.TEXT);
TextMessage textMessageMock = mock(TextMessage.class);
MyAnotherBean bean = new MyAnotherBean("test", "lengthy description");
given(sessionMock.createTextMessage(isA(String.class))).willReturn(textMessageMock);
converter.toMessage(bean, sessionMock, returnType);
verify(textMessageMock).setStringProperty("__typeid__", MyAnotherBean.class.getName());
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class MappingJackson2MessageConverterTests method toTextMessageWithAnotherJsonViewClass.
@Test
void toTextMessageWithAnotherJsonViewClass() throws JMSException {
converter.setTargetType(MessageType.TEXT);
TextMessage textMessageMock = mock(TextMessage.class);
MyAnotherBean bean = new MyAnotherBean("test", "lengthy description");
given(sessionMock.createTextMessage(isA(String.class))).willReturn(textMessageMock);
converter.toMessage(bean, sessionMock, Full.class);
verify(textMessageMock).setStringProperty("__typeid__", MyAnotherBean.class.getName());
verify(sessionMock).createTextMessage("{\"name\":\"test\",\"description\":\"lengthy description\"}");
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class MethodJmsListenerEndpointTests method emptySendTo.
@Test
void emptySendTo() throws JMSException {
MessagingMessageListenerAdapter listener = createDefaultInstance(String.class);
TextMessage reply = mock(TextMessage.class);
Session session = mock(Session.class);
given(session.createTextMessage("content")).willReturn(reply);
assertThatExceptionOfType(ReplyFailureException.class).isThrownBy(() -> listener.onMessage(createSimpleJmsTextMessage("content"), session)).withCauseInstanceOf(InvalidDestinationException.class);
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class MethodJmsListenerEndpointTests method processAndReply.
@Test
void processAndReply() throws JMSException {
MessagingMessageListenerAdapter listener = createDefaultInstance(String.class);
String body = "echo text";
String correlationId = "link-1234";
Destination replyDestination = new Destination() {
};
TextMessage reply = mock(TextMessage.class);
QueueSender queueSender = mock(QueueSender.class);
Session session = mock(Session.class);
given(session.createTextMessage(body)).willReturn(reply);
given(session.createProducer(replyDestination)).willReturn(queueSender);
listener.setDefaultResponseDestination(replyDestination);
StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
inputMessage.setJMSCorrelationID(correlationId);
listener.onMessage(inputMessage, session);
assertDefaultListenerMethodInvocation();
verify(reply).setJMSCorrelationID(correlationId);
verify(queueSender).send(reply);
verify(queueSender).close();
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class MethodJmsListenerEndpointTests method processAndReplyWithSendTo.
private void processAndReplyWithSendTo(MessagingMessageListenerAdapter listener, String replyDestinationName, boolean pubSubDomain, QosSettings replyQosSettings) throws JMSException {
String body = "echo text";
String correlationId = "link-1234";
Destination replyDestination = new Destination() {
};
DestinationResolver destinationResolver = mock(DestinationResolver.class);
TextMessage reply = mock(TextMessage.class);
QueueSender queueSender = mock(QueueSender.class);
Session session = mock(Session.class);
given(destinationResolver.resolveDestinationName(session, replyDestinationName, pubSubDomain)).willReturn(replyDestination);
given(session.createTextMessage(body)).willReturn(reply);
given(session.createProducer(replyDestination)).willReturn(queueSender);
listener.setDestinationResolver(destinationResolver);
StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
inputMessage.setJMSCorrelationID(correlationId);
listener.onMessage(inputMessage, session);
verify(destinationResolver).resolveDestinationName(session, replyDestinationName, pubSubDomain);
verify(reply).setJMSCorrelationID(correlationId);
if (replyQosSettings != null) {
verify(queueSender).send(reply, replyQosSettings.getDeliveryMode(), replyQosSettings.getPriority(), replyQosSettings.getTimeToLive());
} else {
verify(queueSender).send(reply);
}
verify(queueSender).close();
}
Aggregations