Source Code Cross Referenced for JspDocStyleTest.java in  » Code-Analyzer » pmd-4.2rc1 » test » net » sourceforge » pmd » jsp » ast » 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 » Code Analyzer » pmd 4.2rc1 » test.net.sourceforge.pmd.jsp.ast 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package test.net.sourceforge.pmd.jsp.ast;
002:
003:        import static org.junit.Assert.assertEquals;
004:        import net.sourceforge.pmd.jsp.ast.ASTAttribute;
005:        import net.sourceforge.pmd.jsp.ast.ASTAttributeValue;
006:        import net.sourceforge.pmd.jsp.ast.ASTCData;
007:        import net.sourceforge.pmd.jsp.ast.ASTCommentTag;
008:        import net.sourceforge.pmd.jsp.ast.ASTDoctypeDeclaration;
009:        import net.sourceforge.pmd.jsp.ast.ASTDoctypeExternalId;
010:        import net.sourceforge.pmd.jsp.ast.ASTElement;
011:
012:        import org.junit.Test;
013:
014:        import java.util.ArrayList;
015:        import java.util.Collections;
016:        import java.util.Comparator;
017:        import java.util.List;
018:        import java.util.Set;
019:
020:        /**
021:         * Test parsing of a JSP in document style, by checking the generated AST.
022:         * 
023:         * @author pieter_van_raemdonck - Application Engineers NV/SA - www.ae.be
024:         * 
025:         */
026:        public class JspDocStyleTest extends AbstractJspNodesTst {
027:
028:            /**
029:             * Smoke test for JSP parser.
030:             * 
031:             * @throws Throwable
032:             */
033:            @Test
034:            public void testSimplestJsp() throws Throwable {
035:                assertNumberOfNodes(ASTElement.class, TEST_SIMPLEST_HTML, 1);
036:            }
037:
038:            /**
039:             * Test the information on a Element and Attribute.
040:             * 
041:             * @throws Throwable
042:             */
043:            @Test
044:            public void testElementAttributeAndNamespace() throws Throwable {
045:                Set nodes = getNodes(null, TEST_ELEMENT_AND_NAMESPACE);
046:
047:                Set<ASTElement> elementNodes = getNodesOfType(ASTElement.class,
048:                        nodes);
049:                assertEquals("One element node expected!", 1, elementNodes
050:                        .size());
051:                ASTElement element = elementNodes.iterator().next();
052:                assertEquals("Correct name expected!", "h:html", element
053:                        .getName());
054:                assertEquals("Has namespace prefix!", true, element
055:                        .isHasNamespacePrefix());
056:                assertEquals("Element is empty!", true, element.isEmpty());
057:                assertEquals("Correct namespace prefix of element expected!",
058:                        "h", element.getNamespacePrefix());
059:                assertEquals("Correct local name of element expected!", "html",
060:                        element.getLocalName());
061:
062:                Set attributeNodes = getNodesOfType(ASTAttribute.class, nodes);
063:                assertEquals("One attribute node expected!", 1, attributeNodes
064:                        .size());
065:                ASTAttribute attribute = (ASTAttribute) attributeNodes
066:                        .iterator().next();
067:                assertEquals("Correct name expected!", "MyNsPrefix:MyAttr",
068:                        attribute.getName());
069:                assertEquals("Has namespace prefix!", true, attribute
070:                        .isHasNamespacePrefix());
071:                assertEquals("Correct namespace prefix of element expected!",
072:                        "MyNsPrefix", attribute.getNamespacePrefix());
073:                assertEquals("Correct local name of element expected!",
074:                        "MyAttr", attribute.getLocalName());
075:
076:            }
077:
078:            /**
079:             * Test exposing a bug of parsing error when having a hash as last character
080:             * in an attribute value.
081:             *
082:             */
083:            @Test
084:            public void testAttributeValueContainingHash() {
085:                Set nodes = getNodes(null, TEST_ATTRIBUTE_VALUE_CONTAINING_HASH);
086:
087:                Set<ASTAttribute> attributes = getNodesOfType(
088:                        ASTAttribute.class, nodes);
089:                assertEquals("Three attributes expected!", 3, attributes.size());
090:
091:                List<ASTAttribute> attrsList = new ArrayList<ASTAttribute>(
092:                        attributes);
093:                Collections.sort(attrsList, new Comparator<ASTAttribute>() {
094:                    public int compare(ASTAttribute arg0, ASTAttribute arg1) {
095:                        return arg0.getName().compareTo(arg1.getName());
096:                    }
097:                });
098:
099:                ASTAttribute attr = attrsList.get(0);
100:                assertEquals("Correct attribute name expected!", "foo", attr
101:                        .getName());
102:                assertEquals("Correct attribute value expected!", "CREATE",
103:                        attr.getFirstChildOfType(ASTAttributeValue.class)
104:                                .getImage());
105:
106:                attr = attrsList.get(1);
107:                assertEquals("Correct attribute name expected!", "href", attr
108:                        .getName());
109:                assertEquals("Correct attribute value expected!", "#", attr
110:                        .getFirstChildOfType(ASTAttributeValue.class)
111:                        .getImage());
112:
113:                attr = attrsList.get(2);
114:                assertEquals("Correct attribute name expected!", "something",
115:                        attr.getName());
116:                assertEquals("Correct attribute value expected!", "#yes#", attr
117:                        .getFirstChildOfType(ASTAttributeValue.class)
118:                        .getImage());
119:            }
120:
121:            /**
122:             * Test correct parsing of CDATA.
123:             */
124:            @Test
125:            public void testCData() {
126:                Set cdataNodes = getNodes(ASTCData.class, TEST_CDATA);
127:
128:                assertEquals("One CDATA node expected!", 1, cdataNodes.size());
129:                ASTCData cdata = (ASTCData) cdataNodes.iterator().next();
130:                assertEquals("Content incorrectly parsed!",
131:                        " some <cdata> ]] ]> ", cdata.getImage());
132:            }
133:
134:            /**
135:             * Test parsing of Doctype declaration.
136:             */
137:            @Test
138:            public void testDoctype() {
139:                Set nodes = getNodes(null, TEST_DOCTYPE);
140:
141:                Set<ASTDoctypeDeclaration> docTypeDeclarations = getNodesOfType(
142:                        ASTDoctypeDeclaration.class, nodes);
143:                assertEquals("One doctype declaration expected!", 1,
144:                        docTypeDeclarations.size());
145:                ASTDoctypeDeclaration docTypeDecl = docTypeDeclarations
146:                        .iterator().next();
147:                assertEquals("Correct doctype-name expected!", "html",
148:                        docTypeDecl.getName());
149:
150:                Set externalIds = getNodesOfType(ASTDoctypeExternalId.class,
151:                        nodes);
152:                assertEquals("One doctype external id expected!", 1,
153:                        externalIds.size());
154:                ASTDoctypeExternalId externalId = (ASTDoctypeExternalId) externalIds
155:                        .iterator().next();
156:                assertEquals("Correct external public id expected!",
157:                        "-//W3C//DTD XHTML 1.1//EN", externalId.getPublicId());
158:                assertEquals("Correct external uri expected!",
159:                        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd",
160:                        externalId.getUri());
161:
162:            }
163:
164:            /**
165:             * Test parsing of a XML comment.
166:             *
167:             */
168:            @Test
169:            public void testComment() {
170:                Set comments = getNodes(ASTCommentTag.class, TEST_COMMENT);
171:                assertEquals("One comment expected!", 1, comments.size());
172:                ASTCommentTag comment = (ASTCommentTag) comments.iterator()
173:                        .next();
174:                assertEquals("Correct comment content expected!", "comment",
175:                        comment.getImage());
176:            }
177:
178:            private static final String TEST_SIMPLEST_HTML = "<html/>";
179:
180:            private static final String TEST_ELEMENT_AND_NAMESPACE = "<h:html MyNsPrefix:MyAttr='MyValue'/>";
181:
182:            private static final String TEST_CDATA = "<html><![CDATA[ some <cdata> ]] ]> ]]></html>";
183:
184:            private static final String TEST_DOCTYPE = "<?xml version=\"1.0\" standalone='yes'?>\n"
185:                    + "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" "
186:                    + "\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n"
187:                    + "<greeting>Hello, world!</greeting>";
188:
189:            private static final String TEST_COMMENT = "<html><!-- comment --></html>";
190:
191:            private static final String TEST_ATTRIBUTE_VALUE_CONTAINING_HASH = "<tag:if something=\"#yes#\" foo=\"CREATE\">  <a href=\"#\">foo</a> </tag:if>";
192:
193:            public static junit.framework.Test suite() {
194:                return new junit.framework.JUnit4TestAdapter(
195:                        JspDocStyleTest.class);
196:            }
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.