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