Search in sources :

Example 1 with ObjectMessage

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

the class MethodJmsListenerEndpointTests method resolveObjectPayload.

@Test
void resolveObjectPayload() throws JMSException {
    MessagingMessageListenerAdapter listener = createDefaultInstance(MyBean.class);
    MyBean myBean = new MyBean();
    myBean.name = "myBean name";
    Session session = mock(Session.class);
    ObjectMessage message = mock(ObjectMessage.class);
    given(message.getObject()).willReturn(myBean);
    listener.onMessage(message, session);
    assertDefaultListenerMethodInvocation();
}
Also used : MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) ObjectMessage(jakarta.jms.ObjectMessage) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 2 with ObjectMessage

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

the class MessageListenerAdapterTests method testWithMessageContentsDelegateForObjectMessageWithPlainObject.

@Test
void testWithMessageContentsDelegateForObjectMessageWithPlainObject() throws Exception {
    ObjectMessage objectMessage = mock(ObjectMessage.class);
    given(objectMessage.getObject()).willReturn(OBJECT);
    MessageContentsDelegate delegate = mock(MessageContentsDelegate.class);
    MessageListenerAdapter adapter = new MessageListenerAdapter(delegate);
    adapter.onMessage(objectMessage);
    verify(delegate).handleMessage(OBJECT);
}
Also used : ObjectMessage(jakarta.jms.ObjectMessage) Test(org.junit.jupiter.api.Test)

Example 3 with ObjectMessage

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

the class MessageListenerAdapterTests method testWithMessageContentsDelegateForObjectMessage.

@Test
void testWithMessageContentsDelegateForObjectMessage() throws Exception {
    ObjectMessage objectMessage = mock(ObjectMessage.class);
    given(objectMessage.getObject()).willReturn(NUMBER);
    MessageContentsDelegate delegate = mock(MessageContentsDelegate.class);
    MessageListenerAdapter adapter = new MessageListenerAdapter(delegate);
    adapter.onMessage(objectMessage);
    verify(delegate).handleMessage(NUMBER);
}
Also used : ObjectMessage(jakarta.jms.ObjectMessage) Test(org.junit.jupiter.api.Test)

Example 4 with ObjectMessage

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

the class MessagingMessageConverterTests method simpleObject.

@Test
public void simpleObject() throws Exception {
    Session session = mock(Session.class);
    Serializable payload = mock(Serializable.class);
    ObjectMessage jmsMessage = mock(ObjectMessage.class);
    given(session.createObjectMessage(payload)).willReturn(jmsMessage);
    this.converter.toMessage(MessageBuilder.withPayload(payload).build(), session);
    verify(session).createObjectMessage(payload);
}
Also used : Serializable(java.io.Serializable) ObjectMessage(jakarta.jms.ObjectMessage) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 5 with ObjectMessage

use of jakarta.jms.ObjectMessage 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)

Aggregations

ObjectMessage (jakarta.jms.ObjectMessage)6 Test (org.junit.jupiter.api.Test)6 Session (jakarta.jms.Session)4 BytesMessage (jakarta.jms.BytesMessage)2 MapMessage (jakarta.jms.MapMessage)2 Message (jakarta.jms.Message)2 TextMessage (jakarta.jms.TextMessage)2 SimpleMessageConverter (org.springframework.jms.support.converter.SimpleMessageConverter)2 Serializable (java.io.Serializable)1 MessagingMessageListenerAdapter (org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter)1