Source Code Cross Referenced for MakumbaJspTestCase.java in  » Web-Framework » makumba » test » util » 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 » Web Framework » makumba » test.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package test.util;
002:
003:        import java.io.BufferedReader;
004:        import java.io.BufferedWriter;
005:        import java.io.File;
006:        import java.io.FileNotFoundException;
007:        import java.io.FileReader;
008:        import java.io.FileWriter;
009:        import java.io.IOException;
010:        import java.io.StringReader;
011:
012:        import junit.extensions.TestSetup;
013:        import junit.framework.Test;
014:
015:        import org.apache.cactus.JspTestCase;
016:
017:        /**
018:         * Utility class which enables it to quickly write tests based on the execution of a JSP. Since we know the expected
019:         * result, we can fetch this result and store it into a file, and then compare the next executions of the test against
020:         * this file.
021:         * 
022:         * @author Manuel Gay
023:         * @version $Id: MakumbaJSPTest.java,v 1.1 25.09.2007 16:08:26 Manuel Exp $
024:         */
025:        public class MakumbaJspTestCase extends JspTestCase {
026:
027:            private static final class Suite extends TestSetup {
028:                private Suite(Test arg0) {
029:                    super (arg0);
030:                }
031:            }
032:
033:            /**
034:             * Compares a test output to its stored (expected) result. The method detects automatically the name of the test
035:             * based on the invoking method, so all there's to do is to pass it the new result. TODO this should be much more
036:             * verbose
037:             * 
038:             * @param result
039:             *            the new result, from the currently running test
040:             * @return <code>true</code> if this worked out, <code>false</code> otherwise.
041:             * @throws FileNotFoundException in case the comparison basis file is not found, this indicates it
042:             */
043:            protected boolean compareTest(String result) throws Exception {
044:
045:                boolean testOk = true;
046:
047:                // first we retrieve the name of the method which calls us
048:                String testName = new Throwable().fillInStackTrace()
049:                        .getStackTrace()[1].getMethodName();
050:
051:                // based on the method name, we retrieve the file used as comparison basis
052:
053:                File f = new File("classes/test/expected/" + testName + ".txt");
054:
055:                if (!f.exists())
056:                    throw new Exception(
057:                            "Couldn't find the comparison file in classes/test/expected/"
058:                                    + testName
059:                                    + ".txt - create it first using the fetchValidTestResult(String result) method!");
060:
061:                String fileIntoString = "";
062:                BufferedReader fileIn = null;
063:                BufferedReader stringIn = null;
064:
065:                try {
066:                    fileIn = new BufferedReader(new FileReader(f));
067:                    stringIn = new BufferedReader(new StringReader(result));
068:                    String strFile = "";
069:                    String strStr = "";
070:
071:                    while ((strFile = fileIn.readLine()) != null) {
072:                        fileIntoString += strFile + "\n";
073:                        strStr = stringIn.readLine();
074:                        testOk = strFile.equals(strStr);
075:                    }
076:
077:                } catch (IOException e) {
078:                    // TODO Auto-generated catch block
079:                    e.printStackTrace();
080:                } finally {
081:                    try {
082:                        fileIn.close();
083:                    } catch (IOException e) {
084:                        // TODO Auto-generated catch block
085:                        e.printStackTrace();
086:                    }
087:                }
088:
089:                if (!testOk) {
090:                    System.out.println("************************ Test "
091:                            + testName + " failed! ************************");
092:                    System.out
093:                            .println("======================== Expected ========================");
094:                    System.out.println(fileIntoString);
095:                    System.out
096:                            .println("======================== Actual ========================");
097:                    System.out.println(result);
098:
099:                }
100:
101:                return testOk;
102:            }
103:
104:            /**
105:             * Method that helps to fetch the result of a test, on the first run. Just pass it the expected result, it will
106:             * store it automatically. Don't forget to remove it after the first time!
107:             * 
108:             * @param output
109:             *            the result (HTML code) of the page that was ran correctly.
110:             * @param record TODO
111:             */
112:            protected void fetchValidTestResult(String output, boolean record) {
113:
114:                if (!record)
115:                    return;
116:
117:                // first we retrieve the name of the method which calls us
118:                String testName = new Throwable().fillInStackTrace()
119:                        .getStackTrace()[1].getMethodName();
120:
121:                File f = new File("classes/test/expected/" + testName + ".txt");
122:                if (!f.exists())
123:                    try {
124:                        f.createNewFile();
125:                    } catch (IOException e1) {
126:                        // TODO Auto-generated catch block
127:                        e1.printStackTrace();
128:                    }
129:
130:                try {
131:                    BufferedWriter out = new BufferedWriter(new FileWriter(f));
132:                    out.write(output);
133:                    out.close();
134:                } catch (IOException e) {
135:                    e.printStackTrace();
136:                }
137:            }
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.