Skip to content

Commit

Permalink
Merge pull request #15257 from radcortez/fix-15221
Browse files Browse the repository at this point in the history
Ignore config_ordinal for default values source
  • Loading branch information
geoand authored Feb 23, 2021
2 parents dfab7d9 + 4b76fbb commit 3fdebef
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 3fdebef

Please sign in to comment.