use of org.springframework.context.support.StaticMessageSource in project spring-boot by spring-projects.
the class RelaxedDataBinderTests method testRequiredFieldsValidation.
@Test
public void testRequiredFieldsValidation() throws Exception {
TargetWithValidatedMap target = new TargetWithValidatedMap();
BindingResult result = bind(target, "info[foo]: bar");
assertThat(result.getErrorCount()).isEqualTo(2);
for (FieldError error : result.getFieldErrors()) {
System.err.println(new StaticMessageSource().getMessage(error, Locale.getDefault()));
}
}
use of org.springframework.context.support.StaticMessageSource in project spring-boot by spring-projects.
the class PropertiesConfigurationFactoryParameterizedTests method setupFactory.
private void setupFactory() throws IOException {
this.factory.setTargetName(this.targetName);
this.factory.setMessageSource(new StaticMessageSource());
}
use of org.springframework.context.support.StaticMessageSource in project spring-boot by spring-projects.
the class PropertiesConfigurationFactoryTests method setupFactory.
private void setupFactory() throws IOException {
this.factory = new PropertiesConfigurationFactory<>(Foo.class);
this.factory.setValidator(this.validator);
this.factory.setTargetName(this.targetName);
this.factory.setIgnoreUnknownFields(this.ignoreUnknownFields);
this.factory.setMessageSource(new StaticMessageSource());
}
use of org.springframework.context.support.StaticMessageSource in project spring-framework by spring-projects.
the class DataBinderTests method testRejectWithoutDefaultMessage.
@Test
public void testRejectWithoutDefaultMessage() throws Exception {
TestBean tb = new TestBean();
tb.setName("myName");
tb.setAge(99);
BeanPropertyBindingResult ex = new BeanPropertyBindingResult(tb, "tb");
ex.reject("invalid");
ex.rejectValue("age", "invalidField");
StaticMessageSource ms = new StaticMessageSource();
ms.addMessage("invalid", Locale.US, "general error");
ms.addMessage("invalidField", Locale.US, "invalid field");
assertEquals("general error", ms.getMessage(ex.getGlobalError(), Locale.US));
assertEquals("invalid field", ms.getMessage(ex.getFieldError("age"), Locale.US));
}
Aggregations