diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestConfig.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestConfig.java index f4c3b9eb0f4ae..f93894a7a1e72 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestConfig.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestConfig.java @@ -185,7 +185,7 @@ public interface TestConfig { * When the artifact is a {@code container}, this string is passed right after the {@code docker run} command. * When the artifact is a {@code native binary}, this string is passed right after the native binary name. */ - Optional> argLine(); + Optional<@WithConverter(TrimmedStringConverter.class) List> argLine(); /** * Additional environment variables to be set in the process that {@code @QuarkusIntegrationTest} launches. diff --git a/test-framework/common/src/main/java/io/quarkus/test/common/LauncherUtil.java b/test-framework/common/src/main/java/io/quarkus/test/common/LauncherUtil.java index 63c687909ef0b..46586ca9b0178 100644 --- a/test-framework/common/src/main/java/io/quarkus/test/common/LauncherUtil.java +++ b/test-framework/common/src/main/java/io/quarkus/test/common/LauncherUtil.java @@ -34,6 +34,7 @@ public final class LauncherUtil { private LauncherUtil() { } + @Deprecated(forRemoval = true, since = "3.17") public static Config installAndGetSomeConfig() { return ConfigProvider.getConfig(); } @@ -227,7 +228,6 @@ static void updateConfigForPort(Integer effectivePort) { if (effectivePort != null) { System.setProperty("quarkus.http.port", effectivePort.toString()); //set the port as a system property in order to have it applied to Config System.setProperty("quarkus.http.test-port", effectivePort.toString()); // needed for RestAssuredManager - installAndGetSomeConfig(); // reinitialize the configuration to make sure the actual port is used System.clearProperty("test.url"); // make sure the old value does not interfere with setting the new one System.setProperty("test.url", TestHTTPResourceManager.getUri()); } diff --git a/test-framework/common/src/main/java/io/quarkus/test/common/TestConfigUtil.java b/test-framework/common/src/main/java/io/quarkus/test/common/TestConfigUtil.java index 8c6e128b28ad7..8b394c258958b 100644 --- a/test-framework/common/src/main/java/io/quarkus/test/common/TestConfigUtil.java +++ b/test-framework/common/src/main/java/io/quarkus/test/common/TestConfigUtil.java @@ -18,6 +18,7 @@ public final class TestConfigUtil { private TestConfigUtil() { } + @Deprecated(forRemoval = true, since = "3.17") public static List argLineValue(Config config) { String strValue = config.getOptionalValue("quarkus.test.arg-line", String.class) .orElse(config.getOptionalValue("quarkus.test.argLine", String.class) // legacy value @@ -37,17 +38,20 @@ public static List argLineValue(Config config) { return result; } + @Deprecated(forRemoval = true, since = "3.17") public static Map env(Config config) { return ((SmallRyeConfig) config).getOptionalValues("quarkus.test.env", String.class, String.class) .orElse(Collections.emptyMap()); } + @Deprecated(forRemoval = true, since = "3.17") public static Duration waitTimeValue(Config config) { return config.getOptionalValue("quarkus.test.wait-time", Duration.class) .orElseGet(() -> config.getOptionalValue("quarkus.test.jar-wait-time", Duration.class) // legacy value .orElseGet(() -> Duration.ofSeconds(DEFAULT_WAIT_TIME_SECONDS))); } + @Deprecated(forRemoval = true, since = "3.17") public static String integrationTestProfile(Config config) { return config.getOptionalValue("quarkus.test.integration-test-profile", String.class) .orElseGet(() -> config.getOptionalValue("quarkus.test.native-image-profile", String.class) 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 41b99f9d82c99..2e0cadbf4f15e 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 @@ -29,7 +29,7 @@ import jakarta.inject.Inject; import org.apache.commons.lang3.RandomStringUtils; -import org.eclipse.microprofile.config.Config; +import org.eclipse.microprofile.config.ConfigProvider; import org.eclipse.microprofile.config.inject.ConfigProperty; import org.jboss.jandex.Index; import org.junit.jupiter.api.extension.ExtensionContext; @@ -49,7 +49,6 @@ import io.quarkus.runtime.LaunchMode; import io.quarkus.runtime.logging.LoggingSetupRecorder; import io.quarkus.test.common.ArtifactLauncher; -import io.quarkus.test.common.LauncherUtil; import io.quarkus.test.common.PathTestHelper; import io.quarkus.test.common.TestClassIndexer; import io.quarkus.test.common.TestResourceManager; @@ -276,9 +275,8 @@ public void accept(String s, String s2) { } catch (Exception e) { // use the network the use has specified or else just generate one if none is configured - Config config = LauncherUtil.installAndGetSomeConfig(); - Optional networkIdOpt = config - .getOptionalValue("quarkus.test.container.network", String.class); + Optional networkIdOpt = ConfigProvider.getConfig().getOptionalValue("quarkus.test.container.network", + String.class); if (networkIdOpt.isPresent()) { networkId = networkIdOpt.get(); } else { 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 84f460e27704e..1c1b3c7429c00 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 @@ -19,7 +19,6 @@ import java.io.File; import java.lang.reflect.Field; import java.nio.file.Path; -import java.time.Duration; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -31,7 +30,7 @@ import java.util.function.Function; import java.util.stream.Collectors; -import org.eclipse.microprofile.config.Config; +import org.eclipse.microprofile.config.ConfigProvider; import org.junit.jupiter.api.extension.AfterAllCallback; import org.junit.jupiter.api.extension.AfterEachCallback; import org.junit.jupiter.api.extension.AfterTestExecutionCallback; @@ -44,11 +43,11 @@ import io.quarkus.bootstrap.app.CuratedApplication; import io.quarkus.bootstrap.logging.InitialConfigurator; +import io.quarkus.deployment.dev.testing.TestConfig; import io.quarkus.runtime.logging.JBossVersion; import io.quarkus.runtime.test.TestHttpEndpointProvider; import io.quarkus.test.common.ArtifactLauncher; import io.quarkus.test.common.DevServicesContext; -import io.quarkus.test.common.LauncherUtil; import io.quarkus.test.common.PropertyTestUtil; import io.quarkus.test.common.RestAssuredURLManager; import io.quarkus.test.common.RunCommandLauncher; @@ -58,6 +57,7 @@ import io.quarkus.test.common.TestScopeManager; import io.quarkus.test.junit.callback.QuarkusTestMethodContext; import io.quarkus.test.junit.launcher.ArtifactLauncherProvider; +import io.smallrye.config.SmallRyeConfig; public class QuarkusIntegrationTestExtension extends AbstractQuarkusTestWithContextExtension implements BeforeTestExecutionCallback, AfterTestExecutionCallback, BeforeEachCallback, AfterEachCallback, @@ -193,10 +193,10 @@ private QuarkusTestExtensionState doProcessStart(Properties quarkusArtifactPrope String artifactType = getArtifactType(quarkusArtifactProperties); - Config config = LauncherUtil.installAndGetSomeConfig(); - String testProfile = TestConfigUtil.integrationTestProfile(config); + SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class); + TestConfig testConfig = config.getConfigMapping(TestConfig.class); boolean isDockerLaunch = isContainer(artifactType) - || (isJar(artifactType) && "test-with-native-agent".equals(testProfile)); + || (isJar(artifactType) && "test-with-native-agent".equals(testConfig.integrationTestProfile())); ArtifactLauncher.InitContext.DevServicesLaunchResult devServicesLaunchResult = handleDevServices(context, isDockerLaunch); @@ -269,20 +269,19 @@ public void close() throws Throwable { }); additionalProperties.putAll(resourceManagerProps); - ArtifactLauncher launcher = null; + ArtifactLauncher launcher; String testHost = System.getProperty("quarkus.http.test-host"); if ((testHost != null) && !testHost.isEmpty()) { launcher = new TestHostLauncher(); } else { - 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); + target, testConfig.waitTime()); if (launcher == null) { ServiceLoader loader = ServiceLoader.load(ArtifactLauncherProvider.class); for (ArtifactLauncherProvider launcherProvider : loader) { - if (launcherProvider.supportsArtifactType(artifactType, testProfile)) { + if (launcherProvider.supportsArtifactType(artifactType, testConfig.integrationTestProfile())) { launcher = launcherProvider.create( new DefaultArtifactLauncherCreateContext(quarkusArtifactProperties, context, requiredTestClass, @@ -378,7 +377,7 @@ private void throwBootFailureException() { private boolean isCallbacksEnabledForIntegrationTests() { return Optional.ofNullable(System.getProperty(ENABLED_CALLBACKS_PROPERTY)).map(Boolean::parseBoolean) - .or(() -> LauncherUtil.installAndGetSomeConfig().getOptionalValue(ENABLED_CALLBACKS_PROPERTY, Boolean.class)) + .or(() -> ConfigProvider.getConfig().getOptionalValue(ENABLED_CALLBACKS_PROPERTY, Boolean.class)) .orElse(false); } diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainIntegrationTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainIntegrationTestExtension.java index a7dea2f0c0fc1..b2b3c9ae6dae7 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainIntegrationTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainIntegrationTestExtension.java @@ -17,7 +17,7 @@ import java.util.Properties; import java.util.ServiceLoader; -import org.eclipse.microprofile.config.Config; +import org.eclipse.microprofile.config.ConfigProvider; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.extension.AfterEachCallback; import org.junit.jupiter.api.extension.BeforeEachCallback; @@ -26,16 +26,16 @@ import org.junit.jupiter.api.extension.ParameterResolutionException; import org.junit.jupiter.api.extension.ParameterResolver; +import io.quarkus.deployment.dev.testing.TestConfig; import io.quarkus.runtime.logging.JBossVersion; import io.quarkus.test.common.ArtifactLauncher; -import io.quarkus.test.common.LauncherUtil; -import io.quarkus.test.common.TestConfigUtil; import io.quarkus.test.common.TestResourceManager; import io.quarkus.test.junit.launcher.ArtifactLauncherProvider; import io.quarkus.test.junit.main.Launch; import io.quarkus.test.junit.main.LaunchResult; import io.quarkus.test.junit.main.QuarkusMainLauncher; import io.quarkus.test.junit.util.CloseAdaptor; +import io.smallrye.config.SmallRyeConfig; public class QuarkusMainIntegrationTestExtension extends AbstractQuarkusTestWithContextExtension implements BeforeEachCallback, AfterEachCallback, ParameterResolver { @@ -157,13 +157,13 @@ private ArtifactLauncher.LaunchResult doProcessStart(ExtensionContext context, S testResourceManager.inject(context.getRequiredTestInstance()); - Config config = LauncherUtil.installAndGetSomeConfig(); - String testProfile = TestConfigUtil.integrationTestProfile(config); + SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class); + TestConfig testConfig = config.getConfigMapping(TestConfig.class); ArtifactLauncher launcher = null; ServiceLoader loader = ServiceLoader.load(ArtifactLauncherProvider.class); for (ArtifactLauncherProvider launcherProvider : loader) { - if (launcherProvider.supportsArtifactType(artifactType, testProfile)) { + if (launcherProvider.supportsArtifactType(artifactType, testConfig.integrationTestProfile())) { launcher = launcherProvider.create( new DefaultArtifactLauncherCreateContext(quarkusArtifactProperties, context, requiredTestClass, devServicesLaunchResult)); 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 319ebcbaed462..e475c7e4e28aa 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,13 +17,14 @@ import java.util.OptionalInt; import java.util.ServiceLoader; +import org.eclipse.microprofile.config.ConfigProvider; + +import io.quarkus.deployment.dev.testing.TestConfig; import io.quarkus.deployment.images.ContainerImages; import io.quarkus.deployment.util.FileUtil; import io.quarkus.test.common.ArtifactLauncher; 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 { @@ -38,6 +39,7 @@ public DockerContainerArtifactLauncher create(CreateContext context) { String containerImage = context.quarkusArtifactProperties().getProperty("metadata.container-image"); boolean pullRequired = Boolean .parseBoolean(context.quarkusArtifactProperties().getProperty("metadata.pull-required", "false")); + SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class); if ((containerImage != null) && !containerImage.isEmpty()) { DockerContainerArtifactLauncher launcher; ServiceLoader loader = ServiceLoader.load(DockerContainerArtifactLauncher.class); @@ -47,7 +49,6 @@ public DockerContainerArtifactLauncher create(CreateContext context) { } else { launcher = new DefaultDockerContainerLauncher(); } - SmallRyeConfig config = (SmallRyeConfig) LauncherUtil.installAndGetSomeConfig(); launcherInit(context, launcher, config, containerImage, pullRequired, Optional.empty(), volumeMounts(config), Collections.emptyList()); return launcher; @@ -59,10 +60,8 @@ public DockerContainerArtifactLauncher create(CreateContext context) { // adding a volume mapping pointing to the build output directory, // and then instructing the java process to run the run jar, // along with the native image agent arguments and any other additional parameters. - SmallRyeConfig config = (SmallRyeConfig) LauncherUtil.installAndGetSomeConfig(); - String testProfile = TestConfigUtil.integrationTestProfile(config); - - if ("test-with-native-agent".equals(testProfile)) { + TestConfig testConfig = config.getConfigMapping(TestConfig.class); + if ("test-with-native-agent".equals(testConfig.integrationTestProfile())) { DockerContainerArtifactLauncher launcher = new DefaultDockerContainerLauncher(); Optional entryPoint = Optional.of("java"); Map volumeMounts = new HashMap<>(volumeMounts(config)); @@ -83,13 +82,14 @@ public DockerContainerArtifactLauncher create(CreateContext context) { private void launcherInit(CreateContext context, DockerContainerArtifactLauncher launcher, SmallRyeConfig config, String containerImage, boolean pullRequired, Optional entryPoint, Map volumeMounts, List programArgs) { + TestConfig testConfig = config.getConfigMapping(TestConfig.class); 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), - TestConfigUtil.waitTimeValue(config), - TestConfigUtil.integrationTestProfile(config), - TestConfigUtil.argLineValue(config), - TestConfigUtil.env(config), + testConfig.waitTime(), + testConfig.integrationTestProfile(), + testConfig.argLine().orElse(List.of()), + testConfig.env(), 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 ef360c7500053..3a6c6104227cf 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 @@ -12,13 +12,13 @@ import java.util.OptionalInt; import java.util.ServiceLoader; -import org.eclipse.microprofile.config.Config; +import org.eclipse.microprofile.config.ConfigProvider; +import io.quarkus.deployment.dev.testing.TestConfig; import io.quarkus.test.common.ArtifactLauncher; import io.quarkus.test.common.DefaultJarLauncher; import io.quarkus.test.common.JarArtifactLauncher; -import io.quarkus.test.common.LauncherUtil; -import io.quarkus.test.common.TestConfigUtil; +import io.smallrye.config.SmallRyeConfig; public class JarLauncherProvider implements ArtifactLauncherProvider { @@ -40,14 +40,15 @@ public JarArtifactLauncher create(CreateContext context) { launcher = new DefaultJarLauncher(); } - Config config = LauncherUtil.installAndGetSomeConfig(); + SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class); + TestConfig testConfig = config.getConfigMapping(TestConfig.class); 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), - TestConfigUtil.waitTimeValue(config), - TestConfigUtil.integrationTestProfile(config), - TestConfigUtil.argLineValue(config), - TestConfigUtil.env(config), + testConfig.waitTime(), + testConfig.integrationTestProfile(), + testConfig.argLine().orElse(List.of()), + testConfig.env(), 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 e33465517c0c2..a9b2e2138e2cc 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 @@ -11,13 +11,13 @@ import java.util.OptionalInt; import java.util.ServiceLoader; -import org.eclipse.microprofile.config.Config; +import org.eclipse.microprofile.config.ConfigProvider; +import io.quarkus.deployment.dev.testing.TestConfig; import io.quarkus.test.common.ArtifactLauncher; import io.quarkus.test.common.DefaultNativeImageLauncher; -import io.quarkus.test.common.LauncherUtil; import io.quarkus.test.common.NativeImageLauncher; -import io.quarkus.test.common.TestConfigUtil; +import io.smallrye.config.SmallRyeConfig; public class NativeImageLauncherProvider implements ArtifactLauncherProvider { @Override @@ -38,14 +38,15 @@ public NativeImageLauncher create(CreateContext context) { launcher = new DefaultNativeImageLauncher(); } - Config config = LauncherUtil.installAndGetSomeConfig(); + SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class); + TestConfig testConfig = config.getConfigMapping(TestConfig.class); 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), - TestConfigUtil.waitTimeValue(config), - TestConfigUtil.integrationTestProfile(config), - TestConfigUtil.argLineValue(config), - TestConfigUtil.env(config), + testConfig.waitTime(), + testConfig.nativeImageProfile(), + testConfig.argLine().orElse(List.of()), + testConfig.env(), context.devServicesLaunchResult(), System.getProperty("native.image.path"), config.getOptionalValue("quarkus.package.output-directory", String.class).orElse(null),