use of jakarta.jms.Connection in project spring-boot by spring-projects.
the class JmsHealthIndicatorTests method jmsBrokerCouldNotRetrieveProviderMetadata.
@Test
void jmsBrokerCouldNotRetrieveProviderMetadata() throws JMSException {
ConnectionMetaData connectionMetaData = mock(ConnectionMetaData.class);
given(connectionMetaData.getJMSProviderName()).willThrow(new JMSException("test", "123"));
Connection connection = mock(Connection.class);
given(connection.getMetaData()).willReturn(connectionMetaData);
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
given(connectionFactory.createConnection()).willReturn(connection);
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
Health health = indicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails().get("provider")).isNull();
then(connection).should().close();
}
use of jakarta.jms.Connection in project spring-boot by spring-projects.
the class JmsHealthIndicatorTests method jmsBrokerIsUp.
@Test
void jmsBrokerIsUp() throws JMSException {
ConnectionMetaData connectionMetaData = mock(ConnectionMetaData.class);
given(connectionMetaData.getJMSProviderName()).willReturn("JMS test provider");
Connection connection = mock(Connection.class);
given(connection.getMetaData()).willReturn(connectionMetaData);
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
given(connectionFactory.createConnection()).willReturn(connection);
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
Health health = indicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().get("provider")).isEqualTo("JMS test provider");
then(connection).should().close();
}
use of jakarta.jms.Connection in project spring-boot by spring-projects.
the class JmsHealthIndicator method doHealthCheck.
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
try (Connection connection = this.connectionFactory.createConnection()) {
new MonitoredConnection(connection).start();
builder.up().withDetail("provider", connection.getMetaData().getJMSProviderName());
}
}
use of jakarta.jms.Connection in project spring-framework by spring-projects.
the class JmsTransactionManagerTests method testTransactionRollback.
@Test
public void testTransactionRollback() throws JMSException {
ConnectionFactory cf = mock(ConnectionFactory.class);
Connection con = mock(Connection.class);
final Session session = mock(Session.class);
given(cf.createConnection()).willReturn(con);
given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session);
JmsTransactionManager tm = new JmsTransactionManager(cf);
TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition());
JmsTemplate jt = new JmsTemplate(cf);
jt.execute((SessionCallback<Void>) sess -> {
assertThat(session).isSameAs(sess);
return null;
});
tm.rollback(ts);
verify(session).rollback();
verify(session).close();
verify(con).close();
}
use of jakarta.jms.Connection in project spring-framework by spring-projects.
the class JmsTransactionManagerTests method testTransactionCommitWithMessageProducer.
@Test
public void testTransactionCommitWithMessageProducer() throws JMSException {
Destination dest = new StubQueue();
ConnectionFactory cf = mock(ConnectionFactory.class);
Connection con = mock(Connection.class);
Session session = mock(Session.class);
MessageProducer producer = mock(MessageProducer.class);
final Message message = mock(Message.class);
given(cf.createConnection()).willReturn(con);
given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session);
given(session.createProducer(dest)).willReturn(producer);
given(session.getTransacted()).willReturn(true);
JmsTransactionManager tm = new JmsTransactionManager(cf);
TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition());
JmsTemplate jt = new JmsTemplate(cf);
jt.send(dest, sess -> message);
tm.commit(ts);
verify(producer).send(message);
verify(session).commit();
verify(producer).close();
verify(session).close();
verify(con).close();
}
Aggregations