Source Code Cross Referenced for DOMTest.java in  » Web-Framework » Tapestry » org » apache » tapestry » dom » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » Tapestry » org.apache.tapestry.dom 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright 2006, 2007 The Apache Software Foundation
002:        //
003:        // Licensed under the Apache License, Version 2.0 (the "License");
004:        // you may not use this file except in compliance with the License.
005:        // You may obtain a copy of the License at
006:        //
007:        //     http://www.apache.org/licenses/LICENSE-2.0
008:        //
009:        // Unless required by applicable law or agreed to in writing, software
010:        // distributed under the License is distributed on an "AS IS" BASIS,
011:        // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:        // See the License for the specific language governing permissions and
013:        // limitations under the License.
014:
015:        package org.apache.tapestry.dom;
016:
017:        import org.apache.tapestry.internal.test.InternalBaseTestCase;
018:        import org.testng.annotations.Test;
019:
020:        /**
021:         * Tests for a number of DOM node classes, including {@link org.apache.tapestry.dom.Element} and
022:         * {@link org.apache.tapestry.dom.Document}.
023:         */
024:        public class DOMTest extends InternalBaseTestCase {
025:            @Test
026:            public void document_with_empty_root_element() {
027:                Document d = new Document();
028:
029:                d.newRootElement("empty");
030:
031:                assertEquals(d.toString(), "<empty></empty>");
032:            }
033:
034:            @Test
035:            public void xml_style_empty_element() {
036:                Document d = new Document(new XMLMarkupModel());
037:
038:                d.newRootElement("empty");
039:
040:                assertEquals(d.toString(), "<empty/>");
041:            }
042:
043:            /** Also demonstrates that attributes are provided in alphabetical order. */
044:            @Test
045:            public void document_with_root_element_and_attributes()
046:                    throws Exception {
047:                Document d = new Document();
048:
049:                Element e = d.newRootElement("has-attributes");
050:
051:                e.attribute("fred", "flintstone");
052:                e.attribute("barney", "rubble");
053:
054:                assertEquals(d.toString(), readFile(
055:                        "document_with_root_element_and_attributes.txt", true));
056:            }
057:
058:            @Test
059:            public void nested_elements() throws Exception {
060:                Document d = new Document();
061:
062:                Element e = d.newRootElement("population");
063:
064:                Element p = e.element("person");
065:                p.attribute("first-name", "Fred");
066:                p.attribute("last-name", "Flintstone");
067:
068:                assertSame(p.getParent(), e);
069:
070:                p = e.element("person");
071:                p.attribute("first-name", "Barney");
072:                p.attribute("last-name", "Rubble");
073:
074:                assertSame(p.getParent(), e);
075:
076:                assertEquals(d.toString(),
077:                        readFile("nested_elements.txt", true));
078:            }
079:
080:            @Test
081:            public void to_string_on_empty_document() {
082:                Document d = new Document();
083:
084:                assertEquals(d.toString(), "[empty Document]");
085:            }
086:
087:            @Test(expectedExceptions=IllegalArgumentException.class)
088:            public void attribute_names_may_not_be_blank() {
089:                Document d = new Document();
090:
091:                Element e = d.newRootElement("fred");
092:
093:                e.attribute("", "value");
094:            }
095:
096:            @Test
097:            public void element_name_may_not_be_blank() {
098:                Document d = new Document();
099:
100:                d.newRootElement("");
101:            }
102:
103:            @Test
104:            public void attribute_value_null_is_no_op() {
105:                Document d = new Document();
106:
107:                Element e = d.newRootElement("root");
108:
109:                e.attribute("foo", "bar");
110:
111:                final String expected = "<root foo=\"bar\"></root>";
112:
113:                assertEquals(d.toString(), expected);
114:
115:                e.attribute("foo", null);
116:
117:                assertEquals(d.toString(), expected);
118:
119:                e.attribute("gnip", null);
120:
121:                assertEquals(d.toString(), expected);
122:            }
123:
124:            @Test
125:            public void comments() throws Exception {
126:                Document d = new Document();
127:
128:                // Can't add comments to the document, not yet.
129:
130:                Element e = d.newRootElement("html");
131:
132:                e.comment("Created by Tapestry 5.0");
133:
134:                assertEquals(d.toString(),
135:                        "<html><!-- Created by Tapestry 5.0 --></html>");
136:            }
137:
138:            @Test
139:            public void text() {
140:                Document d = new Document();
141:
142:                Element e = d.newRootElement("body");
143:
144:                e.text("Tapestry does DOM.");
145:
146:                assertEquals(d.toString(), "<body>Tapestry does DOM.</body>");
147:            }
148:
149:            @Test
150:            public void text_with_control_characters() {
151:                Document d = new Document();
152:
153:                Element e = d.newRootElement("root");
154:
155:                e.text("<this> & <that>");
156:
157:                assertEquals(d.toString(),
158:                        "<root>&lt;this&gt; &amp; &lt;that&gt;</root>");
159:            }
160:
161:            @Test
162:            public void specify_attributes_with_new_element() {
163:                Document d = new Document();
164:
165:                Element e = d.newRootElement("root");
166:
167:                e.element("foo", "alpha", "legion");
168:
169:                assertEquals(d.toString(),
170:                        "<root><foo alpha=\"legion\"></foo></root>");
171:            }
172:
173:            @Test
174:            public void writef_with_text() {
175:                Document d = new Document();
176:
177:                Element e = d.newRootElement("root");
178:
179:                Text t = e.text("Start: ");
180:
181:                t.writef("** %s: %d **", "foo", 5);
182:
183:                assertEquals(d.toString(), "<root>Start: ** foo: 5 **</root>");
184:            }
185:
186:            @Test
187:            public void get_element_by_id() {
188:                Document d = new Document();
189:                Element e = d.newRootElement("root");
190:                Element e1 = e.element("e1", "id", "x");
191:                Element e2 = e.element("e2", "id", "y");
192:                assertSame(e1.getElementById("x"), e1);
193:                assertSame(e.getElementById("y"), e2);
194:                assertNull(e.getElementById("z"));
195:            }
196:
197:            @Test
198:            public void get_child_markup() {
199:                Document d = new Document();
200:                Element e0 = d.newRootElement("root");
201:                Element e1 = e0.element("e1");
202:                e1.text("123");
203:                assertEquals(e1.getChildText(), "123");
204:                assertEquals(e0.getChildText(), "<e1>123</e1>");
205:            }
206:
207:            @Test
208:            public void document_find_no_root_element() {
209:                Document d = new Document();
210:
211:                assertNull(d.find("does/not/matter"));
212:            }
213:
214:            @Test
215:            public void document_find_not_a_match() {
216:                Document d = new Document();
217:
218:                d.newRootElement("fred");
219:
220:                assertNull(d.find("barney"));
221:                assertNull(d.find("wilma/betty"));
222:            }
223:
224:            @Test
225:            public void document_find_root_is_match() {
226:                Document d = new Document();
227:
228:                Element root = d.newRootElement("fred");
229:
230:                assertSame(d.find("fred"), root);
231:            }
232:
233:            @Test
234:            public void document_find_match() {
235:                Document d = new Document();
236:
237:                Element root = d.newRootElement("fred");
238:
239:                root.text("text");
240:                Element barney = root.element("barney");
241:                Element bambam = barney.element("bambam");
242:
243:                assertSame(d.find("fred/barney/bambam"), bambam);
244:                assertSame(root.find("barney/bambam"), bambam);
245:            }
246:
247:            @Test
248:            public void document_find_no_match() {
249:                Document d = new Document();
250:
251:                Element root = d.newRootElement("fred");
252:
253:                root.text("text");
254:                Element barney = root.element("barney");
255:                barney.element("bambam");
256:
257:                assertNull(d.find("fred/barney/pebbles"));
258:                assertNull(root.find("barney/pebbles"));
259:            }
260:
261:            @Test
262:            public void insert_element_at() {
263:                Document d = new Document(new XMLMarkupModel());
264:
265:                Element root = d.newRootElement("fred");
266:
267:                root.element("start");
268:                root.element("end");
269:
270:                root.elementAt(1, "one").element("tiny");
271:                root.elementAt(2, "two").element("bubbles");
272:
273:                assertEquals(d.toString(),
274:                        "<fred><start/><one><tiny/></one><two><bubbles/></two><end/></fred>");
275:            }
276:
277:            @Test
278:            public void force_attributes_overrides_existing() {
279:                Document d = new Document(new XMLMarkupModel());
280:
281:                Element root = d.newRootElement("fred");
282:
283:                root.attributes("hi", "ho", "gnip", "gnop");
284:
285:                assertEquals(root.toString(), "<fred gnip=\"gnop\" hi=\"ho\"/>");
286:
287:                root.forceAttributes("hi", "bit", "gnip", null);
288:
289:                assertEquals(root.toString(), "<fred hi=\"bit\"/>");
290:            }
291:
292:            @Test
293:            public void raw_output() {
294:                Document d = new Document(new XMLMarkupModel());
295:
296:                Element root = d.newRootElement("fred");
297:
298:                Element em = root.element("em");
299:
300:                em.text("<");
301:                em.raw("&nbsp;");
302:                em.text(">");
303:
304:                // The '<' and '>' are filtered into entities, but the '&' in &nbsp; is left alone (left
305:                // raw).
306:
307:                assertEquals(root.toString(),
308:                        "<fred><em>&lt;&nbsp;&gt;</em></fred>");
309:            }
310:
311:            @Test
312:            public void dtd_with_markup() {
313:                Document d = new Document(new XMLMarkupModel());
314:                Element root = d.newRootElement("prime");
315:                root.element("slag");
316:                d.dtd("prime", "-//TF", "tf");
317:                String expected = "<!DOCTYPE prime PUBLIC \"-//TF\" \"tf\"><prime><slag/></prime>";
318:                assertEquals(d.toString(), expected);
319:            }
320:
321:            @Test
322:            public void dtd_with_nullids() {
323:                Document d = new Document(new XMLMarkupModel());
324:                d.newRootElement("prime");
325:                d.dtd("prime", null, null);
326:                assertEquals(d.toString(), "<prime/>");
327:                d.dtd("prime", "-//TF", null);
328:                assertEquals(d.toString(),
329:                        "<!DOCTYPE prime PUBLIC \"-//TF\"><prime/>");
330:
331:                d.dtd("prime", null, "tf");
332:                assertEquals(d.toString(),
333:                        "<!DOCTYPE prime SYSTEM \"tf\"><prime/>");
334:            }
335:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.