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.TestHelper; 32 33 34 public class TestELCancelTag 35 extends JspTagTestCase { 36 37 protected static final String PROPERTY_ATTR_VALUE = "stuff"; 38 protected static final String REQUIRED_DISABLED_VALUE_KEY = 39 "RequiredDisabledValue"; 40 protected static final String REQUIRED_TYPE_VALUE_KEY = 41 "RequiredTypeValue"; 42 protected static final String REQUIRED_VALUE_VALUE_KEY = 43 "RequiredValueValue"; 44 protected static final String REQUIRED_NAME_VALUE_KEY = 45 "RequiredNameValue"; 46 protected ELCancelTag elCancelTag = null; 47 48 public TestELCancelTag(String theName) { 49 super(theName); 50 } 51 52 public static void main(String [] args) { 53 junit.awtui.TestRunner.main( 54 new String [] { TestELCancelTag.class.getName() }); 55 } 56 57 public static Test suite() { 58 return new TestSuite(TestELCancelTag.class); 59 } 60 61 public void setUp() { 62 elCancelTag = new ELCancelTag(); 63 elCancelTag.setPageContext(pageContext); 64 elCancelTag.setPropertyExpr(PROPERTY_ATTR_VALUE); 65 } 66 67 public void tearDown() { 68 elCancelTag = null; 69 } 70 71 74 public void testPlain() 75 throws ServletException , JspException { 76 HttpServletResponse response = (HttpServletResponse )pageContext.getResponse(); 77 78 String requiredNameValue = PROPERTY_ATTR_VALUE; 79 response.addHeader(REQUIRED_NAME_VALUE_KEY, requiredNameValue); 80 String requiredTypeValue = "submit"; 81 response.addHeader(REQUIRED_TYPE_VALUE_KEY, requiredTypeValue); 82 83 String requiredValueValue = "Cancel"; 84 response.addHeader(REQUIRED_VALUE_VALUE_KEY, requiredValueValue); 85 86 int startTagReturn = elCancelTag.doStartTag(); 87 int afterBodyReturn = elCancelTag.doAfterBody(); 88 int endTagReturn = elCancelTag.doEndTag(); 89 } 90 91 public void endPlain(com.meterware.httpunit.WebResponse testResponse) { 92 try { 93 TestHelper.printResponse(testResponse); 94 95 org.w3c.dom.Document document = testResponse.getDOM(); 96 DOMHelper.printNode(document.getDocumentElement()); 97 98 HashMap attrMap = new HashMap (); 99 DOMHelper.recordFoundAttributes(testResponse.getDOM(), 100 "/html/body/input", attrMap); 101 DOMHelper.verifyAttributesPresent(attrMap, 102 new String [] { 103 "name", "type", "value", "onclick" }, 104 false); 105 106 checkAttrValue(attrMap, testResponse, REQUIRED_NAME_VALUE_KEY, 107 "cancel", "name"); 108 checkAttrValue(attrMap, testResponse, REQUIRED_TYPE_VALUE_KEY, 109 "cancel", "type"); 110 checkAttrValue(attrMap, testResponse, REQUIRED_VALUE_VALUE_KEY, 111 "cancel", "value"); 112 } catch (Exception ex) { 113 ex.printStackTrace(); 114 fail(); 115 } 116 } 117 118 121 public void testDisabled() 122 throws ServletException , JspException { 123 124 elCancelTag.setDisabledExpr("true"); 125 126 String requiredDisabledValue = "disabled"; 127 response.addHeader(REQUIRED_DISABLED_VALUE_KEY, requiredDisabledValue); 128 129 int startTagReturn = elCancelTag.doStartTag(); 130 int afterBodyReturn = elCancelTag.doAfterBody(); 131 int endTagReturn = elCancelTag.doEndTag(); 132 } 133 134 public void endDisabled(com.meterware.httpunit.WebResponse testResponse) { 135 try { 136 TestHelper.printResponse(testResponse); 137 138 org.w3c.dom.Document document = testResponse.getDOM(); 139 DOMHelper.printNode(document.getDocumentElement()); 140 141 HashMap attrMap = new HashMap (); 142 DOMHelper.recordFoundAttributes(testResponse.getDOM(), 143 "/html/body/input", attrMap); 144 DOMHelper.verifyAttributesPresent(attrMap, 145 new String [] { "disabled" }, 146 true); 147 checkAttrValue(attrMap, testResponse, REQUIRED_DISABLED_VALUE_KEY, 148 "cancel", "disabled"); 149 } catch (Exception ex) { 150 ex.printStackTrace(); 151 fail(); 152 } 153 } 154 } 155 | Popular Tags |