Source Code Cross Referenced for EMBTestCaseBase.java in  » J2EE » JOnAS-4.8.6 » com » ibm » emb » junit » 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 » J2EE » JOnAS 4.8.6 » com.ibm.emb.junit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.ibm.emb.junit;
002:
003:        import java.io.File;
004:        import java.io.FileInputStream;
005:        import java.io.IOException;
006:        import java.text.SimpleDateFormat;
007:
008:        import javax.emb.MediaException;
009:
010:        import junit.framework.TestCase;
011:
012:        /**
013:         * This class extends junit.TestCase and is the base class for all EMB test
014:         * classes, allowing for easier implementations of future extensions. Error,
015:         * test, and tracing routines are provided along with the EMBTestConfiguration
016:         * singleton, which provides access to configurable properties needed to run the
017:         * test cases.
018:         */
019:        public class EMBTestCaseBase extends TestCase {
020:
021:            protected EMBTestConfiguration embTestConfig = null;
022:
023:            private static String MEBTESTER_JNDI = "java:comp/env/ejb/MediaEntityLocalTestDriverHome";
024:
025:            private static String TIMESTAMP_PATTERN = "yyyy-MM-dd HH:mm:ss:SS";
026:
027:            /**
028:             * Constructor for EMBTestCaseBase
029:             */
030:            public EMBTestCaseBase(String name) throws MediaException {
031:                super (name);
032:                // always retrieve the EMBTestConfiguration singleton
033:                embTestConfig = EMBTestConfiguration.instance();
034:                File mediaDir = new File(embTestConfig.getMediaDir());
035:                if (!mediaDir.exists() || !mediaDir.isDirectory()) {
036:                    throw new MediaException(
037:                            "Media directory in EMBTestConfiguration property does not exit");
038:                }
039:            }
040:
041:            /**
042:             * initialization of test cases
043:             */
044:            protected void setUp() throws Exception {
045:            }
046:
047:            /**
048:             * freeup resources
049:             */
050:            protected void tearDown() throws Exception {
051:                removeFilesInDir(new File(embTestConfig.getMediaDir()
052:                        + File.separatorChar + "Generated"));
053:                removeFilesInDir(new File(embTestConfig.getMediaDir()
054:                        + File.separatorChar + "export"));
055:
056:                //
057:                //        try {
058:                //                InitialContext ic = new InitialContext();
059:                //                Object ojb = ic.lookup(MEBTESTER_JNDI);
060:                //                mebHome = (MediaEntityLocalTestDriverHome) PortableRemoteObject.narrow(ojb,
061:                //                        MediaEntityLocalTestDriverHome.class);
062:                //            } catch (Exception e) {
063:                //                System.out.println("Exception while cleaning : "+e.getLocalizedMessage());
064:                //            }
065:                //        }
066:                //        // create new instance of MediaEntityLocalTestDriver
067:                //        mebTester = mebHome.create();
068:            }
069:
070:            /**
071:             * Utility function used to write logging information to system out and to a
072:             * log file.
073:             */
074:            public void testLog(String msg) {
075:                SimpleDateFormat df = new SimpleDateFormat(TIMESTAMP_PATTERN);
076:                String timeString = df.format(new java.util.Date());
077:                String message = "[" + timeString + "][" + this .getName()
078:                        + "][LOG][" + this .getClass().getName() + "] :" + msg;
079:                System.out.println(message);
080:                if (embTestConfig.getWriteLog()) {
081:                    try {
082:                        embTestConfig.getLogWriter().write(message);
083:                        embTestConfig.getLogWriter().newLine();
084:                        embTestConfig.getLogWriter().flush();
085:                    } catch (java.io.IOException e) {
086:                        e.printStackTrace();
087:                    }
088:                }
089:            }
090:
091:            /**
092:             * Utility function called at the end of a succeeded testcase Event is then
093:             * written to the test case log file an aditional message can be appended
094:             */
095:            public void succeed(String msg) {
096:                SimpleDateFormat df = new SimpleDateFormat(TIMESTAMP_PATTERN);
097:                String timeString = df.format(new java.util.Date());
098:                String message = "[" + timeString + "][" + this .getName()
099:                        + "][SUCCEEDED][" + this .getClass().getName() + "] :"
100:                        + msg;
101:                System.out.println(message);
102:                if (embTestConfig.getWriteLog()) {
103:                    try {
104:                        embTestConfig.getLogWriter().write(message);
105:                        embTestConfig.getLogWriter().newLine();
106:                        embTestConfig.getLogWriter().flush();
107:                    } catch (java.io.IOException e) {
108:                        e.printStackTrace();
109:                    }
110:                }
111:            }
112:
113:            /**
114:             * Utility Function called at the end of a succeded testcase Event is then
115:             * written to the TestCase log file
116:             */
117:            public void succeed() {
118:                SimpleDateFormat df = new SimpleDateFormat(TIMESTAMP_PATTERN);
119:                String timeString = df.format(new java.util.Date());
120:                String message = "[" + timeString + "][" + this .getName()
121:                        + "][SUCCEEDED][" + this .getClass().getName() + "]";
122:                System.out.println(message);
123:                if (embTestConfig.getWriteLog()) {
124:                    try {
125:                        embTestConfig.getLogWriter().write(message);
126:                        embTestConfig.getLogWriter().newLine();
127:                        embTestConfig.getLogWriter().flush();
128:                    } catch (java.io.IOException e) {
129:                        e.printStackTrace();
130:                    }
131:                }
132:            }
133:
134:            /**
135:             * Utility function used to log a test suite error to system out and to the
136:             * log file
137:             */
138:            public void testError(String msg) {
139:                java.text.SimpleDateFormat df = new java.text.SimpleDateFormat(
140:                        TIMESTAMP_PATTERN);
141:                String timeString = df.format(new java.util.Date());
142:                String message = "[" + timeString + "][ERROR]["
143:                        + this .getName() + "][" + this .getClass().getName()
144:                        + "] :" + msg;
145:                System.out.println(message);
146:                if (embTestConfig.getWriteLog()) {
147:                    try {
148:                        embTestConfig.getLogWriter().write(message);
149:                        embTestConfig.getLogWriter().newLine();
150:                        embTestConfig.getLogWriter().flush();
151:                    } catch (java.io.IOException e) {
152:                        e.printStackTrace();
153:                    }
154:                }
155:            }
156:
157:            /**
158:             * Utility function used to write tracing to system out and to a traceFile.
159:             * For the more common logging there is an additional function testLog
160:             */
161:            public void testTrace(String msg) {
162:                SimpleDateFormat df = new SimpleDateFormat(TIMESTAMP_PATTERN);
163:                String timeString = df.format(new java.util.Date());
164:                String message = "[" + timeString + "]["
165:                        + this .getName().substring(4) + "][TRACE]["
166:                        + this .getClass().getName() + "] :"
167:                        + (msg == null ? "null" : msg);
168:                System.out.println(message);
169:                if (embTestConfig.getWriteTrace()) {
170:                    try {
171:                        embTestConfig.getTraceWriter().write(message);
172:                        embTestConfig.getTraceWriter().newLine();
173:                        embTestConfig.getTraceWriter().flush();
174:                    } catch (java.io.IOException e) {
175:                        e.printStackTrace();
176:                    }
177:                }
178:            }
179:
180:            /**
181:             * removes files in directory used to clean up after tests
182:             */
183:            public static void removeFilesInDir(File srcDir) throws IOException {
184:                File[] srcFiles = srcDir.listFiles();
185:                if (srcFiles == null) {
186:                    EMBStaticHelper
187:                            .testTrace("file name does not point to a directory");
188:                } else {
189:                    for (int i = 0; i < srcFiles.length; i++) {
190:                        if (!(srcFiles[i].isDirectory())) {
191:                            srcFiles[i].delete();
192:                        }
193:                    }
194:                }
195:            }
196:
197:            /**
198:             * returns a byte array of the given file's contents
199:             * @return Returns a byte[]
200:             */
201:            public static byte[] getByteArrayFromFile(File arg)
202:                    throws IOException {
203:                FileInputStream fileInputStream = new FileInputStream(arg);
204:                byte[] retByteArray = new byte[(int) arg.length()];
205:                long inputByte = fileInputStream.read(retByteArray);
206:                fileInputStream.close();
207:                return retByteArray;
208:            }
209:
210:            /**
211:             * writes a known and reported error to the log if flag is enabled
212:             * simplifies tracking of known errors
213:             */
214:            public void logProductError(String msg) {
215:                if (embTestConfig.getLogKnownErrors()) {
216:                    testLog(msg);
217:                }
218:            }
219:
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.