Search in sources :

Example 36 with ConnectionFactory

use of jakarta.jms.ConnectionFactory in project spring-boot by spring-projects.

the class ArtemisAutoConfigurationTests method nativeConnectionFactoryCredentials.

@Test
void nativeConnectionFactoryCredentials() {
    this.contextRunner.withUserConfiguration(EmptyConfiguration.class).withPropertyValues("spring.artemis.mode:native", "spring.artemis.user:user", "spring.artemis.password:secret").run((context) -> {
        JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
        ConnectionFactory connectionFactory = getConnectionFactory(context);
        assertThat(connectionFactory).isEqualTo(jmsTemplate.getConnectionFactory());
        ActiveMQConnectionFactory activeMQConnectionFactory = getActiveMQConnectionFactory(connectionFactory);
        assertNettyConnectionFactory(activeMQConnectionFactory, "localhost", 61616);
        assertThat(activeMQConnectionFactory.getUser()).isEqualTo("user");
        assertThat(activeMQConnectionFactory.getPassword()).isEqualTo("secret");
    });
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) CachingConnectionFactory(org.springframework.jms.connection.CachingConnectionFactory) ConnectionFactory(jakarta.jms.ConnectionFactory) JmsTemplate(org.springframework.jms.core.JmsTemplate) Test(org.junit.jupiter.api.Test)

Example 37 with ConnectionFactory

use of jakarta.jms.ConnectionFactory in project spring-boot by spring-projects.

the class ArtemisAutoConfigurationTests method connectionFactoryCachingCanBeDisabled.

@Test
void connectionFactoryCachingCanBeDisabled() {
    this.contextRunner.withUserConfiguration(EmptyConfiguration.class).withPropertyValues("spring.jms.cache.enabled=false").run((context) -> {
        assertThat(context).doesNotHaveBean(CachingConnectionFactory.class);
        ConnectionFactory connectionFactory = getConnectionFactory(context);
        assertThat(connectionFactory).isInstanceOf(ActiveMQConnectionFactory.class);
    });
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) CachingConnectionFactory(org.springframework.jms.connection.CachingConnectionFactory) ConnectionFactory(jakarta.jms.ConnectionFactory) Test(org.junit.jupiter.api.Test)

Example 38 with ConnectionFactory

use of jakarta.jms.ConnectionFactory in project spring-boot by spring-projects.

the class JndiConnectionFactoryAutoConfigurationTests method detectWithXAConnectionFactory.

@Test
void detectWithXAConnectionFactory() {
    ConnectionFactory connectionFactory = configureConnectionFactory("java:/XAConnectionFactory");
    this.contextRunner.run(assertConnectionFactory(connectionFactory));
}
Also used : ConnectionFactory(jakarta.jms.ConnectionFactory) Test(org.junit.jupiter.api.Test)

Example 39 with ConnectionFactory

use of jakarta.jms.ConnectionFactory in project spring-boot by spring-projects.

the class JndiConnectionFactoryAutoConfigurationTests method jndiNamePropertySet.

@Test
void jndiNamePropertySet() {
    ConnectionFactory connectionFactory = configureConnectionFactory("java:comp/env/myCF");
    this.contextRunner.withPropertyValues("spring.jms.jndi-name=java:comp/env/myCF").run(assertConnectionFactory(connectionFactory));
}
Also used : ConnectionFactory(jakarta.jms.ConnectionFactory) Test(org.junit.jupiter.api.Test)

Example 40 with ConnectionFactory

use of jakarta.jms.ConnectionFactory 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();
}
Also used : MessageProducer(jakarta.jms.MessageProducer) TransactionDefinition(org.springframework.transaction.TransactionDefinition) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JMSException(jakarta.jms.JMSException) Session(jakarta.jms.Session) TransactionSynchronizationManager(org.springframework.transaction.support.TransactionSynchronizationManager) BDDMockito.given(org.mockito.BDDMockito.given) Destination(jakarta.jms.Destination) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) JmsTemplate(org.springframework.jms.core.JmsTemplate) ConnectionFactory(jakarta.jms.ConnectionFactory) Connection(jakarta.jms.Connection) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) Message(jakarta.jms.Message) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) StubQueue(org.springframework.jms.StubQueue) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) Mockito.times(org.mockito.Mockito.times) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) SessionCallback(org.springframework.jms.core.SessionCallback) Mockito.mock(org.mockito.Mockito.mock) ConnectionFactory(jakarta.jms.ConnectionFactory) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) Connection(jakarta.jms.Connection) TransactionStatus(org.springframework.transaction.TransactionStatus) JmsTemplate(org.springframework.jms.core.JmsTemplate) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Aggregations

ConnectionFactory (jakarta.jms.ConnectionFactory)60 Test (org.junit.jupiter.api.Test)42 Connection (jakarta.jms.Connection)32 JMSException (jakarta.jms.JMSException)20 Session (jakarta.jms.Session)19 Message (jakarta.jms.Message)15 QueueConnectionFactory (jakarta.jms.QueueConnectionFactory)15 TopicConnectionFactory (jakarta.jms.TopicConnectionFactory)15 JmsTemplate (org.springframework.jms.core.JmsTemplate)11 QueueConnection (jakarta.jms.QueueConnection)10 TopicConnection (jakarta.jms.TopicConnection)10 StubQueue (org.springframework.jms.StubQueue)10 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)9 BDDMockito.given (org.mockito.BDDMockito.given)9 Mockito.mock (org.mockito.Mockito.mock)9 Mockito.verify (org.mockito.Mockito.verify)9 TransactionStatus (org.springframework.transaction.TransactionStatus)9 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)9 Destination (jakarta.jms.Destination)8 MessageProducer (jakarta.jms.MessageProducer)8