diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/ConfigUtil.java b/test-framework/common/src/main/java/io/quarkus/test/common/TestConfigUtil.java similarity index 61% rename from test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/ConfigUtil.java rename to test-framework/common/src/main/java/io/quarkus/test/common/TestConfigUtil.java index a3d99b23f1b85..8c6e128b28ad7 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/ConfigUtil.java +++ b/test-framework/common/src/main/java/io/quarkus/test/common/TestConfigUtil.java @@ -1,6 +1,4 @@ -package io.quarkus.test.junit.launcher; - -import static io.quarkus.test.junit.IntegrationTestUtil.DEFAULT_WAIT_TIME_SECONDS; +package io.quarkus.test.common; import java.time.Duration; import java.util.ArrayList; @@ -10,11 +8,14 @@ import org.eclipse.microprofile.config.Config; +import io.quarkus.runtime.configuration.QuarkusConfigFactory; import io.smallrye.config.SmallRyeConfig; -public final class ConfigUtil { +public final class TestConfigUtil { + + public static final long DEFAULT_WAIT_TIME_SECONDS = 60; - private ConfigUtil() { + private TestConfigUtil() { } public static List argLineValue(Config config) { @@ -57,4 +58,26 @@ public static String runTarget(Config config) { return config.getOptionalValue("quarkus.run.target", String.class) .orElse(null); } + + /** + * Clean up config left over from badly-behaving previous tests. + *

+ * Tests may call ConfigProvider.getConfig() directly or indirectly, + * triggering lazy initialization in QuarkusConfigFactory#getConfigFor, + * and if they don't call QuarkusConfigFactory.setConfig(null) afterward, + * they may leak that config. + * As it's quite hard to guarantee that all tests clean up after them, + * especially if they don't use any Quarkus*Test extensions, + * we call this cleanup here in Quarkus*Test extensions as an additional safeguard. + *

+ * Note this must be called quite early in extensions in order to be effective: + * things like TestHTTPResourceManager#getUri make use of config and may be called very early, + * upon test instantiation, so cleaning up in beforeEach() won't cut it for example. + */ + public static void cleanUp() { + try { + QuarkusConfigFactory.setConfig(null); + } catch (Throwable ignored) { + } + } } diff --git a/test-framework/junit5-internal/src/main/java/io/quarkus/test/ConfigUtil.java b/test-framework/junit5-internal/src/main/java/io/quarkus/test/ConfigUtil.java deleted file mode 100644 index c7c0c5ebc1488..0000000000000 --- a/test-framework/junit5-internal/src/main/java/io/quarkus/test/ConfigUtil.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.quarkus.test; - -import io.quarkus.runtime.configuration.QuarkusConfigFactory; - -public final class ConfigUtil { - private ConfigUtil() { - } - - /** - * Clean up config left over from badly-behaving previous tests. - *

- * Tests may call ConfigProvider.getConfig() directly or indirectly, - * triggering lazy initialization in QuarkusConfigFactory#getConfigFor, - * and if they don't call QuarkusConfigFactory.setConfig(null) afterward, - * they may leak that config. - * As it's quite hard to guarantee that all tests clean up after them, - * especially if they don't use any Quarkus*Test extensions, - * we call this cleanup here in Quarkus*Test extensions as an additional safeguard. - *

- * Note this must be called quite early in extensions in order to be effective: - * things like TestHTTPResourceManager#getUri make use of config and may be called very early, - * upon test instantiation, so cleaning up in beforeEach() won't cut it for example. - */ - public static void cleanUp() { - try { - QuarkusConfigFactory.setConfig(null); - } catch (Throwable ignored) { - } - } -} diff --git a/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusDevModeTest.java b/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusDevModeTest.java index 79cc8f6b2c1b7..d12b7e583b734 100644 --- a/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusDevModeTest.java +++ b/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusDevModeTest.java @@ -54,6 +54,7 @@ import io.quarkus.test.common.GroovyClassValue; import io.quarkus.test.common.PathTestHelper; import io.quarkus.test.common.PropertyTestUtil; +import io.quarkus.test.common.TestConfigUtil; import io.quarkus.test.common.TestResourceManager; import io.quarkus.test.common.http.TestHTTPResourceManager; @@ -228,7 +229,7 @@ public Object createTestInstance(TestInstanceFactoryContext factoryContext, Exte @Override public void beforeAll(ExtensionContext context) throws Exception { - ConfigUtil.cleanUp(); + TestConfigUtil.cleanUp(); GroovyClassValue.disable(); //set the right launch mode in the outer CL, used by the HTTP host config source ProfileManager.setLaunchMode(LaunchMode.DEVELOPMENT); @@ -325,7 +326,7 @@ public void afterAll(ExtensionContext context) throws Exception { inMemoryLogHandler.clearRecords(); inMemoryLogHandler.setFilter(null); ClearCache.clearAnnotationCache(); - ConfigUtil.cleanUp(); + TestConfigUtil.cleanUp(); } @Override diff --git a/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusProdModeTest.java b/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusProdModeTest.java index 936ce48d4cb6e..f77201d07bf6b 100644 --- a/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusProdModeTest.java +++ b/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusProdModeTest.java @@ -63,6 +63,7 @@ import io.quarkus.maven.dependency.Dependency; import io.quarkus.test.common.PathTestHelper; import io.quarkus.test.common.RestAssuredURLManager; +import io.quarkus.test.common.TestConfigUtil; import io.quarkus.test.common.TestResourceManager; import io.quarkus.utilities.JavaBinFinder; @@ -365,7 +366,7 @@ private JavaArchive getArchiveProducerOrDefault() { @Override public void beforeAll(ExtensionContext extensionContext) throws Exception { - ConfigUtil.cleanUp(); + TestConfigUtil.cleanUp(); ensureNoInjectAnnotationIsUsed(extensionContext.getRequiredTestClass()); ExclusivityChecker.checkTestType(extensionContext, QuarkusProdModeTest.class); @@ -759,7 +760,7 @@ public void afterAll(ExtensionContext extensionContext) throws Exception { FileUtil.deleteDirectory(outputDir); } - ConfigUtil.cleanUp(); + TestConfigUtil.cleanUp(); } } diff --git a/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusUnitTest.java b/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusUnitTest.java index 53c82ed45d735..39cfc3e9aa36d 100644 --- a/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusUnitTest.java +++ b/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusUnitTest.java @@ -75,6 +75,7 @@ import io.quarkus.test.common.PathTestHelper; import io.quarkus.test.common.PropertyTestUtil; import io.quarkus.test.common.RestAssuredURLManager; +import io.quarkus.test.common.TestConfigUtil; import io.quarkus.test.common.TestResourceManager; import io.quarkus.test.common.http.TestHTTPResourceManager; @@ -507,7 +508,7 @@ private void runExtensionMethod(ReflectiveInvocationContext invocationCo @Override public void beforeAll(ExtensionContext extensionContext) throws Exception { - ConfigUtil.cleanUp(); + TestConfigUtil.cleanUp(); GroovyClassValue.disable(); //set the right launch mode in the outer CL, used by the HTTP host config source ProfileManager.setLaunchMode(LaunchMode.TEST); @@ -767,7 +768,7 @@ public void afterAll(ExtensionContext extensionContext) throws Exception { afterAllCustomizer.run(); } ClearCache.clearAnnotationCache(); - ConfigUtil.cleanUp(); + TestConfigUtil.cleanUp(); } if (records != null) { assertLogRecords.accept(records); diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestUtil.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestUtil.java index f7f1a4cf31650..47ff74106e7dc 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestUtil.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestUtil.java @@ -64,7 +64,6 @@ public final class IntegrationTestUtil { public static final int DEFAULT_PORT = 8081; public static final int DEFAULT_HTTPS_PORT = 8444; - public static final long DEFAULT_WAIT_TIME_SECONDS = 60; private IntegrationTestUtil() { } diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java index 3957326e54067..6192437575331 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java @@ -52,12 +52,12 @@ import io.quarkus.test.common.PropertyTestUtil; import io.quarkus.test.common.RestAssuredURLManager; import io.quarkus.test.common.RunCommandLauncher; +import io.quarkus.test.common.TestConfigUtil; import io.quarkus.test.common.TestHostLauncher; import io.quarkus.test.common.TestResourceManager; import io.quarkus.test.common.TestScopeManager; import io.quarkus.test.junit.callback.QuarkusTestMethodContext; import io.quarkus.test.junit.launcher.ArtifactLauncherProvider; -import io.quarkus.test.junit.launcher.ConfigUtil; public class QuarkusIntegrationTestExtension extends AbstractQuarkusTestWithContextExtension implements BeforeTestExecutionCallback, AfterTestExecutionCallback, BeforeEachCallback, AfterEachCallback, @@ -267,8 +267,8 @@ public void close() throws Throwable { launcher = new TestHostLauncher(); } else { Config config = LauncherUtil.installAndGetSomeConfig(); - Duration waitDuration = ConfigUtil.waitTimeValue(config); - String target = ConfigUtil.runTarget(config); + Duration waitDuration = TestConfigUtil.waitTimeValue(config); + String target = TestConfigUtil.runTarget(config); // try to execute a run command published by an extension if it exists. We do this so that extensions that have a custom run don't have to create any special artifact type launcher = RunCommandLauncher.tryLauncher(devServicesLaunchResult.getCuratedApplication().getQuarkusBootstrap(), target, waitDuration); diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/DockerContainerLauncherProvider.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/DockerContainerLauncherProvider.java index 118e9f7323124..68e5d02992776 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/DockerContainerLauncherProvider.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/DockerContainerLauncherProvider.java @@ -17,6 +17,7 @@ import io.quarkus.test.common.DefaultDockerContainerLauncher; import io.quarkus.test.common.DockerContainerArtifactLauncher; import io.quarkus.test.common.LauncherUtil; +import io.quarkus.test.common.TestConfigUtil; import io.smallrye.config.SmallRyeConfig; public class DockerContainerLauncherProvider implements ArtifactLauncherProvider { @@ -44,10 +45,10 @@ public DockerContainerArtifactLauncher create(CreateContext context) { launcher.init(new DefaultDockerInitContext( config.getValue("quarkus.http.test-port", OptionalInt.class).orElse(DEFAULT_PORT), config.getValue("quarkus.http.test-ssl-port", OptionalInt.class).orElse(DEFAULT_HTTPS_PORT), - ConfigUtil.waitTimeValue(config), - ConfigUtil.integrationTestProfile(config), - ConfigUtil.argLineValue(config), - ConfigUtil.env(config), + TestConfigUtil.waitTimeValue(config), + TestConfigUtil.integrationTestProfile(config), + TestConfigUtil.argLineValue(config), + TestConfigUtil.env(config), context.devServicesLaunchResult(), containerImage, pullRequired, diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/JarLauncherProvider.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/JarLauncherProvider.java index 75a1f7ed4d89e..ce2efc03d62a9 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/JarLauncherProvider.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/JarLauncherProvider.java @@ -18,6 +18,7 @@ import io.quarkus.test.common.DefaultJarLauncher; import io.quarkus.test.common.JarArtifactLauncher; import io.quarkus.test.common.LauncherUtil; +import io.quarkus.test.common.TestConfigUtil; public class JarLauncherProvider implements ArtifactLauncherProvider { @@ -43,10 +44,10 @@ public JarArtifactLauncher create(CreateContext context) { launcher.init(new DefaultJarInitContext( config.getValue("quarkus.http.test-port", OptionalInt.class).orElse(DEFAULT_PORT), config.getValue("quarkus.http.test-ssl-port", OptionalInt.class).orElse(DEFAULT_HTTPS_PORT), - ConfigUtil.waitTimeValue(config), - ConfigUtil.integrationTestProfile(config), - ConfigUtil.argLineValue(config), - ConfigUtil.env(config), + TestConfigUtil.waitTimeValue(config), + TestConfigUtil.integrationTestProfile(config), + TestConfigUtil.argLineValue(config), + TestConfigUtil.env(config), context.devServicesLaunchResult(), context.buildOutputDirectory().resolve(pathStr))); return launcher; diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/NativeImageLauncherProvider.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/NativeImageLauncherProvider.java index f4ea8ece1921c..1ade26e674a59 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/NativeImageLauncherProvider.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/NativeImageLauncherProvider.java @@ -17,6 +17,7 @@ import io.quarkus.test.common.DefaultNativeImageLauncher; import io.quarkus.test.common.LauncherUtil; import io.quarkus.test.common.NativeImageLauncher; +import io.quarkus.test.common.TestConfigUtil; public class NativeImageLauncherProvider implements ArtifactLauncherProvider { @Override @@ -41,10 +42,10 @@ public NativeImageLauncher create(CreateContext context) { launcher.init(new NativeImageLauncherProvider.DefaultNativeImageInitContext( config.getValue("quarkus.http.test-port", OptionalInt.class).orElse(DEFAULT_PORT), config.getValue("quarkus.http.test-ssl-port", OptionalInt.class).orElse(DEFAULT_HTTPS_PORT), - ConfigUtil.waitTimeValue(config), - ConfigUtil.integrationTestProfile(config), - ConfigUtil.argLineValue(config), - ConfigUtil.env(config), + TestConfigUtil.waitTimeValue(config), + TestConfigUtil.integrationTestProfile(config), + TestConfigUtil.argLineValue(config), + TestConfigUtil.env(config), context.devServicesLaunchResult(), System.getProperty("native.image.path"), config.getOptionalValue("quarkus.package.output-directory", String.class).orElse(null),