Source Code Cross Referenced for TestUtils.java in  » UML » UMLGraph » org » umlgraph » test » 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 » UML » UMLGraph » org.umlgraph.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * UmlGraph class diagram testing framework
003:         *
004:         * Contibuted by Andrea Aime
005:         * (C) Copyright 2005 Diomidis Spinellis
006:         *
007:         * Permission to use, copy, and distribute this software and its
008:         * documentation for any purpose and without fee is hereby granted,
009:         * provided that the above copyright notice appear in all copies and that
010:         * both that copyright notice and this permission notice appear in
011:         * supporting documentation.
012:         *
013:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
014:         * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
015:         * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
016:         *
017:         * $Id$
018:         *
019:         */
020:
021:        package org.umlgraph.test;
022:
023:        import java.io.BufferedReader;
024:        import java.io.File;
025:        import java.io.FileReader;
026:        import java.io.IOException;
027:        import java.io.PrintWriter;
028:        import java.util.List;
029:
030:        /**
031:         * Collection of utility methods used by the test classes
032:         * @author wolf
033:         * 
034:         */
035:        public class TestUtils {
036:
037:            /**
038:             * Simple text file diffing: will tell you if two text files are line by
039:             * line equals, and will stop at the first difference found.
040:             * @throws IOException
041:             */
042:            public static boolean textFilesEquals(PrintWriter pw,
043:                    File refTextFile, File outTextFile) throws IOException {
044:                BufferedReader refReader = null, outReader = null;
045:                String refLine = null, outFile = null;
046:                try {
047:                    pw.println("Performing diff:");
048:                    pw.println("out: " + outTextFile.getAbsolutePath());
049:                    pw.println("ref: " + refTextFile.getAbsolutePath());
050:
051:                    refReader = new BufferedReader(new FileReader(refTextFile));
052:                    outReader = new BufferedReader(new FileReader(outTextFile));
053:
054:                    /*
055:                     * Line by line scan, exit when one file ends or lines are not
056:                     * equal.
057:                     * Ignore the "Generated by javadoc ..." comments, and the
058:                     * "<META NAME="date"" tags
059:                     */
060:                    for (;;) {
061:                        refLine = refReader.readLine();
062:                        outFile = outReader.readLine();
063:                        if (refLine == null || outFile == null) {
064:                            break;
065:                        } else if (refLine.startsWith("<META NAME=\"date\"")) {
066:                            if (!outFile.startsWith("<META NAME=\"date\""))
067:                                break;
068:                        } else if (refLine
069:                                .startsWith("<!-- Generated by javadoc ")) {
070:                            if (!outFile
071:                                    .startsWith("<!-- Generated by javadoc "))
072:                                break;
073:                        } else if (!refLine.equals(outFile)) {
074:                            break;
075:                        }
076:
077:                    }
078:                } finally {
079:                    if (refReader != null)
080:                        refReader.close();
081:                    if (outReader != null)
082:                        outReader.close();
083:                }
084:                // they were equals if both files ended at the same time
085:                boolean equal = refLine == null && outFile == null;
086:                if (equal)
087:                    pw.print("File contents are equal");
088:                else
089:                    pw.println("Differences found\nref: " + refLine + "\nout: "
090:                            + outFile);
091:                pw.println();
092:                pw.println();
093:
094:                return equal;
095:            }
096:
097:            public static boolean dotFilesEqual(PrintWriter pw, String dotPath,
098:                    String refPath) throws IOException {
099:                pw.println("Performing diff:\nout:" + dotPath + "\nref:"
100:                        + refPath);
101:                DotDiff differ = new DotDiff(new File(dotPath), new File(
102:                        refPath));
103:                boolean equal = differ.graphEquals();
104:                if (equal) {
105:                    pw.println("File contents are structurally equal");
106:                } else {
107:                    pw.println("File contents are structurally not equal");
108:                    printList(pw, "# Lines in out but not in ref", differ
109:                            .getExtraLines1());
110:                    printList(pw, "# Lines in ref but not in out", differ
111:                            .getExtraLines2());
112:                    printList(pw, "# Nodes in out but not in ref", differ
113:                            .getNodes1());
114:                    printList(pw, "# Nodes in ref but not in out", differ
115:                            .getNodes2());
116:                    printList(pw, "# Arcs in out but not in ref", differ
117:                            .getArcs1());
118:                    printList(pw, "# Arcs in ref but not in out", differ
119:                            .getArcs2());
120:                }
121:                pw.println("\n\n");
122:                return equal;
123:            }
124:
125:            public static void printList(PrintWriter pw, String message,
126:                    List extraOut) {
127:                if (extraOut.size() > 0) {
128:                    pw.println(message);
129:                    for (Object o : extraOut) {
130:                        pw.println(o);
131:                    }
132:                }
133:            }
134:
135:            /**
136:             * Deletes the content of the folder, eventually in a recursive way (but
137:             * avoids deleting eventual .cvsignore files and CVS folders)
138:             */
139:            public static void cleanFolder(File folder, boolean recurse) {
140:                for (File f : folder.listFiles()) {
141:                    if (f.isDirectory() && !f.getName().equals("CVS")) {
142:                        if (recurse) {
143:                            cleanFolder(f, true);
144:                            if (f.list().length == 0)
145:                                f.delete();
146:                        }
147:                    } else if (!f.getName().equals(".cvsignore")) {
148:                        f.delete();
149:                    }
150:
151:                }
152:
153:            }
154:
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.