Search in sources :

Example 41 with Session

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

the class DynamicDestinationResolverTests method resolveWithPointToPointVanillaSession.

@Test
public void resolveWithPointToPointVanillaSession() throws Exception {
    Queue expectedDestination = new StubQueue();
    Session session = mock(Session.class);
    given(session.createQueue(DESTINATION_NAME)).willReturn(expectedDestination);
    testResolveDestination(session, expectedDestination, false);
}
Also used : StubQueue(org.springframework.jms.StubQueue) StubQueue(org.springframework.jms.StubQueue) Queue(jakarta.jms.Queue) QueueSession(jakarta.jms.QueueSession) Session(jakarta.jms.Session) TopicSession(jakarta.jms.TopicSession) Test(org.junit.jupiter.api.Test)

Example 42 with Session

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

the class JndiDestinationResolverTests method testDoesNotDelegateToFallbackIfNotResolvedInJndi.

@Test
public void testDoesNotDelegateToFallbackIfNotResolvedInJndi() throws Exception {
    final Session session = mock(Session.class);
    DestinationResolver dynamicResolver = mock(DestinationResolver.class);
    final JndiDestinationResolver resolver = new JndiDestinationResolver() {

        @Override
        protected <T> T lookup(String jndiName, Class<T> requiredClass) throws NamingException {
            throw new NamingException();
        }
    };
    resolver.setDynamicDestinationResolver(dynamicResolver);
    assertThatExceptionOfType(DestinationResolutionException.class).isThrownBy(() -> resolver.resolveDestinationName(session, DESTINATION_NAME, true));
}
Also used : NamingException(javax.naming.NamingException) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 43 with Session

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

the class JndiDestinationResolverTests method testDoesNotUseCacheIfCachingIsTurnedOff.

@Test
public void testDoesNotUseCacheIfCachingIsTurnedOff() throws Exception {
    Session session = mock(Session.class);
    CountingCannedJndiDestinationResolver resolver = new CountingCannedJndiDestinationResolver();
    resolver.setCache(false);
    Destination destination = resolver.resolveDestinationName(session, DESTINATION_NAME, true);
    assertThat(destination).isNotNull();
    assertThat(destination).isSameAs(DESTINATION);
    assertThat(resolver.getCallCount()).isEqualTo(1);
    destination = resolver.resolveDestinationName(session, DESTINATION_NAME, true);
    assertThat(destination).isNotNull();
    assertThat(destination).isSameAs(DESTINATION);
    assertThat(resolver.getCallCount()).isEqualTo(2);
}
Also used : Destination(jakarta.jms.Destination) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 44 with Session

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

the class JndiDestinationResolverTests method testHitsCacheSecondTimeThrough.

@Test
public void testHitsCacheSecondTimeThrough() throws Exception {
    Session session = mock(Session.class);
    JndiDestinationResolver resolver = new OneTimeLookupJndiDestinationResolver();
    Destination destination = resolver.resolveDestinationName(session, DESTINATION_NAME, true);
    assertThat(destination).isNotNull();
    assertThat(destination).isSameAs(DESTINATION);
}
Also used : Destination(jakarta.jms.Destination) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 45 with Session

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

the class MethodJmsListenerEndpointTests method resolveHeaderAndPayload.

@Test
void resolveHeaderAndPayload() throws JMSException {
    MessagingMessageListenerAdapter listener = createDefaultInstance(String.class, int.class);
    Session session = mock(Session.class);
    StubTextMessage message = createSimpleJmsTextMessage("my payload");
    message.setIntProperty("myCounter", 55);
    listener.onMessage(message, session);
    assertDefaultListenerMethodInvocation();
}
Also used : MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) StubTextMessage(org.springframework.jms.StubTextMessage) 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