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 junit.framework.TestResult;
019:
020: import java.io.InputStream;
021: import java.io.OutputStream;
022: import java.io.PrintStream;
023: import java.net.URL;
024: import java.util.Properties;
025: import java.util.Iterator;
026: import java.util.Map;
027:
028: /**
029: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
030: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
031: *
032: * @version $Rev: 634481 $ $Date: 2008-03-06 16:39:07 -0800 $
033: */
034: public class TestRunner extends junit.textui.TestRunner {
035: private static final String helpBase = "/META-INF/org.apache.openejb.cli/";
036:
037: /**
038: * Constructs a TestRunner.
039: */
040: public TestRunner() {
041: this (System.out);
042: }
043:
044: /**
045: * Constructs a TestRunner using the given stream for all the output
046: */
047: public TestRunner(PrintStream writer) {
048: this (new ResultPrinter(writer));
049: }
050:
051: /**
052: * Constructs a TestRunner using the given ResultPrinter all the output
053: */
054: public TestRunner(ResultPrinter printer) {
055: super (printer);
056: }
057:
058: /**
059: * main entry point.
060: */
061: public static void main(String args[]) {
062: if (args.length == 0) {
063: printHelp();
064: } else {
065: if (args[0].equals("--help")) {
066: printHelp();
067:
068: return;
069: } else if (args[0].equals("local")) {
070: runLocalTests();
071: } else if (args[0].equals("remote")) {
072: runRemoteTests();
073: } else if (args[0].equals("http")) {
074: runRemoteHttpTests();
075: } else if (args[0].equals("tomcat")) {
076: runTomcatRemoteHttpTests();
077: } else {
078: printHelp();
079:
080: return;
081: }
082:
083: try {
084: TestRunner aTestRunner = new TestRunner();
085: TestResult r = aTestRunner
086: .start(new String[] { "org.apache.openejb.test.ClientTestSuite" });
087:
088: System.out.println("");
089: System.out
090: .println("_________________________________________________");
091: System.out.println("CLIENT JNDI PROPERTIES");
092: Properties env = TestManager.getServer()
093: .getContextEnvironment();
094: for (Iterator iterator = env.entrySet().iterator(); iterator
095: .hasNext();) {
096: Map.Entry entry = (Map.Entry) iterator.next();
097: String key = (String) entry.getKey();
098: Object value = entry.getValue();
099: System.out.println(key + " = " + value);
100: }
101: System.out
102: .println("_________________________________________________");
103:
104: if (!r.wasSuccessful())
105: System.exit(FAILURE_EXIT);
106: System.exit(SUCCESS_EXIT);
107: } catch (Exception e) {
108: System.err.println(e.getMessage());
109: System.exit(EXCEPTION_EXIT);
110: }
111: }
112: }
113:
114: private static void runLocalTests() {
115: setDefault("openejb.test.server",
116: "org.apache.openejb.test.IvmTestServer");
117: setDefault("openejb.test.database",
118: "org.apache.openejb.test.HsqldbTestDatabase");
119:
120: System.out
121: .println("_________________________________________________");
122: System.out
123: .println("|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|\n");
124: System.out
125: .println("Running EJB compliance tests on IntraVM Server");
126: System.out
127: .println("_________________________________________________");
128: }
129:
130: private static void setDefault(String key, String value) {
131: value = System.getProperty(key, value);
132: System.setProperty(key, value);
133: }
134:
135: private static void runRemoteTests() {
136: setDefault("openejb.test.server",
137: "org.apache.openejb.test.RemoteTestServer");
138: setDefault("openejb.test.database",
139: "org.apache.openejb.test.HsqldbTestDatabase");
140:
141: System.out
142: .println("_________________________________________________");
143: System.out
144: .println("|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|\n");
145: System.out
146: .println("Running EJB compliance tests on Remote Server");
147: System.out
148: .println("_________________________________________________");
149: }
150:
151: private static void runRemoteHttpTests() {
152: setDefault("openejb.test.server",
153: "org.apache.openejb.test.RemoteHttpTestServer");
154: setDefault("openejb.test.database",
155: "org.apache.openejb.test.HsqldbTestDatabase");
156:
157: System.out
158: .println("_________________________________________________");
159: System.out
160: .println("|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|\n");
161: System.out
162: .println("Running EJB compliance tests on HTTP/Remote Server");
163: System.out
164: .println("_________________________________________________");
165: }
166:
167: private static void runTomcatRemoteHttpTests() {
168: setDefault("openejb.test.server", TomcatRemoteTestServer.class
169: .getName());
170: setDefault("openejb.test.database",
171: "org.apache.openejb.test.HsqldbTestDatabase");
172: setDefault("openejb.test.servlets", "true");
173:
174: System.out
175: .println("_________________________________________________");
176: System.out
177: .println("|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|\n");
178: System.out
179: .println("Running EJB compliance tests on HTTP/Tomcat Server");
180: System.out
181: .println("_________________________________________________");
182: }
183:
184: private static void printHelp() {
185: String header = "OpenEJB Compliance Tests ";
186: try {
187: InputStream is = TestRunner.class
188: .getResourceAsStream("/META-INF/openejb-version.properties");
189: Properties versionInfo = new Properties();
190: versionInfo.load(is);
191: header += versionInfo.get("version");
192: } catch (java.io.IOException e) {
193: }
194:
195: System.out.println(header);
196:
197: // Internationalize this
198: try {
199: InputStream in = TestRunner.class
200: .getResourceAsStream(helpBase + "test.help");
201: int b = in.read();
202: while (b != -1) {
203: System.out.write(b);
204: b = in.read();
205: }
206: } catch (java.io.IOException e) {
207: }
208: }
209:
210: public TestResult start(String args[]) throws Exception {
211: TestResult result = null;
212: try {
213:
214: TestManager.init(null);
215: TestManager.start();
216: } catch (Exception e) {
217: System.out
218: .println("Cannot initialize the test environment: "
219: + e.getClass().getName() + " "
220: + e.getMessage());
221: e.printStackTrace();
222: // System.exit(-1);
223: throw e;
224: }
225:
226: try {
227: result = super .start(args);
228: } catch (Exception ex) {
229: } finally {
230: try {
231: TestManager.stop();
232: } catch (Exception e) {
233: ; // ignore it
234: }
235: }
236: // System.exit(0);
237: return result;
238: }
239:
240: private static final class Pipe implements Runnable {
241:
242: private final InputStream is;
243:
244: private final OutputStream out;
245:
246: private Pipe(InputStream is, OutputStream out) {
247:
248: super ();
249:
250: this .is = is;
251:
252: this .out = out;
253:
254: }
255:
256: public void run() {
257:
258: try {
259:
260: int i = is.read();
261:
262: out.write(i);
263:
264: while (i != -1) {
265:
266: i = is.read();
267:
268: out.write(i);
269:
270: }
271:
272: } catch (Exception e) {
273:
274: e.printStackTrace();
275:
276: }
277:
278: }
279:
280: }
281: }
|