use of jakarta.jms.Session in project spring-framework by spring-projects.
the class SimpleMessageListenerContainerTests method testContextRefreshedEventDoesNotStartTheConnectionIfAutoStartIsSetToFalse.
@Test
public void testContextRefreshedEventDoesNotStartTheConnectionIfAutoStartIsSetToFalse() throws Exception {
MessageConsumer messageConsumer = mock(MessageConsumer.class);
Session session = mock(Session.class);
// Queue gets created in order to create MessageConsumer for that Destination...
given(session.createQueue(DESTINATION_NAME)).willReturn(QUEUE_DESTINATION);
// and then the MessageConsumer gets created...
// no MessageSelector...
given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer);
Connection connection = mock(Connection.class);
// session gets created in order to register MessageListener...
given(connection.createSession(this.container.isSessionTransacted(), this.container.getSessionAcknowledgeMode())).willReturn(session);
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
given(connectionFactory.createConnection()).willReturn(connection);
this.container.setConnectionFactory(connectionFactory);
this.container.setDestinationName(DESTINATION_NAME);
this.container.setMessageListener(new TestMessageListener());
this.container.setAutoStartup(false);
this.container.afterPropertiesSet();
GenericApplicationContext context = new GenericApplicationContext();
context.getBeanFactory().registerSingleton("messageListenerContainer", this.container);
context.refresh();
context.close();
verify(connection).setExceptionListener(this.container);
}
use of jakarta.jms.Session in project spring-framework by spring-projects.
the class MessagingMessageConverterTests method simpleObject.
@Test
public void simpleObject() throws Exception {
Session session = mock(Session.class);
Serializable payload = mock(Serializable.class);
ObjectMessage jmsMessage = mock(ObjectMessage.class);
given(session.createObjectMessage(payload)).willReturn(jmsMessage);
this.converter.toMessage(MessageBuilder.withPayload(payload).build(), session);
verify(session).createObjectMessage(payload);
}
use of jakarta.jms.Session in project spring-framework by spring-projects.
the class DynamicDestinationResolverTests method resolveWithPubSubVanillaSession.
@Test
public void resolveWithPubSubVanillaSession() throws Exception {
Topic expectedDestination = new StubTopic();
Session session = mock(Session.class);
given(session.createTopic(DESTINATION_NAME)).willReturn(expectedDestination);
testResolveDestination(session, expectedDestination, true);
}
use of jakarta.jms.Session 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);
}
use of jakarta.jms.Session in project spring-framework by spring-projects.
the class JmsMessagingTemplateTests method convertAndSendCustomJmsMessageConverter.
@Test
public void convertAndSendCustomJmsMessageConverter() throws JMSException {
this.messagingTemplate.setJmsMessageConverter(new SimpleMessageConverter() {
@Override
public jakarta.jms.Message toMessage(Object object, Session session) throws JMSException, org.springframework.jms.support.converter.MessageConversionException {
throw new org.springframework.jms.support.converter.MessageConversionException("Test exception");
}
});
this.messagingTemplate.convertAndSend("myQueue", "msg to convert");
verify(this.jmsTemplate).send(eq("myQueue"), this.messageCreator.capture());
assertThatExceptionOfType(org.springframework.messaging.converter.MessageConversionException.class).isThrownBy(() -> this.messageCreator.getValue().createMessage(mock(Session.class))).withMessageContaining("Test exception");
}
Aggregations