Skip to content

Commit

Permalink
Search for indexed property names before flattened comma separated va…
Browse files Browse the repository at this point in the history
…lue name when loading Collections for CDI injection (#1204)
  • Loading branch information
radcortez authored Jul 30, 2024
1 parent 706dac9 commit 1550541
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ public static <T> T getValue(String name, Type type, String defaultValue, Config

private static <T> T convertValues(ConfigValue configValue, Type type, SmallRyeConfig config) {
List<String> indexedProperties = config.getIndexedProperties(configValue.getName());
// If converting a config property which exists (i.e. myProp[1] = aValue) or no indexed properties exist for the config property
if (configValue.getRawValue() != null || indexedProperties.isEmpty()) {
if (indexedProperties.isEmpty()) {
return config.convertValue(configValue, resolveConverter(type, config));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void indexed() {
assertEquals(Stream.of(new ConvertedValue("out")).collect(Collectors.toList()), indexedBean.getConverted());
assertEquals(Stream.of("a", "b", "c").collect(Collectors.toList()), indexedBean.getDefaults());
assertEquals(Stream.of("e", "f").collect(Collectors.toList()), indexedBean.getOverrideDefaults());
assertEquals(Stream.of("a", "b", "c").collect(Collectors.toList()), indexedBean.getComma());
assertEquals(Stream.of("a", "b").collect(Collectors.toList()), indexedBean.getComma());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static java.util.Collections.singletonMap;
import static java.util.stream.Collectors.toSet;
import static java.util.stream.StreamSupport.stream;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -107,6 +108,24 @@ void unwrap() {
assertThrows(IllegalArgumentException.class, () -> config.unwrap(Object.class));
}

@Test
void getValueArray() {
SmallRyeConfig config = new SmallRyeConfigBuilder()
.withSources(config("array", "one,two,three"))
.build();

String[] strings = config.getValue("array", String[].class);
assertEquals(3, strings.length);
assertArrayEquals(new String[] { "one", "two", "three" }, strings);

config = new SmallRyeConfigBuilder()
.withSources(config("array[0]", "one", "array[1]", "two", "array[2]", "three"))
.build();
strings = config.getValue("array", String[].class);
assertEquals(3, strings.length);
assertArrayEquals(new String[] { "one", "two", "three" }, strings);
}

@Test
void getIndexedValues() {
SmallRyeConfig config = new SmallRyeConfigBuilder()
Expand Down

0 comments on commit 1550541

Please sign in to comment.