Search in sources :

Example 96 with ResourceBundleMessageSource

use of org.springframework.context.support.ResourceBundleMessageSource in project irida by phac-nml.

the class SampleTest method setUp.

@Before
public void setUp() {
    Configuration<?> configuration = Validation.byDefaultProvider().configure();
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename(MESSAGES_BASENAME);
    configuration.messageInterpolator(new ResourceBundleMessageInterpolator(new PlatformResourceBundleLocator(MESSAGES_BASENAME)));
    ValidatorFactory factory = configuration.buildValidatorFactory();
    validator = factory.getValidator();
}
Also used : ResourceBundleMessageInterpolator(org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator) ValidatorFactory(javax.validation.ValidatorFactory) PlatformResourceBundleLocator(org.hibernate.validator.resourceloading.PlatformResourceBundleLocator) ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource) Before(org.junit.Before)

Example 97 with ResourceBundleMessageSource

use of org.springframework.context.support.ResourceBundleMessageSource in project irida by phac-nml.

the class UserTest method setUp.

@Before
public void setUp() {
    b = ResourceBundle.getBundle(MESSAGES_BASENAME);
    Configuration<?> configuration = Validation.byDefaultProvider().configure();
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename(MESSAGES_BASENAME);
    configuration.messageInterpolator(new ResourceBundleMessageInterpolator(new PlatformResourceBundleLocator(MESSAGES_BASENAME)));
    ValidatorFactory factory = configuration.buildValidatorFactory();
    validator = factory.getValidator();
}
Also used : ResourceBundleMessageInterpolator(org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator) PlatformResourceBundleLocator(org.hibernate.validator.resourceloading.PlatformResourceBundleLocator) ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource) Before(org.junit.Before)

Example 98 with ResourceBundleMessageSource

use of org.springframework.context.support.ResourceBundleMessageSource in project irida by phac-nml.

the class GalaxyAccountEmailTest method setUp.

@Before
public void setUp() {
    b = ResourceBundle.getBundle(MESSAGES_BASENAME);
    Configuration<?> configuration = Validation.byDefaultProvider().configure();
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename(MESSAGES_BASENAME);
    configuration.messageInterpolator(new ResourceBundleMessageInterpolator(new PlatformResourceBundleLocator(MESSAGES_BASENAME)));
    ValidatorFactory factory = configuration.buildValidatorFactory();
    validator = factory.getValidator();
}
Also used : ResourceBundleMessageInterpolator(org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator) ValidatorFactory(javax.validation.ValidatorFactory) PlatformResourceBundleLocator(org.hibernate.validator.resourceloading.PlatformResourceBundleLocator) ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource) Before(org.junit.Before)

Example 99 with ResourceBundleMessageSource

use of org.springframework.context.support.ResourceBundleMessageSource in project cloudbreak by hortonworks.

the class MessagesConfig method messageSource.

@Bean
public MessageSource messageSource() {
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename("messages/messages");
    return messageSource;
}
Also used : ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource) Bean(org.springframework.context.annotation.Bean)

Example 100 with ResourceBundleMessageSource

use of org.springframework.context.support.ResourceBundleMessageSource in project spring-framework by spring-projects.

the class DataBinderTests method testBindingErrors.

@Test
void testBindingErrors() {
    TestBean rod = new TestBean();
    DataBinder binder = new DataBinder(rod, "person");
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("age", "32x");
    binder.bind(pvs);
    Errors errors = binder.getBindingResult();
    FieldError ageError = errors.getFieldError("age");
    assertThat(ageError.getCode()).isEqualTo("typeMismatch");
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename("org.springframework.validation.messages1");
    String msg = messageSource.getMessage(ageError, Locale.getDefault());
    assertThat(msg).isEqualTo("Field age did not have correct type");
    messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename("org.springframework.validation.messages2");
    msg = messageSource.getMessage(ageError, Locale.getDefault());
    assertThat(msg).isEqualTo("Field Age did not have correct type");
    messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename("org.springframework.validation.messages3");
    msg = messageSource.getMessage(ageError, Locale.getDefault());
    assertThat(msg).isEqualTo("Field Person Age did not have correct type");
}
Also used : DerivedTestBean(org.springframework.beans.testfixture.beans.DerivedTestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) IndexedTestBean(org.springframework.beans.testfixture.beans.IndexedTestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource) Test(org.junit.jupiter.api.Test)

Aggregations

ResourceBundleMessageSource (org.springframework.context.support.ResourceBundleMessageSource)179 Bean (org.springframework.context.annotation.Bean)99 Before (org.junit.Before)16 MessageSourceAccessor (org.springframework.context.support.MessageSourceAccessor)13 LocalValidatorFactoryBean (org.springframework.validation.beanvalidation.LocalValidatorFactoryBean)9 ValidatorFactory (javax.validation.ValidatorFactory)6 ResourceBundleMessageInterpolator (org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator)6 PlatformResourceBundleLocator (org.hibernate.validator.resourceloading.PlatformResourceBundleLocator)6 Test (org.junit.Test)6 Test (org.junit.jupiter.api.Test)6 IOException (java.io.IOException)5 List (java.util.List)5 Locale (java.util.Locale)5 ReaderFactoryByMap (net.n2oapp.framework.config.selective.reader.ReaderFactoryByMap)5 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)5 MessageSource (org.springframework.context.MessageSource)5 ArrayList (java.util.ArrayList)4 N2oApplicationBuilder (net.n2oapp.framework.config.N2oApplicationBuilder)4 N2oEnvironment (net.n2oapp.framework.config.compile.pipeline.N2oEnvironment)4 PersisterFactoryByMap (net.n2oapp.framework.config.selective.persister.PersisterFactoryByMap)4