KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > common > launch > TestLauncher


1 package org.jacorb.test.common.launch;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 2005 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
21  * MA 02110-1301, USA.
22  */

23
24 import java.io.*;
25 import java.util.*;
26 import java.text.*;
27
28 import org.jacorb.test.common.*;
29
30 /**
31  * This is the main class for launching regression tests. It takes care
32  * of launching the client side (on which the JUnit tests are actually executed)
33  * against an appropriate JacORB version. The client-side code itself
34  * launches servers when appropriate. This is the invocation syntax:
35  *
36  * java [ -Djacorb.test.client.version=CLIENT_VERSION ]
37  * [ -Djacorb.test.server.version=SERVER_VERSION ]
38  * [ -Djacorb.test.coverage=on/off ]
39  * org.jacorb.test.common.launch.TestLauncher
40  * TESTSUITE
41  *
42  * Here, CLIENT_VERSION and SERVER_VERSION are ids of available JacORB
43  * installations, as specified in the file
44  * $JACORB_HOME/test/regression/test.properties.
45  * The third optional property, jacorb.test.coverage, specifies whether
46  * coverage information should be collected during this test run or not.
47  * The final argument, after the name of the class itself, is the name
48  * of the TESTSUITE to execute (e.g. org.jacorb.test.AllTest).
49  *
50  * @author Andre Spiegel spiegel@gnu.org
51  * @version $Id: TestLauncher.java,v 1.2 2005/05/16 17:34:06 andre.spiegel Exp $
52  */

53 public class TestLauncher
54 {
55     private static String JavaDoc[] args = null;
56     private static PrintWriter outFile = null;
57     private static Date testDate = new java.util.Date JavaDoc();
58     
59     private static DateFormat idFormatter =
60         new SimpleDateFormat ("yyyy-MM-dd.HH-mm-ss");
61     
62     private static DateFormat dateStringFormatter =
63         new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss Z");
64     
65     private static class Listener extends Thread JavaDoc
66     {
67         private BufferedReader in = null;
68         
69         public Listener (InputStream in)
70         {
71             this.in = new BufferedReader (new InputStreamReader (in));
72         }
73         
74         public void run()
75         {
76             try
77             {
78                 while (true)
79                 {
80                     String JavaDoc line = in.readLine();
81                     if (line == null) break;
82                     System.out.println (line);
83                     outFile.println (line);
84                 }
85             }
86             catch (Exception JavaDoc ex)
87             {
88                 System.out.println ("exception reading from test client: "
89                                     + ex.toString());
90             }
91         }
92         
93     }
94     
95     public static void printTestHeader (PrintWriter out)
96     {
97         out.println ("-------------------------------------------------------------------------------");
98         out.println();
99         out.println (" JacORB Regression Test Report");
100         out.println();
101         out.println (" Suite: " + getSuiteName());
102         out.println ("");
103         out.println (" Date: " + getTestDateString());
104         out.println (" User: " + getTestUser());
105         out.println (" Platform: " + getTestPlatform());
106         out.println();
107         out.println (" Client Version: " + getClientVersion());
108         out.println (" Server Version: " + getServerVersion());
109         out.println (" Coverage: " + (getCoverage() ? "yes" : "no"));
110         out.println();
111         out.println ("-------------------------------------------------------------------------------");
112     }
113     
114     public static void printTestHeader (PrintStream out)
115     {
116         PrintWriter x = new PrintWriter (out);
117         printTestHeader(x);
118         x.flush();
119     }
120     
121     public static String JavaDoc getSuiteName()
122     {
123         return args[0];
124     }
125     
126     public static Date getTestDate()
127     {
128         return testDate;
129     }
130     
131     public static String JavaDoc getTestID()
132     {
133         return idFormatter.format (getTestDate());
134     }
135     
136     public static String JavaDoc getTestDateString()
137     {
138         return dateStringFormatter.format (getTestDate());
139     }
140     
141     public static boolean getCoverage()
142     {
143         String JavaDoc cs = System.getProperty("jacorb.test.coverage", "false");
144         return cs.equals("true") || cs.equals("on") || cs.equals("yes");
145     }
146
147     public static String JavaDoc getClientVersion()
148     {
149         return System.getProperty ("jacorb.test.client.version", "cvs");
150     }
151     
152     public static String JavaDoc getServerVersion()
153     {
154         return System.getProperty ("jacorb.test.server.version", "cvs");
155     }
156     
157     public static String JavaDoc getTestUser()
158     {
159         return System.getProperty ("user.name", "<unknown>");
160     }
161     
162     public static String JavaDoc getTestPlatform()
163     {
164         return "java " + System.getProperty ("java.version")
165              + " (" + System.getProperty ("java.vendor") + ") "
166              + System.getProperty ("os.name") + " "
167              + System.getProperty ("os.version") + " ("
168              + System.getProperty ("os.arch") + ")";
169     }
170     
171     public static String JavaDoc getOutFilename()
172     {
173         String JavaDoc dir = TestUtils.testHome() + "/output/" + getTestID();
174         File dirF = new File (dir);
175         if (!dirF.exists()) dirF.mkdir();
176         return dir + "/report.txt";
177     }
178     
179     public static void main(String JavaDoc[] args) throws Exception JavaDoc
180     {
181         TestLauncher.args = args;
182         outFile = new PrintWriter (new FileWriter (getOutFilename()));
183         printTestHeader (outFile);
184         printTestHeader (System.out);
185         
186         String JavaDoc mainClass = "junit.textui.TestRunner";
187
188         String JavaDoc classpath = TestUtils.testHome() + "/classes:"
189                          + TestUtils.testHome() + "/lib/junit.jar:"
190                          + TestUtils.testHome() + "/lib/easymock-1.1.jar";
191
192         Properties props = new Properties();
193         props.put("jacorb.test.id", getTestID());
194         props.put("jacorb.test.coverage", getCoverage() ? "true" : "false");
195         props.put("jacorb.test.client.version", getClientVersion());
196         props.put("jacorb.test.server.version", getServerVersion());
197         props.put("javax.rmi.CORBA.UtilClass",
198                   "org.jacorb.test.orb.rmi.FixSunDelegateBug");
199
200         JacORBLauncher launcher = JacORBLauncher.getLauncher
201         (
202             getClientVersion(), getCoverage()
203         );
204
205         if (getCoverage())
206             props.put ("emma.coverage.out.file",
207                        launcher.getJacorbHome()
208                        + "/test/regression/output/"
209                        + getTestID() + "/coverage-client.ec");
210         
211         Process JavaDoc p = launcher.launch(classpath, props, mainClass, args);
212
213         Listener outL = new Listener(p.getInputStream());
214         outL.start();
215         Listener errL = new Listener(p.getErrorStream());
216         errL.start();
217
218         p.waitFor();
219         
220         outFile.close();
221     }
222 }
223
Popular Tags