1 18 19 package org.apache.strutsel.taglib.html; 20 21 import java.util.HashMap ; 22 23 import javax.servlet.ServletException ; 24 import javax.servlet.http.HttpServletResponse ; 25 import javax.servlet.jsp.JspException ; 26 import junit.framework.Test; 27 import junit.framework.TestSuite; 28 29 import org.apache.strutsel.taglib.utils.DOMHelper; 30 import org.apache.strutsel.taglib.utils.JspTagTestCase; 31 import org.apache.strutsel.taglib.utils.TestFormBean; 32 import org.apache.strutsel.taglib.utils.TestHelper; 33 34 public class TestELCheckboxTag 35 extends JspTagTestCase { 36 protected static final String PROPERTY_ATTR_VALUE = 37 "stringProperty"; 38 protected static final String REQUIRED_CHECKED_VALUE_KEY = 39 "RequiredCheckedValue"; 40 protected static final String REQUIRED_DISABLED_VALUE_KEY = 41 "RequiredDisabledValue"; 42 protected static final String REQUIRED_NAME_VALUE_KEY = 43 "RequiredNameValue"; 44 protected static final String REQUIRED_TYPE_VALUE_KEY = 45 "RequiredTypeValue"; 46 protected static final String REQUIRED_VALUE_VALUE_KEY = 47 "RequiredValueValue"; 48 protected ELCheckboxTag elCheckboxTag = null; 49 50 public TestELCheckboxTag(String theName) { 51 super(theName); 52 } 53 54 public static void main(String [] args) { 55 junit.awtui.TestRunner.main( 56 new String [] { TestELCheckboxTag.class.getName() }); 57 } 58 59 public static Test suite() { 60 return new TestSuite(TestELCheckboxTag.class); 61 } 62 63 public void setUp() { 64 elCheckboxTag = new ELCheckboxTag(); 65 elCheckboxTag.setPageContext(pageContext); 66 elCheckboxTag.setPropertyExpr(PROPERTY_ATTR_VALUE); 67 } 68 69 public void tearDown() { 70 elCheckboxTag = null; 71 } 72 73 77 public void testPlain() 78 throws ServletException , JspException { 79 HttpServletResponse response = (HttpServletResponse )pageContext.getResponse(); 80 String requiredNameValue = PROPERTY_ATTR_VALUE; 81 response.addHeader(REQUIRED_NAME_VALUE_KEY, requiredNameValue); 82 83 String requiredTypeValue = "checkbox"; 84 response.addHeader(REQUIRED_TYPE_VALUE_KEY, requiredTypeValue); 85 86 String requiredValueValue = "on"; 87 response.addHeader(REQUIRED_VALUE_VALUE_KEY, requiredValueValue); 88 89 TestFormBean formBean = new TestFormBean(); 90 pageContext.setAttribute("testFormBean", formBean); 91 92 elCheckboxTag.setNameExpr("testFormBean"); 93 94 int startTagReturn = elCheckboxTag.doStartTag(); 95 int afterBodyReturn = elCheckboxTag.doAfterBody(); 96 int endTagReturn = elCheckboxTag.doEndTag(); 97 } 98 99 public void endPlain(com.meterware.httpunit.WebResponse testResponse) { 100 try { 101 TestHelper.printResponse(testResponse); 102 DOMHelper.printNode(testResponse.getDOM().getDocumentElement()); 103 104 HashMap attrMap = new HashMap (); 105 DOMHelper.recordFoundAttributes(testResponse.getDOM(), 106 "/html/body/input", attrMap); 107 DOMHelper.verifyAttributesPresent(attrMap, 108 new String [] { 109 "name", "type", "value" 110 }, false); 111 checkAttrValue(attrMap, testResponse, REQUIRED_NAME_VALUE_KEY, 112 "checkbox", "name"); 113 checkAttrValue(attrMap, testResponse, REQUIRED_TYPE_VALUE_KEY, 114 "checkbox", "type"); 115 checkAttrValue(attrMap, testResponse, REQUIRED_VALUE_VALUE_KEY, 116 "checkbox", "value"); 117 } catch (Exception ex) { 118 ex.printStackTrace(); 119 fail(); 120 } 121 } 122 123 132 135 138 141 144 150 155 159 162 183 193 196 199 202 208 213 217 220 241 247 249 253 258 262 265 279 289 292 295 300 305 309 312 320 } 334 | Popular Tags |