Source Code Cross Referenced for TestXMLPrinter.java in  » Code-Analyzer » DependencyFinder » com » jeantessier » metrics » 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 » DependencyFinder » com.jeantessier.metrics 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Copyright (c) 2001-2007, Jean Tessier
003:         *  All rights reserved.
004:         *  
005:         *  Redistribution and use in source and binary forms, with or without
006:         *  modification, are permitted provided that the following conditions
007:         *  are met:
008:         *  
009:         *      * Redistributions of source code must retain the above copyright
010:         *        notice, this list of conditions and the following disclaimer.
011:         *  
012:         *      * Redistributions in binary form must reproduce the above copyright
013:         *        notice, this list of conditions and the following disclaimer in the
014:         *        documentation and/or other materials provided with the distribution.
015:         *  
016:         *      * Neither the name of Jean Tessier nor the names of his contributors
017:         *        may be used to endorse or promote products derived from this software
018:         *        without specific prior written permission.
019:         *  
020:         *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021:         *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022:         *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023:         *  A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR
024:         *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025:         *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026:         *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027:         *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028:         *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029:         *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030:         *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031:         */
032:
033:        package com.jeantessier.metrics;
034:
035:        import java.io.*;
036:        import java.util.*;
037:        import javax.xml.parsers.*;
038:
039:        import junit.framework.*;
040:        import org.apache.oro.text.perl.*;
041:        import org.xml.sax.*;
042:
043:        import com.jeantessier.classreader.*;
044:
045:        public class TestXMLPrinter extends TestCase implements  ErrorHandler {
046:            private static final String TEST_CLASS = "test";
047:            private static final String TEST_FILENAME = "classes"
048:                    + File.separator + "test.class";
049:            private static final String CONFIGURATION_FILENAME = "etc"
050:                    + File.separator + "MetricsConfig.xml";
051:
052:            private static final String SPECIFIC_ENCODING = "iso-latin-1";
053:            private static final String SPECIFIC_DTD_PREFIX = "./etc";
054:
055:            private StringWriter buffer;
056:            private MetricsConfiguration configuration;
057:            private XMLReader reader;
058:
059:            private Perl5Util perl;
060:
061:            protected void setUp() throws Exception {
062:                buffer = new StringWriter();
063:                configuration = new MetricsConfigurationLoader()
064:                        .load(CONFIGURATION_FILENAME);
065:
066:                reader = SAXParserFactory.newInstance().newSAXParser()
067:                        .getXMLReader();
068:                reader.setFeature("http://xml.org/sax/features/validation",
069:                        true);
070:                reader
071:                        .setFeature(
072:                                "http://apache.org/xml/features/nonvalidating/load-external-dtd",
073:                                true);
074:                reader.setErrorHandler(this );
075:
076:                perl = new Perl5Util();
077:            }
078:
079:            public void testDefaultDTDPrefix() {
080:                XMLPrinter printer = new XMLPrinter(new PrintWriter(buffer),
081:                        configuration);
082:
083:                String xmlDocument = buffer.toString();
084:                assertTrue(xmlDocument + "Missing DTD", perl.match(
085:                        "/DOCTYPE \\S+ SYSTEM \"(.*)\"/", xmlDocument));
086:                assertTrue("DTD \"" + perl.group(1)
087:                        + "\" does not have prefix \""
088:                        + XMLPrinter.DEFAULT_DTD_PREFIX + "\"", perl.group(1)
089:                        .startsWith(XMLPrinter.DEFAULT_DTD_PREFIX));
090:
091:                try {
092:                    reader
093:                            .parse(new InputSource(
094:                                    new StringReader(xmlDocument)));
095:                    fail("Parsed non-existant document\n" + xmlDocument);
096:                } catch (SAXException ex) {
097:                    // Ignore
098:                } catch (IOException ex) {
099:                    fail("Could not read XML Document: " + ex.getMessage()
100:                            + "\n" + xmlDocument);
101:                }
102:            }
103:
104:            public void testSpecificDTDPrefix() {
105:                XMLPrinter printer = new XMLPrinter(new PrintWriter(buffer),
106:                        configuration, XMLPrinter.DEFAULT_ENCODING,
107:                        SPECIFIC_DTD_PREFIX);
108:
109:                String xmlDocument = buffer.toString();
110:                assertTrue(xmlDocument + "Missing DTD", perl.match(
111:                        "/DOCTYPE \\S+ SYSTEM \"(.*)\"/", xmlDocument));
112:                assertTrue("DTD \"" + perl.group(1)
113:                        + "\" does not have prefix \"./etc\"", perl.group(1)
114:                        .startsWith(SPECIFIC_DTD_PREFIX));
115:
116:                try {
117:                    reader
118:                            .parse(new InputSource(
119:                                    new StringReader(xmlDocument)));
120:                    fail("Parsed non-existant document\n" + xmlDocument);
121:                } catch (SAXException ex) {
122:                    // Ignore
123:                } catch (IOException ex) {
124:                    fail("Could not read XML Document: " + ex.getMessage()
125:                            + "\n" + xmlDocument);
126:                }
127:            }
128:
129:            public void testDefaultEncoding() {
130:                XMLPrinter printer = new XMLPrinter(new PrintWriter(buffer),
131:                        configuration);
132:
133:                String xmlDocument = buffer.toString();
134:                assertTrue(xmlDocument + "Missing encoding", perl.match(
135:                        "/encoding=\"([^\"]*)\"/", xmlDocument));
136:                assertEquals("Encoding", XMLPrinter.DEFAULT_ENCODING, perl
137:                        .group(1));
138:
139:                try {
140:                    reader
141:                            .parse(new InputSource(
142:                                    new StringReader(xmlDocument)));
143:                    fail("Parsed non-existant document\n" + xmlDocument);
144:                } catch (SAXException ex) {
145:                    // Ignore
146:                } catch (IOException ex) {
147:                    fail("Could not read XML Document: " + ex.getMessage()
148:                            + "\n" + xmlDocument);
149:                }
150:            }
151:
152:            public void testSpecificEncoding() {
153:                XMLPrinter printer = new XMLPrinter(new PrintWriter(buffer),
154:                        configuration, SPECIFIC_ENCODING,
155:                        XMLPrinter.DEFAULT_DTD_PREFIX);
156:
157:                String xmlDocument = buffer.toString();
158:                assertTrue(xmlDocument + "Missing encoding", perl.match(
159:                        "/encoding=\"([^\"]*)\"/", xmlDocument));
160:                assertEquals("Encoding", SPECIFIC_ENCODING, perl.group(1));
161:
162:                try {
163:                    reader
164:                            .parse(new InputSource(
165:                                    new StringReader(xmlDocument)));
166:                    fail("Parsed non-existant document\n" + xmlDocument);
167:                } catch (SAXException ex) {
168:                    // Ignore
169:                } catch (IOException ex) {
170:                    fail("Could not read XML Document: " + ex.getMessage()
171:                            + "\n" + xmlDocument);
172:                }
173:            }
174:
175:            public void testOneClass() {
176:                MetricsFactory factory = new MetricsFactory("test",
177:                        configuration);
178:
179:                ClassfileLoader loader = new AggregatingClassfileLoader();
180:                loader.load(Collections.singleton(TEST_FILENAME));
181:                loader.getClassfile(TEST_CLASS).accept(
182:                        new MetricsGatherer("test", factory));
183:
184:                XMLPrinter printer = new XMLPrinter(new PrintWriter(buffer),
185:                        configuration, XMLPrinter.DEFAULT_ENCODING,
186:                        SPECIFIC_DTD_PREFIX);
187:                printer.visitMetrics(factory.getProjectMetrics());
188:
189:                String xmlDocument = buffer.toString();
190:
191:                try {
192:                    reader
193:                            .parse(new InputSource(
194:                                    new StringReader(xmlDocument)));
195:                } catch (SAXException ex) {
196:                    fail("Could not parse XML Document: " + ex.getMessage()
197:                            + "\n" + xmlDocument);
198:                } catch (IOException ex) {
199:                    fail("Could not read XML Document: " + ex.getMessage()
200:                            + "\n" + xmlDocument);
201:                }
202:            }
203:
204:            public void error(SAXParseException ex) {
205:                // Ignore
206:            }
207:
208:            public void fatalError(SAXParseException ex) {
209:                // Ignore
210:            }
211:
212:            public void warning(SAXParseException ex) {
213:                // Ignore
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.