Source Code Cross Referenced for TestReport.java in  » Code-Analyzer » JBlanket » csdl » jblanket » report » 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 » JBlanket » csdl.jblanket.report 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package csdl.jblanket.report;
002:
003:        import csdl.jblanket.methodset.MethodSet;
004:
005:        import java.io.File;
006:        import java.io.FileInputStream;
007:        import java.io.FileNotFoundException;
008:        import java.io.IOException;
009:        import java.util.ArrayList;
010:        import java.util.Iterator;
011:
012:        import junit.framework.TestCase;
013:        import junit.framework.TestSuite;
014:        import junit.textui.TestRunner;
015:
016:        import org.apache.tools.ant.util.FileUtils;
017:
018:        import org.jdom.Document;
019:        import org.jdom.Element;
020:        import org.jdom.JDOMException;
021:        import org.jdom.input.SAXBuilder;
022:
023:        /**
024:         * Tests the operations of the jblanketreport Ant task.
025:         * <p>
026:         * If using Ant to execute this test class a 'jblanket.testdir' system property needs to be set
027:         * in the build.xml file.  If running test class from command line, must provide -D argument with
028:         * 'jblanket.testdir' to set the system property.  This value is used in the testFileOperations
029:         * method.
030:         * <p>
031:         * The 'jblanket.dir' system property also needs to be temporarily overrided by setting its
032:         * value in the build.xml file.  This value should be the same as 'jblanket.testdir'.  If
033:         * running test class from command line, must provide -D argument with 'jblanket.testdir'
034:         * to set the system property.  This value is used in the testFileOperations method.
035:         *
036:         * @author Joy M. Agustin
037:         * @version $Id: TestReport.java,v 1.2 2004/11/07 08:53:27 timshadel Exp $
038:         */
039:        public class TestReport extends TestCase {
040:
041:            /** Tag for the report format */
042:            private final String reportFormat = "-reportFormat";
043:
044:            /** Describes if one-line methods should be excluded from the coverage measurement */
045:            private final String excludeOneLineMethods = "-excludeOneLineMethods";
046:            /** Describes if constructors should be excluded from the coverage measurement */
047:            private final String excludeConstructors = "-excludeConstructors";
048:
049:            /** Tag for the totalfile */
050:            private final String totalFile = "-totalFile";
051:            /** Tag for the testfile */
052:            private final String testFile = "-testedFile";
053:            /** Tag for the untestedfile */
054:            private final String untestedFile = "-untestedFile";
055:            /** Tag for the untestedfile */
056:            private final String untestableFile = "-untestableFile";
057:            /** Tag for the onelinefile */
058:            private final String oneLineFile = "-oneLineFile";
059:            /** Tag for the onelinefile */
060:            private final String constructorFile = "-constructorFile";
061:
062:            /** Describes if one-line methods should be excluded from the coverage measurement */
063:            private final boolean excludeOneLineMethodsValue = true;
064:            /** Describes if constructors should be excluded from the coverage measurement */
065:            private final boolean excludeConstructorsValue = true;
066:
067:            /** Frame format for report */
068:            private final String frames = "frames";
069:
070:            /** Name of total methods XML file */
071:            private final String totalXmlFile = "totalMethods.xml";
072:            /** Name of tested methods XML file */
073:            private final String testXmlFile = "testedMethods.xml";
074:            /** Name of untested methods XML file */
075:            private final String untestedXmlFile = "untestedMethods.xml";
076:            /** Name of untested methods XML file */
077:            private final String untestableXmlFile = "untestableMethods.xml";
078:            /** Name of one-line methods XML file */
079:            private final String oneLineXmlFile = "onelineMethods.xml";
080:            /** Name of constructors XML file */
081:            private final String constructorXmlFile = "constructorMethods.xml";
082:
083:            /** Name of intermediate cover XML file */
084:            private final String coverFile1 = "COVER-csdl.foo.TestBar.xml";
085:            /** Name of intermediate cover XML file */
086:            private final String coverFile2 = "COVER-csdl.foo.TestBar2.xml";
087:            /** Name of aggregate cover XML file */
088:            private final String coverFile3 = "COVER-MethodSets.xml";
089:
090:            /** MethodSet for totalFile */
091:            private MethodSet methodSetTotal;
092:            /** MethodSet for testFile */
093:            private MethodSet methodSetTest;
094:            /** MethodSet for untestedFile */
095:            private MethodSet methodSetDiff;
096:            /** MethodSet for oneLineFile */
097:            private MethodSet methodSetOneLine;
098:            /** MethodSet for constructorFile */
099:            private MethodSet methodSetConstructor;
100:
101:            /** Directory containing test data */
102:            private File xmlTestdataDir;
103:            /** Name of directory containing test data */
104:            private final String testdataDirName = "testdata";
105:            /** Name of directory containing XML test data */
106:            private final String xmlTestdataDirName = "xml";
107:            /** Prefix for copied files */
108:            private final String prefix = "test.";
109:
110:            /** Directory for holding JBlanket output */
111:            private String jblanketDir;
112:
113:            /**
114:             * Required for JUnit.
115:             *
116:             * @param name Test case name.
117:             */
118:            public TestReport(String name) {
119:
120:                super (name);
121:            }
122:
123:            /**
124:             * Sets up instance variables for testing.
125:             *
126:             * @throws Exception if cannot move files from /jblanket/testdata/xml directory to
127:             *                   'jblanket.testdir'.
128:             */
129:            public void setUp() throws Exception {
130:
131:                String testdataDir = System.getProperty("jblanket.data.dir");
132:
133:                this .xmlTestdataDir = new File(testdataDir,
134:                        this .xmlTestdataDirName);
135:                this .jblanketDir = System.getProperty("jblanket.testdir");
136:                assertNotNull("Checking for presence of jblanket.testdir.",
137:                        jblanketDir);
138:
139:                // move needed files to jblanket.testdir
140:                FileUtils util = FileUtils.newFileUtils();
141:                util.copyFile(new File(this .xmlTestdataDir, this .totalXmlFile),
142:                        new File(this .jblanketDir, this .totalXmlFile));
143:                util.copyFile(
144:                        new File(this .xmlTestdataDir, this .oneLineXmlFile),
145:                        new File(this .jblanketDir, this .oneLineXmlFile));
146:                util.copyFile(new File(this .xmlTestdataDir,
147:                        this .constructorXmlFile), new File(this .jblanketDir,
148:                        this .constructorXmlFile));
149:                util.copyFile(new File(this .xmlTestdataDir, this .coverFile1),
150:                        new File(this .jblanketDir, this .coverFile1));
151:                util.copyFile(new File(this .xmlTestdataDir, this .coverFile2),
152:                        new File(this .jblanketDir, this .coverFile2));
153:                util.copyFile(new File(this .xmlTestdataDir, this .coverFile3),
154:                        new File(this .jblanketDir, this .prefix
155:                                + this .coverFile3));
156:            }
157:
158:            /**
159:             * Tests the jblanketreport Ant task process.
160:             *
161:             * @throws Exception If problems occur.
162:             */
163:            public void testReport() throws Exception {
164:
165:                // format arguments
166:                ArrayList args = new ArrayList();
167:                args.add(this .reportFormat);
168:                args.add(this .frames);
169:                args.add(this .totalFile);
170:                args.add(this .totalXmlFile);
171:                args.add(this .testFile);
172:                args.add(this .testXmlFile);
173:                args.add(this .untestedFile);
174:                args.add(this .untestedXmlFile);
175:                args.add(this .untestableFile);
176:                args.add(this .untestableXmlFile);
177:                args.add(this .excludeOneLineMethods);
178:                args.add(new Boolean(this .excludeOneLineMethodsValue));
179:                args.add(this .oneLineFile);
180:                args.add(this .oneLineXmlFile);
181:                args.add(this .excludeConstructors);
182:                args.add(new Boolean(this .excludeConstructorsValue));
183:                args.add(this .constructorFile);
184:                args.add(this .constructorXmlFile);
185:
186:                // create the report
187:                JBlanketReport.main(args);
188:
189:                // verify the values of the test, untested, and COVER-MethodSets XML files.
190:                verifyFileContents(new File(this .jblanketDir, this .prefix
191:                        + this .coverFile3), new File(this .jblanketDir,
192:                        this .coverFile3));
193:            }
194:
195:            /**
196:             * Verifies that elements in <code>newFile</code> are the same as <code>oldFile</code>.
197:             *
198:             * @param oldFile the file to compare against.
199:             * @param newFile the file created from testing.
200:             * @throws FileNotFoundException if cannot find either newFile or oldFile.
201:             * @throws JDOMException if cannot read from either newFile or oldFile.
202:             * @throws IOException if cannot create SAXBuilder for either oldFile or newFile.
203:             */
204:            private void verifyFileContents(File oldFile, File newFile)
205:                    throws FileNotFoundException, JDOMException, IOException {
206:
207:                // create inputstreams for the two input files
208:                FileInputStream stream1 = new FileInputStream(oldFile);
209:                FileInputStream stream2 = new FileInputStream(newFile);
210:
211:                // use JDOM to read elements in XML file
212:                SAXBuilder builder1 = new SAXBuilder();
213:                SAXBuilder builder2 = new SAXBuilder();
214:                Document doc1 = builder1.build(stream1);
215:                Document doc2 = builder2.build(stream2);
216:
217:                // load method information
218:                Element rootElement1 = doc1.getRootElement();
219:                Element rootElement2 = doc2.getRootElement();
220:
221:                // check each element in second file
222:                Iterator j = rootElement2.getChildren().iterator();
223:
224:                // check each element in first file
225:                for (Iterator i = rootElement1.getChildren().iterator(); i
226:                        .hasNext();) {
227:                    Element element1 = (Element) i.next();
228:                    Element element2 = (Element) j.next();
229:
230:                    // check the "tested" value
231:                    String value1, value2;
232:                    value1 = element1.getAttributeValue("tested");
233:                    value2 = element2.getAttributeValue("tested");
234:                    assertEquals("Checking tested values", value1, value2);
235:
236:                    // check the "untested" value
237:                    value1 = element1.getAttributeValue("untested");
238:                    value2 = element2.getAttributeValue("untested");
239:                    assertEquals("Checking untested values", value1, value2);
240:
241:                    // check the "oneline" value
242:                    value1 = element1.getAttributeValue("oneline");
243:                    value2 = element2.getAttributeValue("oneline");
244:                    assertEquals("Checking oneline values", value1, value2);
245:                }
246:            }
247:
248:            /**
249:             * Provide stand-alone execution of this test case during initial development.
250:             *
251:             * @param args The command line arguments
252:             */
253:            public static void main(String[] args) {
254:
255:                System.out
256:                        .println("JUnit testing csdl.jblanket.report package.");
257:                //Runs all no-arg methods starting with "test".
258:                TestRunner.run(new TestSuite(TestReport.class));
259:            }
260:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.