1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.views.jsp;
23
24 import org.apache.struts2.TestAction;
25 import org.apache.struts2.StrutsTestCase;
26 import org.apache.struts2.ServletActionContext;
27 import org.apache.struts2.StrutsException;
28 import com.mockobjects.servlet.MockPageContext;
29 import com.mockobjects.servlet.MockJspWriter;
30 import com.opensymphony.xwork2.util.ValueStack;
31 import com.opensymphony.xwork2.ActionContext;
32
33 import javax.servlet.jsp.JspException;
34 import javax.servlet.jsp.tagext.TagSupport;
35
36 public class I18nTagTest extends StrutsTestCase {
37
38 I18nTag tag;
39 MockPageContext pageContext;
40 ValueStack stack;
41
42 protected void setUp() throws Exception {
43 super.setUp();
44
45 tag = new I18nTag();
46 stack = ActionContext.getContext().getValueStack();
47
48
49 StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
50 ActionContext.getContext().setValueStack(stack);
51 request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack);
52
53
54 pageContext = new MockPageContext();
55 pageContext.setRequest(request);
56 pageContext.setJspWriter(new MockJspWriter());
57
58
59 tag.setPageContext(pageContext);
60 }
61
62 public void testSimple() throws Exception {
63
64
65 tag.setName("testmessages");
66
67 int result = 0;
68
69 try {
70 result = tag.doStartTag();
71 } catch (JspException e) {
72 e.printStackTrace();
73 fail();
74 }
75
76 assertEquals(TagSupport.EVAL_BODY_INCLUDE, result);
77
78 try {
79 result = tag.doEndTag();
80 } catch (JspException e) {
81 e.printStackTrace();
82 fail();
83 }
84 }
85
86 /***
87 * Asserts that an exception is thrown when something unexpected is popped off the stack by the closing tag
88 *
89 * @throws Exception
90 */
91 public void testUnexpectedPop() throws Exception {
92
93
94 tag.setName("testmessages");
95
96 int result = 0;
97
98 try {
99 result = tag.doStartTag();
100 } catch (JspException e) {
101 e.printStackTrace();
102 fail();
103 }
104
105 stack.push("An new object on top of the stack");
106
107 assertEquals(TagSupport.EVAL_BODY_INCLUDE, result);
108
109 try {
110 result = tag.doEndTag();
111 fail();
112 } catch (JspException e) {
113 e.printStackTrace();
114 fail();
115 } catch (StrutsException e) {
116 e.printStackTrace();
117
118 }
119
120 }
121 }