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 org.apache.tapestry.dom.Document;
18: import org.apache.tapestry.test.PageTester;
19: import org.testng.Assert;
20: import org.testng.annotations.DataProvider;
21: import org.testng.annotations.Test;
22:
23: public class DTDTest extends Assert {
24: private static final String FRAMESET = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">";
25:
26: private static final String TRANSITIONAL = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
27:
28: private static final String STRICT = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
29:
30: @DataProvider(name="dtd_page_provider")
31: public Object[][] dtd_page_provider() {
32: return new Object[][] {
33: { "DTDFromPage", FRAMESET, "slagheap", },
34: { "DTDFromComponent", TRANSITIONAL, "flubber", },
35: { "MultipleDTD", STRICT, "blubber", },
36: { "NoDTD", "", "no_dtd_loser", } };
37: }
38:
39: @Test(dataProvider="dtd_page_provider")
40: public void verify_correct_dtds(String pageName,
41: String expectedDTD, String checkText) {
42: String appPackage = "org.apache.tapestry.integration.app2";
43: String appName = "";
44: PageTester tester = new PageTester(appPackage, appName);
45: Document doc = tester.renderPage(pageName);
46: String txt = doc.toString();
47: // use startsWith to make sure the DTD is getting into the right spot.
48: assertTrue(txt.startsWith(expectedDTD));
49: // we should also make sure that the other DTD's don't appear anywhere else...
50: checkOtherDTD(txt, expectedDTD);
51: // spot check the body of the pages to make sure they correctly rendered...
52: // they should have, based on the unit tests for template rendering, but...
53: assertTrue(txt.contains(checkText));
54:
55: }
56:
57: private void checkOtherDTD(String txt, String expected) {
58: if (expected.equals(TRANSITIONAL)) {
59: check(txt, FRAMESET, STRICT);
60: } else if (expected.equals(FRAMESET)) {
61: check(txt, STRICT, TRANSITIONAL);
62: ;
63: } else if (expected.equals(STRICT)) {
64: check(txt, FRAMESET, TRANSITIONAL);
65: } else if (expected.equals("")) {
66: check(txt, FRAMESET, STRICT, TRANSITIONAL);
67: } else {
68: throw new RuntimeException("Unknown expected string: "
69: + expected);
70: }
71: }
72:
73: private void check(String txt, String... invalids) {
74: for (String invalid : invalids) {
75: assertFalse(txt.contains(invalid));
76: }
77: }
78:
79: }
|