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

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

Introduction

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

Prototype

public void addMessage(String code, Locale locale, String msg) 

Source Link

Document

Associate the given message with the given code.

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: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: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: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:org.openregistry.core.web.AddSoRPersonFlowTests.java

protected void setUp() {

    this.personService = mock(PersonService.class);

    final StaticMessageSource staticMessageSource = new StaticMessageSource();
    staticMessageSource.addMessage("personAddedFinalConfirm", Locale.getDefault(), "test");
    staticMessageSource.addMessage("roleAdded", Locale.getDefault(), "test");
    staticMessageSource.addMessage("errorCode", Locale.getDefault(), "test");

    this.messageContext = new DefaultMessageContext(staticMessageSource);
    this.personSearchAction = new PersonSearchAction(this.personService);
    this.personSearchAction.setPreferredPersonIdentifierType("NETID");
    this.referenceRepository = new MockReferenceRepository();
    this.reconciliationCriteriaFactory = new MockReconciliationCriteriaFactory();
}