Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore config_ordinal for default values source #15257

Merged
merged 1 commit into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}