Method from org.apache.jdo.tck.util.BatchTestRunner Detail: |
public static String changeFileName(String fileName) {
String directory = LOG_DIRECTORY;
String db = System.getProperty("jdo.tck.database");
String identityType = System.getProperty("jdo.tck.identitytype");
if (identityType!=null) {
if (identityType.equals("applicationidentity")) {
identityType = "app";
} else {
identityType = "dsid";
}
}
String configuration = System.getProperty("jdo.tck.cfg");
if (configuration!=null) {
int index = configuration.indexOf('.');
if (index!=-1) {
configuration = configuration.substring(0, index);
}
}
directory = fixPartialFileName(directory);
db = fixPartialFileName(db, '-',
new String[]{identityType, configuration, fileName});
identityType = fixPartialFileName(identityType, '-',
new String[]{configuration, fileName});
configuration = fixPartialFileName(configuration, '-',
new String[]{fileName});
return directory + db + identityType + configuration + fileName;
}
Returns a file name which is constructed by values
of some system properties appended by the given file name.
The system properties evaluated are:
- jdo.tck.log.directory: Specifies the directory for the file.
- jdo.tck.database, jdo.tck.cfg:
The values of these properties prepend the given file name.
- jdo.tck.identitytype: The value of this property is replaced by
"app" if it equals "applicationidentity" ,
else it is replaced by "dsid" .
The returned file name is constructed as follows:
/--
Values of properties which do not exist default to "" . |
public TestResult doRun(Test test) {
TestResult result = null;
try {
result = doRun(test, false);
JDO_Test.dumpSupportedOptions(LOG_DIRECTORY + "configuration");
} finally {
JDO_Test.closePMF();
}
return result;
}
Runs the specified test or test suite and closes the pmf. |
protected ResultPrinter getDefaultResultPrinter() {
return new BatchResultPrinter(System.out);
}
Returns an instance of the default result printer class
BatchResultPrinter. |
public static String getFileName() {
return changeFileName("junit.txt");
}
|
protected ResultPrinter getResultPrinter() {
String className = System.getProperty(RESULTPRINTER_PROPERTY);
if (className != null) {
className = className.trim();
if (className.length() != 0) {
String msg = null;
try {
// get class instance
Class clazz = Class.forName(className);
Constructor ctor = null;
OutputStream stream = null;
// choose constructor taking ConsoleFileOutput arg
if (!Boolean.getBoolean("no.log.file")) {
try {
ctor = clazz.getConstructor(
new Class[] { ConsoleFileOutput.class } );
stream = new ConsoleFileOutput();
}
catch (NoSuchMethodException ex) {
ctor = null;
}
}
// choose constructor taking PrintStream arg
if (ctor == null) {
ctor = clazz.getConstructor(
new Class[] { PrintStream.class } );
stream = System.out;
}
return (ResultPrinter)ctor.newInstance(
new Object[] { stream });
}
catch (ClassNotFoundException ex) {
// specified ResultPrinter class not
msg = "Cannot find specified result printer class " +
className + ".";
}
catch (NoSuchMethodException ex) {
msg = "Class " + className +
" does not provide constructor taking a PrintStream.";
}
catch (InstantiationException ex) {
msg = "Class " + className + " is abstract.";
}
catch (IllegalAccessException ex) {
msg = "Constructor taking a PrintStream of class " +
className + " is not accessible.";
}
catch (InvocationTargetException ex) {
msg = "Constructor call results in exception " + ex + ".";
}
// ResultPrinter class specified, but not avaiable
System.out.println(msg);
ResultPrinter printer = getDefaultResultPrinter();
System.out.println("Using default result printer of class " +
printer.getClass().getName());
}
}
// ResultPrinter class not specified = > use default
return getDefaultResultPrinter();
}
Returns a result printer instance. The system property
ResultPrinterClass specifies the class of the returned instanec. The
class must extend junit.textui.ResultPrinter. |
protected TestSuite getTestSuite(String[] classNames) {
TestSuite testSuite = new TestSuite();
for (int i = 0; i < classNames.length; i++) {
String className = classNames[i];
try {
testSuite.addTestSuite(Class.forName(className));
}
catch (ClassNotFoundException ex) {
System.out.println(
"Cannot find test class '" + className + "'.");
}
}
return testSuite;
}
Returns a JUnit TestSuite instance for the classes of the specified
list of class names. |
public static void main(String[] args) {
try {
TestResult r = new BatchTestRunner().start(args);
if (!r.wasSuccessful())
System.exit(FAILURE_EXIT);
System.exit(SUCCESS_EXIT);
} catch(Exception e) {
System.err.println(e.getMessage());
System.exit(EXCEPTION_EXIT);
}
}
Runs in batch mode and sets an exit code. If the specified String
array includes a single fully qualified class name, this test class
is executed. |
public static void run(Class clazz) {
run(new TestSuite(clazz));
}
Runs all test methods from the specified class. |
public static TestResult run(Test test) {
return new BatchTestRunner().doRun(test);
}
Runs the specified test or test suite |
public static void runAndWait(Test suite) {
new BatchTestRunner().doRun(suite, true);
}
Runs the specified test and waits until the user types RETURN. |
public TestResult start(String[] args) {
Test suite = null;
if ((args == null) || args.length == 0) {
String conf = System.getProperty("jdo.tck.cfg");
throw new JDOFatalException(
"Missing JDO TCK test classes for configuration '" + conf +
"'. Please check the property 'jdo.tck.classes'.");
}
else if (args.length == 1) {
suite = getTest(args[0]);
}
else {
suite = getTestSuite(args);
}
return doRun(suite);
}
|