Skip to content

Commit 0cb91b9

Browse files
committed
Test and fix for MP config bug 8737 (getOrdinal returning wrong value) (helidon-io#8744)
1 parent f4b8eed commit 0cb91b9

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

config/config-mp/src/main/java/io/helidon/config/mp/MpEnvironmentVariablesSource.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021 Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2024 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,8 +25,9 @@
2525

2626
import org.eclipse.microprofile.config.spi.ConfigSource;
2727

28-
@Priority(300)
28+
@Priority(MpEnvironmentVariablesSource.MY_DEFAULT_ORDINAL)
2929
class MpEnvironmentVariablesSource implements ConfigSource {
30+
static final int MY_DEFAULT_ORDINAL = 300;
3031
private static final Pattern DISALLOWED_CHARS = Pattern.compile("[^a-zA-Z0-9_]");
3132
private static final String UNDERSCORE = "_";
3233

@@ -71,6 +72,16 @@ public String getValue(String propertyName) {
7172
}).value;
7273
}
7374

75+
@Override
76+
public int getOrdinal() {
77+
String configOrdinal = getValue(CONFIG_ORDINAL);
78+
if (configOrdinal == null) {
79+
return MY_DEFAULT_ORDINAL;
80+
} else {
81+
return ConfigSource.super.getOrdinal();
82+
}
83+
}
84+
7485
@Override
7586
public String getName() {
7687
return "Environment Variables";

config/config-mp/src/main/java/io/helidon/config/mp/MpSystemPropertiesSource.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021 Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2024 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,8 +26,9 @@
2626

2727
import org.eclipse.microprofile.config.spi.ConfigSource;
2828

29-
@Priority(400)
29+
@Priority(MpSystemPropertiesSource.MY_DEFAULT_ORDINAL)
3030
class MpSystemPropertiesSource implements ConfigSource {
31+
static final int MY_DEFAULT_ORDINAL = 400;
3132
private final Properties props;
3233

3334
MpSystemPropertiesSource() {
@@ -58,6 +59,16 @@ public String getName() {
5859
return "System Properties";
5960
}
6061

62+
@Override
63+
public int getOrdinal() {
64+
String configOrdinal = getValue(CONFIG_ORDINAL);
65+
if (configOrdinal == null) {
66+
return MY_DEFAULT_ORDINAL;
67+
} else {
68+
return ConfigSource.super.getOrdinal();
69+
}
70+
}
71+
6172
@Override
6273
public String toString() {
6374
return getName() + " (" + getOrdinal() + ")";

config/config-mp/src/test/java/io/helidon/config/mp/MpConfigSourcesTest.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2024 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -107,6 +107,18 @@ void testMpConfigSourcesNullConfig() {
107107
assertThat(npe.getMessage(), is("Config cannot be null"));
108108
}
109109

110+
@Test
111+
void testSystemPropertiesConfigSourceDefaultOrdinal() {
112+
org.eclipse.microprofile.config.spi.ConfigSource configSource = MpConfigSources.systemProperties();
113+
assertThat(configSource.getOrdinal(), is(400));
114+
}
115+
116+
@Test
117+
void testEnvironmentVariablesConfigSourceDefaultOrdinal() {
118+
org.eclipse.microprofile.config.spi.ConfigSource configSource = MpConfigSources.environmentVariables();
119+
assertThat(configSource.getOrdinal(), is(300));
120+
}
121+
110122
private static final class NodeImpl implements ConfigSource, NodeConfigSource {
111123
private static final String DESCRIPTION = "node-unit-test";
112124
private static final String KEY = "key";

0 commit comments

Comments
 (0)