KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > web > FormUploadTest


1 package com.tonbeller.wcf.web;
2
3 import java.io.IOException JavaDoc;
4
5 import javax.xml.transform.TransformerException JavaDoc;
6
7 import org.jaxen.JaxenException;
8 import org.xml.sax.SAXException JavaDoc;
9
10 import com.meterware.httpunit.GetMethodWebRequest;
11 import com.meterware.httpunit.UploadFileSpec;
12 import com.meterware.httpunit.WebForm;
13
14 /**
15  * Adds file upload to form test. It is important to test all
16  * control types since parameters are parsed with a different encoding
17  */

18 public class FormUploadTest extends HttpUnitTestCase {
19
20   public FormUploadTest(String JavaDoc arg0) {
21     super(arg0);
22   }
23
24   private void check(String JavaDoc name, String JavaDoc id) throws JaxenException, IOException JavaDoc, SAXException JavaDoc,
25       TransformerException JavaDoc {
26     utils.check(name, "filter.xsl", id);
27   }
28
29   /**
30    * run form tests w/o faces servlet. This tests WCF EL and navigation
31    */

32   public void testWcfForm() throws Exception JavaDoc {
33     wc.sendRequest(new GetMethodWebRequest(servletUrl + "/uploaddemo.jsp"));
34     runTests();
35   }
36
37   private void runTests() throws Exception JavaDoc {
38     check("upload-01", "form01");
39     WebForm wf = wc.getCurrentPage().getFormWithID("form01");
40     String JavaDoc id = "uploadcomp";
41     // ********* test valid input ****************
42
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 JavaDoc[] { 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     // ******** test invalid input *************
57
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     // ******** test upload *************
67
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