1 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 ; 14 import javax.servlet.jsp.tagext.TagSupport ; 15 16 17 21 public class ElseTagTest extends TestCase { 22 24 ElseTag elseTag; 25 MockPageContext pageContext; 26 OgnlValueStack stack; 27 28 30 public void testTestFalse() { 31 pageContext.setAttribute(IfTag.ANSWER, new Boolean (false)); 32 elseTag.setPageContext(pageContext); 33 34 int result = 0; 35 36 try { 37 result = elseTag.doStartTag(); 38 elseTag.doEndTag(); 39 } catch (JspException 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 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 (true)); 64 elseTag.setPageContext(pageContext); 65 66 int result = 0; 67 68 try { 69 result = elseTag.doStartTag(); 70 } catch (JspException e) { 71 e.printStackTrace(); 72 fail(); 73 } 74 75 assertEquals(TagSupport.SKIP_BODY, result); 76 } 77 78 protected void setUp() throws Exception { 79 elseTag = new ElseTag(); 81 stack = new OgnlValueStack(); 82 83 MockHttpServletRequest request = new MockHttpServletRequest(); 85 ActionContext.getContext().setValueStack(stack); 86 87 pageContext = new WebWorkMockPageContext(); 89 pageContext.setRequest(request); 90 } 91 92 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 |