24
24
import org .junit .jupiter .api .Test ;
25
25
import org .junit .jupiter .api .io .TempDir ;
26
26
27
- import io .smallrye .config .PropertiesConfigSource ;
28
27
import io .smallrye .config .SmallRyeConfig ;
29
28
import io .smallrye .config .SmallRyeConfigBuilder ;
30
- import io .smallrye .config .source .yaml .YamlConfigSource ;
31
29
32
30
public class PropertiesLocationTest {
33
31
@ Test
@@ -56,7 +54,7 @@ void multipleResourcesInClassPath(@TempDir Path tempDir) throws Exception {
56
54
57
55
assertEquals ("1234" , config .getRawValue ("my.prop.one" ));
58
56
assertEquals ("5678" , config .getRawValue ("my.prop.two" ));
59
- assertEquals (2 , countSources (config , PropertiesConfigSource . class ));
57
+ assertEquals (2 , countSources (config , "resources.properties" ));
60
58
} finally {
61
59
Thread .currentThread ().setContextClassLoader (contextClassLoader );
62
60
}
@@ -93,7 +91,7 @@ void multipleResourcesInClassPathYaml(@TempDir Path tempDir) throws Exception {
93
91
94
92
assertEquals ("1234" , config .getRawValue ("my.prop.one" ));
95
93
assertEquals ("5678" , config .getRawValue ("my.prop.two" ));
96
- assertEquals (2 , countSources (config , YamlConfigSource . class ));
94
+ assertEquals (2 , countSources (config , "resources.yml" ));
97
95
} finally {
98
96
Thread .currentThread ().setContextClassLoader (contextClassLoader );
99
97
}
@@ -115,7 +113,7 @@ void jar(@TempDir Path tempDir) throws Exception {
115
113
SmallRyeConfig config = buildConfig ("jar:" + filePathOne .toUri () + "!/resources.properties" );
116
114
117
115
assertEquals ("1234" , config .getRawValue ("my.prop.one" ));
118
- assertEquals (1 , countSources (config , PropertiesConfigSource . class ));
116
+ assertEquals (1 , countSources (config , "resources.properties" ));
119
117
} finally {
120
118
Thread .currentThread ().setContextClassLoader (contextClassLoader );
121
119
}
@@ -141,7 +139,7 @@ void jarYaml(@TempDir Path tempDir) throws Exception {
141
139
SmallRyeConfig config = buildConfig ("jar:" + filePathOne .toUri () + "!/resources.yml" );
142
140
143
141
assertEquals ("1234" , config .getRawValue ("my.prop.one" ));
144
- assertEquals (1 , countSources (config , YamlConfigSource . class ));
142
+ assertEquals (1 , countSources (config , "resources.yml" ));
145
143
} finally {
146
144
Thread .currentThread ().setContextClassLoader (contextClassLoader );
147
145
}
@@ -206,9 +204,13 @@ void priorityLoadOrder(@TempDir Path tempDir) throws Exception {
206
204
assertEquals ("main" , config .getRawValue ("my.prop.common" ));
207
205
// This should be loaded by the first discovered source in the classpath
208
206
assertEquals ("1" , config .getRawValue ("my.prop.jar.common" ));
209
- assertEquals (4 , countSources (config , PropertiesConfigSource .class ));
207
+ assertEquals (3 , countSources (config , "microprofile-config.properties" ));
208
+ assertEquals (1 , countSources (config , "fallback.properties" ));
210
209
assertTrue (stream (config .getConfigSources ().spliterator (), false )
211
- .filter (PropertiesConfigSource .class ::isInstance )
210
+ .filter (configSource -> configSource .getName ().contains ("microprofile-config.properties" ))
211
+ .allMatch (configSource -> configSource .getOrdinal () == 100 ));
212
+ assertTrue (stream (config .getConfigSources ().spliterator (), false )
213
+ .filter (configSource -> configSource .getName ().contains ("fallback.properties" ))
212
214
.allMatch (configSource -> configSource .getOrdinal () == 100 ));
213
215
} finally {
214
216
Thread .currentThread ().setContextClassLoader (contextClassLoader );
@@ -384,8 +386,10 @@ void mixedProfiles(@TempDir Path tempDir) throws Exception {
384
386
assertEquals ("common-file" , config .getRawValue ("my.prop.common" ));
385
387
assertEquals ("dev-file" , config .getRawValue ("my.prop.profile" ));
386
388
387
- final List <ConfigSource > sources = stream (config .getConfigSources ().spliterator (), false )
388
- .filter (PropertiesConfigSource .class ::isInstance ).collect (toList ());
389
+ List <ConfigSource > sources = stream (config .getConfigSources ().spliterator (), false )
390
+ .filter (configSource -> configSource .getName ().contains ("config.properties" )
391
+ || configSource .getName ().contains ("config-" ))
392
+ .collect (toList ());
389
393
assertEquals (6 , sources .size ());
390
394
assertEquals ("1" , sources .get (0 ).getValue ("order" ));
391
395
assertEquals ("2" , sources .get (1 ).getValue ("order" ));
@@ -457,7 +461,7 @@ void mixedExtensions(@TempDir Path tempDir) throws Exception {
457
461
.build ();
458
462
459
463
assertEquals ("5678" , config .getRawValue ("my.prop.one" ));
460
- assertEquals (2 , countSources (config , YamlConfigSource . class ));
464
+ assertEquals (2 , countSources (config , "resources" ));
461
465
} finally {
462
466
Thread .currentThread ().setContextClassLoader (contextClassLoader );
463
467
}
@@ -481,8 +485,9 @@ private static SmallRyeConfig buildConfig(String... locations) {
481
485
.build ();
482
486
}
483
487
484
- private static int countSources (SmallRyeConfig config , Class <?> configSource ) {
485
- return (int ) stream (config .getConfigSources ().spliterator (), false ).filter (configSource ::isInstance )
488
+ private static int countSources (SmallRyeConfig config , String name ) {
489
+ return (int ) stream (config .getConfigSources ().spliterator (), false )
490
+ .filter (configSource -> configSource .getName ().contains (name ))
486
491
.count ();
487
492
}
488
493
}
0 commit comments