1 5 package com.opensymphony.webwork.views.jsp; 6 7 import com.mockobjects.servlet.MockHttpServletRequest; 8 import com.mockobjects.servlet.MockJspWriter; 9 import com.mockobjects.servlet.MockPageContext; 10 import com.opensymphony.xwork.ActionContext; 11 import com.opensymphony.xwork.util.OgnlValueStack; 12 import junit.framework.TestCase; 13 14 import javax.servlet.jsp.JspException ; 15 16 17 21 public class PropertyTagTest extends TestCase { 22 24 MockHttpServletRequest request = new MockHttpServletRequest(); 25 OgnlValueStack stack = new OgnlValueStack(); 26 27 29 public void testDefaultValue() { 30 PropertyTag tag = new PropertyTag(); 31 32 Foo foo = new Foo(); 33 34 stack.push(foo); 35 36 MockJspWriter jspWriter = new MockJspWriter(); 37 jspWriter.setExpectedData("TEST"); 38 39 MockPageContext pageContext = new MockPageContext(); 40 pageContext.setJspWriter(jspWriter); 41 pageContext.setRequest(request); 42 43 tag.setPageContext(pageContext); 44 tag.setValue("title"); 45 tag.setDefault("TEST"); 46 47 try { 48 tag.doStartTag(); 49 } catch (JspException e) { 50 e.printStackTrace(); 51 fail(); 52 } 53 54 request.verify(); 55 jspWriter.verify(); 56 pageContext.verify(); 57 } 58 59 public void testNull() { 60 PropertyTag tag = new PropertyTag(); 61 62 Foo foo = new Foo(); 63 64 stack.push(foo); 65 66 MockJspWriter jspWriter = new MockJspWriter(); 67 jspWriter.setExpectedData(""); 68 69 MockPageContext pageContext = new MockPageContext(); 70 pageContext.setJspWriter(jspWriter); 71 pageContext.setRequest(request); 72 73 tag.setPageContext(pageContext); 74 tag.setValue("title"); 75 76 try { 77 tag.doStartTag(); 78 } catch (JspException e) { 79 e.printStackTrace(); 80 fail(); 81 } 82 83 request.verify(); 84 jspWriter.verify(); 85 pageContext.verify(); 86 } 87 88 public void testSimple() { 89 PropertyTag tag = new PropertyTag(); 90 91 Foo foo = new Foo(); 92 foo.setTitle("test"); 93 94 stack.push(foo); 95 96 MockJspWriter jspWriter = new MockJspWriter(); 97 jspWriter.setExpectedData("test"); 98 99 MockPageContext pageContext = new MockPageContext(); 100 pageContext.setJspWriter(jspWriter); 101 pageContext.setRequest(request); 102 103 tag.setPageContext(pageContext); 104 tag.setValue("title"); 105 106 try { 107 tag.doStartTag(); 108 } catch (JspException e) { 109 e.printStackTrace(); 110 fail(); 111 } 112 113 request.verify(); 114 jspWriter.verify(); 115 pageContext.verify(); 116 } 117 118 public void testTopOfStack() { 119 PropertyTag tag = new PropertyTag(); 120 121 Foo foo = new Foo(); 122 foo.setTitle("test"); 123 124 stack.push(foo); 125 126 MockJspWriter jspWriter = new MockJspWriter(); 127 jspWriter.setExpectedData("Foo is: test"); 128 129 MockPageContext pageContext = new MockPageContext(); 130 pageContext.setJspWriter(jspWriter); 131 pageContext.setRequest(request); 132 133 tag.setPageContext(pageContext); 134 135 try { 136 tag.doStartTag(); 137 } catch (JspException e) { 138 e.printStackTrace(); 139 fail(); 140 } 141 142 request.verify(); 143 jspWriter.verify(); 144 pageContext.verify(); 145 } 146 147 protected void setUp() throws Exception { 148 ActionContext.getContext().setValueStack(stack); 149 request.setupGetAttribute(stack); 150 } 151 152 154 public class Foo { 155 private String title; 156 157 public void setTitle(String title) { 158 this.title = title; 159 } 160 161 public String getTitle() { 162 return title; 163 } 164 165 public String toString() { 166 return "Foo is: " + title; 167 } 168 } 169 } 170 | Popular Tags |