Search in sources :

Example 86 with Session

use of javax.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);
    try {
        resolver.resolveDestinationName(session, DESTINATION_NAME, true);
        fail("expected DestinationResolutionException");
    } catch (DestinationResolutionException ex) {
    // expected
    }
}
Also used : NamingException(javax.naming.NamingException) Session(javax.jms.Session) Test(org.junit.Test)

Example 87 with Session

use of javax.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);
    assertNotNull(destination);
    assertSame(DESTINATION, destination);
}
Also used : Destination(javax.jms.Destination) Session(javax.jms.Session) Test(org.junit.Test)

Example 88 with Session

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

the class MessagingMessageListenerAdapterTests method replyUsesMessageConverterForPayload.

@Test
public void replyUsesMessageConverterForPayload() throws JMSException {
    Session session = mock(Session.class);
    MessageConverter messageConverter = mock(MessageConverter.class);
    given(messageConverter.toMessage("Response", session)).willReturn(new StubTextMessage("Response"));
    Message<String> result = MessageBuilder.withPayload("Response").build();
    MessagingMessageListenerAdapter listener = getSimpleInstance("echo", Message.class);
    listener.setMessageConverter(messageConverter);
    javax.jms.Message replyMessage = listener.buildMessage(session, result);
    verify(messageConverter, times(1)).toMessage("Response", session);
    assertNotNull("reply should never be null", replyMessage);
    assertEquals("Response", ((TextMessage) replyMessage).getText());
}
Also used : StubTextMessage(org.springframework.jms.StubTextMessage) MappingJackson2MessageConverter(org.springframework.jms.support.converter.MappingJackson2MessageConverter) MessageConverter(org.springframework.jms.support.converter.MessageConverter) Session(javax.jms.Session) Test(org.junit.Test)

Example 89 with Session

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

the class MessagingMessageListenerAdapterTests method replyPayloadNoDestination.

@Test
public void replyPayloadNoDestination() throws JMSException {
    Queue replyDestination = mock(Queue.class);
    Session session = mock(Session.class);
    MessageProducer messageProducer = mock(MessageProducer.class);
    TextMessage responseMessage = mock(TextMessage.class);
    given(session.createTextMessage("Response")).willReturn(responseMessage);
    given(session.createProducer(replyDestination)).willReturn(messageProducer);
    MessagingMessageListenerAdapter listener = getPayloadInstance("Response", "replyPayloadNoDestination", Message.class);
    listener.setDefaultResponseDestination(replyDestination);
    listener.onMessage(mock(javax.jms.Message.class), session);
    verify(session, times(0)).createQueue(anyString());
    verify(session).createTextMessage("Response");
    verify(messageProducer).send(responseMessage);
    verify(messageProducer).close();
}
Also used : StubTextMessage(org.springframework.jms.StubTextMessage) Message(org.springframework.messaging.Message) TextMessage(javax.jms.TextMessage) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 90 with Session

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

the class MessagingMessageListenerAdapterTests method testReplyWithJackson.

public TextMessage testReplyWithJackson(String methodName, String replyContent) throws JMSException {
    Queue replyDestination = mock(Queue.class);
    Session session = mock(Session.class);
    MessageProducer messageProducer = mock(MessageProducer.class);
    TextMessage responseMessage = mock(TextMessage.class);
    given(session.createTextMessage(replyContent)).willReturn(responseMessage);
    given(session.createProducer(replyDestination)).willReturn(messageProducer);
    MessagingMessageListenerAdapter listener = getPayloadInstance("Response", methodName, Message.class);
    MappingJackson2MessageConverter messageConverter = new MappingJackson2MessageConverter();
    messageConverter.setTargetType(MessageType.TEXT);
    listener.setMessageConverter(messageConverter);
    listener.setDefaultResponseDestination(replyDestination);
    listener.onMessage(mock(javax.jms.Message.class), session);
    verify(session, times(0)).createQueue(anyString());
    verify(session).createTextMessage(replyContent);
    verify(messageProducer).send(responseMessage);
    verify(messageProducer).close();
    return responseMessage;
}
Also used : MappingJackson2MessageConverter(org.springframework.jms.support.converter.MappingJackson2MessageConverter) StubTextMessage(org.springframework.jms.StubTextMessage) Message(org.springframework.messaging.Message) TextMessage(javax.jms.TextMessage) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Aggregations

Session (javax.jms.Session)281 MessageProducer (javax.jms.MessageProducer)131 Connection (javax.jms.Connection)120 Test (org.junit.Test)110 Message (javax.jms.Message)86 TextMessage (javax.jms.TextMessage)84 JMSException (javax.jms.JMSException)80 MessageConsumer (javax.jms.MessageConsumer)64 Destination (javax.jms.Destination)46 Topic (javax.jms.Topic)40 ConnectionFactory (javax.jms.ConnectionFactory)37 ObjectMessage (javax.jms.ObjectMessage)28 Queue (javax.jms.Queue)26 StubTextMessage (org.springframework.jms.StubTextMessage)20 QueueSession (javax.jms.QueueSession)16 MessagingMessageListenerAdapter (org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter)16 MessageCreator (org.springframework.jms.core.MessageCreator)15 BytesMessage (javax.jms.BytesMessage)14 MapMessage (javax.jms.MapMessage)12 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)12