diff --git a/core/runtime/src/test/java/io/quarkus/runtime/configuration/ConfigExpanderTestCase.java b/core/runtime/src/test/java/io/quarkus/runtime/configuration/ConfigExpanderTestCase.java index 464c1a05cc1e7..3c62be1e69f18 100644 --- a/core/runtime/src/test/java/io/quarkus/runtime/configuration/ConfigExpanderTestCase.java +++ b/core/runtime/src/test/java/io/quarkus/runtime/configuration/ConfigExpanderTestCase.java @@ -8,10 +8,6 @@ import java.util.Map; import java.util.NoSuchElementException; -import org.eclipse.microprofile.config.Config; -import org.eclipse.microprofile.config.spi.ConfigProviderResolver; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import io.smallrye.config.ExpressionConfigSourceInterceptor; @@ -23,32 +19,11 @@ */ public class ConfigExpanderTestCase { - static ClassLoader classLoader; - static ConfigProviderResolver cpr; - Config config; - - @BeforeAll - public static void initConfig() { - classLoader = Thread.currentThread().getContextClassLoader(); - cpr = ConfigProviderResolver.instance(); - } - - @AfterEach - public void doAfter() { - try { - cpr.releaseConfig(cpr.getConfig()); - } catch (IllegalStateException ignored) { - // just means no config was installed, which is fine - } - } - private SmallRyeConfig buildConfig(Map configMap) { final SmallRyeConfigBuilder builder = new SmallRyeConfigBuilder(); builder.withInterceptors(new ExpressionConfigSourceInterceptor()); builder.withSources(new PropertiesConfigSource(configMap, "test input", 500)); final SmallRyeConfig config = (SmallRyeConfig) builder.build(); - cpr.registerConfig(config, classLoader); - this.config = config; return config; } diff --git a/core/runtime/src/test/java/io/quarkus/runtime/configuration/ConfigProfileTestCase.java b/core/runtime/src/test/java/io/quarkus/runtime/configuration/ConfigProfileTestCase.java index 6b9be41d66154..8bbcf1fdc8805 100644 --- a/core/runtime/src/test/java/io/quarkus/runtime/configuration/ConfigProfileTestCase.java +++ b/core/runtime/src/test/java/io/quarkus/runtime/configuration/ConfigProfileTestCase.java @@ -11,9 +11,6 @@ import java.util.Map; import java.util.stream.StreamSupport; -import org.eclipse.microprofile.config.spi.ConfigProviderResolver; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import io.smallrye.config.ExpressionConfigSourceInterceptor; @@ -24,24 +21,6 @@ public class ConfigProfileTestCase { - static ClassLoader classLoader; - static ConfigProviderResolver cpr; - - @BeforeAll - public static void initConfig() { - classLoader = Thread.currentThread().getContextClassLoader(); - cpr = ConfigProviderResolver.instance(); - } - - @AfterEach - public void doAfter() { - try { - cpr.releaseConfig(cpr.getConfig()); - } catch (IllegalStateException ignored) { - // just means no config was installed, which is fine - } - } - private SmallRyeConfigBuilder configBuilder(String... keyValues) { return new SmallRyeConfigBuilder() .addDefaultInterceptors() @@ -51,7 +30,6 @@ private SmallRyeConfigBuilder configBuilder(String... keyValues) { private SmallRyeConfig buildConfig(String... keyValues) { final SmallRyeConfig config = configBuilder(keyValues).build(); - cpr.registerConfig(config, classLoader); return config; } diff --git a/core/runtime/src/test/java/io/quarkus/runtime/configuration/DotEnvTestCase.java b/core/runtime/src/test/java/io/quarkus/runtime/configuration/DotEnvTestCase.java index e641f71699fb7..ea123ddce5818 100644 --- a/core/runtime/src/test/java/io/quarkus/runtime/configuration/DotEnvTestCase.java +++ b/core/runtime/src/test/java/io/quarkus/runtime/configuration/DotEnvTestCase.java @@ -15,9 +15,6 @@ import java.util.HashMap; import java.util.Map; -import org.eclipse.microprofile.config.spi.ConfigProviderResolver; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import io.smallrye.config.SmallRyeConfig; @@ -28,24 +25,6 @@ */ public class DotEnvTestCase { - static ClassLoader classLoader; - static ConfigProviderResolver cpr; - - @BeforeAll - public static void initConfig() { - classLoader = Thread.currentThread().getContextClassLoader(); - cpr = ConfigProviderResolver.instance(); - } - - @AfterEach - public void doAfter() { - try { - cpr.releaseConfig(cpr.getConfig()); - } catch (IllegalStateException ignored) { - // just means no config was installed, which is fine - } - } - private SmallRyeConfig buildConfig(Map configMap) throws IOException { final SmallRyeConfigBuilder builder = new SmallRyeConfigBuilder(); final Path dotEnv = Files.createTempFile("test-", ".env"); @@ -62,10 +41,10 @@ private SmallRyeConfig buildConfig(Map configMap) throws IOExcep } } builder.withSources( - new ConfigUtils.BuildTimeDotEnvConfigSourceProvider(dotEnv.toUri().toString()).getConfigSources(classLoader)); + new ConfigUtils.BuildTimeDotEnvConfigSourceProvider(dotEnv.toUri().toString()) + .getConfigSources(Thread.currentThread().getContextClassLoader())); final SmallRyeConfig config = builder.build(); Files.delete(dotEnv); - cpr.registerConfig(config, classLoader); return config; } diff --git a/core/runtime/src/test/java/io/quarkus/runtime/configuration/UUIDPropertyTest.java b/core/runtime/src/test/java/io/quarkus/runtime/configuration/UUIDPropertyTest.java index 1709abb8c35fe..68bb5e7df36f3 100644 --- a/core/runtime/src/test/java/io/quarkus/runtime/configuration/UUIDPropertyTest.java +++ b/core/runtime/src/test/java/io/quarkus/runtime/configuration/UUIDPropertyTest.java @@ -4,9 +4,6 @@ import java.util.UUID; -import org.eclipse.microprofile.config.spi.ConfigProviderResolver; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import io.quarkus.runtime.LaunchMode; @@ -16,29 +13,10 @@ public class UUIDPropertyTest { - static ClassLoader classLoader; - static ConfigProviderResolver cpr; - - @BeforeAll - public static void initConfig() { - classLoader = Thread.currentThread().getContextClassLoader(); - cpr = ConfigProviderResolver.instance(); - } - - @AfterEach - public void doAfter() { - try { - cpr.releaseConfig(cpr.getConfig()); - } catch (IllegalStateException ignored) { - // just means no config was installed, which is fine - } - } - private SmallRyeConfig buildConfig() { final SmallRyeConfigBuilder builder = new SmallRyeConfigBuilder(); builder.withDefaultValue(ConfigUtils.UUID_KEY, UUID.randomUUID().toString()); final SmallRyeConfig config = builder.build(); - cpr.registerConfig(config, classLoader); return config; } diff --git a/extensions/resteasy-classic/rest-client-config/runtime/src/test/java/io/quarkus/restclient/config/RestClientConfigTest.java b/extensions/resteasy-classic/rest-client-config/runtime/src/test/java/io/quarkus/restclient/config/RestClientConfigTest.java index f59f1bb2db1df..ad43a18cbdb40 100644 --- a/extensions/resteasy-classic/rest-client-config/runtime/src/test/java/io/quarkus/restclient/config/RestClientConfigTest.java +++ b/extensions/resteasy-classic/rest-client-config/runtime/src/test/java/io/quarkus/restclient/config/RestClientConfigTest.java @@ -4,8 +4,6 @@ import java.io.IOException; import java.net.URL; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Optional; import org.eclipse.microprofile.config.Config; @@ -13,13 +11,28 @@ import org.eclipse.microprofile.config.spi.ConfigBuilder; import org.eclipse.microprofile.config.spi.ConfigProviderResolver; import org.eclipse.microprofile.rest.client.ext.QueryParamStyle; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import io.smallrye.config.ConfigLogging; import io.smallrye.config.PropertiesConfigSource; public class RestClientConfigTest { + private static ClassLoader classLoader; + private static ConfigProviderResolver configProviderResolver; + + @BeforeAll + public static void initConfig() { + classLoader = Thread.currentThread().getContextClassLoader(); + configProviderResolver = ConfigProviderResolver.instance(); + } + + @AfterEach + public void releaseConfig() { + configProviderResolver.releaseConfig(configProviderResolver.getConfig()); + } + @Test public void testLoadRestClientConfig() throws IOException { setupMPConfig(); @@ -62,27 +75,10 @@ private void verifyConfig(RestClientConfig config) { } private static void setupMPConfig() throws IOException { - ConfigProviderResolver resolver = ConfigProviderResolver.instance(); - ConfigBuilder configBuilder = resolver.getBuilder(); + ConfigBuilder configBuilder = configProviderResolver.getBuilder(); URL propertyFile = RestClientConfigTest.class.getClassLoader().getResource("application.properties"); assertThat(propertyFile).isNotNull(); configBuilder.withSources(new PropertiesConfigSource(propertyFile)); - resolver.registerConfig(configBuilder.build(), getContextClassLoader()); - } - - static ClassLoader getContextClassLoader() { - if (System.getSecurityManager() == null) { - return Thread.currentThread().getContextClassLoader(); - } else { - return AccessController.doPrivileged((PrivilegedAction) () -> { - ClassLoader tccl = null; - try { - tccl = Thread.currentThread().getContextClassLoader(); - } catch (SecurityException ex) { - ConfigLogging.log.failedToRetrieveClassloader(ex); - } - return tccl; - }); - } + configProviderResolver.registerConfig(configBuilder.build(), classLoader); } }