Search in sources :

Example 16 with Destination

use of jakarta.jms.Destination 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();
}
Also used : Destination(jakarta.jms.Destination) MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) QueueSender(jakarta.jms.QueueSender) StubTextMessage(org.springframework.jms.StubTextMessage) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 17 with Destination

use of jakarta.jms.Destination 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();
}
Also used : Destination(jakarta.jms.Destination) DestinationResolver(org.springframework.jms.support.destination.DestinationResolver) QueueSender(jakarta.jms.QueueSender) StubTextMessage(org.springframework.jms.StubTextMessage) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Session(jakarta.jms.Session)

Example 18 with Destination

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

the class JmsTransactionManagerTests method testTransactionCommitWithMessageProducer.

@Test
public void testTransactionCommitWithMessageProducer() throws JMSException {
    Destination dest = new StubQueue();
    ConnectionFactory cf = mock(ConnectionFactory.class);
    Connection con = mock(Connection.class);
    Session session = mock(Session.class);
    MessageProducer producer = mock(MessageProducer.class);
    final Message message = mock(Message.class);
    given(cf.createConnection()).willReturn(con);
    given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session);
    given(session.createProducer(dest)).willReturn(producer);
    given(session.getTransacted()).willReturn(true);
    JmsTransactionManager tm = new JmsTransactionManager(cf);
    TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition());
    JmsTemplate jt = new JmsTemplate(cf);
    jt.send(dest, sess -> message);
    tm.commit(ts);
    verify(producer).send(message);
    verify(session).commit();
    verify(producer).close();
    verify(session).close();
    verify(con).close();
}
Also used : Destination(jakarta.jms.Destination) ConnectionFactory(jakarta.jms.ConnectionFactory) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) Message(jakarta.jms.Message) Connection(jakarta.jms.Connection) TransactionStatus(org.springframework.transaction.TransactionStatus) JmsTemplate(org.springframework.jms.core.JmsTemplate) StubQueue(org.springframework.jms.StubQueue) MessageProducer(jakarta.jms.MessageProducer) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 19 with Destination

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

the class JmsMessagingTemplateTests method sendAndReceiveDefaultDestination.

@Test
public void sendAndReceiveDefaultDestination() {
    Destination destination = new Destination() {
    };
    this.messagingTemplate.setDefaultDestination(destination);
    Message<String> request = createTextMessage();
    jakarta.jms.Message replyJmsMessage = createJmsTextMessage();
    given(this.jmsTemplate.sendAndReceive(eq(destination), any())).willReturn(replyJmsMessage);
    Message<?> actual = this.messagingTemplate.sendAndReceive(request);
    verify(this.jmsTemplate, times(1)).sendAndReceive(eq(destination), any());
    assertTextMessage(actual);
}
Also used : Destination(jakarta.jms.Destination) Test(org.junit.jupiter.api.Test)

Example 20 with Destination

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

the class JmsMessagingTemplateTests method convertAndSendPayload.

@Test
public void convertAndSendPayload() throws JMSException {
    Destination destination = new Destination() {
    };
    this.messagingTemplate.convertAndSend(destination, "my Payload");
    verify(this.jmsTemplate).send(eq(destination), this.messageCreator.capture());
    TextMessage textMessage = createTextMessage(this.messageCreator.getValue());
    assertThat(textMessage.getText()).isEqualTo("my Payload");
}
Also used : Destination(jakarta.jms.Destination) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Test(org.junit.jupiter.api.Test)

Aggregations

Destination (jakarta.jms.Destination)41 Test (org.junit.jupiter.api.Test)31 StubTextMessage (org.springframework.jms.StubTextMessage)11 Session (jakarta.jms.Session)8 TextMessage (jakarta.jms.TextMessage)5 JMSException (jakarta.jms.JMSException)3 HashMap (java.util.HashMap)3 DestinationResolutionException (org.springframework.jms.support.destination.DestinationResolutionException)3 DestinationResolver (org.springframework.jms.support.destination.DestinationResolver)3 MessageProducer (jakarta.jms.MessageProducer)2 QueueSender (jakarta.jms.QueueSender)2 NamingException (javax.naming.NamingException)2 StubQueue (org.springframework.jms.StubQueue)2 Connection (jakarta.jms.Connection)1 ConnectionFactory (jakarta.jms.ConnectionFactory)1 Message (jakarta.jms.Message)1 MessageConsumer (jakarta.jms.MessageConsumer)1 Map (java.util.Map)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 JmsTemplate (org.springframework.jms.core.JmsTemplate)1