Search in sources :

Example 21 with TextMessage

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);
}
Also used : HashMap(java.util.HashMap) TextMessage(jakarta.jms.TextMessage) Test(org.junit.jupiter.api.Test)

Example 22 with TextMessage

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);
}
Also used : Message(jakarta.jms.Message) BytesMessage(jakarta.jms.BytesMessage) TextMessage(jakarta.jms.TextMessage) MapMessage(jakarta.jms.MapMessage) ObjectMessage(jakarta.jms.ObjectMessage) SimpleMessageConverter(org.springframework.jms.support.converter.SimpleMessageConverter) TextMessage(jakarta.jms.TextMessage) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 23 with TextMessage

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));
}
Also used : TextMessage(jakarta.jms.TextMessage) Result(javax.xml.transform.Result) Test(org.junit.jupiter.api.Test)

Example 24 with TextMessage

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);
}
Also used : StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Message(org.springframework.messaging.Message) ObjectMessage(jakarta.jms.ObjectMessage) StubTextMessage(org.springframework.jms.StubTextMessage) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Test(org.junit.jupiter.api.Test)

Example 25 with TextMessage

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\"}");
}
Also used : TextMessage(jakarta.jms.TextMessage) Test(org.junit.jupiter.api.Test)

Aggregations

TextMessage (jakarta.jms.TextMessage)54 Test (org.junit.jupiter.api.Test)47 StubTextMessage (org.springframework.jms.StubTextMessage)22 Session (jakarta.jms.Session)20 MessageProducer (jakarta.jms.MessageProducer)13 Message (jakarta.jms.Message)12 Queue (jakarta.jms.Queue)10 ObjectMessage (jakarta.jms.ObjectMessage)9 Message (org.springframework.messaging.Message)9 BytesMessage (jakarta.jms.BytesMessage)8 Destination (jakarta.jms.Destination)7 QueueSession (jakarta.jms.QueueSession)7 SimpleMessageConverter (org.springframework.jms.support.converter.SimpleMessageConverter)5 JMSException (jakarta.jms.JMSException)4 QueueSender (jakarta.jms.QueueSender)4 MessageConsumer (jakarta.jms.MessageConsumer)3 HashMap (java.util.HashMap)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 QosSettings (org.springframework.jms.support.QosSettings)3 ConnectionFactory (jakarta.jms.ConnectionFactory)2