use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ValidationBindHandlerTests method bindShouldFailWithAccessToNameAndValue.
@Test
void bindShouldFailWithAccessToNameAndValue() {
this.sources.add(new MockConfigurationPropertySource("foo.nested.age", "4"));
BindValidationException cause = bindAndExpectValidationError(() -> this.binder.bind(ConfigurationPropertyName.of("foo"), Bindable.of(ExampleValidatedWithNestedBean.class), this.handler));
assertThat(cause.getValidationErrors().getName().toString()).isEqualTo("foo.nested");
assertThat(cause.getMessage()).contains("nested.age");
assertThat(cause.getMessage()).contains("rejected value [4]");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ValidationBindHandlerTests method validationShouldBeSkippedIfPreviousValidationErrorPresent.
@Test
void validationShouldBeSkippedIfPreviousValidationErrorPresent() {
this.sources.add(new MockConfigurationPropertySource("foo.inner.person-age", 2));
BindValidationException cause = bindAndExpectValidationError(() -> this.binder.bind(ConfigurationPropertyName.of("foo"), Bindable.of(ExampleCamelCase.class), this.handler));
FieldError fieldError = (FieldError) cause.getValidationErrors().getAllErrors().get(0);
assertThat(fieldError.getField()).isEqualTo("personAge");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ValidationBindHandlerTests method bindShouldFailWithAccessToOrigin.
@Test
void bindShouldFailWithAccessToOrigin() {
this.sources.add(new MockConfigurationPropertySource("foo.age", 4, "file"));
BindValidationException cause = bindAndExpectValidationError(() -> this.binder.bind(ConfigurationPropertyName.of("foo"), Bindable.of(ExampleValidatedBean.class), this.handler));
ObjectError objectError = cause.getValidationErrors().getAllErrors().get(0);
assertThat(Origin.from(objectError).toString()).isEqualTo("file");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ValidationBindHandlerTests method validationErrorsForCamelCaseFieldsShouldContainRejectedValue.
@Test
void validationErrorsForCamelCaseFieldsShouldContainRejectedValue() {
this.sources.add(new MockConfigurationPropertySource("foo.inner.person-age", 2));
BindValidationException cause = bindAndExpectValidationError(() -> this.binder.bind(ConfigurationPropertyName.of("foo"), Bindable.of(ExampleCamelCase.class), this.handler));
assertThat(cause.getMessage()).contains("rejected value [2]");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class MapBinderTests method bindToMapWithCustomConverter.
@Test
void bindToMapWithCustomConverter() {
DefaultConversionService conversionService = new DefaultConversionService();
conversionService.addConverter(new MapConverter());
Binder binder = new Binder(this.sources, null, conversionService, null);
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo", "a,b");
this.sources.add(source);
Map<String, String> map = binder.bind("foo", STRING_STRING_MAP).get();
assertThat(map.get("a")).isNotNull();
assertThat(map.get("b")).isNotNull();
}
Aggregations