1 7 package com.inversoft.verge.mvc.view.jsp.html.test; 8 9 10 import javax.servlet.jsp.JspException ; 11 import javax.servlet.jsp.tagext.Tag ; 12 13 import com.inversoft.junit.AutoJspTestCallback; 14 import com.inversoft.junit.JspTestCallback; 15 import com.inversoft.junit.JspTestCase; 16 import com.inversoft.verge.mvc.view.jsp.html.FormTag; 17 import com.inversoft.verge.mvc.view.jsp.html.OptionTag; 18 import com.inversoft.verge.mvc.view.jsp.html.SelectTag; 19 20 21 30 public class OptionTagTest extends JspTestCase { 31 32 36 public OptionTagTest(String name) { 37 super(name); 38 setLocal(true); 39 } 40 41 42 45 public void testValue() { 46 SelectTag parent = new SelectTag(); 47 OptionTag tag = new OptionTag(); 48 tag.setParent(parent); 49 tag.setPageContext(pageContext); 50 tag.setValue("test"); 51 52 try { 53 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 54 String tagStr = getPageContext().getMockOut().getText(); 55 56 System.out.println("Option tag: " + tagStr); 57 assertEquals("Should be option tag", tagStr, 58 "<option value=\"test\"></option>"); 59 } catch (JspException e) { 60 fail(e.toString()); 61 } 62 } 63 64 67 public void testSelected() { 68 SelectTag parent = new SelectTag(); 69 OptionTag tag = new OptionTag(); 70 tag.setParent(parent); 71 tag.setPageContext(pageContext); 72 tag.setValue("test"); 73 tag.setSelected(Boolean.TRUE); 74 75 try { 76 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 77 String tagStr = getPageContext().getMockOut().getText(); 78 79 System.out.println("Option tag: " + tagStr); 80 assertEquals("Should be option tag", tagStr, 81 "<option value=\"test\" selected></option>"); 82 } catch (JspException e) { 83 fail(e.toString()); 84 } 85 } 86 87 90 public void testDisabled() { 91 SelectTag parent = new SelectTag(); 92 OptionTag tag = new OptionTag(); 93 tag.setParent(parent); 94 tag.setPageContext(pageContext); 95 tag.setValue("test"); 96 tag.setDisabled(Boolean.TRUE); 97 98 try { 99 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 100 String tagStr = getPageContext().getMockOut().getText(); 101 102 System.out.println("Option tag: " + tagStr); 103 assertEquals("Should be option tag", tagStr, 104 "<option value=\"test\" disabled></option>"); 105 } catch (JspException e) { 106 fail(e.toString()); 107 } 108 } 109 110 114 public void testSelectValue() { 115 FormTag form = new FormTag(); 116 SelectTag parent = new SelectTag(); 117 parent.setParent(form); 118 parent.setName("sel"); 119 parent.setValue("test"); 120 parent.setPageContext(pageContext); 121 OptionTag tag = new OptionTag(); 122 tag.setParent(parent); 123 tag.setPageContext(pageContext); 124 tag.setValue("test"); 125 126 JspTestCallback callback = new AutoJspTestCallback(new Tag []{tag}); 127 try { 128 assertEquals("Should return EVAL_PAGE", runTag(parent, callback), 129 Tag.EVAL_PAGE); 130 String tagStr = getPageContext().getMockOut().getText(); 131 String expected = "<select name=\"sel\"><option value=\"test\" selected></option></select>"; 132 133 System.out.println("Option tag: " + tagStr); 134 assertEquals(expected, tagStr); 135 } catch (JspException e) { 136 fail(e.toString()); 137 } 138 } 139 140 144 public void testSelectValueEL() { 145 pageContext.setAttribute("someValue", "test"); 146 147 FormTag form = new FormTag(); 148 SelectTag parent = new SelectTag(); 149 parent.setParent(form); 150 parent.setName("sel"); 151 parent.setValue("${someValue}"); 152 parent.setPageContext(pageContext); 153 OptionTag tag = new OptionTag(); 154 tag.setParent(parent); 155 tag.setPageContext(pageContext); 156 tag.setValue("test"); 157 158 JspTestCallback callback = new AutoJspTestCallback(new Tag []{tag}); 159 try { 160 assertEquals("Should return EVAL_PAGE", runTag(parent, callback), 161 Tag.EVAL_PAGE); 162 String tagStr = getPageContext().getMockOut().getText(); 163 String expected = "<select name=\"sel\"><option value=\"test\" selected></option></select>"; 164 165 System.out.println("Option tag: " + tagStr); 166 assertEquals(expected, tagStr); 167 } catch (JspException e) { 168 fail(e.toString()); 169 } 170 } 171 172 175 public void testLabel() { 176 SelectTag parent = new SelectTag(); 177 OptionTag tag = new OptionTag(); 178 tag.setParent(parent); 179 tag.setPageContext(pageContext); 180 tag.setValue("test"); 181 tag.setLabel("testLabel"); 182 183 try { 184 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 185 String tagStr = getPageContext().getMockOut().getText(); 186 187 System.out.println("Option tag: " + tagStr); 188 assertEquals("Should be option tag", tagStr, 189 "<option value=\"test\" label=\"testLabel\"></option>"); 190 } catch (JspException e) { 191 fail(e.toString()); 192 } 193 } 194 } | Popular Tags |