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


001:        /**
002:         * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
003:         */package test.net.sourceforge.pmd.jaxen;
004:
005:        import static org.junit.Assert.assertEquals;
006:        import static org.junit.Assert.assertFalse;
007:        import static org.junit.Assert.assertSame;
008:        import static org.junit.Assert.fail;
009:        import net.sourceforge.pmd.AbstractRule;
010:        import net.sourceforge.pmd.PMD;
011:        import net.sourceforge.pmd.Report;
012:        import net.sourceforge.pmd.ast.ASTCompilationUnit;
013:        import net.sourceforge.pmd.ast.ASTImportDeclaration;
014:        import net.sourceforge.pmd.ast.ASTPrimaryExpression;
015:        import net.sourceforge.pmd.ast.ASTPrimaryPrefix;
016:        import net.sourceforge.pmd.ast.ASTStatement;
017:        import net.sourceforge.pmd.ast.Node;
018:        import net.sourceforge.pmd.jaxen.DocumentNavigator;
019:
020:        import org.jaxen.BaseXPath;
021:        import org.jaxen.JaxenException;
022:        import org.jaxen.UnsupportedAxisException;
023:        import org.junit.Before;
024:        import org.junit.Test;
025:
026:        import test.net.sourceforge.pmd.testframework.RuleTst;
027:
028:        import java.util.Iterator;
029:        import java.util.List;
030:
031:        public class DocumentNavigatorTest extends RuleTst {
032:
033:            private TestRule rule;
034:
035:            private class TestRule extends AbstractRule {
036:
037:                private Node compilationUnit;
038:                private Node importDeclaration;
039:                private Node statement;
040:                private Node primaryPrefix;
041:                private Node primaryExpression;
042:
043:                /**
044:                 * @see net.sourceforge.pmd.ast.JavaParserVisitor#visit(ASTCompilationUnit, Object)
045:                 */
046:                public Object visit(ASTCompilationUnit node, Object data) {
047:                    this .compilationUnit = node;
048:                    return super .visit(node, data);
049:                }
050:
051:                public Object visit(ASTImportDeclaration node, Object data) {
052:                    this .importDeclaration = node;
053:                    return super .visit(node, data);
054:                }
055:
056:                public Object visit(ASTStatement node, Object data) {
057:                    this .statement = node;
058:                    return super .visit(node, data);
059:                }
060:
061:                public Object visit(ASTPrimaryPrefix node, Object data) {
062:                    this .primaryPrefix = node;
063:                    return super .visit(node, data);
064:                }
065:
066:                public Object visit(ASTPrimaryExpression node, Object data) {
067:                    this .primaryExpression = node;
068:                    return super .visit(node, data);
069:                }
070:            }
071:
072:            @Before
073:            public void setUp() throws Exception {
074:                try {
075:                    rule = new TestRule();
076:                    runTestFromString(TEST, rule, new Report());
077:                } catch (Throwable xx) {
078:                    xx.printStackTrace();
079:                    fail();
080:                }
081:            }
082:
083:            @Test
084:            public void testChildAxisIterator() {
085:                DocumentNavigator nav = new DocumentNavigator();
086:                Iterator iter = nav.getChildAxisIterator(rule.compilationUnit);
087:                assertSame(rule.compilationUnit.jjtGetChild(0), iter.next());
088:                assertSame(rule.compilationUnit.jjtGetChild(1), iter.next());
089:                assertFalse(iter.hasNext());
090:            }
091:
092:            @Test
093:            public void testParentAxisIterator() {
094:                DocumentNavigator nav = new DocumentNavigator();
095:                Iterator iter = nav
096:                        .getParentAxisIterator(rule.importDeclaration);
097:                assertSame(rule.importDeclaration.jjtGetParent(), iter.next());
098:                assertFalse(iter.hasNext());
099:            }
100:
101:            @Test
102:            public void testParentAxisIterator2() {
103:                DocumentNavigator nav = new DocumentNavigator();
104:                Iterator iter = nav.getParentAxisIterator(rule.compilationUnit);
105:                assertFalse(iter.hasNext());
106:            }
107:
108:            @Test
109:            public void testDescendantAxisIterator()
110:                    throws UnsupportedAxisException {
111:                DocumentNavigator nav = new DocumentNavigator();
112:                Iterator iter = nav.getDescendantAxisIterator(rule.statement);
113:                Node statementExpression = rule.statement.jjtGetChild(0);
114:                assertSame(statementExpression, iter.next());
115:                Node primaryExpression = statementExpression.jjtGetChild(0);
116:                assertSame(primaryExpression, iter.next());
117:                Node primaryPrefix = primaryExpression.jjtGetChild(0);
118:                assertSame(primaryPrefix, iter.next());
119:                Node primarySuffix = primaryExpression.jjtGetChild(1);
120:                //        assertSame(primarySuffix, iter.next());
121:                Node name = primaryPrefix.jjtGetChild(0);
122:                //        assertSame(name, iter.next());
123:                Node arguments = primarySuffix.jjtGetChild(0);
124:                //        assertSame(arguments, iter.next());
125:                //        assertFalse(iter.hasNext());
126:            }
127:
128:            @Test
129:            public void testDescendantAxisIterator2()
130:                    throws UnsupportedAxisException {
131:                DocumentNavigator nav = new DocumentNavigator();
132:                Iterator iter = nav
133:                        .getDescendantAxisIterator(rule.primaryPrefix);
134:                Node name = rule.primaryPrefix.jjtGetChild(0);
135:                assertSame(name, iter.next());
136:                assertFalse(iter.hasNext());
137:            }
138:
139:            @Test
140:            public void testFollowingSiblingAxisIterator() {
141:                DocumentNavigator nav = new DocumentNavigator();
142:                Iterator iter = nav
143:                        .getFollowingSiblingAxisIterator(rule.primaryExpression
144:                                .jjtGetChild(0));
145:                assertSame(rule.primaryExpression.jjtGetChild(1), iter.next());
146:                assertFalse(iter.hasNext());
147:            }
148:
149:            @Test
150:            public void testFollowingSiblingAxisIterator2() {
151:                DocumentNavigator nav = new DocumentNavigator();
152:                Iterator iter = nav
153:                        .getFollowingSiblingAxisIterator(rule.primaryExpression
154:                                .jjtGetChild(1));
155:                assertFalse(iter.hasNext());
156:            }
157:
158:            @Test
159:            public void testPrecedingSiblingAxisIterator() {
160:                DocumentNavigator nav = new DocumentNavigator();
161:                Iterator iter = nav
162:                        .getPrecedingSiblingAxisIterator(rule.primaryExpression
163:                                .jjtGetChild(1));
164:                assertSame(rule.primaryExpression.jjtGetChild(0), iter.next());
165:                assertFalse(iter.hasNext());
166:            }
167:
168:            @Test
169:            public void testPrecedingSiblingAxisIterator2() {
170:                DocumentNavigator nav = new DocumentNavigator();
171:                Iterator iter = nav
172:                        .getPrecedingSiblingAxisIterator(rule.primaryExpression
173:                                .jjtGetChild(0));
174:                assertFalse(iter.hasNext());
175:            }
176:
177:            @Test
178:            public void testXPath() throws JaxenException {
179:                BaseXPath xPath = new BaseXPath(".//*", new DocumentNavigator());
180:                List matches = xPath.selectNodes(rule.statement);
181:                assertEquals(6, matches.size());
182:            }
183:
184:            @Test
185:            public void testXPath2() throws JaxenException {
186:                BaseXPath xPath = new BaseXPath(".//*", new DocumentNavigator());
187:                List matches = xPath.selectNodes(rule.importDeclaration);
188:                assertEquals(1, matches.size());
189:            }
190:
191:            public static final String TEST = "import java.io.*;" + PMD.EOL
192:                    + "public class Foo {" + PMD.EOL + " public Foo() {"
193:                    + PMD.EOL + "  try {" + PMD.EOL
194:                    + "   FileReader fr = new FileReader(\"/dev/null\");"
195:                    + PMD.EOL + "  } catch (Exception e) {}" + PMD.EOL
196:                    + "  try {" + PMD.EOL
197:                    + "   FileReader fr = new FileReader(\"/dev/null\");"
198:                    + PMD.EOL + "  } catch (Exception e) {" + PMD.EOL
199:                    + "   e.printStackTrace();" + PMD.EOL
200:                    + "   // this shouldn't show up on the report" + PMD.EOL
201:                    + "  }" + PMD.EOL + " }" + PMD.EOL + "}";
202:
203:            public static junit.framework.Test suite() {
204:                return new junit.framework.JUnit4TestAdapter(
205:                        DocumentNavigatorTest.class);
206:            }
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.