1 7 package com.inversoft.verge.mvc.view.jsp.model.test; 8 9 10 import javax.servlet.jsp.JspException ; 11 import javax.servlet.jsp.tagext.Tag ; 12 13 import com.inversoft.junit.JspTestCase; 14 import com.inversoft.verge.mvc.view.jsp.html.FormTag; 15 import com.inversoft.verge.mvc.view.jsp.model.PasswordTag; 16 import com.inversoft.verge.util.ScopeConstants; 17 18 19 28 public class PasswordTagTest extends JspTestCase { 29 30 35 public PasswordTagTest(String name) { 36 super(name); 37 setLocal(true); 38 } 39 40 41 44 public void testLinkWeb() { 45 Bean bean = new Bean(); 46 request.setAttribute("bean", bean); 47 48 FormTag parent = new FormTag(); 49 PasswordTag tag = new PasswordTag(); 50 tag.setParent(parent); 51 tag.setPageContext(pageContext); 52 tag.setId("test"); 53 tag.setName("test"); 54 tag.setModel("bean.text"); 55 56 try { 57 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 58 String tagStr = getPageContext().getMockOut().getText(); 59 String compStr = "<input type=\"password\" id=\"test\" name=\"test\"/>" + 60 TestTools.createWebLink("bean.text", 61 "com.inversoft.verge.mvc.view.jsp.model.test.Bean", 62 ScopeConstants.REQUEST_INT); 63 64 System.out.println("Password tag: " + tagStr); 65 System.out.println("Compare string: " + compStr); 66 assertEquals("Should be password", tagStr, compStr); 67 } catch (JspException e) { 68 fail(e.toString()); 69 } 70 } 71 72 75 public void testLinkWebEL() { 76 Bean bean = new Bean(); 77 request.setAttribute("bean", bean); 78 pageContext.setAttribute("propertyName", "text"); 79 80 FormTag parent = new FormTag(); 81 PasswordTag tag = new PasswordTag(); 82 tag.setParent(parent); 83 tag.setPageContext(pageContext); 84 tag.setId("test"); 85 tag.setName("test"); 86 tag.setModel("bean.${propertyName}"); 87 88 try { 89 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 90 String tagStr = getPageContext().getMockOut().getText(); 91 String compStr = "<input type=\"password\" id=\"test\" name=\"test\"/>" + 92 TestTools.createWebLink("bean.text", 93 "com.inversoft.verge.mvc.view.jsp.model.test.Bean", 94 ScopeConstants.REQUEST_INT); 95 96 System.out.println("Password tag: " + tagStr); 97 System.out.println("Compare string: " + compStr); 98 assertEquals("Should be password", tagStr, compStr); 99 } catch (JspException e) { 100 fail(e.toString()); 101 } 102 } 103 104 107 public void testELFailure() { 108 Bean bean = new Bean(); 109 request.setAttribute("bean", bean); 110 pageContext.setAttribute("propertyName", "text"); 112 113 FormTag parent = new FormTag(); 114 PasswordTag tag = new PasswordTag(); 115 tag.setParent(parent); 116 tag.setPageContext(pageContext); 117 tag.setId("test"); 118 tag.setName("test"); 119 tag.setModel("bean.${wrongEL}"); 120 121 try { 122 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 123 fail("Should have failed because EL is wrong"); 124 } catch (JspException e) { 125 System.out.println("Excpetion: " + e.toString()); 126 } 127 } 128 129 132 public void testValueSupression() { 133 Bean bean = new Bean(); 134 bean.setText("testValue"); 135 request.setAttribute("bean", bean); 136 138 FormTag parent = new FormTag(); 139 PasswordTag tag = new PasswordTag(); 140 tag.setParent(parent); 141 tag.setPageContext(pageContext); 142 tag.setId("test"); 143 tag.setName("test"); 144 tag.setModel("bean.text"); 145 tag.setGetValue(false); 146 147 try { 148 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 149 String tagStr = getPageContext().getMockOut().getText(); 150 String compStr = "<input type=\"password\" id=\"test\" name=\"test\"/>" + 151 TestTools.createWebLink("bean.text", 152 "com.inversoft.verge.mvc.view.jsp.model.test.Bean", 153 ScopeConstants.REQUEST_INT); 154 155 System.out.println("Password tag: " + tagStr); 156 System.out.println("Compare string: " + compStr); 157 assertEquals("Should be password", tagStr, compStr); 158 } catch (JspException e) { 159 fail(e.toString()); 160 } 161 } 162 163 166 public void testValue() { 167 Bean bean = new Bean(); 168 bean.setText("testValue"); 169 request.setAttribute("bean", bean); 170 172 FormTag parent = new FormTag(); 173 PasswordTag tag = new PasswordTag(); 174 tag.setParent(parent); 175 tag.setPageContext(pageContext); 176 tag.setId("test"); 177 tag.setName("test"); 178 tag.setModel("bean.text"); 179 tag.setShowPassword(true); 180 181 try { 182 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 183 String tagStr = getPageContext().getMockOut().getText(); 184 String compStr = "<input type=\"password\" id=\"test\" name=\"test\" value=\"testValue\"/>" + 185 TestTools.createWebLink("bean.text", 186 "com.inversoft.verge.mvc.view.jsp.model.test.Bean", 187 ScopeConstants.REQUEST_INT); 188 189 System.out.println("Password tag: " + tagStr); 190 System.out.println("Compare string: " + compStr); 191 assertEquals("Should be password", tagStr, compStr); 192 } catch (JspException e) { 193 fail(e.toString()); 194 } 195 } 196 197 200 public void testTagReuse() { 201 Bean bean = new Bean(); 202 bean.setText("testValue"); 203 request.setAttribute("bean", bean); 204 205 FormTag parent = new FormTag(); 206 PasswordTag tag = new PasswordTag(); 207 tag.setParent(parent); 208 tag.setPageContext(pageContext); 209 tag.setId("test"); 210 tag.setName("test"); 211 tag.setModel("bean.text"); 212 tag.setGetValue(false); 213 214 try { 215 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 216 String tagStr = getPageContext().getMockOut().getText(); 217 String compStr = "<input type=\"password\" id=\"test\" name=\"test\"/>" + 218 TestTools.createWebLink("bean.text", 219 "com.inversoft.verge.mvc.view.jsp.model.test.Bean", 220 ScopeConstants.REQUEST_INT); 221 222 System.out.println("Password tag: " + tagStr); 223 System.out.println("Compare string: " + compStr); 224 assertEquals("Should be password", tagStr, compStr); 225 } catch (JspException e) { 226 fail(e.toString()); 227 } 228 229 getPageContext().getMockOut().clear(); 231 232 try { 233 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 234 String tagStr = getPageContext().getMockOut().getText(); 235 String compStr = "<input type=\"password\" id=\"test\" name=\"test\"/>" + 236 TestTools.createWebLink("bean.text", 237 "com.inversoft.verge.mvc.view.jsp.model.test.Bean", 238 ScopeConstants.REQUEST_INT); 239 240 System.out.println("Password tag: " + tagStr); 241 System.out.println("Compare string: " + compStr); 242 assertEquals("Should be password", tagStr, compStr); 243 } catch (JspException e) { 244 fail(e.toString()); 245 } 246 } 247 248 251 public void testNoSet() { 252 Bean bean = new Bean(); 253 bean.setText("testValue"); 254 request.setAttribute("bean", bean); 255 256 FormTag parent = new FormTag(); 257 PasswordTag tag = new PasswordTag(); 258 tag.setParent(parent); 259 tag.setPageContext(pageContext); 260 tag.setId("test"); 261 tag.setName("test"); 262 tag.setModel("bean.text"); 263 tag.setGetValue(false); 264 tag.setSetValue(false); 265 266 try { 267 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 268 String tagStr = getPageContext().getMockOut().getText(); 269 String compStr = "<input type=\"password\" id=\"test\" name=\"test\"/>"; 270 271 System.out.println("Password tag: " + tagStr); 272 System.out.println("Compare string: " + compStr); 273 assertEquals("Should be password", tagStr, compStr); 274 } catch (JspException e) { 275 fail(e.toString()); 276 } 277 } 278 } | Popular Tags |