Source Code Cross Referenced for TestManager.java in  » J2EE » openejb3 » org » apache » openejb » 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 » J2EE » openejb3 » org.apache.openejb.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */package org.apache.openejb.test;
017:
018:        import java.io.File;
019:        import java.io.FileInputStream;
020:        import java.util.Properties;
021:        import java.security.PrivilegedAction;
022:        import java.security.AccessController;
023:
024:        /**
025:         * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
026:         * 
027:         * @version $Rev: 636618 $ $Date: 2008-03-12 20:20:58 -0700 $
028:         */
029:        public class TestManager {
030:
031:            private static TestServer server;
032:            private static TestDatabase database;
033:            private static TestJms jms;
034:            private static boolean warn = true;
035:
036:            // TODO: Move it to a central place where all system properties are managed in a unified way
037:            final static String TESTSUITE_PROPERTY_FILENAME = "openejb.testsuite.properties";
038:            final static String TEST_SERVER_CLASSNAME = "openejb.test.server";
039:            final static String TEST_DATABASE_CLASSNAME = "openejb.test.database";
040:            final static String TEST_JMS_CLASSNAME = "openejb.test.jms";
041:
042:            public static void init(String propertiesFileName) throws Exception {
043:                Properties props = null;
044:
045:                try {
046:                    props = new Properties(System.getProperties());
047:                    warn = props.getProperty("openejb.test.nowarn") == null;
048:                } catch (SecurityException e) {
049:                    throw new IllegalArgumentException(
050:                            "Cannot access the system properties: "
051:                                    + e.getClass().getName() + " "
052:                                    + e.getMessage());
053:                }
054:
055:                if (propertiesFileName == null) {
056:                    try {
057:                        propertiesFileName = System
058:                                .getProperty(TESTSUITE_PROPERTY_FILENAME);
059:                        if (propertiesFileName != null) {
060:                            props.putAll(getProperties(propertiesFileName));
061:                        }
062:
063:                    } catch (SecurityException e) {
064:                        throw new IllegalArgumentException(
065:                                "Cannot access the system property \""
066:                                        + TESTSUITE_PROPERTY_FILENAME + "\": "
067:                                        + e.getClass().getName() + " "
068:                                        + e.getMessage());
069:                    }
070:                } else {
071:                    props.putAll(getProperties(propertiesFileName));
072:                }
073:                initServer(props);
074:                initDatabase(props);
075:                initJms(props);
076:            }
077:
078:            public static void start() throws Exception {
079:                try {
080:                    if (server != null) {
081:                        server.start();
082:                    }
083:                } catch (Exception e) {
084:                    if (warn)
085:                        System.out
086:                                .println("Cannot start the test server: "
087:                                        + e.getClass().getName() + " "
088:                                        + e.getMessage());
089:                    throw e;
090:                }
091:                try {
092:                    if (database != null) {
093:                        database.start();
094:                    }
095:                } catch (Exception e) {
096:                    if (warn)
097:                        System.out
098:                                .println("Cannot start the test database: "
099:                                        + e.getClass().getName() + " "
100:                                        + e.getMessage());
101:                    throw e;
102:                }
103:            }
104:
105:            public static void stop() throws Exception {
106:                try {
107:                    if (database != null) {
108:                        database.stop();
109:                    }
110:                } catch (Exception e) {
111:                    if (warn)
112:                        System.out
113:                                .println("Cannot stop the test database: "
114:                                        + e.getClass().getName() + " "
115:                                        + e.getMessage());
116:                    throw e;
117:                }
118:                try {
119:                    if (server != null) {
120:                        server.stop();
121:                    }
122:                } catch (Exception e) {
123:                    if (warn)
124:                        System.out
125:                                .println("Cannot stop the test server 2: "
126:                                        + e.getClass().getName() + " "
127:                                        + e.getMessage());
128:                    throw e;
129:                }
130:            }
131:
132:            private static Properties getProperties(String fileName)
133:                    throws Exception {
134:                File file = new File(fileName);
135:                file = file.getAbsoluteFile();
136:                Properties props = (Properties) System.getProperties().clone();
137:                props.load(new FileInputStream(file));
138:                return props;
139:            }
140:
141:            private static ClassLoader getContextClassLoader() {
142:                return AccessController
143:                        .doPrivileged(new PrivilegedAction<ClassLoader>() {
144:                            public ClassLoader run() {
145:                                return Thread.currentThread()
146:                                        .getContextClassLoader();
147:                            }
148:                        });
149:            }
150:
151:            private static void initServer(Properties props) {
152:                try {
153:
154:                    String className = props.getProperty(TEST_SERVER_CLASSNAME);
155:                    if (className == null) {
156:                        throw new IllegalArgumentException(
157:                                "Must specify a test server by setting its class name using the system property \""
158:                                        + TEST_SERVER_CLASSNAME + "\"");
159:                    }
160:                    ClassLoader cl = getContextClassLoader();
161:                    Class<?> testServerClass = Class.forName(className, true,
162:                            cl);
163:                    server = (TestServer) testServerClass.newInstance();
164:                    server.init(props);
165:                } catch (Exception e) {
166:                    if (warn)
167:                        e.printStackTrace();
168:                    if (warn)
169:                        System.out
170:                                .println("Cannot instantiate or initialize the test server: "
171:                                        + e.getClass().getName()
172:                                        + " "
173:                                        + e.getMessage());
174:                    throw new RuntimeException(
175:                            "Cannot instantiate or initialize the test server: "
176:                                    + e.getClass().getName() + " "
177:                                    + e.getMessage(), e);
178:                }
179:            }
180:
181:            private static void initDatabase(Properties props) {
182:                try {
183:                    String className = props
184:                            .getProperty(TEST_DATABASE_CLASSNAME);
185:                    if (className == null)
186:                        throw new IllegalArgumentException(
187:                                "Must specify a test database by setting its class name  using the system property \""
188:                                        + TEST_DATABASE_CLASSNAME + "\"");
189:                    ClassLoader cl = getContextClassLoader();
190:                    Class<?> testDatabaseClass = Class.forName(className, true,
191:                            cl);
192:                    database = (TestDatabase) testDatabaseClass.newInstance();
193:                    database.init(props);
194:                } catch (Exception e) {
195:                    if (warn)
196:                        System.out
197:                                .println("Cannot instantiate or initialize the test database: "
198:                                        + e.getClass().getName()
199:                                        + " "
200:                                        + e.getMessage());
201:                    throw new RuntimeException(
202:                            "Cannot instantiate or initialize the test database: "
203:                                    + e.getClass().getName() + " "
204:                                    + e.getMessage(), e);
205:                }
206:            }
207:
208:            private static void initJms(Properties props) {
209:                try {
210:                    String className = props.getProperty(TEST_JMS_CLASSNAME);
211:                    if (className == null)
212:                        className = "org.apache.openejb.test.ActiveMqTestJms";
213:                    ClassLoader cl = getContextClassLoader();
214:                    Class<?> testJmsClass = Class.forName(className, true, cl);
215:                    jms = (TestJms) testJmsClass.newInstance();
216:                    jms.init(props);
217:                } catch (Exception e) {
218:                    if (warn)
219:                        System.out
220:                                .println("Cannot instantiate or initialize the test jms: "
221:                                        + e.getClass().getName()
222:                                        + " "
223:                                        + e.getMessage());
224:                    throw new RuntimeException(
225:                            "Cannot instantiate or initialize the test jms: "
226:                                    + e.getClass().getName() + " "
227:                                    + e.getMessage(), e);
228:                }
229:            }
230:
231:            public static TestServer getServer() {
232:                return server;
233:            }
234:
235:            public static TestDatabase getDatabase() {
236:                return database;
237:            }
238:
239:            public static TestJms getJms() {
240:                return jms;
241:            }
242:
243:            public static Properties getContextEnvironment() {
244:                return server.getContextEnvironment();
245:            }
246:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.