use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class NoUnboundElementsBindHandlerTests method bindWhenUsingNoUnboundElementsHandlerShouldBindIfUnboundSystemProperties.
@Test
void bindWhenUsingNoUnboundElementsHandlerShouldBindIfUnboundSystemProperties() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("example.foo", "bar");
source.put("example.other", "baz");
this.sources.add(source);
this.binder = new Binder(this.sources);
NoUnboundElementsBindHandler handler = new NoUnboundElementsBindHandler(BindHandler.DEFAULT, ((configurationPropertySource) -> false));
Example bound = this.binder.bind("example", Bindable.of(Example.class), handler).get();
assertThat(bound.getFoo()).isEqualTo("bar");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class NoUnboundElementsBindHandlerTests method bindWhenUsingNoUnboundElementsHandlerAndUnboundListElementsShouldThrowException.
@Test
void bindWhenUsingNoUnboundElementsHandlerAndUnboundListElementsShouldThrowException() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("example.foo[0]", "bar");
this.sources.add(source);
this.binder = new Binder(this.sources);
assertThatExceptionOfType(BindException.class).isThrownBy(() -> this.binder.bind("example", Bindable.of(Example.class), new NoUnboundElementsBindHandler())).satisfies((ex) -> assertThat(ex.getCause().getMessage()).contains("The elements [example.foo[0]] were left unbound"));
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class NoUnboundElementsBindHandlerTests method bindWhenUsingNoUnboundElementsHandlerShouldBindIfPrefixDifferent.
@Test
void bindWhenUsingNoUnboundElementsHandlerShouldBindIfPrefixDifferent() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("example.foo", "bar");
source.put("other.baz", "bar");
this.sources.add(source);
this.binder = new Binder(this.sources);
Example bound = this.binder.bind("example", Bindable.of(Example.class), new NoUnboundElementsBindHandler()).get();
assertThat(bound.getFoo()).isEqualTo("bar");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class NoUnboundElementsBindHandlerTests method bindWhenUsingNoUnboundElementsHandlerShouldBindIfUnboundNestedCollectionProperties.
@Test
void bindWhenUsingNoUnboundElementsHandlerShouldBindIfUnboundNestedCollectionProperties() {
MockConfigurationPropertySource source1 = new MockConfigurationPropertySource();
source1.put("example.nested[0].string-value", "bar");
MockConfigurationPropertySource source2 = new MockConfigurationPropertySource();
source2.put("example.nested[0].string-value", "bar");
source2.put("example.nested[0].int-value", "2");
source2.put("example.nested[1].string-value", "baz");
source2.put("example.nested[1].other-nested.baz", "baz");
this.sources.add(source1);
this.sources.add(source2);
this.binder = new Binder(this.sources);
NoUnboundElementsBindHandler handler = new NoUnboundElementsBindHandler();
ExampleWithNestedList bound = this.binder.bind("example", Bindable.of(ExampleWithNestedList.class), handler).get();
assertThat(bound.getNested().get(0).getStringValue()).isEqualTo("bar");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ValidationBindHandlerTests method bindShouldBindWithoutHandler.
@Test
void bindShouldBindWithoutHandler() {
this.sources.add(new MockConfigurationPropertySource("foo.age", 4));
ExampleValidatedBean bean = this.binder.bind("foo", Bindable.of(ExampleValidatedBean.class)).get();
assertThat(bean.getAge()).isEqualTo(4);
}
Aggregations