1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.views.jsp;
22
23 import javax.servlet.jsp.tagext.TagSupport;
24
25 import junit.framework.TestCase;
26
27 import org.apache.struts2.ServletActionContext;
28 import org.apache.struts2.StrutsTestCase;
29 import org.apache.struts2.components.If;
30
31 import com.mockobjects.servlet.MockJspWriter;
32 import com.mockobjects.servlet.MockPageContext;
33 import com.opensymphony.xwork2.util.ValueStack;
34 import com.opensymphony.xwork2.util.ValueStackFactory;
35
36 /***
37 *
38 */
39 public class ElseIfTagTest extends StrutsTestCase {
40
41 protected MockPageContext pageContext;
42 protected MockJspWriter jspWriter;
43 protected ValueStack stack;
44
45
46 public void testIfIsFalseElseIfIsTrue() throws Exception {
47 stack.getContext().put(If.ANSWER, Boolean.FALSE);
48
49 ElseIfTag tag = new ElseIfTag();
50 tag.setPageContext(pageContext);
51 tag.setTest("true");
52
53 int result = tag.doStartTag();
54 tag.doEndTag();
55
56 assertEquals(result, TagSupport.EVAL_BODY_INCLUDE);
57 }
58
59 public void testIfIsFalseElseIfIsFalse() throws Exception {
60 stack.getContext().put(If.ANSWER, Boolean.FALSE);
61
62 ElseIfTag tag = new ElseIfTag();
63 tag.setPageContext(pageContext);
64 tag.setTest("false");
65
66 int result = tag.doStartTag();
67 tag.doEndTag();
68
69 assertEquals(result, TagSupport.SKIP_BODY);
70 }
71
72 public void testIfIsTrueElseIfIsTrue() throws Exception {
73 stack.getContext().put(If.ANSWER, Boolean.TRUE);
74
75 ElseIfTag tag = new ElseIfTag();
76 tag.setPageContext(pageContext);
77 tag.setTest("true");
78
79 int result = tag.doStartTag();
80 tag.doEndTag();
81
82 assertEquals(result, TagSupport.SKIP_BODY);
83 }
84
85 public void testIfIsTrueElseIfIsFalse() throws Exception {
86 stack.getContext().put(If.ANSWER, Boolean.TRUE);
87
88 ElseIfTag tag = new ElseIfTag();
89 tag.setPageContext(pageContext);
90 tag.setTest("false");
91
92 int result = tag.doStartTag();
93 tag.doEndTag();
94
95 assertEquals(result, TagSupport.SKIP_BODY);
96 }
97
98
99 protected void setUp() throws Exception {
100 super.setUp();
101 stack = ValueStackFactory.getFactory().createValueStack();
102
103 jspWriter = new MockJspWriter();
104
105 StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
106
107 StrutsMockServletContext servletContext = new StrutsMockServletContext();
108 servletContext.setServletInfo("not-weblogic");
109
110 pageContext = new MockPageContext();
111 pageContext.setJspWriter(jspWriter);
112 pageContext.setRequest(request);
113 pageContext.setServletContext(servletContext);
114
115 request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack);
116 }
117
118
119 }