Skip to content

Commit bd88ab6

Browse files
authored
Merge pull request #13327 from rabbitmq/mergify/bp/v4.1.x/pr-13324
Use JUnit extension to configure JMS tests (backport #13324)
2 parents f83fdfa + 5e4942a commit bd88ab6

File tree

9 files changed

+371
-306
lines changed

9 files changed

+371
-306
lines changed

deps/rabbit/test/amqp_jms_SUITE.erl

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,32 +122,24 @@ jms_temporary_queue(Config) ->
122122

123123
%% Send different message types from JMS client to JMS client.
124124
message_types_jms_to_jms(Config) ->
125-
TestName = QName = atom_to_binary(?FUNCTION_NAME),
126-
ok = declare_queue(QName, <<"quorum">>, Config),
127-
ok = run_jms_test(TestName, [{"-Dqueue=~ts", [rabbitmq_amqp_address:queue(QName)]}], Config),
128-
ok = delete_queue(QName, Config).
125+
ok = run_jms_test(?FUNCTION_NAME, Config).
129126

130127
%% Send different message types from JMS client to Erlang AMQP 1.0 client.
131128
message_types_jms_to_amqp(Config) ->
132-
TestName = atom_to_binary(?FUNCTION_NAME),
133-
ok = run_jms_test(TestName, [], Config).
129+
ok = run_jms_test(?FUNCTION_NAME, Config).
134130

135131
temporary_queue_rpc(Config) ->
136-
TestName = QName = atom_to_binary(?FUNCTION_NAME),
137-
ok = declare_queue(QName, <<"classic">>, Config),
138-
ok = run_jms_test(TestName, [{"-Dqueue=~ts", [rabbitmq_amqp_address:queue(QName)]}], Config),
139-
ok = delete_queue(QName, Config).
132+
ok = run_jms_test(?FUNCTION_NAME, Config).
140133

141134
temporary_queue_delete(Config) ->
142-
TestName = atom_to_binary(?FUNCTION_NAME),
143-
ok = run_jms_test(TestName, [], Config).
135+
ok = run_jms_test(?FUNCTION_NAME, Config).
144136

145137
%% -------------------------------------------------------------------
146138
%% Helpers
147139
%% -------------------------------------------------------------------
148140

149-
run_jms_test(TestName, JavaProps, Config) ->
150-
run(TestName, [{"-Dtest=JmsTest#~ts", [TestName]} | JavaProps], Config).
141+
run_jms_test(TestName, Config) ->
142+
run(TestName, [{"-Dtest=JmsTest#~ts", [TestName]}], Config).
151143

152144
run(TestName, JavaProps, Config) ->
153145
TestProjectDir = ?config(data_dir, Config),

deps/rabbit/test/amqp_jms_SUITE_data/pom.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@
5050
<version>${assertj.version}</version>
5151
<scope>test</scope>
5252
</dependency>
53+
<!-- add explicitly to update automatically with dependabot -->
54+
<dependency>
55+
<groupId>com.google.googlejavaformat</groupId>
56+
<artifactId>google-java-format</artifactId>
57+
<version>${google-java-format.version}</version>
58+
<scope>test</scope>
59+
</dependency>
5360

5461
</dependencies>
5562
<build>
@@ -89,6 +96,26 @@
8996
<style>GOOGLE</style>
9097
</googleJavaFormat>
9198
</java>
99+
<ratchetFrom>origin/main</ratchetFrom>
100+
<licenseHeader>
101+
<content>// The contents of this file are subject to the Mozilla Public License
102+
// Version 2.0 (the "License"); you may not use this file except in
103+
// compliance with the License. You may obtain a copy of the License
104+
// at https://www.mozilla.org/en-US/MPL/2.0/
105+
//
106+
// Software distributed under the License is distributed on an "AS IS"
107+
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
108+
// the License for the specific language governing rights and
109+
// limitations under the License.
110+
//
111+
// The Original Code is RabbitMQ.
112+
//
113+
// The Initial Developer of the Original Code is Pivotal Software, Inc.
114+
// Copyright (c) $YEAR Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc.
115+
// and/or its subsidiaries. All rights reserved.
116+
//
117+
</content>
118+
</licenseHeader>
92119
</configuration>
93120
</plugin>
94121

deps/rabbit/test/amqp_jms_SUITE_data/src/test/java/com/rabbitmq/amqp/tests/jms/Cli.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
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
package com.rabbitmq.amqp.tests.jms;
1718

deps/rabbit/test/amqp_jms_SUITE_data/src/test/java/com/rabbitmq/amqp/tests/jms/JmsConnectionTest.java

Lines changed: 50 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,12 @@
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-
1817
package com.rabbitmq.amqp.tests.jms;
1918

2019
import static com.rabbitmq.amqp.tests.jms.Cli.startBroker;
2120
import static com.rabbitmq.amqp.tests.jms.Cli.stopBroker;
2221
import 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

2824
import jakarta.jms.*;
2925
import java.util.concurrent.CountDownLatch;
@@ -41,34 +37,32 @@
4137
@JmsTestInfrastructure
4238
public 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
}

deps/rabbit/test/amqp_jms_SUITE_data/src/test/java/com/rabbitmq/amqp/tests/jms/JmsTemporaryQueueTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@
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-
1817
package com.rabbitmq.amqp.tests.jms;
1918

2019
import static com.rabbitmq.amqp.tests.jms.TestUtils.brokerUri;
21-
import static com.rabbitmq.amqp.tests.jms.TestUtils.connection;
22-
import static org.junit.jupiter.api.Assertions.*;
23-
import static org.junit.jupiter.api.Assertions.fail;
20+
import static org.assertj.core.api.Assertions.*;
2421

2522
import jakarta.jms.*;
2623
import jakarta.jms.IllegalStateException;
@@ -35,13 +32,16 @@
3532
* Based on
3633
* https://github.com/apache/qpid-jms/tree/main/qpid-jms-interop-tests/qpid-jms-activemq-tests.
3734
*/
35+
@JmsTestInfrastructure
3836
public class JmsTemporaryQueueTest {
3937

38+
ConnectionFactory factory;
39+
4040
Connection connection;
4141

4242
@BeforeEach
4343
void init() throws JMSException {
44-
connection = connection();
44+
connection = factory.createConnection();
4545
}
4646

4747
@AfterEach
@@ -55,14 +55,14 @@ public void testCreatePublishConsumeTemporaryQueue() throws Exception {
5555
connection.start();
5656

5757
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
58-
assertNotNull(session);
58+
assertThat(session).isNotNull();
5959
TemporaryQueue queue = session.createTemporaryQueue();
6060
MessageConsumer consumer = session.createConsumer(queue);
6161

6262
MessageProducer producer = session.createProducer(queue);
6363
String body = UUID.randomUUID().toString();
6464
producer.send(session.createTextMessage(body));
65-
assertEquals(body, consumer.receive(60_000).getBody(String.class));
65+
assertThat(consumer.receive(60_000).getBody(String.class)).isEqualTo(body);
6666
}
6767

6868
@Test

0 commit comments

Comments
 (0)