-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ConfigMapping test to Yaml Source.
- Loading branch information
Showing
2 changed files
with
29 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
@@ -15,10 +16,11 @@ | |
import org.junit.jupiter.api.Test; | ||
import org.yaml.snakeyaml.Yaml; | ||
|
||
import io.smallrye.config.ConfigMapping; | ||
import io.smallrye.config.SmallRyeConfig; | ||
import io.smallrye.config.SmallRyeConfigBuilder; | ||
|
||
public class YamlConfigSourceTest { | ||
class YamlConfigSourceTest { | ||
@Test | ||
void flatten() throws Exception { | ||
YamlConfigSource yaml = new YamlConfigSource("yaml", | ||
|
@@ -82,7 +84,6 @@ void config() throws Exception { | |
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) | ||
|
@@ -102,7 +103,6 @@ void quotedProperties() throws Exception { | |
SmallRyeConfig config = new SmallRyeConfigBuilder() | ||
.withSources( | ||
new YamlConfigSource("yaml", YamlConfigSourceTest.class.getResourceAsStream("/example-quotes.yml"))) | ||
.withConverter(Users.class, 100, new UserConverter()) | ||
.build(); | ||
|
||
final List<String> propertyNames = StreamSupport.stream(config.getPropertyNames().spliterator(), false) | ||
|
@@ -127,13 +127,29 @@ void commas() throws Exception { | |
} | ||
|
||
@Test | ||
void intKeys() throws Exception { | ||
void intKeys() { | ||
try { | ||
new SmallRyeConfigBuilder() | ||
.withSources(new YamlConfigSource("yaml", | ||
YamlConfigSourceTest.class.getResourceAsStream("/example-int-keys.yml"))) | ||
.build(); | ||
} catch (Exception e) { | ||
fail(e); | ||
} | ||
} | ||
|
||
@Test | ||
void configMapping() throws Exception { | ||
SmallRyeConfig config = new SmallRyeConfigBuilder() | ||
.withSources( | ||
new YamlConfigSource("yaml", YamlConfigSourceTest.class.getResourceAsStream("/example-int-keys.yml"))) | ||
.withSources(new YamlConfigSource("yaml", YamlConfigSourceTest.class.getResourceAsStream("/example-216.yml"))) | ||
.withConverter(Users.class, 100, new UserConverter()) | ||
.withMapping(UsersMapping.class, "admin") | ||
.build(); | ||
|
||
UsersMapping usersMapping = config.getConfigMapping(UsersMapping.class); | ||
assertEquals(2, usersMapping.users().getUsers().size()); | ||
assertEquals(usersMapping.users().users.get(0).getEmail(), "[email protected]"); | ||
assertEquals(usersMapping.users().users.get(0).getRoles(), Stream.of("Moderator", "Admin").collect(toList())); | ||
} | ||
|
||
public static class Users { | ||
|
@@ -193,4 +209,9 @@ public Users convert(final String value) { | |
return new Yaml().loadAs(value, Users.class); | ||
} | ||
} | ||
|
||
@ConfigMapping(prefix = "admin") | ||
interface UsersMapping { | ||
Users users(); | ||
} | ||
} |