File: AllPackages.java

package info (click to toggle)
derby 10.14.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 79,056 kB
  • sloc: java: 691,961; sql: 42,686; xml: 20,512; sh: 3,373; sed: 96; makefile: 60
file content (219 lines) | stat: -rw-r--r-- 8,466 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*

   Derby - Class org.apache.derbyTesting.functionTests.suites.AllPackages

   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to you under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

 */
package org.apache.derbyTesting.functionTests.suites;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import junit.framework.Test;
import org.apache.derbyTesting.functionTests.tests.replicationTests.ReplicationSuite;
import org.apache.derbyTesting.junit.BaseTestCase;
import org.apache.derbyTesting.junit.BaseTestSuite;

/**
 * All package suites for the function tests.
 * 
 * Suites added:
 * <UL>
 * <LI> tests.lang
 * <LI> tests.jdbcapi
 * <LI> tests.tools
 * <LI> tests.jdbc4 (Java SE 6  only)
 * </UL>
 */
public class AllPackages extends BaseTestCase {
    /**
     * Use suite method instead.
     */
    private AllPackages(String name) {
        super(name);
    }

    public static Test suite() throws Exception {

        BaseTestSuite suite = new BaseTestSuite("AllPackages");

        for (Iterator it = getTestClasses().iterator(); it.hasNext(); ) {
            Object testClass = it.next();
            if (testClass instanceof String) {
                suite.addTest(addSuiteByReflection((String) testClass));
            } else {
                suite.addTest(invokeSuite((Class) testClass));
            }
        }

        return suite;
    }

    /**
     * <p>
     * Get a list of test classes to add. The classes that have been compiled
     * with target level equal to the lowest supported level are included as
     * {@code java.lang.Class} objects. Classes compiled with higher target
     * levels are included as {@code java.lang.String}s with the class names
     * so that this method does not fail with class not found errors on some
     * platforms.
     * </p>
     *
     * <p>
     * To construct a test suite from these classes, the classes' static
     * {@code suite()} methods have to be called.
     * </p>
     *
     * @return list of test classes
     */
    private static List getTestClasses() {
        ArrayList<Object> classes = new ArrayList<Object>();

        classes.add(org.apache.derbyTesting.functionTests.tests.derbynet._Suite.class);
        classes.add(org.apache.derbyTesting.functionTests.tests.lang._Suite.class); 
        // DERBY-1903
        // For the largedata test, just run the lite version of the test as
        // the full test is too big.
        classes.add(
             org.apache.derbyTesting.functionTests.tests.largedata.LobLimitsLiteTest.class);
        classes.add(org.apache.derbyTesting.functionTests.tests.jdbcapi._Suite.class);
        classes.add(org.apache.derbyTesting.functionTests.tests.store._Suite.class);
        classes.add(org.apache.derbyTesting.functionTests.tests.storetests._Suite.class);
        classes.add(org.apache.derbyTesting.functionTests.tests.tools._Suite.class);
        classes.add(org.apache.derbyTesting.functionTests.tests.engine._Suite.class);
        classes.add(org.apache.derbyTesting.functionTests.tests.demo._Suite.class);
        classes.add(org.apache.derbyTesting.functionTests.tests.memory._Suite.class);
        classes.add(org.apache.derbyTesting.functionTests.tests.memorydb._Suite.class);
        classes.add(org.apache.derbyTesting.functionTests.tests.i18n._Suite.class);
        classes.add(org.apache.derbyTesting.functionTests.tests.multi.StressMultiTest.class);

        // Suites that are compiled using Java SE 6 target need to
        // be added this way, otherwise creating the suite
        // will throw an invalid class version error
        classes.add("org.apache.derbyTesting.functionTests.tests.jdbc4._Suite");
        
        // JMX management tests are compiled and require JDK 1.5
        classes.add("org.apache.derbyTesting.functionTests.tests.management._Suite");

        // Adding JUnit unit tests here to avoid creating a new JUnit
        // harness above the functionTests and unitTests
        // directories(packages)
        classes.add(org.apache.derbyTesting.unitTests.junit._Suite.class);
        
        // Add the upgrade tests,See upgradeTests._Suite
        // for more information on how the old jars are
        // located. If the system property derbyTesting.oldReleasePath
        // is not set then the jars will be loaded from the Apache SVN repo.
        classes.add(
           org.apache.derbyTesting.functionTests.tests.upgradeTests._Suite.class);

        // Encrypted tests
        // J2ME (JSR169) does not support encryption.
        classes.add(EncryptionSuite.class);

        // Replication tests. Implementation require DataSource.
        // Not supp. by JSR169
        classes.add(ReplicationSuite.class);

        // Compatibility tests (MATS)
        classes.add("org.apache.derbyTesting.functionTests.tests.compatibility._Suite");

        return classes;
    }
    
    /**
     * Get a class's set of tests from its suite method through reflection.
     * Ignore errors caused by the class version of the test class being
     * higher than what's supported on this platform.
     */
    private static Test addSuiteByReflection(String className) throws Exception
    {
        try {
            return invokeSuite(Class.forName(className));
        } catch (LinkageError  e) {
            return new BaseTestSuite("SKIPPED: " + className + " - " +
                    e.getMessage());
        } catch (InvocationTargetException ite) {
            Throwable cause = ite.getCause();
            if (cause instanceof LinkageError) {
               return new BaseTestSuite("SKIPPED: " + className + " - " +
                       cause.getMessage());
            } else {
                System.err.println("FAILED to invoke " + className);
                ite.printStackTrace();
               throw ite;
            }
        } catch (ClassNotFoundException ce) { // Do not add a suite not built.
            return new BaseTestSuite("SKIPPED: Class not found: " + className +
                    " - " + ce.getMessage());
        }
    }

    /**
     * Invoke the static {@code suite()} method on a test class.
     *
     * @param klass the test class
     * @return the test suite returned by {@code suite()}
     * @throws Exception if the suite() method cannot be called or fails
     */
    private static Test invokeSuite(Class<?> klass) throws Exception {
        try {
            return (Test) klass.getMethod("suite").invoke(null);
        } catch (Exception e) {
            System.err.println("Failed to invoke class " + klass.getName());
            e.printStackTrace();
            throw e;
        }
    }

    /**
     * Get the class names of all the top-level JUnit test suites that are
     * included in {@code suites.All}.
     *
     * @return an array containing the class names of all the top-level
     * test suites
     */
    public static String[] getTopLevelSuiteNames() {
        List testClasses = getTestClasses();
        String[] names = new String[testClasses.size()];

        for (int i = 0; i < testClasses.size(); i++) {
            Object testClass = testClasses.get(i);
            if (testClass instanceof String) {
                names[i] = (String) testClass;
            } else {
                names[i] = ((Class) testClass).getName();
            }
        }

        return names;
    }

    /**
     * Print the class names of all the test suites included in
     * {@code suites.All}.
     *
     * @param args command line arguments (ignored)
     */
    public static void main(String[] args) {
        String[] names = getTopLevelSuiteNames();
        for (int i = 0; i < names.length; i++) {
            System.out.println(names[i]);
        }
    }
}