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.UploadFileSpec; 12 import com.meterware.httpunit.WebForm; 13 14 18 public class FormUploadTest extends HttpUnitTestCase { 19 20 public FormUploadTest(String arg0) { 21 super(arg0); 22 } 23 24 private void check(String name, String id) throws JaxenException, IOException , SAXException , 25 TransformerException { 26 utils.check(name, "filter.xsl", id); 27 } 28 29 32 public void testWcfForm() throws Exception { 33 wc.sendRequest(new GetMethodWebRequest(servletUrl + "/uploaddemo.jsp")); 34 runTests(); 35 } 36 37 private void runTests() throws Exception { 38 check("upload-01", "form01"); 39 WebForm wf = wc.getCurrentPage().getFormWithID("form01"); 40 String id = "uploadcomp"; 41 wf.setParameter(id + ".string", "--ÄÖÜß--"); 43 wf.setParameter(id + ".int", "12"); 44 wf.setParameter(id + ".double", "123.456"); 45 wf.setParameter(id + ".date", "12/31/2003"); 46 wf.setParameter(id + ".password", "xxxx"); 47 wf.setParameter(id + ".textarea", "some\nmulti\nline\ntext\n"); 48 wf.setParameter(id + ".checkbox1", "x"); 49 wf.setParameter(id + ".checkbox2", "x"); 50 wf.setParameter(id + ".list1", id + ".list1.1"); 51 wf.setParameter(id + ".listN", new String [] { id + ".listN.1", id + ".listN.4"}); 52 wf.setParameter("group1", id + ".radio1"); 53 wf.submit(wf.getSubmitButtonWithID("uploadcomp.validate")); 54 check("upload-02", "form01"); 55 56 wf = wc.getCurrentPage().getFormWithID("form01"); 58 wf.setParameter(id + ".int", "nan"); 59 wf.setParameter(id + ".double", "nan"); 60 wf.setParameter(id + ".date", "nad"); 61 wf.submit(wf.getSubmitButtonWithID("uploadcomp.ok")); 62 check("upload-03", "form01"); 63 wf.submit(wf.getSubmitButtonWithID("uploadcomp.revert")); 64 check("upload-04", "form01"); 65 66 UploadFileSpec fileSpec = new UploadFileSpec("uploadtest.txt", getClass().getResourceAsStream( 68 "uploadtest.txt"), "text/plain"); 69 wf.setParameter(id + ".fileUpload1", new UploadFileSpec[] { fileSpec}); 70 wf.submit(wf.getSubmitButtonWithID("uploadcomp.validate")); 71 check("upload-05", "uploadInfo"); 72 } 73 74 } | Popular Tags |