Skip to content

Commit a094bc7

Browse files
committed
Fallback quarkus.test.integration-test-profile to quarkus.profile
1 parent 53a8789 commit a094bc7

File tree

4 files changed

+54
-22
lines changed

4 files changed

+54
-22
lines changed

core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public interface TestConfig {
160160
/**
161161
* The profile to use when testing using {@code @QuarkusIntegrationTest}
162162
*/
163-
@WithDefault("${quarkus.profile:prod}")
163+
@WithDefault("prod")
164164
String integrationTestProfile();
165165

166166
/**
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package io.quarkus.deployment.dev.testing;
2+
3+
import java.util.function.Function;
4+
5+
import io.quarkus.runtime.LaunchMode;
6+
import io.smallrye.config.ConfigSourceInterceptor;
7+
import io.smallrye.config.ConfigSourceInterceptorContext;
8+
import io.smallrye.config.ConfigSourceInterceptorFactory;
9+
import io.smallrye.config.FallbackConfigSourceInterceptor;
10+
import io.smallrye.config.SmallRyeConfigBuilder;
11+
import io.smallrye.config.SmallRyeConfigBuilderCustomizer;
12+
13+
public class TestConfigCustomizer implements SmallRyeConfigBuilderCustomizer {
14+
private final LaunchMode launchMode;
15+
16+
public TestConfigCustomizer(final LaunchMode launchMode) {
17+
this.launchMode = launchMode;
18+
}
19+
20+
@Override
21+
public void configBuilder(final SmallRyeConfigBuilder builder) {
22+
builder.withDefaultValue("quarkus.profile", launchMode.getDefaultProfile());
23+
builder.withMapping(TestConfig.class);
24+
builder.withInterceptorFactories(new ConfigSourceInterceptorFactory() {
25+
@Override
26+
public ConfigSourceInterceptor getInterceptor(final ConfigSourceInterceptorContext context) {
27+
return new FallbackConfigSourceInterceptor(new Function<String, String>() {
28+
@Override
29+
public String apply(final String name) {
30+
if (name.equals("quarkus.test.integration-test-profile")) {
31+
return "quarkus.profile";
32+
}
33+
return name;
34+
}
35+
});
36+
}
37+
});
38+
}
39+
40+
@Override
41+
public int priority() {
42+
return SmallRyeConfigBuilderCustomizer.super.priority();
43+
}
44+
}

test-framework/junit5-config/src/main/java/io/quarkus/test/config/TestConfigProviderResolver.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
import org.eclipse.microprofile.config.Config;
88
import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
99

10-
import io.quarkus.deployment.dev.testing.TestConfig;
10+
import io.quarkus.deployment.dev.testing.TestConfigCustomizer;
1111
import io.quarkus.runtime.LaunchMode;
1212
import io.quarkus.runtime.configuration.ConfigUtils;
1313
import io.smallrye.config.SmallRyeConfig;
1414
import io.smallrye.config.SmallRyeConfigBuilder;
15-
import io.smallrye.config.SmallRyeConfigBuilderCustomizer;
1615
import io.smallrye.config.SmallRyeConfigProviderResolver;
1716

1817
/**
@@ -51,28 +50,18 @@ public Config getConfig() {
5150
public Config getConfig(final LaunchMode mode) {
5251
if (classLoader.equals(Thread.currentThread().getContextClassLoader())) {
5352
resolver.releaseConfig(classLoader);
54-
LaunchMode current = LaunchMode.current();
55-
LaunchMode.set(mode);
5653
SmallRyeConfig config = configs.computeIfAbsent(mode, new Function<LaunchMode, SmallRyeConfig>() {
5754
@Override
5855
public SmallRyeConfig apply(final LaunchMode launchMode) {
59-
return ConfigUtils.configBuilder(false, true, mode)
60-
.withCustomizers(new SmallRyeConfigBuilderCustomizer() {
61-
@Override
62-
public void configBuilder(final SmallRyeConfigBuilder builder) {
63-
builder.withDefaultValue("quarkus.profile", launchMode.getDefaultProfile());
64-
}
65-
66-
@Override
67-
public int priority() {
68-
return Integer.MAX_VALUE;
69-
}
70-
})
71-
.withMapping(TestConfig.class, "quarkus.test")
56+
LaunchMode current = LaunchMode.current();
57+
LaunchMode.set(launchMode);
58+
SmallRyeConfig config = ConfigUtils.configBuilder(false, true, mode)
59+
.withCustomizers(new TestConfigCustomizer(mode))
7260
.build();
61+
LaunchMode.set(current);
62+
return config;
7363
}
7464
});
75-
LaunchMode.set(current);
7665
resolver.registerConfig(config, classLoader);
7766
return config;
7867
}

test-framework/junit5/src/main/java/io/quarkus/test/junit/classloading/QuarkusTestConfigProviderResolver.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.quarkus.test.junit.classloading;
22

3-
import io.quarkus.deployment.dev.testing.TestConfig;
3+
import io.quarkus.deployment.dev.testing.TestConfigCustomizer;
44
import io.quarkus.runtime.LaunchMode;
55
import io.quarkus.runtime.configuration.ConfigUtils;
66
import io.smallrye.config.SmallRyeConfig;
@@ -17,9 +17,8 @@ public QuarkusTestConfigProviderResolver() {
1717
try {
1818
Thread.currentThread().setContextClassLoader(classLoader);
1919
SmallRyeConfig config = ConfigUtils.configBuilder(false, true, LaunchMode.TEST)
20-
.withProfile(LaunchMode.TEST.getDefaultProfile())
21-
.withMapping(TestConfig.class, "quarkus.test")
2220
.forClassLoader(classLoader)
21+
.withCustomizers(new TestConfigCustomizer(LaunchMode.TEST))
2322
.build();
2423

2524
// See comments on AbstractJVMTestExtension#evaluateExecutionCondition for why this is the system classloader

0 commit comments

Comments
 (0)