diff --git a/smallrye-reactive-messaging-amqp/src/test/java/io/smallrye/reactive/messaging/amqp/AmqpBrokerHolder.java b/smallrye-reactive-messaging-amqp/src/test/java/io/smallrye/reactive/messaging/amqp/AmqpBrokerHolder.java new file mode 100644 index 0000000000..e2d1c4f726 --- /dev/null +++ b/smallrye-reactive-messaging-amqp/src/test/java/io/smallrye/reactive/messaging/amqp/AmqpBrokerHolder.java @@ -0,0 +1,74 @@ +package io.smallrye.reactive.messaging.amqp; + +import jakarta.enterprise.inject.se.SeContainer; + +import org.eclipse.microprofile.config.ConfigProvider; + +import io.smallrye.config.SmallRyeConfigProviderResolver; +import io.smallrye.reactive.messaging.providers.connectors.ExecutionHolder; +import io.smallrye.reactive.messaging.providers.extension.HealthCenter; +import io.smallrye.reactive.messaging.test.common.config.MapBasedConfig; +import io.vertx.mutiny.core.Vertx; + +public class AmqpBrokerHolder { + + public static final AmqpBroker broker = new AmqpBroker(); + + protected ExecutionHolder executionHolder; + protected final static String host = "127.0.0.1"; + protected final static int port = 5672; + protected final static String username = "artemis"; + protected final static String password = "artemis"; + + protected AmqpUsage usage; + + public static void startBroker(String brokerXmlUrl) { + if (brokerXmlUrl != null) { + broker.setConfigResourcePath(brokerXmlUrl); + } + broker.start(port); + System.setProperty("amqp-host", host); + System.setProperty("amqp-port", Integer.toString(port)); + System.setProperty("amqp-user", username); + System.setProperty("amqp-pwd", password); + } + + public static void stopBroker() { + broker.stop(); + System.clearProperty("amqp-host"); + System.clearProperty("amqp-port"); + } + + public void setup() { + executionHolder = new ExecutionHolder(Vertx.vertx()); + usage = new AmqpUsage(executionHolder.vertx(), host, port, username, password); + SmallRyeConfigProviderResolver.instance().releaseConfig(ConfigProvider.getConfig()); + MapBasedConfig.cleanup(); + } + + public void tearDown() { + usage.close(); + executionHolder.terminate(null); + SmallRyeConfigProviderResolver.instance().releaseConfig(ConfigProvider.getConfig()); + MapBasedConfig.cleanup(); + } + + public boolean isAmqpConnectorReady(SeContainer container) { + HealthCenter health = container.getBeanManager().createInstance().select(HealthCenter.class).get(); + return health.getReadiness().isOk(); + } + + public boolean isAmqpConnectorReady(AmqpConnector connector) { + return connector.getReadiness().isOk(); + } + + public boolean isAmqpConnectorAlive(SeContainer container) { + HealthCenter health = container.getBeanManager().createInstance().select(HealthCenter.class).get(); + return health.getLiveness().isOk(); + } + + public boolean isAmqpConnectorAlive(AmqpConnector connector) { + return connector.getLiveness().isOk(); + } + +} diff --git a/smallrye-reactive-messaging-amqp/src/test/java/io/smallrye/reactive/messaging/amqp/AmqpBrokerTestBase.java b/smallrye-reactive-messaging-amqp/src/test/java/io/smallrye/reactive/messaging/amqp/AmqpBrokerTestBase.java index 0b8655c3d9..10c1775f38 100644 --- a/smallrye-reactive-messaging-amqp/src/test/java/io/smallrye/reactive/messaging/amqp/AmqpBrokerTestBase.java +++ b/smallrye-reactive-messaging-amqp/src/test/java/io/smallrye/reactive/messaging/amqp/AmqpBrokerTestBase.java @@ -1,85 +1,30 @@ package io.smallrye.reactive.messaging.amqp; -import jakarta.enterprise.inject.se.SeContainer; - -import org.eclipse.microprofile.config.ConfigProvider; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; -import io.smallrye.config.SmallRyeConfigProviderResolver; -import io.smallrye.reactive.messaging.providers.connectors.ExecutionHolder; -import io.smallrye.reactive.messaging.providers.extension.HealthCenter; -import io.smallrye.reactive.messaging.test.common.config.MapBasedConfig; -import io.vertx.mutiny.core.Vertx; - -public class AmqpBrokerTestBase { - - public static final AmqpBroker broker = new AmqpBroker(); - protected static final String BROKER_XML_LOCATION = "ampq.broker.xml.name"; - - protected ExecutionHolder executionHolder; - protected final static String host = "127.0.0.1"; - protected final static int port = 5672; - protected final static String username = "artemis"; - protected final static String password = "artemis"; - - protected AmqpUsage usage; +public class AmqpBrokerTestBase extends AmqpBrokerHolder { @BeforeAll public static void startBroker() { - String brokerXmlUrl = System.getProperty(BROKER_XML_LOCATION); - if (brokerXmlUrl != null) { - broker.setConfigResourcePath(brokerXmlUrl); - } - broker.start(port); - System.setProperty("amqp-host", host); - System.setProperty("amqp-port", Integer.toString(port)); - System.setProperty("amqp-user", username); - System.setProperty("amqp-pwd", password); + startBroker(null); } @AfterAll public static void stopBroker() { - broker.stop(); - System.clearProperty("amqp-host"); - System.clearProperty("amqp-port"); + AmqpBrokerHolder.stopBroker(); } @BeforeEach public void setup() { - executionHolder = new ExecutionHolder(Vertx.vertx()); - - usage = new AmqpUsage(executionHolder.vertx(), host, port, username, password); - SmallRyeConfigProviderResolver.instance().releaseConfig(ConfigProvider.getConfig()); - MapBasedConfig.cleanup(); + super.setup(); } @AfterEach public void tearDown() { - usage.close(); - executionHolder.terminate(null); - SmallRyeConfigProviderResolver.instance().releaseConfig(ConfigProvider.getConfig()); - MapBasedConfig.cleanup(); - } - - public boolean isAmqpConnectorReady(SeContainer container) { - HealthCenter health = container.getBeanManager().createInstance().select(HealthCenter.class).get(); - return health.getReadiness().isOk(); - } - - public boolean isAmqpConnectorReady(AmqpConnector connector) { - return connector.getReadiness().isOk(); - } - - public boolean isAmqpConnectorAlive(SeContainer container) { - HealthCenter health = container.getBeanManager().createInstance().select(HealthCenter.class).get(); - return health.getLiveness().isOk(); - } - - public boolean isAmqpConnectorAlive(AmqpConnector connector) { - return connector.getLiveness().isOk(); + super.tearDown(); } } diff --git a/smallrye-reactive-messaging-amqp/src/test/java/io/smallrye/reactive/messaging/amqp/ssl/AmqpSSLSinkCDISSLContextTest.java b/smallrye-reactive-messaging-amqp/src/test/java/io/smallrye/reactive/messaging/amqp/ssl/AmqpSSLSinkCDISSLContextTest.java index f54095ca3d..9a1cffacf2 100644 --- a/smallrye-reactive-messaging-amqp/src/test/java/io/smallrye/reactive/messaging/amqp/ssl/AmqpSSLSinkCDISSLContextTest.java +++ b/smallrye-reactive-messaging-amqp/src/test/java/io/smallrye/reactive/messaging/amqp/ssl/AmqpSSLSinkCDISSLContextTest.java @@ -2,6 +2,8 @@ import static org.assertj.core.api.Assertions.assertThat; +import java.io.IOException; +import java.net.URISyntaxException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -15,31 +17,24 @@ import org.junit.jupiter.api.Test; import io.smallrye.config.SmallRyeConfigProviderResolver; -import io.smallrye.reactive.messaging.amqp.AmqpBrokerTestBase; +import io.smallrye.reactive.messaging.amqp.AmqpBrokerHolder; import io.smallrye.reactive.messaging.amqp.AmqpConnector; import io.smallrye.reactive.messaging.amqp.AmqpUsage; import io.smallrye.reactive.messaging.amqp.ProducingBean; import io.smallrye.reactive.messaging.test.common.config.MapBasedConfig; -public class AmqpSSLSinkCDISSLContextTest extends AmqpBrokerTestBase { +public class AmqpSSLSinkCDISSLContextTest extends AmqpBrokerHolder { private WeldContainer container; - private AmqpConnector provider; @BeforeAll - public static void startBroker() { - try { - String brokerXml = SSLBrokerConfigUtil.createSecuredBrokerXml(); - System.setProperty(BROKER_XML_LOCATION, brokerXml); - AmqpBrokerTestBase.startBroker(); - } catch (Exception e) { - throw new RuntimeException(e); - } + public static void startBroker() throws IOException, URISyntaxException { + startBroker(SSLBrokerConfigUtil.createSecuredBrokerXml()); } @AfterAll - public static void clearSslBrokerName() { - System.clearProperty(BROKER_XML_LOCATION); + public static void stopBroker() { + AmqpBrokerHolder.stopBroker(); } @Override @@ -51,12 +46,14 @@ public void setup() { usage = new AmqpUsage(executionHolder.vertx(), host, port + 1, username, password); } + @Override @AfterEach - public void cleanup() { - if (provider != null) { - provider.terminate(null); - } + public void tearDown() { + super.tearDown(); + } + @AfterEach + public void cleanup() { if (container != null) { container.shutdown(); } diff --git a/smallrye-reactive-messaging-amqp/src/test/java/io/smallrye/reactive/messaging/amqp/ssl/AmqpSSLSourceCDISSLContextTest.java b/smallrye-reactive-messaging-amqp/src/test/java/io/smallrye/reactive/messaging/amqp/ssl/AmqpSSLSourceCDISSLContextTest.java index 70c1f5501b..b1fb194004 100644 --- a/smallrye-reactive-messaging-amqp/src/test/java/io/smallrye/reactive/messaging/amqp/ssl/AmqpSSLSourceCDISSLContextTest.java +++ b/smallrye-reactive-messaging-amqp/src/test/java/io/smallrye/reactive/messaging/amqp/ssl/AmqpSSLSourceCDISSLContextTest.java @@ -3,6 +3,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; +import java.io.IOException; +import java.net.URISyntaxException; import java.util.List; import java.util.UUID; import java.util.concurrent.TimeUnit; @@ -15,35 +17,29 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import io.smallrye.config.SmallRyeConfigProviderResolver; -import io.smallrye.reactive.messaging.amqp.AmqpBrokerTestBase; +import io.smallrye.reactive.messaging.amqp.AmqpBrokerHolder; import io.smallrye.reactive.messaging.amqp.AmqpConnector; import io.smallrye.reactive.messaging.amqp.AmqpUsage; import io.smallrye.reactive.messaging.amqp.ConsumptionBean; import io.smallrye.reactive.messaging.test.common.config.MapBasedConfig; -public class AmqpSSLSourceCDISSLContextTest extends AmqpBrokerTestBase { - - private AmqpConnector provider; +@Disabled +public class AmqpSSLSourceCDISSLContextTest extends AmqpBrokerHolder { private WeldContainer container; @BeforeAll - public static void startBroker() { - try { - String brokerXml = SSLBrokerConfigUtil.createSecuredBrokerXml(); - System.setProperty(BROKER_XML_LOCATION, brokerXml); - AmqpBrokerTestBase.startBroker(); - } catch (Exception e) { - throw new RuntimeException(e); - } + public static void startBroker() throws IOException, URISyntaxException { + startBroker(SSLBrokerConfigUtil.createSecuredBrokerXml()); } @AfterAll - public static void clearSslBrokerName() { - System.clearProperty(BROKER_XML_LOCATION); + public static void stopBroker() { + AmqpBrokerHolder.stopBroker(); } @Override @@ -57,10 +53,6 @@ public void setup() { @AfterEach public void cleanup() { - if (provider != null) { - provider.terminate(null); - } - if (container != null) { container.shutdown(); }