-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Allow to fetch multiple config parameters as a Map #17579
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
...c/deployment/src/test/java/io/quarkus/arc/test/config/ConfigPropertyMapInjectionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package io.quarkus.arc.test.config; | ||
|
||
import static io.smallrye.common.constraint.Assert.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.function.Supplier; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.eclipse.microprofile.config.spi.Converter; | ||
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 ConfigPropertyMapInjectionTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addAsServiceProvider(Converter.class, VersionConverter.class) | ||
.addAsResource(new StringAsset( | ||
"root.numbers.1=one\n" + | ||
"root.numbers.2=two\n" + | ||
"root.numbers.3=three\n" + | ||
"versions.v1=1.The version 1.2.3\n" + | ||
"versions.v1.2=1.The version 1.2.0\n" + | ||
"versions.v2=2.The version 2.0.0\n"), | ||
"application.properties")); | ||
|
||
@ConfigProperty(name = "root.numbers") | ||
Map<Integer, String> numbers; | ||
|
||
@ConfigProperty(name = "root.numbers") | ||
Optional<Map<Integer, String>> oNumbers; | ||
|
||
@ConfigProperty(name = "root.numbers") | ||
Supplier<Map<Integer, String>> sNumbers; | ||
|
||
@ConfigProperty(name = "versions") | ||
Map<String, Version> versions; | ||
|
||
@ConfigProperty(name = "default.versions", defaultValue = "v0.1=0.The version 0;v1\\=1;2;3=1.The version 1\\;2\\;3;v2\\=2;1;0=2.The version 2\\;1\\;0") | ||
Map<String, Version> versionsDefault; | ||
|
||
@Test | ||
void mapInjection() { | ||
assertNotNull(numbers); | ||
assertEquals(3, numbers.size()); | ||
assertEquals("one", numbers.get(1)); | ||
assertEquals("two", numbers.get(2)); | ||
assertEquals("three", numbers.get(3)); | ||
|
||
assertNotNull(numbers); | ||
assertEquals(3, numbers.size()); | ||
assertEquals("one", numbers.get(1)); | ||
assertEquals("two", numbers.get(2)); | ||
assertEquals("three", numbers.get(3)); | ||
|
||
assertNotNull(oNumbers); | ||
assertTrue(oNumbers.isPresent()); | ||
assertEquals(3, oNumbers.get().size()); | ||
assertEquals("one", oNumbers.get().get(1)); | ||
assertEquals("two", oNumbers.get().get(2)); | ||
assertEquals("three", oNumbers.get().get(3)); | ||
|
||
assertNotNull(sNumbers); | ||
assertEquals(3, sNumbers.get().size()); | ||
assertEquals("one", sNumbers.get().get(1)); | ||
assertEquals("two", sNumbers.get().get(2)); | ||
assertEquals("three", sNumbers.get().get(3)); | ||
|
||
assertEquals(2, versions.size()); | ||
assertEquals(new Version(1, "The version 1.2.3"), versions.get("v1")); | ||
assertEquals(new Version(2, "The version 2.0.0"), versions.get("v2")); | ||
assertEquals(2, versionsDefault.size()); | ||
assertEquals(new Version(1, "The version 1;2;3"), versionsDefault.get("v1=1;2;3")); | ||
assertEquals(new Version(2, "The version 2;1;0"), versionsDefault.get("v2=2;1;0")); | ||
} | ||
|
||
static class Version { | ||
int id; | ||
String name; | ||
|
||
Version(int id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
Version version = (Version) o; | ||
return id == version.id && Objects.equals(name, version.name); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, name); | ||
} | ||
} | ||
|
||
public static class VersionConverter implements Converter<Version> { | ||
|
||
@Override | ||
public Version convert(String value) { | ||
return new Version(Integer.parseInt(value.substring(0, 1)), value.substring(2)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make sure change this :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@geoand My bad I should have added a comment. It's ok @radcortez is aware and asked me to do it 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is so we don't forget the changes required for the next SR Config version.