KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > views > jsp > ElseTagTest


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork.views.jsp;
6
7 import com.mockobjects.servlet.MockHttpServletRequest;
8 import com.mockobjects.servlet.MockPageContext;
9 import com.opensymphony.xwork.ActionContext;
10 import com.opensymphony.xwork.util.OgnlValueStack;
11 import junit.framework.TestCase;
12
13 import javax.servlet.jsp.JspException JavaDoc;
14 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
15
16
17 /**
18  * @author $Author: jcarreira $
19  * @version $Revision: 1.6 $
20  */

21 public class ElseTagTest extends TestCase {
22     //~ Instance fields ////////////////////////////////////////////////////////
23

24     ElseTag elseTag;
25     MockPageContext pageContext;
26     OgnlValueStack stack;
27
28     //~ Methods ////////////////////////////////////////////////////////////////
29

30     public void testTestFalse() {
31         pageContext.setAttribute(IfTag.ANSWER, new Boolean JavaDoc(false));
32         elseTag.setPageContext(pageContext);
33
34         int result = 0;
35
36         try {
37             result = elseTag.doStartTag();
38             elseTag.doEndTag();
39         } catch (JspException JavaDoc e) {
40             e.printStackTrace();
41             fail();
42         }
43
44         assertEquals(TagSupport.EVAL_BODY_INCLUDE, result);
45     }
46
47     public void testTestNull() {
48         elseTag.setPageContext(pageContext);
49
50         int result = 0;
51
52         try {
53             result = elseTag.doStartTag();
54         } catch (JspException JavaDoc e) {
55             e.printStackTrace();
56             fail();
57         }
58
59         assertEquals(TagSupport.SKIP_BODY, result);
60     }
61
62     public void testTestTrue() {
63         pageContext.setAttribute(IfTag.ANSWER, new Boolean JavaDoc(true));
64         elseTag.setPageContext(pageContext);
65
66         int result = 0;
67
68         try {
69             result = elseTag.doStartTag();
70         } catch (JspException JavaDoc e) {
71             e.printStackTrace();
72             fail();
73         }
74
75         assertEquals(TagSupport.SKIP_BODY, result);
76     }
77
78     protected void setUp() throws Exception JavaDoc {
79         // create the needed objects
80
elseTag = new ElseTag();
81         stack = new OgnlValueStack();
82
83         // create the mock http servlet request
84
MockHttpServletRequest request = new MockHttpServletRequest();
85         ActionContext.getContext().setValueStack(stack);
86
87         // create the mock page context
88
pageContext = new WebWorkMockPageContext();
89         pageContext.setRequest(request);
90     }
91
92     //~ Inner Classes //////////////////////////////////////////////////////////
93

94     class Foo {
95         int num;
96
97         public void setNum(int num) {
98             this.num = num;
99         }
100
101         public int getNum() {
102             return num;
103         }
104     }
105 }
106
Popular Tags