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.struts.util.LabelValueBean; 30 import org.apache.strutsel.taglib.utils.DOMHelper; 31 import org.apache.strutsel.taglib.utils.JspTagTestCase; 32 import org.apache.strutsel.taglib.utils.TestHelper; 33 34 35 public class TestELButtonTag 36 extends JspTagTestCase { 37 protected static final String REQUIRED_DISABLED_VALUE_KEY = 38 "RequiredDisabledValue"; 39 protected static final String REQUIRED_TYPE_VALUE_KEY = 40 "RequiredTypeValue"; 41 protected static final String REQUIRED_VALUE_VALUE_KEY = 42 "RequiredValueValue"; 43 protected ELButtonTag elButtonTag = null; 44 45 protected static String [] eventHandlers = 46 { 47 "onblur", "onchange", "onclick", "ondblclick", "onfocus", "onkeydown", 48 "onkeypress", "onkeyup", "onmousedown", "onmousemove", "onmouseout", 49 "onmouseover", "onmouseup" 50 }; 51 52 public TestELButtonTag(String theName) { 53 super(theName); 54 } 55 56 public static void main(String [] args) { 57 junit.awtui.TestRunner.main( 58 new String [] { TestELButtonTag.class.getName() }); 59 } 60 61 public static Test suite() { 62 return new TestSuite(TestELButtonTag.class); 63 } 64 65 public void setUp() { 66 elButtonTag = new ELButtonTag(); 67 elButtonTag.setPageContext(pageContext); 68 } 69 70 public void tearDown() { 71 elButtonTag = null; 72 } 73 74 77 public void testPlain() 78 throws ServletException , JspException { 79 HttpServletResponse response = 80 (HttpServletResponse )pageContext.getResponse(); 81 String requiredTypeValue = "button"; 82 response.addHeader(REQUIRED_TYPE_VALUE_KEY, requiredTypeValue); 83 84 String requiredValueValue = "Click"; 85 response.addHeader(REQUIRED_VALUE_VALUE_KEY, requiredValueValue); 86 87 int startTagReturn = elButtonTag.doStartTag(); 88 int afterBodyReturn = elButtonTag.doAfterBody(); 89 int endTagReturn = elButtonTag.doEndTag(); 90 } 91 92 public void endPlain(com.meterware.httpunit.WebResponse testResponse) { 93 try { 94 TestHelper.printResponse(testResponse); 95 96 org.w3c.dom.Document document = testResponse.getDOM(); 97 DOMHelper.printNode(document.getDocumentElement()); 98 99 HashMap attrMap = new HashMap (); 100 DOMHelper.recordFoundAttributes(testResponse.getDOM(), 101 "/html/body/input", attrMap); 102 DOMHelper.verifyAttributesPresent(attrMap, 103 new String [] { "type", "value" }, 104 false); 105 checkAttrValue(attrMap, testResponse, REQUIRED_TYPE_VALUE_KEY, 106 "button", "type"); 107 checkAttrValue(attrMap, testResponse, REQUIRED_VALUE_VALUE_KEY, 108 "button", "value"); 109 } catch (Exception ex) { 110 ex.printStackTrace(); 111 fail(); 112 } 113 } 114 115 118 public void testDisabled() 119 throws ServletException , JspException { 120 121 elButtonTag.setDisabledExpr("true"); 122 123 String requiredDisabledValue = "disabled"; 124 response.addHeader(REQUIRED_DISABLED_VALUE_KEY, requiredDisabledValue); 125 126 int startTagReturn = elButtonTag.doStartTag(); 127 int afterBodyReturn = elButtonTag.doAfterBody(); 128 int endTagReturn = elButtonTag.doEndTag(); 129 } 130 131 public void endDisabled(com.meterware.httpunit.WebResponse testResponse) { 132 try { 133 TestHelper.printResponse(testResponse); 134 135 org.w3c.dom.Document document = testResponse.getDOM(); 136 DOMHelper.printNode(document.getDocumentElement()); 137 138 HashMap attrMap = new HashMap (); 139 DOMHelper.recordFoundAttributes(testResponse.getDOM(), 140 "/html/body/input", attrMap); 141 DOMHelper.verifyAttributesPresent(attrMap, 142 new String [] { "disabled" }, 143 true); 144 checkAttrValue(attrMap, testResponse, REQUIRED_DISABLED_VALUE_KEY, 145 "button", "disabled"); 146 } catch (Exception ex) { 147 ex.printStackTrace(); 148 fail(); 149 } 150 } 151 152 public void testEventHandlers() 153 throws ServletException , JspException 154 { 155 LabelValueBean bean = new LabelValueBean("junk", "stuff"); 156 pageContext.setAttribute("testFormBean", bean); 157 158 String expr = "${" + "testFormBean.value" + "}"; 159 160 elButtonTag.setOnblurExpr(expr); 161 elButtonTag.setOnchangeExpr(expr); 162 elButtonTag.setOnclickExpr(expr); 163 elButtonTag.setOndblclickExpr(expr); 164 elButtonTag.setOnfocusExpr(expr); 165 elButtonTag.setOnkeydownExpr(expr); 166 elButtonTag.setOnkeypressExpr(expr); 167 elButtonTag.setOnkeyupExpr(expr); 168 elButtonTag.setOnmousedownExpr(expr); 169 elButtonTag.setOnmousemoveExpr(expr); 170 elButtonTag.setOnmouseoutExpr(expr); 171 elButtonTag.setOnmouseoverExpr(expr); 172 elButtonTag.setOnmouseupExpr(expr); 173 174 int startTagReturn = elButtonTag.doStartTag(); 175 int afterBodyReturn = elButtonTag.doAfterBody(); 176 int endTagReturn = elButtonTag.doEndTag(); 177 } 178 179 public void 180 endEventHandlers(com.meterware.httpunit.WebResponse testResponse) { 181 try { 182 TestHelper.printResponse(testResponse); 183 184 org.w3c.dom.Document document = testResponse.getDOM(); 185 DOMHelper.printNode(document.getDocumentElement()); 186 187 HashMap attrMap = new HashMap (); 188 DOMHelper.recordFoundAttributes(testResponse.getDOM(), 189 "/html/body/input", attrMap); 190 DOMHelper.verifyAttributesPresent(attrMap, eventHandlers, true); 191 for (int ctr = 0; ctr < eventHandlers.length; ++ ctr) { 192 if (!((String ) attrMap.get(eventHandlers[ctr])). 193 equals("stuff")) { 194 fail(); 195 } 196 } 197 198 } catch (Exception ex) { 199 ex.printStackTrace(); 200 fail(); 201 } 202 } 203 } 204 | Popular Tags |