use of org.apache.derbyTesting.junit.BaseTestSuite in project derby by apache.
the class RunTest method execTestNoProcess.
private static void execTestNoProcess(Properties sysProp, String systemHome, String propString, String scriptPath) throws Exception {
// For platforms where executing a process is failing
Properties ptmp = System.getProperties();
ptmp.put("derby.system.home", systemHome);
ptmp.put("derby.infolog.append", "true");
// passed on on command line to individual tests...
if (framework.startsWith("DerbyNet"))
ptmp.put("hostName=", hostName);
System.setProperties(ptmp);
String pathStr = "";
// a bug in the EPOC jvm.
try {
pathStr = tmpOutFile.getCanonicalPath().replace(File.separatorChar, fileSep);
} catch (IOException e) {
FileWriter fw = new FileWriter(tmpOutFile);
fw.close();
pathStr = tmpOutFile.getCanonicalPath().replace(File.separatorChar, fileSep);
}
PrintStream ps = new PrintStream(new FileOutputStream(pathStr), true);
// Install a security manager within this JVM for this test.
composePolicyFile();
boolean installedSecurityManager = installSecurityManager();
if (testType.equals("sql")) {
String[] ijarg = new String[3];
ijarg[0] = "-p";
ijarg[1] = propString;
ijarg[2] = scriptPath;
// direct the standard output and error to the print stream for the .tmp file
PrintStream stdout = System.out;
PrintStream stderr = System.err;
System.setOut(ps);
System.setErr(ps);
RunIJ ij = new RunIJ(ijarg);
Thread ijThread = new Thread(ij);
try {
ijThread.start();
if (timeout < 0) {
ijThread.join();
} else {
ijThread.join(timeout * 60 * 1000);
}
} catch (Exception e) {
System.out.println("Aiiie! Got some kind of exception " + e);
}
// Now make sure a shutdown is complete if necessary
if (shutdownurl != null) {
String[] sdargs = new String[2];
sdargs[0] = systemHome;
sdargs[1] = shutdownurl;
shutdown.main(sdargs);
}
// Reset ij.defaultResourcePackage
ptmp = System.getProperties();
ptmp.put("ij.defaultResourcePackage", "/org/apache/derbyTesting/");
ptmp.put("usesystem", "");
System.setProperties(ptmp);
// Reset System.out and System.err
System.setOut(stdout);
System.setErr(stderr);
} else if (testType.equals("java")) {
if (javaPath == null)
javaPath = "org.apache.derbyTesting.functionTests.tests." + testDirName;
String[] args = new String[2];
args[0] = "-p";
args[1] = propString;
Class[] classArray = new Class[1];
classArray[0] = args.getClass();
String testName = javaPath + "." + testBase;
Class<?> JavaTest = Class.forName(testName);
PrintStream stdout = System.out;
PrintStream stderr = System.err;
System.setOut(ps);
System.setErr(ps);
// Get the tests's main method and invoke it
Method testMain = JavaTest.getMethod("main", classArray);
Object[] argObj = new Object[1];
argObj[0] = args;
RunClass testObject = new RunClass(testMain, argObj);
Thread testThread = new Thread(testObject);
try {
testThread.start();
if (timeout < 0) {
testThread.join();
} else {
testThread.join(timeout * 60 * 1000);
}
} catch (Exception e) {
System.out.println("Exception upon invoking test..." + e);
e.printStackTrace();
}
try {
java.sql.DriverManager.getConnection("jdbc:derby:;shutdown=true");
} catch (java.sql.SQLException e) {
// ignore the errors, they are expected.
}
// Reset System.out and System.err
System.setOut(stdout);
System.setErr(stderr);
} else if (testType.equals("multi")) {
System.out.println("scriptiflename is: later " + scriptFileName);
// multi tests will now run with useprocess=false;
// however, probably because they use Threads, if run
// within another test suite, the next suite will not run
// And using a Thread.join() to start the tests doesn't resolve
// this. So this support is here simply to allow running
// something like stressmulti just by itself for debugging
// javaPath = "org.apache.derbyTesting.functionTests.harness.MultiTest";
String[] args = new String[5];
args[0] = scriptFileName;
args[1] = "-i";
args[2] = mtestdir;
args[3] = "-o";
args[4] = outDir.getPath();
System.out.println("Try running MultiTest.main");
for (int i = 0; i < args.length; i++) System.out.println("args: " + args[i]);
System.exit(1);
org.apache.derbyTesting.functionTests.harness.MultiTest.main(args);
} else if (testType.equals("unit")) {
// direct the standard output and error to the print stream for the .tmp file
PrintStream stdout = System.out;
PrintStream stderr = System.err;
System.setOut(ps);
System.setErr(ps);
System.out.println("Unit tests not implemented yet with useprocess=false");
// Reset System.out and System.err
System.setOut(stdout);
System.setErr(stderr);
// repeat to stdout...
System.out.println("Unit tests not implemented yet with useprocess=false");
// System.exit(1);
/*
String[] args = new String[2];
args[0] = "-p";
args[1] = propString;
org.apache.derbyTesting.unitTests.harness.UnitTestMain.main(args);
*/
} else if (testType.equals("junit")) {
PrintStream stdout = System.out;
PrintStream stderr = System.err;
System.setOut(ps);
System.setErr(ps);
if (javaPath == null) {
javaPath = "org.apache.derbyTesting.functionTests.tests." + testDirName;
}
String testName = javaPath + "." + testBase;
// NOTE: This is most likely a temporary solution that will be
// replaced once we get our own TestRunner.
// Cannot use junit.textui.TestRunner.main() since it will exit
// the JVM when done.
// Extract/create a BaseTestSuite object, which is either
// a) retreived from a static suite() method in the test class
//
// or, if a) fails
//
// b) containing all methods starting with "test" in the junit
// test class.
// This corresponds to what the junit.textui.TestRunner would
// do if invoked in a separate process (useprocess=true).
// Load the test class
Class<?> testClass = Class.forName(testName);
BaseTestSuite junitTestSuite = null;
try {
// Get the static suite() method if it exists.
Method suiteMethod = testClass.getMethod("suite", null);
// Get the BaseTestSuite object returned by the suite() method
// by invoking it.
// Method is static, hence param1 is null
// Method has no formal parameters, hence param2 is null
junitTestSuite = (BaseTestSuite) suiteMethod.invoke(null, null);
} catch (Exception ex) {
// Not able to access static suite() method (with no params)
// returning a BaseTestSuite object.
// Use JUnit to create a BaseTestSuite with all methods in the
// test class starting with "test"
junitTestSuite = new BaseTestSuite(testClass);
}
if (junitTestSuite != null) {
// Now run the test suite
junit.textui.TestRunner.run(junitTestSuite);
} else {
System.out.println("Not able to extract JUnit BaseTestSuite from " + "test class " + testName);
}
// Reset System.out and System.err
System.setOut(stdout);
System.setErr(stderr);
}
ps.close();
if (installedSecurityManager) {
System.setSecurityManager(null);
}
}
use of org.apache.derbyTesting.junit.BaseTestSuite in project derby by apache.
the class BiggerTemporaryClobTest method suite.
public static Test suite() throws Exception {
Class<? extends TestCase> theClass = BiggerTemporaryClobTest.class;
BaseTestSuite suite = new BaseTestSuite(theClass, "BiggerTemporaryClobTest suite");
suite.addTest(addModifyingTests(theClass));
return suite;
}
use of org.apache.derbyTesting.junit.BaseTestSuite in project derby by apache.
the class InternalClobTest method addModifyingTests.
protected static Test addModifyingTests(Class<? extends TestCase> theClass) throws Exception {
BaseTestSuite suite = new BaseTestSuite("Modifying InternalClob test suite");
Method[] methods = theClass.getMethods();
List<String> testMethods = new ArrayList<String>();
for (int i = 0; i < methods.length; i++) {
Method m = methods[i];
if (m.getReturnType().equals(Void.TYPE) && m.getName().startsWith("modTest") && m.getParameterTypes().length == 0) {
testMethods.add(m.getName());
}
}
Constructor<? extends Test> ctor = theClass.getConstructor(new Class[] { String.class });
for (int i = 0; i < testMethods.size(); i++) {
suite.addTest(ctor.newInstance(new Object[] { testMethods.get(i) }));
}
return suite;
}
use of org.apache.derbyTesting.junit.BaseTestSuite in project derby by apache.
the class _Suite method suite.
public static Test suite() throws Exception {
BaseTestSuite suite = new BaseTestSuite("jdbc.impl package-private");
suite.addTest(SmallTemporaryClobTest.suite());
suite.addTest(BiggerTemporaryClobTest.suite());
suite.addTest(SmallStoreStreamClobTest.suite());
suite.addTest(BiggerStoreStreamClobTest.suite());
suite.addTest(UTF8ReaderTest.suite());
return suite;
}
use of org.apache.derbyTesting.junit.BaseTestSuite in project derby by apache.
the class PackagePrivateTestSuite method suite.
public static Test suite() throws Exception {
BaseTestSuite suite = new BaseTestSuite("Package-private tests");
suite.addTest(org.apache.derby.impl.jdbc._Suite.suite());
suite.addTest(org.apache.derby.client.am._Suite.suite());
return suite;
}
Aggregations