Source Code Cross Referenced for Compare.java in  » Portal » Open-Portal » com » sun » portal » samples » asc » tests » 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 » Portal » Open Portal » com.sun.portal.samples.asc.tests 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.sun.portal.samples.asc.tests;
002:
003:        import java.io.*;
004:        import java.util.*;
005:        import junit.framework.*;
006:
007:        /**
008:         * Compares test results with expected and unexpected reference output. Each
009:         * line of the reference file(s) is compared against the test results. A test
010:         * failure is generated if:
011:         * <ul>
012:         * <li> any line in the expected reference file is not found as a substring of
013:         * any line in the test results, or </li>
014:         * <li> any line in the unexpected reference file is found as a substring of any
015:         * line in the test results </li>
016:         * </ul>
017:         */
018:        public class Compare {
019:            public TestCase test = null;
020:
021:            public PrintStream out = null;
022:
023:            /**
024:             * Creates a <code>Compare</code> class with error messages going to
025:             * stdout.
026:             * 
027:             * @param test
028:             *            the test case calling this class
029:             */
030:            public Compare(TestCase test) {
031:                this (test, System.out);
032:            }
033:
034:            /**
035:             * Creates a <code>Compare</code> class.
036:             * 
037:             * @param test
038:             *            the test case calling this class
039:             * @param out
040:             *            where error messages will be sent
041:             */
042:            public Compare(TestCase test, PrintStream out) {
043:                this .test = test;
044:                this .out = out;
045:            }
046:
047:            /**
048:             * Checks the given test results against expected and unexpected output.
049:             * 
050:             * @param result
051:             *            the test results
052:             * @param expected
053:             *            the filename for expected output
054:             * @param unexpected
055:             *            the filename for unexpected output
056:             */
057:            public void check(String result, String expected, String unexpected) {
058:                check(result, expected, true);
059:                check(result, unexpected, false);
060:            }
061:
062:            /**
063:             * Checks the given test results against expected output.
064:             * 
065:             * @param result
066:             *            the test results
067:             * @param filename
068:             *            the filename for expected output
069:             */
070:            public void expected(String result, String filename) {
071:                check(result, filename, true);
072:            }
073:
074:            /**
075:             * Checks the given test results against unexpected output.
076:             * 
077:             * @param result
078:             *            the test results
079:             * @param filename
080:             *            the filename for unexpected output
081:             */
082:            public void unexpected(String result, String filename) {
083:                check(result, filename, false);
084:            }
085:
086:            private void check(String result, String filename, boolean expected) {
087:                // check for null result
088:                if (result == null) {
089:                    TestCase.fail("Result was null!");
090:                }
091:
092:                // open the reference file and tokenize
093:                File file = new File(filename);
094:                String refStr = null;
095:                if (file.exists()) {
096:                    try {
097:                        refStr = TestUtils.getString(new FileInputStream(file));
098:                    } catch (Exception e) {
099:                    }
100:                } else {
101:                    // I guess Luu assumed missing files meant no failure
102:                    // refStr = "";
103:                    TestCase.fail("Reference file " + filename + " missing!");
104:                }
105:                Enumeration reference = new StringTokenizer(refStr, "\n");
106:
107:                // loop through reference strings looking for (un)expected strings
108:                // in the result
109:                boolean failed = false;
110:                StringBuffer failure = new StringBuffer();
111:                while (reference.hasMoreElements()) {
112:                    String next = (String) reference.nextElement();
113:                    // leading & trailing white space ignored
114:                    next = next.trim();
115:                    // compare is irrespective of order
116:                    boolean found = (result.indexOf(next.trim()) != -1);
117:                    if ((expected && !found) || (!expected && found)) {
118:                        if (failed) {
119:                            failure.append("\n");
120:                        } else {
121:                            failed = true;
122:                        }
123:                        failure.append(next);
124:                    }
125:                }
126:
127:                if (failed) {
128:                    fail(result, failure.toString(), expected);
129:                }
130:            }
131:
132:            private void fail(String result, String failure, boolean expected) {
133:                StringBuffer msg = new StringBuffer();
134:                msg.append("\n");
135:                msg.append("----- result:\n");
136:                msg.append(result);
137:                msg.append("\n");
138:                if (expected) {
139:                    msg.append("----- expected:\n");
140:                } else {
141:                    msg.append("----- unexpected:\n");
142:                }
143:                msg.append(failure);
144:
145:                TestCase.fail(msg.toString());
146:            }
147:
148:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.