1111// The Original Code is RabbitMQ.
1212//
1313// The Initial Developer of the Original Code is Pivotal Software, Inc.
14- // Copyright (c) 2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
14+ // Copyright (c) 2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc.
15+ // and/or its subsidiaries. All rights reserved.
1516//
1617
1718package com .rabbitmq .amqp .tests .jms ;
3132import org .apache .qpid .jms .JmsConnectionFactory ;
3233import org .junit .jupiter .api .Disabled ;
3334import org .junit .jupiter .api .Test ;
34- import org .junit .jupiter .api .TestInfo ;
3535import org .junit .jupiter .api .Timeout ;
3636
3737/**
38- * Based on https://github.com/apache/qpid-jms/tree/main/qpid-jms-interop-tests/qpid-jms-activemq-tests.
38+ * Based on
39+ * https://github.com/apache/qpid-jms/tree/main/qpid-jms-interop-tests/qpid-jms-activemq-tests.
3940 */
41+ @ JmsTestInfrastructure
4042public class JmsConnectionTest {
4143
44+ String destination ;
45+
4246 @ Test
4347 @ Timeout (30 )
4448 public void testCreateConnection () throws Exception {
45- JmsConnectionFactory factory = new JmsConnectionFactory (brokerUri ());
46- try (Connection connection = factory .createConnection ()) {
49+ try (Connection connection = connection ()) {
4750 assertNotNull (connection );
4851 }
4952 }
5053
5154 @ Test
5255 @ Timeout (30 )
5356 public void testCreateConnectionAndStart () throws Exception {
54- JmsConnectionFactory factory = new JmsConnectionFactory (brokerUri ());
55- try (Connection connection = factory .createConnection ()) {
57+ try (Connection connection = connection ()) {
5658 assertNotNull (connection );
5759 connection .start ();
5860 }
@@ -63,7 +65,7 @@ public void testCreateConnectionAndStart() throws Exception {
6365 // Currently not supported by RabbitMQ.
6466 @ Disabled
6567 public void testCreateWithDuplicateClientIdFails () throws Exception {
66- JmsConnectionFactory factory = new JmsConnectionFactory ( brokerUri () );
68+ JmsConnectionFactory factory = ( JmsConnectionFactory ) connectionFactory ( );
6769 JmsConnection connection1 = (JmsConnection ) factory .createConnection ();
6870 connection1 .setClientID ("Test" );
6971 assertNotNull (connection1 );
@@ -87,8 +89,7 @@ public void testSetClientIdAfterStartedFails() {
8789 assertThrows (
8890 JMSException .class ,
8991 () -> {
90- JmsConnectionFactory factory = new JmsConnectionFactory (brokerUri ());
91- try (Connection connection = factory .createConnection ()) {
92+ try (Connection connection = connection ()) {
9293 connection .setClientID ("Test" );
9394 connection .start ();
9495 connection .setClientID ("NewTest" );
@@ -99,7 +100,7 @@ public void testSetClientIdAfterStartedFails() {
99100 @ Test
100101 @ Timeout (30 )
101102 public void testCreateConnectionAsSystemAdmin () throws Exception {
102- JmsConnectionFactory factory = new JmsConnectionFactory ( brokerUri () );
103+ JmsConnectionFactory factory = ( JmsConnectionFactory ) connectionFactory ( );
103104 factory .setUsername (adminUsername ());
104105 factory .setPassword (adminPassword ());
105106 try (Connection connection = factory .createConnection ()) {
@@ -111,8 +112,8 @@ public void testCreateConnectionAsSystemAdmin() throws Exception {
111112 @ Test
112113 @ Timeout (30 )
113114 public void testCreateConnectionCallSystemAdmin () throws Exception {
114- JmsConnectionFactory factory = new JmsConnectionFactory ( brokerUri ());
115- try ( Connection connection = factory .createConnection (adminUsername (), adminPassword ())) {
115+ try ( Connection connection =
116+ connectionFactory () .createConnection (adminUsername (), adminPassword ())) {
116117 assertNotNull (connection );
117118 connection .start ();
118119 }
@@ -124,7 +125,7 @@ public void testCreateConnectionAsUnknwonUser() {
124125 assertThrows (
125126 JMSSecurityException .class ,
126127 () -> {
127- JmsConnectionFactory factory = new JmsConnectionFactory ( TestUtils . brokerUri () );
128+ JmsConnectionFactory factory = ( JmsConnectionFactory ) connectionFactory ( );
128129 factory .setUsername ("unknown" );
129130 factory .setPassword ("unknown" );
130131 try (Connection connection = factory .createConnection ()) {
@@ -140,8 +141,7 @@ public void testCreateConnectionCallUnknwonUser() {
140141 assertThrows (
141142 JMSSecurityException .class ,
142143 () -> {
143- JmsConnectionFactory factory = new JmsConnectionFactory (brokerUri ());
144- try (Connection connection = factory .createConnection ("unknown" , "unknown" )) {
144+ try (Connection connection = connectionFactory ().createConnection ("unknown" , "unknown" )) {
145145 assertNotNull (connection );
146146 connection .start ();
147147 }
@@ -150,14 +150,11 @@ public void testCreateConnectionCallUnknwonUser() {
150150
151151 @ Test
152152 @ Timeout (30 )
153- public void testBrokerStopWontHangConnectionClose (TestInfo info ) throws Exception {
154- Connection connection = new JmsConnectionFactory ( brokerUri ()). createConnection ();
153+ public void testBrokerStopWontHangConnectionClose () throws Exception {
154+ Connection connection = connection ();
155155 Session session = connection .createSession (false , Session .AUTO_ACKNOWLEDGE );
156156
157- // TODO use a "regular" queue
158- TemporaryQueue queue = session .createTemporaryQueue ();
159- // String destinationName = name(info);
160- // Queue queue = session.createQueue("/queues/" + destinationName);
157+ Queue queue = queue (destination );
161158 connection .start ();
162159
163160 MessageProducer producer = session .createProducer (queue );
@@ -182,7 +179,7 @@ public void testBrokerStopWontHangConnectionClose(TestInfo info) throws Exceptio
182179 @ Timeout (60 )
183180 public void testConnectionExceptionBrokerStop () throws Exception {
184181 final CountDownLatch latch = new CountDownLatch (1 );
185- try (Connection connection = new JmsConnectionFactory ( brokerUri ()). createConnection ()) {
182+ try (Connection connection = connection ()) {
186183 connection .setExceptionListener (exception -> latch .countDown ());
187184 connection .start ();
188185 Session session = connection .createSession (false , Session .AUTO_ACKNOWLEDGE );
0 commit comments