KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 JavaDoc arg0) {
19     super(arg0);
20     HttpUnitOptions.setExceptionsThrownOnScriptError(false);
21     HttpUnitOptions.setScriptingEnabled(false);
22   }
23
24   private void check(String JavaDoc name) throws JaxenException, IOException JavaDoc, SAXException JavaDoc, TransformerException JavaDoc {
25     utils.check(name, "/com/tonbeller/wcf/web/form.xsl", "form01");
26   }
27
28   /**
29    * BEA does not recognize the response charEncoding when including files,
30    * so we tests <c:import ../> here.
31    */

32   public void testCharEnc() throws Exception JavaDoc {
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     // 2-ter test:
40
// URL mit UTF-8 encodierten Zeichen, funktioniert im Browser (entgegen der Spec)
41
// Funktioniert nicht mit httpunit. httpunit liefert unter Linux andere
42
// Ergebnisse als unter Windows, das XML enthaelt non-utf-8 Zeichen.
43
WebLink link = wr.getLinkWithID("a02");
44     wr = link.click();
45     // check("form-charenc-02");
46
}
47
48   public void testRequiredField() throws Exception JavaDoc {
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 JavaDoc {
55     wc.sendRequest(new GetMethodWebRequest(servletUrl + "/multicolumn.jsp"));
56     check("form-multicolumn");
57   }
58   /**
59    * run form tests w/o faces servlet. This tests WCF EL and navigation
60    */

61   public void testWcfForm() throws Exception JavaDoc {
62     wc.sendRequest(new GetMethodWebRequest(servletUrl + "/formdemo.jsp"));
63     runTests();
64   }
65
66   /**
67    * run form tests in faces context. This tests non-faces JSP thru faces servlet
68    */

69   public void testJsfForm() throws Exception JavaDoc {
70     wc.sendRequest(new GetMethodWebRequest(servletUrl + "/formdemo.faces"));
71     runTests();
72   }
73
74   private void runTests() throws Exception JavaDoc {
75     check("form-01");
76     WebForm wf = wc.getCurrentPage().getFormWithID("form01");
77     String JavaDoc id = "formcomp";
78
79     // ********* test valid input ****************
80
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 JavaDoc[]{ 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     // ******** test invalid input *************
95
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