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 ;
2120import static com .rabbitmq .amqp .tests .jms .Cli .stopBroker ;
2221import static com .rabbitmq .amqp .tests .jms .TestUtils .*;
23- import static org .junit .jupiter .api .Assertions .assertNotNull ;
24- import static org .junit .jupiter .api .Assertions .assertThrows ;
25- import static org .junit .jupiter .api .Assertions .assertTrue ;
26- import static org .junit .jupiter .api .Assertions .fail ;
22+ import static org .assertj .core .api .Assertions .*;
2723
2824import jakarta .jms .*;
2925import java .util .concurrent .CountDownLatch ;
4137@ JmsTestInfrastructure
4238public class JmsConnectionTest {
4339
44- String destination ;
40+ ConnectionFactory factory ;
4541
4642 @ Test
4743 @ Timeout (30 )
4844 public void testCreateConnection () throws Exception {
49- try (Connection connection = connection ()) {
50- assertNotNull (connection );
45+ try (Connection connection = factory . createConnection ()) {
46+ assertThat (connection ). isNotNull ( );
5147 }
5248 }
5349
5450 @ Test
5551 @ Timeout (30 )
5652 public void testCreateConnectionAndStart () throws Exception {
57- try (Connection connection = connection ()) {
58- assertNotNull (connection );
53+ try (Connection connection = factory . createConnection ()) {
54+ assertThat (connection ). isNotNull ( );
5955 connection .start ();
6056 }
6157 }
6258
6359 @ Test
6460 @ Timeout (30 )
65- // Currently not supported by RabbitMQ.
66- @ Disabled
61+ @ Disabled ("Client ID conflict detection is not supported by RabbitMQ" )
6762 public void testCreateWithDuplicateClientIdFails () throws Exception {
68- JmsConnectionFactory factory = (JmsConnectionFactory ) connectionFactory ();
6963 JmsConnection connection1 = (JmsConnection ) factory .createConnection ();
7064 connection1 .setClientID ("Test" );
71- assertNotNull (connection1 );
65+ assertThat (connection1 ). isNotNull ( );
7266 connection1 .start ();
7367 JmsConnection connection2 = (JmsConnection ) factory .createConnection ();
7468 try {
@@ -86,75 +80,74 @@ public void testCreateWithDuplicateClientIdFails() throws Exception {
8680
8781 @ Test
8882 public void testSetClientIdAfterStartedFails () {
89- assertThrows (
90- JMSException . class ,
91- () -> {
92- try ( Connection connection = connection ()) {
93- connection .setClientID ( "Test" );
94- connection .start ( );
95- connection . setClientID ( "NewTest" );
96- }
97- } );
83+ assertThatThrownBy (
84+ () -> {
85+ try ( Connection connection = factory . createConnection ()) {
86+ connection . setClientID ( "Test" );
87+ connection .start ( );
88+ connection .setClientID ( "NewTest" );
89+ }
90+ })
91+ . isInstanceOf ( JMSException . class );
9892 }
9993
10094 @ Test
10195 @ Timeout (30 )
10296 public void testCreateConnectionAsSystemAdmin () throws Exception {
103- JmsConnectionFactory factory = (JmsConnectionFactory ) connectionFactory ();
104- factory .setUsername (adminUsername ());
105- factory .setPassword (adminPassword ());
97+ JmsConnectionFactory f = (JmsConnectionFactory ) factory ;
98+
99+ f .setUsername (adminUsername ());
100+ f .setPassword (adminPassword ());
106101 try (Connection connection = factory .createConnection ()) {
107- assertNotNull (connection );
102+ assertThat (connection ). isNotNull ( );
108103 connection .start ();
109104 }
110105 }
111106
112107 @ Test
113108 @ Timeout (30 )
114109 public void testCreateConnectionCallSystemAdmin () throws Exception {
115- try (Connection connection =
116- connectionFactory ().createConnection (adminUsername (), adminPassword ())) {
117- assertNotNull (connection );
110+ try (Connection connection = factory .createConnection (adminUsername (), adminPassword ())) {
111+ assertThat (connection ).isNotNull ();
118112 connection .start ();
119113 }
120114 }
121115
122116 @ Test
123117 @ Timeout (30 )
124- public void testCreateConnectionAsUnknwonUser () {
125- assertThrows (
126- JMSSecurityException . class ,
127- () -> {
128- JmsConnectionFactory factory = ( JmsConnectionFactory ) connectionFactory ( );
129- factory . setUsername ("unknown" );
130- factory .setPassword ( "unknown" );
131- try ( Connection connection = factory . createConnection ()) {
132- assertNotNull ( connection );
133- connection . start ();
134- }
135- } );
118+ public void testCreateConnectionAsUnknownUser () {
119+ assertThatThrownBy (
120+ () -> {
121+ JmsConnectionFactory f = ( JmsConnectionFactory ) factory ;
122+ f . setUsername ( "unknown" );
123+ f . setPassword ("unknown" );
124+ try ( Connection connection = factory .createConnection ()) {
125+ assertThat ( connection ). isNotNull ();
126+ connection . start ( );
127+ }
128+ })
129+ . isInstanceOf ( JMSSecurityException . class );
136130 }
137131
138132 @ Test
139133 @ Timeout (30 )
140- public void testCreateConnectionCallUnknwonUser () {
141- assertThrows (
142- JMSSecurityException . class ,
143- () -> {
144- try ( Connection connection = connectionFactory (). createConnection ( "unknown" , "unknown" )) {
145- assertNotNull ( connection );
146- connection . start ();
147- }
148- } );
134+ public void testCreateConnectionCallUnknownUser () {
135+ assertThatThrownBy (
136+ () -> {
137+ try ( Connection connection = factory . createConnection ( "unknown" , "unknown" )) {
138+ assertThat ( connection ). isNotNull ();
139+ connection . start ( );
140+ }
141+ })
142+ . isInstanceOf ( JMSSecurityException . class );
149143 }
150144
151145 @ Test
152146 @ Timeout (30 )
153- public void testBrokerStopWontHangConnectionClose () throws Exception {
154- Connection connection = connection ();
147+ public void testBrokerStopWontHangConnectionClose (Queue queue ) throws Exception {
148+ Connection connection = factory . createConnection ();
155149 Session session = connection .createSession (false , Session .AUTO_ACKNOWLEDGE );
156150
157- Queue queue = queue (destination );
158151 connection .start ();
159152
160153 MessageProducer producer = session .createProducer (queue );
@@ -179,15 +172,15 @@ public void testBrokerStopWontHangConnectionClose() throws Exception {
179172 @ Timeout (60 )
180173 public void testConnectionExceptionBrokerStop () throws Exception {
181174 final CountDownLatch latch = new CountDownLatch (1 );
182- try (Connection connection = connection ()) {
175+ try (Connection connection = factory . createConnection ()) {
183176 connection .setExceptionListener (exception -> latch .countDown ());
184177 connection .start ();
185178 Session session = connection .createSession (false , Session .AUTO_ACKNOWLEDGE );
186- assertNotNull (session );
179+ assertThat (session ). isNotNull ( );
187180
188181 try {
189182 stopBroker ();
190- assertTrue (latch .await (10 , TimeUnit .SECONDS ));
183+ assertThat (latch .await (10 , TimeUnit .SECONDS )). isTrue ( );
191184 } finally {
192185 startBroker ();
193186 }
0 commit comments