Source Code Cross Referenced for XMLRendererTest.java in  » Code-Analyzer » pmd-4.2rc1 » test » net » sourceforge » pmd » renderers » 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.renderers 
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.renderers;
004:
005:        import static org.junit.Assert.assertEquals;
006:        import static org.junit.Assert.assertNull;
007:        import net.sourceforge.pmd.AbstractRule;
008:        import net.sourceforge.pmd.PMD;
009:        import net.sourceforge.pmd.Report;
010:        import net.sourceforge.pmd.RuleContext;
011:        import net.sourceforge.pmd.RuleSet;
012:        import net.sourceforge.pmd.SourceType;
013:        import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration;
014:        import net.sourceforge.pmd.renderers.XMLRenderer;
015:
016:        import org.junit.Test;
017:        import org.w3c.dom.Element;
018:        import org.xml.sax.InputSource;
019:        import org.xml.sax.SAXException;
020:
021:        import test.net.sourceforge.pmd.testframework.RuleTst;
022:
023:        import java.io.IOException;
024:        import java.io.StringReader;
025:
026:        import javax.xml.parsers.DocumentBuilderFactory;
027:        import javax.xml.parsers.ParserConfigurationException;
028:
029:        public class XMLRendererTest extends RuleTst {
030:
031:            private static class FooRule extends AbstractRule {
032:                public Object visit(ASTClassOrInterfaceDeclaration c, Object ctx) {
033:                    if (c.getImage().equals("Foo"))
034:                        addViolation(ctx, c);
035:                    return ctx;
036:                }
037:
038:                public String getMessage() {
039:                    return "blah";
040:                }
041:
042:                public String getName() {
043:                    return "Foo";
044:                }
045:
046:                public String getRuleSetName() {
047:                    return "RuleSet";
048:                }
049:
050:                public String getDescription() {
051:                    return "desc";
052:                }
053:            }
054:
055:            @Test
056:            public void testEmptyReport() throws Throwable {
057:                Element root = parseRootElement(new Report());
058:                assertEquals("pmd", root.getNodeName());
059:                assertNull(root.getFirstChild().getNextSibling()); // only one child, it's whitespace
060:            }
061:
062:            @Test
063:            public void testErrorReport() throws Throwable {
064:                Report report = new Report();
065:                report.addError(new Report.ProcessingError("test_msg",
066:                        "test_filename"));
067:                Element root = parseRootElement(report);
068:                assertEquals("test_msg", root.getFirstChild().getNextSibling()
069:                        .getAttributes().getNamedItem("msg").getNodeValue());
070:            }
071:
072:            @Test
073:            public void testSingleReport() throws Throwable {
074:                Report report = new Report();
075:                runTestFromString(TEST1, new FooRule(), report);
076:                Element root = parseRootElement(report);
077:                assertEquals("n/a", root.getFirstChild().getNextSibling()
078:                        .getAttributes().getNamedItem("name").getNodeValue());
079:                assertEquals("Foo", root.getFirstChild().getNextSibling()
080:                        .getFirstChild().getNextSibling().getAttributes()
081:                        .getNamedItem("rule").getNodeValue());
082:                assertEquals("RuleSet", root.getFirstChild().getNextSibling()
083:                        .getFirstChild().getNextSibling().getAttributes()
084:                        .getNamedItem("ruleset").getNodeValue());
085:                assertEquals("1", root.getFirstChild().getNextSibling()
086:                        .getFirstChild().getNextSibling().getAttributes()
087:                        .getNamedItem("beginline").getNodeValue());
088:            }
089:
090:            private static final String TEST1 = "public class Foo {}" + PMD.EOL;
091:
092:            private static final String TEST2 = "public class Foo {" + PMD.EOL
093:                    + " public class Foo {}" + PMD.EOL + "}" + PMD.EOL;
094:
095:            @Test
096:            public void testDoubleReport() throws Throwable {
097:                Report report = new Report();
098:                runTestFromString(TEST2, new FooRule(), report);
099:                runTestFromString(TEST2, new FooRule(), report);
100:                Element root = parseRootElement(report);
101:                assertEquals("Foo", root.getFirstChild().getNextSibling()
102:                        .getFirstChild().getNextSibling().getAttributes()
103:                        .getNamedItem("rule").getNodeValue());
104:                assertEquals("Foo", root.getFirstChild().getNextSibling()
105:                        .getFirstChild().getNextSibling().getNextSibling()
106:                        .getNextSibling().getAttributes().getNamedItem("rule")
107:                        .getNodeValue());
108:            }
109:
110:            @Test
111:            public void testTwoFiles() throws Throwable {
112:                Report report = new Report();
113:                FooRule rule = new FooRule();
114:                runTestFromString(TEST2, rule, report);
115:                PMD p = new PMD();
116:                p.setJavaVersion(SourceType.JAVA_14);
117:                RuleContext ctx = new RuleContext();
118:                ctx.setReport(report);
119:                ctx.setSourceCodeFilename("bar");
120:                RuleSet rules = new RuleSet();
121:                rules.addRule(rule);
122:                p.processFile(new StringReader(TEST2), rules, ctx);
123:                Element root = parseRootElement(report);
124:                assertEquals("bar", root.getFirstChild().getNextSibling()
125:                        .getAttributes().getNamedItem("name").getNodeValue());
126:                assertEquals("n/a", root.getFirstChild().getNextSibling()
127:                        .getNextSibling().getNextSibling().getAttributes()
128:                        .getNamedItem("name").getNodeValue());
129:            }
130:
131:            private Element parseRootElement(Report rpt) throws SAXException,
132:                    IOException, ParserConfigurationException {
133:                return DocumentBuilderFactory.newInstance()
134:                        .newDocumentBuilder().parse(
135:                                new InputSource(new StringReader(
136:                                        new XMLRenderer().render(rpt))))
137:                        .getDocumentElement();
138:            }
139:
140:            public static junit.framework.Test suite() {
141:                return new junit.framework.JUnit4TestAdapter(
142:                        XMLRendererTest.class);
143:            }
144:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.