1414// Copyright (c) 2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc.
1515// and/or its subsidiaries. All rights reserved.
1616//
17-
1817package com .rabbitmq .amqp .tests .jms ;
1918
2019import static com .rabbitmq .amqp .tests .jms .Cli .startBroker ;
4140@ JmsTestInfrastructure
4241public class JmsConnectionTest {
4342
44- String destination ;
43+ ConnectionFactory factory ;
4544
4645 @ Test
4746 @ Timeout (30 )
4847 public void testCreateConnection () throws Exception {
49- try (Connection connection = connection ()) {
48+ try (Connection connection = factory . createConnection ()) {
5049 assertNotNull (connection );
5150 }
5251 }
5352
5453 @ Test
5554 @ Timeout (30 )
5655 public void testCreateConnectionAndStart () throws Exception {
57- try (Connection connection = connection ()) {
56+ try (Connection connection = factory . createConnection ()) {
5857 assertNotNull (connection );
5958 connection .start ();
6059 }
@@ -65,7 +64,6 @@ public void testCreateConnectionAndStart() throws Exception {
6564 // Currently not supported by RabbitMQ.
6665 @ Disabled
6766 public void testCreateWithDuplicateClientIdFails () throws Exception {
68- JmsConnectionFactory factory = (JmsConnectionFactory ) connectionFactory ();
6967 JmsConnection connection1 = (JmsConnection ) factory .createConnection ();
7068 connection1 .setClientID ("Test" );
7169 assertNotNull (connection1 );
@@ -89,7 +87,7 @@ public void testSetClientIdAfterStartedFails() {
8987 assertThrows (
9088 JMSException .class ,
9189 () -> {
92- try (Connection connection = connection ()) {
90+ try (Connection connection = factory . createConnection ()) {
9391 connection .setClientID ("Test" );
9492 connection .start ();
9593 connection .setClientID ("NewTest" );
@@ -100,9 +98,10 @@ public void testSetClientIdAfterStartedFails() {
10098 @ Test
10199 @ Timeout (30 )
102100 public void testCreateConnectionAsSystemAdmin () throws Exception {
103- JmsConnectionFactory factory = (JmsConnectionFactory ) connectionFactory ();
104- factory .setUsername (adminUsername ());
105- factory .setPassword (adminPassword ());
101+ JmsConnectionFactory f = (JmsConnectionFactory ) factory ;
102+
103+ f .setUsername (adminUsername ());
104+ f .setPassword (adminPassword ());
106105 try (Connection connection = factory .createConnection ()) {
107106 assertNotNull (connection );
108107 connection .start ();
@@ -112,22 +111,21 @@ public void testCreateConnectionAsSystemAdmin() throws Exception {
112111 @ Test
113112 @ Timeout (30 )
114113 public void testCreateConnectionCallSystemAdmin () throws Exception {
115- try (Connection connection =
116- connectionFactory ().createConnection (adminUsername (), adminPassword ())) {
114+ try (Connection connection = factory .createConnection (adminUsername (), adminPassword ())) {
117115 assertNotNull (connection );
118116 connection .start ();
119117 }
120118 }
121119
122120 @ Test
123121 @ Timeout (30 )
124- public void testCreateConnectionAsUnknwonUser () {
122+ public void testCreateConnectionAsUnknownUser () {
125123 assertThrows (
126124 JMSSecurityException .class ,
127125 () -> {
128- JmsConnectionFactory factory = (JmsConnectionFactory ) connectionFactory () ;
129- factory .setUsername ("unknown" );
130- factory .setPassword ("unknown" );
126+ JmsConnectionFactory f = (JmsConnectionFactory ) factory ;
127+ f .setUsername ("unknown" );
128+ f .setPassword ("unknown" );
131129 try (Connection connection = factory .createConnection ()) {
132130 assertNotNull (connection );
133131 connection .start ();
@@ -137,11 +135,11 @@ public void testCreateConnectionAsUnknwonUser() {
137135
138136 @ Test
139137 @ Timeout (30 )
140- public void testCreateConnectionCallUnknwonUser () {
138+ public void testCreateConnectionCallUnknownUser () {
141139 assertThrows (
142140 JMSSecurityException .class ,
143141 () -> {
144- try (Connection connection = connectionFactory () .createConnection ("unknown" , "unknown" )) {
142+ try (Connection connection = factory .createConnection ("unknown" , "unknown" )) {
145143 assertNotNull (connection );
146144 connection .start ();
147145 }
@@ -150,11 +148,10 @@ public void testCreateConnectionCallUnknwonUser() {
150148
151149 @ Test
152150 @ Timeout (30 )
153- public void testBrokerStopWontHangConnectionClose () throws Exception {
154- Connection connection = connection ();
151+ public void testBrokerStopWontHangConnectionClose (Queue queue ) throws Exception {
152+ Connection connection = factory . createConnection ();
155153 Session session = connection .createSession (false , Session .AUTO_ACKNOWLEDGE );
156154
157- Queue queue = queue (destination );
158155 connection .start ();
159156
160157 MessageProducer producer = session .createProducer (queue );
@@ -179,7 +176,7 @@ public void testBrokerStopWontHangConnectionClose() throws Exception {
179176 @ Timeout (60 )
180177 public void testConnectionExceptionBrokerStop () throws Exception {
181178 final CountDownLatch latch = new CountDownLatch (1 );
182- try (Connection connection = connection ()) {
179+ try (Connection connection = factory . createConnection ()) {
183180 connection .setExceptionListener (exception -> latch .countDown ());
184181 connection .start ();
185182 Session session = connection .createSession (false , Session .AUTO_ACKNOWLEDGE );
0 commit comments