Example usage for org.springframework.context.support StaticMessageSource StaticMessageSource

List of usage examples for org.springframework.context.support StaticMessageSource StaticMessageSource

Introduction

In this page you can find the example usage for org.springframework.context.support StaticMessageSource StaticMessageSource.

Prototype

StaticMessageSource

Source Link

Usage

From source file:org.slc.sli.ingestion.util.spring.MessageSourceHelperTest.java

@Test
public void testMessageSourceHelper() {
    StaticMessageSource ms = new StaticMessageSource();

    ms.addMessage("MSG1", Locale.getDefault(), "This is message 1");

    ms.addMessage("MSG2", Locale.getDefault(), "This is message 2 with param: {0}");

    String actual = MessageSourceHelper.getMessage(ms, "MSG1");
    Assert.assertEquals("This is message 1", actual);

    actual = MessageSourceHelper.getMessage(ms, "MSG1", "Test Param");
    Assert.assertEquals("This is message 1", actual);

    actual = MessageSourceHelper.getMessage(ms, "MSG2", "Test Param");
    Assert.assertEquals("This is message 2 with param: Test Param", actual);
}

From source file:de.perdian.commons.i18n.polyglot.PolyglotImplTest.java

@Test
public void testGetMeta() {

    StaticMessageSource messageSource = new StaticMessageSource();
    messageSource.addMessage("key1", Locale.GERMANY, "value1");
    messageSource.addMessage("key2", Locale.GERMANY, "value2");

    PolyglotImpl<ExamplePolyglotSimple> polyglotImpl = new PolyglotImpl<>();
    polyglotImpl.setInstanceClass(ExamplePolyglotSimple.class);
    polyglotImpl.setMessageSource(messageSource);
    PolyglotMeta polyglotMeta = polyglotImpl.getMeta(Locale.GERMANY);

    Assert.assertEquals(Locale.GERMANY, polyglotMeta.getLocale());
    Assert.assertEquals(2, polyglotMeta.getKeys().size());
    Assert.assertEquals(0, polyglotMeta.getMissingValueKeys().size());
    Assert.assertTrue(polyglotMeta.getKeys().containsAll(Arrays.asList("key1", "key2")));

}

From source file:com.github.pjungermann.config.validation.ConfigValidationExceptionTest.java

@Test
public void getMessage_errors_exceptionWithListOfConfigErrorMessages() {
    StaticMessageSource messageSource = new StaticMessageSource();
    messageSource.addMessage("fake.config.error.A", Locale.getDefault(), "Error A happened: {0}");
    messageSource.addMessage("fake.config.error.B", Locale.getDefault(), "Error B happened");

    ArrayList<ConfigError> errors = new ArrayList<>();
    errors.add(new FakeConfigErrorA(123));
    errors.add(new FakeConfigErrorA("2nd"));
    errors.add(new FakeConfigErrorB());

    ConfigValidationException exception = new ConfigValidationException(messageSource, errors);

    assertEquals("Validation errors:\n" + "- Error A happened: 123\n" + "- Error A happened: 2nd\n"
            + "- Error B happened", exception.getMessage());
}

From source file:gov.nih.nci.cabig.caaers.web.ae.AeTabTestCase.java

@Override
protected void setUp() throws Exception {
    super.setUp();
    messageSource = new StaticMessageSource();
    messageSource.addMessage("instruction_ae_modification_detected", Locale.getDefault(), "Testing");
    tab = createTab();//from ww  w.  j  a  va 2 s. c  o m
    tab.setMessageSource(messageSource);
    tab.setExpeditedReportTree(expeditedReportTree);
    tab.setEvaluationService(evaluationService);
}

From source file:com.github.pjungermann.config.specification.constraint.multi.MultiConfigErrorTest.java

@Test
public void toMessage_always_renderMessageSummary() {
    StaticMessageSource messageSource = new StaticMessageSource();
    CollectionKey key = new CollectionKey("fake-key", "fake-collection-key", new IntRange(true, 1, 100),
            "fake-property");

    MultiConfigError error = new MultiConfigError(key, Arrays.asList(new NoCollectionError(key, "invalid"),
            new UnsupportedCollectionEntryPropertyError(key, "invalid")));

    assertEquals(//from w  w w. j  a  va  2  s  . c  om
            "validation errors for collection with key \"fake-collection-key\":\n"
                    + "  - errors.collection.no_collection\n" + "  - error.collection.property.unsupported",
            error.toMessage(messageSource, Locale.getDefault()));
}

From source file:de.perdian.commons.i18n.polyglot.PolyglotImplTest.java

@Test
public void testGetMetaWithConfiguration() {

    StaticMessageSource messageSource = new StaticMessageSource();
    messageSource.addMessage("prefix.key1.postfix", Locale.GERMANY, "value1");

    PolyglotImpl<ExamplePolyglotWithConfiguration> polyglotImpl = new PolyglotImpl<>();
    polyglotImpl.setInstanceClass(ExamplePolyglotWithConfiguration.class);
    polyglotImpl.setMessageSource(messageSource);
    PolyglotMeta polyglotMeta = polyglotImpl.getMeta(Locale.GERMANY);

    Assert.assertEquals(Locale.GERMANY, polyglotMeta.getLocale());
    Assert.assertEquals(1, polyglotMeta.getKeys().size());
    Assert.assertEquals(0, polyglotMeta.getMissingValueKeys().size());
    Assert.assertTrue(polyglotMeta.getKeys().containsAll(Arrays.asList("prefix.key1.postfix")));

}

From source file:com.github.pjungermann.config.validation.ConfigValidationExceptionTest.java

@Test
public void getMessage_noErrors_justErrorHeader() {
    StaticMessageSource messageSource = new StaticMessageSource();
    ArrayList<ConfigError> errors = new ArrayList<>();

    ConfigValidationException exception = new ConfigValidationException(messageSource, errors);

    assertEquals("Validation errors:", exception.getMessage());
}

From source file:de.perdian.commons.i18n.polyglot.PolyglotImplTest.java

@Test
public void testGetMetaWithConfigurationAndNoValues() {

    PolyglotImpl<ExamplePolyglotWithConfiguration> polyglotImpl = new PolyglotImpl<>();
    polyglotImpl.setInstanceClass(ExamplePolyglotWithConfiguration.class);
    polyglotImpl.setMessageSource(new StaticMessageSource());
    PolyglotMeta polyglotMeta = polyglotImpl.getMeta(Locale.GERMANY);

    Assert.assertEquals(Locale.GERMANY, polyglotMeta.getLocale());
    Assert.assertEquals(1, polyglotMeta.getKeys().size());
    Assert.assertEquals(1, polyglotMeta.getMissingValueKeys().size());
    Assert.assertTrue(polyglotMeta.getKeys().containsAll(Arrays.asList("prefix.key1.postfix")));
    Assert.assertTrue(polyglotMeta.getMissingValueKeys().containsAll(Arrays.asList("prefix.key1.postfix")));

}

From source file:org.cloudfoundry.identity.uaa.config.YamlBindingTests.java

@Test
public void testRequiredFieldsValidation() {
    TargetWithValidatedMap target = new TargetWithValidatedMap();
    BindingResult result = bind(target, "info:\n  foo: bar");
    assertEquals(2, result.getErrorCount());
    for (FieldError error : result.getFieldErrors()) {
        System.err.println(new StaticMessageSource().getMessage(error, Locale.getDefault()));
    }/*from   www  . jav a2 s  . c om*/
}

From source file:org.codehaus.groovy.grails.commons.test.AbstractGrailsMockTests.java

protected MessageSource createMessageSource() {
    return new StaticMessageSource();
}