use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class MapBinderTests method bindToMapShouldBindToMapValue.
@Test
void bindToMapShouldBindToMapValue() {
ResolvableType type = ResolvableType.forClassWithGenerics(Map.class, ResolvableType.forClass(String.class), STRING_INTEGER_MAP.getType());
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.bar.baz", "1");
source.put("foo.bar.bin", "2");
source.put("foo.far.baz", "3");
source.put("foo.far.bin", "4");
source.put("faf.far.bin", "x");
this.sources.add(source);
Map<String, Map<String, Integer>> result = this.binder.bind("foo", Bindable.<Map<String, Map<String, Integer>>>of(type)).get();
assertThat(result).hasSize(2);
assertThat(result.get("bar")).containsEntry("baz", 1).containsEntry("bin", 2);
assertThat(result.get("far")).containsEntry("baz", 3).containsEntry("bin", 4);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class MapBinderTests method bindToMapWhenHasExistingMapShouldReplaceOnlyNewContents.
@Test
void bindToMapWhenHasExistingMapShouldReplaceOnlyNewContents() {
this.sources.add(new MockConfigurationPropertySource("foo.bar", "1"));
Map<String, Integer> existing = new HashMap<>();
existing.put("bar", 1000);
existing.put("baz", 1001);
Bindable<Map<String, Integer>> target = STRING_INTEGER_MAP.withExistingValue(existing);
Map<String, Integer> result = this.binder.bind("foo", target).get();
assertThat(result).isExactlyInstanceOf(HashMap.class);
assertThat(result).hasSize(2);
assertThat(result).containsEntry("bar", 1);
assertThat(result).containsEntry("baz", 1001);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class MapBinderTests method bindToPropertiesShouldBeEquivalentToMapOfStringString.
@Test
void bindToPropertiesShouldBeEquivalentToMapOfStringString() {
this.sources.add(new MockConfigurationPropertySource("foo.bar.baz", "1", "line1"));
Bindable<Properties> target = Bindable.of(Properties.class);
Properties properties = this.binder.bind("foo", target).get();
assertThat(properties.getProperty("bar.baz")).isEqualTo("1");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class MapBinderTests method bindToMapStringArrayWithDotKeysAndCommaSeparatedShouldPreserveDot.
@Test
void bindToMapStringArrayWithDotKeysAndCommaSeparatedShouldPreserveDot() {
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
mockSource.put("foo.bar.baz", "a,b,c");
this.sources.add(mockSource);
Map<String, String[]> map = this.binder.bind("foo", STRING_ARRAY_MAP).get();
assertThat(map.get("bar.baz")).containsExactly("a", "b", "c");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class MapBinderTests method bindToMapWithPlaceholdersShouldBeGreedyForScalars.
@Test
void bindToMapWithPlaceholdersShouldBeGreedyForScalars() {
StandardEnvironment environment = new StandardEnvironment();
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(environment, "foo=boo");
MockConfigurationPropertySource source = new MockConfigurationPropertySource("foo.aaa.bbb.ccc", "baz-${foo}");
this.sources.add(source);
this.binder = new Binder(this.sources, new PropertySourcesPlaceholdersResolver(environment));
Map<String, ExampleEnum> result = this.binder.bind("foo", Bindable.mapOf(String.class, ExampleEnum.class)).get();
assertThat(result).containsEntry("aaa.bbb.ccc", ExampleEnum.BAZ_BOO);
}
Aggregations