use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class MapBinderTests method bindToMapNonScalarCollectionWithDotKeysShouldBind.
@Test
void bindToMapNonScalarCollectionWithDotKeysShouldBind() {
Bindable<List<JavaBean>> valueType = Bindable.listOf(JavaBean.class);
Bindable<Map<String, List<JavaBean>>> target = getMapBindable(String.class, valueType.getType());
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
mockSource.put("foo.bar.baz[0].value", "a");
mockSource.put("foo.bar.baz[1].value", "b");
mockSource.put("foo.bar.baz[2].value", "c");
this.sources.add(mockSource);
Map<String, List<JavaBean>> map = this.binder.bind("foo", target).get();
List<String> values = map.get("bar.baz").stream().map(JavaBean::getValue).collect(Collectors.toList());
assertThat(values).containsExactly("a", "b", "c");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class MapBinderTests method bindToMapShouldBeGreedyForScalars.
@Test
void bindToMapShouldBeGreedyForScalars() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.aaa.bbb.ccc", "foo-bar");
source.put("foo.bbb.ccc.ddd", "BAR_BAZ");
source.put("foo.ccc.ddd.eee", "bazboo");
this.sources.add(source);
Map<String, ExampleEnum> result = this.binder.bind("foo", Bindable.mapOf(String.class, ExampleEnum.class)).get();
assertThat(result).hasSize(3);
assertThat(result).containsEntry("aaa.bbb.ccc", ExampleEnum.FOO_BAR);
assertThat(result).containsEntry("bbb.ccc.ddd", ExampleEnum.BAR_BAZ);
assertThat(result).containsEntry("ccc.ddd.eee", ExampleEnum.BAZ_BOO);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class MapBinderTests method bindToMapShouldTriggerOnSuccess.
@Test
void bindToMapShouldTriggerOnSuccess() {
this.sources.add(new MockConfigurationPropertySource("foo.bar", "1", "line1"));
BindHandler handler = mock(BindHandler.class, Answers.CALLS_REAL_METHODS);
Bindable<Map<String, Integer>> target = STRING_INTEGER_MAP;
this.binder.bind("foo", target, handler);
InOrder ordered = inOrder(handler);
ordered.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo.bar")), eq(Bindable.of(Integer.class)), any(), eq(1));
ordered.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo")), eq(target), any(), isA(Map.class));
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class MapBinderTests method nestedMapsShouldNotBindToNull.
@Test
void nestedMapsShouldNotBindToNull() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.value", "one");
source.put("foo.foos.foo1.value", "two");
source.put("foo.foos.foo2.value", "three");
this.sources.add(source);
BindResult<NestableFoo> foo = this.binder.bind("foo", NestableFoo.class);
assertThat(foo.get().getValue()).isNotNull();
assertThat(foo.get().getFoos().get("foo1").getValue()).isEqualTo("two");
assertThat(foo.get().getFoos().get("foo2").getValue()).isEqualTo("three");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class MapBinderTests method bindToMapWithNoDefaultConstructor.
@Test
void bindToMapWithNoDefaultConstructor() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.items.a", "b");
this.sources.add(source);
ExampleCustomNoDefaultConstructorBean result = this.binder.bind("foo", ExampleCustomNoDefaultConstructorBean.class).get();
assertThat(result.getItems()).containsOnly(entry("foo", "bar"), entry("a", "b"));
}
Aggregations