Source Code Cross Referenced for MarkupWriterImplTest.java in  » Web-Framework » Tapestry » org » apache » tapestry » internal » services » 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.internal.services 
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.internal.services;
016:
017:        import org.apache.tapestry.Link;
018:        import org.apache.tapestry.MarkupWriter;
019:        import org.apache.tapestry.dom.Element;
020:        import org.apache.tapestry.dom.XMLMarkupModel;
021:        import org.apache.tapestry.internal.test.InternalBaseTestCase;
022:        import org.testng.annotations.Test;
023:
024:        public class MarkupWriterImplTest extends InternalBaseTestCase {
025:            @Test(expectedExceptions=IllegalStateException.class)
026:            public void write_with_no_current_element() {
027:                MarkupWriter w = new MarkupWriterImpl();
028:
029:                w.write("fail!");
030:            }
031:
032:            @Test
033:            public void write_whitespace_before_start_of_root_element_is_ignored() {
034:                MarkupWriter w = new MarkupWriterImpl(new XMLMarkupModel(),
035:                        null);
036:
037:                w.write("  ");
038:
039:                w.element("root");
040:                w.end();
041:
042:                assertEquals(w.toString(), "<root/>");
043:            }
044:
045:            @Test
046:            public void write_whitespace_after_end_of_root_element_is_ignored() {
047:                MarkupWriter w = new MarkupWriterImpl(new XMLMarkupModel(),
048:                        null);
049:
050:                w.element("root");
051:                w.end();
052:
053:                w.write("  ");
054:
055:                assertEquals(w.toString(), "<root/>");
056:            }
057:
058:            @Test(expectedExceptions=IllegalStateException.class)
059:            public void comment_with_no_current_element() {
060:                MarkupWriter w = new MarkupWriterImpl();
061:
062:                w.comment("fail!");
063:            }
064:
065:            @Test(expectedExceptions=IllegalStateException.class)
066:            public void end_with_no_current_element() {
067:                MarkupWriter w = new MarkupWriterImpl();
068:
069:                w.end();
070:            }
071:
072:            @Test(expectedExceptions=IllegalStateException.class)
073:            public void attributes_with_no_current_element() {
074:                MarkupWriter w = new MarkupWriterImpl();
075:
076:                w.attributes("fail", "now");
077:            }
078:
079:            @Test
080:            public void current_element_at_end_of_root_element_is_null() {
081:                MarkupWriter w = new MarkupWriterImpl();
082:
083:                w.element("root");
084:
085:                assertNull(w.end());
086:            }
087:
088:            @Test
089:            public void element_nesting() {
090:                MarkupWriter w = new MarkupWriterImpl();
091:
092:                Element root = w.element("root");
093:
094:                w.attributes("foo", "bar");
095:
096:                w.write("before child");
097:
098:                assertNotSame(w.element("nested"), root);
099:
100:                w.write("inner text");
101:
102:                assertSame(w.end(), root);
103:
104:                w.write("after child");
105:
106:                root.attribute("gnip", "gnop");
107:
108:                assertEquals(
109:                        w.toString(),
110:                        "<root foo=\"bar\" gnip=\"gnop\">before child<nested>inner text</nested>after child</root>");
111:            }
112:
113:            @Test
114:            public void element_with_attributes() {
115:                MarkupWriter w = new MarkupWriterImpl();
116:
117:                w.element("img", "src", "foo.png", "width", 20, "height", 20);
118:                w.end();
119:
120:                // img is a tag with an end tag style of omit, so no close tag is written.
121:
122:                assertEquals(w.toString(),
123:                        "<img height=\"20\" src=\"foo.png\" width=\"20\">");
124:            }
125:
126:            @Test
127:            public void attributes() {
128:                MarkupWriter w = new MarkupWriterImpl();
129:
130:                w.element("root");
131:
132:                w.attributes("foo", "bar", "gnip", "gnop");
133:
134:                assertEquals(w.toString(),
135:                        "<root foo=\"bar\" gnip=\"gnop\"></root>");
136:            }
137:
138:            @Test
139:            public void comment() {
140:                MarkupWriter w = new MarkupWriterImpl();
141:
142:                w.element("root");
143:                w.comment("A comment");
144:                w.end();
145:
146:                assertEquals(w.toString(), "<root><!-- A comment --></root>");
147:            }
148:
149:            @Test
150:            public void new_text_node_after_comment_node() {
151:                MarkupWriter w = new MarkupWriterImpl();
152:
153:                w.element("root");
154:                w.write("before");
155:                w.comment("A comment");
156:                w.write("after");
157:                w.end();
158:
159:                assertEquals(w.toString(),
160:                        "<root>before<!-- A comment -->after</root>");
161:            }
162:
163:            @Test
164:            public void null_write_is_ok() {
165:                MarkupWriter w = new MarkupWriterImpl();
166:
167:                w.element("root");
168:                w.write(null);
169:                w.end();
170:
171:                assertEquals(w.toString(), "<root></root>");
172:            }
173:
174:            @Test
175:            public void writef() {
176:                MarkupWriter w = new MarkupWriterImpl();
177:
178:                w.element("root");
179:                w.writef("Test name: %s", "writef");
180:
181:                assertEquals(w.toString(), "<root>Test name: writef</root>");
182:            }
183:
184:            @Test
185:            public void writer_notifies_map_about_links() {
186:                ComponentInvocationMap map = mockComponentInvocationMap();
187:
188:                MarkupWriter writer = new MarkupWriterImpl(
189:                        new XMLMarkupModel(), map);
190:                Link link = mockLink();
191:
192:                Element e = writer.element("form");
193:
194:                map.store(e, link);
195:
196:                replay();
197:
198:                writer.attributes("action", link);
199:
200:                verify();
201:            }
202:
203:            @Test
204:            public void write_raw() {
205:                MarkupWriter w = new MarkupWriterImpl();
206:
207:                w.element("root");
208:                w.write("<");
209:                w.writeRaw("&nbsp;");
210:                w.write(">");
211:                w.end();
212:
213:                assertEquals(w.toString(), "<root>&lt;&nbsp;&gt;</root>");
214:            }
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.