use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class MappingJackson2MessageConverterTests method fromTextMessageAsMap.
@Test
void fromTextMessageAsMap() throws Exception {
TextMessage textMessageMock = mock(TextMessage.class);
Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar");
String text = "{\"foo\":\"bar\"}";
given(textMessageMock.getStringProperty("__typeid__")).willReturn(HashMap.class.getName());
given(textMessageMock.getText()).willReturn(text);
Object result = converter.fromMessage(textMessageMock);
assertThat(unmarshalled).as("Invalid result").isEqualTo(result);
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class SimpleMessageConverterTests method testStringConversion.
@Test
public void testStringConversion() throws JMSException {
Session session = mock(Session.class);
TextMessage message = mock(TextMessage.class);
String content = "test";
given(session.createTextMessage(content)).willReturn(message);
given(message.getText()).willReturn(content);
SimpleMessageConverter converter = new SimpleMessageConverter();
Message msg = converter.toMessage(content, session);
assertThat(converter.fromMessage(msg)).isEqualTo(content);
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class MarshallingMessageConverterTests method toTextMessage.
@Test
public void toTextMessage() throws Exception {
converter.setTargetType(MessageType.TEXT);
TextMessage textMessageMock = mock(TextMessage.class);
Object toBeMarshalled = new Object();
given(sessionMock.createTextMessage(isA(String.class))).willReturn(textMessageMock);
converter.toMessage(toBeMarshalled, sessionMock);
verify(marshallerMock).marshal(eq(toBeMarshalled), isA(Result.class));
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class MessagingMessageConverterTests method customPayloadConverter.
@Test
public void customPayloadConverter() throws JMSException {
TextMessage jmsMsg = new StubTextMessage("1224");
this.converter.setPayloadConverter(new TestMessageConverter());
Message<?> msg = (Message<?>) this.converter.fromMessage(jmsMsg);
assertThat(msg.getPayload()).isEqualTo(1224L);
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class MappingJackson2MessageConverterTests method toTextMessageWithJsonViewClass.
@Test
void toTextMessageWithJsonViewClass() 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, Summary.class);
verify(textMessageMock).setStringProperty("__typeid__", MyAnotherBean.class.getName());
verify(sessionMock).createTextMessage("{\"name\":\"test\"}");
}
Aggregations