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
}
}
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);
}
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());
}
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();
}
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;
}
Aggregations