Search in sources :

Example 31 with Destination

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

the class DynamicDestinationResolverTests method testResolveDestination.

private static void testResolveDestination(Session session, Destination expectedDestination, boolean isPubSub) throws JMSException {
    DynamicDestinationResolver resolver = new DynamicDestinationResolver();
    Destination destination = resolver.resolveDestinationName(session, DESTINATION_NAME, isPubSub);
    assertThat(destination).isNotNull();
    assertThat(destination).isSameAs(expectedDestination);
}
Also used : Destination(jakarta.jms.Destination)

Example 32 with Destination

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

the class JndiDestinationResolverTests method testDelegatesToFallbackIfNotResolvedInJndi.

@Test
public void testDelegatesToFallbackIfNotResolvedInJndi() throws Exception {
    Session session = mock(Session.class);
    DestinationResolver dynamicResolver = mock(DestinationResolver.class);
    given(dynamicResolver.resolveDestinationName(session, DESTINATION_NAME, true)).willReturn(DESTINATION);
    JndiDestinationResolver resolver = new JndiDestinationResolver() {

        @Override
        protected <T> T lookup(String jndiName, Class<T> requiredClass) throws NamingException {
            throw new NamingException();
        }
    };
    resolver.setFallbackToDynamicDestination(true);
    resolver.setDynamicDestinationResolver(dynamicResolver);
    Destination destination = resolver.resolveDestinationName(session, DESTINATION_NAME, true);
    assertThat(destination).isNotNull();
    assertThat(destination).isSameAs(DESTINATION);
}
Also used : Destination(jakarta.jms.Destination) NamingException(javax.naming.NamingException) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 33 with Destination

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

the class JmsMessagingTemplateTests method convertDestinationResolutionExceptionOnSend.

@Test
public void convertDestinationResolutionExceptionOnSend() {
    Destination destination = new Destination() {
    };
    willThrow(DestinationResolutionException.class).given(this.jmsTemplate).send(eq(destination), any());
    assertThatExceptionOfType(org.springframework.messaging.core.DestinationResolutionException.class).isThrownBy(() -> this.messagingTemplate.send(destination, createTextMessage()));
}
Also used : Destination(jakarta.jms.Destination) DestinationResolutionException(org.springframework.jms.support.destination.DestinationResolutionException) Test(org.junit.jupiter.api.Test)

Example 34 with Destination

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

the class JmsMessagingTemplateTests method convertAndSendPayloadAndHeaders.

@Test
public void convertAndSendPayloadAndHeaders() throws JMSException {
    Destination destination = new Destination() {
    };
    Map<String, Object> headers = new HashMap<>();
    headers.put("foo", "bar");
    this.messagingTemplate.convertAndSend(destination, "Hello", headers);
    verify(this.jmsTemplate).send(eq(destination), this.messageCreator.capture());
    // see createTextMessage
    assertTextMessage(this.messageCreator.getValue());
}
Also used : Destination(jakarta.jms.Destination) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 35 with Destination

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

the class JmsMessagingTemplateTests method receiveAndConvertDefaultDestination.

@Test
public void receiveAndConvertDefaultDestination() {
    Destination destination = new Destination() {
    };
    this.messagingTemplate.setDefaultDestination(destination);
    jakarta.jms.Message jmsMessage = createJmsTextMessage("my Payload");
    given(this.jmsTemplate.receive(destination)).willReturn(jmsMessage);
    String payload = this.messagingTemplate.receiveAndConvert(String.class);
    assertThat(payload).isEqualTo("my Payload");
    verify(this.jmsTemplate).receive(destination);
}
Also used : Destination(jakarta.jms.Destination) 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