From 4b76fbb8c9af267a6bb9c7a90d521ea17d5b8dd5 Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Mon, 22 Feb 2021 22:50:07 +0000 Subject: [PATCH] Ignore config_ordinal for default values source --- .../BuildTimeConfigurationReader.java | 5 ++ .../arc/test/config/ConfigDefaultValues.java | 49 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 extensions/arc/deployment/src/test/java/io/quarkus/arc/test/config/ConfigDefaultValues.java diff --git a/core/deployment/src/main/java/io/quarkus/deployment/configuration/BuildTimeConfigurationReader.java b/core/deployment/src/main/java/io/quarkus/deployment/configuration/BuildTimeConfigurationReader.java index 49a77b3ea6361..109885691ee38 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/configuration/BuildTimeConfigurationReader.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/configuration/BuildTimeConfigurationReader.java @@ -24,6 +24,7 @@ import java.util.TreeMap; import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.eclipse.microprofile.config.spi.ConfigSource; import org.eclipse.microprofile.config.spi.Converter; import org.jboss.logging.Logger; import org.wildfly.common.Assert; @@ -296,6 +297,10 @@ ReadResult run() { } // sweep-up for (String propertyName : config.getPropertyNames()) { + if (propertyName.equals(ConfigSource.CONFIG_ORDINAL)) { + continue; + } + NameIterator ni = new NameIterator(propertyName); if (ni.hasNext() && ni.nextSegmentEquals("quarkus")) { ni.next(); diff --git a/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/config/ConfigDefaultValues.java b/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/config/ConfigDefaultValues.java new file mode 100644 index 0000000000000..9de4efe466e02 --- /dev/null +++ b/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/config/ConfigDefaultValues.java @@ -0,0 +1,49 @@ +package io.quarkus.arc.test.config; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import javax.inject.Inject; + +import org.eclipse.microprofile.config.Config; +import org.eclipse.microprofile.config.spi.ConfigSource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; + +public class ConfigDefaultValues { + @RegisterExtension + static final QuarkusUnitTest TEST = new QuarkusUnitTest() + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) + .addAsResource(new StringAsset("config_ordinal=1000\n" + + "my.prop=1234\n"), "application.properties")); + @Inject + Config config; + + @Test + void configDefaultValues() { + ConfigSource defaultValues = getConfigSourceByName("PropertiesConfigSource[source=Specified default values]"); + assertNotNull(defaultValues); + assertEquals(Integer.MIN_VALUE + 100, defaultValues.getOrdinal()); + + ConfigSource applicationProperties = getConfigSourceByName("PropertiesConfigSource[source=application.properties]"); + assertNotNull(applicationProperties); + assertEquals(1000, applicationProperties.getOrdinal()); + + assertEquals("1234", defaultValues.getValue("my.prop")); + assertEquals("1234", applicationProperties.getValue("my.prop")); + } + + private ConfigSource getConfigSourceByName(String name) { + for (ConfigSource configSource : config.getConfigSources()) { + if (configSource.getName().contains(name)) { + return configSource; + } + } + return null; + } +}