Search in sources :

Example 1 with DefaultMessageSourceResolvable

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

the class MessageTagTests method messageTagWithMessageSourceResolvable.

@Test
public void messageTagWithMessageSourceResolvable() throws JspException {
    PageContext pc = createPageContext();
    final StringBuffer message = new StringBuffer();
    MessageTag tag = new MessageTag() {

        @Override
        protected void writeMessage(String msg) {
            message.append(msg);
        }
    };
    tag.setPageContext(pc);
    tag.setMessage(new DefaultMessageSourceResolvable("test"));
    assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
    assertEquals("Correct doEndTag return value", Tag.EVAL_PAGE, tag.doEndTag());
    assertEquals("Correct message", "test message", message.toString());
}
Also used : DefaultMessageSourceResolvable(org.springframework.context.support.DefaultMessageSourceResolvable) PageContext(javax.servlet.jsp.PageContext) Test(org.junit.Test)

Example 2 with DefaultMessageSourceResolvable

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

the class ThemeTagTests method requestContext.

@Test
@SuppressWarnings("rawtypes")
public void requestContext() throws ServletException {
    PageContext pc = createPageContext();
    RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest());
    assertEquals("theme test message", rc.getThemeMessage("themetest"));
    assertEquals("theme test message", rc.getThemeMessage("themetest", (String[]) null));
    assertEquals("theme test message", rc.getThemeMessage("themetest", "default"));
    assertEquals("theme test message", rc.getThemeMessage("themetest", (Object[]) null, "default"));
    assertEquals("theme test message arg1", rc.getThemeMessage("themetestArgs", new String[] { "arg1" }));
    assertEquals("theme test message arg1", rc.getThemeMessage("themetestArgs", Arrays.asList(new String[] { "arg1" })));
    assertEquals("default", rc.getThemeMessage("themetesta", "default"));
    assertEquals("default", rc.getThemeMessage("themetesta", (List) null, "default"));
    MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] { "themetest" });
    assertEquals("theme test message", rc.getThemeMessage(resolvable));
}
Also used : DefaultMessageSourceResolvable(org.springframework.context.support.DefaultMessageSourceResolvable) MessageSourceResolvable(org.springframework.context.MessageSourceResolvable) DefaultMessageSourceResolvable(org.springframework.context.support.DefaultMessageSourceResolvable) PageContext(javax.servlet.jsp.PageContext) List(java.util.List) RequestContext(org.springframework.web.servlet.support.RequestContext) Test(org.junit.Test)

Example 3 with DefaultMessageSourceResolvable

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

the class MessageTagTests method requestContext.

@Test
@SuppressWarnings("rawtypes")
public void requestContext() throws ServletException {
    PageContext pc = createPageContext();
    RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest(), pc.getServletContext());
    assertEquals("test message", rc.getMessage("test"));
    assertEquals("test message", rc.getMessage("test", (Object[]) null));
    assertEquals("test message", rc.getMessage("test", "default"));
    assertEquals("test message", rc.getMessage("test", (Object[]) null, "default"));
    assertEquals("test arg1 message arg2", rc.getMessage("testArgs", new String[] { "arg1", "arg2" }, "default"));
    assertEquals("test arg1 message arg2", rc.getMessage("testArgs", Arrays.asList(new String[] { "arg1", "arg2" }), "default"));
    assertEquals("default", rc.getMessage("testa", "default"));
    assertEquals("default", rc.getMessage("testa", (List) null, "default"));
    MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] { "test" });
    assertEquals("test message", rc.getMessage(resolvable));
}
Also used : DefaultMessageSourceResolvable(org.springframework.context.support.DefaultMessageSourceResolvable) MessageSourceResolvable(org.springframework.context.MessageSourceResolvable) DefaultMessageSourceResolvable(org.springframework.context.support.DefaultMessageSourceResolvable) PageContext(javax.servlet.jsp.PageContext) List(java.util.List) RequestContext(org.springframework.web.servlet.support.RequestContext) Test(org.junit.Test)

Aggregations

PageContext (javax.servlet.jsp.PageContext)3 Test (org.junit.Test)3 DefaultMessageSourceResolvable (org.springframework.context.support.DefaultMessageSourceResolvable)3 List (java.util.List)2 MessageSourceResolvable (org.springframework.context.MessageSourceResolvable)2 RequestContext (org.springframework.web.servlet.support.RequestContext)2