001: /*
002: * The contents of this file are subject to the Sapient Public License
003: * Version 1.0 (the "License"); you may not use this file except in compliance
004: * with the License. You may obtain a copy of the License at
005: * http://carbon.sf.net/License.html.
006: *
007: * Software distributed under the License is distributed on an "AS IS" basis,
008: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
009: * the specific language governing rights and limitations under the License.
010: *
011: * The Original Code is The Carbon Component Framework.
012: *
013: * The Initial Developer of the Original Code is Sapient Corporation
014: *
015: * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
016: */
017:
018: package org.sape.carbon.core.test;
019:
020: import java.lang.reflect.InvocationTargetException;
021: import java.lang.reflect.Method;
022: import java.lang.reflect.Modifier;
023: import java.util.HashSet;
024: import java.util.Iterator;
025: import java.util.Set;
026:
027: import org.sape.carbon.core.bootstrap.test.BootStrapperTest;
028: import org.sape.carbon.core.util.reflection.ClassFinder;
029:
030: import junit.framework.Test;
031: import junit.framework.TestCase;
032: import junit.framework.TestSuite;
033:
034: /**
035: * Test harness that aggregates all the core test harnesses. This test
036: * harness will search the classpath and find all the classes that
037: * extend TestCase and are in a package below org.sape.carbon.core. It will
038: * then execute the static method <code>Test suite()</code> on each
039: * of these classes. If the suite method does not exists or can not be
040: * called for any reason, the TestCase is skipped. The BootStrapperTest
041: * is called explicitly first because it contains tests that require that
042: * Carbon has not been loaded.
043: *
044: * Copyright 2002 Sapient
045: * @since carbon 1.0
046: * @author Douglas Voet, March 2002
047: * @version $Revision: 1.14 $($Author: dvoet $ / $Date: 2003/05/05 21:21:21 $)
048: */
049: public class CoreTest extends TestCase {
050:
051: private static Set excludedTests;
052:
053: static {
054: excludedTests = new HashSet();
055: excludedTests.add(BootStrapperTest.class.getName());
056: excludedTests.add(CoreTest.class.getName());
057:
058: // Exclude Performance test cases
059: //excludedTests.add(LocalHomeCachePerformanceTest.class.getName());
060: //excludedTests.add(RemoteHomeCachePerformanceTest.class.getName());
061:
062: }
063:
064: public CoreTest(String name) {
065: super (name);
066: }
067:
068: public static Test suite() {
069: TestSuite suite = new TestSuite();
070:
071: suite.addTest(BootStrapperTest.suite());
072:
073: ClassFinder classFinder = new ClassFinder(TestCase.class,
074: "org.sape.carbon");
075: Set testClasses = classFinder.getClasses();
076:
077: ClassFinder perfClassFinder = new ClassFinder(TestCase.class,
078: "PerformanceTest");
079: Set performanceClasses = perfClassFinder.getClasses();
080:
081: boolean result = testClasses.removeAll(performanceClasses);
082:
083: Iterator testClassIterator = testClasses.iterator();
084: while (testClassIterator.hasNext()) {
085: String testClassName = (String) testClassIterator.next();
086:
087: if (!excludedTests.contains(testClassName)) {
088: try {
089: Class testClass = Class.forName(testClassName);
090: Method suiteMethod = testClass.getMethod("suite",
091: null);
092: if (Modifier.isStatic(suiteMethod.getModifiers())) {
093: suite.addTest((Test) suiteMethod.invoke(null,
094: null));
095: }
096:
097: // don't care about any of these exceptions, if they occur
098: // just eat them an move on to the next test case
099: } catch (SecurityException e) {
100: } catch (IllegalArgumentException e) {
101: } catch (ClassNotFoundException e) {
102: } catch (NoSuchMethodException e) {
103: } catch (IllegalAccessException e) {
104: } catch (InvocationTargetException e) {
105: }
106: }
107: }
108:
109: return suite;
110: }
111:
112: }
|