KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > core > test > CoreTest


1 /*
2  * The contents of this file are subject to the Sapient Public License
3  * Version 1.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://carbon.sf.net/License.html.
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is The Carbon Component Framework.
12  *
13  * The Initial Developer of the Original Code is Sapient Corporation
14  *
15  * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16  */

17
18 package org.sape.carbon.core.test;
19
20 import java.lang.reflect.InvocationTargetException JavaDoc;
21 import java.lang.reflect.Method JavaDoc;
22 import java.lang.reflect.Modifier JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.Set JavaDoc;
26
27 import org.sape.carbon.core.bootstrap.test.BootStrapperTest;
28 import org.sape.carbon.core.util.reflection.ClassFinder;
29
30 import junit.framework.Test;
31 import junit.framework.TestCase;
32 import junit.framework.TestSuite;
33
34 /**
35  * Test harness that aggregates all the core test harnesses. This test
36  * harness will search the classpath and find all the classes that
37  * extend TestCase and are in a package below org.sape.carbon.core. It will
38  * then execute the static method <code>Test suite()</code> on each
39  * of these classes. If the suite method does not exists or can not be
40  * called for any reason, the TestCase is skipped. The BootStrapperTest
41  * is called explicitly first because it contains tests that require that
42  * Carbon has not been loaded.
43  *
44  * Copyright 2002 Sapient
45  * @since carbon 1.0
46  * @author Douglas Voet, March 2002
47  * @version $Revision: 1.14 $($Author: dvoet $ / $Date: 2003/05/05 21:21:21 $)
48  */

49 public class CoreTest extends TestCase {
50
51     private static Set JavaDoc excludedTests;
52
53     static {
54         excludedTests = new HashSet JavaDoc();
55         excludedTests.add(BootStrapperTest.class.getName());
56         excludedTests.add(CoreTest.class.getName());
57
58         // Exclude Performance test cases
59
//excludedTests.add(LocalHomeCachePerformanceTest.class.getName());
60
//excludedTests.add(RemoteHomeCachePerformanceTest.class.getName());
61

62     }
63
64     public CoreTest(String JavaDoc name) {
65         super(name);
66     }
67
68     public static Test suite() {
69         TestSuite suite = new TestSuite();
70
71         suite.addTest(BootStrapperTest.suite());
72
73         ClassFinder classFinder = new ClassFinder(TestCase.class, "org.sape.carbon");
74         Set JavaDoc testClasses = classFinder.getClasses();
75
76         ClassFinder perfClassFinder = new ClassFinder(TestCase.class,"PerformanceTest");
77         Set JavaDoc performanceClasses = perfClassFinder.getClasses();
78
79         boolean result = testClasses.removeAll(performanceClasses);
80
81         Iterator JavaDoc testClassIterator = testClasses.iterator();
82         while(testClassIterator.hasNext()) {
83             String JavaDoc testClassName = (String JavaDoc) testClassIterator.next();
84
85             if (!excludedTests.contains(testClassName)) {
86                 try {
87                     Class JavaDoc testClass = Class.forName(testClassName);
88                     Method JavaDoc suiteMethod = testClass.getMethod("suite", null);
89                     if (Modifier.isStatic(suiteMethod.getModifiers())) {
90                         suite.addTest((Test) suiteMethod.invoke(null, null));
91                     }
92
93                     // don't care about any of these exceptions, if they occur
94
// just eat them an move on to the next test case
95
} catch(SecurityException JavaDoc e) {
96                 } catch(IllegalArgumentException JavaDoc e) {
97                 } catch(ClassNotFoundException JavaDoc e) {
98                 } catch(NoSuchMethodException JavaDoc e) {
99                 } catch(IllegalAccessException JavaDoc e) {
100                 } catch(InvocationTargetException JavaDoc e) {
101                 }
102             }
103         }
104
105         return suite;
106     }
107
108 }
109
Popular Tags