1 package com.tonbeller.wcf.web; 2 3 import java.io.IOException ; 4 5 import javax.xml.transform.TransformerException ; 6 7 import org.jaxen.JaxenException; 8 import org.xml.sax.SAXException ; 9 10 import com.meterware.httpunit.GetMethodWebRequest; 11 import com.meterware.httpunit.HttpUnitOptions; 12 import com.meterware.httpunit.WebForm; 13 import com.meterware.httpunit.WebLink; 14 import com.meterware.httpunit.WebResponse; 15 16 public class FormTest extends HttpUnitTestCase { 17 18 public FormTest(String arg0) { 19 super(arg0); 20 HttpUnitOptions.setExceptionsThrownOnScriptError(false); 21 HttpUnitOptions.setScriptingEnabled(false); 22 } 23 24 private void check(String name) throws JaxenException, IOException , SAXException , TransformerException { 25 utils.check(name, "/com/tonbeller/wcf/web/form.xsl", "form01"); 26 } 27 28 32 public void testCharEnc() throws Exception { 33 wc.setHeaderField("accept-charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); 34 GetMethodWebRequest req = new GetMethodWebRequest(servletUrl + "/charencmain.jsp"); 35 wc.sendRequest(req); 36 WebResponse wr = utils.submitButton("form01", "submit"); 37 check("form-charenc-01"); 38 39 WebLink link = wr.getLinkWithID("a02"); 44 wr = link.click(); 45 } 47 48 public void testRequiredField() throws Exception { 49 wc.sendRequest(new GetMethodWebRequest(servletUrl + "/multicolumn.jsp")); 50 utils.submitButton("form01", "multicolumnForm.ok"); 51 check("form-required"); 52 } 53 54 public void testMultiColumn() throws Exception { 55 wc.sendRequest(new GetMethodWebRequest(servletUrl + "/multicolumn.jsp")); 56 check("form-multicolumn"); 57 } 58 61 public void testWcfForm() throws Exception { 62 wc.sendRequest(new GetMethodWebRequest(servletUrl + "/formdemo.jsp")); 63 runTests(); 64 } 65 66 69 public void testJsfForm() throws Exception { 70 wc.sendRequest(new GetMethodWebRequest(servletUrl + "/formdemo.faces")); 71 runTests(); 72 } 73 74 private void runTests() throws Exception { 75 check("form-01"); 76 WebForm wf = wc.getCurrentPage().getFormWithID("form01"); 77 String id = "formcomp"; 78 79 wf.setParameter(id + ".string", "--ÄÖÜß--"); 81 wf.setParameter(id + ".int", "12"); 82 wf.setParameter(id + ".double", "123.456"); 83 wf.setParameter(id + ".date", "12/31/2003"); 84 wf.setParameter(id + ".password", "xäöüÄÖÜß"); 85 wf.setParameter(id + ".textarea", "some\nmulti\nline\ntext\n"); 86 wf.setParameter(id + ".checkbox1", "x"); 87 wf.setParameter(id + ".checkbox2", "x"); 88 wf.setParameter(id + ".list1", id + ".list1.1"); 89 wf.setParameter(id + ".listN", new String []{ id + ".listN.1", id + ".listN.4"}); 90 wf.setParameter("group1", id + ".radio1"); 91 wf.submit(wf.getSubmitButtonWithID("formcomp.validate")); 92 check("form-02"); 93 94 wf = wc.getCurrentPage().getFormWithID("form01"); 96 wf.setParameter(id + ".int", "nan"); 97 wf.setParameter(id + ".double", "nan"); 98 wf.setParameter(id + ".date", "nad"); 99 wf.submit(wf.getSubmitButtonWithID("formcomp.ok")); 100 check("form-03"); 101 wf.submit(wf.getSubmitButtonWithID("formcomp.revert")); 102 check("form-04"); 103 } 104 105 } 106 | Popular Tags |