From 7e0a75ebe165ed7297236ef856a174655ea3d059 Mon Sep 17 00:00:00 2001 From: Jeromy Evans Date: Tue, 26 Feb 2008 22:50:17 +0000 Subject: [PATCH] WW-2511 fixed OGNL expression in the I18n component to call TextProvider's getTexts(bundleName) method. Added new unit test for this tag. git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@631413 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/struts2/components/I18n.java | 2 +- .../apache/struts2/views/jsp/I18nTagTest.java | 63 +++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 core/src/test/java/org/apache/struts2/views/jsp/I18nTagTest.java diff --git a/core/src/main/java/org/apache/struts2/components/I18n.java b/core/src/main/java/org/apache/struts2/components/I18n.java index db094079a..44993155c 100644 --- a/core/src/main/java/org/apache/struts2/components/I18n.java +++ b/core/src/main/java/org/apache/struts2/components/I18n.java @@ -102,7 +102,7 @@ public class I18n extends Component { try { String name = this.findString(this.name, "name", "Resource bundle name is required. Example: foo or foo_en"); - ResourceBundle bundle = (ResourceBundle) findValue("texts('" + name + "')"); + ResourceBundle bundle = (ResourceBundle) findValue("getTexts('" + name + "')"); if (bundle == null) { bundle = LocalizedTextUtil.findResourceBundle(name, (Locale) getStack().getContext().get(ActionContext.LOCALE)); diff --git a/core/src/test/java/org/apache/struts2/views/jsp/I18nTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/I18nTagTest.java new file mode 100644 index 000000000..2deb26afc --- /dev/null +++ b/core/src/test/java/org/apache/struts2/views/jsp/I18nTagTest.java @@ -0,0 +1,63 @@ +package org.apache.struts2.views.jsp; + +import org.apache.struts2.TestAction; +import org.apache.struts2.StrutsTestCase; +import org.apache.struts2.ServletActionContext; +import com.mockobjects.servlet.MockPageContext; +import com.mockobjects.servlet.MockJspWriter; +import com.opensymphony.xwork2.util.ValueStack; +import com.opensymphony.xwork2.ActionContext; + +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.tagext.TagSupport; + +public class I18nTagTest extends StrutsTestCase { + + I18nTag tag; + MockPageContext pageContext; + ValueStack stack; + + protected void setUp() throws Exception { + super.setUp(); + // create the needed objects + tag = new I18nTag(); + stack = ActionContext.getContext().getValueStack(); + + // create the mock http servlet request + StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest(); + ActionContext.getContext().setValueStack(stack); + request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack); + + // create the mock page context + pageContext = new MockPageContext(); + pageContext.setRequest(request); + pageContext.setJspWriter(new MockJspWriter()); + + // associate the tag with the mock page request + tag.setPageContext(pageContext); + } + + public void testSimple() throws Exception { + + // set the resource bundle + tag.setName("testmessages"); + + int result = 0; + + try { + result = tag.doStartTag(); + } catch (JspException e) { + e.printStackTrace(); + fail(); + } + + assertEquals(TagSupport.EVAL_BODY_INCLUDE, result); + + try { + result = tag.doEndTag(); + } catch (JspException e) { + e.printStackTrace(); + fail(); + } + } +}