-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hide indexed propertyNames from YAML source. (#360)
- Loading branch information
Showing
5 changed files
with
118 additions
and
27 deletions.
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
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 |
---|---|---|
|
@@ -2,14 +2,21 @@ | |
|
||
import static java.util.stream.Collectors.toList; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
import java.util.stream.StreamSupport; | ||
|
||
import org.eclipse.microprofile.config.spi.Converter; | ||
import org.junit.jupiter.api.Test; | ||
import org.yaml.snakeyaml.Yaml; | ||
|
||
import io.smallrye.config.SmallRyeConfig; | ||
import io.smallrye.config.SmallRyeConfigBuilder; | ||
|
||
public class YamlConfigSourceTest { | ||
@Test | ||
void flatten() throws Exception { | ||
|
@@ -34,6 +41,61 @@ void profiles() throws Exception { | |
assertEquals("prod", yaml.getValue("%prod.foo.bar")); | ||
} | ||
|
||
@Test | ||
void list() { | ||
String yaml = "quarkus:\n" + | ||
" http:\n" + | ||
" ssl:\n" + | ||
" protocols:\n" + | ||
" - TLSv1.2\n" + | ||
" - TLSv1.3"; | ||
|
||
SmallRyeConfig config = new SmallRyeConfigBuilder().withSources(new YamlConfigSource("Yaml", yaml)).build(); | ||
String[] values = config.getValue("quarkus.http.ssl.protocols", String[].class); | ||
assertEquals(2, values.length); | ||
assertEquals("TLSv1.2", values[0]); | ||
assertEquals("TLSv1.3", values[1]); | ||
|
||
List<String> list = config.getValues("quarkus.http.ssl.protocols", String.class, ArrayList::new); | ||
assertEquals(2, list.size()); | ||
assertEquals("TLSv1.2", list.get(0)); | ||
assertEquals("TLSv1.3", list.get(1)); | ||
} | ||
|
||
@Test | ||
void config() throws Exception { | ||
SmallRyeConfig config = new SmallRyeConfigBuilder() | ||
.withSources(new YamlConfigSource("yaml", YamlConfigSourceTest.class.getResourceAsStream("/example-216.yml"))) | ||
.withConverter(Users.class, 100, new UserConverter()) | ||
.build(); | ||
|
||
final Users users = config.getValue("admin.users", Users.class); | ||
assertEquals(2, users.getUsers().size()); | ||
assertEquals(users.users.get(0).getEmail(), "[email protected]"); | ||
assertEquals(users.users.get(0).getRoles(), Stream.of("Moderator", "Admin").collect(toList())); | ||
|
||
assertEquals("[email protected]", config.getRawValue("admin.users.[0].email")); | ||
} | ||
|
||
@Test | ||
void propertyNames() throws Exception { | ||
SmallRyeConfig config = new SmallRyeConfigBuilder() | ||
.withSources(new YamlConfigSource("yaml", YamlConfigSourceTest.class.getResourceAsStream("/example.yml"))) | ||
.withConverter(Users.class, 100, new UserConverter()) | ||
.build(); | ||
|
||
final List<String> propertyNames = StreamSupport.stream(config.getPropertyNames().spliterator(), false) | ||
.collect(toList()); | ||
|
||
assertTrue(propertyNames.contains("quarkus.http.port")); | ||
assertTrue(propertyNames.contains("quarkus.http.ssl-port")); | ||
assertTrue(propertyNames.contains("quarkus.http.ssl.protocols")); | ||
assertFalse(propertyNames.contains("quarkus.http.ssl.protocols.[0]")); | ||
assertEquals("TLSv1.2", config.getRawValue("quarkus.http.ssl.protocols.[0]")); | ||
assertFalse(propertyNames.contains("quarkus.http.ssl.protocols.[1]")); | ||
assertEquals("TLSv1.3", config.getRawValue("quarkus.http.ssl.protocols.[1]")); | ||
} | ||
|
||
public static class Users { | ||
List<User> users; | ||
|
||
|
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,22 @@ | ||
quarkus: | ||
http: | ||
port: 8081 | ||
ssl-port: 2443 | ||
cors: | ||
~: true | ||
access-control-max-age: 24H | ||
exposed-headers: "SOME-HEADER" | ||
methods: GET,PUT,POST,DELETE,OPTIONS | ||
ssl: | ||
protocols: | ||
- TLSv1.2 | ||
- TLSv1.3 | ||
cipher-suites: | ||
- TLS_AES_128_GCM_SHA256 | ||
- TLS_AES_256_GCM_SHA384 | ||
- TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 | ||
- TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 | ||
- TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 | ||
- TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 | ||
swagger-ui: | ||
always-include: true |