KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > test > SimpleTestRunner


1 /*
2
3    Copyright 2001,2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.test;
19
20 /**
21  * Simple GUI tool to run a <tt>Test</tt>. This tool takes
22  * a class name parameter as an input and provides a GUI to
23  * run an instance of the test. The generated <tt>TestReport</tt>
24  * is printed to the standard output with the
25  * <tt>SimpleTestReportProcessor</tt>
26  *
27  * @author <a HREF="mailto:vhardy@apache.org">Vincent Hardy</a>
28  * @version $Id: SimpleTestRunner.java,v 1.4 2004/08/18 07:16:57 vhardy Exp $
29  */

30 public class SimpleTestRunner {
31     /**
32      * Error Messages.
33      */

34     public static final String JavaDoc ERROR_CLASS_CAST =
35         "Messages.SimpleTestRuner.error.class.cast";
36
37     public static final String JavaDoc ERROR_CLASS_NOT_FOUND =
38         "Messages.SimpleTestRuner.error.class.not.found";
39
40     public static final String JavaDoc ERROR_INSTANTIATION =
41         "Messages.SimpleTestRunner.error.instantiation";
42
43     public static final String JavaDoc ERROR_ILLEGAL_ACCESS =
44         "Messages.SimpleTestRunner.error.illegal.access";
45
46     /**
47      * Usage for this tool
48      */

49     public static final String JavaDoc USAGE
50         = "Messages.SimpleTestRunner.usage";
51
52     public static void main(String JavaDoc args[]) throws Exception JavaDoc{
53         if(args.length < 1){
54             System.err.println(Messages.formatMessage(USAGE, null));
55             System.exit(0);
56         }
57
58         String JavaDoc className = args[0];
59
60         Class JavaDoc cl = null;
61
62         try{
63             cl = Class.forName(className);
64         }catch(ClassNotFoundException JavaDoc e){
65             System.err.println(Messages.formatMessage(ERROR_CLASS_NOT_FOUND,
66                                                       new Object JavaDoc[]{className,
67                                                       e.getClass().getName(),
68                                                       e.getMessage()}));
69             System.exit(0);
70         }
71
72         Test t = null;
73
74         try{
75             t = (Test)cl.newInstance();
76         }catch(ClassCastException JavaDoc e){
77             System.err.println(Messages.formatMessage(ERROR_CLASS_CAST,
78                                                       new Object JavaDoc[]{ className,
79                                                                     e.getClass().getName(),
80                                                                     e.getMessage()
81                                                       }));
82             System.exit(0);
83         }catch(InstantiationException JavaDoc e){
84             System.err.println(Messages.formatMessage(ERROR_INSTANTIATION,
85                                                       new Object JavaDoc[]{ className,
86                                                                     e.getClass().getName(),
87                                                                     e.getMessage() } ));
88             System.exit(0);
89         }catch(IllegalAccessException JavaDoc e){
90             System.err.println(Messages.formatMessage(ERROR_ILLEGAL_ACCESS,
91                                                       new Object JavaDoc[] { className,
92                                                                      e.getClass().getName(),
93                                                                      e.getMessage() }));
94
95             System.exit(0);
96         }
97                                
98
99         //
100
// Run test and process report with simple
101
// text output.
102
//
103
TestReport tr = t.run();
104
105         try{
106             TestReportProcessor p
107                 = new org.apache.batik.test.xml.XMLTestReportProcessor();
108             
109             p.processReport(tr);
110         }catch(TestException e){
111             System.out.println(e.getClass().getName());
112             System.out.println(e.getMessage());
113             Exception JavaDoc source = e.getSourceError();
114             if(source != null) {
115                 System.out.println(source);
116                 System.out.println(source.getMessage());
117                 source.printStackTrace();
118             }
119         }
120         System.exit(1);
121
122     }
123 }
124
Popular Tags