Search in sources :

Example 81 with Session

use of jakarta.jms.Session in project spring-framework by spring-projects.

the class SimpleMessageConverterTests method testToMessageSimplyReturnsMessageAsIsIfSuppliedWithMessage.

@Test
public void testToMessageSimplyReturnsMessageAsIsIfSuppliedWithMessage() throws JMSException {
    Session session = mock(Session.class);
    ObjectMessage message = mock(ObjectMessage.class);
    SimpleMessageConverter converter = new SimpleMessageConverter();
    Message msg = converter.toMessage(message, session);
    assertThat(msg).isSameAs(message);
}
Also used : Message(jakarta.jms.Message) BytesMessage(jakarta.jms.BytesMessage) TextMessage(jakarta.jms.TextMessage) MapMessage(jakarta.jms.MapMessage) ObjectMessage(jakarta.jms.ObjectMessage) ObjectMessage(jakarta.jms.ObjectMessage) SimpleMessageConverter(org.springframework.jms.support.converter.SimpleMessageConverter) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 82 with Session

use of jakarta.jms.Session in project spring-framework by spring-projects.

the class SimpleMessageConverterTests method testMapConversionWhereMapHasNNullForKey.

@Test
public void testMapConversionWhereMapHasNNullForKey() throws JMSException {
    MapMessage message = mock(MapMessage.class);
    Session session = mock(Session.class);
    given(session.createMapMessage()).willReturn(message);
    Map<Object, String> content = new HashMap<>(1);
    content.put(null, "value1");
    SimpleMessageConverter converter = new SimpleMessageConverter();
    assertThatExceptionOfType(MessageConversionException.class).isThrownBy(() -> converter.toMessage(content, session));
}
Also used : MessageConversionException(org.springframework.jms.support.converter.MessageConversionException) HashMap(java.util.HashMap) MapMessage(jakarta.jms.MapMessage) SimpleMessageConverter(org.springframework.jms.support.converter.SimpleMessageConverter) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 83 with Session

use of jakarta.jms.Session in project spring-framework by spring-projects.

the class SimpleMessageConverterTests method testMapConversion.

@Test
public void testMapConversion() throws JMSException {
    Session session = mock(Session.class);
    MapMessage message = mock(MapMessage.class);
    Map<String, String> content = new HashMap<>(2);
    content.put("key1", "value1");
    content.put("key2", "value2");
    given(session.createMapMessage()).willReturn(message);
    given(message.getMapNames()).willReturn(Collections.enumeration(content.keySet()));
    given(message.getObject("key1")).willReturn("value1");
    given(message.getObject("key2")).willReturn("value2");
    SimpleMessageConverter converter = new SimpleMessageConverter();
    Message msg = converter.toMessage(content, session);
    assertThat(converter.fromMessage(msg)).isEqualTo(content);
    verify(message).setObject("key1", "value1");
    verify(message).setObject("key2", "value2");
}
Also used : Message(jakarta.jms.Message) BytesMessage(jakarta.jms.BytesMessage) TextMessage(jakarta.jms.TextMessage) MapMessage(jakarta.jms.MapMessage) ObjectMessage(jakarta.jms.ObjectMessage) HashMap(java.util.HashMap) MapMessage(jakarta.jms.MapMessage) SimpleMessageConverter(org.springframework.jms.support.converter.SimpleMessageConverter) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 84 with Session

use of jakarta.jms.Session in project spring-framework by spring-projects.

the class SimpleMessageConverterTests method testSerializableConversion.

@Test
public void testSerializableConversion() throws JMSException {
    Session session = mock(Session.class);
    ObjectMessage message = mock(ObjectMessage.class);
    Integer content = 5;
    given(session.createObjectMessage(content)).willReturn(message);
    given(message.getObject()).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) ObjectMessage(jakarta.jms.ObjectMessage) SimpleMessageConverter(org.springframework.jms.support.converter.SimpleMessageConverter) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Aggregations

Session (jakarta.jms.Session)84 Test (org.junit.jupiter.api.Test)71 Connection (jakarta.jms.Connection)30 Message (jakarta.jms.Message)27 TextMessage (jakarta.jms.TextMessage)26 StubTextMessage (org.springframework.jms.StubTextMessage)22 ConnectionFactory (jakarta.jms.ConnectionFactory)21 JMSException (jakarta.jms.JMSException)20 MessageProducer (jakarta.jms.MessageProducer)19 Destination (jakarta.jms.Destination)18 MessagingMessageListenerAdapter (org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter)16 Queue (jakarta.jms.Queue)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)12 BDDMockito.given (org.mockito.BDDMockito.given)12 Mockito.mock (org.mockito.Mockito.mock)12 Mockito.verify (org.mockito.Mockito.verify)12 StubQueue (org.springframework.jms.StubQueue)12 ObjectMessage (jakarta.jms.ObjectMessage)11 QueueSession (jakarta.jms.QueueSession)11 SimpleMessageConverter (org.springframework.jms.support.converter.SimpleMessageConverter)11