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.html.OptionTag; 16 import com.inversoft.verge.mvc.view.jsp.model.SelectTag; 17 import com.inversoft.verge.util.ScopeConstants; 18 19 20 29 public class SelectTagTest extends JspTestCase { 30 31 35 public SelectTagTest(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 49 FormTag parent = new FormTag(); 50 SelectTag tag = new SelectTag(); 51 tag.setParent(parent); 52 tag.setPageContext(pageContext); 53 tag.setId("test"); 54 tag.setName("test"); 55 tag.setModel("bean.text"); 56 57 try { 58 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 59 String tagStr = getPageContext().getMockOut().getText(); 60 String compStr = "<select id=\"test\" name=\"test\"></select>" + 61 TestTools.createWebLink("bean.text", 62 "com.inversoft.verge.mvc.view.jsp.model.test.Bean", 63 ScopeConstants.REQUEST_INT); 64 65 System.out.println("Select tag: " + tagStr); 66 System.out.println("Compare string: " + compStr); 67 assertEquals("Should be select", tagStr, compStr); 68 } catch (JspException e) { 69 fail(e.toString()); 70 } 71 } 72 73 76 public void testLinkWebEL() { 77 Bean bean = new Bean(); 78 request.setAttribute("bean", bean); 79 pageContext.setAttribute("propertyName", "text"); 81 82 FormTag parent = new FormTag(); 83 SelectTag tag = new SelectTag(); 84 tag.setParent(parent); 85 tag.setPageContext(pageContext); 86 tag.setId("test"); 87 tag.setName("test"); 88 tag.setModel("bean.${propertyName}"); 89 90 try { 91 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 92 String tagStr = getPageContext().getMockOut().getText(); 93 String compStr = "<select id=\"test\" name=\"test\"></select>" + 94 TestTools.createWebLink("bean.text", 95 "com.inversoft.verge.mvc.view.jsp.model.test.Bean", 96 ScopeConstants.REQUEST_INT); 97 98 System.out.println("Select tag: " + tagStr); 99 System.out.println("Compare string: " + compStr); 100 assertEquals("Should be select", tagStr, compStr); 101 } catch (JspException e) { 102 fail(e.toString()); 103 } 104 } 105 106 109 public void testChecked1() { 110 Bean bean = new Bean(); 111 bean.setText("testValue1"); 112 request.setAttribute("bean", bean); 113 115 FormTag parent = new FormTag(); 116 SelectTag tag = new SelectTag(); 117 tag.setParent(parent); 118 tag.setPageContext(pageContext); 119 tag.setId("test"); 120 tag.setName("test"); 121 tag.setModel("bean.text"); 122 123 OptionTag option1 = new OptionTag(); 124 option1.setValue("testValue1"); 125 option1.setParent(tag); 126 option1.setPageContext(pageContext); 127 OptionTag option2 = new OptionTag(); 128 option2.setValue("testValue2"); 129 option2.setParent(tag); 130 option2.setPageContext(pageContext); 131 132 try { 133 assertEquals("Should return EVAL_BODY_INCLUDE", tag.doStartTag(), Tag.EVAL_BODY_INCLUDE); 134 assertEquals("Should return EVAL_PAGE", runTag(option1), Tag.EVAL_PAGE); 135 assertEquals("Should return EVAL_PAGE", runTag(option2), Tag.EVAL_PAGE); 136 assertEquals("Should return SKIP_BODY", tag.doAfterBody(), Tag.SKIP_BODY); 137 assertEquals("Should return EVAL_PAGE", tag.doEndTag(), Tag.EVAL_PAGE); 138 139 String tagStr = getPageContext().getMockOut().getText(); 140 String compStr = 141 "<select id=\"test\" name=\"test\">" + 142 "<option value=\"testValue1\" selected></option>" + 143 "<option value=\"testValue2\"></option>" + 144 "</select>" + 145 TestTools.createWebLink("bean.text", 146 "com.inversoft.verge.mvc.view.jsp.model.test.Bean", 147 ScopeConstants.REQUEST_INT); 148 149 System.out.println("Select tag: " + tagStr); 150 System.out.println("Compare string: " + compStr); 151 assertEquals("Should be select", tagStr, compStr); 152 } catch (JspException e) { 153 fail(e.toString()); 154 } 155 } 156 157 160 public void testNoGet() { 161 Bean bean = new Bean(); 162 bean.setText("testValue1"); 163 request.setAttribute("bean", bean); 164 166 FormTag parent = new FormTag(); 167 SelectTag tag = new SelectTag(); 168 tag.setParent(parent); 169 tag.setPageContext(pageContext); 170 tag.setId("test"); 171 tag.setName("test"); 172 tag.setModel("bean.text"); 173 tag.setGetValue(false); 174 175 OptionTag option1 = new OptionTag(); 176 option1.setValue("testValue1"); 177 option1.setParent(tag); 178 option1.setPageContext(pageContext); 179 OptionTag option2 = new OptionTag(); 180 option2.setValue("testValue2"); 181 option2.setParent(tag); 182 option2.setPageContext(pageContext); 183 184 try { 185 assertEquals("Should return EVAL_BODY_INCLUDE", tag.doStartTag(), Tag.EVAL_BODY_INCLUDE); 186 assertEquals("Should return EVAL_PAGE", runTag(option1), Tag.EVAL_PAGE); 187 assertEquals("Should return EVAL_PAGE", runTag(option2), Tag.EVAL_PAGE); 188 assertEquals("Should return SKIP_BODY", tag.doAfterBody(), Tag.SKIP_BODY); 189 assertEquals("Should return EVAL_PAGE", tag.doEndTag(), Tag.EVAL_PAGE); 190 191 String tagStr = getPageContext().getMockOut().getText(); 192 String compStr = 193 "<select id=\"test\" name=\"test\">" + 194 "<option value=\"testValue1\"></option>" + 195 "<option value=\"testValue2\"></option>" + 196 "</select>" + 197 TestTools.createWebLink("bean.text", 198 "com.inversoft.verge.mvc.view.jsp.model.test.Bean", 199 ScopeConstants.REQUEST_INT); 200 201 System.out.println("Select tag: " + tagStr); 202 System.out.println("Compare string: " + compStr); 203 assertEquals("Should be select", tagStr, compStr); 204 } catch (JspException e) { 205 fail(e.toString()); 206 } 207 } 208 209 212 public void testChecked2() { 213 Bean bean = new Bean(); 214 bean.setText("testValue2"); 215 request.setAttribute("bean", bean); 216 218 FormTag parent = new FormTag(); 219 SelectTag tag = new SelectTag(); 220 tag.setParent(parent); 221 tag.setPageContext(pageContext); 222 tag.setId("test"); 223 tag.setName("test"); 224 tag.setModel("bean.text"); 225 226 OptionTag option1 = new OptionTag(); 227 option1.setValue("testValue1"); 228 option1.setParent(tag); 229 option1.setPageContext(pageContext); 230 OptionTag option2 = new OptionTag(); 231 option2.setValue("testValue2"); 232 option2.setParent(tag); 233 option2.setPageContext(pageContext); 234 235 try { 236 assertEquals("Should return EVAL_BODY_INCLUDE", tag.doStartTag(), Tag.EVAL_BODY_INCLUDE); 237 assertEquals("Should return EVAL_PAGE", runTag(option1), Tag.EVAL_PAGE); 238 assertEquals("Should return EVAL_PAGE", runTag(option2), Tag.EVAL_PAGE); 239 assertEquals("Should return SKIP_BODY", tag.doAfterBody(), Tag.SKIP_BODY); 240 assertEquals("Should return EVAL_PAGE", tag.doEndTag(), Tag.EVAL_PAGE); 241 242 String tagStr = getPageContext().getMockOut().getText(); 243 String compStr = 244 "<select id=\"test\" name=\"test\">" + 245 "<option value=\"testValue1\"></option>" + 246 "<option value=\"testValue2\" selected></option>" + 247 "</select>" + 248 TestTools.createWebLink("bean.text", 249 "com.inversoft.verge.mvc.view.jsp.model.test.Bean", 250 ScopeConstants.REQUEST_INT); 251 252 System.out.println("Select tag: " + tagStr); 253 System.out.println("Compare string: " + compStr); 254 assertEquals("Should be select", tagStr, compStr); 255 } catch (JspException e) { 256 fail(e.toString()); 257 } 258 } 259 260 264 public void testTagReuse() { 265 Bean bean = new Bean(); 266 bean.setText("testValue1"); 267 request.setAttribute("bean", bean); 268 270 FormTag parent = new FormTag(); 271 SelectTag tag = new SelectTag(); 272 tag.setParent(parent); 273 tag.setPageContext(pageContext); 274 tag.setId("test"); 275 tag.setName("test"); 276 tag.setModel("bean.text"); 277 278 OptionTag option1 = new OptionTag(); 279 option1.setValue("testValue1"); 280 option1.setParent(tag); 281 option1.setPageContext(pageContext); 282 OptionTag option2 = new OptionTag(); 283 option2.setValue("testValue2"); 284 option2.setParent(tag); 285 option2.setPageContext(pageContext); 286 287 try { 288 assertEquals("Should return EVAL_BODY_INCLUDE", tag.doStartTag(), Tag.EVAL_BODY_INCLUDE); 289 assertEquals("Should return EVAL_PAGE", runTag(option1), Tag.EVAL_PAGE); 290 assertEquals("Should return EVAL_PAGE", runTag(option2), Tag.EVAL_PAGE); 291 assertEquals("Should return SKIP_BODY", tag.doAfterBody(), Tag.SKIP_BODY); 292 assertEquals("Should return EVAL_PAGE", tag.doEndTag(), Tag.EVAL_PAGE); 293 294 String tagStr = getPageContext().getMockOut().getText(); 295 String compStr = 296 "<select id=\"test\" name=\"test\">" + 297 "<option value=\"testValue1\" selected></option>" + 298 "<option value=\"testValue2\"></option>" + 299 "</select>" + 300 TestTools.createWebLink("bean.text", 301 "com.inversoft.verge.mvc.view.jsp.model.test.Bean", 302 ScopeConstants.REQUEST_INT); 303 304 System.out.println("Select tag: " + tagStr); 305 System.out.println("Compare string: " + compStr); 306 assertEquals("Should be select", tagStr, compStr); 307 } catch (JspException e) { 308 fail(e.toString()); 309 } 310 311 getPageContext().getMockOut().clear(); 313 bean.setText(null); 314 315 try { 316 assertEquals("Should return EVAL_BODY_INCLUDE", tag.doStartTag(), Tag.EVAL_BODY_INCLUDE); 317 assertEquals("Should return EVAL_PAGE", runTag(option1), Tag.EVAL_PAGE); 318 assertEquals("Should return EVAL_PAGE", runTag(option2), Tag.EVAL_PAGE); 319 assertEquals("Should return SKIP_BODY", tag.doAfterBody(), Tag.SKIP_BODY); 320 assertEquals("Should return EVAL_PAGE", tag.doEndTag(), Tag.EVAL_PAGE); 321 322 String tagStr = getPageContext().getMockOut().getText(); 323 String compStr = 324 "<select id=\"test\" name=\"test\">" + 325 "<option value=\"testValue1\"></option>" + 326 "<option value=\"testValue2\"></option>" + 327 "</select>" + 328 TestTools.createWebLink("bean.text", 329 "com.inversoft.verge.mvc.view.jsp.model.test.Bean", 330 ScopeConstants.REQUEST_INT); 331 332 System.out.println("Select tag: " + tagStr); 333 System.out.println("Compare string: " + compStr); 334 assertEquals("Should be select", tagStr, compStr); 335 } catch (JspException e) { 336 fail(e.toString()); 337 } 338 } 339 340 343 public void testNoSet() { 344 Bean bean = new Bean(); 345 bean.setText("testValue1"); 346 request.setAttribute("bean", bean); 347 348 FormTag parent = new FormTag(); 349 SelectTag tag = new SelectTag(); 350 tag.setParent(parent); 351 tag.setPageContext(pageContext); 352 tag.setId("test"); 353 tag.setName("test"); 354 tag.setModel("bean.text"); 355 tag.setSetValue(false); 356 357 OptionTag option1 = new OptionTag(); 358 option1.setValue("testValue1"); 359 option1.setParent(tag); 360 option1.setPageContext(pageContext); 361 OptionTag option2 = new OptionTag(); 362 option2.setValue("testValue2"); 363 option2.setParent(tag); 364 option2.setPageContext(pageContext); 365 366 try { 367 assertEquals("Should return EVAL_BODY_INCLUDE", tag.doStartTag(), Tag.EVAL_BODY_INCLUDE); 368 assertEquals("Should return EVAL_PAGE", runTag(option1), Tag.EVAL_PAGE); 369 assertEquals("Should return EVAL_PAGE", runTag(option2), Tag.EVAL_PAGE); 370 assertEquals("Should return SKIP_BODY", tag.doAfterBody(), Tag.SKIP_BODY); 371 assertEquals("Should return EVAL_PAGE", tag.doEndTag(), Tag.EVAL_PAGE); 372 373 String tagStr = getPageContext().getMockOut().getText(); 374 String compStr = 375 "<select id=\"test\" name=\"test\">" + 376 "<option value=\"testValue1\" selected></option>" + 377 "<option value=\"testValue2\"></option>" + 378 "</select>"; 379 380 System.out.println("Select tag: " + tagStr); 381 System.out.println("Compare string: " + compStr); 382 assertEquals("Should be select", tagStr, compStr); 383 } catch (JspException e) { 384 fail(e.toString()); 385 } 386 } 387 } | Popular Tags |