01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.integration.pagelevel;
16:
17: import java.util.Map;
18:
19: import org.apache.tapestry.dom.Document;
20: import org.apache.tapestry.dom.Element;
21: import org.apache.tapestry.ioc.internal.util.CollectionFactory;
22: import org.apache.tapestry.test.PageTester;
23: import org.testng.Assert;
24: import org.testng.annotations.AfterMethod;
25: import org.testng.annotations.BeforeMethod;
26: import org.testng.annotations.Test;
27:
28: public class SubmitTest extends Assert {
29: private PageTester _tester;
30:
31: private Document _doc;
32:
33: private Map<String, String> _fieldValues;
34:
35: @Test
36: public void submit_form() {
37: Element submitButton = _doc.getElementById("capitalize1");
38: _fieldValues.put("t1", "hello");
39: _doc = _tester.clickSubmit(submitButton, _fieldValues);
40: assertTrue(_doc.toString().contains("Value is: HELLO"));
41: }
42:
43: @Test
44: public void access_following_fields() {
45: Element submitButton = _doc.getElementById("capitalize2");
46: _fieldValues.put("t2", "world");
47: _doc = _tester.clickSubmit(submitButton, _fieldValues);
48: assertTrue(_doc.toString().contains("Value is: WORLD"));
49: }
50:
51: @Test(expectedExceptions=IllegalArgumentException.class)
52: public void not_a_submit() {
53: Element submitButton = _doc.getElementById("t1");
54: _tester.clickSubmit(submitButton, _fieldValues);
55: }
56:
57: @Test(expectedExceptions=IllegalArgumentException.class)
58: public void not_in_form() {
59: Element submitButton = _doc.getElementById("orphanedSubmit");
60: _tester.clickSubmit(submitButton, _fieldValues);
61: }
62:
63: @BeforeMethod
64: public void before() {
65: String appPackage = "org.apache.tapestry.integration.app2";
66: String appName = "";
67: _tester = new PageTester(appPackage, appName);
68: _doc = _tester.renderPage("TestPageForSubmit");
69: _fieldValues = CollectionFactory.newMap();
70: }
71:
72: @AfterMethod
73: public void after() {
74: if (_tester != null) {
75: _tester.shutdown();
76: }
77: }
78: }
|