1 45 package org.openejb.test; 46 47 import java.io.File ; 48 import java.io.InputStream ; 49 import java.io.OutputStream ; 50 import java.io.PrintStream ; 51 import java.net.URL ; 52 import java.util.Properties ; 53 import java.util.Iterator ; 54 import java.util.Map ; 55 56 import junit.framework.TestResult; 57 58 import org.openejb.util.JarUtils; 59 60 65 public class TestRunner extends junit.textui.TestRunner { 66 private static final String helpBase = "META-INF/org.openejb.cli/"; 67 68 71 public TestRunner() { 72 this(System.out); 73 } 74 75 78 public TestRunner(PrintStream writer) { 79 this(new ResultPrinter(writer)); 80 } 81 82 85 public TestRunner(ResultPrinter printer) { 86 super(printer); 87 } 88 89 92 public static void main(String args[]) { 93 if (args.length == 0) { 94 printHelp(); 95 } else { 96 if (args[0].equals("--help")) { 97 printHelp(); 98 99 return; 100 } else if (args[0].equals("local")) { 101 runLocalTests(); 102 } else if (args[0].equals("remote")) { 103 runRemoteTests(); 104 } else if (args[0].equals("http")) { 105 runRemoteHttpTests(); 106 } else if (args[0].equals("tomcat")) { 107 runTomcatRemoteHttpTests(); 108 } else { 109 printHelp(); 110 111 return; 112 } 113 114 try { 115 TestRunner aTestRunner = new TestRunner(); 116 TestResult r = aTestRunner 117 .start(new String [] { "org.openejb.test.ClientTestSuite" }); 118 119 System.out.println(""); 120 System.out.println("_________________________________________________"); 121 System.out.println("CLIENT JNDI PROPERTIES"); 122 Properties env = TestManager.getServer().getContextEnvironment(); 123 for (Iterator iterator = env.entrySet().iterator(); iterator.hasNext();) { 124 Map.Entry entry = (Map.Entry ) iterator.next(); 125 String key = (String ) entry.getKey(); 126 Object value = entry.getValue(); 127 System.out.println(key+" = "+value); 128 } 129 System.out.println("_________________________________________________"); 130 131 if (!r.wasSuccessful()) 132 System.exit(FAILURE_EXIT); 133 System.exit(SUCCESS_EXIT); 134 } catch (Exception e) { 135 System.err.println(e.getMessage()); 136 System.exit(EXCEPTION_EXIT); 137 } 138 139 140 } 141 } 142 143 private static void runLocalTests() { 144 System.setProperty("openejb.test.server", 145 "org.openejb.test.IvmTestServer"); 146 System.setProperty("openejb.test.database", 147 "org.openejb.test.InstantDbTestDatabase"); 148 149 System.out.println("_________________________________________________"); 150 System.out 151 .println("|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|\n"); 152 System.out.println("Running EJB compliance tests on IntraVM Server"); 153 System.out.println("_________________________________________________"); 154 } 155 156 private static void runRemoteTests() { 157 System.setProperty("openejb.test.server", 158 "org.openejb.test.RemoteTestServer"); 159 System.setProperty("openejb.test.database", 160 "org.openejb.test.InstantDbTestDatabase"); 161 162 System.out.println("_________________________________________________"); 163 System.out 164 .println("|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|\n"); 165 System.out.println("Running EJB compliance tests on Remote Server"); 166 System.out.println("_________________________________________________"); 167 } 168 169 private static void runRemoteHttpTests() { 170 System.setProperty("openejb.test.server", 171 "org.openejb.test.RemoteHttpTestServer"); 172 System.setProperty("openejb.test.database", 173 "org.openejb.test.InstantDbTestDatabase"); 174 175 System.out.println("_________________________________________________"); 176 System.out 177 .println("|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|\n"); 178 System.out.println("Running EJB compliance tests on HTTP/Remote Server"); 179 System.out.println("_________________________________________________"); 180 } 181 182 private static void runTomcatRemoteHttpTests() { 183 System.setProperty("openejb.test.server", TomcatRemoteTestServer.class.getName()); 184 System.setProperty("openejb.test.database", "org.openejb.test.InstantDbTestDatabase"); 185 186 System.out.println("_________________________________________________"); 187 System.out 188 .println("|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|\n"); 189 System.out.println("Running EJB compliance tests on HTTP/Tomcat Server"); 190 System.out.println("_________________________________________________"); 191 } 192 193 private static void printHelp() { 194 String header = "OpenEJB Compliance Tests "; 195 try { 196 JarUtils.setHandlerSystemProperty(); 197 Properties versionInfo = new Properties (); 198 versionInfo.load(new URL ("resource:/openejb-version.properties").openConnection().getInputStream()); 199 header += versionInfo.get("version"); 200 } catch (java.io.IOException e) { 201 } 202 203 System.out.println(header); 204 205 try { 207 InputStream in = Thread.currentThread().getContextClassLoader() 208 .getResource(helpBase + "test.help").openConnection() 209 .getInputStream(); 210 211 int b = in.read(); 212 while (b != -1) { 213 System.out.write(b); 214 b = in.read(); 215 } 216 } catch (java.io.IOException e) { 217 } 218 } 219 220 public TestResult start(String args[]) throws Exception { 221 TestResult result = null; 222 try { 223 224 TestManager.init(null); 225 TestManager.start(); 226 } catch (Exception e) { 227 System.out.println("Cannot initialize the test environment: " 228 + e.getClass().getName() + " " + e.getMessage()); 229 throw e; 232 } 233 234 try { 235 result = super.start(args); 236 } catch (Exception ex) { 237 } finally { 238 try { 239 TestManager.stop(); 240 } catch (Exception e) { 241 ; } 243 } 244 return result; 246 } 247 248 private static final class Pipe implements Runnable { 249 250 private final InputStream is; 251 252 private final OutputStream out; 253 254 private Pipe(InputStream is, OutputStream out) { 255 256 super(); 257 258 this.is = is; 259 260 this.out = out; 261 262 } 263 264 public void run() { 265 266 try { 267 268 int i = is.read(); 269 270 out.write(i); 271 272 while (i != -1) { 273 274 i = is.read(); 275 276 out.write(i); 277 278 } 279 280 } catch (Exception e) { 281 282 e.printStackTrace(); 283 284 } 285 286 } 287 288 } 289 } 290 | Popular Tags |