Skip to content

Commit

Permalink
Always record original default values
Browse files Browse the repository at this point in the history
(cherry picked from commit 3877f16)
  • Loading branch information
radcortez authored and gsmet committed May 14, 2024
1 parent d54eb0d commit dca2ce9
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1233,12 +1233,12 @@ private static void getDefaults(
ClassDefinition.ItemMember itemMember = (ClassDefinition.ItemMember) member;
String defaultValue = itemMember.getDefaultValue();
if (defaultValue != null) {
// lookup config to make sure we catch relocates or fallbacks
// lookup config to make sure we catch relocates or fallbacks and override the value
ConfigValue configValue = config.getConfigValue(propertyName.toString());
if (configValue.getValue() != null) {
defaultValues.put(configValue.getName(), configValue.getValue());
if (configValue.getValue() != null && !configValue.getName().equals(propertyName.toString())) {
defaultValues.put(propertyName.toString(), configValue.getValue());
} else {
defaultValues.put(configValue.getName(), defaultValue);
defaultValues.put(propertyName.toString(), defaultValue);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,10 @@ void generateBuilders(
// Runtime values may contain active profiled names that override sames names in defaults
// We need to keep the original name definition in case a different profile is used to run the app
String activeName = ProfileConfigSourceInterceptor.activeName(entry.getKey(), profiles);
defaultValues.remove(activeName);
// But keep the default
if (!configItem.getReadResult().getRunTimeDefaultValues().containsKey(activeName)) {
defaultValues.remove(activeName);
}
defaultValues.put(entry.getKey(), entry.getValue());
}
defaultValues.putAll(configItem.getReadResult().getRunTimeValues());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ quarkus.arc.unremovable-types[0]=foo
### recording
bt.ok.to.record=from-app
%test.bt.profile.record=properties
%test.quarkus.mapping.rt.record-default=from-app
%test.quarkus.rt.record-default=from-app

### mappings
quarkus.mapping.bt.value=value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ void doNotRecordActiveUnprofiledPropertiesDefaults() {
assertNull(defaultValues.get().getValue("bt.profile.record"));
}

@Test
void recordDefaultFromRootEvenIfInActiveProfile() {
Optional<ConfigSource> defaultValues = config.getConfigSource("DefaultValuesConfigSource");
assertTrue(defaultValues.isPresent());

// Old Roots
assertEquals("from-app", defaultValues.get().getValue("%test.quarkus.rt.record-default"));
assertEquals("from-default", defaultValues.get().getValue("quarkus.rt.record-default"));
// Mappings
assertEquals("from-app", defaultValues.get().getValue("%test.quarkus.mapping.rt.record-default"));
assertEquals("from-default", defaultValues.get().getValue("quarkus.mapping.rt.record-default"));

Check failure on line 66 in integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/extest/RuntimeDefaultsTest.java

View check run for this annotation

quarkus-bot / Build summary for dca2ce9a3f819a4cf8a0488ea7f6aade75fec550

JVM Tests - JDK 17

org.opentest4j.AssertionFailedError: expected: <from-default> but was: <null> at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151) at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
Raw output
org.opentest4j.AssertionFailedError: expected: <from-default> but was: <null>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:177)
	at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1145)
	at io.quarkus.extest.RuntimeDefaultsTest.recordDefaultFromRootEvenIfInActiveProfile(RuntimeDefaultsTest.java:66)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at io.quarkus.test.QuarkusUnitTest.runExtensionMethod(QuarkusUnitTest.java:500)
	at io.quarkus.test.QuarkusUnitTest.interceptTestMethod(QuarkusUnitTest.java:414)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

Check failure on line 66 in integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/extest/RuntimeDefaultsTest.java

View check run for this annotation

quarkus-bot / Build summary for dca2ce9a3f819a4cf8a0488ea7f6aade75fec550

JVM Tests - JDK 21

org.opentest4j.AssertionFailedError: expected: <from-default> but was: <null> at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151) at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
Raw output
org.opentest4j.AssertionFailedError: expected: <from-default> but was: <null>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:177)
	at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1145)
	at io.quarkus.extest.RuntimeDefaultsTest.recordDefaultFromRootEvenIfInActiveProfile(RuntimeDefaultsTest.java:66)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at io.quarkus.test.QuarkusUnitTest.runExtensionMethod(QuarkusUnitTest.java:500)
	at io.quarkus.test.QuarkusUnitTest.interceptTestMethod(QuarkusUnitTest.java:414)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

Check failure on line 66 in integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/extest/RuntimeDefaultsTest.java

View check run for this annotation

quarkus-bot / Build summary for dca2ce9a3f819a4cf8a0488ea7f6aade75fec550

JVM Tests - JDK 17 Windows

org.opentest4j.AssertionFailedError: expected: <from-default> but was: <null> at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151) at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
Raw output
org.opentest4j.AssertionFailedError: expected: <from-default> but was: <null>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:177)
	at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1145)
	at io.quarkus.extest.RuntimeDefaultsTest.recordDefaultFromRootEvenIfInActiveProfile(RuntimeDefaultsTest.java:66)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at io.quarkus.test.QuarkusUnitTest.runExtensionMethod(QuarkusUnitTest.java:500)
	at io.quarkus.test.QuarkusUnitTest.interceptTestMethod(QuarkusUnitTest.java:414)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
}

@Test
void recordProfile() {
Optional<ConfigSource> defaultValues = config.getConfigSource("DefaultValuesConfigSource");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;

@ConfigMapping(prefix = "quarkus.mapping.rt")
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
Expand All @@ -25,6 +26,12 @@ public interface TestMappingRunTime {
/** Record values with named profile **/
Optional<String> recordProfiled();

/**
* Record Default
*/
@WithDefault("from-default")
String recordDefault();

interface Group {
/**
* A Group value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ public class TestRunTimeConfig {
@ConfigItem
public Optional<String> doNotRecord;

/**
* Record Default
*/
@ConfigItem(defaultValue = "from-default")
public String recordDefault;

@Override
public String toString() {
return "TestRunTimeConfig{" +
Expand Down

0 comments on commit dca2ce9

Please sign in to comment.