Add helpers for JMS tests
This commit is contained in:
parent
9062476a18
commit
fd350386a9
|
@ -10,6 +10,7 @@
|
||||||
<properties>
|
<properties>
|
||||||
<junit.jupiter.version>5.10.2</junit.jupiter.version>
|
<junit.jupiter.version>5.10.2</junit.jupiter.version>
|
||||||
<qpid-jms-client.version>2.6.1</qpid-jms-client.version>
|
<qpid-jms-client.version>2.6.1</qpid-jms-client.version>
|
||||||
|
<amqp-client.version>[0.5.0-SNAPSHOT,)</amqp-client.version>
|
||||||
<logback.version>1.2.13</logback.version>
|
<logback.version>1.2.13</logback.version>
|
||||||
<spotless.version>2.43.0</spotless.version>
|
<spotless.version>2.43.0</spotless.version>
|
||||||
<google-java-format.version>1.25.2</google-java-format.version>
|
<google-java-format.version>1.25.2</google-java-format.version>
|
||||||
|
@ -30,13 +31,18 @@
|
||||||
<version>${qpid-jms-client.version}</version>
|
<version>${qpid-jms-client.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ch.qos.logback</groupId>
|
<groupId>ch.qos.logback</groupId>
|
||||||
<artifactId>logback-classic</artifactId>
|
<artifactId>logback-classic</artifactId>
|
||||||
<version>${logback.version}</version>
|
<version>${logback.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.rabbitmq.client</groupId>
|
||||||
|
<artifactId>amqp-client</artifactId>
|
||||||
|
<version>${amqp-client.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
|
@ -81,4 +87,16 @@
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>ossrh</id>
|
||||||
|
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||||
|
<snapshots><enabled>true</enabled></snapshots>
|
||||||
|
<releases><enabled>false</enabled></releases>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
</repositories>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
// The Original Code is RabbitMQ.
|
// The Original Code is RabbitMQ.
|
||||||
//
|
//
|
||||||
// The Initial Developer of the Original Code is Pivotal Software, Inc.
|
// The Initial Developer of the Original Code is Pivotal Software, Inc.
|
||||||
// Copyright (c) 2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
|
// Copyright (c) 2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc.
|
||||||
|
// and/or its subsidiaries. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
package com.rabbitmq.amqp.tests.jms;
|
package com.rabbitmq.amqp.tests.jms;
|
||||||
|
@ -31,19 +32,21 @@ import org.apache.qpid.jms.JmsConnection;
|
||||||
import org.apache.qpid.jms.JmsConnectionFactory;
|
import org.apache.qpid.jms.JmsConnectionFactory;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.TestInfo;
|
|
||||||
import org.junit.jupiter.api.Timeout;
|
import org.junit.jupiter.api.Timeout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Based on https://github.com/apache/qpid-jms/tree/main/qpid-jms-interop-tests/qpid-jms-activemq-tests.
|
* Based on
|
||||||
|
* https://github.com/apache/qpid-jms/tree/main/qpid-jms-interop-tests/qpid-jms-activemq-tests.
|
||||||
*/
|
*/
|
||||||
|
@JmsTestInfrastructure
|
||||||
public class JmsConnectionTest {
|
public class JmsConnectionTest {
|
||||||
|
|
||||||
|
String destination;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Timeout(30)
|
@Timeout(30)
|
||||||
public void testCreateConnection() throws Exception {
|
public void testCreateConnection() throws Exception {
|
||||||
JmsConnectionFactory factory = new JmsConnectionFactory(brokerUri());
|
try (Connection connection = connection()) {
|
||||||
try (Connection connection = factory.createConnection()) {
|
|
||||||
assertNotNull(connection);
|
assertNotNull(connection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,8 +54,7 @@ public class JmsConnectionTest {
|
||||||
@Test
|
@Test
|
||||||
@Timeout(30)
|
@Timeout(30)
|
||||||
public void testCreateConnectionAndStart() throws Exception {
|
public void testCreateConnectionAndStart() throws Exception {
|
||||||
JmsConnectionFactory factory = new JmsConnectionFactory(brokerUri());
|
try (Connection connection = connection()) {
|
||||||
try (Connection connection = factory.createConnection()) {
|
|
||||||
assertNotNull(connection);
|
assertNotNull(connection);
|
||||||
connection.start();
|
connection.start();
|
||||||
}
|
}
|
||||||
|
@ -63,7 +65,7 @@ public class JmsConnectionTest {
|
||||||
// Currently not supported by RabbitMQ.
|
// Currently not supported by RabbitMQ.
|
||||||
@Disabled
|
@Disabled
|
||||||
public void testCreateWithDuplicateClientIdFails() throws Exception {
|
public void testCreateWithDuplicateClientIdFails() throws Exception {
|
||||||
JmsConnectionFactory factory = new JmsConnectionFactory(brokerUri());
|
JmsConnectionFactory factory = (JmsConnectionFactory) connectionFactory();
|
||||||
JmsConnection connection1 = (JmsConnection) factory.createConnection();
|
JmsConnection connection1 = (JmsConnection) factory.createConnection();
|
||||||
connection1.setClientID("Test");
|
connection1.setClientID("Test");
|
||||||
assertNotNull(connection1);
|
assertNotNull(connection1);
|
||||||
|
@ -87,8 +89,7 @@ public class JmsConnectionTest {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
JMSException.class,
|
JMSException.class,
|
||||||
() -> {
|
() -> {
|
||||||
JmsConnectionFactory factory = new JmsConnectionFactory(brokerUri());
|
try (Connection connection = connection()) {
|
||||||
try (Connection connection = factory.createConnection()) {
|
|
||||||
connection.setClientID("Test");
|
connection.setClientID("Test");
|
||||||
connection.start();
|
connection.start();
|
||||||
connection.setClientID("NewTest");
|
connection.setClientID("NewTest");
|
||||||
|
@ -99,7 +100,7 @@ public class JmsConnectionTest {
|
||||||
@Test
|
@Test
|
||||||
@Timeout(30)
|
@Timeout(30)
|
||||||
public void testCreateConnectionAsSystemAdmin() throws Exception {
|
public void testCreateConnectionAsSystemAdmin() throws Exception {
|
||||||
JmsConnectionFactory factory = new JmsConnectionFactory(brokerUri());
|
JmsConnectionFactory factory = (JmsConnectionFactory) connectionFactory();
|
||||||
factory.setUsername(adminUsername());
|
factory.setUsername(adminUsername());
|
||||||
factory.setPassword(adminPassword());
|
factory.setPassword(adminPassword());
|
||||||
try (Connection connection = factory.createConnection()) {
|
try (Connection connection = factory.createConnection()) {
|
||||||
|
@ -111,8 +112,8 @@ public class JmsConnectionTest {
|
||||||
@Test
|
@Test
|
||||||
@Timeout(30)
|
@Timeout(30)
|
||||||
public void testCreateConnectionCallSystemAdmin() throws Exception {
|
public void testCreateConnectionCallSystemAdmin() throws Exception {
|
||||||
JmsConnectionFactory factory = new JmsConnectionFactory(brokerUri());
|
try (Connection connection =
|
||||||
try (Connection connection = factory.createConnection(adminUsername(), adminPassword())) {
|
connectionFactory().createConnection(adminUsername(), adminPassword())) {
|
||||||
assertNotNull(connection);
|
assertNotNull(connection);
|
||||||
connection.start();
|
connection.start();
|
||||||
}
|
}
|
||||||
|
@ -124,7 +125,7 @@ public class JmsConnectionTest {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
JMSSecurityException.class,
|
JMSSecurityException.class,
|
||||||
() -> {
|
() -> {
|
||||||
JmsConnectionFactory factory = new JmsConnectionFactory(TestUtils.brokerUri());
|
JmsConnectionFactory factory = (JmsConnectionFactory) connectionFactory();
|
||||||
factory.setUsername("unknown");
|
factory.setUsername("unknown");
|
||||||
factory.setPassword("unknown");
|
factory.setPassword("unknown");
|
||||||
try (Connection connection = factory.createConnection()) {
|
try (Connection connection = factory.createConnection()) {
|
||||||
|
@ -140,8 +141,7 @@ public class JmsConnectionTest {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
JMSSecurityException.class,
|
JMSSecurityException.class,
|
||||||
() -> {
|
() -> {
|
||||||
JmsConnectionFactory factory = new JmsConnectionFactory(brokerUri());
|
try (Connection connection = connectionFactory().createConnection("unknown", "unknown")) {
|
||||||
try (Connection connection = factory.createConnection("unknown", "unknown")) {
|
|
||||||
assertNotNull(connection);
|
assertNotNull(connection);
|
||||||
connection.start();
|
connection.start();
|
||||||
}
|
}
|
||||||
|
@ -150,14 +150,11 @@ public class JmsConnectionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Timeout(30)
|
@Timeout(30)
|
||||||
public void testBrokerStopWontHangConnectionClose(TestInfo info) throws Exception {
|
public void testBrokerStopWontHangConnectionClose() throws Exception {
|
||||||
Connection connection = new JmsConnectionFactory(brokerUri()).createConnection();
|
Connection connection = connection();
|
||||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
|
|
||||||
// TODO use a "regular" queue
|
Queue queue = queue(destination);
|
||||||
TemporaryQueue queue = session.createTemporaryQueue();
|
|
||||||
// String destinationName = name(info);
|
|
||||||
// Queue queue = session.createQueue("/queues/" + destinationName);
|
|
||||||
connection.start();
|
connection.start();
|
||||||
|
|
||||||
MessageProducer producer = session.createProducer(queue);
|
MessageProducer producer = session.createProducer(queue);
|
||||||
|
@ -182,7 +179,7 @@ public class JmsConnectionTest {
|
||||||
@Timeout(60)
|
@Timeout(60)
|
||||||
public void testConnectionExceptionBrokerStop() throws Exception {
|
public void testConnectionExceptionBrokerStop() throws Exception {
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
try (Connection connection = new JmsConnectionFactory(brokerUri()).createConnection()) {
|
try (Connection connection = connection()) {
|
||||||
connection.setExceptionListener(exception -> latch.countDown());
|
connection.setExceptionListener(exception -> latch.countDown());
|
||||||
connection.start();
|
connection.start();
|
||||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
|
|
|
@ -11,12 +11,14 @@
|
||||||
// The Original Code is RabbitMQ.
|
// The Original Code is RabbitMQ.
|
||||||
//
|
//
|
||||||
// The Initial Developer of the Original Code is Pivotal Software, Inc.
|
// The Initial Developer of the Original Code is Pivotal Software, Inc.
|
||||||
// Copyright (c) 2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
|
// Copyright (c) 2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc.
|
||||||
|
// and/or its subsidiaries. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
package com.rabbitmq.amqp.tests.jms;
|
package com.rabbitmq.amqp.tests.jms;
|
||||||
|
|
||||||
import static com.rabbitmq.amqp.tests.jms.TestUtils.brokerUri;
|
import static com.rabbitmq.amqp.tests.jms.TestUtils.brokerUri;
|
||||||
|
import static com.rabbitmq.amqp.tests.jms.TestUtils.connection;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
|
@ -25,16 +27,23 @@ import jakarta.jms.IllegalStateException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import org.apache.qpid.jms.JmsConnectionFactory;
|
import org.apache.qpid.jms.JmsConnectionFactory;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.Timeout;
|
import org.junit.jupiter.api.Timeout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Based on https://github.com/apache/qpid-jms/tree/main/qpid-jms-interop-tests/qpid-jms-activemq-tests.
|
* Based on
|
||||||
|
* https://github.com/apache/qpid-jms/tree/main/qpid-jms-interop-tests/qpid-jms-activemq-tests.
|
||||||
*/
|
*/
|
||||||
public class JmsTemporaryQueueTest {
|
public class JmsTemporaryQueueTest {
|
||||||
|
|
||||||
Connection connection;
|
Connection connection;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void init() throws JMSException {
|
||||||
|
connection = connection();
|
||||||
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
void tearDown() throws JMSException {
|
void tearDown() throws JMSException {
|
||||||
connection.close();
|
connection.close();
|
||||||
|
@ -43,7 +52,6 @@ public class JmsTemporaryQueueTest {
|
||||||
@Test
|
@Test
|
||||||
@Timeout(60)
|
@Timeout(60)
|
||||||
public void testCreatePublishConsumeTemporaryQueue() throws Exception {
|
public void testCreatePublishConsumeTemporaryQueue() throws Exception {
|
||||||
connection = new JmsConnectionFactory(brokerUri()).createConnection();
|
|
||||||
connection.start();
|
connection.start();
|
||||||
|
|
||||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
|
@ -60,7 +68,6 @@ public class JmsTemporaryQueueTest {
|
||||||
@Test
|
@Test
|
||||||
@Timeout(60)
|
@Timeout(60)
|
||||||
public void testCantConsumeFromTemporaryQueueCreatedOnAnotherConnection() throws Exception {
|
public void testCantConsumeFromTemporaryQueueCreatedOnAnotherConnection() throws Exception {
|
||||||
connection = new JmsConnectionFactory(brokerUri()).createConnection();
|
|
||||||
connection.start();
|
connection.start();
|
||||||
|
|
||||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
|
@ -84,7 +91,6 @@ public class JmsTemporaryQueueTest {
|
||||||
@Test
|
@Test
|
||||||
@Timeout(60)
|
@Timeout(60)
|
||||||
public void testCantSendToTemporaryQueueFromClosedConnection() throws Exception {
|
public void testCantSendToTemporaryQueueFromClosedConnection() throws Exception {
|
||||||
connection = new JmsConnectionFactory(brokerUri()).createConnection();
|
|
||||||
connection.start();
|
connection.start();
|
||||||
|
|
||||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
|
@ -113,7 +119,6 @@ public class JmsTemporaryQueueTest {
|
||||||
@Test
|
@Test
|
||||||
@Timeout(60)
|
@Timeout(60)
|
||||||
public void testCantDeleteTemporaryQueueWithConsumers() throws Exception {
|
public void testCantDeleteTemporaryQueueWithConsumers() throws Exception {
|
||||||
connection = new JmsConnectionFactory(brokerUri()).createConnection();
|
|
||||||
connection.start();
|
connection.start();
|
||||||
|
|
||||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
// The contents of this file are subject to the Mozilla Public License
|
||||||
|
// Version 2.0 (the "License"); you may not use this file except in
|
||||||
|
// compliance with the License. You may obtain a copy of the License
|
||||||
|
// at https://www.mozilla.org/en-US/MPL/2.0/
|
||||||
|
//
|
||||||
|
// Software distributed under the License is distributed on an "AS IS"
|
||||||
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||||
|
// the License for the specific language governing rights and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
// The Original Code is RabbitMQ.
|
||||||
|
//
|
||||||
|
// The Initial Developer of the Original Code is Pivotal Software, Inc.
|
||||||
|
// Copyright (c) 2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc.
|
||||||
|
// and/or its subsidiaries. All rights reserved.
|
||||||
|
//
|
||||||
|
package com.rabbitmq.amqp.tests.jms;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
@ExtendWith(JmsTestInfrastructureExtension.class)
|
||||||
|
public @interface JmsTestInfrastructure {}
|
|
@ -0,0 +1,83 @@
|
||||||
|
// The contents of this file are subject to the Mozilla Public License
|
||||||
|
// Version 2.0 (the "License"); you may not use this file except in
|
||||||
|
// compliance with the License. You may obtain a copy of the License
|
||||||
|
// at https://www.mozilla.org/en-US/MPL/2.0/
|
||||||
|
//
|
||||||
|
// Software distributed under the License is distributed on an "AS IS"
|
||||||
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||||
|
// the License for the specific language governing rights and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
// The Original Code is RabbitMQ.
|
||||||
|
//
|
||||||
|
// The Initial Developer of the Original Code is Pivotal Software, Inc.
|
||||||
|
// Copyright (c) 2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
|
||||||
|
//
|
||||||
|
package com.rabbitmq.amqp.tests.jms;
|
||||||
|
|
||||||
|
|
||||||
|
import com.rabbitmq.client.amqp.Connection;
|
||||||
|
import com.rabbitmq.client.amqp.Environment;
|
||||||
|
import com.rabbitmq.client.amqp.impl.AmqpEnvironmentBuilder;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import org.junit.jupiter.api.extension.*;
|
||||||
|
|
||||||
|
final class JmsTestInfrastructureExtension
|
||||||
|
implements BeforeAllCallback, AfterAllCallback, BeforeEachCallback, AfterEachCallback {
|
||||||
|
|
||||||
|
private static final ExtensionContext.Namespace NAMESPACE =
|
||||||
|
ExtensionContext.Namespace.create(JmsTestInfrastructureExtension.class);
|
||||||
|
|
||||||
|
private static ExtensionContext.Store store(ExtensionContext extensionContext) {
|
||||||
|
return extensionContext.getRoot().getStore(NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Field field(Class<?> cls, String name) {
|
||||||
|
Field field = null;
|
||||||
|
while (field == null && cls != null) {
|
||||||
|
try {
|
||||||
|
field = cls.getDeclaredField(name);
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
cls = cls.getSuperclass();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beforeAll(ExtensionContext context) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beforeEach(ExtensionContext context) throws Exception {
|
||||||
|
Field field = field(context.getTestInstance().get().getClass(), "destination");
|
||||||
|
if (field != null) {
|
||||||
|
field.setAccessible(true);
|
||||||
|
String destination = TestUtils.name(context);
|
||||||
|
field.set(context.getTestInstance().get(), destination);
|
||||||
|
try (Environment environment = new AmqpEnvironmentBuilder().build();
|
||||||
|
Connection connection = environment.connectionBuilder().uri(TestUtils.brokerUri()).build()) {
|
||||||
|
connection.management().queue(destination).declare();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterEach(ExtensionContext context) throws Exception {
|
||||||
|
Field field = field(context.getTestInstance().get().getClass(), "destination");
|
||||||
|
if (field != null) {
|
||||||
|
field.setAccessible(true);
|
||||||
|
String destination = (String) field.get(context.getTestInstance().get());
|
||||||
|
try (Environment environment = new AmqpEnvironmentBuilder().build();
|
||||||
|
Connection connection = environment.connectionBuilder().uri(TestUtils.brokerUri()).build()) {
|
||||||
|
connection.management().queueDelete(destination);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterAll(ExtensionContext context) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,29 +11,30 @@
|
||||||
// The Original Code is RabbitMQ.
|
// The Original Code is RabbitMQ.
|
||||||
//
|
//
|
||||||
// The Initial Developer of the Original Code is Pivotal Software, Inc.
|
// The Initial Developer of the Original Code is Pivotal Software, Inc.
|
||||||
// Copyright (c) 2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
|
// Copyright (c) 2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc.
|
||||||
|
// and/or its subsidiaries. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
package com.rabbitmq.amqp.tests.jms;
|
package com.rabbitmq.amqp.tests.jms;
|
||||||
|
|
||||||
import static java.lang.String.format;
|
import static java.lang.String.format;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import jakarta.jms.Connection;
|
||||||
import java.lang.annotation.Retention;
|
import jakarta.jms.ConnectionFactory;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import jakarta.jms.JMSException;
|
||||||
import java.lang.annotation.Target;
|
import jakarta.jms.Queue;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import org.apache.qpid.jms.JmsConnectionFactory;
|
||||||
import org.junit.jupiter.api.Tag;
|
import org.apache.qpid.jms.JmsQueue;
|
||||||
import org.junit.jupiter.api.TestInfo;
|
import org.junit.jupiter.api.TestInfo;
|
||||||
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
|
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||||
|
|
||||||
final class TestUtils {
|
final class TestUtils {
|
||||||
|
|
||||||
private static final String DEFAULT_BROKER_URI = "amqp://localhost:5672";
|
private static final String DEFAULT_BROKER_URI = "amqp://localhost:5672";
|
||||||
|
|
||||||
private TestUtils() { }
|
private TestUtils() {}
|
||||||
|
|
||||||
static String brokerUri() {
|
static String brokerUri() {
|
||||||
String uri = System.getProperty("rmq_broker_uri", "amqp://localhost:5672");
|
String uri = System.getProperty("rmq_broker_uri", "amqp://localhost:5672");
|
||||||
|
@ -48,10 +49,26 @@ final class TestUtils {
|
||||||
return "guest";
|
return "guest";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ConnectionFactory connectionFactory() {
|
||||||
|
return new JmsConnectionFactory(brokerUri());
|
||||||
|
}
|
||||||
|
|
||||||
|
static Connection connection() throws JMSException {
|
||||||
|
return connectionFactory().createConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
static Queue queue(String name) {
|
||||||
|
// no path encoding, use names with e.g. ASCII characters only
|
||||||
|
return new JmsQueue("/queues/" + name);
|
||||||
|
}
|
||||||
|
|
||||||
static String name(TestInfo info) {
|
static String name(TestInfo info) {
|
||||||
return name(info.getTestClass().get(), info.getTestMethod().get());
|
return name(info.getTestClass().get(), info.getTestMethod().get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String name(ExtensionContext context) {
|
||||||
|
return name(context.getTestInstance().get().getClass(), context.getTestMethod().get());
|
||||||
|
}
|
||||||
|
|
||||||
private static String name(Class<?> testClass, Method testMethod) {
|
private static String name(Class<?> testClass, Method testMethod) {
|
||||||
return name(testClass, testMethod.getName());
|
return name(testClass, testMethod.getName());
|
||||||
|
@ -62,5 +79,4 @@ final class TestUtils {
|
||||||
return format(
|
return format(
|
||||||
"%s_%s%s", testClass.getSimpleName(), testMethod, uuid.substring(uuid.length() / 2));
|
"%s_%s%s", testClass.getSimpleName(), testMethod, uuid.substring(uuid.length() / 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue